Skip to content

Commit

Permalink
[Update] Added support for VNFR calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinprasadme committed May 10, 2019
1 parent a1b1fb8 commit c72c2c8
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/adaptor/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# This call to setup() does all the work
setup(
name="python-mano-wrappers",
version="0.9.5",
version="0.9.6",
description="REST API Wrappers for various MANOs in compliance with ETSI SOL0005",
long_description=README,
long_description_content_type="text/x-rst",
Expand Down
6 changes: 6 additions & 0 deletions src/adaptor/tests/osm/osm_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@ def get_vim_info_keys():
return ['_id', 'vim_user', 'name', '_admin', 'vim_password', 'vim_url',
'vim_type', 'vim_tenant_name', 'schema_version', 'config']

@fixture
def get_vnf_instances_keys():
return ['_id', 'member-vnf-index-ref', '_admin', 'id', 'vnfd-ref', 'vnfd-id', 'ip-address', 'vim-account-id', 'created-time', 'vdur', 'nsr-id-ref', 'connection-point']

@fixture
def get_vnf_instances_vnfinstanceid_keys():
return ['_id', 'member-vnf-index-ref', '_admin', 'id', 'vnfd-ref', 'vnfd-id', 'ip-address', 'vim-account-id', 'created-time', 'vdur', 'nsr-id-ref', 'connection-point']

39 changes: 38 additions & 1 deletion src/adaptor/tests/osm/test_nslcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,44 @@ def test_get_ns_instances_nsinstanceid():
return True
else:
return False


def test_get_vnf_instances(get_vnf_instances_keys):
"""Tests API call query multiple VNF instances"""
osm_nslcm = OSMClient.Nslcm(HOST_URL)
osm_auth = OSMClient.Auth(HOST_URL)
_token = json.loads(osm_auth.auth(username=USERNAME, password=PASSWORD))
_token = json.loads(_token["data"])

response = json.loads(osm_nslcm.get_vnf_instances(
token=_token["id"]))
response = json.loads(response["data"])

assert isinstance(response, list)
if len(response) > 0:
assert set(get_vnf_instances_keys).issubset(
response[0].keys()), "All keys should be in the response"

def test_get_vnf_instances_vnfinstanceid(get_vnf_instances_vnfinstanceid_keys):
"""Tests API call to read an individual VNF instance resource"""
osm_nslcm = OSMClient.Nslcm(HOST_URL)
osm_auth = OSMClient.Auth(HOST_URL)
_token = json.loads(osm_auth.auth(username=USERNAME, password=PASSWORD))
_token = json.loads(_token["data"])

_vnf_list = json.loads(osm_nslcm.get_vnf_instances(
token=_token["id"]))
_vnf_list = json.loads(_vnf_list["data"])

response = json.loads(osm_nslcm.get_vnf_instances_vnfinstanceid(
token=_token["id"], vnfInstanceId=_vnf_list[0]["id"]))

assert response['error'] == False
response = json.loads(response["data"])
assert isinstance(response, dict)
assert set(get_vnf_instances_vnfinstanceid_keys).issubset(
response.keys()), "All keys should be in the response"



# def test_get_ns_lcm_op_ops(get_ns_lcm_op_ops_keys):
# """Tests API call to query multiple NS LCM operation occurrences"""
Expand Down
7 changes: 7 additions & 0 deletions src/adaptor/tests/sonata/sonata_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,10 @@ def get_packages_keys():
return ['descriptor_version', 'package_group', 'package_name', 'package_version', 'package_maintainer', 'package_description',
'entry_service_template', 'sealed', 'package_content', 'artifact_dependencies']

@fixture
def get_vnf_instances_keys():
return ['created_at', 'descriptor_reference', 'descriptor_version', 'status', 'updated_at', 'version', 'virtual_deployment_units', 'uuid']

@fixture
def get_vnf_instances_vnfinstanceid_keys():
return ['created_at', 'descriptor_reference', 'descriptor_version', 'status', 'updated_at', 'version', 'virtual_deployment_units', 'uuid']
36 changes: 36 additions & 0 deletions src/adaptor/tests/sonata/test_nslcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,42 @@ def test_get_ns_instances_nsinstanceid(test_get_ns_instances_nsinstanceid_keys):
response.keys()), "All keys should be in the response"


def test_get_vnf_instances(get_vnf_instances_keys):
"""Tests API call query multiple VNF instances"""
sonata_nslcm = SONATAClient.Nslcm(HOST_URL)
sonata_auth = SONATAClient.Auth(HOST_URL)
_token = json.loads(sonata_auth.auth(username=USERNAME, password=PASSWORD))
_token = json.loads(_token["data"])
response = json.loads(sonata_nslcm.get_vnf_instances(
token=_token["token"]["access_token"]))
response = json.loads(response["data"])

assert isinstance(response, list)
if len(response) > 0:
assert set(get_vnf_instances_keys).issubset(
response[0].keys()), "All keys should be in the response"

def test_get_vnf_instances_vnfinstanceid(get_vnf_instances_vnfinstanceid_keys):
"""Tests API call to read an individual VNF instance resource"""
sonata_nslcm = SONATAClient.Nslcm(HOST_URL)
sonata_auth = SONATAClient.Auth(HOST_URL)
_token = json.loads(sonata_auth.auth(username=USERNAME, password=PASSWORD))
_token = json.loads(_token["data"])

_vnf_list = json.loads(sonata_nslcm.get_vnf_instances(
token=_token["token"]["access_token"]))
_vnf_list = json.loads(_vnf_list["data"])

response = json.loads(sonata_nslcm.get_vnf_instances_vnfinstanceid(
token=_token["token"]["access_token"], vnfInstanceId=_vnf_list[0]["uuid"]))

assert response['error'] == False
response = json.loads(response["data"])
assert isinstance(response, dict)
assert set(get_vnf_instances_vnfinstanceid_keys).issubset(
response.keys()), "All keys should be in the response"


def test_post_ns_instances_nsinstanceid_instantiate(post_ns_instances_nsinstanceid_instantiate_keys):
"""Tests API call to instantiate an NS"""
sonata_nslcm = SONATAClient.Nslcm(HOST_URL)
Expand Down
82 changes: 82 additions & 0 deletions src/adaptor/wrappers/OSMClient/nslcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,88 @@ def get_ns_instances(self, token, host=None, port=None):
result['data'] = r.text
return json.dumps(result)

def get_vnf_instances(self, token, host=None, port=None):
""" NS Lifecycle Management interface -
VNF instances - *NON ETSI
GET - Query multiple VNF instances.
:param token: auth token retrieved by the auth call
:param host: host url
:param port: port where the MANO API can be accessed
Example:
.. code-block:: python
osm_nslcm = OSMClient.Nslcm(HOST_URL)
osm_auth = OSMClient.Auth(HOST_URL)
_token = json.loads(osm_auth.auth(username=USERNAME, password=PASSWORD))
_token = json.loads(_token["data"])
response = json.loads(osm_nslcm.get_vnf_instances(token=_token["id"]))
response = json.loads(response["data"])
"""

if host is None:
base_path = self._base_path.format(self._host, self._port)
else:
base_path = self._base_path.format(host, port)

result = {'error': True, 'data': ''}
headers = {"Content-Type": "application/yaml",
"accept": "application/json" ,
"Authorization": 'Bearer {}'.format(token)}
_endpoint = "{0}/nslcm/v1/vnfrs".format(base_path)

try:
r = requests.get(_endpoint, params=None, verify=False,
headers=headers)
except Exception as e:
result['data'] = str(e)
return result

if r.status_code == requests.codes.ok:
result['error'] = False

result['data'] = r.text
return json.dumps(result)

def get_vnf_instances_vnfinstanceid(self, token, vnfInstanceId ,host=None, port=None):
""" NS Lifecycle Management interface -
Individual VNF instance - *NON ETSI
GET - Read an individual VNF instance resource.
:param token: auth token retrieved by the auth call
:param vnfInstanceId: id of the VNF instance
:param host: host url
:param port: port where the MANO API can be accessed
"""
if host is None:
base_path = self._base_path.format(self._host, self._port)
else:
base_path = self._base_path.format(host, port)

result = {'error': True, 'data': ''}
headers = {"Content-Type": "application/json",
"accept": "application/json",
"Authorization": 'Bearer {}'.format(token)}
_endpoint = "{0}/nslcm/v1/vnfrs/{1}".format(base_path, vnfInstanceId)

try:
r = requests.get(_endpoint, params=None, verify=False,
headers=headers)
except Exception as e:
result['data'] = str(e)
return result
if r.status_code == requests.codes.ok:
result['error'] = False

result['data'] = r.text
return json.dumps(result)

def post_ns_instances_nsinstanceid_instantiate(self, token, nsDescription,
nsName, nsdId, vimAccountId, host=None, port=None):
""" NS Lifecycle Management interface -
Expand Down
87 changes: 85 additions & 2 deletions src/adaptor/wrappers/SONATAClient/nslcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ class Nslcm(CommonInterfaceNslcm):
"""
Lifecycle Management interface
"""
def __init__(self, host, port=32001):
def __init__(self, host, port=32001, repositories_port=4002):
self._host = host
self._port = port
self._repositories_port = repositories_port
self._base_path = 'http://{0}:{1}/api/v2'
self._repositories_base_path = 'http://{0}:{1}/'

def get_ns_instances(self, token, host=None, port=None):
""" NS Lifecycle Management interface -
Expand Down Expand Up @@ -96,7 +98,88 @@ def get_ns_instances_nsinstanceid(self, token, nsInstanceId ,host=None, port=Non
result['data'] = r.text
return json.dumps(result)


def get_vnf_instances(self, token, host=None, port=None):
""" NS Lifecycle Management interface -
VNF instances - *NON ETSI
GET - Query multiple VNF instances.
:param token: auth token retrieved by the auth call
:param host: host url
:param port: port where the MANO API can be accessed
Example:
.. code-block:: python
sonata_nslcm = SONATAClient.Nslcm(HOST_URL)
sonata_auth = SONATAClient.Auth(HOST_URL)
_token = json.loads(sonata_auth.auth(username=USERNAME, password=PASSWORD))
_token = json.loads(_token["data"])
response = json.loads(sonata_nslcm.get_vnf_instances(
token=_token["token"]["access_token"]))
response = json.loads(response["data"])
"""

if host is None:
base_path = self._repositories_base_path.format(self._host, self._repositories_port)
else:
base_path = self._repositories_base_path.format(host, port)

result = {'error': True, 'data': ''}
headers = {"Content-Type": "application/yaml",
"accept": "application/json" ,
"Authorization": 'Bearer {}'.format(token)}
_endpoint = "{0}/records/vnfr/vnf-instances".format(base_path)

try:
r = requests.get(_endpoint, params=None, verify=False,
headers=headers)
except Exception as e:
result['data'] = str(e)
return result

if r.status_code == requests.codes.ok:
result['error'] = False

result['data'] = r.text
return json.dumps(result)

def get_vnf_instances_vnfinstanceid(self, token, vnfInstanceId ,host=None, port=None):
""" NS Lifecycle Management interface -
Individual VNF instance - *NON ETSI
GET - Read an individual VNF instance resource.
:param token: auth token retrieved by the auth call
:param vnfInstanceId: id of the VNF instance
:param host: host url
:param port: port where the MANO API can be accessed
"""
if host is None:
base_path = self._repositories_base_path.format(self._host, self._repositories_port)
else:
base_path = self._repositories_base_path.format(host, port)
result = {'error': True, 'data': ''}
headers = {"Content-Type": "application/json",
"accept": "application/json",
"Authorization": 'Bearer {}'.format(token)}
_endpoint = "{0}/records/vnfr/vnf-instances/{1}".format(base_path, vnfInstanceId)

try:
r = requests.get(_endpoint, params=None, verify=False,
headers=headers)
except Exception as e:
result['data'] = str(e)
return result
if r.status_code == requests.codes.ok:
result['error'] = False

result['data'] = r.text
return json.dumps(result)


def post_ns_instances_nsinstanceid_instantiate(self, token, nsInstanceId, egresses=[], ingresses=[], host=None, port=None):
""" NS Lifecycle Management interface -
Instantiate NS task
Expand Down

0 comments on commit c72c2c8

Please sign in to comment.