X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=RO-VIM-aws%2Fosm_rovim_aws%2Fvimconn_aws.py;h=11442922e5de12aa94174006acbff240f2ddcd9b;hb=3f8f2f4707c2a5095fd5cb9cc6602e7e9f33dbd8;hp=8173662ec2a4485ac6a6fbc69988caf61f2805b2;hpb=7d782eff123e5b44d41437377ccca66ad1e8b21b;p=osm%2FRO.git diff --git a/RO-VIM-aws/osm_rovim_aws/vimconn_aws.py b/RO-VIM-aws/osm_rovim_aws/vimconn_aws.py index 8173662e..11442922 100644 --- a/RO-VIM-aws/osm_rovim_aws/vimconn_aws.py +++ b/RO-VIM-aws/osm_rovim_aws/vimconn_aws.py @@ -28,7 +28,7 @@ AWS-connector implements all the methods to interact with AWS using the BOTO cli __author__ = "Saboor Ahmad" __date__ = "10-Apr-2017" -from osm_ro import vimconn +from osm_ro_plugin import vimconn import yaml import logging import netaddr @@ -39,7 +39,7 @@ import boto.ec2 import boto.vpc -class vimconnector(vimconn.vimconnector): +class vimconnector(vimconn.VimConnector): def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None, log_level=None, config={}, persistent_info={}): """ Params: uuid - id asigned to this VIM @@ -59,7 +59,7 @@ class vimconnector(vimconn.vimconnector): empty dict. Useful to store login/tokens information for speed up communication """ - vimconn.vimconnector.__init__(self, uuid, name, tenant_id, tenant_name, url, url_admin, user, passwd, log_level, + vimconn.VimConnector.__init__(self, uuid, name, tenant_id, tenant_name, url, url_admin, user, passwd, log_level, config, persistent_info) self.persistent_info = persistent_info @@ -67,15 +67,15 @@ class vimconnector(vimconn.vimconnector): if user: self.a_creds['aws_access_key_id'] = user else: - raise vimconn.vimconnAuthException("Username is not specified") + raise vimconn.VimConnAuthException("Username is not specified") if passwd: self.a_creds['aws_secret_access_key'] = passwd else: - raise vimconn.vimconnAuthException("Password is not specified") + raise vimconn.VimConnAuthException("Password is not specified") if 'region_name' in config: self.region = config.get('region_name') else: - raise vimconn.vimconnException("AWS region_name is not specified at config") + raise vimconn.VimConnException("AWS region_name is not specified at config") self.vpc_data = {} self.subnet_data = {} @@ -113,13 +113,13 @@ class vimconnector(vimconn.vimconnector): self.flavor_info = yaml.load(flavor_data, Loader=yaml.Loader) except yaml.YAMLError as e: self.flavor_info = None - raise vimconn.vimconnException("Bad format at file '{}': {}".format(flavor_data[1:], e)) + raise vimconn.VimConnException("Bad format at file '{}': {}".format(flavor_data[1:], e)) except IOError as e: - raise vimconn.vimconnException("Error reading file '{}': {}".format(flavor_data[1:], e)) + raise vimconn.VimConnException("Error reading file '{}': {}".format(flavor_data[1:], e)) elif isinstance(flavor_data, dict): self.flavor_info = flavor_data - self.logger = logging.getLogger('openmano.vim.aws') + self.logger = logging.getLogger('ro.vim.aws') if log_level: self.logger.setLevel(getattr(logging, log_level)) @@ -134,7 +134,7 @@ class vimconnector(vimconn.vimconnector): elif index == 'region': self.region = value else: - vimconn.vimconnector.__setitem__(self, index, value) + vimconn.VimConnector.__setitem__(self, index, value) def _reload_connection(self): """Returns: sets boto.EC2 and boto.VPC connection to work with AWS services @@ -145,7 +145,8 @@ class vimconnector(vimconn.vimconnector): aws_secret_access_key=self.a_creds['aws_secret_access_key']) self.conn_vpc = boto.vpc.connect_to_region(self.region, aws_access_key_id=self.a_creds['aws_access_key_id'], aws_secret_access_key=self.a_creds['aws_secret_access_key']) - # client = boto3.client("sts", aws_access_key_id=self.a_creds['aws_access_key_id'], aws_secret_access_key=self.a_creds['aws_secret_access_key']) + # client = boto3.client("sts", aws_access_key_id=self.a_creds['aws_access_key_id'], + # aws_secret_access_key=self.a_creds['aws_secret_access_key']) # self.account_id = client.get_caller_identity()["Account"] except Exception as e: self.format_vimconn_exception(e) @@ -157,7 +158,7 @@ class vimconnector(vimconn.vimconnector): self.conn = None self.conn_vpc = None - raise vimconn.vimconnConnectionException(type(e).__name__ + ": " + str(e)) + raise vimconn.VimConnConnectionException(type(e).__name__ + ": " + str(e)) def get_availability_zones_list(self): """Obtain AvailabilityZones from AWS @@ -251,7 +252,7 @@ class vimconnector(vimconn.vimconnector): if availability_zones != 2 and availability_zones != 3: self.logger.debug("Number of AZs should be 2 or 3") - raise vimconn.vimconnNotSupportedException("Number of AZs should be 2 or 3") + raise vimconn.VimConnNotSupportedException("Number of AZs should be 2 or 3") netmasks = ('255.255.252.0', '255.255.254.0', '255.255.255.0', '255.255.255.128') ip = netaddr.IPNetwork(cidr) @@ -259,7 +260,7 @@ class vimconnector(vimconn.vimconnector): if str(mask) not in netmasks: self.logger.debug("Netmask " + str(mask) + " not found") - raise vimconn.vimconnNotFoundException("Netmask " + str(mask) + " not found") + raise vimconn.VimConnNotFoundException("Netmask " + str(mask) + " not found") if availability_zones == 2: for n, netmask in enumerate(netmasks): @@ -277,7 +278,7 @@ class vimconnector(vimconn.vimconnector): return map(str, subnets) - def new_network(self, net_name, net_type, ip_profile=None, shared=False, vlan=None): + 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 @@ -295,7 +296,6 @@ class vimconnector(vimconn.vimconnector): '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 a tuple with the network 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_network. Can be used to store created segments, created l2gw connections, etc. @@ -310,11 +310,13 @@ class vimconnector(vimconn.vimconnector): subnet = None vpc_id = self.vpc_id if self.vpc_data.get(vpc_id, None): - cidr_block = list(set(self.vpc_data[vpc_id]['subnets']) - set(self.get_network_details({'tenant_id': vpc_id}, detail='cidr_block')))[0] + cidr_block = list(set(self.vpc_data[vpc_id]['subnets']) - + set(self.get_network_details({'tenant_id': vpc_id}, detail='cidr_block')))[0] else: vpc = self.get_tenant_list({'id': vpc_id})[0] subnet_list = self.subnet_sizes(len(self.get_availability_zones_list()), vpc['cidr_block']) - cidr_block = list(set(subnet_list) - set(self.get_network_details({'tenant_id': vpc['id']}, detail='cidr_block')))[0] + cidr_block = list(set(subnet_list) - set(self.get_network_details({'tenant_id': vpc['id']}, + detail='cidr_block')))[0] subnet = self.conn_vpc.create_subnet(vpc_id, cidr_block) return subnet.id, created_items except Exception as e: @@ -337,7 +339,8 @@ class vimconnector(vimconn.vimconnector): 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) 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 @@ -436,13 +439,13 @@ class vimconnector(vimconn.vimconnector): else: subnet_dict['status'] = 'ERROR' subnet_dict['error_msg'] = '' - except Exception as e: + except Exception: subnet_dict['status'] = 'DELETED' subnet_dict['error_msg'] = 'Network not found' finally: try: subnet_dict['vim_info'] = yaml.safe_dump(subnet, default_flow_style=True, width=256) - except yaml.YAMLError as e: + except yaml.YAMLError: subnet_dict['vim_info'] = str(subnet) dict_entry[net_id] = subnet_dict return dict_entry @@ -460,7 +463,7 @@ class vimconnector(vimconn.vimconnector): if flavor_id in self.flavor_info: return self.flavor_info[flavor_id] else: - raise vimconn.vimconnNotFoundException("Cannot find flavor with this flavor ID/Name") + raise vimconn.VimConnNotFoundException("Cannot find flavor with this flavor ID/Name") except Exception as e: self.format_vimconn_exception(e) @@ -480,37 +483,41 @@ class vimconnector(vimconn.vimconnector): flavor = None for key, values in self.flavor_info.items(): if (values["ram"], values["cpus"], values["disk"]) == ( - flavor_dict["ram"], flavor_dict["vcpus"], flavor_dict["disk"]): + flavor_dict["ram"], flavor_dict["vcpus"], flavor_dict["disk"]): flavor = (key, values) break elif (values["ram"], values["cpus"], values["disk"]) >= ( - flavor_dict["ram"], flavor_dict["vcpus"], flavor_dict["disk"]): + flavor_dict["ram"], flavor_dict["vcpus"], flavor_dict["disk"]): if not flavor: flavor = (key, values) else: if (flavor[1]["ram"], flavor[1]["cpus"], flavor[1]["disk"]) >= ( - values["ram"], values["cpus"], values["disk"]): + values["ram"], values["cpus"], values["disk"]): flavor = (key, values) if flavor: return flavor[0] - raise vimconn.vimconnNotFoundException("Cannot find flavor with this flavor ID/Name") + raise vimconn.VimConnNotFoundException("Cannot find flavor with this flavor ID/Name") except Exception as e: self.format_vimconn_exception(e) def new_image(self, image_dict): """ Adds a tenant image to VIM Params: image_dict - name (string) - The name of the AMI. Valid only for EBS-based images. - description (string) - The description of the AMI. - image_location (string) - Full path to your AMI manifest in Amazon S3 storage. Only used for S3-based AMI’s. - architecture (string) - The architecture of the AMI. Valid choices are: * i386 * x86_64 - kernel_id (string) - The ID of the kernel with which to launch the instances - root_device_name (string) - The root device name (e.g. /dev/sdh) - block_device_map (boto.ec2.blockdevicemapping.BlockDeviceMapping) - A BlockDeviceMapping data structure describing the EBS volumes associated with the Image. - virtualization_type (string) - The virutalization_type of the image. Valid choices are: * paravirtual * hvm - sriov_net_support (string) - Advanced networking support. Valid choices are: * simple - snapshot_id (string) - A snapshot ID for the snapshot to be used as root device for the image. Mutually exclusive with block_device_map, requires root_device_name - delete_root_volume_on_termination (bool) - Whether to delete the root volume of the image after instance termination. Only applies when creating image from snapshot_id. Defaults to False. Note that leaving volumes behind after instance termination is not free + name (string) - The name of the AMI. Valid only for EBS-based images. + description (string) - The description of the AMI. + image_location (string) - Full path to your AMI manifest in Amazon S3 storage. Only used for S3-based AMI’s. + architecture (string) - The architecture of the AMI. Valid choices are: * i386 * x86_64 + kernel_id (string) - The ID of the kernel with which to launch the instances + root_device_name (string) - The root device name (e.g. /dev/sdh) + block_device_map (boto.ec2.blockdevicemapping.BlockDeviceMapping) - A BlockDeviceMapping data structure + describing the EBS volumes associated with the Image. + virtualization_type (string) - The virutalization_type of the image. Valid choices are: * paravirtual * hvm + sriov_net_support (string) - Advanced networking support. Valid choices are: * simple + snapshot_id (string) - A snapshot ID for the snapshot to be used as root device for the image. Mutually + exclusive with block_device_map, requires root_device_name + delete_root_volume_on_termination (bool) - Whether to delete the root volume of the image after instance + termination. Only applies when creating image from snapshot_id. Defaults to False. Note that leaving + volumes behind after instance termination is not free Returns: image_id - image ID of the newly created image """ @@ -608,19 +615,23 @@ class vimconnector(vimconn.vimconnector): net_list name net_id - subnet_id from AWS - vpci - (optional) virtual vPCI address to assign at the VM. Can be ignored depending on VIM capabilities + 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 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 + '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 + 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 - vim_id': must be filled/added by this method with the VIM identifier generated by the VIM for this interface. 'net_list' is modified + 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 + vim_id': must be filled/added by this method with the VIM identifier generated by the VIM for this + interface. 'net_list' is modified elastic_ip - True/False to define if an elastic_ip is required cloud_config': (optional) dictionary with: key-pairs': (optional) list of strings with the public key to be inserted to the default user @@ -689,7 +700,7 @@ class vimconnector(vimconn.vimconnector): network_interface_id=boto.ec2.networkinterface.NetworkInterfaceCollection(net_intr), instance_id=instance.id, device_index=0) break - except: + except Exception: time.sleep(10) net_list[index]['vim_id'] = reservation.instances[0].interfaces[index].id @@ -763,7 +774,7 @@ class vimconnector(vimconn.vimconnector): interface_dict['vim_interface_id'] = interface.id interface_dict['vim_net_id'] = interface.subnet_id interface_dict['mac_address'] = interface.mac_address - if hasattr(interface, 'publicIp') and interface.publicIp != None: + if hasattr(interface, 'publicIp') and interface.publicIp is not None: interface_dict['ip_address'] = interface.publicIp + ";" + interface.private_ip_address else: interface_dict['ip_address'] = interface.private_ip_address @@ -775,7 +786,7 @@ class vimconnector(vimconn.vimconnector): finally: try: instance_dict['vim_info'] = yaml.safe_dump(instance, default_flow_style=True, width=256) - except yaml.YAMLError as e: + except yaml.YAMLError: # self.logger.error("Exception getting vm status: %s", str(e), exc_info=True) instance_dict['vim_info'] = str(instance) instances[instance.id] = instance_dict