Пример #1
0
def get_ns_name(ns_uuid):
    # Get the NS name based on the NS uuid
    token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'),
                         OSM_ADMIN_CREDENTIALS.get('password'))
    ns = NetworkService(token)
    response = ns.get(ns_uuid=ns_uuid)
    data = response.json()
    return data['name']
Пример #2
0
def get_nsd_ref_name(token, ns_uuid):
    """ Get the nsd reference name by ns identifier

    Args:
        token (str): the auth token in OSM
        ns_uuid (str): The identifier of the NS

    Returns:
        str: the nsd reference name
    """
    ns = NetworkService(token)
    request = ns.get(ns_uuid=ns_uuid)
    response = request.json()
    return response.get('nsd-name-ref', None)
Пример #3
0
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
Пример #4
0
    def apply(self, vnf_index, scale_action="scale_out"):
        """ Apply the scaling in or out

        Args:
            vnf_index (int): The VNF index
            scale_action (str): Scale in or out

        Returns:
            None

        Raises:
            VnfScaleNotCompleted: The scale action in VNF-level was failed.

        Examples:
            >>> from actions import scale as vnf_scale_action
            >>> ns_uuid = "xxxx"
            >>> vnfd_uuid = "yyyy"
            >>> vnf_index = 2
            >>> vnf_scale = vnf_scale_action.Action(ns_uuid, vnfd_uuid)
            >>> vnf_scale.apply(vnf_index, scale_action="scale_out")
        """
        scale_out = True if scale_action == "scale_out" else False

        if not self.allow_scale_action(scale_action=scale_action):
            raise VnfScaleNotCompleted(
                'The scaling action of the VNF with index `{}` (part of NS with uuid `{}`) is '
                'not allowed due to the number of edge vCaches.'.format(
                    vnf_index, self.ns_uuid))

        if self.detect_pending_scale_actions(scale_action=scale_action):
            raise VnfScaleNotCompleted(
                'The scaling action of the VNF with index `{}` (part of NS with uuid `{}`) is '
                'not allowed since a pending `{}` was detected.'.format(
                    vnf_index, self.ns_uuid, scale_action))

        network_service = Ns(self.__token)
        scale_request = network_service.scale_vnf(
            ns_uuid=self.ns_uuid,
            vnf_index=vnf_index,
            scaling_group_name=self.scaling_group_name,
            scale_out=scale_out)

        if int(scale_request.status_code) != 201:
            raise VnfScaleNotCompleted(
                'The status code `{}` in the scaling action of the VNF with index `{}` (part '
                'of NS with uuid `{}`) is not expected. '.format(
                    scale_request.status_code, vnf_index, self.ns_uuid))
Пример #5
0
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
Пример #6
0
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
Пример #7
0
def get_vnf_details(vnf_uuid, record, source="vtranscoder3d"):
    """ Append MANO (OSM) details (ns, vnf and vdu) by given VNF uuid

    Args:
        vnf_uuid (str): The uuid of the VNF
        record (dict): The original metric as it is sent from monitoring metrics generator
        source (str): The NFVI or application ref. It could be "vtranscoder3d" etc..

    Returns:
        dict: osm info for the given vdu
    """
    mano = {}
    token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'),
                         OSM_ADMIN_CREDENTIALS.get('password'))
    vnfr = Vnf(token)
    vnf_response = vnfr.get(vnf_uuid=vnf_uuid)
    vnf_record = vnf_response.json()

    # Get NS details
    ns_id = vnf_record.get("nsr-id-ref", None)
    ns = Ns(token)
    ns_response = ns.get(ns_uuid=ns_id)
    nsr = ns_response.json()

    # VNFd info
    vnfd = vnf_record.get("vnfd-id", None)

    # VDUs info
    vdu_records = vnf_record.get('vdur', [])
    # Number of VDU per VNFd
    vdus_count = len(vdu_records)
    if vdus_count > 1:
        logger.critical("{} VDUs were found for the VNF with uuid: {}".format(
            vdus_count, vnf_uuid))

    vdu_record = vdu_records[0]
    try:
        # Find the VDU info
        vdu_metadata = record.get("resource_metadata", {})

        # If the data coming from VNFs, discover in different way the VDU info
        if source in [
                "telegraf", "vtranscoder3d", "vce", "kubernetes", "opennebula",
                "vtranscoder3d_spectators"
        ]:
            vdu_metadata["instance_id"] = vdu_record.get('vim-id', None)
            vdu_metadata["flavor"] = {}
            if vdus_count:
                # TODO: what about the IPs if exists VNF with multiple VDUs?
                vdu_metadata["state"] = vdu_record.get('status', "")
                vdu_metadata['name'] = vdu_record.get('name', "")
                vdu_metadata["flavor"]["ram"] = None
                vdu_metadata["flavor"]["vcpus"] = None
                vdu_metadata["flavor"]["disk"] = None

        elif source == "openstack":
            """By default, OpenStack (ceilometer) provides us the following info: vcpus, ram, 
            ephemeral, swap, disk, name, id
            """
            pass

        # Get IP per VDU
        vdu_metadata['ip_address'] = vdu_record.get("ip-address", None)

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

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

        mano = {
            "ns": {
                "id": ns_id,
                "name": nsr.get('name-ref', None),
                "nsd_id": nsd_id,
                "nsd_name": nsr.get('nsd-name-ref', None)
            },
            "vnf": {
                "id": vnf_record.get("id", None),
                "name": vnf_record.get("name", None),
                # not in osm r5: it could be <vnfd_name>_<index>
                "index": vnf_record.get("member-vnf-index-ref", 0),
                "short_name": vnf_record.get("short-name",
                                             None),  # not in osm r5
                "vnfd_id": vnf_record.get("vnfd-id", None),
                "vnfd_name": vnf_record.get('vnfd-ref', None)
            },
            "vdu": {
                "id": vdu_metadata.get("instance_id", None),
                "name": vdu_metadata.get("name", None),
                "image_id": vdu_metadata.get("image", {}).get("id", None),
                "flavor": vdu_metadata.get("flavor", {}),
                "status": vdu_metadata.get("state", None),
                "ip_address": vdu_metadata['ip_address'],
                "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": source
            }
        }
        logger.debug(mano)
    except Exception as ex:
        logger.exception(ex)
    finally:
        # TODO: Since we don't know the VDU uuid, the 1st VDU will be used since 1 VDU is used for the VNF (UC1).
        return mano
Пример #8
0
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
Пример #9
0
def get_vdus_info(ns_uuid=None):
    """Get information about NS, VNF(s) and VDU(s) by given NS uuid

    Args:
        ns_uuid (str): The NS uuid

    Returns:
        dict: ns, vnf and vdu info
    """
    vdus_info = []
    if ns_uuid is None:
        return vdus_info

    token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'),
                         OSM_ADMIN_CREDENTIALS.get('username'))
    ns = Ns(token)
    ns_response = ns.get(ns_uuid=ns_uuid)
    nsr = ns_response.json()

    # Get Vim
    vim_uuid = nsr.get('datacenter', None)
    vim_info = get_vim_info(vim_uuid=vim_uuid)

    # Get the Vnf UUIDs, members of the NS
    vnf_uuids = nsr.get('constituent-vnfr-ref', [])

    vnfr = Vnf(token)

    for vnf_uuid in vnf_uuids:
        vnf_response = vnfr.get(vnf_uuid=vnf_uuid)
        vnf_record = vnf_response.json()

        # VDUs info
        vdu_records = vnf_record.get('vdur', [])

        for vdu_record in vdu_records:
            mano = {
                "vim": vim_info,
                "ns": {
                    "id": ns_uuid,
                    "name": nsr.get('name-ref', None),
                    "nsd_id": nsr.get('nsdId', None),
                    "nsd_name": nsr.get('nsd-name-ref', None)
                },
                "vnf": {
                    "id": vnf_record.get("id", None),
                    "name": None,  # not provided in osm r4
                    "short_name": None,  # not provided in osm r4
                    "vnfd_id": vnf_record.get("vnfd-id", None),
                    "vnfd_name": None  # not provided in osm r4
                },
                "vdu": {
                    "id": vdu_record.get("vim-id", None),  # NFVI-based uuid
                    "image_id": None,
                    "flavor": {},
                    "status": vdu_record.get("status", None),
                    "ip_address": vdu_record.get("ip-address", None),
                    "mgmt-interface": None  # future usage
                }
            }
            vdus_info.append(mano)
    return vdus_info