vmware vcloud python开发包

pyvcloud.mishkin的Python项目详细描述


pyvcloud

用于vmware vcloud的python sdk。它支持vcloud air点播和订阅。它还支持vCloud Director。

Release early, release often.

此项目正在开发中,类、方法和参数可能会随时间而更改。本自述文件通常反映最新版本的语法。

示例用法:

导入模块并实例化vcloud air对象:

from pyvcloud.vcloudair import VCA
vca = VCA(host, user, service_type, service_version, verify)

登录vcloud控制器实例:

result = vca.login(password=password, org=org)

安装

python sdk需要libxml2和libxslt库,有关详细信息,请参见lxml。在debian/ubuntu上,您可以使用以下命令安装库:

sudo apt-get install libxml2-dev libxslt-dev

当然,python开发环境是必需的:

sudo apt-get install python-dev python-pip

python sdk可以使用以下命令安装:

pip install pyvcloud

建议使用virtualenv

用法

sdk支持登录到不同类型的服务:vcloud air订阅、vcloud air on demand和vcloud director standalone。以下面的code为例:

import time, datetime, os
from pyvcloud.vcloudair import VCA

def print_vca(vca):
    if vca:
        print 'vca token:            ', vca.token
        if vca.vcloud_session:
            print 'vcloud session token: ', vca.vcloud_session.token
            print 'org name:             ', vca.vcloud_session.org
            print 'org url:              ', vca.vcloud_session.org_url
            print 'organization:         ', vca.vcloud_session.organization
        else:
            print 'vca vcloud session:   ', vca.vcloud_session
    else:
        print 'vca: ', vca

def test_vcloud_session(vca, vdc, vapp):
    the_vdc = vca.get_vdc(vdc)
    for x in range(1, 5):
        print datetime.datetime.now(), the_vdc.get_name(), vca.vcloud_session.token
        the_vdc = vca.get_vdc(vdc)
        if the_vdc: print the_vdc.get_name(), vca.vcloud_session.token
        else: print False
        the_vapp = vca.get_vapp(the_vdc, vapp)
        if the_vapp: print the_vapp.me.name
        else: print False
        time.sleep(2)

### Subscription
host='vchs.vmware.com'
username = os.environ['VCAUSER']
password = os.environ['PASSWORD']
service = '85-719'
org = 'AppServices'
vdc = 'AppServices'
vapp = 'cts'

#sample login sequence on vCloud Air Subscription
vca = VCA(host=host, username=username, service_type='subscription', version='5.6', verify=True)

#first login, with password
result = vca.login(password=password)
print_vca(vca)

#next login, with token, no password
#this tests the vca token
result = vca.login(token=vca.token)
print_vca(vca)

#uses vca.token to generate vca.vcloud_session.token
vca.login_to_org(service, org)
print_vca(vca)

#this tests the vcloud session token
test_vcloud_session(vca, vdc, vapp)


### On Demand
host='iam.vchs.vmware.com'
username = os.environ['VCAUSER']
password = os.environ['PASSWORD']
instance = 'c40ba6b4-c158-49fb-b164-5c66f90344fa'
org = 'a6545fcb-d68a-489f-afff-2ea055104cc1'
vdc = 'VDC1'
vapp = 'ubu'

#sample login sequence on vCloud Air On Demand
vca = VCA(host=host, username=username, service_type='ondemand', version='5.7', verify=True)

#first login, with password
result = vca.login(password=password)
print_vca(vca)

#then login with password and instance id, this will generate a session_token
result = vca.login_to_instance(password=password, instance=instance, token=None, org_url=None)
print_vca(vca)

#next login, with token, org and org_url, no password, it will retrieve the organization
result = vca.login_to_instance(instance=instance, password=None, token=vca.vcloud_session.token, org_url=vca.vcloud_session.org_url)
print_vca(vca)

#this tests the vca token
result = vca.login(token=vca.token)
if result: print result, vca.instances
else: print False

#this tests the vcloud session token
test_vcloud_session(vca, vdc, vapp)


### vCloud Director standalone
host='p1v21-vcd.vchs.vmware.com'
username = os.environ['VCAUSER']
password = os.environ['PASSWORD']
service = '85-719'
org = 'AppServices'
vdc = 'AppServices'
vapp = 'cts'

#sample login sequence on vCloud Director standalone
vca = VCA(host=host, username=username, service_type='vcd', version='5.6', verify=True)

#first login, with password and org name
result = vca.login(password=password, org=org)
print_vca(vca)

#next login, with token, org and org_url, no password, it will retrieve the organization
result = vca.login(token=vca.token, org=org, org_url=vca.vcloud_session.org_url)
print_vca(vca)

#this tests the vcloud session token
test_vcloud_session(vca, vdc, vapp)

开发

要测试当前代码,请从github签出并使用以下命令安装它:

pip install --editable .

要调试python会话,请添加以下代码:

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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何通过编程为datasnapshot的每个子级创建一个按钮?   java用透明像素填充BuffereImage   过滤器如何在Java中对图像进行逐行扫描?   ssl在Java中,使用PEM文件创建SSLContext的最简单方法是什么?   java JApplet绘图时加载屏幕   java错误:不兼容类型:无法将上下文转换为HomeMenu   java通知演示者模型已更改   java如何使用object作为ArrayList类的变量?   使用mixin对Lombok@Builder类的java Jackson反序列化不起作用   java为什么我的库不能访问它的资源?   java无法使用GET方法   如何在Java中存储dowhile循环的每个实例上的数据?   java无法在64位系统上下载32位SWT   java按钮未在Jframe中显示   在Java中,当我只需要大于5的值时,如何返回数组   java有没有一种简单的方法可以在osgi环境中禁用日志记录?   java当我试图通过Hibernate添加到数据库时,我遗漏了什么?   为什么我不能在Java中向文件添加文本?   java ActiveMQ加载失败:类路径资源[ActiveMQ.xml]