Examples
libcloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from libcloud.types import Provider | |
from libcloud.providers import get_driver | |
GG_ACCESS_ID = "" | |
GG_SECRET = "" | |
if __name__ == "__main__": | |
Driver = get_driver(Provider.GOGRID) | |
conn = Driver(GG_ACCESS_ID, GG_SECRET) | |
# get a location | |
locations = conn.list_locations() | |
location = [location for location in locations | |
if location.name == "US-West-1"][0] | |
# find the first centos image available in this location | |
image = [image for image in conn.list_images(location=location) | |
if "CentOS" in image.name][0] | |
# finally create node | |
node = conn.create_node(name='loctest', | |
image=image, size=conn.list_sizes()[0], | |
location=location) | |
print node |
lc-tools
Some of the lc-tools support '-l' flag to specify location id. Here's how a typical sequence would look like:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(10:50) novel@fsol:~ %> lc-locations-list | |
1 US-West-1 US | |
2 US-East-1 US | |
(10:50) novel@fsol:~ %> lc-image-list -l 2|grep -i centos | |
image CentOS 5.3 (32-bit) w/ None (id = 1531) | |
image CentOS 5.3 (64-bit) w/ None (id = 1532) | |
(10:50) novel@fsol:~ %> lc-node-add -i 1531 -n myeastnode -s "1GB" -l 2 | |
<Node: uuid=25351b0e79c48c5098670c013ee534e97fa52b0a, name=myeastnode, state=0, public_ip=[u'fake'], provider=GoGrid ...> | |
(10:56) novel@fsol:~ %> |
Few notes here: you probably noticed that we filter images by locations but don't do it for sizes. Strictly speaking, sizes might differ for various providers and this is also accounted by libcloud API; but for GoGrid sizes are same for both locations, so I skipped this step.
And the second thing: all these features are available in svn version of libcloud and git version of lc-tools.
Also the thing I should have been mentioned for some time already: GoGrid provided me with an account and it is quite helpful for various testing.
No comments:
Post a Comment