Reputation: 55
I am trying to to list images in CloudStack, using libcloud api in Python:
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
from libcloud.common.base import Response
#import libcloud.security as sec
#sec.VERIFY_SSL_CERT = False
#USER = 'ACCESSKEY'
#API_KEY = 'SECRETKEY'
Driver = get_driver(Provider.CLOUDSTACK)
url = 'MY URL'
conn = Driver(key=USER, secret=API_KEY, url=url)
print "Connection established"
images = conn.list_images()
print images
When running this code, I get the following error:
body = self.parse_body()
File "/usr/local/lib/python2.7/dist-packages/libcloud/common/base.py", line 195,
in parse_body driver=self.connection.driver)
libcloud.common.types.MalformedResponseError: <MalformedResponseException in
<libcloud.compute.drivers.cloudstack.CloudStackNodeDriver object at 0x7fc356f55b50>
'Failed to parse JSON'>: 'Unknown_ApiKey'
What am I missing?
Upvotes: 1
Views: 764
Reputation: 2759
A 'region' is not needed for libcloud with CloudStack: See this link for a working example.
From your comments I see that you use interoute.com. By a quick search I found this tutorial how to work with libcloud on interoute. You can find more examples at github.
Your code seems correct to list all images. But the error message contains Unknown_ApiKey
, so please check that you provide the valid credentials for you request.
(Edit) a working example for CloudStack (interoute.com) is:
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
VDCDriver=get_driver(Provider.CLOUDSTACK)
vdc_apikey= 'INSERT YOUR VDC ACCOUNT API KEY HERE'
vdc_secretkey= 'INSERT YOUR VDC ACCOUNT SECRET KEY HERE'
vdc_url= 'https://myservices.interoute.com/myservices/api/vdc'
conn=VDCDriver(key=vdc_apikey, secret=vdc_secretkey, url=vdc_url)
images = conn.list_images()
for i in images:
print "%s - %s" % (i.extra['displaytext'],i.id)
This will output name and id of all available images:
openSUSE 13.2 - abcde-1111-abc-1111-abcde
Ubuntu 14.10 - abcde-2222-abc-2222-abcde
Fedora 21 - abcde-3333-abc-333-abcde
Upvotes: 1