EC2 API
To use EC2-compatible API, pick EUCALYPTUS driver like that:
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.compute.types import Provider | |
from libcloud.compute.providers import get_driver | |
EC2_ACCESS_KEY="" | |
EC2_SECRET_KEY="" | |
# EC2_URL="http://192.168.0.1:8773/services/Cloud" | |
if __name__ == "__main__": | |
Driver = get_driver(Provider.EUCALYPTUS) | |
conn = Driver(EC2_ACCESS_KEY, secret=EC2_SECRET_KEY, | |
host="192.168.0.1", secure=False, port=8773, | |
path="/services/Cloud") | |
print conn.list_nodes() |
You need to define EC2_ACCESS_KEY and EC2_SECRET_KEY variables to match your setup. Hostname, port and path arguments which are passed to constructor could be extracted from your EC2_URL environment variable.
Note: if you're not using trunk version of libcloud, you will need to adjust imports a little, i.e. strip compute. part from them.
Rackspace API
To use Rackspace-compatible API you will to check out trunk version of libcloud (please refer here to obtain it) which provides OPENSTACK driver, which could be used in a similar fashion:
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.compute.types import Provider | |
from libcloud.compute.providers import get_driver | |
NOVA_API_KEY="" | |
NOVA_USERNAME="" | |
# NOVA_URL="http://192.168.0.1:8774/v1.0/" | |
if __name__ == "__main__": | |
Driver = get_driver(Provider.OPENSTACK) | |
conn = Driver(NOVA_USERNAME, NOVA_API_KEY, False, host="192.168.0.1", port=8774) | |
print conn.list_nodes() |
Again, here you will need to redefine NOVA_API_KEY and NOVA_USERNAME for your setup and grab host and port from NOVA_URL.
Let me remind you once again that you need trunk version of libcloud to make it working. One more thing: OpenStack is not fully compatible with Rackspace API, so not everything will work smooth.
lc-tools
lc-tools is a set of command line tools on top of libcloud to manage your cloud servers. Git version of lc-tools supports working with OpenStack both through EC2 and Rackspace compatible APIs. Here's config samples for both:
[ec2compat]
driver = eucalyptus
access_id = CHANGE_ME
secret_key = CHANGE_ME
extra = { "host": "127.0.0.1", "secure": False, "port": 8773, "path": "/services/Cloud" }
[rscompat]
driver = openstack
access_id = nova_admin
secret_key = CHANGE_ME
extra = {"host": "127.0.0.1", "port": 8774}
And just check if it works by executing lc-node-list -p ec2compat and lc-node-list -p rscompat.
References
* libcloud* lc-tools
This comment has been removed by a blog administrator.
ReplyDelete