A simple script that lists currently existed cloud server is below. For more examples and API documentation please refer to the github directories:
https://github.com/rackspace/pyrax/tree/master/docs
https://github.com/rackspace/pyrax/tree/master/samples
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
import os | |
import pyrax | |
conf = os.path.expanduser("rackspace_cloud_credentials.txt") | |
#pyrax.set_credential_file(conf, "LON") | |
pyrax.set_credential_file(conf) | |
cs = pyrax.cloudservers | |
servers = cs.servers.list() | |
print ("cloud server under your account:") | |
for pos, srv in enumerate(servers): | |
print "%s: %s" % (pos, srv.name) |
Problem
By default an execution of the script generate this error:
Traceback (most recent call last): File "C:\Users\radoslaw\workspace\api-challenge\challange1.py", line 6, in <module> pyrax.set_credential_file(conf) File "c:\Python27\lib\site-packages\pyrax\__init__.py", line 215, in set_credential_file authenticate=authenticate) File "c:\Python27\lib\site-packages\pyrax\rax_identity.py", line 108, in set_credential_file self.authenticate() File "c:\Python27\lib\site-packages\pyrax\rax_identity.py", line 138, in authenticate raise exc.AuthenticationFailed("Incorrect/unauthorized " pyrax.exceptions.AuthenticationFailed: Incorrect/unauthorized credentials received
By default the function pyrax.set_credential_file(conf) assumes your cloud account belongs to the USA. For it to work you need to specify the LONDON region like in the commented code above.
pyrax.set_credential_file(conf, "LON")
No comments:
Post a Comment