Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: pquerna/libcloud
base: trunk
...
head fork: pquerna/libcloud
compare: openstack_networks
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 65 additions and 0 deletions.
  1. +65 −0 libcloud/compute/drivers/openstack.py
View
65 libcloud/compute/drivers/openstack.py
@@ -904,6 +904,23 @@ def __init__(self, *args, **kwargs):
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 @@ def create_node(self, **kwargs):
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 @@ def _create_args_to_params(self, node, **kwargs):
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 @@ def ex_update_node(self, node, **node_updates):
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

No commit comments for this range

Something went wrong with that request. Please try again.