Merge remote-tracking branch 'upstream/master' into gerrit-submission
[osm/RO.git] / osm_ro / vimconn_aws.py
index 5ee75e4..22103d0 100644 (file)
@@ -78,7 +78,7 @@ class vimconnector(vimconn.vimconnector):
         if 'region_name' in config:
             self.region = config.get('region_name')
         else:
-            raise vimconn.vimconnNotFoundException("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 = {}
@@ -109,8 +109,11 @@ class vimconnector(vimconn.vimconnector):
             flavor_data = config.get('flavor_info')
             if isinstance(flavor_data, str):
                 try:
-                    with open(flavor_data[1:], 'r') as stream:
-                        self.flavor_info = yaml.load(stream)
+                    if flavor_data[0] == "@":  # read from a file
+                        with open(flavor_data[1:], 'r') as stream:
+                            self.flavor_info = yaml.load(stream)
+                    else:
+                        self.flavor_info = yaml.load(flavor_data)
                 except yaml.YAMLError as e:
                     self.flavor_info = None
                     raise vimconn.vimconnException("Bad format at file '{}': {}".format(flavor_data[1:], e))
@@ -601,13 +604,13 @@ class vimconnector(vimconn.vimconnector):
                     name
                     net_id - subnet_id from AWS
                     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, ...
+                    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'
-                        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,7 +637,11 @@ 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")
@@ -651,9 +658,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,
@@ -672,7 +677,6 @@ class vimconnector(vimconn.vimconnector):
                             network_interfaces=boto.ec2.networkinterface.NetworkInterfaceCollection(net_intr),
                             user_data=userdata
                         )
-                        instance = reservation.instances[0]
                     else:
                         while True:
                             try:
@@ -682,7 +686,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)
 
@@ -696,7 +703,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"""
 
@@ -772,7 +779,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"""
 
@@ -787,6 +794,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)