diff options
author | Fu Jinhua <fu.jinhua@zte.com.cn> | 2019-03-25 02:46:55 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-25 02:46:55 +0000 |
commit | f18cf99bda24ee330a1a7fb92235d8f28fc6501a (patch) | |
tree | ae058e41cb1dd0d88dd855d3d73094605bd35d15 | |
parent | 836cd28dbf538568e4e6e8c0ad2ef4c0ec7c6f88 (diff) | |
parent | c1a85aa8898222ab09dc2be5109eca92c45b2a4f (diff) |
Merge "get ns instance"
-rw-r--r-- | lcm/ns/biz/ns_get.py | 11 | ||||
-rw-r--r-- | lcm/ns/const.py | 3 | ||||
-rw-r--r-- | lcm/ns/urls.py | 6 | ||||
-rw-r--r-- | lcm/ns/views/sol/ns_instances_views.py | 8 | ||||
-rw-r--r-- | lcm/pub/config/config.py | 1 |
5 files changed, 23 insertions, 6 deletions
diff --git a/lcm/ns/biz/ns_get.py b/lcm/ns/biz/ns_get.py index 42ab9535..0d1f77c8 100644 --- a/lcm/ns/biz/ns_get.py +++ b/lcm/ns/biz/ns_get.py @@ -11,10 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import json import logging -from lcm.ns.const import OWNER_TYPE +from lcm.ns.const import OWNER_TYPE, NS_INSTANCE_BASE_URI from lcm.pub.utils import restcall from lcm.pub.database.models import NSInstModel, NfInstModel, VLInstModel, CPInstModel, VNFFGInstModel @@ -53,6 +54,14 @@ class GetNSInfoService(object): # todo 'vnffgInfo': self.get_vnffg_infos(ns_inst.id, ns_inst.nsd_model), # todo 'sapInfo':{}, # todo nestedNsInstanceId + '_links': { + 'self': {'href': NS_INSTANCE_BASE_URI % ns_inst.id}, + 'instantiate': {'href': NS_INSTANCE_BASE_URI + '/instantiate' % ns_inst.id}, + 'terminate': {'href': NS_INSTANCE_BASE_URI + '/terminate' % ns_inst.id}, + 'update': {'href': NS_INSTANCE_BASE_URI + '/update' % ns_inst.id}, + 'scale': {'href': NS_INSTANCE_BASE_URI + '/scale' % ns_inst.id}, + 'heal': {'href': NS_INSTANCE_BASE_URI + '/heal' % ns_inst.id} + } } return { 'nsInstanceId': ns_inst.id, diff --git a/lcm/ns/const.py b/lcm/ns/const.py index c5231be7..684c47f7 100644 --- a/lcm/ns/const.py +++ b/lcm/ns/const.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from lcm.pub.utils.enumutil import enum +from lcm.pub.config.config import MSB_BASE_URL OWNER_TYPE = enum(VNF=0, VNFM=1, NS=2) @@ -166,3 +167,5 @@ CHANGE_RESULT = [ CHANGE_RESULTS.ROLLED_BACK, CHANGE_RESULTS.FAILED ] + +NS_INSTANCE_BASE_URI = MSB_BASE_URL + '/api/nslcm/v1/ns_instances/%s' diff --git a/lcm/ns/urls.py b/lcm/ns/urls.py index 86b8ac01..153d5702 100644 --- a/lcm/ns/urls.py +++ b/lcm/ns/urls.py @@ -42,9 +42,9 @@ urlpatterns = [ # SOL005 URL API definition url(r'^api/nslcm/v1/ns_instances$', NSInstancesView.as_view()), - url(r'^api/nslcm/v1/ns_instances$/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/instantiate$', InstantiateNsView.as_view()), - url(r'^api/nslcm/v1/ns_instances$/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/terminate$', TerminateNsView.as_view()), - url(r'^api/nslcm/v1/ns_instances$/(?P<ns_instance_id>[0-9a-zA-Z_-]+)$', IndividualNsInstanceView.as_view()), + url(r'^api/nslcm/v1/ns_instances/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/instantiate$', InstantiateNsView.as_view()), + url(r'^api/nslcm/v1/ns_instances/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/terminate$', TerminateNsView.as_view()), + url(r'^api/nslcm/v1/ns_instances/(?P<ns_instance_id>[0-9a-zA-Z_-]+)$', IndividualNsInstanceView.as_view()), url(r'^api/nslcm/v1/subscriptions$', SubscriptionsView.as_view()), url(r'^api/nslcm/v1/ns_lcm_op_occs$', QueryMultiNsLcmOpOccs.as_view()), url(r'^api/nslcm/v1/ns_lcm_op_occs/(?P<lcmopoccid>[0-9a-zA-Z_-]+)$', QuerySingleNsLcmOpOcc.as_view()), diff --git a/lcm/ns/views/sol/ns_instances_views.py b/lcm/ns/views/sol/ns_instances_views.py index cc832439..324e6f7a 100644 --- a/lcm/ns/views/sol/ns_instances_views.py +++ b/lcm/ns/views/sol/ns_instances_views.py @@ -27,6 +27,7 @@ from lcm.pub.utils.values import ignore_case_get from lcm.ns.biz.ns_create import CreateNSService from lcm.ns.biz.ns_get import GetNSInfoService from lcm.ns.biz.ns_delete import DeleteNsService +from lcm.ns.const import NS_INSTANCE_BASE_URI logger = logging.getLogger(__name__) @@ -84,11 +85,14 @@ class NSInstancesView(APIView): ns_inst_id = CreateNSService(csar_id, ns_name, description, context).do_biz() logger.debug("CreateNSView::post::ret={'nsInstanceId':%s}", ns_inst_id) ns_filter = {"ns_inst_id": ns_inst_id} - nsInstance = GetNSInfoService(ns_filter).get_ns_info(is_sol=True)[0] # todo + nsInstance = GetNSInfoService(ns_filter).get_ns_info(is_sol=True)[0] resp_serializer = NsInstanceSerializer(data=nsInstance) if not resp_serializer.is_valid(): raise NSLCMException(resp_serializer.errors) - return Response(data=resp_serializer.data, status=status.HTTP_201_CREATED) + response = Response(data=resp_serializer.data, status=status.HTTP_201_CREATED) + response["Location"] = NS_INSTANCE_BASE_URI % nsInstance['id'] + return response + except BadRequestException as e: logger.error("Exception in CreateNS: %s", e.message) data = {'status': status.HTTP_400_BAD_REQUEST, 'detail': e.message} diff --git a/lcm/pub/config/config.py b/lcm/pub/config/config.py index 0d47b962..82faaa2c 100644 --- a/lcm/pub/config/config.py +++ b/lcm/pub/config/config.py @@ -15,6 +15,7 @@ # [MSB] MSB_SERVICE_IP = '10.0.14.1' MSB_SERVICE_PORT = '80' +MSB_BASE_URL = "http://%s:%s" % (MSB_SERVICE_IP, MSB_SERVICE_PORT) # [REDIS] REDIS_HOST = '127.0.0.1' |