Example #1
0
    def new_network(self, net_name, net_type, ip_profile=None, shared=False, provider_network_profile=None):
        """Adds a tenant network to VIM
        Params:
            'net_name': name of the network
            'net_type': one of:
                'bridge': overlay isolated network
                'data':   underlay E-LAN network for Passthrough and SRIOV interfaces
                'ptp':    underlay E-LINE network for Passthrough and SRIOV interfaces.
            'ip_profile': is a dict containing the IP parameters of the network
                'ip_version': can be "IPv4" or "IPv6" (Currently only IPv4 is implemented)
                'subnet_address': ip_prefix_schema, that is X.X.X.X/Y
                'gateway_address': (Optional) ip_schema, that is X.X.X.X
                'dns_address': (Optional) comma separated list of ip_schema, e.g. X.X.X.X[,X,X,X,X]
                'dhcp_enabled': True or False
                'dhcp_start_address': ip_schema, first IP to grant
                'dhcp_count': number of IPs to grant.
            'shared': if this network can be seen/use by other tenants/organization
        Returns the network identifier on success or raises and exception on failure
        """
        self.logger.debug('new_network: {}'.format(locals()))
        if net_type in ['data', 'ptp']:
            raise vimconn.VimConnNotImplemented('{} type of network not supported'.format(net_type))

        net_uuid = '{}'.format(uuid.uuid4())
        desc = {
            'uuid': net_uuid,
            'name': net_name,
            'net_type': 'ELAN',
            'is_mgmt': False
        }

        if ip_profile is not None:
            ip = {}
            if ip_profile.get('ip_version') == 'IPv4':
                ip_info = {}
                ip_range = self.__get_ip_range(ip_profile.get('dhcp_start_address'), ip_profile.get('dhcp_count'))
                dhcp_range = '{},{}'.format(ip_range[0], ip_range[1])
                ip['subnet'] = ip_profile.get('subnet_address')
                ip['dns'] = ip_profile.get('dns', None)
                ip['dhcp_enable'] = ip_profile.get('dhcp_enabled', False)
                ip['dhcp_range'] = dhcp_range
                ip['gateway'] = ip_profile.get('gateway_address', None)
                desc['ip_configuration'] = ip_info
            else:
                raise vimconn.VimConnNotImplemented('IPV6 network is not implemented at VIM')
            desc['ip_configuration'] = ip
        self.logger.debug('VIM new_network args: {} - Generated Eclipse fog05 Descriptor {}'.format(locals(), desc))
        try:
            self.fos_api.network.add_network(desc)
        except fimapi.FIMAResouceExistingException as free:
            raise vimconn.VimConnConflictException("Network already exists at VIM. Error {}".format(free))
        except Exception as e:
            raise vimconn.VimConnException("Unable to create network {}. Error {}".format(net_name, e))
            # No way from the current rest service to get the actual error, most likely it will be an already
            # existing error
        return net_uuid, {}
Example #2
0
 def new_flavor(self, flavor_data):
     """Adds a tenant flavor to VIM
         flavor_data contains a dictionary with information, keys:
             name: flavor name
             ram: memory (cloud type) in MBytes
             vpcus: cpus (cloud type)
             extended: EPA parameters
               - numas: #items requested in same NUMA
                   memory: number of 1G huge pages memory
                   paired-threads|cores|threads: number of paired hyperthreads, complete cores OR individual threads
                   interfaces: # passthrough(PT) or SRIOV interfaces attached to this numa
                       - name: interface name
                         dedicated: yes|no|yes:sriov;  for PT, SRIOV or only one SRIOV for the physical NIC
                         bandwidth: X Gbps; requested guarantee bandwidth
                         vpci: requested virtual PCI address
             disk: disk size
             is_public:
              #TODO to concrete
     Returns the flavor identifier"""
     self.logger.debug('VIM new_flavor with args: {}'.format(locals()))
     flv_id = '{}'.format(uuid.uuid4())
     desc = {
         'uuid': flv_id,
         'name': flavor_data.get('name'),
         'cpu_arch': self.arch,
         'cpu_min_count': flavor_data.get('vcpus'),
         'cpu_min_freq': 0,
         'ram_size_mb': float(flavor_data.get('ram')),
         'storage_size_gb': float(flavor_data.get('disk'))
     }
     try:
         self.fos_api.flavor.add(desc)
     except fimapi.FIMAResouceExistingException as free:
         raise vimconn.VimConnConflictException("Flavor {} already exist at VIM. Error {}".format(flv_id, free))
     except Exception as e:
         raise vimconn.VimConnConnectionException("VIM not reachable. Error {}".format(e))
     return flv_id
Example #3
0
 def new_image(self, image_dict):
     """ Adds a tenant image to VIM. imge_dict is a dictionary with:
         name: name
         disk_format: qcow2, vhd, vmdk, raw (by default), ...
         location: path or URI
         public: "yes" or "no"
         metadata: metadata of the image
     Returns the image id or raises an exception if failed
     """
     self.logger.debug('VIM new_image with args: {}'.format(locals()))
     img_id = '{}'.format(uuid.uuid4())
     desc = {
         'name': image_dict.get('name'),
         'uuid': img_id,
         'uri': image_dict.get('location'),
         'format': image_dict.get('disk_format')
     }
     try:
         self.fos_api.image.add(desc)
     except fimapi.FIMAResouceExistingException as free:
         raise vimconn.VimConnConflictException("Image {} already exist at VIM. Error {}".format(img_id, free))
     except Exception as e:
         raise vimconn.VimConnConnectionException("VIM not reachable. Error {}".format(e))
     return img_id
Example #4
0
 def action_vminstance(self, vm_id, action_dict, created_items={}):
     """
     Send and action over a VM instance. Returns created_items if the action was successfully sent to the VIM.
     created_items is a dictionary with items that
     :param vm_id: VIM identifier of the VM, provided by method new_vminstance
     :param action_dict: dictionary with the action to perform
     :param created_items: provided by method new_vminstance is a dictionary with key-values that will be passed to
         the method delete_vminstance. Can be used to store created ports, volumes, etc. Format is vimconnector
         dependent, but do not use nested dictionaries and a value of None should be the same as not present. This
         method can modify this value
     :return: None, or a console dict
     """
     self.logger.debug('VIM action_vminstance with args: {}'.format(locals()))
     nid = self.fdu_node_map.get(vm_id)
     if nid is None:
         raise vimconn.VimConnNotFoundException('No node for this VM')
     try:
         instance = self.fos_api.fdu.instance_info(vm_id)
         if "start" in action_dict:
             if instance.get('status') == 'CONFIGURE':
                 self.fos_api.fdu.start(vm_id)
             elif instance.get('status') == 'PAUSE':
                 self.fos_api.fdu.resume(vm_id)
             else:
                 raise vimconn.VimConnConflictException('Cannot start from current state: {}'.format(
                     instance.get('status')))
         elif "pause" in action_dict:
             if instance.get('status') == 'RUN':
                 self.fos_api.fdu.pause(vm_id)
             else:
                 raise vimconn.VimConnConflictException('Cannot pause from current state: {}'.format(
                     instance.get('status')))
         elif "resume" in action_dict:
             if instance.get('status') == 'PAUSE':
                 self.fos_api.fdu.resume(vm_id)
             else:
                 raise vimconn.VimConnConflictException('Cannot resume from current state: {}'.format(
                     instance.get('status')))
         elif "shutoff" in action_dict or "shutdown" or "forceOff" in action_dict:
             if instance.get('status') == 'RUN':
                 self.fos_api.fdu.stop(vm_id)
             else:
                 raise vimconn.VimConnConflictException('Cannot shutoff from current state: {}'.format(
                     instance.get('status')))
         elif "terminate" in action_dict:
             if instance.get('status') == 'RUN':
                 self.fos_api.fdu.stop(vm_id)
                 self.fos_api.fdu.clean(vm_id)
                 self.fos_api.fdu.undefine(vm_id)
                 # self.fos_api.fdu.offload(vm_id)
             elif instance.get('status') == 'CONFIGURE':
                 self.fos_api.fdu.clean(vm_id)
                 self.fos_api.fdu.undefine(vm_id)
                 # self.fos_api.fdu.offload(vm_id)
             elif instance.get('status') == 'PAUSE':
                 self.fos_api.fdu.resume(vm_id)
                 self.fos_api.fdu.stop(vm_id)
                 self.fos_api.fdu.clean(vm_id)
                 self.fos_api.fdu.undefine(vm_id)
                 # self.fos_api.fdu.offload(vm_id)
             else:
                 raise vimconn.VimConnConflictException('Cannot terminate from current state: {}'.format(
                     instance.get('status')))
         elif "rebuild" in action_dict:
             raise vimconn.VimConnNotImplemented("Rebuild not implemented")
         elif "reboot" in action_dict:
             if instance.get('status') == 'RUN':
                 self.fos_api.fdu.stop(vm_id)
                 self.fos_api.fdu.start(vm_id)
             else:
                 raise vimconn.VimConnConflictException('Cannot reboot from current state: {}'.format(
                     instance.get('status')))
     except Exception as e:
         raise vimconn.VimConnConnectionException("VIM not reachable. Error {}".format(e))
Example #5
0
    def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None, disk_list=None,
                       availability_zone_index=None, availability_zone_list=None):
        """Adds a VM instance to VIM
        :param start: (boolean) indicates if VM must start or created in pause mode.
        :param image_id: :param flavor_id: image and flavor VIM id to use for the VM
        :param net_list: list of interfaces, each one is a dictionary with:
            'name': (optional) name for the interface.
            'net_id': VIM network id where this interface must be connect to. Mandatory for type==virtual
            'vpci': (optional) virtual vPCI address to assign at the VM. Can be ignored depending on VIM capabilities
            'model': (optional and only have sense for type==virtual) interface model: virtio, e1000, ...
            'mac_address': (optional) mac address to assign to this interface
            'ip_address': (optional) IP address to assign to this interface
            #TODO: CHECK if an optional 'vlan' parameter is needed for VIMs when type if VF and net_id is not provided,
                the VLAN tag to be used. In case net_id is provided, the internal network vlan is used for tagging VF
            'type': (mandatory) can be one of:
                'virtual', in this case always connected to a network of type 'net_type=bridge'
                 'PCI-PASSTHROUGH' or 'PF' (passthrough): depending on VIM capabilities it can be connected to a
                  data/ptp network ot it can created unconnected
                 'SR-IOV' or 'VF' (SRIOV with VLAN tag): same as PF for network connectivity.
                 'VFnotShared'(SRIOV without VLAN tag) same as PF for network connectivity. VF where no other VFs
                        are allocated on the same physical NIC
            'bw': (optional) only for PF/VF/VFnotShared. Minimal Bandwidth required for the interface in GBPS
            'port_security': (optional) If False it must avoid any traffic filtering at this interface. If missing
                            or True, it must apply the default VIM behaviour
            After execution the method will add the key:
            'vim_id': must be filled/added by this method with the VIM identifier generated by the VIM for this
                    interface. 'net_list' is modified
        :param cloud_config: (optional) dictionary with:
            'key-pairs': (optional) list of strings with the public key to be inserted to the default user
            'users': (optional) list of users to be inserted, each item is a dict with:
                'name': (mandatory) user name,
                'key-pairs': (optional) list of strings with the public key to be inserted to the user
            'user-data': (optional) can be a string with the text script to be passed directly to cloud-init,
                or a list of strings, each one contains a script to be passed, usually with a MIMEmultipart file
            'config-files': (optional). List of files to be transferred. Each item is a dict with:
                'dest': (mandatory) string with the destination absolute path
                'encoding': (optional, by default text). Can be one of:
                    'b64', 'base64', 'gz', 'gz+b64', 'gz+base64', 'gzip+b64', 'gzip+base64'
                'content' (mandatory): string with the content of the file
                'permissions': (optional) string with file permissions, typically octal notation '0644'
                'owner': (optional) file owner, string with the format 'owner:group'
            'boot-data-drive': boolean to indicate if user-data must be passed using a boot drive (hard disk)
        :param disk_list: (optional) list with additional disks to the VM. Each item is a dict with:
            'image_id': (optional). VIM id of an existing image. If not provided an empty disk must be mounted
            'size': (mandatory) string with the size of the disk in GB
        :param availability_zone_index: Index of availability_zone_list to use for this this VM. None if not AV required
        :param availability_zone_list: list of availability zones given by user in the VNFD descriptor.  Ignore if
            availability_zone_index is None
        Returns a tuple with the instance identifier and created_items or raises an exception on error
            created_items can be None or a dictionary where this method can include key-values that will be passed to
            the method delete_vminstance and action_vminstance. Can be used to store created ports, volumes, etc.
            Format is vimconnector dependent, but do not use nested dictionaries and a value of None should be the same
            as not present.
        """
        self.logger.debug('new_vminstance with args: {}'.format(locals()))
        fdu_uuid = '{}'.format(uuid.uuid4())

        flv = self.fos_api.flavor.get(flavor_id)
        img = self.fos_api.image.get(image_id)

        if flv is None:
            raise vimconn.VimConnNotFoundException("Flavor {} not found at VIM".format(flavor_id))
        if img is None:
            raise vimconn.VimConnNotFoundException("Image {} not found at VIM".format(image_id))

        created_items = {
            'fdu_id': '',
            'node_id': '',
            'connection_points': []
        }

        fdu_desc = {
            'name': name,
            'id': fdu_uuid,
            'uuid': fdu_uuid,
            'computation_requirements': flv,
            'image': img,
            'hypervisor': self.hv,
            'migration_kind': 'LIVE',
            'interfaces': [],
            'io_ports': [],
            'connection_points': [],
            'depends_on': [],
            'storage': []
        }

        nets = []
        cps = []
        intf_id = 0
        for n in net_list:
            cp_id = '{}'.format(uuid.uuid4())
            n['vim_id'] = cp_id
            pair_id = n.get('net_id')

            cp_d = {
                'id': cp_id,
                'name': cp_id,
                'vld_ref': pair_id
            }
            intf_d = {
                'name': n.get('name', 'eth{}'.format(intf_id)),
                'is_mgmt': False,
                'if_type': 'INTERNAL',
                'virtual_interface': {
                    'intf_type': n.get('model', 'VIRTIO'),
                    'vpci': n.get('vpci', '0:0:0'),
                    'bandwidth': int(n.get('bw', 100))
                },
                'cp_id': cp_id
            }
            if n.get('mac_address', None) is not None:
                intf_d['mac_address'] = n['mac_address']

            created_items['connection_points'].append(cp_id)
            fdu_desc['connection_points'].append(cp_d)
            fdu_desc['interfaces'].append(intf_d)

            intf_id = intf_id + 1

        if cloud_config is not None:
            configuration = {'conf_type': 'CLOUD_INIT'}
            if cloud_config.get('user-data') is not None:
                configuration['script'] = cloud_config.get('user-data')
            if cloud_config.get('key-pairs') is not None:
                configuration['ssh_keys'] = cloud_config.get('key-pairs')

            if 'script' in configuration:
                fdu_desc['configuration'] = configuration

        self.logger.debug('Eclipse fog05 FDU Descriptor: {}'.format(fdu_desc))

        fdu = FDU(fdu_desc)

        try:
            self.fos_api.fdu.onboard(fdu)
            instance = self.fos_api.fdu.define(fdu_uuid)
            instance_list = self.fos_api.fdu.instance_list(fdu_uuid)
            selected_node = ''
            for n in instance_list:
                instances = instance_list[n]
                if instance.uuid in instances:
                    selected_node = n
            if selected_node == '':
                raise ValueError("Unable to find node for network creation")

            self.logger.debug('Selected node by VIM: {}'.format(selected_node))
            created_items['fdu_id'] = fdu_uuid
            created_items['node_id'] = selected_node

            for cp in fdu_desc['connection_points']:
                nets = self.fos_api.network.list()
                for net in nets:
                    if net.get('uuid') == cp['vld_ref']:
                        self.fos_api.network.add_network_to_node(net, selected_node)

            self.fos_api.fdu.configure(instance.uuid)
            self.fos_api.fdu.start(instance.uuid)

            self.logger.debug('Eclipse fog05 FDU Started {}'.format(instance.uuid))

            created_items['instance_id'] = str(instance.uuid)

            self.fdu_node_map[instance.uuid] = selected_node
            self.logger.debug('new_vminstance returns: {} {}'.format(instance.uuid, created_items))
            return str(instance.uuid), created_items
        except fimapi.FIMAResouceExistingException as free:
            raise vimconn.VimConnConflictException("VM already exists at VIM. Error {}".format(free))
        except Exception as e:
            raise vimconn.VimConnException("Error while instantiating VM {}. Error {}".format(name, e))