コード例 #1
0
 def add(self):
     href_params = {
         "id": self.vnf_inst_id,
         "task": self.task,
         "prefix": const.URL_PREFIX
     }
     href = "%(prefix)s/vnf_instances/%(id)s/%(task)s" % href_params
     if href.endswith("/"):
         href = href[:-1]
     VNFLcmOpOccModel(id=self.lcm_op_id,
                      operation_state=const.OPERATION_STATE_TYPE.STARTING,
                      state_entered_time=now_time(),
                      start_time=now_time(),
                      vnf_instance_id=self.vnf_inst_id,
                      grant_id=None,
                      operation=self.operation,
                      is_automatic_invocation=False,
                      operation_params='{}',
                      is_cancel_pending=False,
                      cancel_mode=None,
                      error=None,
                      resource_changes=None,
                      changed_ext_connectivity=None,
                      links=json.dumps({
                          "self": {
                              "href": href
                          },
                          "vnfInstance": {
                              "href": self.vnf_inst_id
                          }
                      })).save()
コード例 #2
0
ファイル: update_vnf.py プロジェクト: lremember/VFC-commit
    def run(self):
        logger.debug("start update for vnf %s", self.nf_inst_id)
        key = "vnfInstanceName"
        try:
            self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.PROCESSING)
            JobUtil.add_job_status(self.job_id, 50, "Start updating VNF.")

            if key in self.data and self.data[key] is not None:
                self.vnf_insts.update(nf_name=self.data[key],
                                      lastuptime=now_time())

            key = "vnfInstanceDescription"
            if key in self.data and self.data[key] is not None:
                self.vnf_insts.update(nf_desc=self.data[key],
                                      lastuptime=now_time())

            key = "vnfPkgId"
            if key in self.data:
                self.vnf_insts.update(vnfdid=self.data[key],
                                      lastuptime=now_time())

            JobUtil.add_job_status(self.job_id, 75,
                                   "Start sending notification.")
            self.send_notification()

            JobUtil.add_job_status(self.job_id, 100, "Update VNF success.")
        except NFLCMException as e:
            logger.error(e.args[0])
            self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, e.args[0])
            JobUtil.add_job_status(self.job_id, 255, e.args[0])
        except Exception as e:
            logger.error(e.args[0])
            logger.error(traceback.format_exc())
            self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, e.args[0])
            JobUtil.add_job_status(self.job_id, 255, e.args[0])
コード例 #3
0
    def do_biz(self):
        logger.debug("CreateVnfIdentifier--CreateVnf::> %s" % self.data)
        is_exist = NfInstModel.objects.filter(
            nf_name=self.vnf_instance_mame).exists()
        logger.debug("check_inst_name_exist::is_exist=%s" % is_exist)
        if is_exist:
            raise NFLCMException('VNF is already exist.')

        nf_inst_id = str(uuid.uuid4())
        try:
            self.package_info = get_packageinfo_by_vnfdid(self.vnfd_id)
            for val in ignore_case_get(self.package_info, "csars"):
                if self.vnfd_id == ignore_case_get(val, "vnfdId"):
                    self.package_id = ignore_case_get(val, "csarId")
                    break

            raw_data = query_rawdata_from_catalog(self.package_id)
            self.vnfd = toscautil.convert_vnfd_model(
                raw_data["rawData"])  # convert to inner json
            self.vnfd = json.JSONDecoder().decode(self.vnfd)

            metadata = ignore_case_get(self.vnfd, "metadata")
            version = ignore_case_get(metadata, "vnfd_version")
            vendor = ignore_case_get(metadata, "vendor")
            netype = ignore_case_get(metadata, "vnf_type")
            vnfsoftwareversion = ignore_case_get(metadata, "version")
            vnfd_model = self.vnfd
            NfInstModel.objects.create(nfinstid=nf_inst_id,
                                       nf_name=self.vnf_instance_mame,
                                       package_id=self.package_id,
                                       version=version,
                                       vendor=vendor,
                                       netype=netype,
                                       vnfd_model=vnfd_model,
                                       status='NOT_INSTANTIATED',
                                       nf_desc=self.description,
                                       vnfdid=self.vnfd_id,
                                       vnfSoftwareVersion=vnfsoftwareversion,
                                       create_time=now_time())
        except:
            NfInstModel.objects.create(nfinstid=nf_inst_id,
                                       nf_name=self.vnf_instance_mame,
                                       package_id='',
                                       version='',
                                       vendor='',
                                       netype='',
                                       vnfd_model='',
                                       status='NOT_INSTANTIATED',
                                       nf_desc=self.description,
                                       vnfdid=self.vnfd_id,
                                       vnfSoftwareVersion='',
                                       create_time=now_time())

        vnf_inst = NfInstModel.objects.get(nfinstid=nf_inst_id)
        logger.debug(
            'id is [%s],name is [%s],vnfd_id is [%s],vnfd_model is [%s],'
            'description is [%s],create_time is [%s]' %
            (vnf_inst.nfinstid, vnf_inst.nf_name, vnf_inst.vnfdid,
             vnf_inst.vnfd_model, vnf_inst.nf_desc, vnf_inst.create_time))
        return nf_inst_id
コード例 #4
0
ファイル: create_vnfs.py プロジェクト: openov2/nfvo
def prepare_create_params():
    nf_inst_id = str(uuid.uuid4())
    NfInstModel(nfinstid=nf_inst_id,
                status=VNF_STATUS.INSTANTIATING,
                create_time=now_time(),
                lastuptime=now_time()).save()
    job_id = JobUtil.create_job(INST_TYPE_NAME.VNF, JOB_TYPE.CREATE_VNF,
                                nf_inst_id)
    JobUtil.add_job_status(job_id, 0, 'create vnf record in database.', 0)
    return nf_inst_id, job_id
コード例 #5
0
 def setUp(self):
     self.client = Client()
     self.nf_inst_id = str(uuid.uuid4())
     NfInstModel(nfinstid=self.nf_inst_id,
                 nf_name='vnf1',
                 vnfm_inst_id='1',
                 vnf_id='vnf_id1',
                 status=VNF_STATUS.ACTIVE,
                 create_time=now_time(),
                 lastuptime=now_time()).save()
コード例 #6
0
def prepare_create_params():
    nf_inst_id = str(uuid.uuid4())
    NfInstModel(nfinstid=nf_inst_id,
                status=VNF_STATUS.INSTANTIATING,
                create_time=now_time(),
                lastuptime=now_time()).save()
    job_id = JobUtil.create_job(JOB_TYPE.VNF, JOB_ACTION.CREATE, nf_inst_id)
    JobUtil.add_job_status(job_id, JOB_PROGRESS.STARTED,
                           'create vnf record in database.',
                           JOB_ERROR_CODE.NO_ERROR)
    return nf_inst_id, job_id
コード例 #7
0
def prepare_notification(nfinstid, jobid, operation, operation_state):
    logger.info('Start to prepare notification')
    notification_content = {
        'id': str(
            uuid.uuid4()
        ),  # shall be the same if sent multiple times due to multiple subscriptions.
        'notificationType': NOTIFY_TYPE.lCM_OP_OCC,
        # set 'subscriptionId' after filtering for subscribers
        'timeStamp': now_time(),
        'notificationStatus': get_notification_status(operation_state),
        'operationState': operation_state,
        'vnfInstanceId': nfinstid,
        'operation': operation,
        'isAutomaticInvocation': False,
        'vnfLcmOpOccId': jobid,
        'affectedVnfcs': [],
        'affectedVirtualLinks': [],
        'affectedVirtualStorages': [],
        'changedExtConnectivity': [],
        'error': None,
        '_links': {
            'vnfInstance': {
                'href': '%s/vnf_instances/%s' % (const.URL_PREFIX, nfinstid)
            },
            'vnfLcmOpOcc': {
                'href': '%s/vnf_lcm_op_occs/%s' % (const.URL_PREFIX, jobid)
            }
        }
    }
    nfInsts = NfInstModel.objects.filter(nfinstid=nfinstid)
    if nfInsts.exists():
        notification_content['vnfmInstId'] = nfInsts[0].vnfminstid
    else:
        notification_content['vnfmInstId'] = "1"
    return notification_content
コード例 #8
0
ファイル: term_vnf.py プロジェクト: openov2/gvnfm-vnflcm
 def lcm_notify(self):
     NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(
         status='NOT_INSTANTIATED', lastuptime=now_time())
     logger.info('[NF termination] send notify request to nfvo end')
     resp = notify_lcm_to_nfvo(json.dumps(self.notify_data))
     logger.info('[NF termination] get lcm response %s' % resp)
     logger.info('[NF termination] send notify request to nfvo end')
コード例 #9
0
 def test_instantiate_vnf_when_already_instantiated(self):
     NfInstModel.objects.create(nfinstid='1111',
                                nf_name='vFW_01',
                                package_id='222',
                                version='',
                                vendor='',
                                netype='',
                                vnfd_model='',
                                status='INSTANTIATED',
                                nf_desc='vFW in Nanjing TIC Edge',
                                vnfdid='111',
                                create_time=now_time())
     self.nf_inst_id = '1111'
     self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
     JobUtil.add_job_status(self.job_id, 0, 'INST_VNF_READY')
     jobs = JobStatusModel.objects.filter(jobid=self.job_id,
                                          progress=0,
                                          descp='INST_VNF_READY')
     self.assertEqual(1, len(jobs))
     data = inst_req_data
     InstantiateVnf(data, nf_inst_id=self.nf_inst_id,
                    job_id=self.job_id).run()
     self.assert_job_result(
         self.job_id, 255,
         'VNF instantiationState is not NOT_INSTANTIATED.')
コード例 #10
0
ファイル: heal_vnf.py プロジェクト: lremember/VFC-commit
 def run(self):
     try:
         self.heal_pre()
         self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.STARTING)
         self.apply_grant()
         self.lcm_op_occ.upd(
             sub_operation=SUB_OPERATION_TASK.GRANTED,
             operation_state=OPERATION_STATE_TYPE.PROCESSING
         )
         self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.PROCESSING)
         self.heal_resource()
         JobUtil.add_job_status(self.job_id, 100, "Heal Vnf success.")
         NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(
             status='INSTANTIATED',
             lastuptime=now_time()
         )
         self.lcm_notify(
             LCM_NOTIFICATION_STATUS.RESULT,
             OPERATION_STATE_TYPE.COMPLETED
         )
         self.lcm_op_occ.upd(
             sub_operation=SUB_OPERATION_TASK.SUCCESS,
             operation_state=OPERATION_STATE_TYPE.COMPLETED
         )
     except NFLCMException as e:
         logger.error(e.args[0])
         self.vnf_heal_failed_handle(e.args[0])
     except Exception as e:
         logger.error(e.args[0])
         logger.error(traceback.format_exc())
         self.vnf_heal_failed_handle(e.args[0])
コード例 #11
0
ファイル: create_vnfs.py プロジェクト: openov2/nfvo
    def send_nf_init_request_to_vnfm(self):
        virtual_link_list, ext_virtual_link = self.get_virtual_link_info(
            self.vnf_id)
        req_param = json.JSONEncoder().encode({
            'vnfInstanceName':
            self.vnf_inst_name,
            'vnfPackageId':
            self.nf_package_info.nfpackageid,
            'vnfDescriptorId':
            self.vnfd_id,
            'extVirtualLink':
            ext_virtual_link,
            'additionalParam': {
                "inputs": self.inputs,
                "vimId": self.vim_id,
                "extVirtualLinks": virtual_link_list
            }
        })
        rsp = send_nf_init_request(self.vnfm_inst_id, req_param)
        self.vnfm_job_id = ignore_case_get(rsp, 'jobId')
        self.vnfm_nf_inst_id = ignore_case_get(rsp, 'vnfInstanceId')

        NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(
            mnfinstid=self.vnfm_nf_inst_id,
            nf_name=self.vnf_inst_name,
            vnf_id=self.vnf_id,
            package_id=self.nf_package_info.nfpackageid,
            vnfm_inst_id=self.vnfm_inst_id,
            ns_inst_id=self.ns_inst_id,
            version=self.nf_package_info.vnfversion,
            vendor=self.nf_package_info.vendor,
            vnfd_model=self.vnfd_model,
            input_params=json.JSONEncoder().encode(self.inputs),
            lastuptime=now_time())
コード例 #12
0
 def vnf_operate_failed_handle(self, error_msg):
     logger.error('VNF Operation failed, detail message: %s' % error_msg)
     NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(
         # status=VNF_STATUS.FAILED,
         lastuptime=now_time())
     self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, error_msg)
     JobUtil.add_job_status(self.job_id, 255, error_msg)
コード例 #13
0
 def test_create_vnf_identifier_when_vnf_is_exist(self):
     NfInstModel.objects.create(
         nfinstid='1111',
         nf_name='vFW_01',
         package_id='222',
         version='',
         vendor='',
         netype='',
         vnfd_model='',
         status='NOT_INSTANTIATED',
         nf_desc='vFW in Nanjing TIC Edge',
         vnfdid='111',
         create_time=now_time()
     )
     data = {
         "vnfdId": "111",
         "vnfInstanceName": "vFW_01",
         "vnfInstanceDescription": "vFW in Nanjing TIC Edge"
     }
     response = self.client.post(
         "/api/vnflcm/v1/vnf_instances",
         data=data,
         format='json'
     )
     self.assertEqual(
         status.HTTP_500_INTERNAL_SERVER_ERROR,
         response.status_code
     )
     context = json.loads(response.content)
     self.assertEqual({
         'detail': 'VNF is already exist.',
         'status': 500
     }, context)
コード例 #14
0
 def run(self):
     try:
         self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.STARTING)
         JobUtil.add_job_status(self.job_id, 10, "Start to apply grant.")
         self.apply_grant()
         self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.PROCESSING)
         JobUtil.add_job_status(self.job_id, 50,
                                "Start to change vnf flavour.")
         self.lcm_op_occ.upd(
             sub_operation=SUB_OPERATION_TASK.GRANTED,
             operation_state=OPERATION_STATE_TYPE.PROCESSING)
         self.do_operation()
         self.vnf_insts.update(status='INSTANTIATED', lastuptime=now_time())
         self.send_notification()
         JobUtil.add_job_status(self.job_id, 100,
                                "Change vnf flavour success.")
         self.lcm_op_occ.upd(sub_operation=SUB_OPERATION_TASK.SUCCESS,
                             operation_state=OPERATION_STATE_TYPE.COMPLETED)
     except NFLCMException as e:
         logger.error(e.args[0])
         self.change_vnf_flavour_failed_handle(e.args[0])
     except Exception as e:
         logger.error(e.args[0])
         logger.error(traceback.format_exc())
         self.change_vnf_flavour_failed_handle(e.args[0])
コード例 #15
0
 def test_instantiate_vnf_when_get_packageinfo_by_csarid_failed(
         self, mock_call_req):
     NfInstModel.objects.create(nfinstid='1111',
                                nf_name='vFW_01',
                                package_id='222',
                                version='',
                                vendor='',
                                netype='',
                                vnfd_model='',
                                status='NOT_INSTANTIATED',
                                nf_desc='vFW in Nanjing TIC Edge',
                                vnfdid='111',
                                create_time=now_time())
     r1_get_vnfpackage_by_vnfdid = [
         1, json.JSONEncoder().encode(vnfpackage_info), '200'
     ]
     mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid]
     self.nf_inst_id = '1111'
     self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
     JobUtil.add_job_status(self.job_id, 0, 'INST_VNF_READY')
     data = inst_req_data
     InstantiateVnf(data, nf_inst_id=self.nf_inst_id,
                    job_id=self.job_id).run()
     self.assert_job_result(self.job_id, 255,
                            'Failed to query vnf CSAR(111) from catalog.')
コード例 #16
0
 def test_instantiate_vnf_when_unexpected_exception(self, mock_call,
                                                    mock_call_req):
     NfInstModel.objects.create(nfinstid='1111',
                                nf_name='vFW_01',
                                package_id='222',
                                version='',
                                vendor='',
                                netype='',
                                vnfd_model='',
                                status='NOT_INSTANTIATED',
                                nf_desc='vFW in Nanjing TIC Edge',
                                vnfdid='111',
                                create_time=now_time())
     r1_get_vnfpackage_by_vnfdid = [
         0, json.JSONEncoder().encode(vnfpackage_info), '200'
     ]
     r2_apply_grant_result = [
         0, json.JSONEncoder().encode(self.grant_result), '200'
     ]
     mock_call_req.side_effect = [
         r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result
     ]
     mock_call.side_effect = [
         c1_data_get_tenant_id, c2_data_create_volume, c3_data_get_volume
     ]
     self.nf_inst_id = '1111'
     self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
     JobUtil.add_job_status(self.job_id, 0, 'INST_VNF_READY')
     data = inst_req_data
     InstantiateVnf(data, nf_inst_id=self.nf_inst_id,
                    job_id=self.job_id).run()
     self.assert_job_result(self.job_id, 255, 'unexpected exception')
コード例 #17
0
 def test_instantiate_operating_conflict(self, mock_call_req):
     NfInstModel.objects.create(nfinstid='1111',
                                nf_name='vFW_01',
                                package_id='222',
                                version='',
                                vendor='',
                                netype='',
                                vnfd_model='',
                                status='NOT_INSTANTIATED',
                                nf_desc='vFW in Nanjing TIC Edge',
                                vnfdid='111',
                                create_time=now_time())
     r1_get_vnfpackage_by_vnfdid = [
         0, json.JSONEncoder().encode(vnfpackage_info), '200'
     ]
     mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid]
     self.nf_inst_id = '1111'
     self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
     JobUtil.add_job_status(self.job_id, 0, 'INST_VNF_READY')
     VNFLcmOpOccModel.objects.create(
         vnf_instance_id=self.nf_inst_id,
         id=self.job_id,
         operation=const.OPERATION_TYPE.INSTANTIATE,
         operation_state=const.OPERATION_STATE_TYPE.PROCESSING)
     response = self.client.post(
         '/api/vnflcm/v1/vnf_instances/1111/instantiate',
         data=inst_req_data,
         format='json')
     self.assertEqual(status.HTTP_409_CONFLICT, response.status_code)
コード例 #18
0
ファイル: create_vnfs.py プロジェクト: openov2/nfvo
 def vnf_inst_failed_handle(self, error_msg):
     logger.error('VNF instantiation failed, detail message: %s' %
                  error_msg)
     NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(
         status=VNF_STATUS.FAILED, lastuptime=now_time())
     JobUtil.add_job_status(
         self.job_id, 255,
         'VNF instantiation failed, detail message: %s' % error_msg, 0)
コード例 #19
0
ファイル: create_vnfs.py プロジェクト: openov2/nfvo
 def save_info_to_db(self):
     logger.debug("save_info_to_db start")
     do_biz_with_share_lock("set-vnflist-in-vnffginst-%s" % self.ns_inst_id,
                            self.save_vnf_inst_id_in_vnffg)
     NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(
         status=VNF_STATUS.ACTIVE, lastuptime=now_time())
     JobUtil.add_job_status(self.job_id, 100, 'vnf instantiation success',
                            0)
     logger.debug("save_info_to_db end")
コード例 #20
0
 def prepareNotificationData(self, status, opState, err=None):
     affected_vnfcs = []
     if status == LCM_NOTIFICATION_STATUS.RESULT and opState == OPERATION_STATE_TYPE.COMPLETED:
         vnfcs = VNFCInstModel.objects.filter(instid=self.nf_inst_id)
         for vnfc in vnfcs:
             vm_resource = {}
             if vnfc.vmid:
                 vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
                 if vm:
                     vm_resource = {
                         'vimConnectionId': vm[0].vimid,
                         'resourceId': vm[0].resourceid,
                         'vimLevelResourceType': 'vm'
                     }
             affected_vnfcs.append({
                 'id': vnfc.vnfcinstanceid,
                 'vduId': vnfc.vduid,
                 'changeType': CHANGE_TYPE.MODIFIED,
                 'computeResource': vm_resource
             })
     notification_content = {
         "id": str(uuid.uuid4()),
         "notificationType": "VnfLcmOperationOccurrenceNotification",
         "subscriptionId": "",
         "timeStamp": now_time(),
         "notificationStatus": status,
         "operationState": opState,
         "vnfInstanceId": self.nf_inst_id,
         "operation": OPERATION_TYPE.OPERATE,
         "isAutomaticInvocation": "false",
         "vnfLcmOpOccId": self.job_id,
         "affectedVnfcs": affected_vnfcs,
         "affectedVirtualLinks": [],
         "affectedVirtualStorages": [],
         "changedInfo": {},
         "changedExtConnectivity": [],
         "_links": {
             "vnfInstance": {
                 "href": ""
             },
             "subscription": {
                 "href": ""
             },
             "vnfLcmOpOcc": {
                 "href": ""
             }
         }
     }
     if opState in (OPERATION_STATE_TYPE.FAILED,
                    OPERATION_STATE_TYPE.FAILED_TEMP):
         notification_content["error"] = {"status": 500, "detail": err}
     notification_content["_links"]["vnfInstance"][
         "href"] = "/vnf_instances/%s" % self.nf_inst_id
     notification_content["_links"]["vnfLcmOpOcc"][
         "href"] = "/vnf_lc_ops/%s" % self.job_id
     return notification_content
コード例 #21
0
 def lcm_notify(self):
     NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(
         status='NOT_INSTANTIATED', lastuptime=now_time())
     logger.info('Send notify request to nfvo')
     try:
         resp = notify_lcm_to_nfvo(json.dumps(self.notify_data))
         logger.info('Lcm notify end, response: %s' % resp)
         NotificationsUtil().send_notification(self.notify_data)
     except Exception as e:
         logger.error("Lcm terminate notify failed: %s", e.args[0])
コード例 #22
0
    def inst_pre(self):
        vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
        if not vnf_insts.exists():
            raise NFLCMException('VNF nf_inst_id is not exist.')

        if vnf_insts[0].status != 'NOT_INSTANTIATED':
            raise NFLCMException('VNF instantiationState is not NOT_INSTANTIATED.')

        JobUtil.add_job_status(self.job_id, 5, 'Get packageinfo by vnfd_id')
        self.vnfd_id = vnf_insts[0].vnfdid
        JobUtil.add_job_status(self.job_id, 10, 'Get vnf package info from catalog by csar_id')
        input_parameters = []
        inputs = ignore_case_get(self.data, "additionalParams")
        if inputs:
            if isinstance(inputs, str):
                inputs = json.loads(inputs)
            for key, val in list(inputs.items()):
                input_parameters.append({"key": key, "value": val})
        vnf_package = query_vnfpackage_by_id(self.vnfd_id)
        pkg_info = ignore_case_get(vnf_package, "packageInfo")
        self.vnfd_info = json.loads(ignore_case_get(pkg_info, "vnfdModel"))
        verifyvnfd.verify(self.vnfd_info)

        self.update_cps()
        metadata = ignore_case_get(self.vnfd_info, "metadata")
        csar_id = ignore_case_get(metadata, "id")
        version = ignore_case_get(metadata, "vnfdVersion")
        vendor = ignore_case_get(metadata, "vendor")
        netype = ignore_case_get(metadata, "type")
        vnfsoftwareversion = ignore_case_get(metadata, "version")
        NfInstModel.objects.filter(nfinstid=self.nf_inst_id).\
            update(package_id=csar_id,
                   flavour_id=ignore_case_get(self.data, "flavourId"),
                   version=version,
                   vendor=vendor,
                   netype=netype,
                   vnfd_model=json.dumps(self.vnfd_info),
                   status='NOT_INSTANTIATED',
                   vnfdid=self.vnfd_id,
                   localizationLanguage=ignore_case_get(self.data, 'localizationLanguage'),
                   input_params=input_parameters,
                   vnfSoftwareVersion=vnfsoftwareversion,
                   lastuptime=now_time())

        logger.info("VimId = %s" % self.vim_id)
        '''
        is_exist = NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id).exists()
        if not is_exist:
            NfvoRegInfoModel.objects.create(
                nfvoid=self.nf_inst_id,
                vnfminstid=ignore_case_get(self.data, "vnfmId"),
                apiurl=self.vim_id)
        '''
        JobUtil.add_job_status(self.job_id, 15, 'Nf instancing pre-check finish')
        logger.info("Nf instancing pre-check finish")
コード例 #23
0
 def change_ext_conn_failed_handle(self, error_msg):
     logger.error('Chnage ext conn failed, detail message: %s', error_msg)
     self.vnf_insts.update(status=VNF_STATUS.FAILED, lastuptime=now_time())
     self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, error_msg)
     JobUtil.add_job_status(self.job_id, 255, error_msg)
     self.lcm_op_occ.upd(sub_operation=SUB_OPERATION_TASK.ERROR,
                         operation_state=OPERATION_STATE_TYPE.FAILED,
                         error={
                             "status": 500,
                             "detail": error_msg
                         })
コード例 #24
0
    def test_heal_vnf_success_reboot(self, mock_call, mock_call_req):
        vim_cache = {}
        res_cache = {}

        NfInstModel.objects.create(nfinstid='1111',
                                   nf_name='2222',
                                   vnfminstid='1',
                                   package_id='todo',
                                   version='',
                                   vendor='',
                                   netype='',
                                   vnfd_model=json.dumps(vnfd_model_dict),
                                   status='INSTANTIATED',
                                   nf_desc='',
                                   vnfdid='',
                                   vnfSoftwareVersion='',
                                   vnfConfigurableProperties='todo',
                                   localizationLanguage='EN_US',
                                   create_time=now_time(),
                                   resInfo=json.dumps(res_cache),
                                   vimInfo=json.dumps(vim_cache))

        VmInstModel.objects.create(vmid="1",
                                   vimid="vimid_1",
                                   resourceid="1",
                                   insttype=0,
                                   instid="1111",
                                   vmname="vduinstname",
                                   is_predefined=1,
                                   tenant="tenantname_1",
                                   operationalstate=1)
        t1_apply_grant_result = [0, json.JSONEncoder().encode(self.grant_result), '200']
        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']
        t3_action_get_vm = [0, json.JSONEncoder().encode(self.getvmResult), '202']
        t4_action_vm_start_reboot = [0, json.JSONEncoder().encode(''), '202']
        mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_get_vm, t4_action_vm_start_reboot]
        mock_call.side_effect = [self.getvmResult, None]
        req_data = {
            "cause": "Error",
            "additionalParams": {
                "action": "vmReset",
                "affectedvm": {
                    "vmid": "1",
                    "vduid": "vdu1Id",
                    "vmname": "vduinstname"
                }
            }
        }
        self.nf_inst_id = '1111'
        self.job_id = JobUtil.create_job('NF', 'HEAL', self.nf_inst_id)
        JobUtil.add_job_status(self.job_id, 0, "HEAL_VNF_READY")
        HealVnf(req_data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
        self.assert_job_result(self.job_id, 100, "Heal Vnf success.")
コード例 #25
0
 def create_ns_inst(self):
     self.ns_inst_id = str(uuid.uuid4())
     logger.debug("CreateNSService::create_ns_inst::ns_inst_id=%s" % self.ns_inst_id)
     NSInstModel(id=self.ns_inst_id,
                 name=self.ns_name,
                 nspackage_id=self.ns_package_id,
                 nsd_id=self.nsd_id,
                 nsd_invariant_id=self.nsd_invariant_id,
                 description=self.description,
                 status='NOT_INSTANTIATED',  # 'empty',
                 lastuptime=now_time(),
                 global_customer_id=self.global_customer_id,
                 service_type=self.service_type).save()
コード例 #26
0
 def setUp(self):
     self.ns_inst_id = str(uuid.uuid4())
     self.job_id = str(uuid.uuid4())
     self.data = {
         'nsInstanceId':
         self.ns_inst_id,
         'additionalParamForNs': {
             "inputs": json.dumps({})
         },
         'additionalParamForVnf': [{
             'vnfprofileid': 'VBras',
             'additionalparam': {
                 'inputs': json.dumps({
                     'vnf_param1': '11',
                     'vnf_param2': '22'
                 }),
                 'vnfminstanceid': "1"
             }
         }],
         'vnfIndex':
         '1'
     }
     self.client = Client()
     NfPackageModel(uuid=str(uuid.uuid4()),
                    nfpackageid='package_id1',
                    vnfdid='zte_vbras',
                    vendor='zte',
                    vnfdversion='1.0.0',
                    vnfversion='1.0.0',
                    vnfdmodel=json.dumps(vnfd_model_dict)).save()
     NSInstModel(id=self.ns_inst_id,
                 name='ns',
                 nspackage_id='1',
                 nsd_id='nsd_id',
                 description='description',
                 status='instantiating',
                 nsd_model=json.dumps(nsd_model_dict),
                 create_time=now_time(),
                 lastuptime=now_time()).save()
コード例 #27
0
    def inst_pre(self):
        vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
        if not vnf_insts.exists():
            raise NFLCMException('VNF nf_inst_id is not exist.')

        if vnf_insts[0].status != 'NOT_INSTANTIATED':
            raise NFLCMException('VNF instantiationState is not NOT_INSTANTIATED.')

        JobUtil.add_job_status(self.job_id, 5, 'Get packageinfo by vnfd_id')
        self.vnfd_id = vnf_insts[0].vnfdid
        package_info = get_packageinfo_by_vnfdid(self.vnfd_id)
        for val in ignore_case_get(package_info, "csars"):
            if self.vnfd_id == ignore_case_get(val, "vnfdId"):
                self.package_id = ignore_case_get(val, "csarId")
                break

        JobUtil.add_job_status(self.job_id, 10, 'Get rawdata from catalog by csar_id')
        input_parameters = []
        inputs = ignore_case_get(self.data['additionalParams'], "inputs")
        if inputs:
            if isinstance(inputs, (str, unicode)):
                inputs = json.loads(inputs)
            for key, val in inputs.items():
                input_parameters.append({"key": key, "value": val})
        raw_data = query_rawdata_from_catalog(self.package_id, input_parameters)
        self.vnfd_info = toscautil.convert_vnfd_model(raw_data["rawData"])  # convert to inner json
        self.vnfd_info = json.JSONDecoder().decode(self.vnfd_info)

        #self.vnfd_info = vnfd_model_dict  # just for test
        self.update_cps()

        self.check_parameter_exist()
        metadata = ignore_case_get(self.vnfd_info, "metadata")
        version = ignore_case_get(metadata, "vnfd_version")
        vendor = ignore_case_get(metadata, "vendor")
        netype = ignore_case_get(metadata, "vnf_type")
        vnfsoftwareversion = ignore_case_get(metadata, "version")
        vnfd_model = self.vnfd_info
        NfInstModel.objects.filter(nfinstid=self.nf_inst_id).\
            update(package_id=self.package_id, flavour_id=ignore_case_get(self.data, "flavourId"), version=version,
                   vendor=vendor, netype=netype, vnfd_model=vnfd_model, status='NOT_INSTANTIATED', vnfdid=self.vnfd_id,
                   localizationLanguage=ignore_case_get(self.data, 'localizationLanguage'), input_params=self.data,
                   vnfSoftwareVersion=vnfsoftwareversion, lastuptime=now_time())

        logger.info("self.vim_id = %s" % self.vim_id)
        NfvoRegInfoModel.objects.create(nfvoid=self.nf_inst_id,
            vnfminstid=ignore_case_get(self.data, "vnfmId"), apiurl=self.vim_id)
        JobUtil.add_job_status(self.job_id, 15, 'Nf instancing pre-check finish')
        logger.info("Nf instancing pre-check finish")
コード例 #28
0
    def apply_grant(self):
        vdus = ignore_case_get(self.vnfd_info, "vdus")
        apply_result = grant_resource(data=self.data,
                                      nf_inst_id=self.nf_inst_id,
                                      job_id=self.job_id,
                                      grant_type=self.grant_type,
                                      vdus=vdus)
        self.set_location(apply_result)

        logger.info('VnfdInfo = %s' % self.vnfd_info)
        NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(
            status='INSTANTIATED',
            lastuptime=now_time()
        )
        JobUtil.add_job_status(self.job_id, 20, 'Nf instancing apply grant finish')
        logger.info("Nf instancing apply grant finish")
コード例 #29
0
 def vnf_inst_failed_handle(self, error_msg):
     logger.error('VNF instantiation failed, detail message: %s' % error_msg)
     NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(
         status='NOT_INSTANTIATED',
         lastuptime=now_time()
     )
     self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, error_msg)
     JobUtil.add_job_status(self.job_id, 255, error_msg)
     self.lcm_op_occ.upd(
         sub_operation=SUB_OPERATION_TASK.ERROR,
         operation_state=OPERATION_STATE_TYPE.FAILED,
         error={
             "status": 500,
             "detail": error_msg
         }
     )
コード例 #30
0
    def test_heal_vnf_success_start(self, mock_call, mock_call_req):
        vim_cache = {}
        res_cache = {"volume": {}, "flavor": {}, "port": {}}
        res_cache["volume"]["volume_storage1"] = "vol1"
        res_cache["flavor"]["vdu1Id"] = "flavor1"
        res_cache["port"]["cpId1"] = "port1"

        NfInstModel.objects.create(nfinstid='1111',
                                   nf_name='2222',
                                   vnfminstid='1',
                                   package_id='todo',
                                   version='',
                                   vendor='',
                                   netype='',
                                   vnfd_model=json.dumps(vnfd_model_dict),
                                   status='INSTANTIATED',
                                   nf_desc='',
                                   vnfdid='',
                                   vnfSoftwareVersion='',
                                   vnfConfigurableProperties='todo',
                                   localizationLanguage='EN_US',
                                   resInfo=json.dumps(res_cache),
                                   vimInfo=json.dumps(vim_cache),
                                   create_time=now_time())

        t1_apply_grant_result = [0, json.JSONEncoder().encode(self.grant_result), '200']
        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']
        t3_action_vm_start_create = [0, json.JSONEncoder().encode(''), '202']
        mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_start_create]
        mock_call.side_effect = [c1_data_get_tenant_id_1, c9_data_create_vm, c10_data_get_vm]
        req_data = {
            "cause": "Error",
            "additionalParams": {
                "action": "vmCreate",
                "affectedvm": {
                    "vmid": "1",
                    "vduid": "vdu1Id",
                    "vmname": "vduinstname"
                }
            }
        }
        self.nf_inst_id = '1111'
        self.job_id = JobUtil.create_job('NF', 'HEAL', self.nf_inst_id)
        JobUtil.add_job_status(self.job_id, 0, "HEAL_VNF_READY")
        HealVnf(req_data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
        self.assert_job_result(self.job_id, 100, "Heal Vnf success.")