1

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? 

smci
  • 32,567
  • 20
  • 113
  • 146
  • Please format your code. – yole Mar 22 '15 at 09:05
  • Hi all, I ve execute above code,i got output like this:{'secure': True, 'connection': , 'region': None, 'secret': 'mysecretkey', 'host': 'myservices.interoute.com', 'key': 'myusername', 'path': '/myservices', 'api_version': None} Still i don't know how to pass region in that ,to llist images,when i give location name in list_images it asks for location id and showing error.Any idea guys? – user4223185 Mar 24 '15 at 12:37
  • In this connection establishing its type is in object but when I call listimages() method it showing json parson error as above mentioned in my1st post ,and also when passing location in listimages method ,it gets ask for locationid – user4223185 Mar 24 '15 at 17:46

1 Answers1

1

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
admirableadmin
  • 2,669
  • 1
  • 24
  • 41
  • Thanks,while creating node showing like this:libcloud.common.types.ProviderError: u'Unable to execute API command deployvirtualmachine due to missing parameter serviceofferingid' hercode: node = conn.create_node(name="IRT-CENTOS-6.3", images="my image id", sizes="my size id", ex_security_groups="None", ex_keyname="None") Whether need to pass any parameter further for creating a node? – user4223185 Apr 07 '15 at 07:25
  • @user4223185 to create a node you have to pass the objects (not the strings) into `conn.create_node` see [this link for an example](https://github.com/Interoute/Libcloud-and-VDC/blob/master/create_node.py) – admirableadmin Apr 09 '15 at 08:21
  • Thanks Andpei, now i ve passed as an object ,but now showing libcloud.common.types.ProviderError: u'The template 2943 is not available for use' Whicg=h means image is not available ah? – user4223185 Apr 09 '15 at 09:22
  • In creating a vm,showing template is not available or network id is not available for zone1.Is this related to resource or any ? – user4223185 May 03 '15 at 06:04