├── .github
└── CODEOWNERS
├── .gitignore
├── .travis.yml
├── CODE-OF-CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── issue_template.md
├── lib
├── README.md
├── index.html
├── nsx-policy-python-sdk
│ ├── index.html
│ └── nsx_policy_python_sdk-4.2.0-py2.py3-none-any.whl
├── nsx-python-sdk
│ ├── index.html
│ └── nsx_python_sdk-4.2.0-py2.py3-none-any.whl
├── nsx-vmc-aws-integration-python-sdk
│ ├── index.html
│ └── nsx_vmc_aws_integration_python_sdk-4.1.2.0.1-py2.py3-none-any.whl
├── nsx-vmc-policy-python-sdk
│ ├── index.html
│ └── nsx_vmc_policy_python_sdk-4.1.2.0.1-py2.py3-none-any.whl
├── src
│ ├── vmwarecloud-aws
│ │ └── vmwarecloud_aws-1.64.1.zip
│ └── vmwarecloud-draas
│ │ └── vmwarecloud_draas-1.23.1.zip
├── vmwarecloud-aws
│ ├── index.html
│ └── vmwarecloud_aws-1.64.1-py2.py3-none-any.whl
└── vmwarecloud-draas
│ ├── index.html
│ └── vmwarecloud_draas-1.23.1-py2.py3-none-any.whl
├── open_source_licenses.txt
├── requirements.txt
├── requirements_pypi.txt
├── sample_template
├── README.md
├── __init__.py
├── sample_template_basic.py
└── sample_template_complex.py
├── samples
├── README.md
├── __init__.py
├── vmc
│ ├── README.md
│ ├── __init__.py
│ ├── draas
│ │ ├── __init__.py
│ │ ├── activate_srm_ops.py
│ │ ├── deploy_additional_instance.py
│ │ ├── deploy_additional_node.py
│ │ ├── get_srm_info.py
│ │ ├── helpers
│ │ │ ├── __init__.py
│ │ │ └── draas_task_helper.py
│ │ ├── site_recovery_activation_ops.py
│ │ └── site_recovery_info.py
│ ├── helpers
│ │ ├── __init__.py
│ │ ├── sample_cli.py
│ │ └── vmc_task_helper.py
│ ├── networks_nsxt
│ │ ├── cgw_firewall_crud.py
│ │ ├── dfw_firewall_crud.py
│ │ ├── hello_world.py
│ │ ├── l3_vpn_crud.py
│ │ ├── nat_crud.py
│ │ ├── security_group_create.py
│ │ ├── security_group_delete.py
│ │ ├── security_group_list.py
│ │ ├── security_group_update.py
│ │ └── segments_firewall_crud.py
│ ├── networks_nsxv
│ │ ├── __init__.py
│ │ ├── dns_crud.py
│ │ ├── expose_public_ip.py
│ │ ├── firewall_rules_crud.py
│ │ ├── ipsec_vpns_crud.py
│ │ ├── logical_network_crud.py
│ │ ├── nat_rule_crud.py
│ │ └── public_ip_crud.py
│ ├── orgs
│ │ ├── README.md
│ │ ├── __init__.py
│ │ └── organization_operations.py
│ ├── sddc
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── add_remove_hosts.py
│ │ ├── connect_to_vsphere_with_default_sddc_password.py
│ │ ├── deploy_ovf_template.py
│ │ └── sddc_crud.py
│ └── tasks
│ │ ├── cancel_task.py
│ │ ├── list_tasks.py
│ │ └── list_tasks_stg.py
├── vsan
│ └── snapservice
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── protection_group
│ │ ├── __init__.py
│ │ ├── create_protection_group.py
│ │ ├── delete_protection_groups.py
│ │ └── list_protection_groups.py
│ │ ├── snapshot
│ │ ├── __init__.py
│ │ └── delete_protection_group_snapshots.py
│ │ └── vsan_snapservice_client.py
└── vsphere
│ ├── README.md
│ ├── __init__.py
│ ├── appliances
│ ├── get_service.py
│ ├── health_messages.py
│ ├── list_service.py
│ ├── monitoring_query.py
│ ├── patching
│ │ ├── README.md
│ │ ├── __init__.py
│ │ └── update_sample.py
│ └── timezone.py
│ ├── backuprestore
│ ├── README.md
│ ├── __init__.py
│ ├── backup_job_list.py
│ └── backup_schedule.py
│ ├── common
│ ├── __init__.py
│ ├── connect_with_cert.py
│ ├── id_generator.py
│ ├── lookup_service_helper.py
│ ├── platform_service_controller.py
│ ├── sample_base.py
│ ├── sample_cli.py
│ ├── sample_util.py
│ ├── service_manager.py
│ ├── service_manager_factory.py
│ ├── ssl_helper.py
│ ├── sso.py
│ ├── vapiconnect.py
│ └── vim
│ │ ├── __init__.py
│ │ ├── datastore_file.py
│ │ ├── file.py
│ │ ├── helpers
│ │ ├── __init__.py
│ │ ├── get_cluster_by_name.py
│ │ ├── get_datastore_by_name.py
│ │ └── vim_utils.py
│ │ ├── inventory.py
│ │ └── vmdk.py
│ ├── compute_policy
│ ├── README.md
│ └── compute_policy_workflow.py
│ ├── contentlibrary
│ ├── README.md
│ ├── __init__.py
│ ├── contentupdate
│ │ ├── __init__.py
│ │ └── content_update.py
│ ├── crud
│ │ ├── __init__.py
│ │ └── library_crud.py
│ ├── isomount
│ │ ├── __init__.py
│ │ └── iso_mount.py
│ ├── lib
│ │ ├── __init__.py
│ │ ├── cls_api_client.py
│ │ ├── cls_api_helper.py
│ │ └── cls_sync_helper.py
│ ├── ovaimport
│ │ └── signed_ova_import.py
│ ├── ovfdeploy
│ │ ├── __init__.py
│ │ └── deploy_ovf_template.py
│ ├── ovfimport
│ │ ├── __init__.py
│ │ └── ovf_import_export.py
│ ├── publishsubscribe
│ │ ├── __init__.py
│ │ └── library_publish_subscribe.py
│ ├── resources
│ │ ├── isoImages
│ │ │ ├── test-2.iso
│ │ │ └── test.iso
│ │ ├── plainVmTemplate
│ │ │ ├── plain-vm.ovf
│ │ │ └── plain-vm.vmdk
│ │ ├── signedOvaWithCertWarning
│ │ │ └── nostalgia-signed.ova
│ │ └── simpleVmTemplate
│ │ │ ├── descriptor.ovf
│ │ │ └── disk-0.vmdk
│ ├── vmcapture
│ │ ├── __init__.py
│ │ └── vm_template_capture.py
│ ├── vmtemplate
│ │ ├── __init__.py
│ │ ├── check_out_vm_template_workflow.py
│ │ ├── create_vm_template.py
│ │ └── deploy_vm_template.py
│ └── vmtx_sync
│ │ ├── __init__.py
│ │ └── vmtx_publish.py
│ ├── deferhistoryimport
│ ├── README.md
│ ├── __init__.py
│ ├── vc_import_history_cli.py
│ ├── vc_import_history_common.py
│ └── vc_import_history_sample.py
│ ├── hardwaretpm
│ ├── README.md
│ └── tpm_info.py
│ ├── logforwarding
│ ├── README.md
│ └── log_forwarding.py
│ ├── oauth
│ ├── __init__.py
│ ├── exchange_access_id_token_for_saml.py
│ ├── grant_types
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── list_vms_authorization_code.py
│ │ ├── list_vms_client_credentials.py
│ │ ├── list_vms_password.py
│ │ ├── list_vms_refresh_token.py
│ │ ├── oauth_utility.py
│ │ └── webserver.py
│ └── list_external_identity_providers.py
│ ├── services
│ └── services_list.py
│ ├── sso
│ ├── README.md
│ ├── __init__.py
│ ├── embedded_psc_sso_workflow.py
│ ├── external_psc_sso_workflow.py
│ └── wsdl
│ │ ├── lookup.wsdl
│ │ └── lookupservice.wsdl
│ ├── tagging
│ ├── README.md
│ ├── __init__.py
│ └── tagging_workflow.py
│ └── vcenter
│ ├── README.md
│ ├── __init__.py
│ ├── certificatemanagement
│ ├── README.md
│ ├── gencsr.py
│ ├── get_tls_certificate.py
│ ├── renew_tls_certificate.py
│ ├── replace_tls_certificate.py
│ ├── replace_tls_certificate_with_vmca_signed.py
│ ├── replace_vmca_root.py
│ ├── trusted_root_chains_create.py
│ ├── trusted_root_chains_delete.py
│ ├── trusted_root_chains_get.py
│ └── trusted_root_chains_list.py
│ ├── crypto_manager
│ └── kms
│ │ └── native_key_provider.py
│ ├── discovery_and_plan
│ ├── README.md
│ ├── __init__.py
│ ├── discovery_sample.py
│ ├── lcm_sample.py
│ └── update_sample.py
│ ├── guest
│ ├── cloudinitDataCustomizationSpecs.py
│ ├── customizationSpecs.py
│ ├── customizationSpecs_import_export.py
│ ├── linSpec.cfg
│ ├── sample_import.json
│ ├── sample_metadata.json
│ ├── sample_metadata.yaml
│ ├── sample_userdata
│ └── winSpec.cfg
│ ├── hcl
│ ├── README.md
│ ├── __init__.py
│ ├── compatibility_data_status_sample.py
│ ├── compatibility_data_update_sample.py
│ ├── compatibility_releases_sample.py
│ ├── compatibility_report_sample.py
│ └── utils.py
│ ├── helper
│ ├── __init__.py
│ ├── cluster_helper.py
│ ├── datacenter_helper.py
│ ├── datastore_helper.py
│ ├── folder_helper.py
│ ├── guest_helper.py
│ ├── network_helper.py
│ ├── resource_pool_helper.py
│ ├── vm_helper.py
│ └── vm_placement_helper.py
│ ├── hvc
│ ├── README.md
│ ├── administrator_client.py
│ └── links_client.py
│ ├── namespace_management
│ ├── list_clusters.py
│ └── supervisor_services
│ │ ├── list_supervisor_services.py
│ │ └── list_supervisor_services_on_cluster.py
│ ├── privilege_checks
│ └── get_priv_checks_for_workflow.py
│ ├── setup
│ ├── README.md
│ ├── __init__.py
│ ├── backend_directory.py
│ ├── cluster.py
│ ├── datacenter.py
│ ├── datastore.py
│ ├── floppy_image.py
│ ├── folder.py
│ ├── host.py
│ ├── iso_image.py
│ ├── main.py
│ ├── network.py
│ ├── setup_cli.py
│ ├── testbed.py
│ └── testbed_setup.py
│ ├── single_session
│ ├── pyvmomi_to_vapi_transfer.py
│ └── vapi_to_pyvmomi_transfer.py
│ ├── topologysvc
│ ├── README.md
│ ├── get_node.py
│ ├── list_embedded_nodes.py
│ ├── list_node_replication_status.py
│ ├── list_nodes.py
│ └── list_replication_status.py
│ ├── transcoder
│ └── transcode.py
│ ├── vlcm
│ ├── README.md
│ ├── __init__.py
│ └── cluster
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── hcl
│ │ ├── README.md
│ │ ├── __init__.py
│ │ └── hw_compatibility_details_sample.py
│ │ └── installed_images
│ │ ├── README.md
│ │ ├── __init__.py
│ │ └── installed_images.py
│ ├── vm
│ ├── README.md
│ ├── __init__.py
│ ├── create
│ │ ├── __init__.py
│ │ ├── create_basic_vm.py
│ │ ├── create_default_vm.py
│ │ └── create_exhaustive_vm.py
│ ├── delete_vm.py
│ ├── guest
│ │ ├── customize_vm.py
│ │ ├── customize_vm_with_cloudinit_data.py
│ │ ├── guest_ops.py
│ │ ├── info.py
│ │ └── power.py
│ ├── hardware
│ │ ├── __init__.py
│ │ ├── adapter
│ │ │ ├── __init__.py
│ │ │ ├── sata.py
│ │ │ └── scsi.py
│ │ ├── boot.py
│ │ ├── boot_device.py
│ │ ├── cdrom.py
│ │ ├── cpu.py
│ │ ├── disk.py
│ │ ├── ethernet.py
│ │ ├── floppy.py
│ │ ├── main.py
│ │ ├── memory.py
│ │ ├── parallel.py
│ │ └── serial.py
│ ├── list_vms.py
│ ├── main.py
│ ├── placement.py
│ └── power.py
│ ├── vstats
│ ├── README.md
│ ├── __init__.py
│ ├── acquisitionspec
│ │ ├── __init__.py
│ │ └── lifecycle.py
│ ├── data
│ │ ├── __init__.py
│ │ ├── query_data_points.py
│ │ ├── query_data_points_set_id.py
│ │ └── query_data_points_with_predicate.py
│ ├── discovery.py
│ └── helpers
│ │ ├── __init__.py
│ │ └── sample_cli.py
│ └── wcp
│ ├── README.md
│ ├── enable_on_zones.py
│ ├── get_supervisor_summary.py
│ └── list_supervisor_summary.py
├── setup.cfg
├── setup.py
├── test-requirements.txt
└── tests
├── test_vmc_client.py
└── test_vsphere_client.py
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # These owners will be the default owners for everything in the repo. Unless a later match takes
2 | # precedence all these users will be requested for review when someone opens a pull request.
3 | * @vmware/vmware_sdk_team
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.py[cod]
2 | __pycache__/
3 | .DS_Store
4 | .idea/*
5 | .gradle/*
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: python
2 | python:
3 | - "2.7"
4 | - "3.6"
5 | # command to install dependencies
6 | install:
7 | - pip install -r requirements.txt --extra-index-url file://$PWD/lib --upgrade --ignore-installed six
8 | - pip install -r test-requirements.txt
9 | # command to run tests
10 | script:
11 | - pycodestyle samples tests
12 | - pytest
13 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Submitting samples
2 |
3 | ### Developer Certificate of Origin
4 |
5 | Before you start working with this project, please read our [Developer Certificate of Origin](https://cla.vmware.com/dco). 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.
6 |
7 | ### Sample Template
8 |
9 | [Sample template](sample_template) contains boilerplate code that can be used to build a new sample.
10 | Please copy one of the files and use it as a starting point to write a new sample.
11 |
12 | ### Required Information
13 |
14 | The following information must be included in the README.md or in the sample docstring in case README already exists in same folder.
15 | * Author Name
16 | * This can include full name, email address or other identifiable piece of information that would allow interested parties to contact author with questions.
17 | * Compatible vCenter version
18 | * This should be the vCenter version when the API is introduced, something like "6.5+" or "6.8.1+".
19 | * Minimal/High Level Description
20 | * What does the sample do ?
21 | * Any KNOWN limitations or dependencies
22 |
23 | ### Contribution Process
24 |
25 | * Follow the [GitHub process](https://help.github.com/articles/fork-a-repo)
26 | * Please use one branch per sample or change-set
27 | * Please use one commit and pull request per sample
28 | * Please post the sample output along with the pull request
29 | * If you include a license with your sample, use the project license
30 |
31 | ### Code Style
32 |
33 | Please conform to pep8 standards: https://pypi.python.org/pypi/pep8 with exceptions listed in setup.cfg
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016-2024 Broadcom, Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/issue_template.md:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 | - [ ] I am using the [latest SDK version](https://github.com/vmware/vsphere-automation-sdk-python/releases)
9 | - [ ] This API is compatible with my vCenter version (You can get the info from '__vcenter_version__' in each sample)
10 | - [ ] I have searched [existing issues](https://github.com/vmware/vsphere-automation-sdk-python/issues?utf8=%E2%9C%93&q=is%3Aissue) and [Troubleshooting wiki](https://github.com/vmware/vsphere-automation-sdk-python/wiki/Troubleshooting)
11 |
12 | ## Environment
13 | - sdk package version:
14 |
15 |
16 | - python version:
17 |
18 |
19 | - vSphere version:
20 |
21 | - Operating System/Shell (used to run SDK-based apps):
22 |
23 | ## Steps or code snippet to reproduce
24 |
25 | ## Actual behavior
26 |
27 | ## Expected behavior
28 |
--------------------------------------------------------------------------------
/lib/README.md:
--------------------------------------------------------------------------------
1 | # SDK libraries
2 |
3 | For python developers, client libraries are supplied for testing and development purposes. All the supplied libraries are located under lib directory.
4 |
5 | Name | Description
6 | ------------------------------------| -------------
7 | vmwarecloud_aws | Client stubs for VMware Cloud on AWS Console APIs
8 | vmwarecloud_draas | Client stubs for VMware Cloud (VMC) Disaster Recovery as a Service (DRaaS) APIs
9 | nsx-python-sdk | Client stubs for VMware NSX-T APIs
10 | nsx-vmc-policy-python-sdk | Client stubs for VMware NSX-T on VMC Policy APIs
11 | nsx-vmc-aws-integration-python-sdk | Client stubs for VMware NSX-T AWS integration app APIs (for AWS underlay management)
12 |
--------------------------------------------------------------------------------
/lib/index.html:
--------------------------------------------------------------------------------
1 |
2 |
Simple Index
3 |
4 |
5 |
6 | vmwarecloud-aws
7 | vmwarecloud-draas
8 | nsx-python-sdk
9 | nsx-policy-python-sdk
10 | nsx-vmc-policy-python-sdk
11 | nsx-vmc-aws-integration-python-sdk
12 |
13 |
14 |
--------------------------------------------------------------------------------
/lib/nsx-policy-python-sdk/index.html:
--------------------------------------------------------------------------------
1 | nsx_policy_python_sdk-4.2.0-py2.py3-none-any.whl
2 |
--------------------------------------------------------------------------------
/lib/nsx-policy-python-sdk/nsx_policy_python_sdk-4.2.0-py2.py3-none-any.whl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/lib/nsx-policy-python-sdk/nsx_policy_python_sdk-4.2.0-py2.py3-none-any.whl
--------------------------------------------------------------------------------
/lib/nsx-python-sdk/index.html:
--------------------------------------------------------------------------------
1 | nsx_python_sdk-4.2.0-py2.py3-none-any.whl
2 |
--------------------------------------------------------------------------------
/lib/nsx-python-sdk/nsx_python_sdk-4.2.0-py2.py3-none-any.whl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/lib/nsx-python-sdk/nsx_python_sdk-4.2.0-py2.py3-none-any.whl
--------------------------------------------------------------------------------
/lib/nsx-vmc-aws-integration-python-sdk/index.html:
--------------------------------------------------------------------------------
1 | nsx_vmc_aws_integration_python_sdk-4.1.2.0.1-py2.py3-none-any.whl
2 |
--------------------------------------------------------------------------------
/lib/nsx-vmc-aws-integration-python-sdk/nsx_vmc_aws_integration_python_sdk-4.1.2.0.1-py2.py3-none-any.whl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/lib/nsx-vmc-aws-integration-python-sdk/nsx_vmc_aws_integration_python_sdk-4.1.2.0.1-py2.py3-none-any.whl
--------------------------------------------------------------------------------
/lib/nsx-vmc-policy-python-sdk/index.html:
--------------------------------------------------------------------------------
1 | nsx_vmc_policy_python_sdk-4.1.2.0.1-py2.py3-none-any.whl
2 |
--------------------------------------------------------------------------------
/lib/nsx-vmc-policy-python-sdk/nsx_vmc_policy_python_sdk-4.1.2.0.1-py2.py3-none-any.whl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/lib/nsx-vmc-policy-python-sdk/nsx_vmc_policy_python_sdk-4.1.2.0.1-py2.py3-none-any.whl
--------------------------------------------------------------------------------
/lib/src/vmwarecloud-aws/vmwarecloud_aws-1.64.1.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/lib/src/vmwarecloud-aws/vmwarecloud_aws-1.64.1.zip
--------------------------------------------------------------------------------
/lib/src/vmwarecloud-draas/vmwarecloud_draas-1.23.1.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/lib/src/vmwarecloud-draas/vmwarecloud_draas-1.23.1.zip
--------------------------------------------------------------------------------
/lib/vmwarecloud-aws/index.html:
--------------------------------------------------------------------------------
1 | vmwarecloud_aws-1.64.1-py2.py3-none-any.whl
2 |
--------------------------------------------------------------------------------
/lib/vmwarecloud-aws/vmwarecloud_aws-1.64.1-py2.py3-none-any.whl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/lib/vmwarecloud-aws/vmwarecloud_aws-1.64.1-py2.py3-none-any.whl
--------------------------------------------------------------------------------
/lib/vmwarecloud-draas/index.html:
--------------------------------------------------------------------------------
1 | vmwarecloud_draas-1.23.1-py3.py3-none-any.whl
2 |
--------------------------------------------------------------------------------
/lib/vmwarecloud-draas/vmwarecloud_draas-1.23.1-py2.py3-none-any.whl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/lib/vmwarecloud-draas/vmwarecloud_draas-1.23.1-py2.py3-none-any.whl
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | ###### Common requirements ######
2 | lxml >= 4.3.0
3 | six (>=1.12)
4 |
5 | requests (>=2.27.1)
6 | pyOpenSSL (>=22.0.0)
7 | cryptography (>=37.0.2)
8 | setuptools (>=62.3.2)
9 | ###### SDK requirements ######
10 | pyVmomi >=8.0.3.0.1
11 | vmware-vcenter == 8.0.3.0
12 | vmwarecloud-aws
13 | nsx-python-sdk
14 | nsx-policy-python-sdk
15 | nsx-vmc-policy-python-sdk
16 | nsx-vmc-aws-integration-python-sdk
17 | vmwarecloud-draas
18 |
--------------------------------------------------------------------------------
/requirements_pypi.txt:
--------------------------------------------------------------------------------
1 | ###### This requirements file is used for local installation where access to GitHub is restricted ######
2 | ###### Common requirements ######
3 | lxml >= 4.3.0
4 | six (>=1.12)
5 | requests (>=2.27.1)
6 | pyOpenSSL (>=22.0.0)
7 | cryptography (>=37.0.2)
8 | setuptools (>=62.3.2)
9 | ###### SDK requirements ######
10 | pyVmomi >= 8.0.3.0.1
11 | vmware-vcenter == 8.0.3.0
12 | vmware-vapi-runtime == 2.52.0
13 | vmware-vapi-common-client == 2.52.0
--------------------------------------------------------------------------------
/sample_template/README.md:
--------------------------------------------------------------------------------
1 | Boilerplate code for new samples
2 | ================================
3 |
4 | * For complex samples require setup and cleanup please use sample_template_complex.py
5 | * For simple samples which just demo basic API usage please use sample_template_basic.py
6 |
--------------------------------------------------------------------------------
/sample_template/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/sample_template/__init__.py
--------------------------------------------------------------------------------
/sample_template/sample_template_basic.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'TODO: '
17 | __vcenter_version__ = 'TODO: '
18 |
19 | from com.vmware.vcenter_client import VM
20 | from vmware.vapi.vsphere.client import create_vsphere_client
21 |
22 | from samples.vsphere.common import sample_cli
23 | from samples.vsphere.common import sample_util
24 | from samples.vsphere.common.ssl_helper import get_unverified_session
25 |
26 |
27 | """
28 | TODO: Sample description and prerequisites.
29 | e.g. Demonstrates getting list of VMs present in vCenter
30 |
31 | Sample Prerequisites:
32 | - vCenter
33 | """
34 |
35 | # Create argument parser for standard inputs:
36 | # server, username, password, cleanup and skipverification
37 | parser = sample_cli.build_arg_parser()
38 |
39 | # Add your custom input arguments
40 | parser.add_argument('--vm_name',
41 | action='store',
42 | default='Sample_Default_VM_for_Simple_Testbed',
43 | help='Name of the testing vm')
44 |
45 | args = sample_util.process_cli_args(parser.parse_args())
46 |
47 | # Skip server cert verification if needed.
48 | # This is not recommended in production code.
49 | session = get_unverified_session() if args.skipverification else None
50 |
51 | # Connect to vSphere client
52 | client = create_vsphere_client(server=args.server,
53 | username=args.username,
54 | password=args.password,
55 | session=session)
56 |
57 | # List VMs
58 | filter_spec = VM.FilterSpec(names=set([args.vm_name]))
59 | vms = client.vcenter.VM.list(filter_spec)
60 | print(vms)
61 |
--------------------------------------------------------------------------------
/samples/README.md:
--------------------------------------------------------------------------------
1 | Directory | Description
2 | ----------------| -------------
3 | vSphere | Samples for vSphere APIs
4 | vmc | Samples for VMware Cloud on AWS Services (currently in preview)
5 |
--------------------------------------------------------------------------------
/samples/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vmc/README.md:
--------------------------------------------------------------------------------
1 | # Samples for VMware Cloud on AWS APIs
2 |
3 | The following table shows the sample sub-directories and their contents.
4 |
5 | Directory | Description
6 | ----------------| -------------
7 | orgs | Samples for operations on organizations
8 | sddc | Samples for operations on SDDCs
9 | draas | Samples for DRaaS APIs
10 | networks | Samples for networking APIs
11 | helpers | Helper methods used by VMware Cloud on AWS API samples
12 |
13 |
--------------------------------------------------------------------------------
/samples/vmc/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2017. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | # Required to distribute different parts of this
17 | # package as multiple distribution
18 | try:
19 | import pkg_resources
20 |
21 | pkg_resources.declare_namespace(__name__)
22 | except ImportError:
23 | from pkgutil import extend_path
24 |
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vmc/draas/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | # Required to distribute different parts of this
17 | # package as multiple distribution
18 | try:
19 | import pkg_resources
20 |
21 | pkg_resources.declare_namespace(__name__)
22 | except ImportError:
23 | from pkgutil import extend_path
24 |
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vmc/draas/get_srm_info.py:
--------------------------------------------------------------------------------
1 | import argparse
2 | import requests
3 |
4 | from vmware.vapi.vmc.client import create_vmc_client
5 |
6 | parser = argparse.ArgumentParser()
7 | parser.add_argument(
8 | '--refresh_token',
9 | required=True,
10 | help='VMware Cloud API refresh token')
11 |
12 | parser.add_argument(
13 | '--org_id',
14 | required=True,
15 | help='Organization identifier.')
16 |
17 | parser.add_argument(
18 | '--sddc_id',
19 | required=True,
20 | help='Sddc Identifier.')
21 |
22 | args = parser.parse_args()
23 | refresh_token = args.refresh_token
24 | org_id = args.org_id
25 | sddc_id = args.sddc_id
26 |
27 | client = create_vmc_client(refresh_token)
28 | site_recovery_activation_task = client.draas.SiteRecovery.get(org_id, sddc_id)
29 | print(site_recovery_activation_task)
30 |
--------------------------------------------------------------------------------
/samples/vmc/draas/helpers/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | # Required to distribute different parts of this
17 | # package as multiple distribution
18 | try:
19 | import pkg_resources
20 |
21 | pkg_resources.declare_namespace(__name__)
22 | except ImportError:
23 | from pkgutil import extend_path
24 |
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vmc/draas/helpers/draas_task_helper.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | from time import sleep
17 |
18 | from com.vmware.vmc.draas.model_client import Task
19 |
20 |
21 | def wait_for_task(task_client, org_id, task_id, interval_sec=60):
22 | """
23 | Helper method to wait for a task to finish
24 | :param task_client: task client to query the task object
25 | :param org_id: organization id
26 | :param task_id: task id
27 | :param interval_sec: task pulling interval_sec in sec
28 | :return: True if task finished successfully, False otherwise.
29 | """
30 | print('Wait for task {} to finish'.format(task_id))
31 | print('Checking task status every {} seconds'.format(interval_sec))
32 |
33 | while True:
34 | task = task_client.get(org_id, task_id)
35 |
36 | if task.status == Task.STATUS_FINISHED:
37 | print('\nTask {} finished successfully'.format(task_id))
38 | return True
39 | elif task.status == Task.STATUS_FAILED:
40 | print('\nTask {} failed'.format(task_id))
41 | return False
42 | elif task.status == Task.STATUS_CANCELED:
43 | print('\nTask {} cancelled'.format(task_id))
44 | return False
45 | else:
46 | print("Estimated time remaining: {} minutes".format(
47 | task.estimated_remaining_minutes))
48 | sleep(interval_sec)
49 |
--------------------------------------------------------------------------------
/samples/vmc/helpers/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2017. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | # Required to distribute different parts of this
17 | # package as multiple distribution
18 | try:
19 | import pkg_resources
20 |
21 | pkg_resources.declare_namespace(__name__)
22 | except ImportError:
23 | from pkgutil import extend_path
24 |
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vmc/helpers/sample_cli.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2019 VMware, Inc. All rights reserved.'
16 |
17 | import argparse
18 |
19 | """
20 | Builds a standard argument parser with required and optional argument groups
21 |
22 | Most of the VMC samples require these three standard required arguments.
23 | If any of these arguments are not required, then build your own parser
24 |
25 | --refresh_token
26 | --org_id
27 | --sddc_id
28 |
29 | """
30 | parser = argparse.ArgumentParser()
31 |
32 | required_args = parser.add_argument_group(
33 | 'required arguments')
34 | optional_args = parser.add_argument_group(
35 | 'optional arguments')
36 |
37 | required_args.add_argument(
38 | '--refresh-token',
39 | required=True,
40 | help='Refresh token obtained from CSP')
41 | required_args.add_argument(
42 | '--org-id',
43 | required=True,
44 | help='Orgization ID')
45 | required_args.add_argument(
46 | '--sddc-id',
47 | required=True,
48 | help='SDDC ID')
49 |
--------------------------------------------------------------------------------
/samples/vmc/helpers/vmc_task_helper.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2017, 2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | from time import sleep
17 |
18 | from com.vmware.vmc.model_client import Task
19 |
20 |
21 | def wait_for_task(task_client, org_id, task_id, interval_sec=60):
22 | """
23 | Helper method to wait for a task to finish
24 | :param task_client: task client to query the task object
25 | :param org_id: organization id
26 | :param task_id: task id
27 | :param interval_sec: task pulling interval_sec in sec
28 | :return: True if task finished successfully, False otherwise.
29 | """
30 | print('Wait for task {} to finish'.format(task_id))
31 | print('Checking task status every {} seconds'.format(interval_sec))
32 |
33 | while True:
34 | task = task_client.get(org_id, task_id)
35 |
36 | if task.status == Task.STATUS_FINISHED:
37 | print('\nTask {} finished successfully'.format(task_id))
38 | return True
39 | elif task.status == Task.STATUS_FAILED:
40 | print('\nTask {} failed'.format(task_id))
41 | return False
42 | elif task.status == Task.STATUS_CANCELED:
43 | print('\nTask {} cancelled'.format(task_id))
44 | return False
45 | else:
46 | print("Estimated time remaining: {} minutes".format(
47 | task.estimated_remaining_minutes))
48 | sleep(interval_sec)
49 |
50 |
51 | def list_all_tasks(task_client, org_id):
52 | """
53 | List all tasks in a given org
54 | :param task_client: task client to query the task object
55 | :param org_id: organization id
56 | """
57 | tasks = task_client.list(org_id)
58 | for task in tasks:
59 | print('ID: {}, Status: {}, Progress: {}, Started: {}, User: {}'.format(
60 | task.id, task.status, task.progress_percent, task.start_time,
61 | task.user_name))
62 |
--------------------------------------------------------------------------------
/samples/vmc/networks_nsxt/hello_world.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 |
18 | import pprint
19 | from samples.vmc.helpers.sample_cli import parser
20 | from com.vmware.nsx_policy_client_for_vmc import (
21 | create_nsx_policy_client_for_vmc)
22 |
23 |
24 | class AuthExample(object):
25 | """
26 | Demonstrates how to authenticate to VMC using the NSX-T SDK
27 | and perform a simple read operation.
28 |
29 | Sample Prerequisites:
30 | - An organization associated with the calling user.
31 | - A SDDC in the organization
32 | """
33 |
34 | def __init__(self):
35 | args = parser.parse_args()
36 |
37 | self.org_id = args.org_id
38 | self.sddc_id = args.sddc_id
39 | self.vmc_client = create_nsx_policy_client_for_vmc(
40 | args.refresh_token, args.org_id, args.sddc_id)
41 |
42 | def get_domains(self):
43 | print('\n# Get Domains: List network domains:')
44 | domains = self.vmc_client.infra.Domains.list()
45 | pprint.pprint(domains)
46 |
47 |
48 | def main():
49 | auth_example = AuthExample()
50 | auth_example.get_domains()
51 |
52 |
53 | if __name__ == '__main__':
54 | main()
55 |
--------------------------------------------------------------------------------
/samples/vmc/networks_nsxt/security_group_list.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc'
17 | __vcenter_version__ = 'VMware Cloud on AWS'
18 |
19 | import requests
20 |
21 | from samples.vmc.helpers.sample_cli import parser, optional_args
22 | from com.vmware.nsx_policy.infra_client import Domains
23 | from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
24 | from vmware.vapi.bindings.struct import PrettyPrinter
25 | from vmware.vapi.lib import connect
26 | from vmware.vapi.security.user_password import \
27 | create_user_password_security_context
28 | from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
29 |
30 |
31 | """
32 | List all Network Security Groups
33 |
34 | Sample Prerequisites:
35 | - SDDC deployed in VMware Cloud on AWS
36 | """
37 | optional_args.add_argument('--gateway_type',
38 | default='mgw',
39 | help='Gateway type. Either mgw or cgw')
40 |
41 | args = parser.parse_args()
42 |
43 | gateway_type = args.gateway_type.lower()
44 |
45 | nsx_client = create_nsx_policy_client_for_vmc(
46 | refresh_token=args.refresh_token,
47 | org_id=args.org_id,
48 | sddc_id=args.sddc_id)
49 |
50 | print('Listing all security groups for "{}"\n'.format(gateway_type))
51 |
52 | security_groups = nsx_client.infra.domains.Groups.list(gateway_type).results
53 |
54 | for group in security_groups:
55 | print('* Group "{}":'.format(group.id))
56 | print('{}\n'.format(group))
57 |
--------------------------------------------------------------------------------
/samples/vmc/networks_nsxv/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | # Required to distribute different parts of this
17 | # package as multiple distribution
18 | try:
19 | import pkg_resources
20 |
21 | pkg_resources.declare_namespace(__name__)
22 | except ImportError:
23 | from pkgutil import extend_path
24 |
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vmc/orgs/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for VMC organization APIs:
2 |
3 | Running the samples
4 |
5 | $ python organization_operations.py -r
6 |
7 | * Testbed Requirement:
8 | - At least one org associated with the calling user.
9 |
10 |
--------------------------------------------------------------------------------
/samples/vmc/orgs/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2017. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | # Required to distribute different parts of this
17 | # package as multiple distribution
18 | try:
19 | import pkg_resources
20 |
21 | pkg_resources.declare_namespace(__name__)
22 | except ImportError:
23 | from pkgutil import extend_path
24 |
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vmc/sddc/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for VMC SDDC APIs:
2 |
3 | Sample | Description | Prerequisites
4 | :--- | :--- | :---
5 | add_remove_hosts.py | Demonstrates add and remove ESX hosts | A SDDC in the organization
6 | connect_to_vsphere_with_default_sddc_password.py | Demonstrates how to connect to a vSphere in a SDDC using the initial cloud admin credentials. | A firewall rule to access the vSphere
7 | deploy_ovf_template.py | Demonstrates the workflow to deploy an OVF library item to a resource pool in VMware Cloud on AWS. | An existing library item with an OVF template and an existing resource pool with resources for deploying the VM.
8 | ovf_import_export_cloud.py | Demonstrates the workflow to import an OVF package into the content library, as well as download of an OVF template from the content library. | An existing vCenter DS with available storage.
9 | sddc_crud.py | Demonstrates create and delete a SDDC | An organization associated with the calling user.
--------------------------------------------------------------------------------
/samples/vmc/sddc/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2017. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | # Required to distribute different parts of this
17 | # package as multiple distribution
18 | try:
19 | import pkg_resources
20 |
21 | pkg_resources.declare_namespace(__name__)
22 | except ImportError:
23 | from pkgutil import extend_path
24 |
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vmc/tasks/cancel_task.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | import argparse
17 | from com.vmware.vmc.model_client import Task
18 | from vmware.vapi.vmc.client import create_vmc_client
19 |
20 | """
21 | Demonstrates how to cancel a running task
22 |
23 | Sample Prerequisites:
24 | - VMware Cloud on AWS console API access
25 | - A running task
26 | """
27 |
28 | parser = argparse.ArgumentParser(
29 | formatter_class=argparse.ArgumentDefaultsHelpFormatter)
30 |
31 | required_args = parser.add_argument_group(
32 | 'required arguments')
33 |
34 | required_args.add_argument(
35 | '--refresh-token',
36 | required=True,
37 | help='Refresh token obtained from CSP')
38 |
39 | required_args.add_argument(
40 | '--org-id',
41 | required=True,
42 | help='Organization identifier.')
43 |
44 | required_args.add_argument(
45 | '--task-id',
46 | required=True,
47 | help='Task ID to be cancelled')
48 |
49 | args = parser.parse_args()
50 |
51 | vmc_client = create_vmc_client(args.refresh_token)
52 |
53 | vmc_client.orgs.Tasks.update(org=args.org_id, task=args.task_id, action='cancel')
54 |
55 | print('Task "{}" is cancelled'.format(args.task_id))
56 |
--------------------------------------------------------------------------------
/samples/vmc/tasks/list_tasks.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | import argparse
17 | from com.vmware.vmc.model_client import Task
18 | from vmware.vapi.vmc.client import create_vmc_client
19 |
20 | """
21 | Demonstrates how to list tasks with given status
22 |
23 | Sample Prerequisites:
24 | - VMware Cloud on AWS console API access
25 | """
26 |
27 | accepted = [Task.STATUS_STARTED, Task.STATUS_CANCELING, Task.STATUS_FINISHED,
28 | Task.STATUS_FAILED, Task.STATUS_CANCELED]
29 |
30 | parser = argparse.ArgumentParser(
31 | formatter_class=argparse.ArgumentDefaultsHelpFormatter)
32 |
33 | required_args = parser.add_argument_group(
34 | 'required arguments')
35 |
36 | required_args.add_argument(
37 | '--refresh-token',
38 | required=True,
39 | help='Refresh token obtained from CSP')
40 | required_args.add_argument(
41 | '--org-id',
42 | required=True,
43 | help='Organization identifier.')
44 |
45 | required_args.add_argument(
46 | '--task-status',
47 | help='Task status to filter. Possible values are: {} \
48 | Show all tasks if no value is passed'.format(accepted))
49 |
50 | args = parser.parse_args()
51 |
52 | vmc_client = create_vmc_client(args.refresh_token)
53 |
54 | tasks = []
55 |
56 | if args.task_status:
57 | status = args.task_status.upper()
58 |
59 | if status not in accepted:
60 | raise ValueError('Status "{}" is invalid, accept values are {}'.
61 | format(args.task_status, accepted))
62 |
63 | tasks = vmc_client.orgs.Tasks.list(
64 | org=args.org_id, filter="(status eq '{}')".format(status))
65 |
66 | print('# List all "{}" tasks:\n'.format(status))
67 | else:
68 | tasks = vmc_client.orgs.Tasks.list(org=args.org_id)
69 | print('# List all tasks:\n')
70 |
71 | for task in tasks:
72 | print('{}\n'.format(task))
73 |
--------------------------------------------------------------------------------
/samples/vmc/tasks/list_tasks_stg.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | import argparse
17 | from com.vmware.vmc.model_client import Task
18 | from vmware.vapi.vmc.client import create_vmc_client
19 |
20 | """
21 | Demonstrates how to list tasks with given status
22 |
23 | Sample Prerequisites:
24 | - VMware Cloud on AWS console API access
25 | """
26 |
27 | accepted = [Task.STATUS_STARTED, Task.STATUS_CANCELING, Task.STATUS_FINISHED,
28 | Task.STATUS_FAILED, Task.STATUS_CANCELED]
29 |
30 | parser = argparse.ArgumentParser(
31 | formatter_class=argparse.ArgumentDefaultsHelpFormatter)
32 |
33 | required_args = parser.add_argument_group(
34 | 'required arguments')
35 | optional_args = parser.add_argument_group(
36 | 'optional arguments')
37 |
38 | required_args.add_argument(
39 | '--refresh-token',
40 | required=True,
41 | help='Refresh token obtained from CSP')
42 |
43 | required_args.add_argument(
44 | '--org-id',
45 | required=True,
46 | help='Organization identifier.')
47 |
48 | optional_args.add_argument(
49 | '--task-status',
50 | help='Task status to filter. Possible values are: {} \
51 | Show all tasks if no value is passed'.format(accepted))
52 |
53 | args = parser.parse_args()
54 |
55 | vmc_client = create_vmc_client(args.refresh_token)
56 |
57 | tasks = []
58 |
59 | if args.task_status:
60 | status = args.task_status.upper()
61 |
62 | if status not in accepted:
63 | raise ValueError('Status "{}" is invalid, accept values are {}'.
64 | format(args.task_status, accepted))
65 |
66 | tasks = vmc_client.orgs.Tasks.list(
67 | org=args.org_id, filter="(status eq '{}')".format(status))
68 |
69 | print('# List all "{}" tasks:\n'.format(status))
70 | else:
71 | tasks = vmc_client.orgs.Tasks.list(org=args.org_id)
72 | print('# List all tasks:\n')
73 |
74 | for task in tasks:
75 | print('{}\n'.format(task))
76 |
--------------------------------------------------------------------------------
/samples/vsan/snapservice/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) 2024 Broadcom. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'Broadcom, Inc.'
15 | __copyright__ = 'Copyright (c) 2024 Broadcom. All Rights Reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsan/snapservice/protection_group/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) 2024 Broadcom. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'Broadcom, Inc.'
15 | __copyright__ = 'Copyright (c) 2024 Broadcom. All Rights Reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsan/snapservice/snapshot/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) 2024 Broadcom. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'Broadcom, Inc.'
15 | __copyright__ = 'Copyright (c) 2024 Broadcom. All Rights Reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/README.md:
--------------------------------------------------------------------------------
1 | # Client Samples
2 |
3 | The following table shows the sample sub-directories and their contents.
4 |
5 | Directory | Description
6 | ----------------| -------------
7 | common | Samples common helper classes and abstractions; This package contains one sample 'connect_with_cert.py', to demonstrate how to connect with valid Cert Verification
8 | appliances | Samples for Appliance APIs
9 | oauth | Samples for oAuth APIs (IDP Federated vCenter Server)
10 | compute_policy | Samples for Compute Policy APIs
11 | contentlibrary | Samples for Content Library APIs
12 | tagging | Samples for Tagging APIs
13 | vcenter | Samples for managing vSphere infrastructure and virtual machines
14 | sso | Samples for Platform Service Controller(PSC), SSO and Lookup Service APIs
15 |
--------------------------------------------------------------------------------
/samples/vsphere/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/appliances/list_service.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | * *******************************************************
4 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
5 | * SPDX-License-Identifier: MIT
6 | * *******************************************************
7 | *
8 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13 | """
14 |
15 | __author__ = 'VMware, Inc.'
16 | __vcenter_version__ = '6.7+'
17 |
18 | from vmware.vapi.vsphere.client import create_vsphere_client
19 |
20 | from samples.vsphere.common import (sample_cli, sample_util)
21 | from samples.vsphere.common.ssl_helper import get_unverified_session
22 |
23 |
24 | """
25 | Description: Demonstrates services api workflow
26 | 1.List all services
27 |
28 | """
29 |
30 | parser = sample_cli.build_arg_parser()
31 | args = sample_util.process_cli_args(parser.parse_args())
32 | session = get_unverified_session() if args.skipverification else None
33 | client = create_vsphere_client(server=args.server,
34 | username=args.username,
35 | password=args.password,
36 | session=session)
37 |
38 | service_list = client.appliance.Services.list()
39 |
40 | print("Example: List Appliance Services:")
41 | print("-------------------\n")
42 | for key, values in service_list.items():
43 | print("Service Name : {} ".format(key))
44 | print("value : {}".format(values.description))
45 | print("State: {} \n".format(values.state))
46 |
--------------------------------------------------------------------------------
/samples/vsphere/appliances/patching/README.md:
--------------------------------------------------------------------------------
1 | This Directory contains samples for Patching API - applmgmt APIs
2 | For more information, please review the official release notes.
3 |
4 | Applmgmt having the followings APIs:
5 | * Pending: Performs patching for pending updates
6 | * Update: Status of update operation
7 |
8 | Overview of the directory code samples:
9 |
10 | * update_sample.py - running a simple workflow to update the vc/component . It's having below APIs.
11 | GET https://{server}/rest/appliance/update/pending
12 | GET https://{server}/rest/appliance/update/pending/{{update_id}}/components
13 | GET https://{server}/rest/appliance/update/pending/{{update_id}}?component={component}
14 | POST https://{server}/rest/appliance/update/pending/{{update_id}}?action=precheck
15 | POST https://{server}/rest/appliance/update/pending/{{update_id}}?action=validate
16 | POST https://{server}/rest/appliance/update/pending/{{update_id}}?action=stage
17 | POST https://{server}/rest/appliance/update/pending/{{update_id}}?action=install
18 |
19 |
20 | To view the available command-line options:
21 |
22 | $ python update_sample.py --help
23 |
24 | Running the samples:
25 |
26 | $ python update_sample.py --server --username --password --url --component --skipverification
27 |
28 |
29 | Testbed Requirement:
30 |
31 | * vCenter Server appliance version 8.0 or above are supported for component update.
32 | * vCenter Server appliance version 6.7 or above are supported for full patch.
--------------------------------------------------------------------------------
/samples/vsphere/appliances/patching/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2022. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2022 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/appliances/timezone.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter_version__ = '6.7+'
16 |
17 | from vmware.vapi.vsphere.client import create_vsphere_client
18 |
19 | from samples.vsphere.common import (sample_cli, sample_util)
20 | from samples.vsphere.common.ssl_helper import get_unverified_session
21 |
22 |
23 | """
24 | Demonstrates setting and getting TimeZone.Accepted values are
25 |
26 | valid Timezone values for appliance
27 |
28 | """
29 |
30 | parser = sample_cli.build_arg_parser()
31 |
32 | parser.add_argument(
33 | '--time_sync',
34 | required=True,
35 | action='store',
36 | choices=['DISABLED', 'HOST'],
37 | help='DISABLED,time synchronization is disabled and HOST,Host time synchronization ')
38 |
39 | args = sample_util.process_cli_args(parser.parse_args())
40 | time_sync = args.time_sync
41 |
42 | # Connect to vAPI services
43 | session = get_unverified_session() if args.skipverification else None
44 | client = create_vsphere_client(server=args.server,
45 | username=args.username,
46 | password=args.password,
47 | session=session)
48 | timesync_mode = client.appliance.Timesync.TimeSyncMode(time_sync)
49 | print("Setting the appliance time syncronization as : " + time_sync)
50 | client.appliance.Timesync.set(timesync_mode)
51 | print("Timesync as : " + client.appliance.Timesync.get())
52 |
--------------------------------------------------------------------------------
/samples/vsphere/backuprestore/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for Backup Restore APIs:
2 |
3 | * List all backup jobs
4 | * CRUD operations on backup schedule
5 |
6 | Running the samples
7 |
8 | $ python /.py --server --username --password
9 |
10 | The additional sample parameters are as follows (all parameters can be displayed for any sample using option --help)
11 |
12 | * backup_schedule.py --location --location_user location_password
13 |
14 | * Testbed Requirement:
15 | - 1 vCenter Server
16 | - Backup server reachable through any of the supported protocols FTP/FTPS/SCP/HTTP/HTTPS
17 |
--------------------------------------------------------------------------------
/samples/vsphere/backuprestore/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2017. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
16 |
17 | # Required to distribute different parts of this
18 | # package as multiple distribution
19 | try:
20 | import pkg_resources
21 |
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 |
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/backuprestore/backup_job_list.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | * *******************************************************
4 | * Copyright (c) VMware, Inc. 2017. All Rights Reserved.
5 | * SPDX-License-Identifier: MIT
6 | * *******************************************************
7 | *
8 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13 | """
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
17 | __vcenter_version__ = '6.7+'
18 |
19 | from samples.vsphere.common import sample_cli
20 | from samples.vsphere.common import sample_util
21 | from samples.vsphere.common import vapiconnect
22 | from com.vmware.appliance.recovery.backup.job_client import Details
23 |
24 |
25 | class BackupJobList(object):
26 | """
27 | Demonstrates backup job list operation
28 |
29 | Retrieves backup job details from vCenter and prints the data
30 |
31 | Prerequisites:
32 | - vCenter
33 | - Backup operation is performed on the vCenter either manually or
34 | by scheduled backups
35 | """
36 |
37 | def __init__(self):
38 | self.stub_config = None
39 |
40 | def setup(self):
41 | parser = sample_cli.build_arg_parser()
42 | args = sample_util.process_cli_args(parser.parse_args())
43 |
44 | # Connect to vAPI services
45 | self.stub_config = vapiconnect.connect(
46 | host=args.server,
47 | user=args.username,
48 | pwd=args.password,
49 | skip_verification=args.skipverification)
50 |
51 | def run(self):
52 | details_client = Details(self.stub_config)
53 | job_list = details_client.list()
54 |
55 | for info in job_list.values():
56 | print(
57 | 'Start time: {}, Duration: {}, Type: {}, Status: {}, Location: {}'
58 | .format(
59 | info.start_time.strftime("%b %d %Y %H:%M"), info.duration,
60 | info.type, info.status, info.location))
61 |
62 |
63 | def main():
64 | backup_job_list = BackupJobList()
65 | backup_job_list.setup()
66 | backup_job_list.run()
67 |
68 |
69 | if __name__ == '__main__':
70 | main()
71 |
--------------------------------------------------------------------------------
/samples/vsphere/common/__init__.py:
--------------------------------------------------------------------------------
1 | # Required to distribute different parts of this
2 | # package as multiple distribution
3 | try:
4 | import pkg_resources
5 |
6 | pkg_resources.declare_namespace(__name__)
7 | except ImportError:
8 | from pkgutil import extend_path
9 |
10 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
11 |
--------------------------------------------------------------------------------
/samples/vsphere/common/id_generator.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2013. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2013 VMware, Inc. All rights reserved.'
16 |
17 |
18 | import uuid
19 | import string
20 | import random
21 |
22 |
23 | def generate_random_uuid():
24 | return str(uuid.uuid4())
25 |
26 |
27 | def rand(value):
28 | return value + generate_random_string(5)
29 |
30 |
31 | def generate_random_string(length):
32 | return ''.join(random.choice(string.ascii_uppercase) for _i in range(length))
33 |
34 |
35 | def main():
36 | print(generate_random_uuid())
37 | print(generate_random_string(5))
38 | print(rand('Simple VM-'))
39 |
40 |
41 | # Start program
42 | if __name__ == "__main__":
43 | main()
44 |
--------------------------------------------------------------------------------
/samples/vsphere/common/sample_cli.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 | import argparse
18 |
19 |
20 | def build_arg_parser():
21 | """
22 | Builds a standard argument parser with arguments for talking to vCenter
23 |
24 | -s server
25 | -u username
26 | -p password
27 | -c cleanup
28 | -v skipverification
29 |
30 | """
31 | parser = argparse.ArgumentParser(
32 | description='Standard Arguments for talking to vCenter')
33 |
34 | required_args = parser.add_argument_group(
35 | 'required arguments')
36 | required_args.add_argument('-s', '--server',
37 | action='store',
38 | required=True,
39 | help='vSphere service IP to connect to')
40 |
41 | required_args.add_argument('-u', '--username',
42 | action='store',
43 | required=True,
44 | help='Username to use when connecting to vc')
45 |
46 | required_args.add_argument('-p', '--password',
47 | action='store',
48 | required=True,
49 | help='Password to use when connecting to vc')
50 |
51 | parser.add_argument('-c', '--cleardata',
52 | action='store_true',
53 | help='Clean up after sample run. ')
54 |
55 | parser.add_argument('-v', '--skipverification',
56 | action='store_true',
57 | help='Verify server certificate when connecting to vc.')
58 |
59 | return parser
60 |
--------------------------------------------------------------------------------
/samples/vsphere/common/service_manager_factory.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2013, 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2013, 2016 VMware, Inc. All rights reserved.'
16 |
17 | from samples.vsphere.common.service_manager import ServiceManager
18 |
19 |
20 | class ServiceManagerFactory(object):
21 | """
22 | Factory class for getting service manager for a management node.
23 | """
24 | service_manager = None
25 |
26 | @classmethod
27 | def get_service_manager(cls, server, username, password, skip_verification):
28 | cls.service_manager = ServiceManager(server,
29 | username,
30 | password,
31 | skip_verification)
32 | cls.service_manager.connect()
33 | return cls.service_manager
34 |
35 | @classmethod
36 | def disconnect(cls):
37 | if cls.service_manager:
38 | cls.service_manager.disconnect()
39 |
40 |
41 | import atexit
42 | atexit.register(ServiceManagerFactory.disconnect)
43 |
--------------------------------------------------------------------------------
/samples/vsphere/common/ssl_helper.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2013, 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | import ssl
17 | import requests
18 |
19 |
20 | def get_unverified_context():
21 | """
22 | Get an unverified ssl context. Used to disable the server certificate
23 | verification.
24 | @return: unverified ssl context.
25 | """
26 | context = None
27 | if hasattr(ssl, '_create_unverified_context'):
28 | context = ssl._create_unverified_context()
29 | return context
30 |
31 |
32 | def get_unverified_session():
33 | """
34 | Get a requests session with cert verification disabled.
35 | Also disable the insecure warnings message.
36 | Note this is not recommended in production code.
37 | @return: a requests session with verification disabled.
38 | """
39 | session = requests.session()
40 | session.verify = False
41 | requests.packages.urllib3.disable_warnings()
42 | return session
43 |
--------------------------------------------------------------------------------
/samples/vsphere/common/vim/__init__.py:
--------------------------------------------------------------------------------
1 | # Required to distribute different parts of this
2 | # package as multiple distribution
3 | try:
4 | import pkg_resources
5 |
6 | pkg_resources.declare_namespace(__name__)
7 | except ImportError:
8 | from pkgutil import extend_path
9 |
10 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
11 |
--------------------------------------------------------------------------------
/samples/vsphere/common/vim/helpers/__init__.py:
--------------------------------------------------------------------------------
1 | # Required to distribute different parts of this
2 | # package as multiple distribution
3 | try:
4 | import pkg_resources
5 |
6 | pkg_resources.declare_namespace(__name__)
7 | except ImportError:
8 | from pkgutil import extend_path
9 |
10 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
11 |
--------------------------------------------------------------------------------
/samples/vsphere/common/vim/inventory.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2016-2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter__ = 'since 6.0'
16 |
17 | from pyVmomi import vim
18 |
19 | from samples.vsphere.vcenter.helper.datastore_helper import get_datastore
20 |
21 |
22 | def get_datastore_mo(client, soap_stub,
23 | datacenter_name, datastore_name):
24 | """
25 | Return datastore managed object with specific datacenter and datastore name
26 | """
27 | datastore = get_datastore(client, datacenter_name, datastore_name)
28 | if not datastore:
29 | return None
30 | datastore_mo = vim.Datastore(datastore, soap_stub)
31 | return datastore_mo
32 |
33 |
34 | # TODO Not the most efficient implementation. This can be done as a single
35 | # property collector query but it's a little more complicated
36 | def get_datacenter_for_datastore(datastore_mo):
37 | datacenter_mo = datastore_mo.parent
38 | while datacenter_mo is not None:
39 | if isinstance(datacenter_mo, vim.Datacenter):
40 | return datacenter_mo
41 | datacenter_mo = datacenter_mo.parent
42 | return None
43 |
--------------------------------------------------------------------------------
/samples/vsphere/common/vim/vmdk.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2016-2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | import pyVim.task
17 | from pyVmomi import vim
18 | from samples.vsphere.common.vim.inventory import get_datastore_mo
19 |
20 | from samples.vsphere.common.vim import datastore_file
21 |
22 |
23 | def create_vmdk(service_instance, datacenter_mo, datastore_path):
24 | """Create vmdk in specific datacenter"""
25 | vdm = service_instance.content.virtualDiskManager
26 | task = vdm.CreateVirtualDisk(
27 | datastore_path, datacenter_mo,
28 | vim.VirtualDiskManager.SeSparseVirtualDiskSpec(
29 | diskType='seSparse', adapterType='lsiLogic',
30 | capacityKb=1024 * 1024 * 4))
31 | pyVim.task.WaitForTask(task)
32 | print("Created VMDK '{}' in Datacenter '{}'".
33 | format(datastore_path, datacenter_mo.name))
34 | return task.info.result
35 |
36 |
37 | def delete_vmdk(service_instance, datacenter_mo, datastore_path):
38 | """Delete vmdk from specific datastore"""
39 | vdm = service_instance.content.virtualDiskManager
40 | task = vdm.DeleteVirtualDisk(datastore_path, datacenter_mo)
41 | pyVim.task.WaitForTask(task)
42 |
43 |
44 | def detect_vmdk(client, soap_stub, datacenter_name, datastore_name,
45 | datastore_path):
46 | """Find vmdk in specific datastore"""
47 | datastore_mo = get_datastore_mo(client,
48 | soap_stub,
49 | datacenter_name,
50 | datastore_name)
51 | if not datastore_mo:
52 | return False
53 |
54 | dsfile = datastore_file.File(datastore_mo)
55 | if dsfile.exists(datastore_path):
56 | return True
57 | else:
58 | return False
59 |
--------------------------------------------------------------------------------
/samples/vsphere/compute_policy/README.md:
--------------------------------------------------------------------------------
1 | # Compute Policy API samples
2 |
3 | This directory contains samples for the Compute Policy APIs.
4 |
5 | ## Compute Policy workflow
6 | `compute_policy_workflow.py` uses the compute policy APIs to create a policy of VM-Host affinity capability and checks the compliance status of the policy for a particular virtual machine after the virtual machine is powered on.
7 |
8 | ## Testbed requirements
9 | - 1 vCenter server.
10 | - 1 cluster on the vCenter server with DRS enabled.
11 | - At least 2 hosts and 1 virtual machine in the cluster.
12 | - A tag that can be associated with virtual machines and a tag that can be associated with hosts. Please refer to the [tagging samples](https://gitlab.eng.vmware.com/vapi-sdk/vsphere-automation-sdk-python/tree/cloud/samples/vsphere/tagging) for more information on creating categories, tags and tag associations.
13 |
14 | ## Running the sample
15 | ```
16 | python3 samples/vsphere/compute_policy/compute_policy_workflow.py \
17 | -s \
18 | -u \
19 | -p \
20 | -v -c \
21 | -n \
22 | -vn \
23 | -vt \
24 | -hn \
25 | -ht \
26 | ```
27 |
28 | ##### Sample output
29 | ```
30 | vcenter server = 10.192.174.79
31 | vc username = Administrator@vsphere.local
32 | Found VM 'vm_1' (vm-31)
33 | Creating a VM-Host affinity policy
34 | Policy created with id: 46e6c0a6-135c-4bfe-82ee-b1938128b5b9
35 | Powering on vm_1
36 | The compliance status of policy 46e6c0a6-135c-4bfe-82ee-b1938128b5b9 for VM vm-31 is COMPLIANT
37 | Deleting the policy 46e6c0a6-135c-4bfe-82ee-b1938128b5b9
38 | Powering off vm_1
39 | ```
40 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/contentupdate/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/crud/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/isomount/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/lib/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 | # Required to distribute different parts of this
18 | # package as multiple distribution
19 | try:
20 | import pkg_resources
21 |
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 |
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/ovfdeploy/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/ovfimport/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/publishsubscribe/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/resources/isoImages/test-2.iso:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/samples/vsphere/contentlibrary/resources/isoImages/test-2.iso
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/resources/isoImages/test.iso:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/samples/vsphere/contentlibrary/resources/isoImages/test.iso
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/resources/plainVmTemplate/plain-vm.vmdk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/samples/vsphere/contentlibrary/resources/plainVmTemplate/plain-vm.vmdk
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/resources/signedOvaWithCertWarning/nostalgia-signed.ova:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/samples/vsphere/contentlibrary/resources/signedOvaWithCertWarning/nostalgia-signed.ova
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/resources/simpleVmTemplate/descriptor.ovf:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | A Virtual system
5 | vmBV8ly
6 |
7 | A human-readable annotation
8 |
9 |
10 |
11 | Virtual hardware requirements
12 |
13 | Virtual Hardware Family
14 | System
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/resources/simpleVmTemplate/disk-0.vmdk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vmware/vsphere-automation-sdk-python/d57e82cb7cd7b3a24bd2af3aedad277865def867/samples/vsphere/contentlibrary/resources/simpleVmTemplate/disk-0.vmdk
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/vmcapture/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/vmtemplate/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2017. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/contentlibrary/vmtx_sync/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/deferhistoryimport/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for the Defer History Data Import APIs. Defer History Data Import is a new
2 | feature for the upgrade that allows historical data and performance metrics data to be imported in the background
3 | after the upgrade is done, thus allowing shorter downtime for the whole upgrade process. The feature is only applicable
4 | for upgrades or migrations from 6.0 and 6.5 with external database. For more information, please review the official
5 | release notes.
6 |
7 | The operations on the API are as follow:
8 |
9 | * status of defer history data import
10 | * pause defer history data import
11 | * resume defer history data import
12 | * cancel defer history data import
13 |
14 | Overview of the directory code samples:
15 |
16 | * vc_import_history_sample.py - running a simple workflow to pause and resume
17 | Defer History Data Import that is still not completed.
18 | * vc_import_history_cli.py - allowing to trigger different parts of the API,
19 | showing example code structure.
20 | * vc_import_history_common.py - common functionality between the main files.
21 |
22 | To view the available command-line options:
23 |
24 | $ python vc_import_history_sample.py --help
25 |
26 | $ python vc_import_history_cli.py --help
27 |
28 | Running the samples:
29 |
30 | $ python vc_import_history_sample.py --server --username --password
31 |
32 | Running the cli:
33 |
34 | $ python vc_import_history_cli.py --server --username --password --operation
35 |
36 | The operation choice is as follows (information is also available using --help)
37 |
38 | * status
39 | * pause
40 | * resume
41 | * cancel
42 |
43 | Testbed Requirement:
44 |
45 | * 1 vCenter Server appliance version 6.7 or above successfully upgraded using the option for transferring historical data after upgrade.
46 |
--------------------------------------------------------------------------------
/samples/vsphere/deferhistoryimport/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2017. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/hardwaretpm/README.md:
--------------------------------------------------------------------------------
1 | This directory contains sample for getting TPM information using Trust Authority APIs added in __vcenter_version__ = '8.0+'
2 | * Get ESX TPM information - tpm_info.py
3 |
4 | Running the samples
5 | $ python /.py --server --username --password
6 |
7 | * Testbed Requirement:
8 | - 1 vCenter Server
9 | - 1 ESX host with TPM enabled
10 |
11 | * Sample output
12 | python samples/vsphere/hardwaretpm/tpm_info.py -s -u -p --skipverification
13 | vcenter server =
14 | vc username =
15 | ----------------------------
16 | TPM Information
17 | ----------------------------
18 | 'major_version: 2'
19 | 'minor_version: 0'
20 | 'active: True'
21 | 'manufacturer: NTC'
22 | 'model: rls'
23 | 'firmware_version: 1.3.1.0'
24 | ----------------------------
25 | ----------------------------
26 | TPM Endorsement key
27 | ----------------------------
28 | ('-----BEGIN PUBLIC KEY-----\n'
29 | 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1I65uMJU5MugQzl3K6yg\n'
30 | 'Zjzed6aP7MX1Cl670NsvMSXs4FRdNZ1wkJHFUHrSG6ihBmHoziqWKhMjv3g9qrmJ\n'
31 | 'tGR6uGsDi2nFsjn0/AK5epDQsQC6FffE6OotqAMtx+MocuU6XOacZ0lyjUcVGZRX\n'
32 | 'RLK1TmRL3ugupFDe0XLcQZPNzv4cYNLub3prYEgEcpac89xVEn/TCyRK/nMGTHxs\n'
33 | 'Z1oMI+FjpKMh5Vj/6c2gwhoX7tYQFXZOLy6S9prok5fWgHssZAjQNLjp1rihVpp3\n'
34 | '6BIkCBRw+LSEdz47naOsZN7NEYO78It3JGlPt2fpYVJ6+/8ObUa5Sv8svzFOb0Qq\n'
35 | 'rQIDAQAB\n'
36 | '-----END PUBLIC KEY-----\n')
37 | ----------------------------
38 |
--------------------------------------------------------------------------------
/samples/vsphere/logforwarding/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for log forwarding APIs:
2 |
3 | * Create log forwarding configurations
4 | * View log forwarding configurations
5 | * Update log forwarding configurations
6 | * Test log forwarding configurations
7 |
8 | To view the available command-line options:
9 |
10 | $ python logforwarding/logforwarding.py --help
11 |
12 | Running the samples:
13 |
14 | $ python logforwarding/logforwarding.py --server --username --password --loghost --port --protocol
15 |
16 | * Testbed Requirement:
17 | - 1 vCenter Server
18 | - Log host listening to syslog packets over any of the supported protocols UDP/TCP/TLS
19 |
--------------------------------------------------------------------------------
/samples/vsphere/oauth/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | # Required to distribute different parts of this
17 | # package as multiple distribution
18 | try:
19 | import pkg_resources
20 |
21 | pkg_resources.declare_namespace(__name__)
22 | except ImportError:
23 | from pkgutil import extend_path
24 |
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/oauth/grant_types/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2020. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 |
16 | # Required to distribute different parts of this
17 | # package as multiple distribution
18 | try:
19 | import pkg_resources
20 |
21 | pkg_resources.declare_namespace(__name__)
22 | except ImportError:
23 | from pkgutil import extend_path
24 |
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/oauth/grant_types/list_vms_client_credentials.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 | from vmware.vapi.vsphere.client import create_vsphere_client
16 |
17 | from samples.vsphere.common import sample_cli
18 | from samples.vsphere.common import sample_util
19 | from samples.vsphere.common.ssl_helper import get_unverified_session
20 | from samples.vsphere.oauth.grant_types.oauth_utility \
21 | import login_using_client_credentials
22 | import argparse
23 |
24 | __author__ = 'VMware, Inc.'
25 | __copyright__ = 'Copyright 2020 VMware, Inc. All rights reserved.'
26 | __vcenter_version__ = '7.0+'
27 |
28 | """
29 | To run this sample,
30 | $ python list_vms_client_credentials.py --server \
31 | -- client_id --client_secret --skipverification
32 | """
33 |
34 | parser = argparse.ArgumentParser()
35 | parser.add_argument("--server",
36 | help="VC IP or hostname")
37 | parser.add_argument("--client_id",
38 | help="Client/Application ID of the server to server app")
39 | parser.add_argument("--client_secret",
40 | help="Client/Application secret \
41 | of the server to server app")
42 | parser.add_argument('--skipverification',
43 | action='store_true',
44 | help='Verify server certificate when connecting to vc.')
45 |
46 | args = parser.parse_args()
47 |
48 | session = get_unverified_session() if args.skipverification else None
49 | saml_assertion = login_using_client_credentials(
50 | args.server,
51 | session,
52 | args.client_id,
53 | args.client_secret)
54 |
55 | client = create_vsphere_client(
56 | server=args.server,
57 | bearer_token=saml_assertion,
58 | session=session)
59 | vms = client.vcenter.VM.list()
60 | print(vms)
61 |
--------------------------------------------------------------------------------
/samples/vsphere/oauth/grant_types/list_vms_password.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 | from vmware.vapi.vsphere.client import create_vsphere_client
16 |
17 | from samples.vsphere.common import sample_cli
18 | from samples.vsphere.common import sample_util
19 | from samples.vsphere.common.ssl_helper import get_unverified_session
20 | from samples.vsphere.oauth.grant_types.oauth_utility \
21 | import login_using_password
22 | import argparse
23 |
24 | __author__ = 'VMware, Inc.'
25 | __copyright__ = 'Copyright 2020 VMware, Inc. All rights reserved.'
26 | __vcenter_version__ = '7.0+'
27 |
28 | """
29 | To run this sample,
30 | $ python list_vms_password --server \
31 | --username --password --skipverification
32 | """
33 |
34 | parser = argparse.ArgumentParser()
35 | parser.add_argument("--server",
36 | help="VC IP or hostname")
37 | parser.add_argument("--username",
38 | help="username to login \
39 | to vCenter")
40 | parser.add_argument("--password",
41 | help="password to login \
42 | to vCenter")
43 | parser.add_argument('--skipverification',
44 | action='store_true',
45 | help='Verify server certificate when connecting to vc.')
46 |
47 | args = parser.parse_args()
48 |
49 | session = get_unverified_session() if args.skipverification else None
50 | saml_assertion = login_using_password(
51 | args.server,
52 | session,
53 | args.username,
54 | args.password)
55 |
56 | client = create_vsphere_client(
57 | server=args.server,
58 | bearer_token=saml_assertion,
59 | session=session)
60 | vms = client.vcenter.VM.list()
61 | print(vms)
62 |
--------------------------------------------------------------------------------
/samples/vsphere/oauth/grant_types/list_vms_refresh_token.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 | from vmware.vapi.vsphere.client import create_vsphere_client
16 |
17 | from samples.vsphere.common import sample_cli
18 | from samples.vsphere.common import sample_util
19 | from samples.vsphere.common.ssl_helper import get_unverified_session
20 | from samples.vsphere.oauth.grant_types.oauth_utility \
21 | import login_using_refresh_token
22 | import argparse
23 |
24 | __author__ = 'VMware, Inc.'
25 | __copyright__ = 'Copyright 2020 VMware, Inc. All rights reserved.'
26 | __vcenter_version__ = '7.0+'
27 |
28 | """
29 | To run this sample,
30 | $ python list_vms_refresh_token.py \
31 | --server --client_id --client_secret \
32 | --refresh_token --skipverification
33 | """
34 |
35 | parser = argparse.ArgumentParser()
36 | parser.add_argument("--server",
37 | help="VC IP or hostname")
38 | parser.add_argument("--client_id",
39 | help="Client/Application ID of the server to server app")
40 | parser.add_argument("--client_secret",
41 | help="Client/Application secret \
42 | of the server to server app")
43 | parser.add_argument("--refresh_token",
44 | help="Refresh token used to refresh the access token")
45 | parser.add_argument('--skipverification',
46 | action='store_true',
47 | help='Verify server certificate when connecting to vc.')
48 |
49 | args = parser.parse_args()
50 |
51 | session = get_unverified_session() if args.skipverification else None
52 | saml_assertion = login_using_refresh_token(
53 | args.server,
54 | session,
55 | args.client_id,
56 | args.client_secret,
57 | args.refresh_token)
58 |
59 | client = create_vsphere_client(
60 | server=args.server,
61 | bearer_token=saml_assertion,
62 | session=session)
63 | vms = client.vcenter.VM.list()
64 | print(vms)
65 |
--------------------------------------------------------------------------------
/samples/vsphere/oauth/list_external_identity_providers.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter_version__ = '6.8.7+'
16 |
17 | import argparse
18 | import requests
19 | from com.vmware.vcenter.identity_client import Providers
20 | from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
21 | from samples.vsphere.common.ssl_helper import get_unverified_session
22 | from vmware.vapi.lib.connect import get_requests_connector
23 |
24 | '''
25 | This sample lists all the external Identity Providers for the given VCenter
26 |
27 | Pre-requisites:
28 | - a VCenter
29 |
30 | To run the sample,
31 | $ python list_external_identity_providers.py --vc --skipverification
32 | '''
33 |
34 | HTTP_ENDPOINT = "https://{}/api"
35 |
36 | parser = argparse.ArgumentParser(description='arguments for listing external Identity Providers')
37 |
38 | parser.add_argument('--vc', dest='vcenter_server',
39 | help='VCenter hostname or IP')
40 | parser.add_argument('--skipverification',
41 | action='store_true',
42 | help='Skip Server Certificate Verification')
43 |
44 | args = parser.parse_args()
45 |
46 | session = requests.session()
47 | if args.skipverification:
48 | session = get_unverified_session()
49 |
50 | stub_config = StubConfigurationFactory.new_std_configuration(get_requests_connector(session=session, url=HTTP_ENDPOINT.format(args.vcenter_server)))
51 |
52 | # use the identity client to list the providers
53 | id_client = Providers(stub_config)
54 | providers = id_client.list()
55 | print("Total providers: {}\n".format(len(providers)))
56 | print("-" * 100)
57 |
58 | # print summary of the providers
59 | for p in providers:
60 | print("Auth Endpoint: {}\n".format(p.oauth2.auth_endpoint))
61 | print("Token Endpoint: {}\n".format(p.oauth2.token_endpoint))
62 | print("-" * 100)
63 |
--------------------------------------------------------------------------------
/samples/vsphere/services/services_list.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | * *******************************************************
4 | * Copyright (c) VMware, Inc. 2016, 2018. All Rights Reserved.
5 | * SPDX-License-Identifier: MIT
6 | * *******************************************************
7 | *
8 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13 | """
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2018 VMware, Inc. All rights reserved.'
17 | __vcenter_version__ = '6.7+'
18 |
19 | from vmware.vapi.vsphere.client import create_vsphere_client
20 | from samples.vsphere.common.ssl_helper import get_unverified_session
21 |
22 | from samples.vsphere.common import sample_cli
23 | from samples.vsphere.common import sample_util
24 |
25 |
26 | class ListServices(object):
27 | """
28 | Demonstrates the details of vCenter Services
29 |
30 | Retrieves the vCenter Services, its Health Status and Service Startup Type.
31 |
32 | Prerequisites:
33 | - vCenter Server
34 | """
35 |
36 | def __init__(self):
37 | # Create argument parser for standard inputs:
38 | # server, username, password and skipverification
39 | parser = sample_cli.build_arg_parser()
40 | args = sample_util.process_cli_args(parser.parse_args())
41 |
42 | # Skip server cert verification if needed.
43 | # This is not recommended in production code.
44 | session = get_unverified_session() if args.skipverification else None
45 |
46 | # Connect to vSphere client
47 | self.client = create_vsphere_client(
48 | server=args.server,
49 | username=args.username,
50 | password=args.password,
51 | session=session)
52 |
53 | def run(self):
54 | services_list = self.client.vcenter.services.Service.list_details()
55 | for key, value in services_list.items():
56 | print(
57 | 'Service Name: {}, Service Name Key: {}, Service Health: {}, Service Status: {}, Service Startup Type: {}'
58 | ).format(key, value.name_key, value.health, value.state,
59 | value.startup_type)
60 |
61 |
62 | def main():
63 | list_services = ListServices()
64 | list_services.run()
65 |
66 |
67 | if __name__ == '__main__':
68 | main()
69 |
--------------------------------------------------------------------------------
/samples/vsphere/sso/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for Platform Service Controller, SSO and Lookup Service APIs:
2 |
3 | The vSphere Automation SDK for Python samples use the vCenter Lookup Service
4 | to obtain the URLs for other vSphere Automation services (SSO, vAPI, VIM, SPBM, etc.).
5 | The SDK contains the Lookup Service WSDL files. The samples use the python SUDS client
6 | for accessing the lookup service. The Lookup Service WSDL files are located in wsdl/ directory.
7 |
8 | Running the samples
9 | ```cmd
10 | $ python external_psc_sso_workflow.py --lsurl https:///lookupservice/sdk -u 'administrator@vsphere.local' -p 'Admin!23' -v
11 | ```
12 | * Testbed Requirement:
13 | - 1 vCenter Server
14 |
15 | ### Deprecation Notice
16 | Starting vCenter server release 7.0, External Platform Services Controller (PSC) is no longer supported. All PSC services are consolidated into vCenter Server.
17 | https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vcenter.configuration.doc/GUID-135F2607-DA51-47A5-BB7A-56AD141113D4.html
18 | In view of the above, related samples (ex: external_psc_sso_workflow) and other related files are deprecated and will be removed in next major SDK release.
19 |
20 | Consequently, lookupservice WSDL files will also be removed in next major SDK release. Use well known URL path (https://docs.vmware.com/en/VMware-vSphere/8.0/vsphere-apis-sdks-introduction/GUID-B625C8FE-5E15-4918-98C0-69313E5880FB.html) instead of lookupservice.
21 |
22 | For SSO, service endpoint is: "https://{domain}/sts/STSService"
23 | https://docs.vmware.com/en/VMware-vSphere/8.0/vsphere-apis-sdks-introduction/GUID-5384662C-CD05-4CAE-894E-972F14A7ECB7.html
24 |
25 | ### Package Dependency Note
26 | To run the deprecated samples, users need "Deprecated" package installed in their environment.
27 | https://pypi.org/project/Deprecated/
28 |
--------------------------------------------------------------------------------
/samples/vsphere/sso/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 | # Required to distribute different parts of this
18 | # package as multiple distribution
19 | try:
20 | import pkg_resources
21 |
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 |
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/sso/wsdl/lookupservice.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/samples/vsphere/tagging/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for Tagging APIs:
2 |
3 | Running the samples
4 |
5 | $ python tagging_workflow.py --server --username --password --clustername --categoryname --categorydesc --tagname -tagdesc -v
6 |
7 | * Testbed Requirement:
8 | - 1 vCenter Server
9 | - 1 cluster
10 |
11 |
--------------------------------------------------------------------------------
/samples/vsphere/tagging/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for the vSphere infrastructure and virtual machine APIs. You have two options to run samples inside this package:
2 |
3 | * Run all samples under vcenter folder using main.py in samples.vsphere.vcenter.setup package. Please see the [README](../../../README.md#running-a-complex-sample) for more details.
4 |
5 | * Run an individual sample in an existing environment. You can either pass the environment parameters through command line arguments or specify them in testbed.py in the setup package.
6 |
7 | For example, to run the create_default_vm sample in the vsphere.samples.vcenter.vm.create package:
8 |
9 | * with the testbed settings specified in testbed.py in a Linux machine:
10 |
11 | $ python samples/vsphere/vcenter/vm/create/create_default_vm.py -v
12 |
13 | * Or specify the credentials using command line parameters:
14 |
15 | $ python samples/vsphere/vcenter/vm/create/create_default_vm.py -s -u -p -v
16 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/certificatemanagement/get_tls_certificate.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __vcenter_version__ = '7.0+'
18 |
19 | import argparse
20 | from samples.vsphere.common import (sample_cli, sample_util)
21 | from vmware.vapi.vsphere.client import create_vsphere_client
22 | import requests
23 |
24 | """
25 | Description: Demonstrates retrieval of the MACHINE SSL certificate from the vCenter
26 | along with the decoded X.509 certificate fields
27 |
28 | Sample Prerequisites:
29 | - The user invoking the API should have the System.Read privilege.
30 | """
31 |
32 | parser = sample_cli.build_arg_parser()
33 |
34 | args = sample_util.process_cli_args(parser.parse_args())
35 |
36 | session = requests.session()
37 | session.verify = False if args.skipverification else True
38 |
39 | # Login to vCenter
40 | vsphere_client = create_vsphere_client(server=args.server,
41 | username=args.username,
42 | password=args.password,
43 | session=session)
44 |
45 | print('Listing the MACHINE SSL certificate along with the decoded X.509 fields ')
46 | print(vsphere_client.vcenter.certificate_management.vcenter.Tls.get())
47 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/certificatemanagement/renew_tls_certificate.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __vcenter_version__ = '7.0+'
18 |
19 | import argparse
20 |
21 | from vmware.vapi.vsphere.client import create_vsphere_client
22 | import requests
23 | from com.vmware.vcenter.certificate_management.vcenter_client import Tls
24 | from samples.vsphere.common import (sample_cli, sample_util)
25 |
26 | """
27 | Description: Demonstrates the renewal of the MACHINE SSL certificate
28 |
29 | Sample Prerequisites:
30 | - The user invoking the API should have the CertificateManagement.Administer privilege.
31 | """
32 |
33 | parser = sample_cli.build_arg_parser()
34 |
35 | parser.add_argument('--duration',
36 | help='Duration of time specified in number of days for which the '
37 | 'MACHINE SSL certificate has to be renewed')
38 |
39 | args = sample_util.process_cli_args(parser.parse_args())
40 |
41 | session = requests.session()
42 | session.verify = False if args.skipverification else True
43 |
44 | # Login to vCenter
45 | vsphere_client = create_vsphere_client(server=args.server,
46 | username=args.username,
47 | password=args.password,
48 | session=session)
49 |
50 | if args.duration is None:
51 | print('Renewing the MACHINE SSL certificate for the duration of ' + str(730) + ' days')
52 | duration = args.duration
53 | else:
54 | print('Renewing the MACHINE SSL certificate for the specified duration of ' + args.duration + ' days')
55 | duration = int(args.duration)
56 |
57 | vsphere_client.vcenter.certificate_management.vcenter.Tls.renew(duration)
58 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/certificatemanagement/trusted_root_chains_create.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __vcenter_version__ = '7.0+'
18 |
19 | import argparse
20 |
21 | from vmware.vapi.vsphere.client import create_vsphere_client
22 | import requests
23 | from com.vmware.vcenter.certificate_management.vcenter_client import TrustedRootChains
24 | from com.vmware.vcenter.certificate_management_client import X509CertChain
25 | from samples.vsphere.common import (sample_cli, sample_util)
26 |
27 | """
28 | Description: Demonstrates the import of the TRUSTED ROOT CHAIN into vCenter
29 |
30 | Sample Prerequisites:
31 | - The user invoking the API should have the CertificateManagement.Manage or the
32 | CertificateManagement.Administer privilege
33 | """
34 |
35 | parser = sample_cli.build_arg_parser()
36 |
37 |
38 | parser.add_argument('--certchain',
39 | required=True,
40 | help='The certificate chain to be imported into vCenter.')
41 |
42 | args = sample_util.process_cli_args(parser.parse_args())
43 |
44 | session = requests.session()
45 | session.verify = False if args.skipverification else True
46 |
47 | # Login to vCenter
48 | vsphere_client = create_vsphere_client(server=args.server,
49 | username=args.username,
50 | password=args.password,
51 | session=session)
52 |
53 | cert_chain = args.certchain.encode(encoding='utf-8').decode('unicode_escape').split(',')
54 |
55 | """
56 | Creation of the spec for input to the API
57 | """
58 | x509_cert_chain = X509CertChain(cert_chain=cert_chain)
59 | cert_chain = TrustedRootChains.CreateSpec(cert_chain=x509_cert_chain)
60 |
61 | print('The alias of the certificate chain successfully imported into vCenter listed below ')
62 | print(vsphere_client.vcenter.certificate_management.vcenter.TrustedRootChains.create(cert_chain))
63 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/certificatemanagement/trusted_root_chains_delete.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __vcenter_version__ = '7.0+'
18 |
19 | import argparse
20 |
21 | from vmware.vapi.vsphere.client import create_vsphere_client
22 | import requests
23 | from com.vmware.vcenter.certificate_management.vcenter_client import TrustedRootChains
24 | from samples.vsphere.common import (sample_cli, sample_util)
25 |
26 | """
27 | Description: Demonstrates the deletion of the TRUSTED ROOT CHAIN corresponding to the provided alias
28 |
29 | Sample Prerequisites:
30 | - The user invoking the API should have the CertificateManagement.Manage or the
31 | CertificateManagement.Administer privilege
32 | """
33 |
34 | parser = sample_cli.build_arg_parser()
35 |
36 | parser.add_argument('--certalias',
37 | required=True,
38 | help='The alias for the certificate chain to be deleted from vCenter.')
39 |
40 | args = sample_util.process_cli_args(parser.parse_args())
41 |
42 | session = requests.session()
43 | session.verify = False if args.skipverification else True
44 |
45 | # Login to vCenter
46 | vsphere_client = create_vsphere_client(server=args.server,
47 | username=args.username,
48 | password=args.password,
49 | session=session)
50 |
51 | cert_alias = args.certalias
52 |
53 | print('Deleting the certificate chain corresponding to the alias ' + cert_alias)
54 | vsphere_client.vcenter.certificate_management.vcenter.TrustedRootChains.delete(cert_alias)
55 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/certificatemanagement/trusted_root_chains_get.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __vcenter_version__ = '7.0+'
18 |
19 | import argparse
20 |
21 | from vmware.vapi.vsphere.client import create_vsphere_client
22 | import requests
23 | from com.vmware.vcenter.certificate_management.vcenter_client import TrustedRootChains
24 | from samples.vsphere.common import (sample_cli, sample_util)
25 |
26 | """
27 | Description: Demonstrates the retrieval of the TRUSTED ROOT CHAIN corresponding to the provided alias
28 |
29 | Sample Prerequisites:
30 | - The user invoking the API should have the System.Read privilege
31 | """
32 |
33 | parser = sample_cli.build_arg_parser()
34 |
35 | parser.add_argument('--certalias',
36 | help='The alias of the certificate chain which is to be retrieved.'
37 | 'All the published certificate chains will be retrieved if not provided')
38 |
39 | args = sample_util.process_cli_args(parser.parse_args())
40 |
41 | session = requests.session()
42 | session.verify = False if args.skipverification else True
43 |
44 | # Login to vCenter
45 | vsphere_client = create_vsphere_client(server=args.server,
46 | username=args.username,
47 | password=args.password,
48 | session=session)
49 |
50 | cert_alias = args.certalias
51 |
52 | if cert_alias is not None:
53 | print('Retrieving the certificate chain corresponding to the alias ' + cert_alias)
54 | print(vsphere_client.vcenter.certificate_management.vcenter.TrustedRootChains.get(cert_alias))
55 | else:
56 | print('Retrieving the all the published certificate chains imported to vCenter')
57 | cert_aliases = vsphere_client.vcenter.certificate_management.vcenter.TrustedRootChains.list()
58 | for alias in cert_aliases:
59 | print('Retrieving the certificate chain for the alias ' + alias.chain)
60 | print(vsphere_client.vcenter.certificate_management.vcenter.TrustedRootChains.get(alias.chain))
61 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/certificatemanagement/trusted_root_chains_list.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __vcenter_version__ = '7.0+'
18 |
19 | import argparse
20 |
21 | from vmware.vapi.vsphere.client import create_vsphere_client
22 | import requests
23 | from com.vmware.vcenter.certificate_management.vcenter_client import TrustedRootChains
24 | from samples.vsphere.common import (sample_cli, sample_util)
25 |
26 | """
27 | Description: Demonstrates the listing of the aliases for the published TRUSTED ROOT CHAINS in vCenter.
28 |
29 | Sample Prerequisites:
30 | - The user invoking the API should have the System.Read privilege
31 | """
32 |
33 | parser = sample_cli.build_arg_parser()
34 |
35 | args = sample_util.process_cli_args(parser.parse_args())
36 |
37 | session = requests.session()
38 | session.verify = False if args.skipverification else True
39 |
40 | # Login to vCenter
41 | vsphere_client = create_vsphere_client(server=args.server,
42 | username=args.username,
43 | password=args.password,
44 | session=session)
45 |
46 |
47 | print('Retrieving all the certificate chain aliases published to vCenter')
48 | cert_aliases = vsphere_client.vcenter.certificate_management.vcenter.TrustedRootChains.list()
49 | print(cert_aliases)
50 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/discovery_and_plan/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 | __copyright__ = 'Copyright 2019 VMware, Inc. All rights reserved.'
17 |
18 |
19 | # Required to distribute different parts of this
20 | # package as multiple distribution
21 | try:
22 | import pkg_resources
23 | pkg_resources.declare_namespace(__name__)
24 | except ImportError:
25 | from pkgutil import extend_path
26 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
27 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/discovery_and_plan/lcm_sample.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | * *******************************************************
4 | * Copyright (c) VMware, Inc. 2019-2020. All Rights Reserved.
5 | * SPDX-License-Identifier: MIT
6 | * *******************************************************
7 | *
8 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13 | """
14 |
15 | __author__ = 'VMware, Inc.'
16 | __vcenter_version__ = '7.0+'
17 |
18 | from com.vmware.vcenter.lcm_client import Reports
19 |
20 | from samples.vsphere.common import sample_cli, sample_util
21 | from samples.vsphere.common.ssl_helper import get_unverified_session
22 | from samples.vsphere.vcenter.hcl.utils import get_configuration
23 |
24 |
25 | class SampleLcm(object):
26 | """
27 | Sample demonstrating vCenter LCM Update APIs
28 | Sample Prerequisites:
29 | vCenter on linux platform
30 | """
31 |
32 | def __init__(self):
33 | parser = sample_cli.build_arg_parser()
34 | parser.add_argument('-f', '--file_name',
35 | help='Provide csv report file name.')
36 | args = sample_util.process_cli_args(parser.parse_args())
37 | self.csv_report = args.file_name
38 | session = get_unverified_session() if args.skipverification else None
39 | stub_config = get_configuration(
40 | args.server, args.username, args.password,
41 | session)
42 | self.report_client = Reports(stub_config)
43 |
44 | def run(self):
45 | """
46 | Access to download the interop report APIs by providing csv_report name
47 | """
48 | report_details = self.report_client.get(self.csv_report)
49 | print("Report Details - ", report_details)
50 |
51 |
52 | def main():
53 | """
54 | Entry point for the sample client
55 | """
56 | lcm = SampleLcm()
57 | lcm.run()
58 |
59 |
60 | if __name__ == '__main__':
61 | main()
62 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/discovery_and_plan/update_sample.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | * *******************************************************
4 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
5 | * SPDX-License-Identifier: MIT
6 | * *******************************************************
7 | *
8 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13 | """
14 |
15 | __author__ = 'VMware, Inc.'
16 | __vcenter_version__ = '7.0+'
17 |
18 | from com.vmware.vcenter.lcm.update_client import Pending, PrecheckReport
19 |
20 | from samples.vsphere.common import sample_cli, sample_util
21 | from samples.vsphere.common.ssl_helper import get_unverified_session
22 | from samples.vsphere.vcenter.hcl.utils import get_configuration
23 |
24 |
25 | class SampleUpdate(object):
26 | """
27 | Sample demonstrating vCenter LCM Update APIs
28 | Sample Prerequisites:
29 | vCenter on linux platform
30 | """
31 | def __init__(self):
32 | parser = sample_cli.build_arg_parser()
33 | args = sample_util.process_cli_args(parser.parse_args())
34 | session = get_unverified_session() if args.skipverification else None
35 | stub_config = get_configuration(
36 | args.server, args.username, args.password,
37 | args.skipverification)
38 | self.pending_client = Pending(stub_config)
39 | self.precheck_client = PrecheckReport(stub_config)
40 |
41 | def run(self):
42 | """
43 | Access the Update APIs to list available patches and details
44 | """
45 | available_updates = self.pending_client.list()
46 | print("vCenter available updates - ", available_updates)
47 | if available_updates.updates:
48 | target_version = available_updates.updates[0].version
49 | update_details = self.pending_client.get(target_version)
50 | print("vCenter available update details - ", update_details)
51 |
52 | # precheck API's
53 | precheck_result = self.precheck_client.create_task(target_version)
54 | print("Pre upgrade checks task id started with: \n{0}".format(precheck_result.get_task_id()))
55 |
56 |
57 | def main():
58 | """
59 | Entry point for the sample client
60 | """
61 | update = SampleUpdate()
62 | update.run()
63 |
64 |
65 | if __name__ == '__main__':
66 | main()
67 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/guest/linSpec.cfg:
--------------------------------------------------------------------------------
1 | [CREATESPEC]
2 | specName=testCreateLinSpec1
3 | specDesc=This is a linux customizationSpec created by vAPI
4 |
5 | [HOSTNAME]
6 | # valid types are: FIXED, PREFIX, VIRTUAL_MACHINE, USER_INPUT_REQUIRED
7 | hostnameGeneratorType=VIRTUAL_MACHINE
8 | # If hostnameGeneratorType is "PREFIX", prefix must be set to some string
9 | #prefix=
10 | # If hostnameGeneratorType is "FIXED", fixedName must be set to the hostname string
11 | #fixedName=
12 |
13 | [LINUXCONFIG]
14 | domainName=test.abc.com
15 | # valid timezone list: https://kb.vmware.com/s/article/2145518
16 | timezone=Asia/Shanghai
17 | # should be some valid bash/shell script txt or empty
18 | #scriptText=
19 |
20 |
21 | [NETWORK]
22 | ### MacAddress ###
23 | # macAddress is optional
24 | # macAddress=fc:00:0a:33:22:11
25 |
26 | ### IPV4 ###
27 | # valid types are: DHCP, STATIC, USER_INPUT_REQUIRED.
28 | # If use "STATIC", then must also input "prefix, gateways=None, ip_address="
29 | ## sample DHCP ipv4Type ##
30 | ipv4Type=DHCP
31 | ## sample STATIC ipv4Type ##
32 | #ipv4Type=STATIC
33 | #ipv4_prefix=31
34 | #ipv4_gateways=192.168.11.13
35 | #ipv4_ip=192.168.11.1
36 |
37 | ### IPV6 ###
38 | # valid types are: DHCP, STATIC, USER_INPUT_REQUIRED.
39 | # If use "STATIC", then must also input "prefix, gateways=None, ip_address="
40 | ## sample DHCP ipv6Type ##
41 | #ipv6Type=DHCP
42 | ## sample STATIC ipv6Type ##
43 | #ipv6Type=STATIC
44 | #ipv6_prefix=128
45 | #ipv6_gateways=fc00:10:31:11::1
46 | #ipv6_ip=fc00:10:31:11::34
47 |
48 |
49 | [DNS]
50 | dnsServers=10.1.2.3,8.8.8.8
51 | dnsSuffixs=test.abc.com,test2.com
52 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/guest/sample_metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "local-hostname": "test-vm-01",
3 | "instance-id": "test-vm-id-01",
4 | "network": {
5 | "version":2,
6 | "ethernets": {
7 | "nics": {
8 | "match": {
9 | "name": "eth*"
10 | },
11 | "nameservers": {
12 | "addresses": ["127.0.0.53"],
13 | "search": ["eng.vmware.com", "vmware.com"]
14 | },
15 | "gateway4": "10.182.15.255",
16 | "dhcp4": false,
17 | "addresses": ["10.182.12.25/24"]
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/guest/sample_metadata.yaml:
--------------------------------------------------------------------------------
1 | instance-id: test-vm-id-01
2 | local-hostname: test-vm-01
3 | network:
4 | version: 2
5 | ethernets:
6 | nics:
7 | match:
8 | name: eth*
9 | dhcp4: yes
10 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/guest/sample_userdata:
--------------------------------------------------------------------------------
1 | #cloud-config
2 | # See more userdata examples at:
3 | # https://cloudinit.readthedocs.io/en/latest/topics/examples.html
4 | write_files:
5 | - encoding: gzip
6 | content: !!binary |
7 | H4sIAIDb/U8C/1NW1E/KzNMvzuBKTc7IV8hIzcnJVyjPL8pJ4QIA6N+MVxsAAAA=
8 | path: /usr/bin/hello
9 | permissions: '0755'
10 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/hcl/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for the ESXi Hardware Compatibility APIs. ESXi Hardware Compatibility feature generates a hardware compatibility report for a given ESXi against a target ESXi version.
2 |
3 | For more information, please review the official release notes.
4 |
5 | The feature is realized with the following APIs:
6 | * Compatibility Data Download: Updates the local compatibility data on the vCenter based on the latest version in the VMware Official repository.
7 | * Compatibility Data Status: Provides information about when the compatibility Datastore on the vCenter was last synced with VMware Official Repository.
8 | * Compatibility Releases : Lists the available ESXi releases for a given host that can be used to generate a compatibility report.
9 | * Compatibility Report: Generates a compatibility report for the source host against the target version.
10 |
11 | Overview of the directory code samples:
12 | * compatibility_data_update_sample.py - Corresponds to Compatibiliy Data download operation as mentioned above.
13 | * compatibility_data_status_sample.py - Corresponds to Compatibiliy Data status as mentioned above.
14 | * compatibility_releases_sample.py - Corresponds to Compatibility Releases operation as mentioned above.
15 | * compatibility_report_sample.py - Corresponds to Compatibility Report operation as mentioned above.
16 |
17 | To view the available command-line options:
18 |
19 | $ python compatibility_data_update_sample.py --help
20 | $ python compatibility_data_status_sample.py --help
21 | $ python compatibility_releases_sample.py --help
22 | $ python compatibility_report_sample.py --help
23 |
24 | Running the samples:
25 |
26 | $ python compatibility_data_update_sample.py --server --username --password --skipverification
27 | $ python compatibility_data_status_sample.py --server --username --password --skipverification
28 | $ python compatibility_releases_sample.py --server --username --password --host --skipverification
29 | $ python compatibility_report_sample.py --server --username --password --host --release --skipverification
30 |
31 | Testbed Requirement:
32 |
33 | * 1 vCenter Server appliance version 7.0 or above are supported.
34 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/hcl/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 |
15 | __author__ = 'VMware, Inc.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/hcl/compatibility_data_status_sample.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | * *******************************************************
4 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
5 | * SPDX-License-Identifier: MIT
6 | * *******************************************************
7 | *
8 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13 | """
14 |
15 | __author__ = 'VMware, Inc.'
16 | __vcenter_version__ = '7.0+'
17 |
18 | from com.vmware.esx.hcl_client import CompatibilityData
19 |
20 | from samples.vsphere.vcenter.hcl.utils import get_configuration
21 | from samples.vsphere.common import sample_cli, sample_util
22 |
23 |
24 | class CompatibilityDataStatusSample(object):
25 | """
26 | Sample demonstrating vCenter HCL Compatibility Data Status Check Operation
27 | Sample Prerequisites:
28 | vCenter on linux platform
29 | """
30 |
31 | def __init__(self):
32 | parser = sample_cli.build_arg_parser()
33 | args = sample_util.process_cli_args(parser.parse_args())
34 |
35 | config = get_configuration(args.server, args.username,
36 | args.password,
37 | args.skipverification)
38 | self.api_client = CompatibilityData(config)
39 |
40 | def run(self):
41 | """
42 | Invokes the HCL Compatibility Data Status GET API to get information
43 | about when the compatibility data was last updated
44 | """
45 | data_status_info = self.api_client.get()
46 | print("Compatibility Data Status : ", data_status_info)
47 |
48 |
49 | def main():
50 | """
51 | Entry point for the CompatibilityDataStatusSample client
52 | """
53 | dataStatusSample = CompatibilityDataStatusSample()
54 | dataStatusSample.run()
55 |
56 |
57 | if __name__ == '__main__':
58 | main()
59 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/hcl/compatibility_data_update_sample.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | * *******************************************************
4 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
5 | * SPDX-License-Identifier: MIT
6 | * *******************************************************
7 | *
8 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13 | """
14 |
15 | __author__ = 'VMware, Inc.'
16 | __vcenter_version__ = '7.0+'
17 |
18 | from com.vmware.esx.hcl_client import CompatibilityData
19 |
20 | from samples.vsphere.vcenter.hcl.utils import get_configuration
21 | from samples.vsphere.common import sample_cli, sample_util
22 |
23 |
24 | class CompatibilityDataUpdateSample(object):
25 | """
26 | Sample demonstrating vCenter HCL Compatibility Data Update Operation
27 | Sample Prerequisites:
28 | vCenter on linux platform
29 | """
30 |
31 | def __init__(self):
32 | parser = sample_cli.build_arg_parser()
33 | args = sample_util.process_cli_args(parser.parse_args())
34 | config = get_configuration(args.server, args.username,
35 | args.password,
36 | args.skipverification)
37 | self.api_client = CompatibilityData(config)
38 |
39 | def run(self):
40 | """
41 | Calls the HCL Compatibility Data Update POST API to update the HCL Datastore on the vCenter
42 | """
43 | data_update_info = self.api_client.update_task()
44 | print("Compatibility Data Update Task ID : ", data_update_info.get_task_id())
45 |
46 |
47 | def main():
48 | """
49 | Entry point for the CompatibilityDataUpdateSample client
50 | """
51 | dataUpdateSample = CompatibilityDataUpdateSample()
52 | dataUpdateSample.run()
53 |
54 |
55 | if __name__ == '__main__':
56 | main()
57 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/hcl/compatibility_releases_sample.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | * *******************************************************
4 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
5 | * SPDX-License-Identifier: MIT
6 | * *******************************************************
7 | *
8 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13 | """
14 |
15 | __author__ = 'VMware, Inc.'
16 | __vcenter_version__ = '7.0+'
17 |
18 | from com.vmware.esx.hcl.hosts_client import CompatibilityReleases
19 |
20 | from samples.vsphere.vcenter.hcl.utils import get_configuration
21 | from samples.vsphere.common import sample_cli, sample_util
22 |
23 |
24 | class CompatibilityReleasesSample(object):
25 | """
26 | Sample demonstrating vCenter HCL Get Compatibility Releases Operation
27 | Sample Prerequisites:
28 | vCenter on linux platform
29 | The vCenter should have HCL DataStore(Compatibility Data) Populated
30 | """
31 |
32 | def __init__(self):
33 | parser = sample_cli.build_arg_parser()
34 | parser.add_argument('-id', '--host',
35 | required=True,
36 | help='MOID of the source host for eg "host-13"')
37 | args = sample_util.process_cli_args(parser.parse_args())
38 | self.host_id = args.host
39 | config = get_configuration(args.server, args.username,
40 | args.password,
41 | args.skipverification)
42 | self.api_client = CompatibilityReleases(config)
43 |
44 | def run(self):
45 | """
46 | Invokes the HCL Compatibility Releases GET API to get list of available releases for the source ESXi host
47 | """
48 | releases_info = self.api_client.list(self.host_id)
49 | print("Compatibility Releases Info : ", releases_info)
50 |
51 |
52 | def main():
53 | """
54 | Entry point for the CompatibilityReleasesSample client
55 | """
56 | releasesSample = CompatibilityReleasesSample()
57 | releasesSample.run()
58 |
59 |
60 | if __name__ == '__main__':
61 | main()
62 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/hcl/utils.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter_version__ = '7.0+'
16 |
17 | import requests
18 |
19 | from com.vmware.cis_client import Session
20 |
21 | from samples.vsphere.common.ssl_helper import get_unverified_session
22 | from vmware.vapi.security.session import create_session_security_context
23 | from vmware.vapi.lib.connect import get_requests_connector
24 | from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
25 | from vmware.vapi.security.client.security_context_filter import \
26 | LegacySecurityContextFilter
27 | from vmware.vapi.security.user_password import \
28 | create_user_password_security_context
29 |
30 |
31 | """
32 | Creates a session and returns the stub configuration
33 | """
34 |
35 |
36 | def get_configuration(server, username, password, skipVerification):
37 | session = get_unverified_session() if skipVerification else None
38 | if not session:
39 | session = requests.Session()
40 | host_url = "https://{}/api".format(server)
41 | sec_ctx = create_user_password_security_context(username,
42 | password)
43 | session_svc = Session(
44 | StubConfigurationFactory.new_std_configuration(
45 | get_requests_connector(
46 | session=session, url=host_url,
47 | provider_filter_chain=[
48 | LegacySecurityContextFilter(
49 | security_context=sec_ctx)])))
50 | session_id = session_svc.create()
51 | print("Session ID : ", session_id)
52 | sec_ctx = create_session_security_context(session_id)
53 | stub_config = StubConfigurationFactory.new_std_configuration(
54 | get_requests_connector(
55 | session=session, url=host_url,
56 | provider_filter_chain=[
57 | LegacySecurityContextFilter(
58 | security_context=sec_ctx)]))
59 | return stub_config
60 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/helper/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/helper/cluster_helper.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2016-2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter_version__ = '6.5+'
16 |
17 | from com.vmware.vcenter_client import Cluster
18 |
19 | from samples.vsphere.vcenter.helper import datacenter_helper
20 |
21 |
22 | def get_cluster(client, datacenter_name, cluster_name):
23 | """
24 | Returns the identifier of a cluster
25 | Note: The method assumes only one cluster and datacenter
26 | with the mentioned name.
27 | """
28 |
29 | datacenter = datacenter_helper.get_datacenter(client, datacenter_name)
30 | if not datacenter:
31 | print("Datacenter '{}' not found".format(datacenter_name))
32 | return None
33 |
34 | filter_spec = Cluster.FilterSpec(names=set([cluster_name]),
35 | datacenters=set([datacenter]))
36 |
37 | cluster_summaries = client.vcenter.Cluster.list(filter_spec)
38 | if len(cluster_summaries) > 0:
39 | cluster = cluster_summaries[0].cluster
40 | print("Detected cluster '{}' as {}".format(cluster_name, cluster))
41 | return cluster
42 | else:
43 | print("Cluster '{}' not found".format(cluster_name))
44 | return None
45 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/helper/datacenter_helper.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2016-2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter_version__ = '6.5+'
16 |
17 | from com.vmware.vcenter_client import Datacenter
18 |
19 |
20 | def get_datacenter(client, datacenter_name):
21 | """
22 | Returns the identifier of a datacenter
23 | Note: The method assumes only one datacenter with the mentioned name.
24 | """
25 |
26 | filter_spec = Datacenter.FilterSpec(names=set([datacenter_name]))
27 |
28 | datacenter_summaries = client.vcenter.Datacenter.list(filter_spec)
29 | if len(datacenter_summaries) > 0:
30 | datacenter = datacenter_summaries[0].datacenter
31 | return datacenter
32 | else:
33 | return None
34 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/helper/datastore_helper.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2016-2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter_version__ = '6.5+'
16 |
17 | from com.vmware.vcenter_client import Datastore
18 |
19 | from samples.vsphere.vcenter.helper import datacenter_helper
20 |
21 |
22 | def get_datastore(client, datacenter_name, datastore_name):
23 | """
24 | Returns the identifier of a datastore
25 | Note: The method assumes that there is only one datastore and datacenter
26 | with the mentioned names.
27 | """
28 | datacenter = datacenter_helper.get_datacenter(client, datacenter_name)
29 | if not datacenter:
30 | print("Datacenter '{}' not found".format(datacenter_name))
31 | return None
32 |
33 | filter_spec = Datastore.FilterSpec(names=set([datastore_name]),
34 | datacenters=set([datacenter]))
35 |
36 | datastore_summaries = client.vcenter.Datastore.list(filter_spec)
37 | if len(datastore_summaries) > 0:
38 | datastore = datastore_summaries[0].datastore
39 | return datastore
40 | else:
41 | return None
42 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/helper/folder_helper.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2016-2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter_version__ = '6.5+'
16 |
17 | from com.vmware.vcenter_client import Folder
18 |
19 | from samples.vsphere.vcenter.helper import datacenter_helper
20 |
21 |
22 | def get_folder(client, datacenter_name, folder_name):
23 | """
24 | Returns the identifier of a folder
25 | Note: The method assumes that there is only one folder and datacenter
26 | with the mentioned names.
27 | """
28 | datacenter = datacenter_helper.get_datacenter(client, datacenter_name)
29 | if not datacenter:
30 | print("Datacenter '{}' not found".format(datacenter_name))
31 | return None
32 |
33 | filter_spec = Folder.FilterSpec(type=Folder.Type.VIRTUAL_MACHINE,
34 | names=set([folder_name]),
35 | datacenters=set([datacenter]))
36 |
37 | folder_summaries = client.vcenter.Folder.list(filter_spec)
38 | if len(folder_summaries) > 0:
39 | folder = folder_summaries[0].folder
40 | print("Detected folder '{}' as {}".format(folder_name, folder))
41 | return folder
42 | else:
43 | print("Folder '{}' not found".format(folder_name))
44 | return None
45 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/helper/network_helper.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2016-2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter_version__ = '6.5+'
16 |
17 | from com.vmware.vcenter_client import Network
18 |
19 | from samples.vsphere.vcenter.helper import datacenter_helper
20 |
21 |
22 | def get_network_backing(client,
23 | porggroup_name,
24 | datacenter_name,
25 | portgroup_type):
26 | """
27 | Gets a standard portgroup network backing for a given Datacenter
28 | Note: The method assumes that there is only one standard portgroup
29 | and datacenter with the mentioned names.
30 | """
31 | datacenter = datacenter_helper.get_datacenter(client, datacenter_name)
32 | if not datacenter:
33 | print("Datacenter '{}' not found".format(datacenter_name))
34 | return None
35 |
36 | filter = Network.FilterSpec(datacenters=set([datacenter]),
37 | names=set([porggroup_name]),
38 | types=set([portgroup_type]))
39 | network_summaries = client.vcenter.Network.list(filter=filter)
40 |
41 | if len(network_summaries) > 0:
42 | network = network_summaries[0].network
43 | print("Selecting {} Portgroup Network '{}' ({})".
44 | format(portgroup_type, porggroup_name, network))
45 | return network
46 | else:
47 | print("Portgroup Network not found in Datacenter '{}'".
48 | format(datacenter_name))
49 | return None
50 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/helper/resource_pool_helper.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2016-2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter_version__ = '6.5+'
16 |
17 | from com.vmware.vcenter_client import ResourcePool
18 |
19 | from samples.vsphere.vcenter.helper import datacenter_helper
20 |
21 |
22 | def get_resource_pool(client, datacenter_name, resource_pool_name=None):
23 | """
24 | Returns the identifier of the resource pool with the given name or the
25 | first resource pool in the datacenter if the name is not provided.
26 | """
27 | datacenter = datacenter_helper.get_datacenter(client, datacenter_name)
28 | if not datacenter:
29 | print("Datacenter '{}' not found".format(datacenter_name))
30 | return None
31 |
32 | names = set([resource_pool_name]) if resource_pool_name else None
33 | filter_spec = ResourcePool.FilterSpec(datacenters=set([datacenter]),
34 | names=names)
35 |
36 | resource_pool_summaries = client.vcenter.ResourcePool.list(filter_spec)
37 | if len(resource_pool_summaries) > 0:
38 | resource_pool = resource_pool_summaries[0].resource_pool
39 | print("Selecting ResourcePool '{}'".format(resource_pool))
40 | return resource_pool
41 | else:
42 | print("ResourcePool not found in Datacenter '{}'".
43 | format(datacenter_name))
44 | return None
45 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/helper/vm_helper.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2016-2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter_version__ = '6.5+'
16 |
17 | from com.vmware.vcenter_client import VM
18 |
19 |
20 | def get_vm(client, vm_name):
21 | """
22 | Return the identifier of a vm
23 | Note: The method assumes that there is only one vm with the mentioned name.
24 | """
25 | names = set([vm_name])
26 | vms = client.vcenter.VM.list(VM.FilterSpec(names=names))
27 |
28 | if len(vms) == 0:
29 | print("VM with name ({}) not found".format(vm_name))
30 | return None
31 |
32 | vm = vms[0].vm
33 | print("Found VM '{}' ({})".format(vm_name, vm))
34 | return vm
35 |
36 |
37 | def get_vms(client, vm_names):
38 | """Return identifiers of a list of vms"""
39 | vms = client.vcenter.VM.list(VM.FilterSpec(names=vm_names))
40 |
41 | if len(vms) == 0:
42 | print('No vm found')
43 | return None
44 |
45 | print("Found VMs '{}' ({})".format(vm_names, vms))
46 | return vms
47 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/helper/vm_placement_helper.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) VMware, Inc. 2016-2018. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __vcenter_version__ = '6.5+'
16 |
17 | from com.vmware.vcenter_client import VM
18 |
19 | from samples.vsphere.vcenter.helper import datastore_helper
20 | from samples.vsphere.vcenter.helper import folder_helper
21 | from samples.vsphere.vcenter.helper import resource_pool_helper
22 |
23 |
24 | def get_placement_spec_for_resource_pool(client,
25 | datacenter_name,
26 | vm_folder_name,
27 | datastore_name):
28 | """
29 | Returns a VM placement spec for a resourcepool. Ensures that the
30 | vm folder and datastore are all in the same datacenter which is specified.
31 | """
32 | resource_pool = resource_pool_helper.get_resource_pool(client,
33 | datacenter_name)
34 |
35 | folder = folder_helper.get_folder(client,
36 | datacenter_name,
37 | vm_folder_name)
38 |
39 | datastore = datastore_helper.get_datastore(client,
40 | datacenter_name,
41 | datastore_name)
42 |
43 | # Create the vm placement spec with the datastore, resource pool and vm
44 | # folder
45 | placement_spec = VM.PlacementSpec(folder=folder,
46 | resource_pool=resource_pool,
47 | datastore=datastore)
48 |
49 | print("get_placement_spec_for_resource_pool: Result is '{}'".
50 | format(placement_spec))
51 | return placement_spec
52 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/hvc/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for managing vSphere hybrid linked mode:
2 |
3 | The sample were tested against vSphere 6.7
4 |
5 | ### Hybrid Linked Mode link Create/List/Delete operations
6 | Sample | Description
7 | ----------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
8 | links_client.py | Demonstrates link Create, List, Delete operations with a foreign platform service controller in a different SSO domain.
9 |
10 | ### Hybrid Linked Mode Administrator identity source group Add/Get/Remove operations
11 | Sample | Description
12 | ----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------
13 | administrator_client.py | Demonstrates Add, Get, Remove operations for a given SSO group in an Identity source to the CloudAdminGroup.
14 |
15 | ### Testbed Requirement:
16 | - 2 vCenter Server in different SSO domains. The 2nd vCenter should be on version 6.5x
17 | - The username being used to run the sample should have the HLM.Manage privilege.
18 | - AdministratorClient sample requires the vCenter under test to have an Identity Source added and a local group called CloudAdminGroup to be created.
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/namespace_management/list_clusters.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2016. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
18 | __vcenter_version__ = '7.0.1+'
19 |
20 | from com.vmware.vcenter.namespace_management_client import Clusters
21 |
22 | from samples.vsphere.common import sample_cli
23 | from samples.vsphere.common import sample_util
24 | from samples.vsphere.common.ssl_helper import get_unverified_session
25 | from samples.vsphere.vcenter.hcl.utils import get_configuration
26 | from pprint import pprint
27 |
28 |
29 | class ListCluster(object):
30 | """
31 | Demonstrates getting list of WCP enabled clusters
32 | Sample Prerequisites:
33 | vCenter/ESX with wcp enable"
34 | """
35 | def __init__(self):
36 | parser = sample_cli.build_arg_parser()
37 | args = sample_util.process_cli_args(parser.parse_args())
38 | session = get_unverified_session() if args.skipverification else None
39 | stub_config = get_configuration(
40 | args.server, args.username, args.password,
41 | session)
42 | self.list_cluster = Clusters(stub_config)
43 |
44 | def run(self):
45 | """
46 | List cluster present in server
47 | """
48 | clusters = self.list_cluster
49 | list_of_cl = clusters.list()
50 | print("----------------------------")
51 | print("List Of clusters")
52 | print("----------------------------")
53 | pprint(list_of_cl)
54 | print("----------------------------")
55 |
56 |
57 | def main():
58 | list_cl = ListCluster()
59 | list_cl.run()
60 |
61 |
62 | if __name__ == '__main__':
63 | main()
64 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/setup/README.md:
--------------------------------------------------------------------------------
1 | This directory contains sample scripts to setup the testbed required to run
2 | the vCenter APIs samples. Refer see [README](../../../../README.md#running-the-sdk-sample-setup-script) for more details.
3 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/setup/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/topologysvc/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for getting vCenter Server replication status and node information
2 |
3 | The samples are compatible with vSPhere 7.0+
4 |
5 | ### vCenter server node topology information List/Get operations
6 | Sample | Description
7 | ----------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
8 | get_node.py | Demonstrates getting the vCenter Server or Platform service controler node information.
9 | list_nodes.py | Demonstrates listing of the vCenter Server or Platform service controller node's information in Link Mode in an SSO Domain.
10 | list_embedded_nodes.py | Demonstrates listing of Embedded vCenter Server node's information in an SSO Domain.
11 |
12 | ### vCenter server Replication Status List operations
13 | Sample | Description
14 | ----------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------
15 | list_replication_status.py | Demonstrates listing of replication status of all vCenter Server's in an SSO Domain.
16 | list_node_replication_status.py | Demonstrates status of replication for a vCenter Server.
17 |
18 | ### Testbed Requirement:
19 | - 1 vCenter Server on version 7.0+
20 | - The username being used to run the sample should have System.Read privilege for the operation to be performed.
21 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/topologysvc/get_node.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __vcenter_version__ = '7.0+'
18 |
19 | from vmware.vapi.vsphere.client import create_vsphere_client
20 | from samples.vsphere.common import (sample_cli, sample_util)
21 | from samples.vsphere.common.ssl_helper import get_unverified_session
22 |
23 | """
24 | Description: Demonstrates getting the vCenter Server or Platform service
25 | controler node information.
26 |
27 | Sample Prerequisites:
28 | - The user invoking the API should have the System.Read privilege.
29 | """
30 |
31 | parser = sample_cli.build_arg_parser()
32 |
33 | parser.add_argument('--node',
34 | required=True,
35 | help='Identifier of the vCenter or Platform Services'
36 | ' Controller node. Identifier should be DNS'
37 | ' resolvable name of the node')
38 |
39 | args = sample_util.process_cli_args(parser.parse_args())
40 |
41 | session = get_unverified_session() if args.skipverification else None
42 |
43 | # Login to vCenter
44 | vsphere_client = create_vsphere_client(server=args.server,
45 | username=args.username,
46 | password=args.password,
47 | session=session)
48 |
49 | print(vsphere_client.vcenter.topology.Nodes.get(args.node))
50 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/topologysvc/list_embedded_nodes.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __vcenter_version__ = '7.0+'
18 |
19 |
20 | from vmware.vapi.vsphere.client import create_vsphere_client
21 | from com.vmware.vcenter.topology_client import Nodes
22 | from samples.vsphere.common import (sample_cli, sample_util)
23 | from samples.vsphere.common.ssl_helper import get_unverified_session
24 |
25 | """
26 | Description: Demonstrates listing of Embedded vCenter Server node's information
27 | in an SSO Domain.
28 |
29 | Sample Prerequisites:
30 | - The user invoking the API should have the System.Read privilege.
31 | """
32 |
33 | parser = sample_cli.build_arg_parser()
34 |
35 | args = sample_util.process_cli_args(parser.parse_args())
36 |
37 | session = get_unverified_session() if args.skipverification else None
38 |
39 | # Login to vCenter
40 | vsphere_client = create_vsphere_client(server=args.server,
41 | username=args.username,
42 | password=args.password,
43 | session=session)
44 |
45 | filter_spec = Nodes.FilterSpec({Nodes.ApplianceType.VCSA_EMBEDDED})
46 |
47 | print(vsphere_client.vcenter.topology.Nodes.list(filter_spec))
48 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/topologysvc/list_node_replication_status.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __vcenter_version__ = '7.0+'
18 |
19 |
20 | from vmware.vapi.vsphere.client import create_vsphere_client
21 | from com.vmware.vcenter.topology_client import ReplicationStatus
22 | from samples.vsphere.common import (sample_cli, sample_util)
23 | from samples.vsphere.common.ssl_helper import get_unverified_session
24 |
25 | """
26 | Description: Demonstrates listing of replication status for a vCenter Server.
27 |
28 | Sample Prerequisites:
29 | - The user invoking the API should have the System.Read privilege.
30 | """
31 |
32 | parser = sample_cli.build_arg_parser()
33 |
34 | parser.add_argument('--node',
35 | required=True,
36 | help='Identifier of the vCenter or Platform Services'
37 | ' Controller node. Identifier should be DNS'
38 | ' resolvable name of the node')
39 |
40 | args = sample_util.process_cli_args(parser.parse_args())
41 |
42 | session = get_unverified_session() if args.skipverification else None
43 |
44 | # Login to vCenter
45 | vsphere_client = create_vsphere_client(server=args.server,
46 | username=args.username,
47 | password=args.password,
48 | session=session)
49 |
50 | filter_spec = ReplicationStatus.FilterSpec({args.node})
51 |
52 | print(vsphere_client.vcenter.topology.ReplicationStatus.list(filter_spec))
53 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/topologysvc/list_nodes.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __vcenter_version__ = '7.0+'
18 |
19 |
20 | from vmware.vapi.vsphere.client import create_vsphere_client
21 | from samples.vsphere.common import (sample_cli, sample_util)
22 | from samples.vsphere.common.ssl_helper import get_unverified_session
23 |
24 | """
25 | Description: Demonstrates listing of the vCenter server or Platform service
26 | controller nodes in Link Mode in an SSO Domain.
27 |
28 | Sample Prerequisites:
29 | - The user invoking the API should have the System.Read privilege.
30 | """
31 |
32 | parser = sample_cli.build_arg_parser()
33 |
34 | args = sample_util.process_cli_args(parser.parse_args())
35 |
36 | session = get_unverified_session() if args.skipverification else None
37 |
38 | # Login to vCenter
39 | vsphere_client = create_vsphere_client(server=args.server,
40 | username=args.username,
41 | password=args.password,
42 | session=session)
43 |
44 | print(vsphere_client.vcenter.topology.Nodes.list())
45 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/topologysvc/list_replication_status.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __vcenter_version__ = '7.0+'
18 |
19 |
20 | from vmware.vapi.vsphere.client import create_vsphere_client
21 | from samples.vsphere.common import (sample_cli, sample_util)
22 | from samples.vsphere.common.ssl_helper import get_unverified_session
23 |
24 | """
25 | Description: Demonstrates listing of the vCenter Server or Platform service
26 | controller node's information in Link Mode in an SSO Domain.
27 |
28 | Sample Prerequisites:
29 | - The user invoking the API should have the System.Read privilege.
30 | """
31 |
32 | parser = sample_cli.build_arg_parser()
33 |
34 | args = sample_util.process_cli_args(parser.parse_args())
35 |
36 | session = get_unverified_session() if args.skipverification else None
37 |
38 | # Login to vCenter
39 | vsphere_client = create_vsphere_client(server=args.server,
40 | username=args.username,
41 | password=args.password,
42 | session=session)
43 |
44 | print(vsphere_client.vcenter.topology.ReplicationStatus.list())
45 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vlcm/README.md:
--------------------------------------------------------------------------------
1 | This directory organizes the different types of available sample vLCM APIs.
2 |
3 | 1. Hardware Compatibilty Details Operations:
4 | * Get the cluster hardware compatibility details - cluster/hcl/hw_compatibility_details_sample.py
5 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vlcm/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2022. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2022 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vlcm/cluster/README.md:
--------------------------------------------------------------------------------
1 | This directory organizes the different types of cluster level sample vLCM APIs.
2 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vlcm/cluster/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2022. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2022 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vlcm/cluster/hcl/README.md:
--------------------------------------------------------------------------------
1 | #vLCM/Cluster/HCL
2 |
3 | This directory contains samples of cluster level vLCM HCL APIs.
4 |
5 | The hardware compatibility service provides a way to ensure that the various driver and firmware components that are going to be installed on certain HW components (which are in use by vSAN) are certified against the ESXi version and present in the vSAN VCG.
6 |
7 | The Hardware Compatibility Details provides information such as the overall compliance status of the cluster, the base image version, pci device compliance, and storage device compliance. Within the more specific sections of the hardware compatibility details, one can find the corresponding supported devices.
8 |
9 | ##Supported Features by Release:
10 |
11 | 7.0 : IO Controllers
12 | 7.0 U3 : IO Controllers, Directly Attached Storage Devices, Storage Devices Configured With RAID Controller
13 | 8.0 : IO Controllers, Directly Attached Storage Devices, Storage Devices Configured With RAID Controller, Intel VMD NVMe, RDMA NIC
14 |
15 | ##APIs
16 | GET Hardware Compatibility Details - Returns the HCL validation check detailed results.
17 |
18 | ##Running the Samples:
19 |
20 | To view the available command-line options:
21 |
22 | $ python hw_compatibility_details_sample.py --help
23 |
24 | Run the samples:
25 |
26 | $ python hw_compatibility_details_sample.py --server --username --password --skipverification --cluster
27 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vlcm/cluster/hcl/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2022. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2022 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vlcm/cluster/hcl/hw_compatibility_details_sample.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | * *******************************************************
4 | * Copyright (c) VMware, Inc. 2022. All Rights Reserved.
5 | * SPDX-License-Identifier: MIT
6 | * *******************************************************
7 | *
8 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13 | """
14 |
15 | __author__ = 'VMware, Inc.'
16 | __vcenter_version__ = '7.0+'
17 |
18 | from com.vmware.esx.settings.clusters.software.reports.hardware_compatibility_client import Details
19 | from samples.vsphere.vcenter.hcl.utils import get_configuration
20 | from samples.vsphere.common import sample_util, sample_cli
21 |
22 |
23 | class HWCompatibilityDetailsSample(object):
24 | """
25 | Sample demonstrating vCenter HCL Get HW Compatibility Details Operation
26 | Sample Prerequisites:
27 | vCenter on linux platform
28 | The vCenter should have HCL DataStore(Compatibility Data) Populated
29 | """
30 |
31 | def __init__(self):
32 | parser = sample_cli.build_arg_parser()
33 | parser.add_argument('-id', '--cluster',
34 | required=True,
35 | help='MOID of the source cluster for eg "domain-c92"')
36 | args = sample_util.process_cli_args(parser.parse_args())
37 | self.cluster_id = args.cluster
38 | config = get_configuration(args.server, args.username,
39 | args.password,
40 | args.skipverification)
41 |
42 | self.api_client = Details(config)
43 |
44 | def run(self):
45 | """
46 | Access the HCL Hardware Compatibility Details GET API to get the task id
47 | """
48 | report_info = self.api_client.get(self.cluster_id)
49 | print("Hardware Compatibility Details : ", report_info)
50 | print("Storage Device Details: ", report_info.storage_device_compliance)
51 | print("PCI Device Details : ", report_info.pci_device_compliance)
52 |
53 |
54 | def main():
55 | """
56 | Entry point for the CompatibilityReportSample client
57 | """
58 | detailsSample = HWCompatibilityDetailsSample()
59 | detailsSample.run()
60 |
61 |
62 | if __name__ == '__main__':
63 | main()
64 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vlcm/cluster/installed_images/README.md:
--------------------------------------------------------------------------------
1 | # vLCM/Cluster/Installed_Images
2 |
3 | This directory contains samples of the cluster-level vLCM installed images API
4 |
5 | The installed images API provides a way to easily see the software running on hosts in a given cluster. This API will scan the hosts in the target cluster and generate a report detailing what images are being run. These images are organized into three categories: "highest versioned image", "most widely used image", and "hostImageList" which just contains the rest of the images.
6 |
7 | ## APIs
8 | POST
9 | - The extract POST method triggers the installed images workflow, which is an asynchronous operation. This API returns a task ID which can be used to monitor the progress of the task.
10 |
11 | GET
12 | - This GET method is a synchronous operation and it returns the most recently generated installed images report for the cluster corresponding to the provided MoID.
13 |
14 | ## Running the samples
15 |
16 | To view the available command-line options:
17 |
18 | ```
19 | python samples/vsphere/vcenter/vlcm/cluster/installed_images/installed_images.py -h
20 | ```
21 |
22 | To run the sample:
23 |
24 | ```
25 | $ python samples/vsphere/vcenter/vlcm/cluster/installed_images/installed_images.py -v -s -u -p --cluster
26 | ```
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vlcm/cluster/installed_images/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright (c) 2024 Broadcom. All Rights Reserved.
4 | * Broadcom Confidential. The term "Broadcom" refers to Broadcom Inc.
5 | * and/or its subsidiaries.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | """
9 |
10 | __author__ = 'Broadcom, Inc.'
11 | __copyright__ = 'Copyright 2024 Broadcom, Inc. All rights reserved.'
12 |
13 |
14 | # Required to distribute different parts of this
15 | # package as multiple distribution
16 | try:
17 | import pkg_resources
18 | pkg_resources.declare_namespace(__name__)
19 | except ImportError:
20 | from pkgutil import extend_path
21 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
22 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vm/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for vCenter virtual machine APIs:
2 |
3 | 1. Virtual machine Create, Read and Delete operations:
4 | * Create a virtual machine with system provided defaults - create/create_default_vm.py
5 | * Create a basic virtual machine - create/create_basic_vm.py
6 | * Create a exhaustive virtual machine - create/create_exhaustive_vm.py
7 |
8 | 2. Virtual machine power lifecycle (requires an existing virtual machine):
9 | * Manage virtual machine power state - power.py
10 |
11 | 3. Update virtual machine hardware settings (requires an existing virtual machine):
12 | * Configure virtual SATA adapters of a virtual machine - hardware/adapter/sata.py
13 | * Configure virtual SCSI adapters of a virtual machine - hardware/adapter/scsi.py
14 | * Configure the booting settings for virtual machine - hardware/boot.py
15 | * Configure the boot devices used by a virtual machine - hardware/boot_device.py
16 | * Configure CD-ROM devices for a virtual machine - hardware/cdrom.py
17 | * Configure CPU settings for a virtual machine - hardware/cpu.py
18 | * Configure disk settings for a virtual machine - hardware/disk.py
19 | * Configure virtual ethernet adapters of a virtual machine - hardware/ethernet.py
20 | * Configure Floppy settings for a virtual machine - hardware/floppy.py
21 | * Configure Memory settings of a virtual machine - hardware/memory.py
22 | * Configure Parallel ports for a virtual machine - hardware/parallel.py
23 | * Configure Serial ports for a virtual machine - hardware/serial.py
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vm/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 | # Required to distribute different parts of this
18 | # package as multiple distribution
19 | try:
20 | import pkg_resources
21 | pkg_resources.declare_namespace(__name__)
22 | except ImportError:
23 | from pkgutil import extend_path
24 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
25 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vm/create/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vm/hardware/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vm/hardware/adapter/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2016. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vm/list_vms.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2016. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
18 | __vcenter_version__ = '6.5+'
19 |
20 | from pprint import pprint
21 |
22 | from vmware.vapi.vsphere.client import create_vsphere_client
23 |
24 | from samples.vsphere.common import sample_cli
25 | from samples.vsphere.common import sample_util
26 | from samples.vsphere.common.ssl_helper import get_unverified_session
27 |
28 |
29 | class ListVM(object):
30 | """
31 | Demonstrates getting list of VMs present in vCenter
32 | Sample Prerequisites:
33 | vCenter/ESX
34 | """
35 | def __init__(self):
36 | parser = sample_cli.build_arg_parser()
37 | args = sample_util.process_cli_args(parser.parse_args())
38 | session = get_unverified_session() if args.skipverification else None
39 | self.client = create_vsphere_client(server=args.server,
40 | username=args.username,
41 | password=args.password,
42 | session=session)
43 |
44 | def run(self):
45 | """
46 | List VMs present in server
47 | """
48 | list_of_vms = self.client.vcenter.VM.list()
49 | print("----------------------------")
50 | print("List Of VMs")
51 | print("----------------------------")
52 | pprint(list_of_vms)
53 | print("----------------------------")
54 |
55 |
56 | def main():
57 | list_vm = ListVM()
58 | list_vm.run()
59 |
60 |
61 | if __name__ == '__main__':
62 | main()
63 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vstats/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2020. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2020 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vstats/acquisitionspec/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2020. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2020 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vstats/data/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2020. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2020 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vstats/helpers/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | * *******************************************************
3 | * Copyright VMware, Inc. 2020. All Rights Reserved.
4 | * SPDX-License-Identifier: MIT
5 | * *******************************************************
6 | *
7 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12 | """
13 |
14 | __author__ = 'VMware, Inc.'
15 | __copyright__ = 'Copyright 2020 VMware, Inc. All rights reserved.'
16 |
17 |
18 | # Required to distribute different parts of this
19 | # package as multiple distribution
20 | try:
21 | import pkg_resources
22 | pkg_resources.declare_namespace(__name__)
23 | except ImportError:
24 | from pkgutil import extend_path
25 | __path__ = extend_path(__path__, __name__) # @ReservedAssignment
26 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/vstats/helpers/sample_cli.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | * *******************************************************
4 | * Copyright (c) VMware, Inc. 2020. All Rights Reserved.
5 | * SPDX-License-Identifier: MIT
6 | * *******************************************************
7 | *
8 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13 | """
14 |
15 | __author__ = 'VMware, Inc.'
16 | __vcenter_version__ = '7.0+'
17 |
18 | from samples.vsphere.common.sample_cli import build_arg_parser
19 |
20 | """
21 | Builds a standard argument parser with required and optional argument groups
22 | Most of the Vsphere Stats samples require these three standard required
23 | arguments.
24 | --expiration
25 | --interval
26 | """
27 | parser = build_arg_parser()
28 |
29 | required_args = parser.add_argument_group(
30 | 'required arguments for creating acquisition spec')
31 |
32 | required_args.add_argument(
33 | '--expiration',
34 | required=True,
35 | help='Create an Acquisition Specification with expiration time.' +
36 | ' Example: 10000000000')
37 |
38 | required_args.add_argument(
39 | '--interval',
40 | required=True,
41 | help='Create an Acquisition Specification with interval. Example: 10')
42 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/wcp/README.md:
--------------------------------------------------------------------------------
1 | This directory contains samples for WCP service APIs:
2 |
3 | * Enable supervisor on zones
4 | * Get/List of supervisor's summary
5 |
6 | Running the samples
7 |
8 | $ python /.py --server --username --password
9 |
10 | * Testbed Requirement:
11 | - 1 vCenter Server >= 8.0.0+
12 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/wcp/get_supervisor_summary.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2022. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __copyright__ = 'Copyright 2022 VMware, Inc. All rights reserved.'
18 | __vcenter_version__ = '8.0.0+'
19 |
20 | from com.vmware.vcenter.namespace_management.supervisors_client import Summary
21 | from samples.vsphere.common import sample_cli
22 | from samples.vsphere.common import sample_util
23 | from samples.vsphere.common.ssl_helper import get_unverified_session
24 | from samples.vsphere.vcenter.hcl.utils import get_configuration
25 |
26 |
27 | class GetSupervisorsSummary(object):
28 | """
29 | Demonstrates looking up a Supervisor Summary on a given Supervisor Cluster.
30 | """
31 |
32 | def __init__(self):
33 | parser = sample_cli.build_arg_parser()
34 | parser.add_argument('--supervisor',
35 | required=True,
36 | help='The MoID of the Supervisor to query.')
37 |
38 | args = sample_util.process_cli_args(parser.parse_args())
39 | session = get_unverified_session() if args.skipverification else None
40 | stub_config = get_configuration(
41 | args.server, args.username, args.password,
42 | session)
43 | self.supervisor_summary = Summary(stub_config)
44 | self.supervisor = args.supervisor
45 |
46 | def run(self):
47 | """
48 | Get Supervisor Summary on vCenter Server.
49 | """
50 | summary = self.supervisor_summary.get(self.supervisor)
51 | print('name: {0}'.format(summary.name))
52 | print('config_status: {0}'.format(summary.config_status))
53 | print('kubernetes_status: {0}'.format(summary.kubernetes_status))
54 | print('stats: {0}\n'.format(summary.stats))
55 |
56 |
57 | def main():
58 | list_cl = GetSupervisorsSummary()
59 | list_cl.run()
60 |
61 |
62 | if __name__ == '__main__':
63 | main()
64 |
--------------------------------------------------------------------------------
/samples/vsphere/vcenter/wcp/list_supervisor_summary.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | * *******************************************************
5 | * Copyright (c) VMware, Inc. 2022. All Rights Reserved.
6 | * SPDX-License-Identifier: MIT
7 | * *******************************************************
8 | *
9 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14 | """
15 |
16 | __author__ = 'VMware, Inc.'
17 | __copyright__ = 'Copyright 2022 VMware, Inc. All rights reserved.'
18 | __vcenter_version__ = '8.0.0+'
19 |
20 | from com.vmware.vcenter.namespace_management.supervisors_client import \
21 | Summary
22 |
23 | from samples.vsphere.common import sample_cli
24 | from samples.vsphere.common import sample_util
25 | from samples.vsphere.common.ssl_helper import get_unverified_session
26 | from samples.vsphere.vcenter.hcl.utils import get_configuration
27 |
28 |
29 | class ListClusterSupervisorServices(object):
30 | """
31 | Demonstrates looking up a list of Supervisor Summary.
32 | """
33 | def __init__(self):
34 | parser = sample_cli.build_arg_parser()
35 | args = sample_util.process_cli_args(parser.parse_args())
36 | session = get_unverified_session() if args.skipverification else None
37 | stub_config = get_configuration(
38 | args.server, args.username, args.password,
39 | session)
40 | self.supervisor_summary = Summary(stub_config)
41 |
42 | def run(self):
43 | """
44 | List Supervisor Summary on vCenter Server.
45 | """
46 | summaries = self.supervisor_summary.list()
47 | print('items:')
48 | for s in summaries.items:
49 | print('- supervisor: {0}'.format(s.supervisor))
50 | print(' info:')
51 | print(' name: {0}'.format(s.info.name))
52 | print(' config_status: {0}'.format(s.info.config_status))
53 | print(' kubernetes_status: {0}'.format(s.info.kubernetes_status))
54 | print(' stats: {0}\n'.format(s.info.stats))
55 |
56 |
57 | def main():
58 | list_cl = ListClusterSupervisorServices()
59 | list_cl.run()
60 |
61 |
62 | if __name__ == '__main__':
63 | main()
64 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [pycodestyle]
2 | ignore = E402, E501, E122, E126, E127, E128, E129, E131, W503, W504, E721
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import os
4 |
5 | from setuptools import setup
6 |
7 | setup(name='vsphere-automation-sdk',
8 | version='1.87.0',
9 | description='VMware vSphere Automation SDK for Python',
10 | url='https://github.com/vmware/vsphere-automation-sdk-python',
11 | author='Broadcom, Inc.',
12 | license='MIT',
13 | packages=[],
14 | install_requires=[
15 | 'lxml >= 4.3.0',
16 | 'pyVmomi == 8.0.3.0.1',
17 | 'vmware-vapi-runtime == 2.52.0',
18 | 'vmware-vcenter == 8.0.3.0',
19 | 'vmware-vapi-common-client == 2.52.0',
20 | 'vmwarecloud-aws @ file://localhost/{}/lib/vmwarecloud-aws/vmwarecloud_aws-1.64.1-py2.py3-none-any.whl'.format(os.getcwd()),
21 | 'nsx-python-sdk @ file://localhost/{}/lib/nsx-python-sdk/nsx_python_sdk-4.2.0-py2.py3-none-any.whl'.format(os.getcwd()),
22 | 'nsx-policy-python-sdk @ file://localhost/{}/lib/nsx-policy-python-sdk/nsx_policy_python_sdk-4.2.0-py2.py3-none-any.whl'.format(os.getcwd()),
23 | 'nsx-vmc-policy-python-sdk @ file://localhost/{}/lib/nsx-vmc-policy-python-sdk/nsx_vmc_policy_python_sdk-4.1.2.0.1-py2.py3-none-any.whl'.format(os.getcwd()),
24 | 'nsx-vmc-aws-integration-python-sdk @ file://localhost/{}/lib/nsx-vmc-aws-integration-python-sdk/nsx_vmc_aws_integration_python_sdk-4.1.2.0.1-py2.py3-none-any.whl'.format(os.getcwd()),
25 | 'vmwarecloud-draas @ file://localhost/{}/lib/vmwarecloud-draas/vmwarecloud_draas-1.23.1-py2.py3-none-any.whl'.format(os.getcwd()),
26 | ]
27 | )
28 |
--------------------------------------------------------------------------------
/test-requirements.txt:
--------------------------------------------------------------------------------
1 | pytest==3.9.1
2 | pycodestyle
3 | pexpect
4 | asn1crypto
5 | setuptools>=62.3.2
6 |
--------------------------------------------------------------------------------
/tests/test_vmc_client.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | * *******************************************************
4 | * Copyright (c) VMware, Inc. 2019. All Rights Reserved.
5 | * SPDX-License-Identifier: MIT
6 | * *******************************************************
7 | *
8 | * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9 | * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10 | * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11 | * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12 | * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13 | """
14 |
15 | __author__ = 'VMware, Inc.'
16 |
17 | from vmware.vapi.vmc.client import create_vmc_client
18 | from vmware.vapi.bindings.stub import ApiClient, StubFactoryBase
19 |
20 | client = create_vmc_client('1234')
21 |
22 |
23 | def test_orgs_client():
24 | assert hasattr(client, 'Orgs')
25 |
26 |
27 | def test_locale_client():
28 | assert hasattr(client, 'Locale')
29 |
30 |
31 | def test_account_link_client():
32 | assert hasattr(client.orgs, 'AccountLink')
33 | assert hasattr(client.orgs, 'account_link')
34 | assert isinstance(client.orgs.account_link, StubFactoryBase)
35 |
36 |
37 | def test_providers_client():
38 | assert hasattr(client.orgs, 'Providers')
39 |
40 |
41 | def test_reservations_client():
42 | assert hasattr(client.orgs, 'Reservations')
43 | assert hasattr(client.orgs, 'reservations')
44 | assert isinstance(client.orgs.reservations, StubFactoryBase)
45 |
46 |
47 | def test_sddcs_client():
48 | assert hasattr(client.orgs, 'Sddcs')
49 | assert hasattr(client.orgs, 'sddcs')
50 | assert isinstance(client.orgs.sddcs, StubFactoryBase)
51 |
52 |
53 | def test_sddcTemplates_client():
54 | assert hasattr(client.orgs, 'SddcTemplates')
55 |
56 |
57 | def test_storage_client():
58 | assert hasattr(client.orgs, 'storage')
59 | assert isinstance(client.orgs.storage, StubFactoryBase)
60 |
61 |
62 | def test_subscriptions_client():
63 | assert hasattr(client.orgs, 'Subscriptions')
64 | assert hasattr(client.orgs, 'subscriptions')
65 | assert isinstance(client.orgs.subscriptions, StubFactoryBase)
66 |
67 |
68 | def test_tbrs_client():
69 | assert hasattr(client.orgs, 'tbrs')
70 | assert isinstance(client.orgs.tbrs, StubFactoryBase)
71 |
72 |
73 | def test_tasks_client():
74 | assert hasattr(client.orgs, 'Tasks')
75 |
--------------------------------------------------------------------------------