libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r1392694 - /libcloud/trunk/libcloud/compute/drivers/openstack.py
Date Mon, 01 Oct 2012 23:37:12 GMT
Author: pquerna
Date: Mon Oct  1 23:37:12 2012
New Revision: 1392694

URL: http://svn.apache.org/viewvc?rev=1392694&view=rev
Log:
Add basic support for OpenStack Quantum networks API extensions.

Modified:
    libcloud/trunk/libcloud/compute/drivers/openstack.py

Modified: libcloud/trunk/libcloud/compute/drivers/openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/openstack.py?rev=1392694&r1=1392693&r2=1392694&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/openstack.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/openstack.py Mon Oct  1 23:37:12 2012
@@ -904,6 +904,23 @@ class OpenStack_1_1_Response(OpenStackRe
         super(OpenStack_1_1_Response, self).__init__(*args, **kwargs)
 
 
+class OpenStackNetwork(object):
+    """
+    A Virtual Network.
+    """
+
+    def __init__(self, id, name, cidr, driver, extra=None):
+        self.id = str(id)
+        self.name = name
+        self.cidr = cidr
+        self.driver = driver
+        self.extra = extra or {}
+
+    def __repr__(self):
+        return '<OpenStackNetwork id="%s" name="%s" cidr="%s">' % (self.id,
+               self.name, self.cidr,)
+
+
 class OpenStack_1_1_Connection(OpenStackComputeConnection):
     responseCls = OpenStack_1_1_Response
     accept_format = 'application/json'
@@ -947,6 +964,9 @@ class OpenStack_1_1_NodeDriver(OpenStack
                                  see
                                  https://help.ubuntu.com/community/CloudInit
         @type       ex_userdata: C{str}
+
+        @keyword    networks: The server is launched into a set of Networks.
+        @type       networks: C{OpenStackNetwork}
         """
 
         server_params = self._create_args_to_params(None, **kwargs)
@@ -1013,6 +1033,11 @@ class OpenStack_1_1_NodeDriver(OpenStack
             server_params['user_data'] = base64.b64encode(
                 b(kwargs['ex_userdata'])).decode('ascii')
 
+        if 'networks' in kwargs:
+            networks = kwargs['networks']
+            networks = [{'uuid': network.id} for network in networks]
+            server_params['networks'] = networks
+
         if 'name' in kwargs:
             server_params['name'] = kwargs.get('name')
         else:
@@ -1201,6 +1226,46 @@ class OpenStack_1_1_NodeDriver(OpenStack
         updates = {'name': potential_data['name']}
         return self._update_node(node, **updates)
 
+    def _to_networks(self, obj):
+        networks = obj['networks']
+        return [self._to_network(network) for network in networks]
+
+    def _to_network(self, obj):
+        return OpenStackNetwork(id=obj['id'],
+                                name=obj['label'],
+                                cidr=obj.get('cidr', None),
+                                driver=self)
+
+    def ex_list_networks(self):
+        """
+        Get a list of Networks that are available.
+
+        @rtype: C{list} of L{OpenStackNetwork}
+        """
+        return self._to_networks(
+            self.connection.request('/os-networksv2').object)
+
+    def ex_create_network(self, name, cidr):
+        """
+        Create a new Network
+
+        @rtype: L{OpenStackNetwork}
+        """
+        return self._to_network(self.connection.request(
+            '/os-networksv2', method='POST',
+            data={'network': {'cidr': cidr, 'label': name}}
+        ).object['network'])
+
+    def ex_delete_network(self, network):
+        """
+        Get a list of NodeNetorks that are available.
+
+        @rtype: L{bool}
+        """
+        resp = self.connection.request('/os-networksv2/%s' % (network.id),
+                                       method='DELETE')
+        return resp.status == httplib.ACCEPTED
+
     def ex_get_size(self, size_id):
         """
         Get a NodeSize



Mime
View raw message