Bug782 fix: use_existing_flavors flag was not working
[osm/RO.git] / osm_ro / vimconn_aws.py
index 12b2411..bcd8cbc 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))
@@ -296,11 +299,16 @@ class vimconnector(vimconn.vimconnector):
                     '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
+        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.
+            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("Adding a subnet to VPC")
         try:
+            created_items = {}
             self._reload_connection()
             subnet = None
             vpc_id = self.vpc_id
@@ -311,7 +319,7 @@ class vimconnector(vimconn.vimconnector):
                 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]
             subnet = self.conn_vpc.create_subnet(vpc_id, cidr_block)
-            return subnet.id
+            return subnet.id, created_items
         except Exception as e:
             self.format_vimconn_exception(e)
 
@@ -381,8 +389,11 @@ class vimconnector(vimconn.vimconnector):
         except Exception as e:
             self.format_vimconn_exception(e)
 
-    def delete_network(self, net_id):
-        """Deletes a tenant network from VIM
+    def delete_network(self, net_id, created_items=None):
+        """
+        Removes a tenant network from VIM and its associated elements
+        :param net_id: VIM identifier of the network, provided by method new_network
+        :param created_items: dictionary with extra items to be deleted. provided by method new_network
         Returns the network identifier or raises an exception upon error or when network is not found
         """
 
@@ -601,7 +612,7 @@ 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'