コード例 #1
0
ファイル: utils.py プロジェクト: 5g-media/mape-translation
def count_running_ns():
    """Find the number of the instantiated NSs in OSM r4
    """
    running_ns = 0
    token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'),
                         OSM_ADMIN_CREDENTIALS.get('username'))

    ns = Ns(token)
    request = ns.get_list()
    ns_list = request.json()

    for i in ns_list:
        if i.get("operational-status") == "running":
            running_ns += 1
    return running_ns
コード例 #2
0
ファイル: utils.py プロジェクト: 5g-media/mape-translation
def discover_vnf_uuid_by_vnfd_name_index(vnfd_name_index):
    """ Discover the VDU uuid by given the vnfd name and index

    Args:
        vnfd_name_index (str): The VNFd name & index

    Returns:
        str: the vnf uuid

    """
    token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'),
                         OSM_ADMIN_CREDENTIALS.get('username'))

    # Get the UUIDs of the running NSs
    ns = Ns(token)
    request = ns.get_list()
    nss_response = request.json()
    ns_uuids = [ns.get('id') for ns in nss_response]

    # TODO: what if more than one NSs are running
    # if len(ns_uuids):
    #     raise Exception("More that one NSs are running...")

    vnf_uuid = None

    for ns_uuid in ns_uuids:
        vnf = Vnf(token)
        request = vnf.get_list_by_ns(ns_uuid=ns_uuid)
        vnfs = request.json()
        for i in vnfs:
            cur_vnfd_name_index = "{}.{}".format(
                i.get("vnfd-ref"),
                i.get("member-vnf-index-ref"),
            )
            if vnfd_name_index == cur_vnfd_name_index:
                return i.get("id")

    return vnf_uuid
コード例 #3
0
ファイル: utils.py プロジェクト: 5g-media/mape-translation
def discover_vdu_uuid_by_vnf_index(vnf_index):
    """ Discover the VDU uuid by given the vnf index

    Args:
        vnf_index (str): The VNF index

    Returns:
        str: the vdu uuid

    """
    token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'),
                         OSM_ADMIN_CREDENTIALS.get('username'))

    # Get the UUIDs of the running NSs
    ns = Ns(token)
    request = ns.get_list()
    nss_response = request.json()
    ns_uuids = [ns.get('id') for ns in nss_response]

    # TODO: what if more than one NSs are running
    # if len(ns_uuids):
    #     raise Exception("More that one NSs are running...")

    vdu_uuid = None

    for ns_uuid in ns_uuids:
        vnf = Vnf(token)
        request = vnf.get_list_by_ns(ns_uuid=ns_uuid)
        vnfs = request.json()
        for i in vnfs:
            if vnf_index in i.get("member-vnf-index-ref"):
                for vdur in i.get("vdur"):
                    vdu_uuid = vdur.get("vim-id")
                    return vdu_uuid

    return vdu_uuid
コード例 #4
0
ファイル: utils.py プロジェクト: 5g-media/mape-translation
def get_faas_vdu_details(vdu_uuid, ro_ns_uuid, vnf_name):
    mano = {}
    nsr = {}
    vnfd = {}

    token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'),
                         OSM_ADMIN_CREDENTIALS.get('password'))

    try:
        if ro_ns_uuid is None or vnf_name is None:
            raise Exception('Empty input')
        vnf_name = vnf_name.split('.')
        vnfd_name = vnf_name[0]
        vnf_index = vnf_name[1]

        # search for ro_ns_uuid in NSs list
        ns = Ns(token)
        ns_response = ns.get_list()
        ns_list = ns_response.json()

        for instance in ns_list:
            # Ensure that RO data are available
            openmano_deployment = instance['_admin'].get('deployed',
                                                         {}).get('RO', {})
            if len(openmano_deployment.keys()) == 0:
                continue
            # Compare the container id with the current NS record uuid
            nsr_id = openmano_deployment.get('nsr_id', None)
            if nsr_id is None or nsr_id != ro_ns_uuid:
                continue
            nsr = instance
            break

        # Get the NSd uuid
        nsd_id = nsr.get('nsdId', None)
        if nsd_id is None:
            nsd_id = nsr.get('instantiate_params', {}).get('nsdId', None)

        # Get the VIM account Info
        datacenter = nsr.get('datacenter', None)
        vim_account = VimAccount(token)
        vim_response = vim_account.get(vim_account_uuid=datacenter)
        vimr = vim_response.json()

        # Get vnfd info
        vnf_descriptor = Vnfd(token)
        vnfd_req = vnf_descriptor.get_list()
        vnfd_list = vnfd_req.json()
        for descriptor in vnfd_list:
            if 'id' in descriptor.keys() and descriptor['id'] == vnfd_name:
                vnfd = descriptor
                break

        mano = {
            "ns": {
                "id": nsr['id'],
                "name": nsr.get('name-ref', None),
                "nsd_id": nsd_id,
                "nsd_name": nsr.get('nsd-name-ref', None)
            },
            "vnf": {
                "id": '{}-{}-{}'.format(vdu_uuid, vnfd_name, vnf_index),
                "name": '{}.{}'.format(vnfd_name, vnf_index),
                "index": vnf_index,
                "short_name": None,
                "vnfd_id": vnfd['_id'],
                "vnfd_name": vnfd_name
            },
            "vdu": {
                "id": vdu_uuid,
                "name": vnfd_name,
                "image_id": vnfd_name,
                "flavor": {},
                "status": 'running',
                "ip_address": '0.0.0.0',
                "mgmt-interface": None  # future usage
            },
            "vim": {
                "uuid": vimr.get('_id', None),
                "name": vimr.get('name', None),
                "type": vimr.get('vim_type', None),
                "url": vimr.get('vim_url', None),
                "tag": 'kubernetes'
            }
        }
    except Exception as ex:
        logger.exception(ex)
    finally:
        return mano