diff options
-rw-r--r-- | NAME/__init__.py | 0 | ||||
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | setup.py | 23 | ||||
-rw-r--r-- | tests/NAME_tests.py | 11 | ||||
-rw-r--r-- | tests/__init__.py | 0 | ||||
-rwxr-xr-x | vnfmgr/vnfmgr_main.py | 72 | ||||
-rw-r--r-- | vnfmgr/vnfmgr_odl/__init__.py | 0 | ||||
-rwxr-xr-x | vnfmgr/vnfmgr_odl/sample_config/RestConf-RSP-HttpPost.json (renamed from vnfmgr_sim/sample_config/RestConf-RSP-HttpPost.json) | 0 | ||||
-rwxr-xr-x | vnfmgr/vnfmgr_odl/sample_config/RestConf-SFCs-HttpPut.json (renamed from vnfmgr_sim/sample_config/RestConf-SFCs-HttpPut.json) | 0 | ||||
-rwxr-xr-x | vnfmgr/vnfmgr_odl/sample_config/RestConf-SFFs-HttpPut.json (renamed from vnfmgr_sim/sample_config/RestConf-SFFs-HttpPut.json) | 0 | ||||
-rwxr-xr-x | vnfmgr/vnfmgr_odl/sample_config/RestConf-SFPs-HttpPut.json (renamed from vnfmgr_sim/sample_config/RestConf-SFPs-HttpPut.json) | 0 | ||||
-rwxr-xr-x | vnfmgr/vnfmgr_odl/sample_config/RestConf-SFs-HttpPut.json (renamed from vnfmgr_sim/sample_config/RestConf-SFs-HttpPut.json) | 0 | ||||
-rwxr-xr-x | vnfmgr/vnfmgr_odl/vnfmgr_odl.py (renamed from vnfmgr_sim/vnfmgr_sim.py) | 13 | ||||
-rw-r--r-- | vnfmgr/vnfmgr_os/__init__.py | 0 | ||||
-rwxr-xr-x | vnfmgr/vnfmgr_os/vnfmgr_os.py | 68 |
15 files changed, 182 insertions, 6 deletions
diff --git a/NAME/__init__.py b/NAME/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/NAME/__init__.py @@ -0,0 +1 @@ +This code deploys the ODL-Openstack maanger. diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..9ff16995 --- /dev/null +++ b/setup.py @@ -0,0 +1,23 @@ +import os +from setuptools import setup + +# Utility function to read the README file. +# Used for the long_description. It's nice, because now 1) we have a top level +# README file and 2) it's easier to type in the README file than to put a raw +# string in below ... +def read(fname): + return open(os.path.join(os.path.dirname(__file__), fname)).read() + +setup( + name = "vnf manager simulator", + version = "1.0", + author = "Manuel Buil, Brady A. Johnson", + author_email = "manuel.buil@ericsson.com, brady.allen.johnson@ericsson.com", + description = ("A script which simulates an orchestrator"), + license = "Apache License Version 2.0", + keywords = "example documentation tutorial", + url = "https://gerrit.opnfv.org/gerrit/#/c/2519", + packages = [".."], + scripts = [".."], + long_description=read('README'), +) diff --git a/tests/NAME_tests.py b/tests/NAME_tests.py new file mode 100644 index 00000000..9f83104c --- /dev/null +++ b/tests/NAME_tests.py @@ -0,0 +1,11 @@ +from nose.tools import * +import NAME + +def setup(): + print "SETUP!" + +def teardown(): + print "TEAR DOWN!" + +def test_basic(): + print "I RAN!" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/__init__.py diff --git a/vnfmgr/vnfmgr_main.py b/vnfmgr/vnfmgr_main.py new file mode 100755 index 00000000..b5ab8be1 --- /dev/null +++ b/vnfmgr/vnfmgr_main.py @@ -0,0 +1,72 @@ +################################################################# +# # +# Copyright 2015 Ericsson AB # +# All Rights Reserved # +# # +# Author: Manuel Buil <Manuel.Buil@ericsson.com> # +# Version: 0.1 # +# # +################################################################# + +import pdb +from vnfmgr_os.vnfmgr_os import OpenStack_API +import vnfmgr_odl.vnfmgr_odl as odlscript +import time +import json + +if __name__ == "__main__": + #OpenStack environment information + authurl = "http://localhost:5000/v2.0" + adminTenantName = 'admin' + adminTenantUser = 'admin' + adminTenantPass = 'abc123' + tenantName = adminTenantName + tenantUser = adminTenantUser + tenantPass = adminTenantPass + + openstack = OpenStack_API(authurl, tenantName, tenantUser, tenantPass) + + # 1 - Get the SF type + # Provide the file with the SFC configuration + file_json = "vnfmgr_odl/sample_config/RestConf-SFCs-HttpPut.json" + # Read the config files which refer to SF + json_data=open(file_json).read() + data = json.loads(json_data) + pdb.set_trace() + + # Grab the SF type + chains = data['service-function-chains']['service-function-chain'] + for chain in chains: + SFs = chain['sfc-service-function'] + for SF in SFs: + sf_type = SF['type'] + name = SF['name'] + #2 - Search the image in glance with that SF type + image = openstack.find_image(sf_type) + if image == None: + print("There is no image with that sf_name") + exit(1) + # 3 - Boot the VM without network + flavor = 1 + print("About to deploy") + vm = openstack.create_vm(name,image,flavor) + if vm == None: + print("Problems to deploy the VM") + exit(1) + + #Make the call to ODL to deploy SFC + context = odlscript.Context() + context.set_path_prefix_paths("vnfmgr_odl/sample_config") + pdb.set_trace() + odlscript.send_rest(context, "PUT", context.rest_url_sf_sel, context.rest_path_sf_sel) + odlscript.send_rest(context, "PUT", context.rest_url_sf, context.rest_path_sf) + odlscript.send_rest(context, "PUT", context.rest_url_sff, context.rest_path_sff) + odlscript.send_rest(context, "PUT", context.rest_url_sfc, context.rest_path_sfc) + odlscript.send_rest(context, "PUT", context.rest_url_sfp, context.rest_path_sfp) + time.sleep(1); + odlscript.send_rest(context, "POST", context.rest_url_rsp_rpc, context.rest_path_rsp) + + + #TO DO + # Check if the SF_VM already exists before creating it + # Network of the VM diff --git a/vnfmgr/vnfmgr_odl/__init__.py b/vnfmgr/vnfmgr_odl/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/vnfmgr/vnfmgr_odl/__init__.py diff --git a/vnfmgr_sim/sample_config/RestConf-RSP-HttpPost.json b/vnfmgr/vnfmgr_odl/sample_config/RestConf-RSP-HttpPost.json index 998d1e07..998d1e07 100755 --- a/vnfmgr_sim/sample_config/RestConf-RSP-HttpPost.json +++ b/vnfmgr/vnfmgr_odl/sample_config/RestConf-RSP-HttpPost.json diff --git a/vnfmgr_sim/sample_config/RestConf-SFCs-HttpPut.json b/vnfmgr/vnfmgr_odl/sample_config/RestConf-SFCs-HttpPut.json index 34449647..34449647 100755 --- a/vnfmgr_sim/sample_config/RestConf-SFCs-HttpPut.json +++ b/vnfmgr/vnfmgr_odl/sample_config/RestConf-SFCs-HttpPut.json diff --git a/vnfmgr_sim/sample_config/RestConf-SFFs-HttpPut.json b/vnfmgr/vnfmgr_odl/sample_config/RestConf-SFFs-HttpPut.json index 191fd540..191fd540 100755 --- a/vnfmgr_sim/sample_config/RestConf-SFFs-HttpPut.json +++ b/vnfmgr/vnfmgr_odl/sample_config/RestConf-SFFs-HttpPut.json diff --git a/vnfmgr_sim/sample_config/RestConf-SFPs-HttpPut.json b/vnfmgr/vnfmgr_odl/sample_config/RestConf-SFPs-HttpPut.json index da1f2c45..da1f2c45 100755 --- a/vnfmgr_sim/sample_config/RestConf-SFPs-HttpPut.json +++ b/vnfmgr/vnfmgr_odl/sample_config/RestConf-SFPs-HttpPut.json diff --git a/vnfmgr_sim/sample_config/RestConf-SFs-HttpPut.json b/vnfmgr/vnfmgr_odl/sample_config/RestConf-SFs-HttpPut.json index 1ea27e79..1ea27e79 100755 --- a/vnfmgr_sim/sample_config/RestConf-SFs-HttpPut.json +++ b/vnfmgr/vnfmgr_odl/sample_config/RestConf-SFs-HttpPut.json diff --git a/vnfmgr_sim/vnfmgr_sim.py b/vnfmgr/vnfmgr_odl/vnfmgr_odl.py index c907e30d..4d35aebb 100755 --- a/vnfmgr_sim/vnfmgr_sim.py +++ b/vnfmgr/vnfmgr_odl/vnfmgr_odl.py @@ -6,7 +6,7 @@ __license__ = "Apache License version 2.0" __version__ = "0.1" __email__ = "brady.allen.johnson@ericsson.com" __status__ = "beta" - +import pdb import os import time import requests @@ -22,7 +22,7 @@ class Context(object): Context class to hold the configuration as specified on the command line """ def __init__(self): - self.rest_path_prefix = 'restInput' + self.rest_path_prefix = 'sampleConfig' self.rest_path_sf = 'RestConf-SFs-HttpPut.json' self.rest_path_sf_sel = 'RestConf-SFselect-HttpPut.json' self.rest_path_sfc = 'RestConf-SFCs-HttpPut.json' @@ -378,7 +378,8 @@ def CLI(context): elif option == '6': send_rest(context, PUT, context.rest_url_acl, context.rest_path_acl) elif option == '7': - send_rest(context, PUT, context.rest_url_sf_sel, context.rest_path_sf_sel) + pdb.set_trace() + send_rest(context, PUT, context.rest_url_sf_sel, context.rest_path_sf_sel) send_rest(context, PUT, context.rest_url_sf, context.rest_path_sf) send_rest(context, PUT, context.rest_url_sff, context.rest_path_sff) send_rest(context, PUT, context.rest_url_sfc, context.rest_path_sfc) @@ -416,11 +417,11 @@ def main(): Command line arguments are expected. Example invocations: To display application command-line help: - vnfmgr_sim.py --help + vnfmgr_odl.py --help To start the application in interractive mode: - vnfmgr_sim.py -prefix <input json dir> + vnfmgr_odl.py -prefix <input json dir> To start the application in batch mode and send an SF JSON REST message: - vnfmgr_sim.py -b -prefix <input json dir> --send-sf + vnfmgr_odl.py -b -prefix <input json dir> --send-sf """ context = Context() diff --git a/vnfmgr/vnfmgr_os/__init__.py b/vnfmgr/vnfmgr_os/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/vnfmgr/vnfmgr_os/__init__.py diff --git a/vnfmgr/vnfmgr_os/vnfmgr_os.py b/vnfmgr/vnfmgr_os/vnfmgr_os.py new file mode 100755 index 00000000..00678503 --- /dev/null +++ b/vnfmgr/vnfmgr_os/vnfmgr_os.py @@ -0,0 +1,68 @@ +################################################################# +# # +# Copyright 2015 Ericsson AB # +# All Rights Reserved # +# # +# Author: Manuel Buil <Manuel.Buil@ericsson.com> # +# Version: 0.1 # +# # +################################################################# + +import pdb + +from novaclient.v2 import client as nova +from novaclient import exceptions as novaexceptions +from keystoneclient.v2_0 import client as keystone +from glanceclient import client as glance + + +class OpenStack_API: + def __init__(self, authurl, tenantName, tenantUser, tenantPass): + self.authurl=authurl + self.tenantName=tenantName + self.tenantUser=tenantUser + self.tenantPass=tenantPass + + def get_token(self): + # Establish connection to Openstack controller + osconn = keystone.Client(username=self.tenantUser, password=self.tenantPass, tenant_name=self.tenantName, auth_url=self.authurl) + token = osconn.auth_token + return token + + def get_endpoint(self,service_type, endpoint_type): + # Establish connection to Openstack controller + osconn = keystone.Client(username=self.tenantUser, password=self.tenantPass, tenant_name=self.tenantName, auth_url=self.authurl) + endpoint = osconn.service_catalog.url_for(service_type=service_type, endpoint_type=endpoint_type) + return endpoint + + def find_image(self,SF_type): + # Find in glance the image that matches the SF we want to deploy + token = self.get_token() + endpoint = self.get_endpoint('image','publicURL') + osconn = glance.Client('1',endpoint=endpoint,token=token) + image_list = osconn.images.list() + for item in image_list: + try: + image_type = item.properties.get('image_type', None) + image_id=None + if (image_type == SF_type): + image_id = item.id + break + except: + print("Errrorr") + + #Search image which matches the SF type + return image_id + + def create_vm(self, name, image, flavor, nics=None): + # Establish connection to Openstack controller + osconn = nova.Client(self.tenantUser, self.tenantPass, self.tenantName, self.authurl, service_type="compute") + try: + if nics is None: + vm = osconn.servers.create(name,image,flavor) + else: + vm = osconn.servers.create(name,image,flavor,nics) + except: + print("Something wrong happened while creating the VM") + vm = None + return vm |