Giter Site home page Giter Site logo

zhuzhubj / pyvcloud Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vmware-archive/pyvcloud

0.0 1.0 0.0 1.13 MB

Python SDK for VMware vCloud

Home Page: vcloud.vmware.com

License: Apache License 2.0

Makefile 0.05% Python 99.91% Shell 0.04%

pyvcloud's Introduction

pyvcloud

Python SDK for VMware vCloud.

Release early, release often.

This project is under development.

Sample usage:

Import modules and instantiate a vCloud Air object:

from pyvcloud.vcloudair import VCA
vca = VCA()

Login to a vCloud Director instance:

vca.login('vcdhost.company.com', 'vcdUser@vcdOrg', 'password', None, 'vcd', '5.6')

A user might have access to one or more datacenters within an organization:

for datacenter in vca.get_vdcReferences():
    print datacenter.name
vcd = vca.get_vCloudDirector(vdcId='mydatacenter')

Login to subscription-based vCloud Air:

vca.login('vchs.vmware.com', '[email protected]', 'password', None, 'subscription', '5.6')

On the subscription-based vCloud Air, there are services and datacenters:

for service in vca.get_serviceReferences():
    print service.serviceId

for datacenter in vca.get_vdcReferences('myservice'):
    print datacenter.name

vcd = vca.get_vCloudDirector('myservice', 'mydatacenter')

In both cases, after getting a reference to a vCloud Director instance (vcd), get all vApps:

for vapp in vcd.get_vApps():
    print "name: %s, status: %s\n" % (vapp.name, vapp.status)

Get all vApp templates:

templates = vcd.list_templates({'--catalog': False})

Get all networks:

networks = vcd.get_networkRefs()

Sample vApp life cycle:

#create vApp and get the reference
vcd.create_vApp('myvapp', 'Ubuntu Server 12.04 LTS (amd64 20140927)', 'Public Catalog', {'--blocking': True, '--json': True, '--deploy': False, '--on': False, '--network': ''})
vapp = vcd.get_vApp('myvapp')

#connect vApp to org network
vcd.connect_vApp(vapp, 'AppServices-default-routed', 'bridged')

#In some cases, the vApp template is connected to the default 'VM Network',
#in those cases it is safe to disconnect the vApp from that network
vapp.disconnect_from_network('VM Network')

#connect the VMs
vapp.connect_vms('AppServices-default-routed', 'POOL')

#power on the vApp and VMs
vapp.poweron()

The vApp is now ready to use. When is time to delet it (need to get the vapp reference before each operation):

vapp = vcd.get_vApp('myvapp')
vapp.undeploy(action='shutdown')

vapp = vcd.get_vApp('myvapp')
vapp.delete()

Displaying the XML representation of the vApp:

import sys
myvapp.me.export(sys.stdout, 0)

Development

To test the current code, check it out from github and install it with:

pip install --editable .

To debug a python session, add this code:

import logging
import httplib
httplib.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

pyvcloud's People

Contributors

pacogomez avatar dananourie avatar

Watchers

Zhu Zhu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.