X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fvimconn_aws.py;h=12b24118a71ce1d5e5ef5c6bffc55a08ec29ae6b;hb=66eba6ece53cd85d0efbe8b4ff4f414c812b347b;hp=3cccbfcf9cd547b48a0be548c5dc7ed6486eeb51;hpb=a92a0eaaf370c626b442863f4127cd11fc64754c;p=osm%2FRO.git diff --git a/osm_ro/vimconn_aws.py b/osm_ro/vimconn_aws.py index 3cccbfcf..12b24118 100644 --- a/osm_ro/vimconn_aws.py +++ b/osm_ro/vimconn_aws.py @@ -605,9 +605,9 @@ class vimconnector(vimconn.vimconnector): 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' - 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. + '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 @@ -634,59 +634,18 @@ class vimconnector(vimconn.vimconnector): 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: instance identifier or raises an exception on error + 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("Creating a new VM instance") try: self._reload_connection() instance = None - userdata = None - if isinstance(cloud_config, dict): - if cloud_config.get("user-data"): - userdata = cloud_config["user-data"] - if cloud_config.get("config-files") or cloud_config.get("users") or cloud_config.get("key-pairs"): - if userdata: - raise vimconn.vimconnConflictException( - "Cloud-config cannot contain both 'userdata' and 'config-files'/'users'/'key-pairs'") - userdata_dict = {} - # default user - if cloud_config.get("key-pairs"): - userdata_dict["ssh-authorized-keys"] = cloud_config["key-pairs"] - userdata_dict["users"] = [{"default": None, "ssh-authorized-keys": cloud_config["key-pairs"]}] - if cloud_config.get("users"): - if "users" not in userdata_dict: - userdata_dict["users"] = ["default"] - for user in cloud_config["users"]: - user_info = { - "name": user["name"], - "sudo": "ALL = (ALL)NOPASSWD:ALL" - } - if "user-info" in user: - user_info["gecos"] = user["user-info"] - if user.get("key-pairs"): - user_info["ssh-authorized-keys"] = user["key-pairs"] - userdata_dict["users"].append(user_info) - - if cloud_config.get("config-files"): - userdata_dict["write_files"] = [] - for file in cloud_config["config-files"]: - file_info = { - "path": file["dest"], - "content": file["content"] - } - if file.get("encoding"): - file_info["encoding"] = file["encoding"] - if file.get("permissions"): - file_info["permissions"] = file["permissions"] - if file.get("owner"): - file_info["owner"] = file["owner"] - userdata_dict["write_files"].append(file_info) - userdata = "#cloud-config\n" - userdata += yaml.safe_dump(userdata_dict, indent=4, default_flow_style=False) - self.logger.debug("userdata: %s", userdata) - elif isinstance(cloud_config, str): - userdata = cloud_config + _, userdata = self._create_user_data(cloud_config) if not net_list: reservation = self.conn.run_instances( @@ -696,9 +655,7 @@ class vimconnector(vimconn.vimconnector): security_groups=self.security_groups, user_data=userdata ) - instance = reservation.instances[0] else: - net_list = [net_list[0]] for index, subnet in enumerate(net_list): net_intr = boto.ec2.networkinterface.NetworkInterfaceSpecification(subnet_id=subnet.get('net_id'), groups=None, @@ -717,7 +674,6 @@ class vimconnector(vimconn.vimconnector): network_interfaces=boto.ec2.networkinterface.NetworkInterfaceCollection(net_intr), user_data=userdata ) - instance = reservation.instances[0] else: while True: try: @@ -727,7 +683,10 @@ class vimconnector(vimconn.vimconnector): break except: time.sleep(10) - return instance.id + net_list[index]['vim_id'] = reservation.instances[0].interfaces[index].id + + instance = reservation.instances[0] + return instance.id, None except Exception as e: self.format_vimconn_exception(e) @@ -741,7 +700,7 @@ class vimconnector(vimconn.vimconnector): except Exception as e: self.format_vimconn_exception(e) - def delete_vminstance(self, vm_id): + def delete_vminstance(self, vm_id, created_items=None): """Removes a VM instance from VIM Returns the instance identifier""" @@ -817,7 +776,7 @@ class vimconnector(vimconn.vimconnector): self.logger.error("Exception getting vm status: %s", str(e), exc_info=True) self.format_vimconn_exception(e) - def action_vminstance(self, vm_id, action_dict): + def action_vminstance(self, vm_id, action_dict, created_items={}): """Send and action over a VM instance from VIM Returns the vm_id if the action was successfully sent to the VIM""" @@ -832,6 +791,6 @@ class vimconnector(vimconn.vimconnector): self.conn.terminate_instances(vm_id) elif "reboot" in action_dict: self.conn.reboot_instances(vm_id) - return vm_id + return None except Exception as e: self.format_vimconn_exception(e)