Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Note: dbSvr is the location where mysql server is running and passwd is the password for user cloud.
  • Run this command to open up the iptables on your management server iptables -I INPUT -p tcp --dport 8096 -j ACCEPT
  • Change the global setting integration.api.port on the CloudStack GUI to 8096 and restart the management server.

...

#Enter an interactive python shell and follow along with the steps listed below. We've used the ipython shell in our example because it has a very handy auto-complete feature

...

#We will import a few essential libraries to start with.

  • The cloudstackTestCase module contains the essential API calls we need and a reference to the API client itself. All tests will be children (subclasses) of the cloudstackTestCase since it contains the toolkit (attributes) to do our testing
    Code Block
    In [1]: import marvin
    In [2]: from marvin.cloudstackTestCase import *
    
  • The deployDataCenter module imported below will help us load our json configuration file we wrote down in the beginning so we can tell the test framework that we have our management server configured and ready
    Code Block
    In [2]: import marvin.deployDataCenter
    

...

  • #Let's load the configuration file using the deployDataCenter module
    Code Block
    
    In [3]: config = marvin.deployDataCenter.deployDataCenters('demo/demo.cfg')
    In [4]: config.loadCfg()
    

...

  • #Once the configuration is loaded successfully, all we'll need is an instance of the apiClient which will help fire our cloudstack APIs against the configured management server. In addition to the apiClient, the test framework also provides a dbClient to help us fire any SQL queries against the database for verification. So let's go ahead and get a reference to the apiClient:
    Code Block
    
    In [5]: apiClient = config.testClient.getApiClient()
    

...

  • #Now we'll start with forming a very simple API call. listConfigurations - which will show us the "global settings" that are set on our instance of CloudStack. The API command is instantiated as shown in the code snippet (as are other API commands).
    Code Block
    
    In [6]: listconfig = listConfigurations.listConfigurationsCmd()
    
    So the framework is intuitive in the verbs used for an API call. To deploy a VM you would be calling the deployVirtualMachineCmd method inside the deployVirtualMachine object. Simple, ain't it?

...

  • #Since it's a large list of global configurations let's limit ourselves to fetch only the configuration with the keyword 'expunge'. Let's change our listconfig object to take this attribute as follows:
    Code Block
    
    In [7]: listconfig.name = 'expunge'
    

...

  • #And finally - we fire the call using the apiClient as shown below:
    Code Block
    
    In [8]: listconfigresponse = apiClient.listConfigurations(listconfig)
    
    Lo' and Behold - the response you've awaited:
    Code Block
    
    In [9]: print listconfigresponse
     
    [ {category : u'Advanced', name : u'expunge.delay', value : u'60', description : u'Determines how long (in seconds) to wait before actually expunging destroyed vm. The default value = the default value of expunge.interval'},
      {category : u'Advanced', name : u'expunge.interval', value : u'60', description : u'The interval (in seconds) to wait before running the expunge thread.'},
      {category : u'Advanced', name : u'expunge.workers', value : u'3', description : u'Number of workers performing expunge '}]
    

The response is presented to us the way our UI receives it, as a JSON object. The object comprises of a list of configurations, each configuration showing the detailed dictionary (key, value) pairs of each config setting.

...