def __init__(self, basepath): pragma.drivers.Driver.__init__(self, basepath) self.setModuleVals() # loads baseurl, apikey, and secret key values execfile(self.driverconf, {}, globals()) # create instance of CloudStack API self.cloudstackcall = CloudStackCall( baseurl, apikey, secretkey, templatefilter) # prefix for VM names self.vmNamePrefix = 'vc' self.nic_names = ["private", "public"] self.logger.info("Using Cloudstack REST API URL: %s" % baseurl) self.logger.info("Loading driver %s information from %s" % (self.drivername, self.driverconf) )
#!/usr/bin/env python # user apikey and secret key are in the file mykeys.py # do not add mykeys.py to git repo from mykeys import * from cloudstack import CloudStackCall ### Main ### # base settings for the cloudstack configuration baseurl = 'http://163.220.56.65:8080/client/api?' templatefilter = 'community' networkoffering = 'DefaultIsolatedNetworkOfferingWithSourceNatService' apicall = CloudStackCall(baseurl, apikey, secretkey, templatefilter) def ListNetworks (): response = apicall.listNetworks() print response.keys() count = response['count'] for i in range(count): d = response['network'][i] print "network:", d['name'], d['id'], d['networkofferingid'], d['cidr'], d['netmask'] def ListTemplates (name = None): response = apicall.listTemplates(name) count = response['count'] for i in range(count): d = response['template'][i] print "template:", d['name'], d['id'] def ListNetworkOfferings(name = None):