- CloudStack is all about allocating a pool of resources out to customers/clients but we don't have a pool of assets (racks of machines) when developing. Luckily there is a pre-configured VirtualBox VM all setup to pretend to be available to CloudStack for just such testing/development purposes.
- Follow these instructions: http://wiki.cloudstack.org/display/COMM/DevCloud
- I work out of
~/eng
, so thecloudstack
git repo is there, but it's scripted to live elsewhere, so...mkdir -p /opt/cloudstack
(might have to sudo, chmod etc.)ln -s /Users/gburd/eng/cloudstack /opt/cloudstack/incubator-cloudstack
- We'll need the cloudstack-python-client later, install that...
git clone git://github.com/jasonhancock/cloudstack-python-client.git
cd cloudstack-python-client
pip install .
- A few
ant
commands will need additional jars in your Ant library path, so do that...mkdir -p ~/.ant/lib
curl http://goo.gl/JJKFU > ~/.ant/lib/jsch-0.1.42.jar
(credit: http://cafe.elharo.com/programming/java-programming/could-not-load-a-dependent-class-comjcraftjschlogger/)
- Now you'll want to reset state in the database and app server, so...
ant rdeploydb
ant rdebug
- And finally let's get past the wizard and automate a development setup, run the bootstrap script (below)
./cs-bootstrap.py
- CREDIT: http://paste.cloudstack.org/IBF5/ http://paste.cloudstack.org/XgZx/
- http://wiki.cloudstack.org/display/COMM/DevCloud?focusedCommentId=11829327#comment-11829327
-
-
Save double-z/4152612 to your computer and use it in GitHub Desktop.
CloudStack DevCloud bootstrap
This file contains 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 | |
# encoding: utf-8 | |
""" | |
Utility script to configure DevCloud | |
Assumes integration.api.port setting has been set to 8096 | |
""" | |
import sys | |
import os | |
import time | |
import urllib | |
import CloudStack | |
from xml.dom.minidom import parseString | |
def GetRootId(url): | |
req=url + 'command=listUsers' | |
dom=parseString(urllib.urlopen(req).read()) | |
return dom.getElementsByTagName('id')[0].toxml().replace('<id>','').replace('</id>','') | |
def EnableEC2(url): | |
'Sets enable.ec2.api Global Setting to TRUE' | |
req=url + 'command=updateConfiguration&name=enable.ec2.api&value=true' | |
return urllib.urlopen(req).read() | |
def EnableS3(url): | |
'Sets enable.s3.api Global Settting to TRUE' | |
req=url + 'command=updateConfiguration&name=enable.s3.api&value=true' | |
return urllib.urlopen(req).read() | |
def GetKeys(url,rootid): | |
req=url + 'command=registerUserKeys&id=' + rootid | |
dom=parseString(urllib.urlopen(req).read()) | |
apikey = dom.getElementsByTagName('apikey')[0].toxml().replace('<apikey>','').replace('</apikey>','') | |
secretkey = dom.getElementsByTagName('secretkey')[0].toxml().replace('<secretkey>','').replace('</secretkey>','') | |
return (apikey,secretkey) | |
def main(): | |
'Uses the integration api, no need for authentication and signing' | |
url = 'http://localhost:8096/client/api?' | |
rootid = GetRootId(url) | |
(apikey,secretkey) = GetKeys(url,rootid) | |
print apikey | |
print secretkey | |
'Enable EC2 and S3 api for testing of cloudbridge' | |
EnableEC2(url) | |
EnableS3(url) | |
''' | |
With the root user api keys we can now authenticate and sign api calls | |
We could keep on using the integration api but that way I can use the CloudStack module | |
''' | |
apiurl = 'http://localhost:8080/client/api' | |
cloudstack = CloudStack.Client(apiurl,apikey,secretkey) | |
'Create DevCloud Infrastructure' | |
devcloudZone = {'dns1':'8.8.8.8','internaldns1':'10.0.2.3','name':'devcloud','networktype':'Basic','securitygroupenabled':'False'} | |
zones = cloudstack.createZone(devcloudZone) | |
print zones | |
'Assume no other zones in the mgt server' | |
zoneid = zones['zone']['id'] | |
print zoneid | |
res=cloudstack.createPhysicalNetwork({'name':'devcloud','zoneid':zoneid}) | |
physnetid=res['id'] | |
'Physical Network needs to be enabled before creating a Guest Network...' | |
jobres = cloudstack.queryAsyncJobResult({'jobid':res['jobid']}) | |
print jobres | |
while jobres['jobstatus'] != 1: | |
time.sleep(2) | |
jobres = cloudstack.queryAsyncJobResult({'jobid':res['jobid']}) | |
cloudstack.updatePhysicalNetwork({'id':physnetid,'state':'Enabled'}) | |
cloudstack.addTrafficType({'physicalnetworkid':physnetid,'traffictype':'Guest'}) | |
cloudstack.addTrafficType({'physicalnetworkid':physnetid,'traffictype':'Management'}) | |
'Enable the VirtualRouter for the physical network, need to configure it first' | |
nspid = cloudstack.listNetworkServiceProviders({'name':'VirtualRouter'})[0]['id'] | |
print nspid | |
vrprovid = cloudstack.listVirtualRouterElements({'nspid':nspid})[0]['id'] | |
res = cloudstack.configureVirtualRouterElement({'id':vrprovid,'enabled':'True'}) | |
confres = cloudstack.queryAsyncJobResult({'jobid':res['jobid']}) | |
while confres['jobstatus'] != 1: | |
time.sleep(2) | |
confres = cloudstack.queryAsyncJobResult({'jobid':res['jobid']}) | |
'Update Network Serive Provider' | |
upnetprovres = cloudstack.updateNetworkServiceProvider({'id':nspid,'state':'Enabled'}) | |
jobres = cloudstack.queryAsyncJobResult({'jobid':upnetprovres['jobid']}) | |
while jobres['jobstatus'] != 1: | |
time.sleep(2) | |
jobres = cloudstack.queryAsyncJobResult({'jobid':upnetprovres['jobid']}) | |
print cloudstack.listNetworkServiceProviders({'physicalnetworkid':physnetid}) | |
''' | |
To create a Guest Network, we need to get the Network Offering ID for a Shared Network (for instance) | |
''' | |
offerings = cloudstack.listNetworkOfferings({'name':'DefaultSharedNetworkOffering'}) | |
print offerings | |
'The first offering is the one with security group, does not seem to be an exact match on name' | |
NetworkOfferingId = offerings[1]['id'] | |
print 'netofferid = ' + NetworkOfferingId | |
devcloudGuestNetwork = {'displaytext':'devcloud','name':'devcloud','networkofferingid':NetworkOfferingId,'zoneid':zoneid, \ | |
'physicalnetworkid':physnetid} | |
netwrk = cloudstack.createNetwork(devcloudGuestNetwork) | |
netid = netwrk['network']['id'] | |
devcloudPod = {'gateway':'10.0.2.2','name':'devcloud','netmask':'255.255.255.0','startip':'10.0.2.200','endip':'10.0.2.220','zoneid':zoneid} | |
pod = cloudstack.createPod(devcloudPod) | |
podid = pod['pod']['id'] | |
vlanrange={'startip':'10.0.2.100','endip':'10.0.2.199','gateway':'10.0.2.2','netmask':'255.255.255.0', \ | |
'networkid':netid,'podid':podid,'forvirtualnetwork':'false'} | |
cloudstack.createVlanIpRange(vlanrange) | |
''' | |
devcloudSecondaryStorage = {'name'='devcloud','url'='10.0.2.15','zoneid'=zoneid} | |
cloudstack.createStoragePool(devcloudSecondaryStorage) | |
''' | |
devcloudCluster = {'clustername':'devcloud','clustertype':'CloudManaged','hypervisor':'XenServer','zoneid':zoneid,'podid':podid} | |
cluster = cloudstack.addCluster(devcloudCluster) | |
print cluster | |
clusterid=cluster['cluster'][0]['id'] | |
devcloudHost = {'hypervisor':'XenServer','password':'password','url':'http://10.0.2.15/','username':'root','zoneid':zoneid,'podid':podid,'clusterid':clusterid} | |
cloudstack.addHost(devcloudHost) | |
cloudstack.addSecondaryStorage({'url':'nfs://10.0.2.15/opt/storage/secondary','zoneid':zoneid}) | |
print cloudstack.updateZone({'id':zoneid,'allocationstate':'Enabled'}) | |
print 'Zoneid = ', zoneid | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment