Просмотр исходного кода

Implement mehtods for adding/removing floating IP address to an instance

Enis Afgan 10 лет назад
Родитель
Сommit
368b052955

+ 20 - 0
cloudbridge/cloud/interfaces/resources.py

@@ -270,6 +270,26 @@ class Instance(ObjectLifeCycleMixin):
         """
         pass
 
+    @abstractmethod
+    def add_floating_ip(self, ip_address):
+        """
+        Add a public IP address to this instance.
+
+        :type ip_address: str
+        :param ip_address: The IP address to associate with the instance.
+        """
+        pass
+
+    @abstractmethod
+    def remove_floating_ip(self, ip_address):
+        """
+        Remove a public IP address from this instance.
+
+        :type ip_address: str
+        :param ip_address: The IP address to remove from the instance.
+        """
+        pass
+
 
 class MachineImageState(object):
 

+ 13 - 0
cloudbridge/cloud/providers/aws/resources.py

@@ -303,6 +303,19 @@ class AWSInstance(BaseInstance):
         image = retry_decorator(self._provider.compute.images.get)(image_id)
         return image
 
+    def add_floating_ip(self, ip_address):
+        """
+        Add an elastic IP address to this instance.
+        """
+        return self._ec2_instance.use_ip(ip_address)
+
+    def remove_floating_ip(self, ip_address):
+        """
+        Remove a elastic IP address from this instance.
+        """
+        raise NotImplementedError(
+            'remove_floating_ip not implemented by this provider.')
+
     @property
     def state(self):
         return AWSInstance.INSTANCE_STATE_MAP.get(

+ 12 - 0
cloudbridge/cloud/providers/openstack/resources.py

@@ -315,6 +315,18 @@ class OpenStackInstance(BaseInstance):
         return OpenStackMachineImage(
             self._provider, self._provider.compute.images.get(image_id))
 
+    def add_floating_ip(self, ip_address):
+        """
+        Add a floating IP address to this instance.
+        """
+        self._os_instance.add_floating_ip(ip_address)
+
+    def remove_floating_ip(self, ip_address):
+        """
+        Remove a floating IP address from this instance.
+        """
+        self._os_instance.remove_floating_ip(ip_address)
+
     @property
     def state(self):
         return OpenStackInstance.INSTANCE_STATE_MAP.get(