Przeglądaj źródła

Update add/remove instance FIP to accept FIP object only

It'd be better if a floating IP object ID cloud be supplied as an alternative to only the FIP object but to retrieve the FIP object based on its ID, we'd need also a gateway ID. Perhaps we could do a provider-specific search with the ID...
Enis Afgan 8 lat temu
rodzic
commit
871bc2c9fe

+ 8 - 2
cloudbridge/cloud/interfaces/resources.py

@@ -584,7 +584,10 @@ class Instance(ObjectLifeCycleMixin, CloudResource):
         Add a public IP address to this instance.
         Add a public IP address to this instance.
 
 
         :type floating_ip: :class:``.FloatingIP``
         :type floating_ip: :class:``.FloatingIP``
-        :param floating_ip: The FloatingIP to associate with the instance.
+        :param floating_ip: The FloatingIP object to associate with the
+                            instance. Note that is not the actual public IP
+                            address but the CloudBridge object encapsulating
+                            the IP.
         """
         """
         pass
         pass
 
 
@@ -594,7 +597,10 @@ class Instance(ObjectLifeCycleMixin, CloudResource):
         Remove a public IP address from this instance.
         Remove a public IP address from this instance.
 
 
         :type floating_ip: :class:``.FloatingIP``
         :type floating_ip: :class:``.FloatingIP``
-        :param floating_ip: The IP address to remove from the instance.
+        :param floating_ip: The FloatingIP object to remove from the
+                            instance. Note that is not the actual public IP
+                            address but the CloudBridge object encapsulating
+                            the IP.
         """
         """
         pass
         pass
 
 

+ 6 - 11
cloudbridge/cloud/providers/aws/resources.py

@@ -297,26 +297,21 @@ class AWSInstance(BaseInstance):
         return image
         return image
 
 
     def add_floating_ip(self, floating_ip):
     def add_floating_ip(self, floating_ip):
-        fip = (
-            floating_ip if isinstance(floating_ip, AWSFloatingIP) else
-            [ip for ip in self._provider.networking.floating_ips.list()
-             if ip.public_ip == floating_ip][0])
         params = trim_empty_params({
         params = trim_empty_params({
             'InstanceId': self.id,
             'InstanceId': self.id,
-            'PublicIp': None if self._ec2_instance.vpc_id else fip.public_ip,
+            'PublicIp': None if self._ec2_instance.vpc_id else
+            floating_ip.public_ip,
             # pylint:disable=protected-access
             # pylint:disable=protected-access
-            'AllocationId': fip._ip.allocation_id})
+            'AllocationId': floating_ip._ip.allocation_id})
         self._provider.ec2_conn.meta.client.associate_address(**params)
         self._provider.ec2_conn.meta.client.associate_address(**params)
         self.refresh()
         self.refresh()
 
 
     def remove_floating_ip(self, floating_ip):
     def remove_floating_ip(self, floating_ip):
-        fip = (
-            floating_ip if isinstance(floating_ip, AWSFloatingIP) else
-            self._provider.networking.floating_ips.get(floating_ip))
         params = trim_empty_params({
         params = trim_empty_params({
-            'PublicIp': None if self._ec2_instance.vpc_id else fip.public_ip,
+            'PublicIp': None if self._ec2_instance.vpc_id else
+            floating_ip.public_ip,
             # pylint:disable=protected-access
             # pylint:disable=protected-access
-            'AssociationId': fip._ip.association_id})
+            'AssociationId': floating_ip._ip.association_id})
         self._provider.ec2_conn.meta.client.disassociate_address(**params)
         self._provider.ec2_conn.meta.client.disassociate_address(**params)
         self.refresh()
         self.refresh()
 
 

+ 2 - 8
cloudbridge/cloud/providers/azure/resources.py

@@ -1443,17 +1443,11 @@ class AzureInstance(BaseInstance):
 
 
     def add_floating_ip(self, floating_ip):
     def add_floating_ip(self, floating_ip):
         """
         """
-        Attaches public ip to the instance
-        :param ip_address:
-        :return:
+        Attaches public ip to the instance.
         """
         """
-        fip = (floating_ip if isinstance(floating_ip, AzureFloatingIP) else
-               self._provider.networking.floating_ips.get(floating_ip))
-
         nic = self._provider.azure_client.get_nic(self._nic_ids[0])
         nic = self._provider.azure_client.get_nic(self._nic_ids[0])
-
         nic.ip_configurations[0].public_ip_address = {
         nic.ip_configurations[0].public_ip_address = {
-            'id': fip.id
+            'id': floating_ip.id
         }
         }
         self._provider.azure_client.update_nic(self._nic_ids[0], nic)
         self._provider.azure_client.update_nic(self._nic_ids[0], nic)