Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GoGrid driver minor improvements.

 * Support specifying IP addresses for new nodes
   at creation time via ex_ip keyword
 * Support filtering IP addresses by location




git-svn-id: https://svn.apache.org/repos/asf/incubator/libcloud/trunk@1072590 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 13274f9bb9461048c6ad77d27d9a5ab036505b2c 1 parent 25f795d
@novel novel authored
Showing with 15 additions and 3 deletions.
  1. +15 −3 libcloud/drivers/gogrid.py
View
18 libcloud/drivers/gogrid.py
@@ -209,6 +209,7 @@ def _to_ip(self, element):
public=element['public'],
subnet=element['subnet'],
state=element["state"]["name"])
+ ip.location = self._to_location(element['datacenter'])
return ip
def _to_ips(self, object):
@@ -278,7 +279,7 @@ def _server_delete(self, id):
method='POST')
def _get_first_ip(self, location=None):
- ips = self.ex_list_ips(public=True, assigned=False)
+ ips = self.ex_list_ips(public=True, assigned=False, location=location)
try:
return ips[0].ip
except IndexError:
@@ -305,13 +306,17 @@ def ex_create_node_nowait(self, **kwargs):
name = kwargs['name']
image = kwargs['image']
size = kwargs['size']
- first_ip = self._get_first_ip(kwargs.get('location'))
+ try:
+ ip = kwargs['ex_ip']
+ except KeyError:
+ ip = self._get_first_ip(kwargs.get('location'))
+
params = {'name': name,
'image': image.id,
'description': kwargs.get('ex_description', ''),
'isSandbox': str(kwargs.get('ex_issandbox', False)).lower(),
'server.ram': size.id,
- 'ip': first_ip}
+ 'ip': ip}
object = self.connection.request('/api/grid/server/add',
params=params, method='POST').object
@@ -328,6 +333,9 @@ def create_node(self, **kwargs):
@type ex_description: C{string}
@keyword ex_issandbox: Should server be sendbox?
@type ex_issandbox: C{bool}
+ @keyword ex_ip: Public IP address to use for a Node. If not
+ specified, first available IP address will be picked
+ @type ex_ip: C{string}
"""
node = self.ex_create_node_nowait(**kwargs)
@@ -439,6 +447,8 @@ def ex_list_ips(self, **kwargs):
addresses and set to None or don't set at all
not no filter by state
@type assigned: C{bool}
+ @keyword location: filter IP addresses by location
+ @type location: L{NodeLocation}
@return: C{list} of L{GoGridIpAddress}es
"""
@@ -450,6 +460,8 @@ def ex_list_ips(self, **kwargs):
if "assigned" in kwargs and kwargs["assigned"] is not None:
params["ip.state"] = {True: "Assigned",
False: "Unassigned"}[kwargs["assigned"]]
+ if "location" in kwargs and kwargs['location'] is not None:
+ params['datacenter'] = kwargs['location'].id
ips = self._to_ips(
self.connection.request('/api/grid/ip/list',
Please sign in to comment.
Something went wrong with that request. Please try again.