Updated vnflcm api output with host-path

Currently vnflcm api operations do not return host-path
in their output inside '_links' href field.
For ex,
"_links": {
"self": {
"href":
    "/vnflcm/v1/vnf_instances/<vnf-instance>"
}
}

This patch updates '_links' href field in vnflcm api output
with host-path.
For ex,
"_links": {
"self": {
"href":
    "http://localhost:9890/vnflcm/v1/vnf_instances/<vnf-instance>"
}
}

*here "http://localhost:9890/" is just an example of host-path.

Related operations:
1. Creates a new VNF instance.
2. Show VNF Instance.
3. List VNF Instances.
4. Show VNF LCM operation occurrence.
5. List VNF LCM operation occurrences.

Co-Authored-By: Navum Gupta <navum.gupta@india.nec.com>

Closes-Bug: #1923360
Change-Id: I245cd2626fac1112d6a9fef3c51bf5ef6b679e05
This commit is contained in:
Sheel Rana 2021-04-04 22:26:47 +05:30
parent c137b0ddfe
commit 2c68a0a84d
5 changed files with 121 additions and 79 deletions

View File

@ -35,7 +35,10 @@ class ViewBuilder(base.BaseViewBuilder):
def _get_links(self, vnf_instance): def _get_links(self, vnf_instance):
links = { links = {
"self": { "self": {
"href": '/vnflcm/v1/vnf_instances/%s' % vnf_instance.id "href":
'{endpoint}/vnflcm/v1/vnf_instances/{id}'.format(
endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_instance.id)
} }
} }
@ -43,8 +46,10 @@ class ViewBuilder(base.BaseViewBuilder):
fields.VnfInstanceState.NOT_INSTANTIATED): fields.VnfInstanceState.NOT_INSTANTIATED):
instantiate_link = { instantiate_link = {
"instantiate": { "instantiate": {
"href": '/vnflcm/v1/vnf_instances/%s/instantiate' "href":
% vnf_instance.id '{endpoint}/vnflcm/v1/vnf_instances/{id}/instantiate'
.format(endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_instance.id)
} }
} }
@ -54,16 +59,22 @@ class ViewBuilder(base.BaseViewBuilder):
fields.VnfInstanceState.INSTANTIATED): fields.VnfInstanceState.INSTANTIATED):
instantiated_state_links = { instantiated_state_links = {
"terminate": { "terminate": {
"href": '/vnflcm/v1/vnf_instances/%s/terminate' "href":
% vnf_instance.id '{endpoint}/vnflcm/v1/vnf_instances/{id}/terminate'
.format(endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_instance.id)
}, },
"heal": { "heal": {
"href": '/vnflcm/v1/vnf_instances/%s/heal' "href":
% vnf_instance.id '{endpoint}/vnflcm/v1/vnf_instances/{id}/heal'
.format(endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_instance.id)
}, },
"changeExtConn": { "changeExtConn": {
"href": '/vnflcm/v1/vnf_instances/%s/change_ext_conn' "href":
% vnf_instance.id '{endpoint}/vnflcm/v1/vnf_instances/{id}/change_ext_conn'
.format(endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_instance.id)
} }
} }
@ -98,37 +109,40 @@ class ViewBuilder(base.BaseViewBuilder):
def _get_lcm_op_occs_links(self, vnf_lcm_op_occs): def _get_lcm_op_occs_links(self, vnf_lcm_op_occs):
_links = { _links = {
"self": { "self": {
"href": '%(endpoint)s/vnflcm/v1/vnf_lcm_op_occs/%(id)s' "href":
% {"endpoint": CONF.vnf_lcm.endpoint_url, '{endpoint}/vnflcm/v1/vnf_lcm_op_occs/{id}'.format(
"id": vnf_lcm_op_occs.id} endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_lcm_op_occs.id)
}, },
"vnfInstance": { "vnfInstance": {
"href": '%(endpoint)s/vnflcm/v1/vnf_instances/%(id)s' "href":
% {"endpoint": CONF.vnf_lcm.endpoint_url, '{endpoint}/vnflcm/v1/vnf_instances/{id}'.format(
"id": vnf_lcm_op_occs.vnf_instance_id} endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_lcm_op_occs.vnf_instance_id)
}, },
"retry": { "retry": {
"href": "href":
'%(endpoint)s/vnflcm/v1/vnf_lcm_op_occs/%(id)s/retry' '{endpoint}/vnflcm/v1/vnf_lcm_op_occs/{id}/retry'.format(
% {"endpoint": CONF.vnf_lcm.endpoint_url, endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
"id": vnf_lcm_op_occs.id} id=vnf_lcm_op_occs.id)
}, },
"rollback": { "rollback": {
"href": "href":
'%(endpoint)s/vnflcm/v1/vnf_lcm_op_occs/%(id)s/rollback' '{endpoint}/vnflcm/v1/vnf_lcm_op_occs/{id}/rollback'.format(
% {"endpoint": CONF.vnf_lcm.endpoint_url, endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
"id": vnf_lcm_op_occs.id} id=vnf_lcm_op_occs.id)
}, },
"grant": { "grant": {
"href": '%(endpoint)s/vnflcm/v1/vnf_lcm_op_occs/%(id)s/grant' "href":
% {"endpoint": CONF.vnf_lcm.endpoint_url, '{endpoint}/vnflcm/v1/vnf_lcm_op_occs/{id}/grant'.format(
"id": vnf_lcm_op_occs.id} endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_lcm_op_occs.id)
}, },
"fail": { "fail": {
"href": "href":
'%(endpoint)s/vnflcm/v1/vnf_lcm_op_occs/%(id)s/fail' '{endpoint}/vnflcm/v1/vnf_lcm_op_occs/{id}/fail'.format(
% {"endpoint": CONF.vnf_lcm.endpoint_url, endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
"id": vnf_lcm_op_occs.id} id=vnf_lcm_op_occs.id)
} }
} }
@ -178,10 +192,10 @@ class ViewBuilder(base.BaseViewBuilder):
return { return {
"_links": { "_links": {
"self": { "self": {
"href": '%(endpoint)s/vnflcm/v1/subscriptions/%(id)s' % "href":
{ '{endpoint}/vnflcm/v1/subscriptions/{id}'.format(
"endpoint": CONF.vnf_lcm.endpoint_url, endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
"id": decode_id}}}} id=decode_id)}}}
def _basic_subscription_info(self, vnf_lcm_subscription, filter=None): def _basic_subscription_info(self, vnf_lcm_subscription, filter=None):
if not filter: if not filter:

View File

@ -32,37 +32,44 @@ class ViewBuilder(base.BaseViewBuilder):
def _get_lcm_op_occs_links(self, vnf_lcm_op_occs): def _get_lcm_op_occs_links(self, vnf_lcm_op_occs):
_links = { _links = {
"self": { "self": {
"href": '%(endpoint)s/vnflcm/v1/vnf_lcm_op_occs/%(id)s' "href":
% {"endpoint": CONF.vnf_lcm.endpoint_url, '{endpoint}/vnflcm/v1/vnf_lcm_op_occs/{id}'.format(
"id": vnf_lcm_op_occs.id} endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_lcm_op_occs.id)
}, },
"vnfInstance": { "vnfInstance": {
"href": '%(endpoint)s/vnflcm/v1/vnf_instances/%(id)s' "href":
% {"endpoint": CONF.vnf_lcm.endpoint_url, '{endpoint}/vnflcm/v1/vnf_instances/{id}'.format(
"id": vnf_lcm_op_occs.vnf_instance_id} endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_lcm_op_occs.vnf_instance_id)
}, },
"retry": { "retry": {
"href": "href":
'%(endpoint)s/vnflcm/v1/vnf_lcm_op_occs/%(id)s/retry' '{endpoint}/vnflcm/v1/vnf_lcm_op_occs/{id}/retry'.
% {"endpoint": CONF.vnf_lcm.endpoint_url, format(
"id": vnf_lcm_op_occs.id} endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_lcm_op_occs.id)
}, },
"rollback": { "rollback": {
"href": "href":
'%(endpoint)s/vnflcm/v1/vnf_lcm_op_occs/%(id)s/rollback' '{endpoint}/vnflcm/v1/vnf_lcm_op_occs/{id}/rollback'.
% {"endpoint": CONF.vnf_lcm.endpoint_url, format(
"id": vnf_lcm_op_occs.id} endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_lcm_op_occs.id)
}, },
"grant": { "grant": {
"href": '%(endpoint)s/vnflcm/v1/vnf_lcm_op_occs/%(id)s/grant' "href":
% {"endpoint": CONF.vnf_lcm.endpoint_url, '{endpoint}/vnflcm/v1/vnf_lcm_op_occs/{id}/grant'.
"id": vnf_lcm_op_occs.id} format(
endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_lcm_op_occs.id)
}, },
"fail": { "fail": {
"href": "href":
'%(endpoint)s/vnflcm/v1/vnf_lcm_op_occs/%(id)s/fail' '{endpoint}/vnflcm/v1/vnf_lcm_op_occs/{id}/fail'.
% {"endpoint": CONF.vnf_lcm.endpoint_url, format(
"id": vnf_lcm_op_occs.id} endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_lcm_op_occs.id)
} }
} }

View File

@ -919,7 +919,7 @@ class VnfLcmController(wsgi.Controller):
# make response # make response
res = webob.Response(content_type='application/json') res = webob.Response(content_type='application/json')
res.status_int = 202 res.status_int = 202
loc_url = CONF.vnf_lcm.endpoint_url + \ loc_url = CONF.vnf_lcm.endpoint_url.rstrip("/") + \
'/vnflcm/v1/vnf_lcm_op_occs/' + op_occs_uuid '/vnflcm/v1/vnf_lcm_op_occs/' + op_occs_uuid
location = ('Location', loc_url) location = ('Location', loc_url)
res.headerlist.append(location) res.headerlist.append(location)
@ -966,7 +966,7 @@ class VnfLcmController(wsgi.Controller):
"See Other", 303, title='See Other') "See Other", 303, title='See Other')
link = ( link = (
'LINK', 'LINK',
CONF.vnf_lcm.endpoint_url + CONF.vnf_lcm.endpoint_url.rstrip("/") +
"/vnflcm/v1/subscriptions/" + "/vnflcm/v1/subscriptions/" +
str(e)[ str(e)[
3:]) 3:])
@ -1242,9 +1242,9 @@ class VnfLcmController(wsgi.Controller):
vnf_instance.task_state = fields.VnfInstanceTaskState.SCALING vnf_instance.task_state = fields.VnfInstanceTaskState.SCALING
vnf_instance.save() vnf_instance.save()
vnflcm_url = CONF.vnf_lcm.endpoint_url + \ vnflcm_url = CONF.vnf_lcm.endpoint_url.rstrip("/") + \
"/vnflcm/v1/vnf_lcm_op_occs/" + vnf_lcm_op_occs_id "/vnflcm/v1/vnf_lcm_op_occs/" + vnf_lcm_op_occs_id
insta_url = CONF.vnf_lcm.endpoint_url + \ insta_url = CONF.vnf_lcm.endpoint_url.rstrip("/") + \
"/vnflcm/v1/vnf_instances/" + inst_vnf_info.vnf_instance_id "/vnflcm/v1/vnf_instances/" + inst_vnf_info.vnf_instance_id
vnf_info['vnflcm_id'] = vnf_lcm_op_occs_id vnf_info['vnflcm_id'] = vnf_lcm_op_occs_id
@ -1324,7 +1324,7 @@ class VnfLcmController(wsgi.Controller):
operation_params) operation_params)
vnf_info['vnf_lcm_op_occ'] = vnf_lcm_op_occs vnf_info['vnf_lcm_op_occ'] = vnf_lcm_op_occs
vnflcm_url = CONF.vnf_lcm.endpoint_url + \ vnflcm_url = CONF.vnf_lcm.endpoint_url.rstrip("/") + \
"/vnflcm/v1/vnf_lcm_op_occs/" + vnf_lcm_op_occs.id "/vnflcm/v1/vnf_lcm_op_occs/" + vnf_lcm_op_occs.id
res = webob.Response() res = webob.Response()
res.status_int = 202 res.status_int = 202

View File

@ -320,10 +320,14 @@ class Conductor(manager.Manager):
self._basic_config_check() self._basic_config_check()
def _get_vnf_instance_href(self, vnf_instance_id): def _get_vnf_instance_href(self, vnf_instance_id):
return '/vnflcm/v1/vnf_instances/%s' % vnf_instance_id return '{endpoint}/vnflcm/v1/vnf_instances/{id}'.format(
endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_instance_id)
def _get_vnf_lcm_op_occs_href(self, vnf_lcm_op_occs_id): def _get_vnf_lcm_op_occs_href(self, vnf_lcm_op_occs_id):
return '/vnflcm/v1/vnf_lcm_op_occs/%s' % vnf_lcm_op_occs_id return '{endpoint}/vnflcm/v1/vnf_lcm_op_occs/{id}'.format(
endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_lcm_op_occs_id)
def _basic_config_check(self): def _basic_config_check(self):
if not os.path.isdir(CONF.vnf_package.vnf_package_csar_path): if not os.path.isdir(CONF.vnf_package.vnf_package_csar_path):

View File

@ -228,14 +228,22 @@ def return_vnf_instance(
def _instantiated_vnf_links(vnf_instance_id): def _instantiated_vnf_links(vnf_instance_id):
links = { links = {
"self": {"href": "/vnflcm/v1/vnf_instances/%s" % vnf_instance_id}, "self": {"href":
"terminate": {"href": "/vnflcm/v1/vnf_instances/%s/terminate" % '{endpoint}/vnflcm/v1/vnf_instances/{id}'.format(
vnf_instance_id}, endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
"heal": {"href": "/vnflcm/v1/vnf_instances/%s/heal" % id=vnf_instance_id)},
vnf_instance_id}, "terminate": {"href":
'{endpoint}/vnflcm/v1/vnf_instances/{id}/terminate'.format(
endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_instance_id)},
"heal": {"href":
'{endpoint}/vnflcm/v1/vnf_instances/{id}/heal'.format(
endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_instance_id)},
"changeExtConn": {"href": "changeExtConn": {"href":
"/vnflcm/v1/vnf_instances/%s/change_ext_conn" % '{endpoint}/vnflcm/v1/vnf_instances/{id}/change_ext_conn'
vnf_instance_id}} .format(endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=vnf_instance_id)}}
return links return links
@ -248,14 +256,16 @@ def _fake_vnf_instance_not_instantiated_response(
'vnfProductName': 'Sample VNF', 'vnfProductName': 'Sample VNF',
'_links': { '_links': {
'self': { 'self': {
'href': os.path.join( "href":
'/vnflcm/v1/vnf_instances/', '{endpoint}/vnflcm/v1/vnf_instances/{id}'.format(
uuidsentinel.vnf_instance_id)}, endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
id=uuidsentinel.vnf_instance_id)},
'instantiate': { 'instantiate': {
'href': os.path.join( "href":
'/vnflcm/v1/vnf_instances', '{endpoint}/vnflcm/v1/vnf_instances/{id}/{op}'.format(
uuidsentinel.vnf_instance_id, endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"),
'instantiate')}}, id=uuidsentinel.vnf_instance_id,
op='instantiate')}},
'instantiationState': 'NOT_INSTANTIATED', 'instantiationState': 'NOT_INSTANTIATED',
'vnfProvider': 'Vnf provider', 'vnfProvider': 'Vnf provider',
'vnfdId': uuidsentinel.vnfd_id, 'vnfdId': uuidsentinel.vnfd_id,
@ -1322,27 +1332,33 @@ def wsgi_app_v1(fake_auth_context=None):
VNFLCMOPOCC_RESPONSE = { VNFLCMOPOCC_RESPONSE = {
'_links': { '_links': {
"self": { "self": {
"href": CONF.vnf_lcm.endpoint_url + '/vnflcm/v1/vnf_lcm_op_occs/' "href": CONF.vnf_lcm.endpoint_url.rstrip("/") +
'/vnflcm/v1/vnf_lcm_op_occs/'
'f26f181d-7891-4720-b022-b074ec1733ef' 'f26f181d-7891-4720-b022-b074ec1733ef'
}, },
"vnfInstance": { "vnfInstance": {
"href": CONF.vnf_lcm.endpoint_url + '/vnflcm/v1/vnf_instances/' "href": CONF.vnf_lcm.endpoint_url.rstrip("/") +
'/vnflcm/v1/vnf_instances/'
'f26f181d-7891-4720-b022-b074ec1733ef' 'f26f181d-7891-4720-b022-b074ec1733ef'
}, },
"retry": { "retry": {
"href": CONF.vnf_lcm.endpoint_url + '/vnflcm/v1/vnf_lcm_op_occs/' "href": CONF.vnf_lcm.endpoint_url.rstrip("/") +
'/vnflcm/v1/vnf_lcm_op_occs/'
'f26f181d-7891-4720-b022-b074ec1733ef/retry' 'f26f181d-7891-4720-b022-b074ec1733ef/retry'
}, },
"rollback": { "rollback": {
"href": CONF.vnf_lcm.endpoint_url + '/vnflcm/v1/vnf_lcm_op_occs/' "href": CONF.vnf_lcm.endpoint_url.rstrip("/") +
'/vnflcm/v1/vnf_lcm_op_occs/'
'f26f181d-7891-4720-b022-b074ec1733ef/rollback' 'f26f181d-7891-4720-b022-b074ec1733ef/rollback'
}, },
"grant": { "grant": {
"href": CONF.vnf_lcm.endpoint_url + '/vnflcm/v1/vnf_lcm_op_occs/' "href": CONF.vnf_lcm.endpoint_url.rstrip("/") +
'/vnflcm/v1/vnf_lcm_op_occs/'
'f26f181d-7891-4720-b022-b074ec1733ef/grant', 'f26f181d-7891-4720-b022-b074ec1733ef/grant',
}, },
"fail": { "fail": {
"href": CONF.vnf_lcm.endpoint_url + '/vnflcm/v1/vnf_lcm_op_occs/' "href": CONF.vnf_lcm.endpoint_url.rstrip("/") +
'/vnflcm/v1/vnf_lcm_op_occs/'
'f26f181d-7891-4720-b022-b074ec1733ef/fail'}}, 'f26f181d-7891-4720-b022-b074ec1733ef/fail'}},
'operationState': 'COMPLETED', 'operationState': 'COMPLETED',
'stateEnteredTime': datetime.datetime(1900, 1, 1, 1, 1, 1, 'stateEnteredTime': datetime.datetime(1900, 1, 1, 1, 1, 1,
@ -1737,9 +1753,10 @@ def _subscription_links(subscription_dict):
links = { links = {
"_links": { "_links": {
"self": { "self": {
"href": "%(endpoint)s/vnflcm/v1/subscriptions/%(id)s" "href":
% {'id': subscription_dict['id'], "{endpoint}/vnflcm/v1/subscriptions/{id}".format(
'endpoint': CONF.vnf_lcm.endpoint_url} id=subscription_dict['id'],
endpoint=CONF.vnf_lcm.endpoint_url.rstrip("/"))
} }
} }
} }