Beispiel #1
0
def update_job(job_id, progress, errcode, desc):
    uri = JOB_INSTANCE_URI % job_id
    data = json.JSONEncoder().encode({
        "progress": progress,
        "errcode": errcode,
        "desc": desc
    })
    restcall.req_by_msb(uri, "POST", data)
def query_pnf_descriptor(filter=None):
    if filter:
        pnfdId = filter.get("pnfdId")
        ret = req_by_msb("/api/nsd/v1/pnf_descriptors?pnfdId=%s" % pnfdId,
                         "GET")
    else:
        ret = req_by_msb("/api/nsd/v1/pnf_descriptors", "GET")
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise NSLCMException(
            "Failed to query pnf descriptor(%s) from catalog." % pnfdId)
    return json.JSONDecoder().decode(ret[1])
Beispiel #3
0
def get_packageinfo_by_vnfdid(vnfdid):
    ret = req_by_msb("openoapi/gvnfmdriver/v1/vnfpackages", "GET")  # TODO
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise NFLCMException(
            "Failed to query package_info of vnfdid(%s) from nslcm." % vnfdid)
    return json.JSONDecoder().decode(ret[1])
Beispiel #4
0
def delete_csar_from_catalog(csar_id):
    ret = req_by_msb("/openoapi/catalog/v1/csars/%s" % csar_id, "DELETE")
    if ret[0] != 0 and ret[2] != '404':
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        set_csar_state(csar_id, "processState", P_STATUS_DELETEFAILED)
        return [1, "Failed to delete CSAR(%s) from catalog." % csar_id]
    return [0, "Delete CSAR(%s) successfully." % csar_id]
Beispiel #5
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")
Beispiel #6
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])
Beispiel #7
0
def create(req_param, url, str):
    ret = req_by_msb(url, "POST", json.dumps(req_param))
    if ret[0] != 0:
        logger.error("Failed to %s to sdncdriver. detail is %s.", str, ret[1])
        raise NSLCMException('Failed to %s to sdncdriver.' % str)
    resp_body = json.loads(ret[1])
    return resp_body["id"]
Beispiel #8
0
def grant_vnf(req_param):
    grant_data = json.JSONEncoder().encode(req_param)
    ret = req_by_msb("/openoapi/resmgr/v1/resource/grant", "PUT", grant_data)
    if ret[0] != 0:
        logger.error("Failed to grant vnf to resmgr. detail is %s.", ret[1])
        #raise NSLCMException('Failed to grant vnf to resmgr.')
        vim_id = ""
        if "vimId" in req_param:
            vim_id = req_param["vimId"]
        elif "additionalparam" in req_param and "vimid" in req_param["additionalparam"]:
            vim_id = req_param["additionalparam"]["vimid"]
        try:
            from lcm.pub.msapi import extsys
            vim = extsys.get_vim_by_id(vim_id)
            if isinstance(vim, list):
                vim = vim[0]
                vim_id = vim["vimId"]
            grant_rsp = {
                "vim": {
                    "vimid": vim_id,
                    "accessinfo": {
                        "tenant": vim["tenant"]
                    }
                }
            }
            logger.debug("grant_rsp=%s" % grant_rsp)
            return grant_rsp
        except:
            raise NSLCMException('Failed to grant vnf to resmgr.')
    return json.JSONDecoder().decode(ret[1])
Beispiel #9
0
def terminate_vnf(vnf_inst_id):
    uri = '/openoapi/resmgr/v1/vnf/%s' % vnf_inst_id
    req_param = {}
    ret = req_by_msb(uri, "DELETE", json.dumps(req_param))
    if ret[0] > 0:
        logger.error('Send terminate VNF request to resmgr failed.')
        #raise NSLCMException('Send terminate VNF request to resmgr failed.')
Beispiel #10
0
def notify_lcm_to_nfvo(data):
    ret = req_by_msb('api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification',
                     'POST', data)
    if ret[0] != 0:
        logger.error('Status code is %s, detail is %s.', ret[2], ret[1])
        raise NFLCMException('Nf lcm notify exception')
    return ret[1]
Beispiel #11
0
def get_packageinfo_by_vnfdid(vnfdid):
    ret = req_by_msb('api/gvnfmdriver/v1/vnfpackages', 'GET')
    if ret[0] != 0:
        logger.error('Status code is %s, detail is %s.', ret[2], ret[1])
        raise NFLCMException(
            'Failed to query package_info of vnfdid(%s) from nslcm.' % vnfdid)
    return json.JSONDecoder().decode(ret[1])
Beispiel #12
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])
Beispiel #13
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])
Beispiel #14
0
def get_scalingmap_json_package(ns_InstanceId):
    csar_id = NSInstModel.objects.filter(id=ns_InstanceId)[0].nspackage_id
    downloadUrl = query_csar_from_catalog(csar_id,
                                          "packageInfo")["downloadUrl"]
    ret = req_by_msb(downloadUrl, 'GET')
    scalingmap_json = json.JSONDecoder().decode(ret[1])

    return scalingmap_json
Beispiel #15
0
 def send_subscription_deletion_request(self):
     if self.subscription:
         self.subscription_id = self.subscription.subscription_id
         ret = req_by_msb('api/gvnfmdriver/v1/%s/subscriptions/%s' % (self.vnfm_id, self.subscription_id), 'DELETE')
         if ret[0] != 0:
             logger.error('Status code is %s, detail is %s.', ret[2], ret[1])
             raise NSLCMException("Failed to subscribe from vnfm(%s)." % self.vnfm_id)
         logger.debug('Subscripton(%s) in vnfm(%s) has been deleted.' % (self.subscription, self.vnfm_id))
Beispiel #16
0
def send_nf_scaling_request(vnfm_inst_id, vnf_inst_id, req_param):
    vnfm = get_vnfm_by_id(vnfm_inst_id)
    uri = '/openoapi/%s/v1/%s/vnfs/%s/scale' % (vnfm["type"], vnfm_inst_id, vnf_inst_id)
    ret = req_by_msb(uri, "POST", req_param)
    if ret[0] > 0:
        logger.error("Failed to send nf scale req:%s,%s", ret[2], ret[1])
        raise NSLCMException('Failed to send nf scale request to VNFM(%s)' % vnfm_inst_id)
    return json.JSONDecoder().decode(ret[1])
Beispiel #17
0
def notify_lcm_to_nfvo(data):
    ret = req_by_msb(
        "openoapi/gvnfmdriver/v1/vnfs/lifecyclechangesnotification", "POST",
        data)
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise NFLCMException("Nf lcm notify exception")
    return ret[1]
Beispiel #18
0
def modify_nsd_state(csar_id, usage_state=1):
    req_param = json.JSONEncoder().encode({"usageState": usage_state})
    ret = req_by_msb("/api/catalog/v1/ns_descriptors/%s" % csar_id, "PUT",
                     req_param)
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise NSLCMException(
            "Failed to modify nsd state of CSAR(%s) from catalog." % csar_id)
Beispiel #19
0
def workflow_run(content):
    content_str = json.JSONEncoder().encode(content)
    ret = req_by_msb("/openoapi/wso2bpel/v1/process/instance", "POST",
                     content_str)
    if ret[0] != 0:
        raise NSLCMException("Status code is %s, detail is %s.", ret[2],
                             ret[1])
    return json.JSONDecoder().decode(ret[1])
Beispiel #20
0
def exec_workflow(content):
    content_str = json.JSONEncoder().encode(content)
    ret = restcall.req_by_msb("api/workflow/v1/process/instance", "POST",
                              content_str)
    if ret[0] != 0:
        raise NSLCMException("Status code is %s, detail is %s.", ret[2],
                             ret[1])
    return json.JSONDecoder().decode(ret[1])
Beispiel #21
0
def send_active_pnf_request(ems_inst_id, pnf_id, req_param):
    ems = get_ems_by_id(ems_inst_id)
    uri = '/api/%s/v1/%s/pnfs/%s/active' % (ems["type"], ems_inst_id, pnf_id)
    ret = req_by_msb(uri, "POST", req_param)
    if ret[0] != 0:
        logger.error("Failed to send nf init req:%s,%s", ret[2], ret[1])
        raise NSLCMException('Failed to send nf init request to VNFM(%s)' %
                             ems_inst_id)
    return json.JSONDecoder().decode(ret[1])
Beispiel #22
0
    def do_func_test(self):
        self.update_job(60, "Start vnf function test.")
        func_data = {"PackageID":self.data["PackageID"]}
        ret = req_by_msb("/openapi/vnfsdk/v1/functest/taskmanager/testtasks", "POST", json.JSONEncoder().encode(func_data))
        if ret[0] != 0:
            raise NSLCMException("Failed to call func test: %s" % ret[1])
        rsp_data = json.JSONDecoder().decode(ret[1])

        if not self.wait_func_test_job_done(rsp_data["TaskID"], 40):
            raise NSLCMException("Func test failed")
        logger.info("Query(%s) job success.", rsp_data["TaskID"])

        ret = req_by_msb("/openapi/vnfsdk/v1/functest/taskmanager/testtasks/%s/result" % rsp_data["TaskID"], "GET")
        if ret[0] != 0:
            raise NSLCMException("Failed to get func test result: %s" % ret[1])
        rsp_result_data = json.JSONDecoder().decode(ret[1])
        logger.info("Func test(%s) result: %s", rsp_result_data)
        self.update_job(80, "Vnf function test success.")
Beispiel #23
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))
Beispiel #24
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)
Beispiel #25
0
def post_deal(ns_inst_id, status):
    uri = "api/nslcm/v1/ns/{nsInstanceId}/postdeal".format(
        nsInstanceId=ns_inst_id)
    data = json.JSONEncoder().encode({"status": status})

    ret = restcall.req_by_msb(uri, "POST", data)
    if ret[0] != 0:
        logger.error("Failed to call post_deal(%s): %s", ns_inst_id, ret[1])
    logger.debug("Call post_deal(%s, %s) successfully.", ns_inst_id, status)
Beispiel #26
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
Beispiel #27
0
def set_csar_state(csar_id, prop, val):
    ret = req_by_msb("/api/catalog/v1/csars/%s?%s=%s" % (csar_id, prop, val),
                     "PUT")
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        return [
            1, "Failed to set %s to %s of CSAR(%s)." % (prop, val, csar_id)
        ]
    return [0, "Set %s to %s of CSAR(%s) successfully." % (prop, val, csar_id)]
Beispiel #28
0
def update_job(job_id, progress, errcode, desc):
    logger.debug("job_id %s" % job_id)
    uri = JOB_INSTANCE_URI % job_id
    data = json.JSONEncoder().encode({
        "progress": progress,
        "errcode": errcode,
        "desc": desc
    })
    ret = restcall.req_by_msb(uri, "POST", data)
    return ret
Beispiel #29
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)
Beispiel #30
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)