get ns instance 24/83124/2
authormaopengzhang <zhang.maopeng1@zte.com.cn>
Mon, 25 Mar 2019 01:23:39 +0000 (09:23 +0800)
committermaopengzhang <zhang.maopeng1@zte.com.cn>
Mon, 25 Mar 2019 01:49:24 +0000 (09:49 +0800)
add ns instance url

Change-Id: I03495c71ea0403c15322cb314a2202bd496ffdbc
Issue-ID: VFC-1213
Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
lcm/ns/biz/ns_get.py
lcm/ns/const.py
lcm/ns/urls.py
lcm/ns/views/sol/ns_instances_views.py
lcm/pub/config/config.py

index 42ab953..0d1f77c 100644 (file)
 # 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,
index c5231be..684c47f 100644 (file)
@@ -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'
index 86b8ac0..153d570 100644 (file)
@@ -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()),
index cc83243..324e6f7 100644 (file)
@@ -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}
index 0d47b96..82faaa2 100644 (file)
@@ -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'