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

Added ObjectLifeCycle to floating ip

Nuwan Goonasekera 8 лет назад
Родитель
Сommit
cd102303a4

+ 14 - 1
cloudbridge/cloud/base/resources.py

@@ -19,6 +19,7 @@ from cloudbridge.cloud.interfaces.resources import BucketContainer
 from cloudbridge.cloud.interfaces.resources import BucketObject
 from cloudbridge.cloud.interfaces.resources import CloudResource
 from cloudbridge.cloud.interfaces.resources import FloatingIP
+from cloudbridge.cloud.interfaces.resources import FloatingIpState
 from cloudbridge.cloud.interfaces.resources import GatewayState
 from cloudbridge.cloud.interfaces.resources import Instance
 from cloudbridge.cloud.interfaces.resources import InstanceState
@@ -976,7 +977,7 @@ class BaseSubnet(BaseCloudResource, BaseObjectLifeCycleMixin, Subnet):
             interval=interval)
 
 
-class BaseFloatingIP(BaseCloudResource, FloatingIP):
+class BaseFloatingIP(BaseCloudResource, BaseObjectLifeCycleMixin, FloatingIP):
 
     def __init__(self, provider):
         super(BaseFloatingIP, self).__init__(provider)
@@ -988,6 +989,18 @@ class BaseFloatingIP(BaseCloudResource, FloatingIP):
         """
         return self.public_ip
 
+    @property
+    def state(self):
+        return (FloatingIpState.IN_USE if self.in_use
+                else FloatingIpState.AVAILABLE)
+
+    def wait_till_ready(self, timeout=None, interval=None):
+        self.wait_for(
+            [FloatingIpState.AVAILABLE, FloatingIpState.IN_USE],
+            terminal_states=[FloatingIpState.ERROR],
+            timeout=timeout,
+            interval=interval)
+
     def __repr__(self):
         return "<CB-{0}: {1} ({2})>".format(self.__class__.__name__,
                                             self.id, self.public_ip)

+ 21 - 5
cloudbridge/cloud/interfaces/resources.py

@@ -790,8 +790,8 @@ class NetworkState(object):
     :cvar UNKNOWN: Network state unknown.
     :cvar PENDING: Network is being created.
     :cvar AVAILABLE: Network is available.
-    :cvar DOWN = Network is not operational.
-    :cvar ERROR = Network errored.
+    :cvar DOWN: Network is not operational.
+    :cvar ERROR: Network errored.
     """
     UNKNOWN = "unknown"
     PENDING = "pending"
@@ -890,8 +890,8 @@ class SubnetState(object):
     :cvar UNKNOWN: Subnet state unknown.
     :cvar PENDING: Subnet is being created.
     :cvar AVAILABLE: Subnet is available.
-    :cvar DOWN = Subnet is not operational.
-    :cvar ERROR = Subnet errored.
+    :cvar DOWN: Subnet is not operational.
+    :cvar ERROR: Subnet errored.
     """
     UNKNOWN = "unknown"
     PENDING = "pending"
@@ -949,7 +949,23 @@ class Subnet(ObjectLifeCycleMixin, CloudResource):
         pass
 
 
-class FloatingIP(CloudResource):
+class FloatingIpState(object):
+
+    """
+    Standard states for a floating ip.
+
+    :cvar UNKNOWN: Floating IP state unknown.
+    :cvar AVAILABLE: Floating IP is available.
+    :cvar IN_USE: Floating IP is attached to a device.
+    :cvar ERROR: Floating IP is in an error state.
+    """
+    UNKNOWN = "unknown"
+    AVAILABLE = "available"
+    IN_USE = "in_use"
+    ERROR = "error"
+
+
+class FloatingIP(ObjectLifeCycleMixin, CloudResource):
     """
     Represents a floating (i.e., static) IP address.
     """

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

@@ -1027,6 +1027,11 @@ class AWSFloatingIP(BaseFloatingIP):
     def delete(self):
         self._ip.release()
 
+    def refresh(self):
+        fip = self._provider.networking.floating_ips.get(self.id)
+        # pylint:disable=protected-access
+        self._ip = fip._ip
+
 
 class AWSRouter(BaseRouter):
 

+ 5 - 0
cloudbridge/cloud/providers/azure/resources.py

@@ -1015,6 +1015,11 @@ class AzureFloatingIP(BaseFloatingIP):
             log.exception(cloudError.message)
             return False
 
+    def refresh(self):
+        fip = self._provider.networking.floating_ips.get(self.id)
+        # pylint:disable=protected-access
+        self._ip = fip._ip
+
 
 class AzureRegion(BaseRegion):
     def __init__(self, provider, azure_region):

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

@@ -879,6 +879,11 @@ class OpenStackFloatingIP(BaseFloatingIP):
     def delete(self):
         self._ip.delete(self._provider.os_conn.session)
 
+    def refresh(self):
+        fip = self._provider.networking.floating_ips.get(self.id)
+        # pylint:disable=protected-access
+        self._ip = fip._ip
+
 
 class OpenStackRouter(BaseRouter):