예제 #1
0
    def vnf_query(self, query_filter, attribute_selector=None):
        vnf_info = VnfInfo()
        vnf_info.instantiation_state = 'INSTANTIATED'
        vnf_info.instantiated_vnf_info = InstantiatedVnfInfo()
        vnf_info.instantiated_vnf_info.vnf_state = 'STARTED'

        return vnf_info
예제 #2
0
    def vnf_query(self, query_filter, attribute_selector=None):
        vnf_instance_id = query_filter['vnf_instance_id']
        vnf_info = VnfInfo()
        vnf_info.vnf_instance_id = str(vnf_instance_id)

        # Build the vnf_info data structure
        vnf_info.vnf_instance_name = 'instance_name'
        vnf_info.vnf_instance_description = 'instance_description'
        vnf_info.vnfd_id = 'vnfd_id'
        vnf_info.instantiation_state = 'INSTANTIATED'

        # Build the InstantiatedVnfInfo information element only if the VNF is in INSTANTIATED state
        if vnf_info.instantiation_state == constants.VNF_INSTANTIATED:
            vnf_info.instantiated_vnf_info = InstantiatedVnfInfo()
            vnf_info.instantiated_vnf_info.vnf_state = 'STARTED'

            vnf_info.instantiated_vnf_info.vnfc_resource_info = []

            for vnf_resource in range(0, 2):

                # Build the VnfcResourceInfo data structure
                vnfc_resource_info = VnfcResourceInfo()
                vnfc_resource_info.vnfc_instance_id = 'vnfc_instance_id'
                vnfc_resource_info.vdu_id = 'vdu_id'

                vnfc_resource_info.compute_resource = ResourceHandle()
                vnfc_resource_info.compute_resource.vim_id = 'vim_id'
                vnfc_resource_info.compute_resource.resource_id = 'resource_id'

                vnf_info.instantiated_vnf_info.vnfc_resource_info.append(
                    vnfc_resource_info)

        return vnf_info
예제 #3
0
 def vnf_query(self, query_filter, attribute_selector=None):
     vnf_instance_id = query_filter['vnf_instance_id']
     vnf_info = VnfInfo()
     vnf_info.vnf_instance_id = vnf_instance_id
     ns_instance_id = self.vnf_to_ns_mapping.get(vnf_instance_id, '')
     try:
         url = '/api/v1/ns-records/%s/vnfrecords/%s' % (ns_instance_id,
                                                        vnf_instance_id)
         status_code, vnf_config = self.request(url=url, method='get')
         if status_code == 400:
             vnf_info.instantiation_state = constants.VNF_NOT_INSTANTIATED
             return vnf_info
     except Exception as e:
         LOG.exception(e)
         raise OpenbatonManoAdapterError(
             'Unable to retrieve status for VNF with ID %s. Reason: %s' %
             (vnf_instance_id, e))
     vnf_info = self.build_vnf_info(vnf_config)
     return vnf_info
예제 #4
0
    def vnf_query(self, query_filter, attribute_selector=None):
        vnf_instance_id = query_filter['vnf_instance_id']
        vnf_info = VnfInfo()
        vnf_info.vnf_instance_id = str(vnf_instance_id)

        resource = '/api/operational/project/vnfr-catalog/vnfr/%s' % vnf_instance_id
        try:
            response = self.session.get(url=self.url + resource)
            if response.status_code == 204:
                # vnf-instance-id not found, so assuming NOT_INSTANTIATED
                vnf_info.instantiation_state = constants.VNF_NOT_INSTANTIATED
                return vnf_info

            assert response.status_code == 200
            json_content = response.json()
        except Exception as e:
            LOG.exception(e)
            raise RiftManoAdapterError('Unable to get VNFR data for VNF %s' %
                                       vnf_instance_id)

        vnfr = json_content['rw-project:project']['vnfr:vnfr-catalog']['vnfr'][
            0]

        vnf_info.vnf_instance_name = str(vnfr['name'])
        vnf_info.vnf_product_name = str(vnfr['member-vnf-index-ref'])

        # TODO: add logic for all states
        vnf_info.instantiation_state = constants.VNF_INSTANTIATED
        vnf_info.vnfd_id = str(vnfr['vnfd']['id'])

        vnf_info.instantiated_vnf_info = InstantiatedVnfInfo()
        if vnfr['operational-status'] == 'running':
            vnf_info.instantiated_vnf_info.vnf_state = constants.VNF_STARTED
        else:
            vnf_info.instantiated_vnf_info.vnf_state = constants.VNF_STOPPED

        vnf_info.instantiated_vnf_info.vnfc_resource_info = []
        for vdur in vnfr['vdur']:
            vnfc_resource_info = VnfcResourceInfo()
            vnfc_resource_info.vnfc_instance_id = str(vdur['id'])
            vnfc_resource_info.vdu_id = str(vdur['vdu-id-ref'])

            vnfc_resource_info.compute_resource = ResourceHandle()
            vnfc_resource_info.compute_resource.vim_id = str(
                vnfr['rw-vnfr:datacenter'])
            vnfc_resource_info.compute_resource.resource_id = str(
                vdur['vim-id'])
            vnf_info.instantiated_vnf_info.vnfc_resource_info.append(
                vnfc_resource_info)

        vnf_info.instantiated_vnf_info.ext_cp_info = []
        for connection_point in vnfr['connection-point']:
            vnf_ext_cp_info = VnfExtCpInfo()
            vnf_ext_cp_info.cp_instance_id = str(
                connection_point['connection-point-id'])
            vnf_ext_cp_info.address = {
                'mac': [str(connection_point['mac-address'])],
                'ip': [str(connection_point['ip-address'])]
            }
            vnf_ext_cp_info.cpd_id = str(connection_point['name'])
            vnf_info.instantiated_vnf_info.ext_cp_info.append(vnf_ext_cp_info)

        return vnf_info
예제 #5
0
    def vnf_query(self, query_filter, attribute_selector=None):
        vnf_instance_id = query_filter['vnf_instance_id']
        tenant_name = query_filter['additional_param']['tenant']
        vnf_info = VnfInfo()
        vnf_info.vnf_instance_id = str(vnf_instance_id)

        # Try to retrieve the instantiation state for the VNF with the given deployment name. If the AttributeError
        # exception is raised, report the VNF instantiation state as NOT_INSTANTIATED.
        try:
            xml = self.nso.get((
                'xpath',
                '/nfvo/vnfr/esc/vnf-deployment[deployment-name="%s"]/plan/component[name="self"]/'
                'state[name="ncs:ready"]/status' % vnf_instance_id)).data_xml
            xml = etree.fromstring(xml)
            nso_vnf_deployment_state = xml.find(
                './/{http://tail-f.com/pkg/tailf-nfvo-esc}state/{http://tail-f.com/pkg/tailf-nfvo-esc}status'
            ).text
        except AttributeError:
            vnf_info.instantiation_state = constants.VNF_NOT_INSTANTIATED
            return vnf_info
        except Exception as e:
            LOG.exception(e)
            raise CiscoNFVManoAdapterError(
                'Unable to get VNF instantiation state from the NSO - %s' % e)

        # Get the VNF state from the ESC
        try:
            xml = self.esc.get((
                'xpath',
                '/esc_datamodel/opdata/tenants/tenant[name="%s"]/deployments[deployment_name="%s"]/'
                'state_machine/state' %
                (tenant_name, vnf_instance_id))).data_xml
            xml = etree.fromstring(xml)
            esc_vnf_deployment_state = xml.find(
                './/{http://www.cisco.com/esc/esc}state_machine/{http://www.cisco.com/esc/esc}state'
            ).text
        except Exception as e:
            LOG.exception(e)
            raise CiscoNFVManoAdapterError(
                'Unable to get VNF state from the ESC - %s' % e)

        # Get the VNFD ID from the NSO
        xml = self.nso.get(
            ('xpath',
             '/nfvo/vnfr/esc/vnf-deployment[deployment-name="%s"]/vnfr/id' %
             vnf_instance_id)).data_xml
        xml = etree.fromstring(xml)
        vnfd_id = xml.find(
            './/{http://tail-f.com/pkg/tailf-nfvo-esc}vnfr/{http://tail-f.com/pkg/tailf-nfvo-esc}id'
        ).text

        # Get the VNFD XML from the NSO
        vnfd_xml = self.nso.get(
            ('xpath', '/nfvo/vnfd[id="%s"]' % vnfd_id)).data_xml
        vnfd_xml = etree.fromstring(vnfd_xml)

        # Build the vnf_info data structure
        vnf_info.vnf_instance_name = vnf_instance_id
        # vnf_info.vnf_instance_description =
        vnf_info.vnfd_id = vnfd_id
        vnf_info.instantiation_state = constants.VNF_INSTANTIATION_STATE[
            'NSO_DEPLOYMENT_STATE'][nso_vnf_deployment_state]

        # Build the InstantiatedVnfInfo information element only if the VNF instantiation state is INSTANTIATED
        if vnf_info.instantiation_state == constants.VNF_INSTANTIATED:
            vnf_info.instantiated_vnf_info = InstantiatedVnfInfo()
            vnf_info.instantiated_vnf_info.vnf_state = constants.VNF_STATE[
                'ESC_DEPLOYMENT_STATE'][esc_vnf_deployment_state]

            # Initialize the VnfcResourceInfo list
            vnf_info.instantiated_vnf_info.vnfc_resource_info = []

            # Initialize the VnfExtCpInfo list
            vnf_info.instantiated_vnf_info.ext_cp_info = []

            # Get the deployment XML from the ESC
            deployment_xml = self.esc.get(
                ('xpath', '/esc_datamodel/opdata/tenants/tenant[name="%s"]/'
                 'deployments[deployment_name="%s"]' %
                 (tenant_name, vnf_instance_id))).data_xml
            deployment_xml = etree.fromstring(deployment_xml)

            # Get the VM group list from the deployment XML
            vm_group_list = deployment_xml.findall(
                './/{http://www.cisco.com/esc/esc}vm_group/{http://www.cisco.com/esc/esc}name'
            )
            for vm_group in vm_group_list:
                vm_group_text = vm_group.text

                # Find all VM IDs in this VM group
                vm_id_list = deployment_xml.findall(
                    './/{http://www.cisco.com/esc/esc}vm_group[{http://www.cisco.com/esc/esc}name="%s"]/'
                    '{http://www.cisco.com/esc/esc}vm_instance/{http://www.cisco.com/esc/esc}vm_id'
                    % vm_group_text)

                # Iterate over the VM IDs in this VM group
                for vm_id in vm_id_list:
                    vm_id_text = vm_id.text

                    # Get the VM name
                    name = deployment_xml.find(
                        './/{http://www.cisco.com/esc/esc}vm_group'
                        '[{http://www.cisco.com/esc/esc}name="%s"]/'
                        '{http://www.cisco.com/esc/esc}vm_instance'
                        '[{http://www.cisco.com/esc/esc}vm_id="%s"]/'
                        '{http://www.cisco.com/esc/esc}name' %
                        (vm_group_text, vm_id_text))
                    name_text = name.text

                    # Build the VnfcResourceInfo data structure
                    vnfc_resource_info = VnfcResourceInfo()
                    vnfc_resource_info.vnfc_instance_id = name_text
                    vnfc_resource_info.vdu_id = vm_group_text

                    vnfc_resource_info.compute_resource = ResourceHandle()
                    # Cisco ESC only support one VIM. Hardcode the VIM ID to string 'default_vim'
                    vnfc_resource_info.compute_resource.vim_id = 'default_vim'
                    vnfc_resource_info.compute_resource.resource_id = vm_id_text

                    # Append the current VnfvResourceInfo element to the VnfcResourceInfo list
                    vnf_info.instantiated_vnf_info.vnfc_resource_info.append(
                        vnfc_resource_info)

                    # Get the list NIC IDs for this VM instance
                    nic_id_list = deployment_xml.findall(
                        './/{http://www.cisco.com/esc/esc}vm_group'
                        '[{http://www.cisco.com/esc/esc}name="%s"]/'
                        '{http://www.cisco.com/esc/esc}vm_instance'
                        '[{http://www.cisco.com/esc/esc}vm_id="%s"]/'
                        '{http://www.cisco.com/esc/esc}interfaces/'
                        '{http://www.cisco.com/esc/esc}interface/'
                        '{http://www.cisco.com/esc/esc}nicid' %
                        (vm_group_text, vm_id_text))

                    # Iterate over the NIC IDs
                    for nic_id in nic_id_list:
                        nic_id_text = nic_id.text

                        # Get the internal connection point ID from the VNFD that corresponds to this port ID
                        cpd_id = vnfd_xml.find(
                            './/{http://tail-f.com/pkg/nfvo}vdu'
                            '[{http://tail-f.com/pkg/nfvo}id="%s"]/'
                            '{http://tail-f.com/pkg/nfvo}internal-connection-point'
                            '[{http://tail-f.com/pkg/tailf-nfvo-esc}interface-id="%s"]/'
                            '{http://tail-f.com/pkg/nfvo}id' %
                            (vm_group_text, nic_id_text))
                        cpd_id_text = cpd_id.text

                        # Get the port ID
                        port_id = deployment_xml.find(
                            './/{http://www.cisco.com/esc/esc}vm_group'
                            '[{http://www.cisco.com/esc/esc}name="%s"]/'
                            '{http://www.cisco.com/esc/esc}vm_instance'
                            '[{http://www.cisco.com/esc/esc}vm_id="%s"]/'
                            '{http://www.cisco.com/esc/esc}interfaces/'
                            '{http://www.cisco.com/esc/esc}interface'
                            '[{http://www.cisco.com/esc/esc}nicid="%s"]/'
                            '{http://www.cisco.com/esc/esc}port_id' %
                            (vm_group_text, vm_id_text, nic_id_text))
                        port_id_text = port_id.text

                        # Get the IP address
                        ip_address = deployment_xml.find(
                            './/{http://www.cisco.com/esc/esc}vm_group'
                            '[{http://www.cisco.com/esc/esc}name="%s"]/'
                            '{http://www.cisco.com/esc/esc}vm_instance'
                            '[{http://www.cisco.com/esc/esc}vm_id="%s"]/'
                            '{http://www.cisco.com/esc/esc}interfaces/'
                            '{http://www.cisco.com/esc/esc}interface'
                            '[{http://www.cisco.com/esc/esc}nicid="%s"]/'
                            '{http://www.cisco.com/esc/esc}ip_address' %
                            (vm_group_text, vm_id_text, nic_id_text))
                        ip_address_text = ip_address.text

                        # Get the MAC address
                        mac_address = deployment_xml.find(
                            './/{http://www.cisco.com/esc/esc}vm_group'
                            '[{http://www.cisco.com/esc/esc}name="%s"]/'
                            '{http://www.cisco.com/esc/esc}vm_instance'
                            '[{http://www.cisco.com/esc/esc}vm_id="%s"]/'
                            '{http://www.cisco.com/esc/esc}interfaces/'
                            '{http://www.cisco.com/esc/esc}interface'
                            '[{http://www.cisco.com/esc/esc}nicid="%s"]/'
                            '{http://www.cisco.com/esc/esc}mac_address' %
                            (vm_group_text, vm_id_text, nic_id_text))
                        mac_address_text = mac_address.text

                        # Build the VnfExtCpInfo data structure
                        vnf_ext_cp_info = VnfExtCpInfo()
                        vnf_ext_cp_info.cp_instance_id = port_id_text
                        vnf_ext_cp_info.address = {
                            'ip': [ip_address_text],
                            'mac': [mac_address_text]
                        }
                        vnf_ext_cp_info.cpd_id = cpd_id_text

                        # Append the current VnfExtCpInfo element to the VnfExtCpInfo list
                        vnf_info.instantiated_vnf_info.ext_cp_info.append(
                            vnf_ext_cp_info)

        # VNF instantiation state is not INSTANTIATED
        else:
            raise CiscoNFVManoAdapterError(
                'The InstantiatedVnfInfo information element cannot be built as the VNF '
                'instantiation state is not INSTANTIATED')

        return vnf_info
예제 #6
0
    def vnf_query(self, query_filter, attribute_selector=None):
        vnf_instance_id = query_filter['vnf_instance_id']
        vnf_info = VnfInfo()
        vnf_info.vnf_instance_id = str(vnf_instance_id)

        response = requests.get(url=self.nfv_api_url +
                                '/nfv/vnf/vnf-instance/%s' % vnf_instance_id)
        vnf_instance_dict = response.json()

        if response.status_code == 404:
            vnf_info.instantiation_state = constants.VNF_NOT_INSTANTIATED
            return vnf_info

        vnf_info.vnf_instance_name = str(
            vnf_instance_dict['vnf-instance']['inst_name'])
        vnf_info.vnf_product_name = str(
            vnf_instance_dict['vnf-instance']['inst_name'])

        # TODO: add logic for all states
        vnf_info.instantiation_state = constants.VNF_INSTANTIATED
        vnf_info.vnfd_id = str(vnf_instance_dict['vnf-instance']['vnf_id'])

        vnf_info.instantiated_vnf_info = InstantiatedVnfInfo()
        if vnf_instance_dict['vnf-instance']['state'][
                'oper_state'] == 'ACTIVE':
            vnf_info.instantiated_vnf_info.vnf_state = constants.VNF_STARTED
        else:
            vnf_info.instantiated_vnf_info.vnf_state = constants.VNF_STOPPED

        vnf_info.instantiated_vnf_info.vnfc_resource_info = []
        for _, vnfc_details in vnf_instance_dict['vnf-instance'][
                'vnfc_instance_list'].items():
            vnfc_resource_info = VnfcResourceInfo()
            vnfc_resource_info.vnfc_instance_id = str(vnfc_details['vnfc_id'])
            vnfc_resource_info.vdu_id = str(
                vnfc_details['vi_resources']['vdu_id'])

            vnfc_resource_info.compute_resource = ResourceHandle()
            vnfc_resource_info.compute_resource.vim_id = str(
                vnfc_details['vi_resources']['vi_descriptor']['virp_id'])
            vnfc_resource_info.compute_resource.resource_id = str(
                vnfc_details['vi_resources']['vi_descriptor']['vi_resources']
                ['mgmt_objects']['OPENSTACK_SERVER'])
            vnf_info.instantiated_vnf_info.vnfc_resource_info.append(
                vnfc_resource_info)

        vnf_info.instantiated_vnf_info.ext_cp_info = []
        for vnfc_resource_info in vnf_info.instantiated_vnf_info.vnfc_resource_info:
            vnf_resource_id = vnfc_resource_info.compute_resource.resource_id
            vim_id = vnfc_resource_info.compute_resource.vim_id
            vim = self.get_vim_helper(vim_id)
            port_iterator = vim.port_list(device_id=vnf_resource_id)

            for port_dict in port_iterator:
                for port in port_dict['ports']:
                    match = re.search(
                        '^%s-p(\d+)\*?$' % vnf_info.vnf_product_name,
                        port['name'])
                    if match is not None:
                        vnf_ext_cp_info = VnfExtCpInfo()
                        vnf_ext_cp_info.cp_instance_id = str(port['id'])
                        vnf_ext_cp_info.address = {
                            'mac': [str(port['mac_address'])],
                            'ip': []
                        }

                        for fixed_ip in port['fixed_ips']:
                            vnf_ext_cp_info.address['ip'].append(
                                str(fixed_ip['ip_address']))

                        vnf_ext_cp_info.cpd_id = str(match.groups()[0])
                        vnf_info.instantiated_vnf_info.ext_cp_info.append(
                            vnf_ext_cp_info)

        return vnf_info
예제 #7
0
    def build_vnf_info(self, vnf_config):
        vnf_info = VnfInfo()
        vnf_info.vnf_instance_id = str(vnf_config['id'])
        if vnf_config['status'] not in ['ACTIVE', 'INACTIVE']:
            vnf_info.instantiation_state = constants.VNF_NOT_INSTANTIATED
            return vnf_info

        vnf_info.instantiation_state = constants.VNF_INSTANTIATED
        vnf_info.vnfd_id = str(vnf_config['descriptor_reference'])
        vnf_info.vnf_instance_name = str(vnf_config['name'])
        vnf_info.vnf_product_name = str(vnf_config['type'])

        vnf_info.instantiated_vnf_info = InstantiatedVnfInfo()
        vnf_info.instantiated_vnf_info.vnf_state = constants.VNF_STATE[
            'OPENBATON_VNF_STATE'][vnf_config['status']]

        vnf_info.instantiated_vnf_info.vnfc_resource_info = []
        vnf_info.instantiated_vnf_info.ext_cp_info = []

        for vdu in vnf_config['vdu']:
            for vnfc_instance in vdu['vnfc_instance']:
                vnfc_resource_info = VnfcResourceInfo()
                vnfc_resource_info.vnfc_instance_id = str(vnfc_instance['id'])
                vnfc_resource_info.vdu_id = str(vdu['parent_vdu'])

                vnfc_resource_info.compute_resource = ResourceHandle()
                vnfc_resource_info.compute_resource.vim_id = str(
                    vnfc_instance['vim_id'])
                vnfc_resource_info.compute_resource.resource_id = str(
                    vnfc_instance['vc_id'])

                vnf_info.instantiated_vnf_info.vnfc_resource_info.append(
                    vnfc_resource_info)

                for ext_cp in vnfc_instance['vnfComponent'][
                        'connection_point']:
                    vnf_ext_cp_info = VnfExtCpInfo()
                    port_name = 'VNFD-' + str(ext_cp['id'])
                    vim_id = str(vnfc_instance['vim_id'])

                    vim = self.get_vim_helper(vim_id)
                    port_dict = vim.port_list(name=port_name)

                    for port_list in port_dict:
                        for port in port_list['ports']:
                            vnf_ext_cp_info = VnfExtCpInfo()
                            vnf_ext_cp_info.cp_instance_id = str(port['id'])
                            vnf_ext_cp_info.address = {
                                'mac': [str(port['mac_address'])],
                                'ip': []
                            }

                            for fixed_ip in port['fixed_ips']:
                                vnf_ext_cp_info.address['ip'].append(
                                    str(fixed_ip['ip_address']))

                    virtual_link_reference = str(
                        ext_cp['virtual_link_reference'])
                    vnf_ext_cp_info.cpd_id = virtual_link_reference + '@' + str(
                        vdu['name'])
                    vnf_info.instantiated_vnf_info.ext_cp_info.append(
                        vnf_ext_cp_info)

        return vnf_info