Giter Site home page Giter Site logo

vmware / pyvcloud Goto Github PK

View Code? Open in Web Editor NEW
170.0 44.0 192.0 25.8 MB

Python SDK for VMware vCloud Director

Home Page: https://vmware.github.io/pyvcloud

License: Other

Python 98.12% Shell 0.42% Groovy 1.45% Dockerfile 0.01%
python vcloud-director sdk sdk-python iaas vcloud

pyvcloud's Introduction

pyvcloud

License Stable Version Build Status

pyvcloud is the Python SDK for VMware vCloud Director.

Supported API versions are 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0.

Installation

In general, pyvcloud can be installed with the following command:

$ pip install --user pyvcloud

Depending on your operating system and distribution you may need additional packages to install successfully. See install.md for full details.

Testing

Contributions to pyvcloud are welcome and it should include unit tests. See the contributing guide for details.

Check out the latest version and install:

git clone https://github.com/vmware/pyvcloud.git
cd pyvcloud
virtualenv .venv
source .venv/bin/activate
python setup.py develop

Sample test parameters are in file tests/config.yml. Create a copy to specify your own settings and use the VCD_TEST_CONFIG_FILE env variable.

cd tests
cp config.yml private.config.yml
# customize credentials and other parameters
export VCD_TEST_CONFIG_FILE=private.config.yml
# run unit test
python -m unittest vcd_login vcd_catalog_setup
# run just a test method
python -m unittest vcd_catalog_setup.TestCatalogSetup.test_validate_ova

See tests for a list of current unit tests written for the new SDK implementation.

Notes

Please note that this project is under development and the interfaces might change over time.

pyvcloud is used by vcd-cli, the Command Line Interface for VMware vCloud Director. It requires Python 3.6 or higher.

Previous versions and deprecated code can be found in this repository under tag 18.2.2.

Contributing

The pyvcloud project team welcomes contributions from the community. Before you start working with pyvcloud, please read our Developer Certificate of Origin. All contributions to this repository must be signed as described on that page. Your signature certifies that you wrote the patch or have the right to pass it on as an open-source patch. For more detailed information, refer to CONTRIBUTING.md.

License

Apache-2.0

pyvcloud's People

Contributors

0lvin avatar andrew-ni avatar anirudh9794 avatar anusuyar avatar blackms avatar chaitanya118 avatar ckolovson avatar dwettstein avatar floriankammermann avatar guptaankit52 avatar harshneelmore avatar jblaine avatar kaneda-fr avatar kkkothari avatar kousgy123 avatar lasko avatar ltimothy7 avatar michaltaratuta avatar mukultaneja avatar pacogomez avatar rajeshk2013 avatar rdbwebster avatar reversecipher avatar rocknes avatar sahithi avatar sakthisunda avatar shashim22 avatar sompa avatar szimszon avatar xcompass avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyvcloud's Issues

Assumes at least one edge gateway exists: Can't login; list index out of range

Symptoms and proposed fix are documented in the following issue within the vca-cli project:

vmware-archive/vcd-cli#30

In addition to the can't login issue, here's another failure example that helped point us in the right direction:

(cloudify)[root@localhost yum.repos.d]# vca --insecure vdc use --vdc devcloud
/etc/yum.repos.d/cloudify/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py:730: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html (This warning will only appear once by default.)
  InsecureRequestWarning)
Using vdc 'devcloud' in profile 'default'
Traceback (most recent call last):
  File "/etc/yum.repos.d/cloudify/bin/vca", line 9, in <module>
    load_entry_point('vca-cli==1.1', 'console_scripts', 'vca')()
  File "/etc/yum.repos.d/cloudify/lib/python2.7/site-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/etc/yum.repos.d/cloudify/lib/python2.7/site-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/etc/yum.repos.d/cloudify/lib/python2.7/site-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/etc/yum.repos.d/cloudify/lib/python2.7/site-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/etc/yum.repos.d/cloudify/lib/python2.7/site-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "/etc/yum.repos.d/cloudify/lib/python2.7/site-packages/click/decorators.py", line 16, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/etc/yum.repos.d/cloudify/lib/python2.7/site-packages/vca_cli/vca_cli.py", line 322, in vdc
    print_vdc_details(ctx, the_vdc, vca.get_gateways(vdc))
  File "/etc/yum.repos.d/cloudify/lib/python2.7/site-packages/pyvcloud/vcloudair.py", line 400, in get_gateways
    response = requests.get(link[0].get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify)
IndexError: list index out of range

FIX import

Import of vcloudType is missing in pyvcloud/vclouddirector.py, line 322
This fix :

from schema.vcd.v1_5.schemas.vcloud import networkType, vdcType, queryRecordViewType, taskType, vAppType, organizationType, catalogType, diskType, vmsType, vcloudType

Error when looking for vApptemplate.

Hello,
I tries to get all available vApptemplate form my vDC's catalogue, I used "get_vdc_templates" But always I have an error:

y=vca._get_vdc_templates()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/pyvcloud/vcloudair.py", line 318, in _get_vdc_templates
self.response = requests.get(link[0].get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify)
IndexError: list index out of range

Many thanks,
Bechir

Invalid numbers of public ips

Function Gateway.get_public_ips() (from gateway.py) retrieve wrong numbers of public ips, because count only first element from subnetParticipation list.

I fix this bug in pull request #19

Timeout issues with block_until_completed function

This is a recent issue but hopefully someone will have some insight
Occasionally when creating a vapp I'll receive a "Connection Refused" error from https://us-california-1-3.vchs.vmware.com --- When I turn on logging it looks like the HTTP session just times out while waiting for a task to finish.

Its pretty random on when it occurs during the creation of the vapp (using the create_vapp function).
Its taking place during the block_until_completed() function.
As an example here is some (sterilized) log output showing whats happening:

send: 'GET /api/compute/api/task/xxxxxxxxxxxxxxxxxxx HTTP/1.1\r\nHost: us-california-1-3.vchs.vmware.com\r\nConnection: keep-alive\r\nx-vcloud-authorization: xxxxxxxxxxxxxx\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/*+xml;version=5.7\r\nUser-Agent: python-requests/2.7.0 CPython/2.7.6 Linux/3.16.0-30-generic\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Wed, 01 Jul 2015 18:48:00 GMT
header: X-Frame-Options: SAMEORIGIN
header: X-VMWARE-VCLOUD-REQUEST-ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
header: x-vcloud-authorization: xxxxxxxxxxxxxxxxxxxxxx
header: X-VMWARE-VCLOUD-REQUEST-EXECUTION-TIME: 38
header: Content-Type: application/vnd.vmware.vcloud.task+xml;version=5.7
header: Content-Encoding: gzip
header: Vary: Accept-Encoding,User-Agent
header: Content-Length: 647
header: Via: 1.1 us-california-1-3.vchs.vmware.com
header: Keep-Alive: timeout=15, max=100
header: Connection: Keep-Alive
('Connection aborted.', error(111, 'Connection refused'))

I used a try/except statement on the vapp_create function and "('Connection aborted.', error(111, 'Connection refused'))" is the Exception caught and printed.

Thoughts? This is a really big issue for me at the moment, and ultimately may end with me having to submit a ticket with the i am.vchs.vmware.com VMWare vCloud Air service to figure out why they are responding with "Connection Refused" or changing providers.

I have two cloud service providers, the other one does not have this issue and works flawlessly with my vapp creation script --

Help? Thoughts?

Upload an iso media to a catalog

I want the ability of upload an iso media to the catalog.

The api will receive the catalog name, media name, description and type and the path to the iso file.

I don't know if media type is necessary on this case but at the HTTP Api it looks like other types of media can be uploaded but by default the ISO media type is used.

Creating Vapp with vm name have changed vapp name

I've used vca-cli, that uses pyvcloud.
I've created a vApp from a template; API version is 5.5.

This request is doing great:

vca vapp create --vapp test_vapp --catalog 'vms' --template 'template_name' --network 'network_name' --mode POOL --vdc vdc_name

But if I've added --vm vm_name, I get the error:

vca  vapp create --vapp test_vapp --vm vm_name --catalog 'vms' --template 'template_name' --network 'network_name' --mode POOL --vdc vdc_name
                   Traceback (most recent call last):
  File "/bin/vca", line 9, in <module>
    load_entry_point('vca-cli==12', 'console_scripts', 'vca')()
  File "/usr/lib/python2.7/site-packages/click/core.py", line 664, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/click/core.py", line 644, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/site-packages/click/core.py", line 991, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/site-packages/click/core.py", line 837, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/site-packages/click/core.py", line 464, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/vca_cli/vca_cli.py", line 705, in vapp
    vca.vcloud_session.get_vcloud_headers())
  File "/usr/lib/python2.7/site-packages/vca_cli/vca_cli.py", line 2460, in display_progress
    sys.stdout.write("\r" + task_table(response.content) + '\n')
UnboundLocalError: local variable 'response' referenced before assignment

It is happen because, there is next condition in the pyvcloud code:
https://github.com/vmware/pyvcloud/blob/master/pyvcloud/vcloudair.py#L381

           if vm_name:
                if self.version == "5.5":
                   templateParams.set_name(vm_name)
                else:
                   gen_params = vcloudType.VmGeneralParamsType()
                   gen_params.set_Name(vm_name)
                   params.set_VmGeneralParams(gen_params)

This part is redefined name for created vApp.
The situtation seems very odd, the vApp is created with name vm_name, not with name test_vapp.

IndexError: list index out of range

https://github.com/vmware/pyvcloud/blob/eaa614498bb8eef1f98f1c81f7e66fc040c56c1d/pyvcloud/vapp.py#L940

I am using pyvcloud Library in my Ansible dynamic inventory script. After upgrading to the newest version of pyvloud it started failing with the following traceback:

ERROR! Attempted to execute 
...
line 176, in update_cache
    vms_details = the_vapp.get_vms_details()
  File "/home/tumarkin/.virtualenvs/ansible2-stable/lib/python2.7/site-packages/pyvcloud/vapp.py", line 940, in get_vms_details
    property_section = filter(lambda section: section.__class__.__name__ == 'PropertySection_Type', es)[0]
IndexError: list index out of range

Possible solution:
enclose the property section with try ... except IndexError: pass

VCD none for vCloudDirector

With this code, i've got a VCD empty :

def test_lib():
    vca = vcloudair.VCA()
    vca.login(host, '%s@%s' % (user, org), password, None, 'vcd', '5.1')
    vcd = vca.get_vCloudDirector()
    print "VCD : %s" % vcd
    print "Catalog"
    for catalog in vcd.list_catalogs():
        print catalog
    print "Templates"
    for templates in vcd.list_templates({'--catalog': False}):
        print templates
        # print "[template]: %s" % template.__dict__
    print "Networks:"
    for networks in vcd.get_networkRefs():
        print networks.__dict__

if __name__ == '__main__':
    test_lib()
$ ./test.py 
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.myhost
send: 'POST /api/sessions HTTP/1.1\r\nHost: api.myhost\r\nContent-Length: 0\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/*+xml;version=5.1\r\nUser-Agent: python-requests/2.4.3 CPython/2.7.6 Linux/3.13.0-30-generic\r\nConnection: keep-alive\r\nAuthorization: Basic bmxhbWlyYXVsdC5vYWJARkNBX09BQjAxOkZUbGFuaV8zMw==\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Fri, 16 Jan 2015 11:56:11 GMT
header: x-vcloud-authorization: PnmR24poQkLcMYyGqkye9JJkSDCT4gwFifHiZfxTg+k=
header: Set-Cookie: vcloud-token=PnmR24poQkLcMYyGqkye9JJkSDCT4gwFifHiZfxTg+k=; Secure; Path=/
header: Content-Type: application/vnd.vmware.vcloud.session+xml;version=5.1
header: Date: Fri, 16 Jan 2015 11:56:12 GMT
header: Content-Length: 1454
header: Connection: close
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.myhost
send: 'GET /api/org/19adf4a6-942d-4048-a36c-09a68161f0e9 HTTP/1.1\r\nHost: api.myhost\r\nConnection: keep-alive\r\nx-vcloud-authorization: PnmR24poQkLcMYyGqkye9JJkSDCT4gwFifHiZfxTg+k=\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/*+xml;version=5.1\r\nUser-Agent: python-requests/2.4.3 CPython/2.7.6 Linux/3.13.0-30-generic\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Fri, 16 Jan 2015 11:56:12 GMT
header: Date: Fri, 16 Jan 2015 11:56:12 GMT
header: Content-Type: application/vnd.vmware.vcloud.org+xml;version=5.1
header: Content-Encoding: gzip
header: Connection: close
VCD : None
Catalog
Traceback (most recent call last):
  File "./test.py", line 187, in <module>
    test_lib()
  File "./test.py", line 158, in test_lib
    for catalog in vcd.list_catalogs():
AttributeError: 'NoneType' object has no attribute 'list_catalogs'

Python 3 errors

The pip entry says it supports python 3, but I see print statements instead of functions in the code, and the init.py imports httplib instead of http.client.

From other issues, it seems folks are using it with python 3, but what is the trick? Do I need to use 2to3 and handle it myself?

Thanks!

Issue with vca-cli or pyvcloud

Issue:
$ vca login -p -t subscription --host https://vchs.vmware.com -v 5.6
Login successful for profile 'default'
$ vca org use --org --service
Using organization in profile 'default'
$ vca nat add --type SNAT --original_ip 192.168.10.2 --translated_ip 23.92.245.228
Traceback (most recent call last):
File "/home/achirko/workspace/vcloud/venv/bin/vca", line 9, in
load_entry_point('vca-cli==6', 'console_scripts', 'vca')()
File "/home/achirko/workspace/vcloud/venv/local/lib/python2.7/site-packages/click/core.py", line 610, in call
return self.main(_args, *_kwargs)
File "/home/achirko/workspace/vcloud/venv/local/lib/python2.7/site-packages/click/core.py", line 590, in main
rv = self.invoke(ctx)
File "/home/achirko/workspace/vcloud/venv/local/lib/python2.7/site-packages/click/core.py", line 936, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/achirko/workspace/vcloud/venv/local/lib/python2.7/site-packages/click/core.py", line 782, in invoke
return ctx.invoke(self.callback, *_ctx.params)
File "/home/achirko/workspace/vcloud/venv/local/lib/python2.7/site-packages/click/core.py", line 416, in invoke
return callback(_args, **kwargs)
File "/home/achirko/workspace/vcloud/vca-cli/vca_cli/vca_cli.py", line 679, in nat
gateways = vca.get_gateways(vdc)
File "/home/achirko/workspace/vcloud/pyvcloud/pyvcloud/vcloudair.py", line 400, in get_gateways
link = filter(lambda link: link.get_rel() == "edgeGateways", self.get_vdc(vdc_name).get_Link())
AttributeError: 'NoneType' object has no attribute 'get_Link'

Enumerate all vApps? get_vapps?

I've scoured the generated docs and poked around through the code but cannot find a way to collect a list of vApps to then iterate over. How might I do that?

The README does not list a contact address or mailing list, so I'm making this issue.

Version issues with 5.5 and older

The latest release of the code creates the same issues as #41 as a result of the fix in #61

The fix should have been something like this:

+
+        if vm_name or vm_cpus or vm_memory:
+            params = vcloudType.SourcedCompositionItemParamType()
+            if ((self.version == "1.0") or (self.version == "1.5") 
+                    or (self.version == "5.1") or (self.version == "5.5")):
+                pass
+            else:

I'll put in a pull request for this but I'm not sure how this affects vca-cli as I'm not using it in my environment.

Non consistent return values in vapp.py

When task failed some functions return None, for example connect_vms
some functions raise exception, for example modify_vm_memory
I suppose all functions must raise exception.

Cannot create disk of selected storage profile

Hi,

The current version of pyvcloud doesn't allow to choose the storage profile when creating an independent disk (available through API since vCloud Director for service provider 5.6.3).

Issues with connecting VMs

Currently I have to create a vapp via:

vca.create_vapp(self.vdc_name, self.vapp_name, "mytemplate", "mycatalog")

A Vapp is created and a VM is created. The problem I'm having is related to connecting the Vapp/VM to my Org Network. Defining it in the create_vapp fails and my "workaround" is as follows:

  • Create the Vapp via the create_vapp function
  • Login to a browser and disconnect/delete the NIC that the VM has.
  • Then run another script to that does the following:
        task = the_vapp.disconnect_from_networks()
        result = vca.block_until_completed(task)
        task = the_vapp.connect_to_network(nets[0].name, nets[0].href)
        result = vca.block_until_completed(task)
        # Connect the VMS to the network
        task = the_vapp.connect_vms(nets[0].name, connection_index=0, ip_allocation_mode="POOL")
        result = vca.block_until_completed(task)

I can then see that the vApp is connected to the Proper OrgNetwork, and the VM is also on the right network.

Help?

v4 : Can't login to vCloudDirector

i update to the last version v4. I update my code using new API :

def test_lib():
    vca = vcloudair.VCA(host, user, service_type='ondemand', version='5.1', verify=True)
    # vca.login(host, '%s@%s' % (user, org), password, None, 'vcd', '5.1')
    result = vca.login(password, org)
    print("Result: %s" % result)

Now, i can't log into my vCloudDirector account :

./test.py 
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.vcloud.com
send: 'GET /api/sc/instances HTTP/1.1\r\nHost: api.vcloud.com\r\nConnection: keep-alive\r\nAuthorization: Bearer FCA_OAB01\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json;version=5.1\r\nUser-Agent: python-requests/2.4.3 CPython/2.7.6 Linux/3.13.0-30-generic\r\n\r\n'
reply: 'HTTP/1.1 403 Forbidden\r\n'
header: Date: Tue, 10 Feb 2015 14:41:15 GMT
header: Content-Type: application/vnd.vmware.vcloud.error+xml;version=5.1
header: Date: Tue, 10 Feb 2015 14:41:15 GMT
header: Connection: close
DEBUG:requests.packages.urllib3.connectionpool:"GET /api/sc/instances HTTP/1.1" 403 None
Traceback (most recent call last):
  File "./test.py", line 193, in <module>
    test_lib()
  File "./test.py", line 153, in test_lib
    result = vca.login(password, org)
  File "/home/vagrant/Apps/pyvcloud/pyvcloud/vcloudair.py", line 88, in login
    self.instances = self.get_instances()
  File "/home/vagrant/Apps/pyvcloud/pyvcloud/vcloudair.py", line 139, in get_instances
    if response.history[-1]:
IndexError: list index out of range

Create is failing with vmname

When I try to create vapp with vmname , its failing with error as "BAD REQUEST" , Invalid content was found starting with element 'SourcedItem' .

connect_vms() not checking existing index

I have 10 vnics in my template, so when I created the vapp, I used disconnect_from_networks() to remove all the vnics. After that I found that connect_vms() won't work, complaining that:

<Error xmlns="http://www.vmware.com/vcloud/v1.5" majorErrorCode="400" message="[ d0aae1fa-fef9-42ec-9b92-c4483b4c9552 ] The maximum number of NICs supported for this virtual machine with hardware version 8 is 10." minorErrorCode="BAD_REQUEST" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://us-virginia-1-4.vchs.vmware.com/api/compute/api/v1.5/schema/master.xsd"></Error>

Then I checked the request that connect_vms() made, I found two NetworkConnectionIndex set to 0:
send: 'PUT /api/compute/api/vApp/vm-a5f43a18-d062-4b0d-b215-f1581ccff807/networkConnectionSection/ HTTP/1.1\r\nHost: us-virginia-1-4.vchs.vmware.com\r\nContent-Length: 4080\r\nAccept-Encoding: gzip, deflate\r\nx-vcloud-authorization: 97db3b170a054069807ce6b019413342\r\nAccept: application/*+xml;version=5.7\r\nUser-Agent: python-requests/2.4.3 CPython/2.7.6 Linux/3.13.0-29-generic\r\nConnection: keep-alive\r\n\r\n<vmw:NetworkConnectionSection xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:vmw="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:yyy1="http://schemas.dmtf.org/ovf/envelope/1" yyy1:required="false" href="https://us-virginia-1-4.vchs.vmware.com/api/compute/api/vApp/vm-a5f43a18-d062-4b0d-b215-f1581ccff807/networkConnectionSection/" type="application/vnd.vmware.vcloud.networkConnectionSection+xml"><ovf:Info xmlns:vmw="http://www.vmware.com/vcloud/v1.5" msgid="">Specifies the available VM network connections</ovf:Info><vmw:PrimaryNetworkConnectionIndex>0</vmw:PrimaryNetworkConnectionIndex><vmw:NetworkConnection needsCustomization="true" network="none"><vmw:NetworkConnectionIndex>0</vmw:NetworkConnectionIndex><vmw:IsConnected>false</vmw:IsConnected><vmw:MACAddress>00:50:56:36:52:94</vmw:MACAddress><vmw:IpAddressAllocationMode>NONE</vmw:IpAddressAllocationMode></vmw:NetworkConnection><vmw:NetworkConnection needsCustomization="true" network="none"><vmw:NetworkConnectionIndex>1</vmw:NetworkConnectionIndex><vmw:IsConnected>false</vmw:IsConnected><vmw:MACAddress>00:50:56:36:52:95</vmw:MACAddress><vmw:IpAddressAllocationMode>NONE</vmw:IpAddressAllocationMode></vmw:NetworkConnection><vmw:NetworkConnection needsCustomization="true" network="none"><vmw:NetworkConnectionIndex>2</vmw:NetworkConnectionIndex><vmw:IsConnected>false</vmw:IsConnected><vmw:MACAddress>00:50:56:36:52:96</vmw:MACAddress><vmw:IpAddressAllocationMode>NONE</vmw:IpAddressAllocationMode></vmw:NetworkConnection><vmw:NetworkConnection needsCustomization="true" network="none"><vmw:NetworkConnectionIndex>3</vmw:NetworkConnectionIndex><vmw:IsConnected>false</vmw:IsConnected><vmw:MACAddress>00:50:56:36:52:97</vmw:MACAddress><vmw:IpAddressAllocationMode>NONE</vmw:IpAddressAllocationMode></vmw:NetworkConnection><vmw:NetworkConnection needsCustomization="true" network="none"><vmw:NetworkConnectionIndex>4</vmw:NetworkConnectionIndex><vmw:IsConnected>false</vmw:IsConnected><vmw:MACAddress>00:50:56:36:52:98</vmw:MACAddress><vmw:IpAddressAllocationMode>NONE</vmw:IpAddressAllocationMode></vmw:NetworkConnection><vmw:NetworkConnection needsCustomization="true" network="none"><vmw:NetworkConnectionIndex>5</vmw:NetworkConnectionIndex><vmw:IsConnected>false</vmw:IsConnected><vmw:MACAddress>00:50:56:36:52:99</vmw:MACAddress><vmw:IpAddressAllocationMode>NONE</vmw:IpAddressAllocationMode></vmw:NetworkConnection><vmw:NetworkConnection needsCustomization="true" network="none"><vmw:NetworkConnectionIndex>6</vmw:NetworkConnectionIndex><vmw:IsConnected>false</vmw:IsConnected><vmw:MACAddress>00:50:56:36:52:9a</vmw:MACAddress><vmw:IpAddressAllocationMode>NONE</vmw:IpAddressAllocationMode></vmw:NetworkConnection><vmw:NetworkConnection needsCustomization="true" network="none"><vmw:NetworkConnectionIndex>7</vmw:NetworkConnectionIndex><vmw:IsConnected>false</vmw:IsConnected><vmw:MACAddress>00:50:56:36:52:9b</vmw:MACAddress><vmw:IpAddressAllocationMode>NONE</vmw:IpAddressAllocationMode></vmw:NetworkConnection><vmw:NetworkConnection needsCustomization="true" network="none"><vmw:NetworkConnectionIndex>8</vmw:NetworkConnectionIndex><vmw:IsConnected>false</vmw:IsConnected><vmw:MACAddress>00:50:56:36:52:9c</vmw:MACAddress><vmw:IpAddressAllocationMode>NONE</vmw:IpAddressAllocationMode></vmw:NetworkConnection><vmw:NetworkConnection needsCustomization="true" network="none"><vmw:NetworkConnectionIndex>9</vmw:NetworkConnectionIndex><vmw:IsConnected>false</vmw:IsConnected><vmw:MACAddress>00:50:56:36:52:9d</vmw:MACAddress><vmw:IpAddressAllocationMode>NONE</vmw:IpAddressAllocationMode></vmw:NetworkConnection><vmw:NetworkConnection network="data-1"><NetworkConnectionIndex>0</NetworkConnectionIndex><IsConnected>true</IsConnected><IpAddressAllocationMode>DHCP</IpAddressAllocationMode></vmw:NetworkConnection><vmw:Link href="https://us-virginia-1-4.vchs.vmware.com/api/compute/api/vApp/vm-a5f43a18-d062-4b0d-b215-f1581ccff807/networkConnectionSection/" type="application/vnd.vmware.vcloud.networkConnectionSection+xml" rel="edit"/></vmw:NetworkConnectionSection>'
So do we want to check index before create a new NetworkConnection object?

Thansk,

add_nat_rule ValueError

Other nat rules worked but while trying to add nat rule:
{'TranslatedIp': '10.10.3.3', 'RuleType': 'DNAT', 'Enable': True, 'OriginalPort': 'any', 'TranslatedPort': 'any', 'OriginalIp': '215.216.66.240', 'Protocol': 'TCP', 'Id': 65552}

pyvcloud==15rc2
python2.7

pyvcloud/gateway.py tried to cast port 'any' to an int and failed with a ValueError.
at https://github.com/vmware/pyvcloud/blob/master/pyvcloud/gateway.py#L134

File ".../.env/local/lib/python2.7/site-packages/pyvcloud/gateway.py", line 134, in add_nat_rule
original_port_modified = str(int(original_port_modified) + 1)
ValueError: invalid literal for int() with base 10: 'any'

Upload OVF to a catalog

Is it possible to upload OVF to a catalog? In the VCA class I only method to create a catalog and delete a catalog. How do I upload an OVF to a catalog ?

Thanks

Unknown function get_networkRefs

I try to creates a vApp using documentation. I've got an error on invalid function :

$ ./test.py
Traceback (most recent call last):
  File "./test.py", line 167, in <module>
    '--fencemode': 'bridged'})
  File "/home/vagrant/Apps/pyvcloud/pyvcloud/vclouddirector.py", line 310, in create_vApp
    networkRefs = filter(lambda networkRef: networkRef.get_name().lower() == args["--network"].lower(), self.get_networkRefs())
AttributeError: 'VCD' object has no attribute 'get_networkRefs'

$ ag networkRefs *
README.rst
47:    networks = vcd.get_networkRefs()

pyvcloud/vclouddirector.py
86:    def get_networkRefs(self):
251:                    networkRefs = filter(lambda networkRef: networkRef.get_name().lower() == args["--network"].lower(), self.get_networkRefs())
252:                    if networkRefs:
253:                        network_name = networkRefs[0].get_name()
254:                        network_href = networkRefs[0].get_href()

Bug in _create_instantiateVAppTemplateParams

When creating a new machine, _create_instantiateVAppTemplateParams attempts to pass a set of parameters to the templateParameters, using add_SourcedItem. Unfortunately, add_SourcedItem isn't supported in versions older than 5.6, so the whole operation fails.
The snippet below is where things break, on the line
templateParams.add_SourcedItem(params)

if ((self.version == "1.0") or (self.version == "1.5") or
           (self.version == "5.1") or (self.version == "5.5")):
            if vm_name or vm_cpus or vm_memory:
                params = vcloudType.SourcedVmInstantiationParamsType()
                params.set_Source(vcloudType.ReferenceType(href=vm_href))
                templateParams.add_SourcedItem(params)
                if vm_name:
                    pass```

can't login if the SSL certificate is self signed

My VCloud Director works with a self signed SSL certificate.
When I try to log on, I got this error

/usr/lib/python2.6/site-packages/pyvcloud-0.8-py2.6.egg/pyvcloud/vcloudair.pyc in login(self, host, username, password, token, service_type, version)
71 headers["Authorization"] = encode.rstrip()
72 headers["Accept"] = "application/xml;version=" + version
---> 73 response = requests.post(url, headers=headers)
74 if response.status_code == requests.codes.created:
75 self.host = host

/usr/lib/python2.6/site-packages/requests-2.4.3-py2.6.egg/requests/api.pyc in post(url, data, json, *_kwargs)
92 """
93
---> 94 return request('post', url, data=data, json=json, *_kwargs)
95
96

/usr/lib/python2.6/site-packages/requests-2.4.3-py2.6.egg/requests/api.pyc in request(method, url, *_kwargs)
47
48 session = sessions.Session()
---> 49 return session.request(method=method, url=url, *_kwargs)
50
51

/usr/lib/python2.6/site-packages/requests-2.4.3-py2.6.egg/requests/sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
455 }
456 send_kwargs.update(settings)
--> 457 resp = self.send(prep, **send_kwargs)
458
459 return resp

/usr/lib/python2.6/site-packages/requests-2.4.3-py2.6.egg/requests/sessions.pyc in send(self, request, *_kwargs)
567
568 # Send the request
--> 569 r = adapter.send(request, *_kwargs)
570
571 # Total elapsed time of the request (approximately)

/usr/lib/python2.6/site-packages/requests-2.4.3-py2.6.egg/requests/adapters.pyc in send(self, request, stream, timeout, verify, cert, proxies)
418 except (_SSLError, _HTTPError) as e:
419 if isinstance(e, _SSLError):
--> 420 raise SSLError(e, request=request)
421 elif isinstance(e, ReadTimeoutError):
422 raise ReadTimeout(e, request=request)

Is there a way to force the script not to check the Certificate validity ?

Thanks for your answer

Error during poweroff action

I try to poweroff an existing vApp :

print("VAPP: %s" % vapp)
print("Poweroff vApp")
task_poweroff = vapp.poweroff()
task_poweroff_status = vca.block_until_completed(task_poweroff)
if task_poweroff_status is True:
    print("Poweron vApp")
    task_poweron = vapp.poweron()
    task_poweron_status = vca.block_until_completed(task_poweron)
    if task_poweron_status is True:
        print("vApp is ready")

The output :

VAPP: <pyvcloud.vapp.VAPP object at 0x3dea910>
Poweroff vApp
unable to execute vApp operation: power:powerOff
Traceback (most recent call last):
  File "./test.py", line 151, in <module>
    test_lib()
  File "./test.py", line 142, in test_lib
    task_poweroff_status = vca.block_until_completed(task_poweroff)
  File "/home/vagrant/Apps/pyvcloud/pyvcloud/vcloudair.py", line 342, in block_until_completed
    progress = task.get_Progress()
AttributeError: 'bool' object has no attribute 'get_Progress'
`̀̀``

vCloudEntities.py invalid syntax in python3

Traceback (most recent call last):
....
....
from pyvcloud.schema.vcd.v1_5.schemas.admin import vCloudEntities
File "/Users/myfile/bin/pyvcloud/pyvcloud/schema/vcd/v1_5/schemas/admin/vCloudEntities.py", line 94
except ImportError, exp:
^
SyntaxError: invalid syntax

Using python3

Create VApp with network

Now VApp is getting created without any proper network , no implementation in Vapp to accept networks.I can implement it , what is the procedure now?

issue of insert media

after insert ISO to CD/DVD sometime show "internal error" in response , in the vm_media function the format string is not correct,
the format should be "(media.get('type'), media.get('name'), media.get('href')".

Network issue when create a Vapp

task = vcd.create_vApp('mytestvapp', 'Windows_XP_Pro_SP3_x86_en-US', 'Windows_XP_x86_SP3' , {'--blocking': True, '--json': True, '--deploy': True, '--on': True, '--network': 'RD LAN', '--fencemode': 'bridged'})
the result,
BAD_REQUEST The VCD entity network "VM Network" does not exist

seems create_vApp still using default VM Network network? (This is for sure. https://communities.vmware.com/message/2457934)

but when i didn't configure the Network when creating Vapps and try to connect the correct network after running below codes:
myvapp.connect_vms('RD LAN', 'POOL')

It told me the network RD LAN didn't exist.

but when i run
networks = vcd.get_networkRefs()
print networks[0].name

the result is RD LAN

Misleading Test/Documentation or Feature Request

Test 0024 in (vcloud_tests.py line 619) seems to indicate that you can and pass cpus and memory as arguments when testing compose_vapp().

    vm_specs = [{
        'template': template,
        'catalog': catalog,
        'name': vm_name,
        'cpus': 3,
        'memory': 4096,
        'storage_profile': storage_profile
    }]

compose_vapp() however does not take either of those two items from the dictionary and put them into the params object.

Can the documentation be updated, an example provided on how to do this if supported, or ideally the compose_vapp updated to allow setting the cpu and memory if it is not. I'm hopeful as this project is under active development, and it would make sense to complete the provisioning of the target VM at the time the vApp is created to avoid additional coding, or taking additional time/cycles of the vCloud.

Bonus if there is an option to set a customization script at this phase, no worries as I'm going to force configuration and power on afterwards.

Thanks,

-Matt

Not able to login to ondemand (host=iam.vchs.vmware.com, version=5.7)

I've been using them for a month and from yesterday I started to get a "HTTP/1.1 403 Forbidden" when doing the first login:

vca = VCA(host=host, username=username, service_type='ondemand',
          version='5.7', verify=True)
result = vca.login(password=password)

The debug is as below. /api/sc/instances gets a 403:

INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): iam.vchs.vmware.com
send: 'POST /api/iam/login HTTP/1.1\r\nHost: iam.vchs.vmware.com\r\nContent-Length: 0\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json;version=5.7\r\nUser-Agent: python-requests/2.4.3 CPython/2.7.6 Linux/3.13.0-29-generic\r\nConnection: keep-alive\r\nAuthorization: Basic <...>\r\n\r\n'
reply: 'HTTP/1.1 201 Created\r\n'
header: Date: Tue, 07 Apr 2015 20:25:03 GMT
header: Via: 1.1 Repose (Repose/6.2.2.0)
header: Date: Tue, 07 Apr 2015 20:25:04 GMT
header: vchs-authorization: eyJhbGciOiJSUzI1NiJ9.eyJqdGkiOiIyZDNmOTE4NC1hMjUyLTRiODYtYTMzMy0xYTVkMWY0ZWY1ZWMiLCJzdWIiOiI5YjcxNzViYS1hYzgzLTRhYjgtOGJkOC1lNzg1NjZiOWMzN2IiLCJzY29wZSI6WyIyIiwiMyIsIm9wZW5pZCJdLCJjbGllbnRfaWQiOiJ2Y2hzX3NjIiwiZ3JhbnRfdHlwZSI6ImltcGxpY2l0IiwidXNlcl9pZCI6IjliNzE3NWJhLWFjODMtNGFiOC04YmQ4LWU3ODU2NmI5YzM3YiIsImVtYWlsIjoiYm93ZW4ubGlAYXZpbmV0d29ya3MuY29tIiwidXNlcl9uYW1lIjoiYm93ZW4ubGlAYXZpbmV0d29ya3MuY29tIiwiY29tcGFueV9pZCI6IjlkMjVkYzc0LTE2ZmQtNDQyNS1hOGUwLTE5Mzk2NDVjNzhjNCIsImNvbXBhbnlfbmFtZSI6Ik11cmFsaSBCYXNhdmFpYWgiLCJjdXN0b21lcl9udW1iZXIiOiIiLCJzZ19pZCI6WyI4ZjY1NjYxYS1kZTY5LTRkMjAtODBlMy1lZTAxZTUzMGM4NGIiLCIxNmU5MDEzNi04MmY0LTRmNjgtYjA3Yy0wOTQwNmIwODU4ODciXSwidmVyc2lvbiI6IjEuMCIsInBsYW5zIjpbXSwiaWF0IjoxNDI4NDM4MzA0LCJleHAiOjE0Mjg0MzkyMDQsImlzcyI6Imh0dHBzOi8vaWFtLnZjaHMudm13YXJlLmNvbS9vYXV0aC90b2tlbiIsImF1ZCI6WyJvcGVuaWQiXX0.FyEPFmPfjMxYEGlMqmYi-ecPuNn7-9oRS5mCx1-7fkZ767jLv8GCITEvQ04QYr7rkyUI00IBAmQHGSC9Vg5Ol1AOcaaBJqX9-TLbiFNeIZOBOYg5zO6NS2xNj0D3abVY3IdFT___pQdFov1y1xJXWhUC8o69Q_WUYRx4afKM6USP546k5SIuF-L4HkSG23oufs0IfB3KH0nIc_JmMs-zbbUKfAR3GANqJhfitUW1A5TLtLyIh5Tpq6Cq8JhggL6uimYDMCUFRwqibnNK1jrXMllBRHAULbA2n6PGg2GASMC_sZr3j4LgiDEaXQ60yQiEeonkiDqVwSwo0STB8Bzvnw
header: Content-Type: application/json; version=5.7
header: Content-Length: 99
header: Connection: close
header: Server: Jetty(9.2.z-SNAPSHOT)
DEBUG:requests.packages.urllib3.connectionpool:"POST /api/iam/login HTTP/1.1" 201 99
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): iam.vchs.vmware.com
send: 'GET /api/sc/instances HTTP/1.1\r\nHost: iam.vchs.vmware.com\r\nConnection: keep-alive\r\nAuthorization: Bearer eyJhbGciOiJSUzI1NiJ9.eyJqdGkiOiIyZDNmOTE4NC1hMjUyLTRiODYtYTMzMy0xYTVkMWY0ZWY1ZWMiLCJzdWIiOiI5YjcxNzViYS1hYzgzLTRhYjgtOGJkOC1lNzg1NjZiOWMzN2IiLCJzY29wZSI6WyIyIiwiMyIsIm9wZW5pZCJdLCJjbGllbnRfaWQiOiJ2Y2hzX3NjIiwiZ3JhbnRfdHlwZSI6ImltcGxpY2l0IiwidXNlcl9pZCI6IjliNzE3NWJhLWFjODMtNGFiOC04YmQ4LWU3ODU2NmI5YzM3YiIsImVtYWlsIjoiYm93ZW4ubGlAYXZpbmV0d29ya3MuY29tIiwidXNlcl9uYW1lIjoiYm93ZW4ubGlAYXZpbmV0d29ya3MuY29tIiwiY29tcGFueV9pZCI6IjlkMjVkYzc0LTE2ZmQtNDQyNS1hOGUwLTE5Mzk2NDVjNzhjNCIsImNvbXBhbnlfbmFtZSI6Ik11cmFsaSBCYXNhdmFpYWgiLCJjdXN0b21lcl9udW1iZXIiOiIiLCJzZ19pZCI6WyI4ZjY1NjYxYS1kZTY5LTRkMjAtODBlMy1lZTAxZTUzMGM4NGIiLCIxNmU5MDEzNi04MmY0LTRmNjgtYjA3Yy0wOTQwNmIwODU4ODciXSwidmVyc2lvbiI6IjEuMCIsInBsYW5zIjpbXSwiaWF0IjoxNDI4NDM4MzA0LCJleHAiOjE0Mjg0MzkyMDQsImlzcyI6Imh0dHBzOi8vaWFtLnZjaHMudm13YXJlLmNvbS9vYXV0aC90b2tlbiIsImF1ZCI6WyJvcGVuaWQiXX0.FyEPFmPfjMxYEGlMqmYi-ecPuNn7-9oRS5mCx1-7fkZ767jLv8GCITEvQ04QYr7rkyUI00IBAmQHGSC9Vg5Ol1AOcaaBJqX9-TLbiFNeIZOBOYg5zO6NS2xNj0D3abVY3IdFT___pQdFov1y1xJXWhUC8o69Q_WUYRx4afKM6USP546k5SIuF-L4HkSG23oufs0IfB3KH0nIc_JmMs-zbbUKfAR3GANqJhfitUW1A5TLtLyIh5Tpq6Cq8JhggL6uimYDMCUFRwqibnNK1jrXMllBRHAULbA2n6PGg2GASMC_sZr3j4LgiDEaXQ60yQiEeonkiDqVwSwo0STB8Bzvnw\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json;version=5.7\r\nUser-Agent: python-requests/2.4.3 CPython/2.7.6 Linux/3.13.0-29-generic\r\n\r\n'
reply: 'HTTP/1.1 403 Forbidden\r\n'
header: Date: Tue, 07 Apr 2015 20:25:04 GMT
header: X-Frame-Options: SAMEORIGIN
header: Via: 1.1 Repose (Repose/6.2.2.0)
header: Content-Length: 0
header: Connection: close
header: Server: Jetty(9.2.z-SNAPSHOT)
DEBUG:requests.packages.urllib3.connectionpool:"GET /api/sc/instances HTTP/1.1" 403 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aviuser/pyvcloud/pyvcloud/pyvcloud/vcloudair.py", line 117, in login
    self.instances = self.get_instances()
  File "/home/aviuser/pyvcloud/pyvcloud/pyvcloud/vcloudair.py", line 157, in get_instances
    if self.response.history[-1]:
IndexError: list index out of range

Do you know if it's a permission issue or something else? I updated the pyvcloud to the newest version and seems like it's still not working.

Thanks!

vApp creation example

could you please add into the README, or examples packages how creating vApp from vca.
Thanks

Bad login URL for vCloud Director

According to http://www.vmware.com/pdf/vcd_15_api_guide.pdf (p.42), it's necessary to determine login URL before gathering auth token from vCloud Director's API and I saw hardcoded '/api/iam/login' string in 2 places.
Correct URL can be determined by sending unauthorized GET /api/versions and finding "LoginUrl" tag for given version.
In my case it points to /api/sessions and I can't connect to it using vca-cli.
Servers gives following logs:

  • - [04/Feb/2016:09:56:20 +0200] "POST /api/iam/login HTTP/1.1" 403 353 "-" "python-requests/2.9.1"

Did it support Vcloud API version 5.5?

Hi , i tried this,

vca = VCA()
vca.login('https://vclouddirectorhost.domain.com', 'username@organization', 'password', None, 'vcd', '5.5')
vcd = vca.get_vCloudDirector()
vapps = vcd.get_vApps()

but vcd didn't get the correct vCloudDirector instance, it gets None.

so i want to known that did the parseString function also worked for version 5.5?

THANKS

Errors in automatic generated files

In several files in dir pyvcloud/schema/vcd/v1_5/schemas/vcloud (for example networkType.py)
I found error in GDSClassesMapping dictonary.
The node's root tag name and corresponding class are swapped.
I found two mismatches:
'AllocatedIpAddresses': IpAddressesType
'IpAddress': AllocatedIpAddressType
Therefore if I try parse string with root node AllocatedIpAddresses, the parser try use build function from IpAddressesType class.

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.