Пример #1
0
 def delete_resource(self, result):
     logger.debug("terminate_type=%s, result=%s", self.terminate_type,
                  result)
     if result[0] == 0:
         job_info = json.JSONDecoder().decode(result[1])
         vnfm_job_id = ignore_case_get(job_info, "jobid")
         self.add_progress(5, "SEND_TERMINATE_REQ_SUCCESS")
         if self.terminate_type == 'forceful':
             ret = wait_job_finish(
                 self.vnfm_inst_id,
                 self.job_id,
                 vnfm_job_id,
                 progress_range=[10, 50],
                 timeout=self.terminate_timeout,
                 job_callback=TerminateNsService.wait_job_mode_callback,
                 mode='1')
             if ret != JOB_MODEL_STATUS.FINISHED:
                 logger.error('[NS terminate] VNFM terminate ns failed')
                 NSInstModel.objects.filter(id=self.ns_inst_id).update(
                     status='FAILED')
                 raise NSLCMException("DELETE_NS_RESOURCE_FAILED")
     else:
         logger.error('[NS terminate] VNFM terminate ns failed')
         NSInstModel.objects.filter(id=self.ns_inst_id).update(
             status='FAILED')
         raise NSLCMException("DELETE_NS_RESOURCE_FAILED")
Пример #2
0
    def get_and_check_params(self):
        nf_info = NfInstModel.objects.filter(nfinstid=self.vnf_instance_id)
        if not nf_info:
            raise NSLCMException('NF instance[id=%s] does not exist' %
                                 self.vnf_instance_id)
        logger.debug('vnfd_model = %s, vnf_instance_id = %s' %
                     (nf_info[0].vnfd_model, self.vnf_instance_id))
        nf_model = nf_info[0].vnfd_model
        self.m_nf_inst_id = nf_info[0].mnfinstid
        self.vnfm_inst_id = nf_info[0].vnfm_inst_id
        scale_vnf_data = ignore_case_get(self.data, 'scaleVnfData')
        if not scale_vnf_data:
            raise NSLCMException('scaleVnfData parameter does not exist')

        self.nf_scale_params.append({
            'type':
            ignore_case_get(scale_vnf_data, 'type'),
            'aspectId':
            ignore_case_get(scale_vnf_data, 'aspectId'),
            'numberOfSteps':
            ignore_case_get(scale_vnf_data, 'numberOfSteps'),
            'additionalParam': {
                'vnfdModel': nf_model
            }
        })
Пример #3
0
    def prepare_update_params(vnf_data):
        vnf_instance_id = ignore_case_get(vnf_data, 'vnfInstanceId')
        if not vnf_instance_id:
            raise NSLCMException(
                'VnfInstanceId does not exist or value is incorrect.')

        change_state_to = ignore_case_get(vnf_data, 'changeStateTo')
        if not change_state_to:
            raise NSLCMException(
                'ChangeStateTo does not exist or value is incorrect.')
        graceful_stop_timeout = ''
        operational_states = ignore_case_get(change_state_to,
                                             'OperationalStates')
        if operational_states == OPERATIONAL_STATE.STOPPED:
            stop_type = ignore_case_get(vnf_data, 'stopType')
            if stop_type == STOP_TYPE.GRACEFUL:
                graceful_stop_timeout = ignore_case_get(
                    vnf_data, 'gracefulStopTimeout')

        result = {
            "vnfInstanceId":
            vnf_instance_id,
            "changeStateTo":
            operational_states,
            "stopType":
            stop_type,
            "gracefulStopTimeout":
            graceful_stop_timeout if graceful_stop_timeout else 0
        }
        return result
Пример #4
0
 def get_and_check_params(self):
     nf_info = NfInstModel.objects.filter(nfinstid=self.vnf_instance_id)
     if not nf_info:
         logger.error('NF instance[id=%s] does not exist' %
                      self.vnf_instance_id)
         raise NSLCMException('NF instance[id=%s] does not exist' %
                              self.vnf_instance_id)
     logger.debug('vnfd_model = %s, vnf_instance_id = %s' %
                  (nf_info[0].vnfd_model, self.vnf_instance_id))
     self.nf_model = json.loads(nf_info[0].vnfd_model)
     self.m_nf_inst_id = nf_info[0].mnfinstid
     self.vnfm_inst_id = nf_info[0].vnfm_inst_id
     self.scale_vnf_data = ignore_case_get(self.data, 'scaleVnfData')
     if not self.scale_vnf_data:
         logger.error(
             'scaleVnfData parameter does not exist or value incorrect')
         raise NSLCMException(
             'scaleVnfData parameter does not exist or value incorrect')
     for vnf_data in self.scale_vnf_data:
         scale_type = ignore_case_get(vnf_data, 'type')
         aspect_id = ignore_case_get(vnf_data, 'aspectId')
         number_of_steps = ignore_case_get(vnf_data, 'numberOfSteps')
         self.nf_scale_params.append({
             'type': scale_type,
             'aspectId': aspect_id,
             'numberOfSteps': number_of_steps,
             'additionalParam': {
                 'vnfdModel': self.nf_model
             }
         })
Пример #5
0
    def send_grant_vnf_to_resMgr(self):
        logger.debug("grant data from vnfm:%s", self.data)
        if isinstance(self.data, (unicode, str)):
            self.data = json.JSONDecoder().decode(self.data)
        has_res_tpl = False
        grant_type = None
        if ignore_case_get(self.data, "addResource"):
            grant_type = "addResource"
        elif ignore_case_get(self.data, "removeResource"):
            grant_type = "removeResource"
        else:
            #raise NSLCMException("No grant resource is found.")
            has_res_tpl = True

        for res in ignore_case_get(self.data, grant_type):
            if "resourceTemplate" in res:
                has_res_tpl = True
                break

        if not has_res_tpl:
            m_vnf_inst_id = ignore_case_get(self.data, "vnfInstanceId")
            additional_param = ignore_case_get(self.data, "additionalparam")
            vnfm_inst_id = ignore_case_get(additional_param, "vnfmid")
            vim_id = ignore_case_get(additional_param, "vimid")

            vnfinsts = NfInstModel.objects.filter(
                mnfinstid=m_vnf_inst_id, vnfm_inst_id=vnfm_inst_id)
            if not vnfinsts:
                raise NSLCMException("Vnfinst(%s) is not found in vnfm(%s)" % (
                    m_vnf_inst_id, vnfm_inst_id))
                
            vnf_pkg_id = vnfinsts[0].package_id
            vnf_pkgs = NfPackageModel.objects.filter(nfpackageid=vnf_pkg_id)
            if not vnf_pkgs:
                raise NSLCMException("vnfpkg(%s) is not found" % vnf_pkg_id)

            vnfd = json.JSONDecoder().decode(vnf_pkgs[0].vnfdmodel)

            req_param = {
                "vnfInstanceId": m_vnf_inst_id, 
                "vimId": vim_id, 
                "additionalParam": additional_param,
                grant_type: []
            }
            for res in ignore_case_get(self.data, grant_type):
                vdu_name = ignore_case_get(res, "vdu")
                grant_res = {
                    "resourceDefinitionId": ignore_case_get(res, "resourceDefinitionId"),
                    "type": ignore_case_get(res,"type"),
                    "vdu": vdu_name
                }
                for vdu in vnfd["vdus"]:
                    if vdu_name in (vdu["vdu_id"], vdu["properties"].get("name", "")):
                        grant_res["resourceTemplate"] = self.get_res_tpl(vdu, vnfd)
                        break
                req_param[grant_type].append(grant_res)
            self.data = req_param
        return resmgr.grant_vnf(self.data)
Пример #6
0
 def check_nf_valid(self):
     vnf_inst = NfInstModel.objects.filter(nfinstid=self.vnf_inst_id)
     if not vnf_inst.exists():
         logger.warning('[VNF terminate] Vnf instance [%s] is not exist.' % self.vnf_inst_id)
         raise NSLCMException('[VNF terminate] Vnf instance is not exist.')
     if not vnf_inst:
         self.add_progress(100, "TERM_VNF_NOT_EXIST_SUCCESS", "finished")
         raise NSLCMException('[VNF terminate] Vnf instance is not exist.')
     self.set_vnf_status(vnf_inst[0])
Пример #7
0
def get_process_id(name, srv_template_id):
    ret = req_by_msb('/openoapi/catalog/v1/servicetemplates/%s/operations' % srv_template_id, 'GET')
    if ret[0] != 0:
        raise NSLCMException('Failed to get service[%s,%s] process id' % (name, srv_template_id))
    items = json.JSONDecoder().decode(ret[1])
    for item in items:
        if name in item['name']:
            return item['processId']
    raise NSLCMException('service[%s,%s] process id not exist' % (name, srv_template_id))
Пример #8
0
def query_csar_from_catalog(csar_id, key=''):
    ret = req_by_msb("/openoapi/catalog/v1/csars/%s" % csar_id, "GET")
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        if ret[2] == '404':
            raise NSLCMException("CSAR(%s) does not exist." % csar_id)
        raise NSLCMException("Failed to query CSAR(%s) from catalog." % csar_id)
    csar_info = json.JSONDecoder().decode(ret[1])
    return ignore_case_get(csar_info, key) if key else csar_info
Пример #9
0
def get_servicetemplate(nsd_id):
    ret = req_by_msb('/openoapi/catalog/v1/servicetemplates', 'GET')
    if ret[0] != 0:
        raise NSLCMException('Failed to get servicetemplates info')
    stpls = json.JSONDecoder().decode(ret[1])
    for stpl in stpls:
        if stpl.get("id", "") == nsd_id:
            return stpl
    return NSLCMException('servicetemplate(%s) does not exist.' % nsd_id)
Пример #10
0
    def set_state_csar(self, csar_id, operation):
        if not NSDModel.objects.filter(id=csar_id):
            raise NSLCMException("CSAR(%s) does not exist." % csar_id)

        csar = query_csar_from_catalog(csar_id)
        if ignore_case_get(csar, "operationalState") == operation.capitalize():
            raise NSLCMException("CSAR(%s) already %s." % (csar_id, operation))
        return set_csar_state(csar_id, 'operationState',
                              operation.capitalize())
Пример #11
0
def confirm_sfc_status(sfc_inst_id):
    uri = "api/nslcm/v1/ns/sfcs/{sfcInstId}".format(sfcInstId=sfc_inst_id)
    ret = restcall.req_by_msb(uri, "GET")
    if ret[0] != 0:
        raise NSLCMException("Failed to call get_sfc(%s)" % sfc_inst_id)
    ret[1] = json.JSONDecoder().decode(ret[1])

    sfc_status = ret[1]["sfcStatus"]
    if sfc_status != "active":
        raise NSLCMException("Status of SFC(%s) is not active" % sfc_inst_id)
Пример #12
0
    def get_and_check_params(self):
        ns_info = NSInstModel.objects.filter(id=self.ns_instance_id)
        if not ns_info:
            raise NSLCMException('NS [id=%s] does not exist' %
                                 self.ns_instance_id)

        self.update_type = ignore_case_get(self.request_data, "updateType")
        if not self.update_type:
            raise NSLCMException(
                'UpdateType parameter does not exist or value incorrect.')
Пример #13
0
def confirm_vnf_status(vnf_inst_id):
    uri = "api/nslcm/v1/ns/vnfs/{vnfInstId}".format(vnfInstId=vnf_inst_id)
    ret = restcall.req_by_msb(uri, "GET")
    if ret[0] != 0:
        raise NSLCMException("Failed to call get_vnf(%s)" % vnf_inst_id)
    ret[1] = json.JSONDecoder().decode(ret[1])

    vnf_status = ret[1]["vnfStatus"]
    if vnf_status != "active":
        raise NSLCMException("Status of VNF(%s) is not active" % vnf_inst_id)
Пример #14
0
 def check_filter_types(self):
     logger.debug(
         "SubscribeNotification--post::> Validating operationTypes and operationStates if exists"
     )
     occ_notification = NOTIFICATION_TYPE.NSLCM_OPERATION_OCCURRENCE_NOTIFICATION
     if self.operation_types and occ_notification not in self.notification_types:
         except_message = "If you are setting operationTypes, notificationTypes must be %s"
         raise NSLCMException(except_message % occ_notification)
     if self.operation_states and occ_notification not in self.notification_types:
         except_message = "If you are setting operationStates, notificationTypes must be %s"
         raise NSLCMException(except_message % occ_notification)
Пример #15
0
    def check_and_set_params(self):
        scale_type = ignore_case_get(self.request_data, 'scaleType')
        if scale_type != SCALE_TYPE[0]:
            raise NSLCMException('scaleType should be SCALE_NS.')

        scale_ns_data = ignore_case_get(self.request_data, 'scaleNsData')
        self.scale_vnf_data = get_scale_vnf_data_info_list(
            scale_ns_data, self.ns_instance_id)
        logger.debug('scale_vnf_data = %s' % self.scale_vnf_data)
        if not self.scale_vnf_data:
            raise NSLCMException('Failed to get scaleVnfData parameter')
Пример #16
0
 def check_callback_uri(self):
     logger.debug(
         "SubscribeNotification-post::> Sending GET request to %s" %
         self.callback_uri)
     try:
         response = requests.get(self.callback_uri, timeout=2)
         if response.status_code != status.HTTP_204_NO_CONTENT:
             raise NSLCMException("callbackUri %s returns %s status code." %
                                  (self.callback_uri, response.status_code))
     except Exception:
         raise NSLCMException(
             "callbackUri %s didn't return 204 status code." %
             self.callback_uri)
Пример #17
0
 def check_valid_auth_info(self):
     logger.debug(
         "SubscribeNotification--post::> Validating Auth details if provided"
     )
     auth_type = self.authentication.get("authType")
     params_basic = self.authentication.get("paramsBasic")
     params_oauth2 = self.authentication.get(
         "paramsOauth2ClientCredentials")
     if params_basic and AUTH_TYPE.BASIC not in auth_type:
         raise NSLCMException('Auth type should be ' + AUTH_TYPE.BASIC)
     if params_oauth2 and AUTH_TYPE.OAUTH2_CLIENT_CREDENTIALS not in auth_type:
         raise NSLCMException('Auth type should be ' +
                              AUTH_TYPE.OAUTH2_CLIENT_CREDENTIALS)
Пример #18
0
 def do_on_boarding(self):
     self.update_job(10, "Start vnf on boarding.")
     onboarding_data = {
         "csarId":self.data["PackageID"],
         "labVimId":ignore_case_get(self.verify_config, "labVimId")
     }
     ret = req_by_msb("/openoapi/nslcm/v1/vnfpackage", "POST", json.JSONEncoder().encode(onboarding_data))
     if ret[0] != 0:
         raise NSLCMException("Failed to call vnf onboarding: %s" % ret[1])
     rsp_data = json.JSONDecoder().decode(ret[1])
     if not self.wait_until_job_done(rsp_data["jobId"], 15):
         raise NSLCMException("Vnf onboarding failed")
     self.update_job(20, "Vnf on boarding success.")
Пример #19
0
def tosca_plan(uri, inputs):
    """
    https://wiki.open-o.org/view/Common_TOSCA_API_Documentation
    """
    content = {"uri": uri, "inputs": inputs}
    content_str = json.JSONEncoder().encode(content)
    ret = req_by_msb("/api/tosca/v1/indirect/instance", "POST", content_str)
    if ret[0] != 0:
        raise NSLCMException("status code is %s, detail is %s.", ret[2],
                             ret[1])
    if ret[2] != '200':
        raise NSLCMException(
            "tosca error occur when call parser api failed: %s" % content_str)
    return ret[1]
Пример #20
0
def get_download_url_from_catalog(csar_id, relative_path):
    ret = req_by_msb("/openoapi/catalog/v1/csars/%s/files?relativePath=%s" % (csar_id, relative_path), "GET")
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise NSLCMException("Failed to get download url of CSAR(%s)." % csar_id)
    csar_file_info = json.JSONDecoder().decode(ret[1])
    return ignore_case_get(csar_file_info, "downloadUri"), ignore_case_get(csar_file_info, "localPath")
Пример #21
0
def query_customer_aai(global_customer_id):
    resource = "/business/customers/customer/%s?depth=all" % global_customer_id
    ret = call_aai(resource, "GET")
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise NSLCMException("Get customer info exception in AAI")
    return json.JSONDecoder().decode(ret[1]) if ret[1] else ret[1]
Пример #22
0
def query_vnfpackage_by_id(csar_id):
    ret = req_by_msb("/api/catalog/v1/vnfpackages/%s" % csar_id, "GET")
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise NSLCMException("Failed to query vnf CSAR(%s) from catalog." %
                             csar_id)
    return json.JSONDecoder().decode(ret[1])
Пример #23
0
 def check_nf_package_valid(self):
     nf_package_info = NfPackageModel.objects.filter(vnfdid=self.vnfd_id)
     if not nf_package_info:
         logger.info('NF package not exist.')
         raise NSLCMException('NF package not exist.')
     self.nf_package_info = nf_package_info[0]
     self.vnfd_model = json.loads(self.nf_package_info.vnfdmodel)
Пример #24
0
def select_vnfm(vnfm_type, vim_id):
    uri = "/external-system/esr-vnfm-list"
    ret = call_aai(uri, "GET")
    if ret[0] > 0:
        logger.error("Failed to call %s: %s", uri, ret[1])
        raise NSLCMException('Failed to get vnfms from extsys.')
    vnfms = json.JSONDecoder().decode(ret[1])
    vnfms = ignore_case_get(vnfms, "esr-vnfm")
    for vnfm in vnfms:
        vnfm_info = get_vnfm_by_id(vnfm.get("vnfm-id"))
        vnfmtype = ignore_case_get(vnfm_info, "type")
        vimid = ignore_case_get(vnfm_info, "vimId")
        if vnfmtype == vnfm_type and vimid == vim_id:
            return vnfm_info
    raise NSLCMException('No vnfm found with %s in vim(%s)' %
                         (vnfm_type, vim_id))
Пример #25
0
def delete_customer_relationship(global_customer_id):
    resource = "/business/customers/customer/{global-customer-id}/relationship-list/relationship" % global_customer_id
    ret = call_aai(resource, "DELETE")
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise NSLCMException("Delete customer relationship exception in AAI")
    return json.JSONDecoder().decode(ret[1]) if ret[1] else ret[1], ret[2]
Пример #26
0
def get_artifact(asset_type, csar_id):
    artifacts = get_artifacts(asset_type)
    for artifact in artifacts:
        if artifact["uuid"] == csar_id:
            return artifact
    raise NSLCMException("Failed to query artifact(%s,%s) from sdc." %
                         (asset_type, csar_id))
Пример #27
0
def undeploy_workflow(deploy_id):
    uri = "api/workflow/v1/package/{deployId}".format(deployId=deploy_id)
    ret = restcall.req_by_msb(uri, "DELETE")
    if ret[0] != 0:
        raise NSLCMException("Status code is %s, detail is %s.", ret[2],
                             ret[1])
    return json.JSONDecoder().decode(ret[1])
Пример #28
0
def query_rawdata_from_catalog(csar_id, input_parameters=[]):
    req_param = json.JSONEncoder().encode({"csarId": csar_id, "inputParameters": input_parameters})
    ret = req_by_msb("/openoapi/catalog/v1/servicetemplates/queryingrawdata", "POST", req_param)
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise NSLCMException("Failed to query rawdata of CSAR(%s) from catalog." % csar_id)
    return json.JSONDecoder().decode(ret[1])
Пример #29
0
    def prepare_vnf_heal_params(self, vnf_data):
        vnf_instance_id = ignore_case_get(vnf_data, 'vnfInstanceId')
        if not vnf_instance_id:
            errmsg = 'vnfinstanceid does not exist or value is incorrect.'
            logger.error(errmsg)
            raise NSLCMException(errmsg)
        cause = ignore_case_get(vnf_data, 'cause')
        additional_params = ignore_case_get(vnf_data, 'additionalParams')
        action = ignore_case_get(additional_params, 'action')
        action_vm_info = ignore_case_get(additional_params, 'actionvminfo')
        vm_id = ignore_case_get(action_vm_info, 'vmid')
        vdu_id = ignore_case_get(action_vm_info, 'vduid')
        vm_name = ignore_case_get(action_vm_info, 'vmname')

        result = {
            "vnfInstanceId": vnf_instance_id,
            "cause": cause,
            "additionalParams": {
                "action": action,
                "actionvminfo": {
                    "vmid": vm_id,
                    "vduid": vdu_id,
                    "vmname": vm_name
                }
            }
        }
        return result
Пример #30
0
def delete_network_relationship(network_id):
    resource = "/network/l3-networks/l3-network/%s/relationship-list/relationship" % network_id
    ret = call_aai(resource, "DELETE")
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise NSLCMException("Delete network relationship exception in AAI")
    return json.JSONDecoder().decode(ret[1]) if ret[1] else ret[1], ret[2]