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

Add methods for listing static IPs.

No tests but tests require methods for adding and removing static IPs so leaving that as a future TODO.
Enis Afgan 10 лет назад
Родитель
Сommit
93ee031ee0

+ 13 - 0
cloudbridge/cloud/interfaces/services.py

@@ -554,6 +554,19 @@ class NetworkService(PageableObjectMixin, CloudService):
         """
         pass
 
+    @abstractproperty
+    def static_ips(self, network_id=None):
+        """
+        List static IP addresses.
+
+        :type: ``str``
+        :param: The ID of the network by which to filter the IPs.
+
+        :rtype: ``lsit`` of strings
+        :return: list of static IPs
+        """
+        pass
+
 
 class SubnetService(PageableObjectMixin, CloudService):
 

+ 7 - 0
cloudbridge/cloud/providers/aws/services.py

@@ -790,6 +790,13 @@ class AWSNetworkService(BaseNetworkService):
     def subnets(self):
         return self._subnet_svc
 
+    def static_ips(self, network_id=None):
+        fltrs = None
+        if network_id:
+            fltrs = {'network-interface-id': network_id}
+        al = self.provider.vpc_conn.get_all_addresses(filters=fltrs)
+        return [a.public_ip for a in al]
+
 
 class AWSSubnetService(BaseSubnetService):
 

+ 8 - 0
cloudbridge/cloud/providers/openstack/services.py

@@ -725,6 +725,14 @@ class OpenStackNetworkService(BaseNetworkService):
     def subnets(self):
         return self._subnet_svc
 
+    def static_ips(self, network_id=None):
+        if network_id:
+            al = self.provider.neutron.list_floatingips(
+                floating_network_id=network_id)['floatingips']
+        else:
+            al = self.provider.neutron.list_floatingips()['floatingips']
+        return [a.get('floating_ip_address') for a in al]
+
 
 class OpenStackSubnetService(BaseSubnetService):