X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=vimconn.py;h=a9bd9be6c53fe50164db3dbac2758d293ec25594;hb=06e6c396413630640cafae3488442a0869f1642d;hp=b5f8b07084c378365741461e3882202c9ed6a016;hpb=fb1987be8f7b90e527c7596bd31a21fa8c0245f9;p=osm%2FRO.git diff --git a/vimconn.py b/vimconn.py index b5f8b070..a9bd9be6 100644 --- a/vimconn.py +++ b/vimconn.py @@ -21,10 +21,10 @@ # contact with: nfvlabs@tid.es ## -''' +""" vimconn implement an Abstract class for the vim connector plugins with the definition of the method to be implemented. -''' +""" __author__="Alfonso Tierno" __date__ ="$16-oct-2015 11:09:29$" @@ -42,57 +42,69 @@ HTTP_Service_Unavailable = 503 HTTP_Internal_Server_Error = 500 class vimconnException(Exception): - '''Common and base class Exception for all vimconnector exceptions''' + """Common and base class Exception for all vimconnector exceptions""" def __init__(self, message, http_code=HTTP_Bad_Request): Exception.__init__(self, message) self.http_code = http_code class vimconnConnectionException(vimconnException): - '''Connectivity error with the VIM''' + """Connectivity error with the VIM""" def __init__(self, message, http_code=HTTP_Service_Unavailable): vimconnException.__init__(self, message, http_code) class vimconnUnexpectedResponse(vimconnException): - '''Get an wrong response from VIM''' + """Get an wrong response from VIM""" def __init__(self, message, http_code=HTTP_Service_Unavailable): vimconnException.__init__(self, message, http_code) class vimconnAuthException(vimconnException): - '''Invalid credentials or authorization to perform this action over the VIM''' + """Invalid credentials or authorization to perform this action over the VIM""" def __init__(self, message, http_code=HTTP_Unauthorized): vimconnException.__init__(self, message, http_code) class vimconnNotFoundException(vimconnException): - '''The item is not found at VIM''' + """The item is not found at VIM""" def __init__(self, message, http_code=HTTP_Not_Found): vimconnException.__init__(self, message, http_code) class vimconnConflictException(vimconnException): - '''There is a conflict, e.g. more item found than one''' + """There is a conflict, e.g. more item found than one""" def __init__(self, message, http_code=HTTP_Conflict): vimconnException.__init__(self, message, http_code) +class vimconnNotSupportedException(vimconnException): + """The request is not supported by connector""" + def __init__(self, message, http_code=HTTP_Service_Unavailable): + vimconnException.__init__(self, message, http_code) + class vimconnNotImplemented(vimconnException): - '''The method is not implemented by the connected''' + """The method is not implemented by the connected""" def __init__(self, message, http_code=HTTP_Not_Implemented): vimconnException.__init__(self, message, http_code) class vimconnector(): - '''Abstract base class for all the VIM connector plugins + """Abstract base class for all the VIM connector plugins These plugins must implement a vimconnector class derived from this - and all these methods - ''' - def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None, log_level=None, config={}): + and all these privated methods + """ + def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None, log_level=None, + config={}, persitent_info={}): """Constructor of VIM - "uuid": id asigned to this VIM - "name": name assigned to this VIM, can be used for logging - "tenant_id", tenant_name: VIM tenant to be used - "url_admin": optional, url used for administrative tasks - "user", "passwd": credentials of the VIM user - "log_level": if must use a different log_level than the general one - "config": dictionary with extra VIM information. This contains a consolidate version of general VIM config at create - and particular VIM config at attach - Returns can raise an exception if some check is done and fails + Params: + 'uuid': id asigned to this VIM + 'name': name assigned to this VIM, can be used for logging + 'tenant_id', 'tenant_name': (only one of them is mandatory) VIM tenant to be used + 'url_admin': (optional), url used for administrative tasks + 'user', 'passwd': credentials of the VIM user + 'log_level': provider if it should use a different log_level than the general one + 'config': dictionary with extra VIM information. This contains a consolidate version of general VIM config + at creation and particular VIM config at teh attachment + 'persistent_info': dict where the class can store information that will be available among class + destroy/creation cycles. This info is unique per VIM/credential. At first call it will contain an + empty dict. Useful to store login/tokens information for speed up communication + + Returns: Raise an exception is some needed parameter is missing, but it must not do any connectivity + check against the VIM """ self.id = uuid self.name = name @@ -151,6 +163,12 @@ class vimconnector(): else: raise KeyError("Invalid key '%s'" %str(index)) + def check_vim_connectivity(self): + """Checks VIM can be reached and user credentials are ok. + Returns None if success or raised vimconnConnectionException, vimconnAuthException, ... + """ + raise vimconnNotImplemented( "Should have implemented this" ) + def new_tenant(self,tenant_name,tenant_description): """Adds a new tenant to VIM with this name and description, this is done using admin_url if provided "tenant_name": string max lenght 64 @@ -167,84 +185,118 @@ class vimconnector(): raise vimconnNotImplemented( "Should have implemented this" ) def get_tenant_list(self, filter_dict={}): - '''Obtain tenants of VIM + """Obtain tenants of VIM filter_dict dictionary that can contain the following keys: name: filter by tenant name id: filter by tenant uuid/id Returns the tenant list of dictionaries, and empty list if no tenant match all the filers: [{'name':', 'id':', ...}, ...] - ''' + """ raise vimconnNotImplemented( "Should have implemented this" ) - def new_network(self,net_name, net_type, ip_profile=None, shared=False): + def new_network(self, net_name, net_type, ip_profile=None, shared=False, vlan=None): """Adds a tenant network to VIM - net_name is the name - net_type can be 'bridge','data'.'ptp'. TODO: this need to be revised - ip_profile is a dict containing the IP parameters of the network - "ip-version": {"type":"string", "enum":["IPv4","IPv6"]}, - "subnet-address": ip_prefix_schema, - "gateway-address": ip_schema, - "dns-address": ip_schema, - "dhcp": dhcp_schema - - shared is a boolean - Returns the network identifier on success or raises and exeption on failure + 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 (Currently only IPv4 is implemented) + 'ip-version': can be one of ["IPv4","IPv6"] + '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) ip_schema, + 'dhcp': (Optional) dict containing + 'enabled': {"type": "boolean"}, + 'start-address': ip_schema, first IP to grant + 'count': number of IPs to grant. + 'shared': if this network can be seen/use by other tenants/organization + 'vlan': in case of a data or ptp net_type, the intended vlan tag to be used for the network + Returns the network identifier on success or raises and exception on failure """ raise vimconnNotImplemented( "Should have implemented this" ) def get_network_list(self, filter_dict={}): - '''Obtain tenant networks of VIM - Filter_dict can be: - name: network name - id: network uuid - shared: boolean - tenant_id: tenant - admin_state_up: boolean - status: 'ACTIVE' - Returns the network list of dictionaries: - [{}, ...] - List can be empty - ''' + """Obtain tenant networks of VIM + Params: + 'filter_dict' (optional) contains entries to return only networks that matches ALL entries: + name: string => returns only networks with this name + id: string => returns networks with this VIM id, this imply returns one network at most + shared: boolean >= returns only networks that are (or are not) shared + tenant_id: sting => returns only networks that belong to this tenant/project + ,#(not used yet) admin_state_up: boolean => returns only networks that are (or are not) in admin state active + #(not used yet) status: 'ACTIVE','ERROR',... => filter networks that are on this status + Returns the network list of dictionaries. each dictionary contains: + 'id': (mandatory) VIM network id + 'name': (mandatory) VIM network name + 'status': (mandatory) can be 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER' + 'error_msg': (optional) text that explains the ERROR status + other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param + List can be empty if no network map the filter_dict. Raise an exception only upon VIM connectivity, + authorization, or some other unspecific error + """ raise vimconnNotImplemented( "Should have implemented this" ) def get_network(self, net_id): - '''Obtain network details of net_id VIM network' - Return a dict with the fields at filter_dict (see get_network_list) plus some VIM specific>}, ...]''' + """Obtain network details from the 'net_id' VIM network + Return a dict that contains: + 'id': (mandatory) VIM network id, that is, net_id + 'name': (mandatory) VIM network name + 'status': (mandatory) can be 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER' + 'error_msg': (optional) text that explains the ERROR status + other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param + Raises an exception upon error or when network is not found + """ raise vimconnNotImplemented( "Should have implemented this" ) def delete_network(self, net_id): - '''Deletes a tenant network from VIM, provide the network id. - Returns the network identifier or raise an exception''' + """Deletes a tenant network from VIM + Returns the network identifier or raises an exception upon error or when network is not found + """ raise vimconnNotImplemented( "Should have implemented this" ) def refresh_nets_status(self, net_list): - '''Get the status of the networks - Params: the list of network identifiers - Returns a dictionary with: - net_id: #VIM id of this network - status: #Mandatory. Text with one of: - # DELETED (not found at vim) - # VIM_ERROR (Cannot connect to VIM, VIM response error, ...) - # OTHER (Vim reported other status not understood) - # ERROR (VIM indicates an ERROR status) - # ACTIVE, INACTIVE, DOWN (admin down), - # BUILD (on building process) - # - error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR - vim_info: #Text with plain information obtained from vim (yaml.safe_dump) - - ''' + """Get the status of the networks + Params: + 'net_list': a list with the VIM network id to be get the status + Returns a dictionary with: + 'net_id': #VIM id of this network + status: #Mandatory. Text with one of: + # DELETED (not found at vim) + # VIM_ERROR (Cannot connect to VIM, authentication problems, VIM response error, ...) + # OTHER (Vim reported other status not understood) + # ERROR (VIM indicates an ERROR status) + # ACTIVE, INACTIVE, DOWN (admin down), + # BUILD (on building process) + error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR + vim_info: #Text with plain information obtained from vim (yaml.safe_dump) + 'net_id2': ... + """ raise vimconnNotImplemented( "Should have implemented this" ) def get_flavor(self, flavor_id): - '''Obtain flavor details from the VIM - Returns the flavor dict details {'id':<>, 'name':<>, other vim specific } #TODO to concrete - ''' + """Obtain flavor details from the VIM + Returns the flavor dict details {'id':<>, 'name':<>, other vim specific } + Raises an exception upon error or if not found + """ raise vimconnNotImplemented( "Should have implemented this" ) - + + def get_flavor_id_from_data(self, flavor_dict): + """Obtain flavor id that match the flavor description + Params: + 'flavor_dict': dictionary that contains: + 'disk': main hard disk in GB + 'ram': meomry in MB + 'vcpus': number of virtual cpus + #TODO: complete parameters for EPA + Returns the flavor_id or raises a vimconnNotFoundException + """ + raise vimconnNotImplemented( "Should have implemented this" ) + def new_flavor(self, flavor_data): - '''Adds a tenant flavor to VIM + """Adds a tenant flavor to VIM flavor_data contains a dictionary with information, keys: name: flavor name ram: memory (cloud type) in MBytes @@ -260,38 +312,34 @@ class vimconnector(): vpci: requested virtual PCI address disk: disk size is_public: - - - #TODO to concrete - Returns the flavor identifier''' + Returns the flavor identifier""" raise vimconnNotImplemented( "Should have implemented this" ) def delete_flavor(self, flavor_id): - '''Deletes a tenant flavor from VIM identify by its id - Returns the used id or raise an exception''' + """Deletes a tenant flavor from VIM identify by its id + Returns the used id or raise an exception""" raise vimconnNotImplemented( "Should have implemented this" ) - def new_image(self,image_dict): - ''' - Adds a tenant image to VIM - Returns: - 200, image-id if the image is created - <0, message if there is an error - ''' + def new_image(self, image_dict): + """ Adds a tenant image to VIM + Returns the image id or raises an exception if failed + """ raise vimconnNotImplemented( "Should have implemented this" ) def delete_image(self, image_id): - '''Deletes a tenant image from VIM''' - '''Returns the HTTP response code and a message indicating details of the success or fail''' + """Deletes a tenant image from VIM + Returns the image_id if image is deleted or raises an exception on error""" raise vimconnNotImplemented( "Should have implemented this" ) def get_image_id_from_path(self, path): - '''Get the image id from image path in the VIM database. Returns the image_id''' + """Get the image id from image path in the VIM database. + Returns the image_id or raises a vimconnNotFoundException + """ raise vimconnNotImplemented( "Should have implemented this" ) def get_image_list(self, filter_dict={}): - '''Obtain tenant images from VIM + """Obtain tenant images from VIM Filter_dict can be: name: image name id: image uuid @@ -300,44 +348,68 @@ class vimconnector(): Returns the image list of dictionaries: [{}, ...] List can be empty - ''' + """ raise vimconnNotImplemented( "Should have implemented this" ) - def new_vminstance(self,name,description,start,image_id,flavor_id,net_list,cloud_config=None): - '''Adds a VM instance to VIM + def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None, + disk_list=None): + """Adds a VM instance to VIM Params: - start: indicates if VM must start or boot in pause mode. Ignored - image_id,flavor_id: image and flavor uuid - net_list: list of interfaces, each one is a dictionary with: - name: - net_id: network uuid to connect - vpci: virtual vcpi to assign - model: interface model, virtio, e2000, ... - mac_address: - use: 'data', 'bridge', 'mgmt' - type: 'virtual', 'PF', 'VF', 'VFnotShared' - vim_id: filled/added by this function - cloud_config: can be a text script to be passed directly to cloud-init, - or an object to inject users and ssh keys with format: - key-pairs: [] list of keys to install to the default user - users: [{ name, key-pairs: []}] list of users to add with their key-pair - #TODO ip, security groups - Returns >=0, the instance identifier - <0, error_text - ''' + 'start': (boolean) indicates if VM must start or created in pause mode. + 'image_id','flavor_id': image and flavor VIM id to use for the VM + '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, e2000, ... + 'mac_address': (optional) mac 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' + 'PF' (passthrough): depending on VIM capabilities it can be connected to a data/ptp network ot it + can created unconnected + '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 + '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) string is a text script to be passed directly to cloud-init + '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) + '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 + Returns the instance identifier or raises an exception on error + """ raise vimconnNotImplemented( "Should have implemented this" ) def get_vminstance(self,vm_id): - '''Returns the VM instance information from VIM''' + """Returns the VM instance information from VIM""" raise vimconnNotImplemented( "Should have implemented this" ) def delete_vminstance(self, vm_id): - '''Removes a VM instance from VIM''' - '''Returns the instance identifier''' + """Removes a VM instance from VIM + Returns the instance identifier""" raise vimconnNotImplemented( "Should have implemented this" ) def refresh_vms_status(self, vm_list): - '''Get the status of the virtual machines and their interfaces/ports + """Get the status of the virtual machines and their interfaces/ports Params: the list of VM identifiers Returns a dictionary with: vm_id: #VIM id of this Virtual Machine @@ -347,27 +419,30 @@ class vimconnector(): # OTHER (Vim reported other status not understood) # ERROR (VIM indicates an ERROR status) # ACTIVE, PAUSED, SUSPENDED, INACTIVE (not running), - # CREATING (on building process), ERROR + # BUILD (on building process), ERROR # ACTIVE:NoMgmtIP (Active but any of its interface has an IP address # error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR vim_info: #Text with plain information obtained from vim (yaml.safe_dump) - interfaces: - - vim_info: #Text with plain information obtained from vim (yaml.safe_dump) + interfaces: list with interface info. Each item a dictionary with: + vim_info: #Text with plain information obtained from vim (yaml.safe_dump) mac_address: #Text format XX:XX:XX:XX:XX:XX - vim_net_id: #network id where this interface is connected + vim_net_id: #network id where this interface is connected, if provided at creation vim_interface_id: #interface/port VIM id ip_address: #null, or text with IPv4, IPv6 address - ''' + physical_compute: #identification of compute node where PF,VF interface is allocated + physical_pci: #PCI address of the NIC that hosts the PF,VF + physical_vlan: #physical VLAN used for VF + """ raise vimconnNotImplemented( "Should have implemented this" ) def action_vminstance(self, vm_id, action_dict): - '''Send and action over a VM instance from VIM - Returns the vm_id if the action was successfully sent to the VIM''' + """Send and action over a VM instance from VIM + Returns the vm_id if the action was successfully sent to the VIM""" raise vimconnNotImplemented( "Should have implemented this" ) - def get_vminstance_console(self,vm_id, console_type="vnc"): - ''' + def get_vminstance_console(self, vm_id, console_type="vnc"): + """ Get a console for the virtual machine Params: vm_id: uuid of the VM @@ -379,53 +454,53 @@ class vimconnector(): server: usually ip address port: the http, ssh, ... port suffix: extra text, e.g. the http path and query string - ''' + """ raise vimconnNotImplemented( "Should have implemented this" ) #NOT USED METHODS in current version def host_vim2gui(self, host, server_dict): - '''Transform host dictionary from VIM format to GUI format, + """Transform host dictionary from VIM format to GUI format, and append to the server_dict - ''' + """ raise vimconnNotImplemented( "Should have implemented this" ) def get_hosts_info(self): - '''Get the information of deployed hosts - Returns the hosts content''' + """Get the information of deployed hosts + Returns the hosts content""" raise vimconnNotImplemented( "Should have implemented this" ) def get_hosts(self, vim_tenant): - '''Get the hosts and deployed instances - Returns the hosts content''' + """Get the hosts and deployed instances + Returns the hosts content""" raise vimconnNotImplemented( "Should have implemented this" ) def get_processor_rankings(self): - '''Get the processor rankings in the VIM database''' + """Get the processor rankings in the VIM database""" raise vimconnNotImplemented( "Should have implemented this" ) def new_host(self, host_data): - '''Adds a new host to VIM''' - '''Returns status code of the VIM response''' + """Adds a new host to VIM""" + """Returns status code of the VIM response""" raise vimconnNotImplemented( "Should have implemented this" ) def new_external_port(self, port_data): - '''Adds a external port to VIM''' - '''Returns the port identifier''' + """Adds a external port to VIM""" + """Returns the port identifier""" raise vimconnNotImplemented( "Should have implemented this" ) def new_external_network(self,net_name,net_type): - '''Adds a external network to VIM (shared)''' - '''Returns the network identifier''' + """Adds a external network to VIM (shared)""" + """Returns the network identifier""" raise vimconnNotImplemented( "Should have implemented this" ) def connect_port_network(self, port_id, network_id, admin=False): - '''Connects a external port to a network''' - '''Returns status code of the VIM response''' + """Connects a external port to a network""" + """Returns status code of the VIM response""" raise vimconnNotImplemented( "Should have implemented this" ) def new_vminstancefromJSON(self, vm_data): - '''Adds a VM instance to VIM''' - '''Returns the instance identifier''' + """Adds a VM instance to VIM""" + """Returns the instance identifier""" raise vimconnNotImplemented( "Should have implemented this" )