diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 52d35b1f..00000000
--- a/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-*.py[cod]
-__pycache__/
-.DS_Store
-.idea/*
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 72b09a0b..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-language: python
-python:
- - "2.7.13"
- - "3.6"
-# command to install dependencies
-install:
- - pip install -r requirements.txt --upgrade --ignore-installed six
- - pip install -r test-requirements.txt
- - pip install pycodestyle
-# command to run tests
-script: pycodestyle samples/*
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index af03d9ce..00000000
--- a/LICENSE
+++ /dev/null
@@ -1,9 +0,0 @@
-The MIT License
-
-Copyright 2017 VMware Inc.
-
-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:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-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.
diff --git a/README.md b/README.md
index 07b5056a..aa39b774 100644
--- a/README.md
+++ b/README.md
@@ -1,212 +1,37 @@
-# VMware vSphere Automation SDK for Python
-[![Build Status](https://travis-ci.com/vmware/vsphere-automation-sdk-python.svg?token=v9mEJjcpDiQ9DrYbzyaQ&branch=master)](https://travis-ci.com/vmware/vsphere-automation-sdk-python)
-## Table of Contents
-- [Abstract](#abstract)
-- [Quick Start Guide](#quick-start-guide)
- - [Installing the required Python Packages](#installing-the-required-python-packages)
- - [Setting up a vSphere Test Environment](#setting-up-a-vsphere-test-environment)
- - [Running the SDK Sample Setup Script](#running-the-sdk-sample-setup-script)
- - [Running a complex sample](#running-a-complex-sample)
-- [API Documentation](#api-documentation)
-- [Submitting samples](#submitting-samples)
- - [Required Information](#required-information)
- - [Suggested Information](#suggested-information)
- - [Contribution Process](#contribution-process)
- - [Code Style](#code-style)
-- [Resource Maintenance](#resource-maintenance)
- - [Maintenance Ownership](#maintenance-ownership)
- - [Filing Issues](#filing-issues)
- - [Resolving Issues](#resolving-issues)
- - [VMware Sample Exchange](#vmware-sample-exchange)
-- [Repository Administrator Resources](#repository-administrator-resources)
- - [Board Members](#board-members)
- - [Approval of Additions](#approval-of-additions)
-- [VMware Resources](#vmware-resources)
-## Abstract
-This document describes the vSphere Automation Python SDK samples that use the vSphere Automation
-python client library. Additionally, some of the samples demonstrate the combined use of the
-vSphere Automation and vSphere APIs. To support this combined use, the vSphere Automation Python SDK
-samples require the vSphere Management SDK packages (pyVmomi) to be installed on the client.
-The samples have been developed to work with python 2.7.x and 3.3+
+# VMTN6720U - Hackathon Training: Getting started with the vSphere Automation SDK for Python
+**Date:** 08/28/17 6:30PM-8:00PM
-## Supported vCenter Releases:
-vCenter 6.0 and 6.5.
-Certain APIs and samples that are introduced in 6.5 release, such as vCenter, Virtual Machine and Appliance Management. Please refer to the notes in each sample for detailed compatibility information.
+# Agenda
+* Introduction to vSphere REST API
+* vSphere Automation SDKs
+* Getting Started Using the Python SDK
+* Lab
-## Quick Start Guide
-This document will walk you through getting up and running with the Python SDK Samples.
-Prior to running the samples you will need to setup a vCenter test environment and
-install local Python packages, the following steps will take you through this process.
+# Introduction to vSphere REST API
+* Consume from SDKs, CLI’s
+* NOTE: Need bullets from Alan
-Before you can run the SDK samples we'll need to walk you through the following steps:
+# vSphere Automation SDKs
+* Supported Languages
+ * Python, Java, Ruby, Perl, .NET, REST (JavaScript/Postman)
+* Open Source on Github
+ * SDK Includes:
+ * Runtime
+ * Serialization
+ * Language Binding
+ * Python Wrapper around REST API
+ * API Reference Documentation (for offline usage)
-1. Installing the required Python packages
-2. Installing SDK provided packages
-3. Setting up a vSphere test environment
-4. Running SDK Samples setup script
+# [Labs](lab.md)
-### Installing the required Python Packages
-**Note:** The SDK requires Python v2.7+ (preferably v3.6) to run the setup/samples,
-please make sure you have the appropriate version installed before continuing.
-If you are on macOS/OSX/Linux, please note that the system installed version of
-Python may be outdated and/or not be intended for development and we recommended you [install Python](http://docs.python-guide.org/en/latest/starting/installation/) yourself before installing the required packages. [Virtualenv](https://virtualenv.pypa.io/en/stable/) is also highly recommended.
+**Wifi**: VMworld-Hackathon-Training-4
+**Wifi Password**: Hackathon2017
-The required packages are listed in the requirements.txt file and installed using "pip install"; For more details on how to install python packages using pip please refer to the [pip user guide](http://pip.readthedocs.io/en/latest/user_guide/).
+Connect to VC matching first letter of your last name (poorman’s load balance):
-```cmd
-pip install -r requirements.txt
-```
+**VC1**: [192.168.104.11](https://192.168.104.11) (A-H)
+**VC2**: [192.168.104.13](https://192.168.104.13) (I-Q)
+**VC3**: [192.168.104.13](https://192.168.104.13) (R-Z)
-### Setting up a vSphere Test Environment
-**NOTE:** The samples are intended to be run against a freshly installed **non-Production** vSphere setup as the scripts may make changes to the test environment and in some cases can destroy items when needed.
-
-To run the samples a vSphere test environment is required with the following configuration
-* 1 vCenter Server
-* 2 ESX hosts
-* 1 NFS Datastore with at least 3GB of free capacity
-
-Please have the details of these available but do not have any configuration pre-created on vCenter server or ESXi Hosts, for example there should be no existing datacenters, clusters or attached hosts on the vCenter server.
-
-### Running the SDK Sample Setup Script
-Before executing the samples we'll need to setup the vSphere test environment using one of the sample scripts. Before we run the script we'll need to edit one of the files and provide IP addresses for the various machine instances.
-
-First, set PYTHONPATH to use SDK helper methods
-
-* Linux/Mac:
-
- export PYTHONPATH=${PWD}:$PYTHONPATH
-
-* Windows:
-
- set PYTHONPATH=%cd%;%PYTHONPATH%
-
-Next, using a text editor open ../samples/vsphere/vcenter/setup/testbed.py and edit the following settings replace everything in < > brackets with your environment information. Leave the rest of the settings in this file at their default values.
-
-```python
-config["SERVER"] = ""
-config["USERNAME"] = ""
-config["PASSWORD"] = ""
-
-config["ESX_HOST1"] = ""
-config["ESX_HOST2"] = ""
-config["ESX_USER"] = ""
-config["ESX_PASS"] = ""
-
-config["USE_NFS"] = True
-config["NFS_HOST"] = ""
-config["NFS_REMOTE_PATH"] = "/store1"
-```
-
-Save and close the file.
-
-At this point, we're ready to run the setup script.
-
-This script will perform the following:
-* Create 2 test Datacenters
-* Create a test Cluster
-* Create Test Folders for VM Storage
-* Attach the hosts
-* Create a Distributed Switch
-* Create a Distributed Portgroup
-* Attach the NFS datastore (if Selected) to the hosts
-* Copy the [Photon OS](https://vmware.github.io/photon/) ISO image downloaded from [VMware's bintray server](https://dl.bintray.com/vmware/photon) to the datastore
-* Create directories to add sample ports
-
-
-**Note:** The setup script may take several minutes to complete.
-
-**To view the available command-line options:**
-
-```cmd
-$ python ../samples/vsphere/vcenter/setup/main.py -h
-```
-
-**To run the setup script:**
-
-```cmd
-$ python ../samples/vsphere/vcenter/setup/main.py -sv
-```
-
-After completion you will see from the output and also the vSphere Webclient that the environment has now been fully setup and is ready to easily run further samples.
-
-### Running a complex sample
-This SDK includes a sample script which can be used to perform a number of actions and give you an indication of how to perform multiple vCenter actions, this script is located in the /samples/vsphere/vcenter/setup/ directory, use the following instructions to run this sample:
-
-**Run the vAPI vCenter sample suite:**
-
-```cmd
-$ python ../samples/vsphere/vcenter/setup/main.py -riv
-```
-
-## API Documentation
-The API documentation can be found [here](doc/client.zip)
-
-## Submitting samples
-
-### Developer Certificate of Origin
-
-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.
-
-### Sample Template
-[Sample template](sample_template) contains boilerplate code that can be used to build a new sample.
-Please copy the file and use it as a starting point to write a new sample.
-
-### Required Information
-The following information must be included in the README.md or in the sample docstring in case README already exists in same folder.
-* Author Name
- * This can include full name, email address or other identifiable piece of information that would allow interested parties to contact author with questions.
-* Minimal/High Level Description
- * What does the sample do ?
-* Any KNOWN limitations or dependencies
-
-### Suggested Information
-The following information should be included when possible. Inclusion of information provides valuable information to consumers of the resource.
-* vSphere version against which the sample was developed/tested
-* SDK version against which the sample was developed/tested
-* Python version against which the sample was developed/tested
-
-### Contribution Process
-
-* Follow the [GitHub process](https://help.github.com/articles/fork-a-repo)
- * Please use one branch per sample or change-set
- * Please use one commit and pull request per sample
- * Please post the sample output along with the pull request
- * If you include a license with your sample, use the project license
-
-### Code Style
-
-Please conform to pep8 standards. Check your code by running the pep8 tool.
- https://pypi.python.org/pypi/pep8
-
-## Resource Maintenance
-### Maintenance Ownership
-Ownership of any and all submitted samples are maintained by the submitter.
-### Filing Issues
-Any bugs or other issues should be filed within GitHub by way of the repository’s Issue Tracker.
-### Resolving Issues
-Any community member can resolve issues within the repository, however only the board member can approve the update. Once approved, assuming the resolution involves a pull request, only a board member will be able to merge and close the request.
-
-### VMware Sample Exchange
-It is highly recommended to add any and all submitted samples to the VMware Sample Exchange:
-
-Sample Exchange can be allowed to access your GitHub resources, by way of a linking process, where they can be indexed and searched by the community. There are VMware social media accounts which will advertise resources posted to the site and there's no additional accounts needed, as the VMware Sample Exchange uses MyVMware credentials.
-
-## Repository Administrator Resources
-### Board Members
-
-Board members are volunteers from the SDK community and VMware staff members, board members are not held responsible for any issues which may occur from running of samples from this repository.
-
-Members:
-* Tianhao He (VMware)
-* Steve Trefethen (VMware)
-
-### Approval of Additions
-Items added to the repository, including items from the Board members, require 2 votes from the board members before being added to the repository. The approving members will have ideally downloaded and tested the item. When two “Approved for Merge” comments are added from board members, the pull can then be committed to the repository.
-
-## VMware Resources
-
-* [vSphere Automation SDK Overview](http://pubs.vmware.com/vsphere-65/index.jsp#com.vmware.vapi.progguide.doc/GUID-AF73991C-FC1C-47DF-8362-184B6544CFDE.html)
-* [VMware Code](https://code.vmware.com/home)
-* [VMware Developer Community](https://communities.vmware.com/community/vmtn/developer)
-* VMware vSphere [REST API Reference documentation](https://vdc-repo.vmware.com/vmwb-repository/dcr-public/1cd28284-3b72-4885-9e31-d1c6d9e26686/9a0dbc46-b15f-47cd-af1d-dc64615b03df/doc/index.html).
-* [VMware Python forum](https://code.vmware.com/forums/7508/vsphere-automation-sdk-for-python)
+**VC Username**: administrator@vsphere.local
+**VC Password**: VMware1!
diff --git a/vmworld2017/_config.yml b/_config.yml
similarity index 100%
rename from vmworld2017/_config.yml
rename to _config.yml
diff --git a/doc/client.zip b/doc/client.zip
deleted file mode 100644
index c68efe32..00000000
Binary files a/doc/client.zip and /dev/null differ
diff --git a/vmworld2017/lab.md b/lab.md
similarity index 100%
rename from vmworld2017/lab.md
rename to lab.md
diff --git a/lib/README.md b/lib/README.md
deleted file mode 100644
index 6d79598a..00000000
--- a/lib/README.md
+++ /dev/null
@@ -1,9 +0,0 @@
-# SDK libraries
-
-For python developers, client libraries are supplied for testing and development purposes. All the supplied libraries are located under lib directory.
-
-Name | Description
-------------------------------------| -------------
-vapi_runtime-\.zip | vAPI runtime responsible for serialization/de-serialization of objects and wire protocol
-vapi_common_client-\.zip | vAPI common client code
-vapi_client_bindings-\.zip | client stubs for vSphere Automation APIs
diff --git a/lib/vapi_client_bindings-2.5.0.zip b/lib/vapi_client_bindings-2.5.0.zip
deleted file mode 100644
index 01f6508b..00000000
Binary files a/lib/vapi_client_bindings-2.5.0.zip and /dev/null differ
diff --git a/lib/vapi_common_client-2.5.0.zip b/lib/vapi_common_client-2.5.0.zip
deleted file mode 100644
index fabafd1e..00000000
Binary files a/lib/vapi_common_client-2.5.0.zip and /dev/null differ
diff --git a/lib/vapi_runtime-2.5.0.zip b/lib/vapi_runtime-2.5.0.zip
deleted file mode 100644
index 412eee5b..00000000
Binary files a/lib/vapi_runtime-2.5.0.zip and /dev/null differ
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index fdb964fd..00000000
--- a/requirements.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-pyOpenSSL >= 0.14
-pyVmomi >= 6.5
-lxml
-suds ; python_version < '3'
-suds-jurko ; python_version >= '3.0'
-lib/vapi_runtime-2.5.0.zip
-lib/vapi_common_client-2.5.0.zip
-lib/vapi_client_bindings-2.5.0.zip
diff --git a/sample_template/README.md b/sample_template/README.md
deleted file mode 100644
index cd96a9c7..00000000
--- a/sample_template/README.md
+++ /dev/null
@@ -1,12 +0,0 @@
-Boilerplate code for new samples
-================================
-
-sample_template.py contains boilerplate code that can be used for most of
-the new samples. Please fill out the TODOs with your sample information.
-The steps included in the template code are:
-
- * Cmd line argument parser.
- * Login to vAPI services using vSphere Automation API.
- * Login to Vim service using [pyVmomi](https://github.com/vmware/pyvmomi).
- * Cleanup after sample execution.
- * Logout from both services.
\ No newline at end of file
diff --git a/sample_template/__init__.py b/sample_template/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/sample_template/sample_template.py b/sample_template/sample_template.py
deleted file mode 100644
index 0bb6a710..00000000
--- a/sample_template/sample_template.py
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'TODO: '
-__vcenter_version__ = 'TODO: '
-
-import atexit
-
-from com.vmware.vcenter_client import VM
-from samples.vsphere.common import sample_cli
-from samples.vsphere.common import sample_util
-from samples.vsphere.common.service_manager import ServiceManager
-
-
-class Sample(object):
- """
- TODO: Sample description and prerequisites.
- e.g. Demonstrates getting list of VMs present in vCenter
-
- Sample Prerequisites:
- - vCenter
- """
-
- def __init__(self):
- self.service_manager = None
- self.vm_name = None
- self.cleardata = None
-
- def setup(self):
- # Create argument parser for standard inputs:
- # server, username, password, cleanup and skipverification
- parser = sample_cli.build_arg_parser()
-
- # Add your custom input arguments
- parser.add_argument('-n', '--vm_name',
- action='store',
- default='Sample_Default_VM_for_Simple_Testbed',
- help='Name of the testing vm')
-
- args = sample_util.process_cli_args(parser.parse_args())
- self.vm_name = args.vm_name
- self.cleardata = args.cleardata
-
- # Connect to both Vim and vAPI services
- self.service_manager = ServiceManager(args.server,
- args.username,
- args.password,
- args.skipverification)
- self.service_manager.connect()
- atexit.register(self.service_manager.disconnect)
-
- def run(self):
- # TODO add your sample code here
-
- # Using REST API service
- vm_service = VM(self.service_manager.stub_config)
- filter_spec = VM.FilterSpec(names=set([self.vm_name]))
- vms = vm_service.list(filter_spec)
- print(vms)
-
- # Using Vim API service (pyVmomi)
- current_time = self.service_manager.si.CurrentTime()
- print(current_time)
-
- def cleanup(self):
- if self.cleardata:
- # TODO add cleanup code
- pass
-
-
-def main():
- sample = Sample()
- sample.setup()
- sample.run()
- sample.cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/__init__.py b/samples/__init__.py
deleted file mode 100644
index 42b8a50b..00000000
--- a/samples/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/README.md b/samples/vsphere/README.md
deleted file mode 100644
index 8d01a4dc..00000000
--- a/samples/vsphere/README.md
+++ /dev/null
@@ -1,11 +0,0 @@
-#Client Samples
-
-The following table shows the sample sub-directories and their contents.
-
-Directory | Description
-----------------| -------------
-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
-contentlibrary | Samples for Content Library APIs
-tagging | Samples for Tagging APIs
-vcenter | Samples for managing vSphere infrastructure and virtual machines
-sso | Samples for Platform Service Controller(PSC), SSO and Lookup Service APIs
diff --git a/samples/vsphere/__init__.py b/samples/vsphere/__init__.py
deleted file mode 100644
index 42b8a50b..00000000
--- a/samples/vsphere/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/common/__init__.py b/samples/vsphere/common/__init__.py
deleted file mode 100644
index 59b403a2..00000000
--- a/samples/vsphere/common/__init__.py
+++ /dev/null
@@ -1,10 +0,0 @@
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
-
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
-
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/common/connect_with_cert.py b/samples/vsphere/common/connect_with_cert.py
deleted file mode 100644
index 187efe30..00000000
--- a/samples/vsphere/common/connect_with_cert.py
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-import atexit
-from com.vmware.cis.tagging_client import (Category, CategoryModel)
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import process_cli_args
-from samples.vsphere.common.sample_cli import build_arg_parser
-
-
-class CertConnect(object):
- """
- Demonstrates how to Connect to vCenter vAPI service with
- with Valid Cert
- """
-
- def __init__(self):
- self.server = None
- self.username = None
- self.password = None
- self.stub_config = None
- self.cleardata = None
- self.skip_verification = False
- self.cert_path = None
- self.category_svc = None
- self.category_id = None
-
- def setup(self):
- parser = build_arg_parser()
- parser.add_argument('-cpath', '--cert_path',
- action='store',
- help='path to a CA_BUNDLE file or directory with certificates of trusted CAs')
- args = parser.parse_args()
-
- self.server, self.username, self.password, self.cleardata, self.skip_verification = \
- process_cli_args(args)
-
- if args.cert_path:
- self.cert_path = args.cert_path
-
- def run(self):
- print('\n\n#### Example: Login to vCenter server with '
- 'Valid Cert Verification')
- # Connect to VAPI
- self.stub_config = vapiconnect.connect(self.server, self.username, self.password,
- self.skip_verification,
- cert_path=self.cert_path)
- atexit.register(vapiconnect.logout, self.stub_config)
-
- # Create and Delete TagCategory to Verify connection is successful
- print('\nStep 3: Creating and Deleting Tag Category...\n')
- self.category_svc = Category(self.stub_config)
-
- self.category_id = self.create_tag_category('TestTagCat', 'TestTagDesc',
- CategoryModel.Cardinality.MULTIPLE)
- assert self.category_id is not None
- print('Tag category created; Id: {0}\n'.format(self.category_id))
-
- # Delete TagCategory
- self.category_svc.delete(self.category_id)
-
- print('VAPI session disconnected successfully...')
-
- def create_tag_category(self, name, description, cardinality):
- """create a category. User who invokes this needs create category privilege."""
- create_spec = self.category_svc.CreateSpec()
- create_spec.name = name
- create_spec.description = description
- create_spec.cardinality = cardinality
- associableTypes = set()
- create_spec.associable_types = associableTypes
- return self.category_svc.create(create_spec)
-
-
-def main():
- connect_with_cert = CertConnect()
- connect_with_cert.setup()
- connect_with_cert.run()
-
-
-# Start program
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/common/id_generator.py b/samples/vsphere/common/id_generator.py
deleted file mode 100644
index b2c71430..00000000
--- a/samples/vsphere/common/id_generator.py
+++ /dev/null
@@ -1,43 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2013. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2013 VMware, Inc. All rights reserved.'
-
-
-import uuid
-import string
-import random
-
-
-def generate_random_uuid():
- return str(uuid.uuid4())
-
-
-def rand(value):
- return value + generate_random_string(5)
-
-
-def generate_random_string(length):
- return ''.join(random.choice(string.ascii_uppercase) for _i in range(length))
-
-
-def main():
- print(generate_random_uuid())
- print(generate_random_string(5))
- print(rand('Simple VM-'))
-
-
-# Start program
-if __name__ == "__main__":
- main()
diff --git a/samples/vsphere/common/lookup_service_helper.py b/samples/vsphere/common/lookup_service_helper.py
deleted file mode 100644
index fe3b3d2f..00000000
--- a/samples/vsphere/common/lookup_service_helper.py
+++ /dev/null
@@ -1,363 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2013. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2013 VMware, Inc. All rights reserved.'
-
-import os
-from suds.client import Client
-
-
-class LookupServiceHelper(object):
- def __init__(self, wsdl_url, soap_url, skip_verification):
- self.wsdl_url = wsdl_url
- self.soap_url = soap_url
- self.skip_verification = skip_verification
- self.client = None
- self.managedObjectReference = None
- self.serviceRegistration = None
-
- def connect(self):
- if self.client is None:
- # Suds library doesn't support passing unverified context to disable
- # server certificate verification. Thus disable checking globally in
- # order to skip verification. This is not recommended in production
- # code. see https://www.python.org/dev/peps/pep-0476/
- if self.skip_verification:
- import ssl
- try:
- _create_unverified_https_context = \
- ssl._create_unverified_context
- except AttributeError:
- # Legacy Python that doesn't verify HTTPS certificates by
- # default
- pass
- else:
- # Handle target environment that doesn't support HTTPS
- # verification
- ssl._create_default_https_context = \
- _create_unverified_https_context
-
- self.client = Client(url=self.wsdl_url, location=self.soap_url)
- assert self.client is not None
- self.client.set_options(service='LsService', port='LsPort')
-
- self.managedObjectReference = self.client.factory.create(
- 'ns0:ManagedObjectReference')
- self.managedObjectReference._type = 'LookupServiceInstance'
- self.managedObjectReference.value = 'ServiceInstance'
-
- lookupServiceContent = self.client.service.RetrieveServiceContent(
- self.managedObjectReference)
-
- self.serviceRegistration = lookupServiceContent.serviceRegistration
-
- def find_sso_urls(self):
- """
- Finds all the SSO service URLs.
- In an MxN setup where there are more than one infrastructure node; This method returns more than one URL.
-
- :rtype: list
- :return: list of SSO Service endpoint URLs
- """
- return self.__find_platform_service_urls(product='com.vmware.cis',
- service='cs.identity',
- endpoint='com.vmware.cis.cs.identity.sso',
- protocol='wsTrust')
-
- def find_sso_url(self):
- """
- Finds the SSO service URL.
- In an MxN setup where there are more than one infrastructure node; This method returns the first SSO service endpoint URL
- as returned by the lookup service.
-
- :rtype: :class:`str`
- :return: SSO Service endpoint URL
- """
- result = self.__find_platform_service_urls(product='com.vmware.cis',
- service='cs.identity',
- endpoint='com.vmware.cis.cs.identity.sso',
- protocol='wsTrust')
- return result[0]
-
- def find_vapi_urls(self):
- """
- Finds all the vAPI service endpoint URLs.
- In an MxN setup where there are more than one management node; this method returns more than one URL.
-
- :rtype: dictionary
- :return: vapi service endpoint URLs in a dictionary where the key is the node_id and the value is the service URL
- """
- return self.__find_service_urls(product='com.vmware.cis',
- service='cs.vapi',
- endpoint='com.vmware.vapi.endpoint',
- protocol='vapi.json.https.public')
-
- def find_vapi_url(self, node_id):
- """
- Finds the vapi service endpoint URL of a management node
-
- :type: :class:`str`
- :param node_id: The UUID of the management node
- :rtype: :class:`str`
- :return: vapi service endpoint URL of a management node or, None if no vapi endpoint is found
- """
- assert node_id is not None
- result = self.__find_service_urls(product='com.vmware.cis',
- service='cs.vapi',
- endpoint='com.vmware.vapi.endpoint',
- protocol='vapi.json.https.public')
- assert result is not None
- return result.get(node_id)
-
- def find_vim_urls(self):
- """
- Finds all the vim service endpoint URLs.
- In an MxN setup where there are more than one management node; this method returns more than one URL.
-
- :rtype: dictionary
- :return: vim service endpoint URLs in a dictionary where the key is the node_id and the value is the service URL
- """
- return self.__find_service_urls(product='com.vmware.cis',
- service='vcenterserver',
- endpoint='com.vmware.vim',
- protocol='vmomi')
-
- def find_vim_url(self, node_id):
- """
- Finds the vim service endpoint URL of a management node
-
- :type: :class:`str`
- :param node_id: The UUID of the management node
- :rtype: :class:`str`
- :return: vim service endpoint URL of a management node or, None if no vim endpoint is found
- """
- assert node_id is not None
- result = self.__find_service_urls(product='com.vmware.cis',
- service='vcenterserver',
- endpoint='com.vmware.vim',
- protocol='vmomi')
- assert result is not None
- return result.get(node_id)
-
- def find_vim_pbm_urls(self):
- """
- Finds all the spbm service endpoint URLs.
- In an MxN setup where there are more than one management node; this method returns more than one URL.
-
- :rtype: dictionary
- :return: spbm service endpoint URLs in a dictionary where the key is the node_id and the value is the service URL
- """
- return self.__find_service_urls(product='com.vmware.vim.sms',
- service='sms',
- endpoint='com.vmware.vim.pbm',
- protocol='https')
-
- def find_vim_pbm_url(self, node_id):
- """
- Finds the spbm service endpoint URL of a management node
-
- :type: :class:`str`
- :param node_id: The UUID of the management node
- :rtype: :class:`str`
- :return: spbm service endpoint URL of a management node or, None if no spbm endpoint is found
- """
- assert node_id is not None
- result = self.__find_service_urls(product='com.vmware.vim.sms',
- service='sms',
- endpoint='com.vmware.vim.pbm',
- protocol='https')
- assert result is not None
- return result.get(node_id)
-
- def __find_service_urls(self, product, service, endpoint, protocol):
- """
- Finds the endpoint URLs of a service running on management nodes.
- Returns a dictionary where the key is the management node id.
- """
- assert self.client is not None
- assert self.serviceRegistration is not None
-
- lookupServiceRegistrationFilter = self.__create_filter_spec(product,
- service,
- endpoint,
- protocol)
-
- result = self.client.service.List(self.serviceRegistration,
- lookupServiceRegistrationFilter)
- assert len(result) > 0
- # Support for MxN
- # return the results in a dictionary where key is NodeId and Value is Service URL
- results_dict = {}
- for lookupServiceRegistrationInfo in result:
- lookupServiceRegistrationEndpoint = \
- lookupServiceRegistrationInfo.serviceEndpoints[0]
- assert lookupServiceRegistrationEndpoint is not None
- results_dict[
- lookupServiceRegistrationInfo.nodeId] = lookupServiceRegistrationEndpoint.url
- return results_dict
-
- def __find_platform_service_urls(self, product, service, endpoint,
- protocol):
- """
- Finds the endpoint URLs of a service running on PSCs (Platform Service Controller).
- Returns a list of service URLs since there is no node id associated with the PSC.
- """
- assert self.client is not None
- assert self.serviceRegistration is not None
-
- lookupServiceRegistrationFilter = self.__create_filter_spec(product,
- service,
- endpoint,
- protocol)
-
- result = self.client.service.List(self.serviceRegistration,
- lookupServiceRegistrationFilter)
- assert len(result) > 0
-
- urls = []
- for lookupServiceRegistrationInfo in result:
- lookupServiceRegistrationEndpoint = \
- lookupServiceRegistrationInfo.serviceEndpoints[0]
- assert lookupServiceRegistrationEndpoint is not None
- urls.append(lookupServiceRegistrationEndpoint.url)
- return urls
-
- def __create_filter_spec(self, product, service, endpoint, protocol):
- assert self.client is not None
-
- lookupServiceRegistrationServiceType = self.client.factory.create(
- 'ns0:LookupServiceRegistrationServiceType')
- lookupServiceRegistrationServiceType.product = product
- lookupServiceRegistrationServiceType.type = service
-
- lookupServiceRegistrationEndpointType = self.client.factory.create(
- 'ns0:LookupServiceRegistrationEndpointType')
- lookupServiceRegistrationEndpointType.type = endpoint
- lookupServiceRegistrationEndpointType.protocol = protocol
-
- lookupServiceRegistrationFilter = self.client.factory.create(
- 'ns0:LookupServiceRegistrationFilter')
- lookupServiceRegistrationFilter.serviceType = lookupServiceRegistrationServiceType
- lookupServiceRegistrationFilter.endpointType = lookupServiceRegistrationEndpointType
- return lookupServiceRegistrationFilter
-
- def find_mgmt_nodes(self):
- """
- Finds all the management nodes
-
- :rtype: dictionary
- :return: management node instance name and node id (UUID) in a dictionary
- """
- assert self.client is not None
- assert self.serviceRegistration is not None
-
- lookupServiceRegistrationServiceType = self.client.factory.create(
- 'ns0:LookupServiceRegistrationServiceType')
- lookupServiceRegistrationServiceType.product = 'com.vmware.cis'
- lookupServiceRegistrationServiceType.type = 'vcenterserver'
-
- lookupServiceRegistrationEndpointType = self.client.factory.create(
- 'ns0:LookupServiceRegistrationEndpointType')
- lookupServiceRegistrationEndpointType.type = 'com.vmware.vim'
- lookupServiceRegistrationEndpointType.protocol = 'vmomi'
-
- lookupServiceRegistrationFilter = self.client.factory.create(
- 'ns0:LookupServiceRegistrationFilter')
- lookupServiceRegistrationFilter.serviceType = lookupServiceRegistrationServiceType
- lookupServiceRegistrationFilter.endpointType = lookupServiceRegistrationEndpointType
-
- result = self.client.service.List(self.serviceRegistration,
- lookupServiceRegistrationFilter)
- assert len(result) > 0
-
- results_dict = {}
- for lookupServiceRegistrationInfo in result:
- for lookupServiceRegistrationAttribute in lookupServiceRegistrationInfo.serviceAttributes:
- if lookupServiceRegistrationAttribute.key == 'com.vmware.vim.vcenter.instanceName':
- results_dict[
- lookupServiceRegistrationAttribute.value] = lookupServiceRegistrationInfo.nodeId
- return results_dict
-
- def get_mgmt_node_id(self, instance_name):
- """
- Get the management node id from the instance name
-
- :type: :class:`str`
- :param instance_name: The instance name of the management node
- :rtype: :class:`str`
- :return: The UUID of the management node or, None is no management node is found by the given instance name
- """
- result = self.find_mgmt_nodes()
- assert result is not None
- return result.get(instance_name)
-
- def get_mgmt_node_instance_name(self, node_id):
- result = self.find_mgmt_nodes()
- assert result is not None
- for k, v in result.items():
- if v == node_id:
- return k
-
- def get_default_mgmt_node(self):
- """
- Finds the instance name and UUID of the management node for M1xN or, when the PSC and
- management services all reside on a single node (embedded).
- """
- result = self.find_mgmt_nodes()
- assert result is not None
- if len(result) < 1:
- raise Exception('No management node found')
- if len(result) > 1:
- raise MultipleManagementNodeException(
- MultipleManagementNodeException.format(result))
- return list(result.keys())[0], list(result.values())[
- 0] # python 3.x dict.keys() returns a view rather than a list
-
-
-class MultipleManagementNodeException(Exception):
- def __init__(self, message):
- super(MultipleManagementNodeException, self).__init__(message)
-
- @staticmethod
- def format(nodes):
- """
- Formats the multiple management node exception message
-
- :type: :class:`dict`
- :param nodes: The dictionary containing management nodes
- :rtype: :class:`str`
- :return: Formatted string output
- """
- message = 'Multiple Management Node Found on server'
- for k, v in nodes.items():
- message = message + os.linesep + 'Node name: {0} uuid: {1}'.format(
- k, v)
- return message
-
-
-def main():
- lookup_service_helper = LookupServiceHelper(
- wsdl_url='file:///path/to/lookupservice.wsdl',
- soap_url='https://server_ip/lookupservice/sdk')
- lookup_service_helper.connect()
- print(lookup_service_helper.find_sso_url())
- print(lookup_service_helper.find_vapi_urls())
- print(lookup_service_helper.find_vim_urls())
- print(lookup_service_helper.find_vim_pbm_urls())
- print(lookup_service_helper.find_mgmt_nodes())
-
-
-# Start program
-if __name__ == "__main__":
- main()
diff --git a/samples/vsphere/common/platform_service_controller.py b/samples/vsphere/common/platform_service_controller.py
deleted file mode 100644
index def7408b..00000000
--- a/samples/vsphere/common/platform_service_controller.py
+++ /dev/null
@@ -1,63 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2013, 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2013, 2016 VMware, Inc. All rights reserved.'
-
-from vmware.vapi.security.sso import create_saml_bearer_security_context
-from samples.vsphere.common import sso
-from samples.vsphere.common.lookup_service_helper import LookupServiceHelper
-
-from samples.vsphere.common.ssl_helper import get_unverified_context
-
-
-class PlatformServiceController(object):
- """
- Manages services on the infrastructure node (e.g. lookup service, SSO etc.)
- """
-
- def __init__(self, lswsdlurl, lssoapurl, ssousername, ssopassword,
- skip_verification):
- self.lswsdlurl = lswsdlurl
- self.lssoapurl = lssoapurl
- self.ssousername = ssousername
- self.ssopassword = ssopassword
- self.lookupservicehelper = None
- self.stsurl = None
- self.bearer_token = None # SAML bearer token
- self.sec_ctx = None # Security context
- self.skip_verification = skip_verification
-
- def login(self):
- """
- Finds the SSO URL from the lookup service and retrieves the SAML token from STS URL
- """
- print('Connecting to lookup service url: {0}'.format(self.lssoapurl))
- self.lookupservicehelper = LookupServiceHelper(wsdl_url=self.lswsdlurl,
- soap_url=self.lssoapurl,
- skip_verification=self.skip_verification)
- self.lookupservicehelper.connect()
-
- self.stsurl = self.lookupservicehelper.find_sso_url()
- assert self.stsurl is not None
-
- print('Retrieving a SAML bearer token from STS url : {0}'.format(
- self.stsurl))
- au = sso.SsoAuthenticator(self.stsurl)
- context = None
- if self.skip_verification:
- context = get_unverified_context()
- self.bearer_token = au.get_bearer_saml_assertion(
- self.ssousername, self.ssopassword, delegatable=True,
- ssl_context=context)
- self.sec_ctx = create_saml_bearer_security_context(self.bearer_token)
diff --git a/samples/vsphere/common/sample_base.py b/samples/vsphere/common/sample_base.py
deleted file mode 100644
index 62386755..00000000
--- a/samples/vsphere/common/sample_base.py
+++ /dev/null
@@ -1,104 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2013, 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2013, 2016 VMware, Inc. All rights reserved.'
-
-import argparse
-import traceback
-from samples.vsphere.common.service_manager_factory import ServiceManagerFactory
-
-
-class SampleBase(object):
- def __init__(self, description):
- if description is None:
- raise Exception('Sample description cannot be empty')
- self.description = description
- # setup the argument parser
- self.argparser = argparse.ArgumentParser(description=description)
- self.argparser.add_argument('-s', '--server',
- help='Hostname of vCenter Server')
- self.argparser.add_argument('-u', '--username',
- help='Username to login to the vCenter Server')
- self.argparser.add_argument('-p', '--password',
- help='Password to login to the vCenter Server')
- self.argparser.add_argument('-c', '--cleardata', action='store_true',
- help='Clears the sample data on server after running')
- self.argparser.add_argument('-v', '--skipverification',
- action='store_true',
- help='Do not verify server certificate')
- self.args = None
- self.server = None
- self.username = None
- self.password = None
- self.cleardata = False
- self.skip_verification = False
-
- def parse_args(self):
- for name in dir(self):
- attr = getattr(self, name)
- if callable(attr) and name == '_options':
- attr() # calling the method
- self.args = self.argparser.parse_args() # parse all the sample arguments when they are all set
-
- self.server = self.args.server
- assert self.server is not None
- print('server: {0}'.format(self.server))
-
- self.username = self.args.username
- assert self.username is not None
-
- self.password = self.args.password
- assert self.password is not None
-
- self.cleardata = self.args.cleardata
- self.skip_verification = self.args.skipverification
-
- def before(self):
-
- for name in dir(self):
- attr = getattr(self, name)
- if callable(attr) and name == '_setup':
- attr() # calling the method
-
- def run(self):
- for name in dir(self):
- attr = getattr(self, name)
- if callable(attr) and name == '_execute':
- try:
- attr() # calling the method
- except Exception as e:
- # print the exception and move on to the cleanup stage if cleardata is set to True.
- traceback.print_exc()
- if bool(self.cleardata) is not True:
- # re-throw the exception
- raise Exception(e)
-
- def after(self):
- if bool(self.cleardata) is True:
- for name in dir(self):
- attr = getattr(self, name)
- if callable(attr) and name == '_cleanup':
- attr() # calling the method
-
- def main(self):
- self.parse_args()
- self.before()
- self.run()
- self.after()
-
- def get_service_manager(self):
- return ServiceManagerFactory.get_service_manager(self.server,
- self.username,
- self.password,
- self.skip_verification)
diff --git a/samples/vsphere/common/sample_cli.py b/samples/vsphere/common/sample_cli.py
deleted file mode 100644
index 41122dbb..00000000
--- a/samples/vsphere/common/sample_cli.py
+++ /dev/null
@@ -1,54 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-import argparse
-
-
-def build_arg_parser():
- """
- Builds a standard argument parser with arguments for talking to vCenter
-
- -s server
- -u username
- -p password
- -c cleanup
- -v skipverification
-
- """
- parser = argparse.ArgumentParser(
- description='Standard Arguments for talking to vCenter')
-
- parser.add_argument('-s', '--server',
- action='store',
- help='vSphere service IP to connect to')
-
- parser.add_argument('-u', '--username',
- action='store',
- help='Username to use when connecting to vc')
-
- parser.add_argument('-p', '--password',
- action='store',
- help='Password to use when connecting to vc')
-
- parser.add_argument('-c', '--cleardata',
- action='store_true',
- help='Clean up after sample run. ')
-
- parser.add_argument('-v', '--skipverification',
- action='store_true',
- help='Verify server certificate when connecting to vc.')
-
- return parser
diff --git a/samples/vsphere/common/sample_util.py b/samples/vsphere/common/sample_util.py
deleted file mode 100644
index a92f8336..00000000
--- a/samples/vsphere/common/sample_util.py
+++ /dev/null
@@ -1,147 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-from six.moves import cStringIO
-from vmware.vapi.bindings.struct import PrettyPrinter
-
-from samples.vsphere.common import sample_cli
-from samples.vsphere.vcenter.setup import testbed
-
-
-def pp(value):
- """ Utility method used to print the data nicely. """
- output = cStringIO()
- PrettyPrinter(stream=output).pprint(value)
- return output.getvalue()
-
-
-def parse_cli_args_vm(vm_name):
- """
- Parse the server IP, credential and vm name used by vcenter vm samples.
- Use values from command line arguments if present, otherwise use values
- from testbed.py
- """
- # parse command line
- parser = sample_cli.build_arg_parser()
- parser.add_argument('-n', '--vm_name',
- action='store',
- help='Name of the testing vm')
- args = process_cli_args(parser.parse_args())
-
- if args.vm_name:
- vm_name = args.vm_name
- else:
- print("Try to use vm name({}) specified in testbed.py".format(vm_name))
- if not vm_name:
- raise Exception("vm name is required")
- print("vm name = {}".format(vm_name))
-
- return args.server, args.username, args.password, args.cleardata, \
- args.skipverification, vm_name
-
-
-def process_cli_args(args):
- """
- Verify if required inputs (server, username and password) are provided.
- If they are not passed through cmd arguments, we will try to get them from
- testbed.py. If they are not configured in testbed.py either, we will raise
- an exception to remind the user to provide them.
- """
-
- if not args.server:
- print("Using vcenter server specified in testbed.py")
- args.server = testbed.config['SERVER']
- if not args.server:
- raise Exception("vcenter server is required")
- print("vcenter server = {}".format(args.server))
-
- if not args.username:
- print("Using vc user specified in testbed.py")
- args.username = testbed.config['USERNAME']
- if not args.username:
- raise Exception("vc username is required")
- print("vc username = {}".format(args.username))
-
- if not args.password:
- print("Using vc password specified in testbed.py")
- args.password = testbed.config['PASSWORD']
-
- return args
-
-
-class Context(object):
- """Class that holds common context for running vcenter samples."""
-
- def __init__(self, testbed, service_instance, stub_config):
- # Testbed configuration
- self.testbed = testbed
-
- # pyVmomi SOAP Service Instance
- self.service_instance = service_instance
-
- # vAPI stub configuration used to make other stubs
- self.stub_config = stub_config
-
- self.option = {}
-
- @property
- def testbed(self):
- return self._testbed
-
- @testbed.setter
- def testbed(self, value):
- self._testbed = value
-
- @property
- def service_instance(self):
- return self._service_instance
-
- @service_instance.setter
- def service_instance(self, value):
- self._service_instance = value
-
- @property
- def soap_stub(self):
- return self._service_instance._stub
-
- @soap_stub.setter
- def soap_stub(self, value):
- self._soap_stub = value
-
- @property
- def stub_config(self):
- return self._stub_config
-
- @stub_config.setter
- def stub_config(self, value):
- self._stub_config = value
-
- @property
- def option(self):
- return self._option
-
- @option.setter
- def option(self, value):
- self._option = value
-
- def to_option_string(self):
- s = ['=' * 79,
- 'Testbed Options:',
- '=' * 79]
- s += [' {}: {}'.format(k, self._option[k])
- for k in sorted(self._option.keys())]
- s += ['=' * 79]
- return '\n'.join(s)
diff --git a/samples/vsphere/common/service_manager.py b/samples/vsphere/common/service_manager.py
deleted file mode 100644
index a71448cc..00000000
--- a/samples/vsphere/common/service_manager.py
+++ /dev/null
@@ -1,67 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2013, 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2013, 2016 VMware, Inc. All rights reserved.'
-
-from pyVim.connect import SmartConnect, Disconnect
-from samples.vsphere.common import vapiconnect
-
-from samples.vsphere.common.ssl_helper import get_unverified_context
-
-
-class ServiceManager(object):
- """
- Manages Vim and vAPI services on a management node.
- """
- def __init__(self, server, username, password, skip_verification):
-
- self.server_url = server
- self.username = username
- self.password = password
- self.skip_verification = skip_verification
- self.vapi_url = None
- self.vim_url = None
- self.session = None
- self.session_id = None
- self.stub_config = None
- self.si = None
- self.content = None
- self.vim_uuid = None
-
- def connect(self):
- # Connect to vAPI Endpoint on vCenter Server system
- self.stub_config = vapiconnect.connect(host=self.server_url,
- user=self.username,
- pwd=self.password,
- skip_verification=self.skip_verification)
-
- # Connect to VIM API Endpoint on vCenter Server system
- context = None
- if self.skip_verification:
- context = get_unverified_context()
- self.si = SmartConnect(host=self.server_url,
- user=self.username,
- pwd=self.password,
- sslContext=context)
- assert self.si is not None
-
- # Retrieve the service content
- self.content = self.si.RetrieveContent()
- assert self.content is not None
- self.vim_uuid = self.content.about.instanceUuid
-
- def disconnect(self):
- print('disconnecting the session')
- vapiconnect.logout(self.stub_config)
- Disconnect(self.si)
diff --git a/samples/vsphere/common/service_manager_factory.py b/samples/vsphere/common/service_manager_factory.py
deleted file mode 100644
index dbfffcfd..00000000
--- a/samples/vsphere/common/service_manager_factory.py
+++ /dev/null
@@ -1,42 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2013, 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2013, 2016 VMware, Inc. All rights reserved.'
-
-from samples.vsphere.common.service_manager import ServiceManager
-
-
-class ServiceManagerFactory(object):
- """
- Factory class for getting service manager for a management node.
- """
- service_manager = None
-
- @classmethod
- def get_service_manager(cls, server, username, password, skip_verification):
- cls.service_manager = ServiceManager(server,
- username,
- password,
- skip_verification)
- cls.service_manager.connect()
- return cls.service_manager
-
- @classmethod
- def disconnect(cls):
- if cls.service_manager:
- cls.service_manager.disconnect()
-
-
-import atexit
-atexit.register(ServiceManagerFactory.disconnect)
diff --git a/samples/vsphere/common/ssl_helper.py b/samples/vsphere/common/ssl_helper.py
deleted file mode 100644
index d645e2c6..00000000
--- a/samples/vsphere/common/ssl_helper.py
+++ /dev/null
@@ -1,29 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2013, 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-import ssl
-
-
-def get_unverified_context():
- """
- Get an unverified ssl context. Used to disable the server certificate
- verification.
- @return: unverified ssl context.
- """
- context = None
- if hasattr(ssl, '_create_unverified_context'):
- context = ssl._create_unverified_context()
- return context
diff --git a/samples/vsphere/common/sso.py b/samples/vsphere/common/sso.py
deleted file mode 100644
index f0aea9ab..00000000
--- a/samples/vsphere/common/sso.py
+++ /dev/null
@@ -1,537 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2013, 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2013, 2016 VMware, Inc. All rights reserved.'
-
-
-# Standard library imports.
-try:
- import httplib
-except ImportError:
- import http.client as httplib
-import base64
-import cgi
-import hashlib
-import re
-import sys
-import time
-from uuid import uuid4
-
-try:
- from StringIO import StringIO
-except ImportError:
- from io import StringIO
-try:
- from urlparse import urlparse
-except ImportError:
- from urllib.parse import urlparse
-
-# Third-party imports.
-from lxml import etree
-
-
-def _extract_certificate(cert):
- """
- Extract DER certificate/private key from DER/base64-ed DER/PEM string.
-
- @type cert: C{str}
- @param cert: Certificate/private key in one of three supported formats.
-
- @rtype: C{str}
- @return: Certificate/private key in DER (binary ASN.1) format.
- """
- if not cert:
- raise IOError('Empty certificate')
- signature = cert[0]
- # DER certificate is sequence. ASN.1 sequence is 0x30.
- if signature == '\x30':
- return cert
- # PEM without preamble. Base64-encoded 0x30 is 0x4D.
- if signature == '\x4D':
- return base64.b64decode(cert)
- # PEM with preamble. Starts with '-'.
- if signature == '-':
- return base64.b64decode(re.sub('-----[A-Z ]*-----', '', cert))
- # Unknown format.
- raise IOError('Invalid certificate file format')
-
-
-class SoapException(Exception):
- """
- Exception raised in case of STS request failure.
- """
- def __init__(self, soap_msg, fault_code, fault_string):
- """
- Initializer for SoapException.
-
- @type soap_msg: C{str}
- @param soap_msg: the soap fault XML returned by STS
- @type fault_code: C{str}
- @param fault_code: The fault code returned by STS.
- @type fault_string: C{str}
- @param fault_string: The fault string returned by STS.
- """
- self._soap_msg = soap_msg
- self._fault_code = fault_code
- self._fault_string = fault_string
- Exception.__init__(self)
-
- def __str__(self):
- """
- Returns the string representation of SoapException.
-
- @rtype: C{str}
- @return: string representation of SoapException
- """
- return ("SoapException:\nfaultcode: %(_fault_code)s\n"
- "faultstring: %(_fault_string)s\n"
- "faultxml: %(_soap_msg)s" % self.__dict__)
-
-
-class SSOHTTPSConnection(httplib.HTTPSConnection):
- """
- An HTTPS class that verifies server's certificate on connect.
- """
- def __init__(self, *args, **kwargs):
- """
- Initializer. See httplib.HTTPSConnection for other arguments
- than thumbprint and server_cert.
-
- At least one of thumbprint, server_cert should be provided,
- otherwise server certificate is not validated.
-
- @type thumbprint: C(str)
- @param thumbprint: Expected SHA-1 thumbprint of the server
- certificate. May be None.
-
- @type server_cert: C(str)
- @param server_cert: File with expected server certificate.
- May be None.
- """
- self.server_thumbprint = kwargs.pop('thumbprint')
- if self.server_thumbprint is not None:
- self.server_thumbprint = re.sub(':', '',
- self.server_thumbprint.lower())
- server_cert_path = kwargs.pop('server_cert')
- if server_cert_path is not None:
- with open(server_cert_path, 'rb') as f:
- server_cert = f.read()
- self.server_cert = _extract_certificate(server_cert)
- else:
- self.server_cert = None
- httplib.HTTPSConnection.__init__(self, *args, **kwargs)
-
- def _check_cert(self, peerCert):
- """
- Verify that peer certificate matches one we expect.
-
- @type peerCert: C(str)
- @param peerCert: Server certificate in DER format.
-
- @rtype: boolean
- @return: True if peerCert is acceptable. False otherwise.
- """
- if self.server_cert is not None:
- if peerCert != self.server_cert:
- return False
- if self.server_thumbprint is not None:
- thumbprint = hashlib.sha1(peerCert).hexdigest().lower() # pylint: disable=E1101
- if thumbprint != self.server_thumbprint:
- return False
- return True
-
- def connect(self):
- """
- Connect method: connects to the remote system, and upon
- successful connection validates certificate.
-
- Throws an exception when something is wrong. See
- httplib.HTTPSConnection.connect() for details.
- """
- httplib.HTTPSConnection.connect(self)
- if not self._check_cert(self.sock.getpeercert(True)):
- self.sock.close()
- self.sock = None
- raise IOError('Invalid certificate')
-
-
-class SsoAuthenticator(object):
- """
- A class to handle the transport layer communication between the client and
- the STS service.
- """
-
- def __init__(self,
- sts_url,
- sts_cert=None,
- thumbprint=None
- ):
- """
- Initializer for SsoAuthenticator.
-
- @type sts_url: C{str}
- @param sts_url: URL for the Security Token Service. Usually
- obtained by querying Component Manager.
- @type sts_cert: C{str}
- @param sts_cert: The file with public key of the Security
- Token Service. Usually obtained from
- Component Manager and written to the file.
- @type thumbprint: C{str}
- @param thumbprint: The SHA-1 thumbprint of the certificate used
- by the Security Token Service. It is same
- thumbprint you can pass to pyVmomi SoapAdapter.
- """
- self._sts_cert = sts_cert
- self._sts_url = sts_url
- self._sts_thumbprint = thumbprint
-
- def perform_request(self,
- soap_message,
- public_key=None,
- private_key=None,
- ssl_context=None):
- """
- Performs a Holder-of-Key SAML token request using the service user's
- certificates or a bearer token request using the user credentials.
-
- @type soap_message: C{str}
- @param soap_message: Authentication SOAP request.
- @type public_key: C{str}
- @param public_key: File containing the public key for the service
- user registered with SSO, in PEM format.
- @type private_key: C{str}
- @param private_key: File containing the private key for the service
- user registered with SSO, in PEM format.
- @type ssl_context: ssl.SSLContext
- @param ssl_context: Context describing the various SSL options.
- @rtype: C{str}
- @return: Response received from the STS after the HoK request.
- """
- parsed = urlparse(self._sts_url)
- host = parsed.netloc # pylint: disable=E1101
-
- import ssl
- if ssl_context and hasattr(ssl, '_create_unverified_context'):
- # Python 2.7.9 has stronger SSL certificate validation, so we need
- # to pass in a context when dealing with self-signed certificates.
- webservice = SSOHTTPSConnection(host=host,
- key_file=private_key,
- cert_file=public_key,
- server_cert=self._sts_cert,
- thumbprint=self._sts_thumbprint,
- context=ssl_context)
- else:
- # Versions of Python before 2.7.9 don't support the context
- # parameter, so if it wan't provided, don't pass it on.
- webservice = SSOHTTPSConnection(host=host,
- key_file=private_key,
- cert_file=public_key,
- server_cert=self._sts_cert,
- thumbprint=self._sts_thumbprint)
-
- webservice.putrequest("POST", parsed.path, skip_host=True) # pylint: disable=E1101
- webservice.putheader("Host", host)
- webservice.putheader("User-Agent", "VMware/pyVmomi")
- webservice.putheader("Accept", "text/xml, multipart/related")
- webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
- webservice.putheader("Content-length", "%d" % len(soap_message))
- webservice.putheader("Connection", "keep-alive")
- webservice.putheader("SOAPAction",
- "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue")
- webservice.endheaders()
- if sys.version_info[0] >= 3: # Python 3
- webservice.send(bytes(soap_message, 'UTF-8'))
- else:
- webservice.send(soap_message)
-
- saml_response = webservice.getresponse()
- if saml_response.status != 200:
- fault = saml_response.read()
- # Best effort at figuring out a SOAP fault.
- if saml_response.status == 500 and fault and 'faultcode' in fault:
- fault_xml = etree.fromstring(fault)
- parsed_fault = fault_xml.xpath("//text()")
- if len(parsed_fault) == 2:
- raise SoapException(fault, *parsed_fault)
- raise Exception("Got response %s: %s\n%s" %
- (saml_response.status, saml_response.msg, fault))
- return saml_response.read()
-
- def get_bearer_saml_assertion(self,
- username,
- password,
- public_key=None,
- private_key=None,
- request_duration=60,
- token_duration=600,
- delegatable=False,
- renewable=False,
- ssl_context=None):
- """
- Extracts the assertion from the Bearer Token received from the Security
- Token Service.
-
- @type username: C{str}
- @param username: Username for the user for which bearer token
- needs to be requested.
- @type password: C{str}
- @param password: Password for the user for which bearer token
- needs to be requested.
- @type public_key: C{str}
- @param public_key: File containing the public key for the service
- user registered with SSO, in PEM format.
- @type private_key: C{str}
- @param private_key: File containing the private key for the service
- user registered with SSO, in PEM format.
-
- @type request_duration: C{long}
- @param request_duration: The duration for which the request is valid. If
- the STS receives this request after this
- duration, it is assumed to have expired. The
- duration is in seconds and the default is 60s.
- @type token_duration: C{long}
- @param token_duration: The duration for which the SAML token is issued
- for. The duration is specified in seconds and
- the default is 600s.
- @type delegatable: C{boolean}
- @param delegatable: Whether the generated token is delegatable or not
- The default value is False
- @type ssl_context: ssl.SSLContext
- @param ssl_context: Context describing the various SSL options.
- @rtype: C{str}
- @return: The SAML assertion.
- """
- request = SecurityTokenRequest(username=username,
- password=password,
- public_key=public_key,
- private_key=private_key,
- request_duration=request_duration,
- token_duration=token_duration)
- soap_message = request.construct_bearer_token_request(
- delegatable=delegatable, renewable=renewable)
- bearer_token = self.perform_request(soap_message,
- public_key,
- private_key,
- ssl_context)
- if sys.version_info[0] >= 3:
- return etree.tostring(
- _extract_element(etree.fromstring(bearer_token),
- 'Assertion',
- {'saml2': "urn:oasis:names:tc:SAML:2.0:assertion"}),
- pretty_print=False).decode('utf-8')
- else:
- return etree.tostring(
- _extract_element(etree.fromstring(bearer_token),
- 'Assertion',
- {'saml2': "urn:oasis:names:tc:SAML:2.0:assertion"}),
- pretty_print=False)
-
-
-class SecurityTokenRequest(object):
- """
- SecurityTokenRequest class handles the serialization of request to the STS
- for a SAML token.
- """
-
- # pylint: disable=R0902
- def __init__(self,
- username=None,
- password=None,
- public_key=None,
- private_key=None,
- request_duration=60,
- token_duration=600):
- """
- Initializer for the SecurityToken Request class.
-
- @type username: C{str}
- @param username: Username for the user for which bearer token
- needs to be requested.
- @type password: C{str}
- @param password: Password for the user for which bearer token
- needs to be requested.
- @type public_key: C{str}
- @param public_key: The file containing the public key of the
- service account requesting the SAML token.
- @type private_key: C{str}
- @param private_key: The file containing the private key of the
- service account requesting the SAML token.
- @type request_duration: C{long}
- @param request_duration: The duration for which the request is valid. If
- the STS receives this request after this
- duration, it is assumed to have expired. The
- duration is specified in seconds and default is
- 60s.
- @type token_duration: C{long}
- @param token_duraiton: The duration for which the SAML token is issued
- for. The duration is specified in seconds and
- the default is 600s.
- """
- self._timestamp_id = _generate_id()
- self._signature_id = _generate_id()
- self._request_id = _generate_id()
- self._security_token_id = _generate_id()
- current = time.time()
- self._created = time.strftime(TIME_FORMAT,
- time.gmtime(current))
- self._expires = time.strftime(TIME_FORMAT,
- time.gmtime(current + token_duration))
- self._request_expires = time.strftime(TIME_FORMAT,
- time.gmtime(current +
- request_duration))
- self._timestamp = TIMESTAMP_TEMPLATE % self.__dict__
- self._username = cgi.escape(username) if username else username
- self._password = cgi.escape(password) if password else password
- self._public_key_file = public_key
- self._private_key_file = private_key
- self._act_as_token = None
- self._renewable = str(False).lower()
- self._delegatable = str(False).lower()
- self._use_key = ''
- self._private_key = None
- self._binary_exchange = None
- self._public_key = None
-
- def construct_bearer_token_request(self, delegatable=False, renewable=False):
- """
- Constructs the actual Bearer token SOAP request.
-
- @type delegatable: C{boolean}
- @param delegatable: Whether the generated token is delegatable or not
- @type renewable: C{boolean}
- @param renewable: Whether the generated token is renewable or not
- The default value is False
- @rtype: C{str}
- @return: Bearer token SOAP request.
- """
- self._key_type = "http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer"
- self._security_token = USERNAME_TOKEN_TEMPLATE % self.__dict__
- self._delegatable = str(delegatable).lower()
- self._renewable = str(renewable).lower()
- return _canonicalize(REQUEST_TEMPLATE % self.__dict__)
-
-
-def _generate_id():
- """
- An internal helper method to generate UUIDs.
-
- @rtype: C{str}
- @return: UUID
- """
- return "_%s" % uuid4()
-
-
-def _canonicalize(xml_string):
- """
- Given an xml string, canonicalize the string per
- U{http://www.w3.org/2001/10/xml-exc-c14n#}
-
- @type xml_string: C{str}
- @param xml_string: The XML string that needs to be canonicalized.
-
- @rtype: C{str}
- @return: Canonicalized string.
- """
- string = StringIO(xml_string)
- parser = etree.XMLParser(remove_blank_text=True)
- tree = etree.parse(string, parser=parser)
- # io.StringIO only accepts Unicode input (i.e. u"multibyte string"), while StringIO.StringIO accepts either 8 bit input or unicode input.
- if sys.version_info[0] >= 3:
- from io import BytesIO
- string = BytesIO()
- tree.write_c14n(string, exclusive=True, with_comments=False)
- return string.getvalue().decode('utf-8')
- else:
- string = StringIO()
- tree.write_c14n(string, exclusive=True, with_comments=False)
- return string.getvalue()
-
-
-def _extract_element(xml, element_name, namespace):
- """
- An internal method provided to extract an element from the given XML.
-
- @type xml: C{str}
- @param xml: The XML string from which the element will be extracted.
- @type element_name: C{str}
- @param element_name: The element that needs to be extracted from the XML.
- @type namespace: dict
- @param namespace: A dict containing the namespace of the element to be
- extracted.
-
- @rtype: etree element.
- @return: The extracted element.
- """
- assert(len(namespace) == 1)
- result = xml.xpath("//%s:%s" % (list(namespace.keys())[0], element_name), # python 3.x dict.keys() returns a view
- namespaces=namespace)
- if result:
- return result[0]
- else:
- raise KeyError('%s does not seem to be present in the XML.' %
- element_name)
-
-
-TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.987Z"
-
-
-# Template container for user's credentials when requesting a bearer token.
-USERNAME_TOKEN_TEMPLATE = """\
-
-%(_username)s
-%(_password)s
-"""
-
-
-# Template containing the anchor to the signature.
-USE_KEY_TEMPLATE = """\
-"""
-
-
-# The follwoing template is used to create a timestamp for the various messages.
-# The timestamp is used to indicate the duration of the request itself.
-TIMESTAMP_TEMPLATE = """\
-
-%(_created)s%(_request_expires)s"""
-
-
-# The following template is used to construct the token requests to the STS.
-REQUEST_TEMPLATE = """\
-
-
-
-%(_timestamp)s
-%(_security_token)s
-
-
-
-
-urn:oasis:names:tc:SAML:2.0:assertion
-http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue
-
-%(_created)s
-%(_expires)s
-
-
-%(_delegatable)s
-%(_key_type)s
-http://www.w3.org/2001/04/xmldsig-more#rsa-sha256%(_use_key)s
-
-"""
diff --git a/samples/vsphere/common/vapiconnect.py b/samples/vsphere/common/vapiconnect.py
deleted file mode 100644
index 7f1c1247..00000000
--- a/samples/vsphere/common/vapiconnect.py
+++ /dev/null
@@ -1,98 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-import requests
-
-from com.vmware.cis_client import Session
-
-from vmware.vapi.lib.connect import get_requests_connector
-from vmware.vapi.security.session import create_session_security_context
-from vmware.vapi.security.user_password import \
- create_user_password_security_context
-from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
-
-
-def get_jsonrpc_endpoint_url(host):
- # The URL for the stub requests are made against the /api HTTP endpoint
- # of the vCenter system.
- return "https://{}/api".format(host)
-
-
-def connect(host, user, pwd, skip_verification=False, cert_path=None, suppress_warning=True):
- """
- Create an authenticated stub configuration object that can be used to issue
- requests against vCenter.
-
- Returns a stub_config that stores the session identifier that can be used
- to issue authenticated requests against vCenter.
- """
- host_url = get_jsonrpc_endpoint_url(host)
-
- session = requests.Session()
- if skip_verification:
- session = create_unverified_session(session, suppress_warning)
- elif cert_path:
- session.verify = cert_path
- connector = get_requests_connector(session=session, url=host_url)
- stub_config = StubConfigurationFactory.new_std_configuration(connector)
-
- return login(stub_config, user, pwd)
-
-
-def login(stub_config, user, pwd):
- """
- Create an authenticated session with vCenter.
-
- Returns a stub_config that stores the session identifier that can be used
- to issue authenticated requests against vCenter.
- """
- # Pass user credentials (user/password) in the security context to
- # authenticate.
- user_password_security_context = create_user_password_security_context(user,
- pwd)
- stub_config.connector.set_security_context(user_password_security_context)
-
- # Create the stub for the session service and login by creating a session.
- session_svc = Session(stub_config)
- session_id = session_svc.create()
-
- # Successful authentication. Store the session identifier in the security
- # context of the stub and use that for all subsequent remote requests
- session_security_context = create_session_security_context(session_id)
- stub_config.connector.set_security_context(session_security_context)
-
- return stub_config
-
-
-def logout(stub_config):
- """
- Delete session with vCenter.
- """
- if stub_config:
- session_svc = Session(stub_config)
- session_svc.delete()
-
-
-def create_unverified_session(session, suppress_warning=True):
- """
- Create a unverified session to disable the server certificate verification.
- """
- session.verify = False
- if suppress_warning:
- # Suppress unverified https request warnings
- from requests.packages.urllib3.exceptions import InsecureRequestWarning
- requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
- return session
diff --git a/samples/vsphere/common/vim/__init__.py b/samples/vsphere/common/vim/__init__.py
deleted file mode 100644
index 59b403a2..00000000
--- a/samples/vsphere/common/vim/__init__.py
+++ /dev/null
@@ -1,10 +0,0 @@
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
-
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
-
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/common/vim/datastore_file.py b/samples/vsphere/common/vim/datastore_file.py
deleted file mode 100644
index 24b2a0fe..00000000
--- a/samples/vsphere/common/vim/datastore_file.py
+++ /dev/null
@@ -1,343 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-import pyVim.task
-import requests
-from pyVmomi import vim
-
-from samples.vsphere.common.vim.inventory import get_datacenter_for_datastore
-
-# TODO:
-# verify=False in all cases. Expose this as a top level control
-
-debug = False
-
-(FILE, FOLDER) = range(2)
-
-
-class FileArray(list):
- def list(self, path=None):
- children = FileArray()
- for e in self:
- children += e.list(path)
- return children
-
- def __repr__(self):
- return '\n'.join([str(e) for e in self])
-
- def _check_unique(self):
- if len(self) == 0:
- raise Exception('FileArray: No elements')
- elif len(self) > 1:
- raise Exception('FileArray: Maybe applied to only one element')
-
- @property
- def path(self):
- self._check_unique()
- return self[0].path
-
- @property
- def datastore_path(self):
- self._check_unique()
- return self[0].datastore_path
-
- @property
- def datastore_mo(self):
- self._check_unique()
- return self[0].datastore_mo
-
- @property
- def type(self):
- self._check_unique()
- return self[0].type
-
- def list(self, path=None):
- self._check_unique()
- return self[0].list(path)
-
- def put(self, path=None, src_url=None, src_file=None, src_path=None,
- content=None):
- self._check_unique()
- return self[0].put(path, src_url, src_file, src_path, content)
-
- def get(self, path=None):
- self._check_unique()
- return self[0].get(path)
-
- def exists(self, path=None):
- self._check_unique()
- return self[0].exists(path)
-
- def delete(self, path=None):
- self._check_unique()
- return self[0].delete(path)
-
- def delete2(self, path=None):
- self._check_unique()
- return self[0].delete2(path)
-
- def mkdir(self, path=None, parent=None):
- self._check_unique()
- return self[0].mkdir(path, parent)
-
-
-class File(object):
- """
- Utility class contains datastore related helper methods using vim API
- and HTTP requests module.
- """
- def __init__(self, parent=None, path=None, ftype=None):
- self._file_manager = None
- if isinstance(parent, vim.Datastore):
- # Iteratively look for the Datacenter parent
- self._datacenter_mo = get_datacenter_for_datastore(parent)
- self._datastore_mo = parent
- self._ftype = FOLDER
- if path:
- self._path = path
- else:
- self._path = ''
- elif isinstance(parent, File):
- self._datacenter_mo = parent._datacenter_mo
- self._datastore_mo = parent.datastore_mo
- self._ftype = ftype
- if parent._path == '':
- self._path = path
- else:
- self._path = '{}/{}'.format(parent._path, path)
- else:
- raise Exception(
- "Invalid type '{}' for datastore_file".format(type(parent)))
-
- def _get_file_manager(self):
- if not self._file_manager:
- soap_stub = self._datacenter_mo._stub
- service_instance = vim.ServiceInstance('ServiceInstance', soap_stub)
- self._file_manager = service_instance.content.fileManager
- return self._file_manager
-
- @property
- def path(self):
- return self._path
-
- @path.setter
- def path(self, value):
- self._path = value
-
- def get_datastore_path(self, path=None):
- if not path:
- return self.datastore_path
-
- paths = [p for p in [self._path, path] if p]
- return '[{}] {}'.format(self._datastore_mo.name, '/'.join(paths))
-
- @property
- def datastore_path(self):
- if self._path != '':
- return '[{}] {}'.format(self._datastore_mo.name, self._path)
- else:
- return '[{}]'.format(self._datastore_mo.name)
-
- @property
- def datastore_mo(self):
- return self._datastore_mo
-
- @datastore_mo.setter
- def datastore_mo(self, value):
- self._datastore_mo = value
-
- @property
- def type(self):
- return self._ftype
-
- @type.setter
- def type(self, value):
- self._ftype = value
-
- def to_string(self):
- s = ''
- if self._ftype == FOLDER:
- s += 'D '
- else:
- s += 'F '
- s += self.datastore_path
- return s
-
- def __repr__(self):
- return self.to_string()
-
- def list(self, path=None):
- match_pattern = None
- dirname = None
-
- if path is not None:
- # Determine the dirname and the basename making sure only the
- # basename is passed in the match_pattern
- paths = path.split('/')
- if len(paths) == 1:
- dirname = paths[0]
- else:
- path = paths[-1]
- dirname = '/'.join(paths[0:-1])
- match_pattern = [path]
-
- browser = self._datastore_mo.browser
- search_spec = vim.host.DatastoreBrowser.SearchSpec(
- query=[vim.host.DatastoreBrowser.FolderQuery(),
- vim.host.DatastoreBrowser.Query()],
- details=vim.host.DatastoreBrowser.FileInfo.Details(fileType=True),
- matchPattern=match_pattern,
- sortFoldersFirst=True)
- if debug:
- print("list: dirname='{}' search_spec='{}'".
- format(dirname, search_spec))
- task = browser.Search(dirname, search_spec)
- pyVim.task.WaitForTask(task)
-
- children = FileArray()
- for f in task.info.result.file:
- ftype = FILE
- if isinstance(f, vim.host.DatastoreBrowser.FolderInfo):
- ftype = FOLDER
- if dirname:
- children.append(
- File(self, path='/'.join([dirname, f.path]), ftype=ftype))
- else:
- children.append(File(self, path=f.path, ftype=ftype))
- return children
-
- def _make_cookie(self, stub):
- cookies = {}
- for c in stub.cookie.split(';'):
- e = c.strip().split('=')
- if len(e) > 1:
- cookies[e[0]] = e[1]
- return cookies
-
- def exists(self, path=None):
- try:
- return len(self.list(path)) > 0
- except vim.fault.FileNotFound:
- return False
-
- def put(self, path=None, src_url=None, src_file=None, src_path=None,
- content=None):
- datacenter_name = self._datacenter_mo.name
- datastore_name = self._datastore_mo.name
- stub = self._datastore_mo._stub
- cookie = self._make_cookie(stub)
- f = None
- if src_file is not None:
- f = src_file
- elif src_url is not None:
- f = requests.get(src_url, stream=True)
- elif src_path is not None:
- f = open(src_file, 'wb')
- elif content is None:
- raise Exception('No input provided for put')
-
- if f:
- data = f
- else:
- data = content
-
- paths = ['https://{0}/folder'.format(stub.host)]
- if self._path:
- paths.append(self._path)
- if path:
- paths.append(path)
- url = '/'.join(paths)
- if debug:
- print("put: url is '{}'".format(url))
-
- r = requests.put(url, params={'dcPath': datacenter_name,
- 'dsName': datastore_name},
- cookies=cookie, verify=False, data=data)
-
- if f:
- f.close()
- f = None
-
- if r.status_code < 200 or r.status_code >= 300:
- raise Exception('Put failed with status {}'.format(r.status_code),
- r)
-
- def get(self, path=None):
- datacenter_name = self._datacenter_mo.name
- datastore_name = self._datastore_mo.name
- stub = self._datastore_mo._stub
- cookie = self._make_cookie(stub)
-
- paths = ['https://{0}/folder'.format(stub.host)]
- if self._path:
- paths.append(self._path)
- if path:
- paths.append(path)
- url = '/'.join(paths)
- if debug:
- print("get: url is '{}'".format(url))
-
- r = requests.get(url, params={'dcPath': datacenter_name,
- 'dsName': datastore_name},
- cookies=cookie, verify=False, stream=True)
-
- if r.status_code < 200 or r.status_code >= 300:
- raise Exception('Get failed with status {}'.format(r.status_code),
- r)
-
- return r
-
- def delete(self, path=None):
- datacenter_name = self._datacenter_mo.name
- datastore_name = self._datastore_mo.name
- stub = self._datastore_mo._stub
- cookie = self._make_cookie(stub)
-
- paths = ['https://{0}/folder'.format(stub.host)]
- if self._path:
- paths.append(self._path)
- if path:
- paths.append(path)
- url = '/'.join(paths)
- if debug:
- print("delete: url is '{}'".format(url))
-
- r = requests.delete(url, params={'dcPath': datacenter_name,
- 'dsName': datastore_name},
- cookies=cookie, verify=False)
-
- if r.status_code < 200 or r.status_code >= 300:
- raise Exception(
- 'Delete failed with status {}'.format(r.status_code), r)
-
- def delete2(self, path=None):
- datacenter_mo = self._datacenter_mo
- file_manager = self._get_file_manager()
- datastore_path = self.get_datastore_path(path)
- if debug:
- print("delete2: datastore_path is '{}'".format(datastore_path))
-
- # TODO 'FileType' is not public?
- # file_manager.Delete(self._datacenter_mo, datastore_path, 'File')
-
- def mkdir(self, path=None, parent=False):
- datacenter_mo = self._datacenter_mo
- file_manager = self._get_file_manager()
- datastore_path = self.get_datastore_path(path)
- if debug:
- print("mkdir: datastore_path is '{}'".format(datastore_path))
-
- file_manager.MakeDirectory(datastore_path, self._datacenter_mo, parent)
diff --git a/samples/vsphere/common/vim/file.py b/samples/vsphere/common/vim/file.py
deleted file mode 100644
index 0a56034e..00000000
--- a/samples/vsphere/common/vim/file.py
+++ /dev/null
@@ -1,128 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-import re
-
-from samples.vsphere.common.vim.inventory import get_datastore_mo
-
-from samples.vsphere.common.vim import datastore_file
-
-datastore_path_regex = re.compile('\[(.+)\]\s?(.*)')
-
-
-def parse_datastore_path(datastore_path):
- """Extract datastore name from datastore path"""
- m = datastore_path_regex.match(datastore_path)
- if m:
- (datastore_name, path) = m.groups()
- return datastore_name, path
- return None, None
-
-
-def detect_directory(context, description, datacenter_name, datastore_path):
- """Find directory based on specific datacenter and datastore path"""
- (datastore_name, path) = parse_datastore_path(datastore_path)
- datastore_mo = get_datastore_mo(context.stub_config,
- context.service_instance._stub,
- datacenter_name,
- datastore_name)
- if not datastore_mo:
- raise Exception("Could not find datastore '{}'".format(datastore_name))
-
- dsfile = datastore_file.File(datastore_mo)
- f = dsfile.list(datastore_path)
- if len(f) == 0:
- print("Failed to detect {} directory '{}'".format(description,
- datastore_path))
- return False
- if f.type != datastore_file.FOLDER:
- print("Path '{}' is not a directory".format(datastore_path))
- return False
- return True
-
-
-def create_directory(context, description, datacenter_name, datastore_path):
- """Create directory in specific datacenter"""
- (datastore_name, path) = parse_datastore_path(datastore_path)
- datastore_mo = get_datastore_mo(context.stub_config,
- context.service_instance._stub,
- datacenter_name,
- datastore_name)
- if not datastore_mo:
- raise Exception("Could not find datastore '{}'".format(datastore_name))
-
- dsfile = datastore_file.File(datastore_mo)
- if not dsfile.exists(datastore_path):
- print("Creating {} directory '{}'".format(description, datastore_path))
- dsfile.mkdir(path, parent=True)
- else:
- # TODO Need to check that this is actually a directory.
- print("{} directory '{}' exists.".format(description, datastore_path))
-
-
-def delete_directory(context, description, datacenter_name, datastore_path):
- """Delete directory from specific datacenter"""
- (datastore_name, path) = parse_datastore_path(datastore_path)
- datastore_mo = get_datastore_mo(context.stub_config,
- context.service_instance._stub,
- datacenter_name,
- datastore_name)
- if not datastore_mo:
- return
-
- dsfile = datastore_file.File(datastore_mo)
- if dsfile.exists(datastore_path):
- print("Deleting {} directory '{}'.".format(description, datastore_path))
- dsfile.delete2(path)
-
-
-def detect_file(context, description, datacenter_name, datastore_path):
- """Find specific file in specific datacenter"""
- (datastore_name, path) = parse_datastore_path(datastore_path)
- datastore_mo = get_datastore_mo(context.stub_config,
- context.service_instance._stub,
- datacenter_name,
- datastore_name)
- if not datastore_mo:
- raise Exception("Could not find datastore '{}'".format(datastore_name))
-
- dsfile = datastore_file.File(datastore_mo)
- f = dsfile.list(datastore_path)
- if len(f) == 0:
- print("Failed to detect {} file '{}'".
- format(description, datastore_path))
- return False
- if f.type != datastore_file.FILE:
- print("Path '{}' is not a file".format(datastore_path))
- return False
- return True
-
-
-def delete_file(stub_config, service_instance,
- description, datacenter_name, datastore_path):
- """Delete a file from specific datacenter"""
- (datastore_name, path) = parse_datastore_path(datastore_path)
- datastore_mo = get_datastore_mo(stub_config,
- service_instance._stub,
- datacenter_name,
- datastore_name)
- if not datastore_mo:
- return
-
- dsfile = datastore_file.File(datastore_mo)
- if dsfile.exists(datastore_path):
- print("Deleting {} file '{}'.".format(description, datastore_path))
- dsfile.delete(path)
diff --git a/samples/vsphere/common/vim/helpers/__init__.py b/samples/vsphere/common/vim/helpers/__init__.py
deleted file mode 100644
index 59b403a2..00000000
--- a/samples/vsphere/common/vim/helpers/__init__.py
+++ /dev/null
@@ -1,10 +0,0 @@
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
-
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
-
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/common/vim/helpers/get_cluster_by_name.py b/samples/vsphere/common/vim/helpers/get_cluster_by_name.py
deleted file mode 100644
index ea15245b..00000000
--- a/samples/vsphere/common/vim/helpers/get_cluster_by_name.py
+++ /dev/null
@@ -1,77 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2013, 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2013, 2016 VMware, Inc. All rights reserved.'
-
-from pyVmomi import vim
-
-from samples.vsphere.common.sample_base import SampleBase
-from samples.vsphere.common.vim.helpers.vim_utils import get_obj
-
-
-class GetClusterByName(SampleBase):
- """
- Retrieves the given cluster MOID from VC using container view
- """
-
- def __init__(self):
- SampleBase.__init__(self, self.__doc__)
- self.cluster_name = None
- self.mo_id = None
- self.servicemanager = None
-
- def _options(self):
- self.argparser.add_argument('-clustername', '--clustername',
- help='Name of the cluster to be queried')
-
- def _setup(self):
- if self.cluster_name is None:
- self.cluster_name = self.args.clustername
- assert self.cluster_name is not None
- if self.servicemanager is None:
- self.servicemanager = self.get_service_manager()
-
- def _execute(self):
- content = self.servicemanager.content
- cluster_obj = get_obj(content, [vim.ClusterComputeResource],
- self.cluster_name)
- if cluster_obj is not None:
- self.mo_id = cluster_obj._GetMoId()
- print('Cluster MoId: {0}'.format(self.mo_id))
- else:
- print('Cluster: {0} not found'.format(self.cluster_name))
-
- def _cleanup(self):
- pass
-
-
-def get_cluster_id(service_manager, cluster_name):
- """
- Returns the cluster's MoId, or None if the cluster doesn't exist
- """
- get_cluster_by_name = GetClusterByName()
- get_cluster_by_name.servicemanager = service_manager
- get_cluster_by_name.cluster_name = cluster_name
- get_cluster_by_name.run()
- return get_cluster_by_name.mo_id
-
-
-def main():
- get_cluster_by_name = GetClusterByName()
- get_cluster_by_name.main()
-
-
-# Start program
-if __name__ == "__main__":
- main()
diff --git a/samples/vsphere/common/vim/helpers/get_datastore_by_name.py b/samples/vsphere/common/vim/helpers/get_datastore_by_name.py
deleted file mode 100644
index a2c385e4..00000000
--- a/samples/vsphere/common/vim/helpers/get_datastore_by_name.py
+++ /dev/null
@@ -1,76 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2013, 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2013, 2016 VMware, Inc. All rights reserved.'
-
-from pyVmomi import vim
-
-from samples.vsphere.common.sample_base import SampleBase
-from samples.vsphere.common.vim.helpers.vim_utils import get_obj
-
-
-class GetDatastoreByName(SampleBase):
- """
- Retrieves the given datastore MOID from VC using container view
- """
-
- def __init__(self):
- SampleBase.__init__(self, self.__doc__)
- self.datastore_name = None
- self.mo_id = None
- self.servicemanager = None
-
- def _options(self):
- self.argparser.add_argument('-datastorename', '--datastorename',
- help='Name of the datastore to be queried')
-
- def _setup(self):
- if self.datastore_name is None:
- self.datastore_name = self.args.datastorename
- assert self.datastore_name is not None
- if self.servicemanager is None:
- self.servicemanager = self.get_service_manager()
-
- def _execute(self):
- content = self.servicemanager.content
- datastore_obj = get_obj(content, [vim.Datastore], self.datastore_name)
- if datastore_obj is not None:
- self.mo_id = datastore_obj._GetMoId()
- print('Datastore MoId: {0}'.format(self.mo_id))
- else:
- print('Datastore: {0} not found'.format(self.datastore_name))
-
- def _cleanup(self):
- pass
-
-
-def get_datastore_id(service_manager, datastore_name):
- """
- returns the datastore's MoId, or None if the datastore doesn't exist
- """
- get_datastore_by_name = GetDatastoreByName()
- get_datastore_by_name.servicemanager = service_manager
- get_datastore_by_name.datastore_name = datastore_name
- get_datastore_by_name.run()
- return get_datastore_by_name.mo_id
-
-
-def main():
- get_datastore_by_name = GetDatastoreByName()
- get_datastore_by_name.main()
-
-
-# Start program
-if __name__ == "__main__":
- main()
diff --git a/samples/vsphere/common/vim/helpers/vim_utils.py b/samples/vsphere/common/vim/helpers/vim_utils.py
deleted file mode 100644
index 88f44eea..00000000
--- a/samples/vsphere/common/vim/helpers/vim_utils.py
+++ /dev/null
@@ -1,160 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2013. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2013 VMware, Inc. All rights reserved.'
-
-from pyVmomi import vim, vmodl
-
-_views = [] # list of container views
-
-
-def get_obj(content, vimtype, name):
- """
- Get the vsphere managed object associated with a given text name
- """
- obj = None
- container = content.viewManager.CreateContainerView(content.rootFolder,
- vimtype, True)
- _views.append(container)
- for c in container.view:
- if c.name == name:
- obj = c
- break
- return obj
-
-
-def get_obj_by_moId(content, vimtype, moid):
- """
- Get the vsphere managed object by moid value
- """
- obj = None
- container = content.viewManager.CreateContainerView(content.rootFolder,
- vimtype, True)
- _views.append(container)
- for c in container.view:
- if c._GetMoId() == moid:
- obj = c
- break
- return obj
-
-
-def delete_object(content, mo):
- """
- Deletes a vsphere managed object and waits for the deletion to complete
- """
- print('Deleting {0}'.format(mo._GetMoId()))
- try:
- wait_for_tasks(content, [mo.Destroy()])
- print('Deleted {0}'.format(mo._GetMoId()))
- except Exception:
- print('Unexpected error while deleting managed object {0}'.format(
- mo._GetMoId()))
- return False
- return True
-
-
-def poweron_vm(content, mo):
- """
- Powers on a VM and wait for power on operation to complete
- """
- if not isinstance(mo, vim.VirtualMachine):
- return False
-
- print('Powering on vm {0}'.format(mo._GetMoId()))
- try:
- wait_for_tasks(content, [mo.PowerOn()])
- print('{0} powered on successfully'.format(mo._GetMoId()))
- except Exception:
- print('Unexpected error while powering on vm {0}'.format(mo._GetMoId()))
- return False
- return True
-
-
-def poweroff_vm(content, mo):
- """
- Powers on a VM and wait for power on operation to complete
- """
- if not isinstance(mo, vim.VirtualMachine):
- return False
-
- print('Powering off vm {0}'.format(mo._GetMoId()))
- try:
- wait_for_tasks(content, [mo.PowerOff()])
- print('{0} powered off successfully'.format(mo._GetMoId()))
- except Exception:
- print(
- 'Unexpected error while powering off vm {0}'.format(mo._GetMoId()))
- return False
- return True
-
-
-def wait_for_tasks(content, tasks):
- """
- Given the tasks, it returns after all the tasks are complete
- """
- taskList = [str(task) for task in tasks]
-
- # Create filter
- objSpecs = [vmodl.query.PropertyCollector.ObjectSpec(obj=task) for task in
- tasks]
- propSpec = vmodl.query.PropertyCollector.PropertySpec(type=vim.Task,
- pathSet=[], all=True)
- filterSpec = vmodl.query.PropertyCollector.FilterSpec()
- filterSpec.objectSet = objSpecs
- filterSpec.propSet = [propSpec]
- task_filter = content.propertyCollector.CreateFilter(filterSpec, True)
-
- try:
- version, state = None, None
-
- # Loop looking for updates till the state moves to a completed state.
- while len(taskList):
- update = content.propertyCollector.WaitForUpdates(version)
- for filterSet in update.filterSet:
- for objSet in filterSet.objectSet:
- task = objSet.obj
- for change in objSet.changeSet:
- if change.name == 'info':
- state = change.val.state
- elif change.name == 'info.state':
- state = change.val
- else:
- continue
-
- if not str(task) in taskList:
- continue
-
- if state == vim.TaskInfo.State.success:
- # Remove task from taskList
- taskList.remove(str(task))
- elif state == vim.TaskInfo.State.error:
- raise task.info.error
- # Move to next version
- version = update.version
- finally:
- if task_filter:
- task_filter.Destroy()
-
-
-def __destroy_container_views():
- for view in _views:
- try:
- view.Destroy()
- except vmodl.fault.ManagedObjectNotFound:
- pass # silently bypass the exception if the objects are already deleted/not found on the server
-
-
-import atexit
-
-atexit.register(__destroy_container_views)
diff --git a/samples/vsphere/common/vim/inventory.py b/samples/vsphere/common/vim/inventory.py
deleted file mode 100644
index 1917c4dc..00000000
--- a/samples/vsphere/common/vim/inventory.py
+++ /dev/null
@@ -1,43 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter__ = 'since 6.0'
-
-from pyVmomi import vim
-
-from samples.vsphere.vcenter.helper.datastore_helper import get_datastore
-
-
-def get_datastore_mo(stub_config, soap_stub,
- datacenter_name, datastore_name):
- """
- Return datastore managed object with specific datacenter and datastore name
- """
- datastore = get_datastore(stub_config, datacenter_name, datastore_name)
- if not datastore:
- return None
- datastore_mo = vim.Datastore(datastore, soap_stub)
- return datastore_mo
-
-
-# TODO Not the most efficient implementation. This can be done as a single
-# property collector query but it's a little more complicated
-def get_datacenter_for_datastore(datastore_mo):
- datacenter_mo = datastore_mo.parent
- while datacenter_mo is not None:
- if isinstance(datacenter_mo, vim.Datacenter):
- return datacenter_mo
- datacenter_mo = datacenter_mo.parent
- return None
diff --git a/samples/vsphere/common/vim/vmdk.py b/samples/vsphere/common/vim/vmdk.py
deleted file mode 100644
index c4a7ca76..00000000
--- a/samples/vsphere/common/vim/vmdk.py
+++ /dev/null
@@ -1,59 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-import pyVim.task
-from pyVmomi import vim
-from samples.vsphere.common.vim.inventory import get_datastore_mo
-
-from samples.vsphere.common.vim import datastore_file
-
-
-def create_vmdk(service_instance, datacenter_mo, datastore_path):
- """Create vmdk in specific datacenter"""
- vdm = service_instance.content.virtualDiskManager
- task = vdm.CreateVirtualDisk(
- datastore_path, datacenter_mo,
- vim.VirtualDiskManager.SeSparseVirtualDiskSpec(
- diskType='seSparse', adapterType='lsiLogic',
- capacityKb=1024 * 1024 * 4))
- pyVim.task.WaitForTask(task)
- print("Created VMDK '{}' in Datacenter '{}'".
- format(datastore_path, datacenter_mo.name))
- return task.info.result
-
-
-def delete_vmdk(service_instance, datacenter_mo, datastore_path):
- """Delete vmdk from specific datastore"""
- vdm = service_instance.content.virtualDiskManager
- task = vdm.DeleteVirtualDisk(datastore_path, datacenter_mo)
- pyVim.task.WaitForTask(task)
-
-
-def detect_vmdk(stub_config, soap_stub, datacenter_name, datastore_name,
- datastore_path):
- """Find vmdk in specific datastore"""
- datastore_mo = get_datastore_mo(stub_config,
- soap_stub,
- datacenter_name,
- datastore_name)
- if not datastore_mo:
- return False
-
- dsfile = datastore_file.File(datastore_mo)
- if dsfile.exists(datastore_path):
- return True
- else:
- return False
diff --git a/samples/vsphere/contentlibrary/README.md b/samples/vsphere/contentlibrary/README.md
deleted file mode 100644
index 8d700455..00000000
--- a/samples/vsphere/contentlibrary/README.md
+++ /dev/null
@@ -1,30 +0,0 @@
-This directory contains samples for Content Library APIs:
-
- * CRUD operations on a content library - crud/library_crud.py
- * Updating content of a content library item - contentupdate/content_update.py
- * Workflow to deploy an OVF library item to a resource pool - ovfdeploy/deploy_ovf_template.py
- * Workflows to import an OVF package into a content library, and download of an OVF template from a content library - ovfimport/ovf_import_export.py
- * Basic workflow to publish and subscribe content libraries - publishsubscribe/library_publish_subscribe.py
- * Workflow to capture a virtual machine into a content library - vmcapture/vm_template_capture.py
- * Content library ISO item mount and unmount workflow - isomount/iso_mount.py
-
-Running the samples
-
- $ python /.py --server --username --password
-
-The additional sample parameters are as follows (all parameters can be displayed for any sample using option --help)
-
- * library_crud.py --datastorename
- * content_update.py --datastorename
- * deploy_ovf_template.py --clustername --libitemname
- * ovf_import_export.py --datastorename
- * library_publish_subscribe.py --datastorename
- * vm_template_capture.py --datastorename --vmname
- * iso_mount.py --datastorename --vmname
-
-* Testbed Requirement:
- - 1 vCenter Server
- - 2 ESX hosts
- - 1 datastore
- - Some samples need a VM or an OVF library item created as mentioned above
-
diff --git a/samples/vsphere/contentlibrary/__init__.py b/samples/vsphere/contentlibrary/__init__.py
deleted file mode 100644
index f42a9c36..00000000
--- a/samples/vsphere/contentlibrary/__init__.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/contentlibrary/contentupdate/__init__.py b/samples/vsphere/contentlibrary/contentupdate/__init__.py
deleted file mode 100644
index 25885b63..00000000
--- a/samples/vsphere/contentlibrary/contentupdate/__init__.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/contentlibrary/contentupdate/content_update.py b/samples/vsphere/contentlibrary/contentupdate/content_update.py
deleted file mode 100644
index d65ee6ec..00000000
--- a/samples/vsphere/contentlibrary/contentupdate/content_update.py
+++ /dev/null
@@ -1,180 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-try:
- import urllib2
-except ImportError:
- import urllib.request as urllib2
-
-from com.vmware.content.library.item_client import UpdateSessionModel
-from samples.vsphere.common.id_generator import generate_random_uuid
-from samples.vsphere.common.sample_base import SampleBase
-from samples.vsphere.contentlibrary.lib.cls_api_client import ClsApiClient
-from samples.vsphere.contentlibrary.lib.cls_api_helper import ClsApiHelper
-
-
-class ContentUpdate(SampleBase):
- """
- Demonstrates the workflow of updating a content library item.
-
- Note: the workflow needs an existing datastore (of type vmfs) with available storage.
- """
-
- ISO_FILE_1 = 'test.iso'
- ISO_FILE_2 = 'test-2.iso'
- ISO_ITEM_NAME = 'test'
-
- def __init__(self):
- SampleBase.__init__(self, self.__doc__)
- self.servicemanager = None
- self.client = None
- self.helper = None
- self.datastore_name = None
- self.lib_name = "demo-lib"
- self.local_library = None
-
- def _options(self):
- self.argparser.add_argument('-datastorename', '--datastorename',
- help='The name of the datastore where '
- 'the library will be created.')
-
- def _setup(self):
- self.datastore_name = self.args.datastorename
- assert self.datastore_name is not None
-
- self.servicemanager = self.get_service_manager()
- self.client = ClsApiClient(self.servicemanager)
- self.helper = ClsApiHelper(self.client, self.skip_verification)
-
- def _execute(self):
- storage_backings = self.helper.create_storage_backings(self.servicemanager,
- self.datastore_name)
-
- library_id = self.helper.create_local_library(storage_backings, self.lib_name)
- self.local_library = self.client.local_library_service.get(library_id)
- self.delete_and_upload_scenario(library_id)
- self.replace_scenario(library_id)
-
- def replace_scenario(self, library_id):
- """
- :param library_id: the Iso item will be created, and then replaced in this library
- :return: None
-
- Content update scenario 2:
- Update ISO library item by creating an update session for the
- item, then adding the new ISO file using the same session file
- name into the update session, which will replace the existing
- ISO file upon session complete.
- """
-
- iso_item_id = self.helper.create_library_item(library_id=library_id,
- item_name=self.ISO_ITEM_NAME,
- item_description='Sample iso file',
- item_type='iso')
- print('ISO Library item version (on creation) {0}:'.format(
- self.get_item_version(iso_item_id)))
-
- iso_files_map = self.helper.get_iso_file_map(item_filename=self.ISO_FILE_1,
- disk_filename=self.ISO_FILE_1)
- self.helper.upload_files(library_item_id=iso_item_id, files_map=iso_files_map)
- original_version = self.get_item_version(iso_item_id)
- print('ISO Library item version (on original content upload) {0}:'.format(
- original_version))
-
- session_id = self.client.upload_service.create(
- create_spec=UpdateSessionModel(library_item_id=iso_item_id),
- client_token=generate_random_uuid())
- # Use the same item filename (update endpoint, as it's a replace scenario)
- iso_files_map = self.helper.get_iso_file_map(item_filename=self.ISO_FILE_1,
- disk_filename=self.ISO_FILE_2)
-
- self.helper.upload_files_in_session(iso_files_map, session_id)
- self.client.upload_service.complete(session_id)
- self.client.upload_service.delete(session_id)
- updated_version = self.get_item_version(iso_item_id)
- print('ISO Library item version (after content update): {0}'.format(
- updated_version))
- assert updated_version > original_version, 'content update should increase the version'
-
- def delete_and_upload_scenario(self, library_id):
- """
- :param library_id: the OVF item will be created and updated in this library
- :return: None
-
- Content update scenario 1:
- Update OVF library item by creating an update session for the
- OVF item, removing all existing files in the session, then
- adding all new files into the same update session, and completing
- the session to finish the content update.
- """
-
- # Create a new library item in the content library for uploading the files
- ovf_item_id = self.helper.create_library_item(library_id=library_id,
- item_name='demo-ovf-item',
- item_description='Sample simple VM template',
- item_type='ovf')
- assert ovf_item_id is not None
- print('Library item created id: {0}'.format(ovf_item_id))
- print('OVF Library item version (at creation) {0}:'.format(
- self.get_item_version(ovf_item_id)))
-
- # Upload a VM template to the CL
- ovf_files_map = self.helper.get_ovf_files_map(ClsApiHelper.SIMPLE_OVF_RELATIVE_DIR)
- self.helper.upload_files(library_item_id=ovf_item_id, files_map=ovf_files_map)
- print('Uploaded ovf and vmdk files to library item {0}'.format(ovf_item_id))
- original_version = self.get_item_version(ovf_item_id)
- print('OVF Library item version (on original content upload): {0}'.format(
- original_version))
-
- # Create a new session and perform content update
- session_id = self.client.upload_service.create(
- create_spec=UpdateSessionModel(library_item_id=ovf_item_id),
- client_token=generate_random_uuid())
- existing_files = self.client.upload_file_service.list(session_id)
- for file in existing_files:
- print('deleting {0}'.format(file.name))
- self.client.upload_file_service.remove(session_id, file.name)
- ovf_files_map = self.helper.get_ovf_files_map(
- ovf_location=ClsApiHelper.PLAIN_OVF_RELATIVE_DIR)
- self.helper.upload_files_in_session(ovf_files_map, session_id)
- self.client.upload_service.complete(session_id)
- self.client.upload_service.delete(session_id)
- updated_version = self.get_item_version(ovf_item_id)
- print('OVF Library item version (after content update): {0}'.format(
- updated_version))
- assert updated_version > original_version, 'content update should increase the version'
-
- def get_item_version(self, item_id):
- ovf_item_model = self.client.library_item_service.get(item_id)
- pre_update_version = ovf_item_model.content_version
- return pre_update_version
-
- def _cleanup(self):
- if self.local_library:
- self.client.local_library_service.delete(library_id=self.local_library.id)
- print('Deleted Library Id: {0}'.format(self.local_library.id))
-
-
-def main():
- content_update_sample = ContentUpdate()
- content_update_sample.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/contentlibrary/crud/__init__.py b/samples/vsphere/contentlibrary/crud/__init__.py
deleted file mode 100644
index 25885b63..00000000
--- a/samples/vsphere/contentlibrary/crud/__init__.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/contentlibrary/crud/library_crud.py b/samples/vsphere/contentlibrary/crud/library_crud.py
deleted file mode 100644
index 8fe65d42..00000000
--- a/samples/vsphere/contentlibrary/crud/library_crud.py
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-from com.vmware.content.library_client import StorageBacking
-from com.vmware.content_client import LibraryModel
-
-from samples.vsphere.common.id_generator import generate_random_uuid
-from samples.vsphere.common.sample_base import SampleBase
-from samples.vsphere.common.vim.helpers.get_datastore_by_name import get_datastore_id
-from samples.vsphere.contentlibrary.lib.cls_api_client import ClsApiClient
-
-
-class LibraryCrud(SampleBase):
- """
- Demonstrates the basic operations of a content library. The sample also
- demonstrates the interoperability of the VIM and vAPI.
-
- Note: the workflow needs an existing VC DS with available storage.
-
- """
-
- def __init__(self):
- SampleBase.__init__(self, self.__doc__)
- self.servicemanager = None
- self.client = None
- self.datastore_name = None
- self.lib_name = "demo-local-lib"
- self.local_library = None
-
- def _options(self):
- self.argparser.add_argument('-datastorename',
- '--datastorename',
- help='The name of the datastore.')
-
- def _setup(self):
- if not self.datastore_name:
- self.datastore_name = self.args.datastorename
- assert self.datastore_name is not None
-
- if not self.servicemanager:
- self.servicemanager = self.get_service_manager()
-
- self.client = ClsApiClient(self.servicemanager)
-
- def _execute(self):
- # List of visible content libraries
- visible_cls = self.client.local_library_service.list()
- if len(visible_cls) > 0:
- for visible_cl in visible_cls:
- get_visible_cl = self.client.local_library_service.get(visible_cl)
- print('Visible content library: {0} with id: {1}'.format(get_visible_cl.name, visible_cl))
-
- # Find the datastore by the given datastore name using property collector
- self.datastore_id = get_datastore_id(service_manager=self.servicemanager, datastore_name=self.datastore_name)
- assert self.datastore_id is not None
- print('DataStore: {0} ID: {1}'.format(self.datastore_name, self.datastore_id))
-
- # Build the storage backing for the library to be created
- storage_backings = []
- storage_backing = StorageBacking(type=StorageBacking.Type.DATASTORE, datastore_id=self.datastore_id)
- storage_backings.append(storage_backing)
-
- # Build the specification for the library to be created
- create_spec = LibraryModel()
- create_spec.name = self.lib_name
- create_spec.description = "Local library backed by VC datastore"
- create_spec.type = create_spec.LibraryType.LOCAL
- create_spec.storage_backings = storage_backings
-
- # Create a local content library backed the VC datastore using vAPIs
- library_id = self.client.local_library_service.create(create_spec=create_spec,
- client_token=generate_random_uuid())
- print('Local library created: ID: {0}'.format(library_id))
-
- # Retrieve the local content library
- self.local_library = self.client.local_library_service.get(library_id)
- print('Retrieved library: ID: {0}'.format(self.local_library.id))
-
- # Update the local content library
- update_spec = LibraryModel()
- update_spec.description = "new description"
- self.client.local_library_service.update(library_id, update_spec)
- print('Updated library description')
-
- def _cleanup(self):
- if self.local_library:
- self.client.local_library_service.delete(library_id=self.local_library.id)
- print('Deleted Library Id: {0}'.format(self.local_library.id))
-
-
-def main():
- sample = LibraryCrud()
- sample.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/contentlibrary/isomount/__init__.py b/samples/vsphere/contentlibrary/isomount/__init__.py
deleted file mode 100644
index 25885b63..00000000
--- a/samples/vsphere/contentlibrary/isomount/__init__.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/contentlibrary/isomount/iso_mount.py b/samples/vsphere/contentlibrary/isomount/iso_mount.py
deleted file mode 100644
index ede1cde1..00000000
--- a/samples/vsphere/contentlibrary/isomount/iso_mount.py
+++ /dev/null
@@ -1,106 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-from samples.vsphere.common.sample_base import SampleBase
-from samples.vsphere.contentlibrary.lib.cls_api_client import ClsApiClient
-from samples.vsphere.contentlibrary.lib.cls_api_helper import ClsApiHelper
-
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-
-class IsoMount(SampleBase):
- """
- Demonstrates the content library ISO item mount and
- unmount workflow via the mount and unmount APIs from the
- ISO service.
- """
-
- ISO_FILENAME = 'test.iso'
-
- def __init__(self):
- SampleBase.__init__(self, self.__doc__)
- self.servicemanager = None
- self.client = None
- self.datastore_name = None
- self.lib_name = "iso-demo-lib"
- self.local_library = None
- self.iso_item_name = "iso-demo-lib-item"
- self.vm_name = None
-
- def _options(self):
- self.argparser.add_argument('-datastorename',
- '--datastorename',
- help='The name of a datastore (of type vmfs) that is'
- ' acceassible to the vm specified with --vmname.')
- self.argparser.add_argument('-vmname',
- '--vmname',
- help='The name of the vm where iso will be mounted. '
- 'The vm needs to be already created on the vCenter')
-
- def _setup(self):
- self.datastore_name = self.args.datastorename
- assert self.datastore_name is not None
-
- self.vm_name = self.args.vmname
- assert self.vm_name is not None
-
- self.servicemanager = self.get_service_manager()
-
- self.client = ClsApiClient(self.servicemanager)
- self.helper = ClsApiHelper(self.client, self.skip_verification)
-
- def _execute(self):
- storage_backings = self.helper.create_storage_backings(
- self.servicemanager, self.datastore_name)
-
- library_id = self.helper.create_local_library(storage_backings,
- self.lib_name)
- self.local_library = self.client.local_library_service.get(library_id)
-
- library_item_id = self.helper.create_iso_library_item(library_id,
- self.iso_item_name,
- self.ISO_FILENAME)
-
- vm_id = get_vm(self.servicemanager.stub_config, self.vm_name)
- assert vm_id is not None
-
- # Mount the iso item as a CDROM device
- device_id = self.client.iso_service.mount(library_item_id, vm_id)
- assert device_id is not None
- print('Mounted library item {0} on vm {1} at device {2}'.
- format(self.iso_item_name, self.vm_name, device_id))
- # Unmount the CDROM
- self.client.iso_service.unmount(vm_id, device_id)
- print('Unmounted library item {0} from vm {1} mounted at device {2}'.
- format(self.iso_item_name, self.vm_name, device_id))
-
- def _cleanup(self):
- if self.local_library:
- self.client.local_library_service.delete(
- library_id=self.local_library.id)
- print('Deleted Library Id: {0}'.format(self.local_library.id))
-
-
-def main():
- iso_mount_sample = IsoMount()
- iso_mount_sample.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/contentlibrary/lib/__init__.py b/samples/vsphere/contentlibrary/lib/__init__.py
deleted file mode 100644
index b069e98b..00000000
--- a/samples/vsphere/contentlibrary/lib/__init__.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
-
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
-
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/contentlibrary/lib/cls_api_client.py b/samples/vsphere/contentlibrary/lib/cls_api_client.py
deleted file mode 100644
index 217939fb..00000000
--- a/samples/vsphere/contentlibrary/lib/cls_api_client.py
+++ /dev/null
@@ -1,78 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-from com.vmware.content_client import (Library,
- LocalLibrary,
- SubscribedLibrary)
-from com.vmware.content.library_client import Item, SubscribedItem
-from com.vmware.content.library.item_client import DownloadSession
-from com.vmware.content.library.item_client import UpdateSession
-from com.vmware.content.library.item.downloadsession_client import File as DownloadSessionFile
-from com.vmware.content.library.item.updatesession_client import File as UpdateSessionFile
-from com.vmware.vcenter_client import VM
-from com.vmware.vcenter.iso_client import Image
-from com.vmware.vcenter.ovf_client import LibraryItem
-
-
-class ClsApiClient(object):
- """
- This is a simplified wrapper around the Content Library APIs.
- It is used to access services exposed by Content Library Service.
-
- """
-
- def __init__(self, service_manager):
- # Client for all the services on a management node.
- self.service_manager = service_manager
-
- # Returns the service which provides support for generic functionality
- # which can be applied equally to all types of libraries
- self.library_service = Library(self.service_manager.stub_config)
-
- # Returns the service for managing local libraries
- self.local_library_service = LocalLibrary(self.service_manager.stub_config)
-
- # Returns the service for managing subscribed libraries
- self.subscribed_library_service = SubscribedLibrary(self.service_manager.stub_config)
-
- # Returns the service for managing library items
- self.library_item_service = Item(self.service_manager.stub_config)
-
- # Returns the service for managing sessions to update or delete content
- self.upload_service = UpdateSession(self.service_manager.stub_config)
-
- # Returns the service for managing files within an update session
- self.upload_file_service = UpdateSessionFile(self.service_manager.stub_config)
-
- # Returns the service for managing sessions to download content
- self.download_service = DownloadSession(self.service_manager.stub_config)
-
- # Returns the service for managing files within a download session
- self.download_file_service = DownloadSessionFile(self.service_manager.stub_config)
-
- # Returns the service for deploying virtual machines from OVF library items
- self.ovf_lib_item_service = LibraryItem(self.service_manager.stub_config)
-
- # Returns the service for mount and unmount of an iso file on a VM
- self.iso_service = Image(self.service_manager.stub_config)
-
- # Returns the service for managing subscribed library items
- self.subscribed_item_service = SubscribedItem(self.service_manager.stub_config)
-
- # Creates the service that communicates with virtual machines
- self.vm_service = VM(self.service_manager.stub_config)
- # TODO: Add the other CLS services, eg. storage, config, type
diff --git a/samples/vsphere/contentlibrary/lib/cls_api_helper.py b/samples/vsphere/contentlibrary/lib/cls_api_helper.py
deleted file mode 100644
index 1a531c64..00000000
--- a/samples/vsphere/contentlibrary/lib/cls_api_helper.py
+++ /dev/null
@@ -1,251 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-import os
-import ssl
-import time
-
-try:
- import urllib2
-except ImportError:
- import urllib.request as urllib2
-
-from com.vmware.content_client import LibraryModel
-from com.vmware.content.library_client import (ItemModel,
- StorageBacking)
-from com.vmware.content.library.item_client import (DownloadSessionModel,
- UpdateSessionModel)
-from com.vmware.content.library.item.downloadsession_client import File as DownloadSessionFile
-from com.vmware.content.library.item.updatesession_client import File as UpdateSessionFile
-from samples.vsphere.common.id_generator import generate_random_uuid
-from samples.vsphere.common.vim.helpers.get_datastore_by_name import get_datastore_id
-
-
-class ClsApiHelper(object):
- """
- Helper class to perform commonly used operations using Content Library API.
-
- """
-
- ISO_FILE_RELATIVE_DIR = '../resources/isoImages/'
- PLAIN_OVF_RELATIVE_DIR = '../resources/plainVmTemplate'
- SIMPLE_OVF_RELATIVE_DIR = '../resources/simpleVmTemplate'
-
- def __init__(self, cls_api_client, skip_verification):
- self.client = cls_api_client
- self.skip_verification = skip_verification
-
- def get_ovf_files_map(self, ovf_location):
- """
- Get OVF template file paths to be used during uploads
-
- Note: This method returns OVF template paths for the template included
- in the SDK resources directory
- """
-
- ovf_files_map = {}
- ovf_dir = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)),
- ovf_location))
- for file_name in os.listdir(ovf_dir):
- if file_name.endswith('.ovf') or file_name.endswith('.vmdk'):
- ovf_files_map[file_name] = os.path.join(ovf_dir, file_name)
- return ovf_files_map
-
- def create_local_library(self, storage_backings, lib_name):
- """
- :param storage_backings: Storage for the library
- :param lib_name: Name of the library
- :return: id of the created library
- """
- create_spec = LibraryModel()
- create_spec.name = lib_name
- create_spec.description = "Local library backed by VC datastore"
- create_spec.type = LibraryModel.LibraryType.LOCAL
- create_spec.storage_backings = storage_backings
-
- # Create a local content library backed the VC datastore
- library_id = self.client.local_library_service.create(create_spec=create_spec,
- client_token=generate_random_uuid())
- print('Local library created, ID: {0}'.format(library_id))
-
- return library_id
-
- def create_storage_backings(self, service_manager, datastore_name):
- """
- :param service_manager:
- :param datastore_name: name of the datastore providing storage
- :return: the storage backing array
- """
-
- # Find the datastore by the given datastore name
- datastore_id = get_datastore_id(service_manager=service_manager,
- datastore_name=datastore_name)
- assert datastore_id is not None
-
- # If provided datastore is not of type vmfs, substitute the type
- # StorageBacking.Type.DATASTORE with StorageBacking.Type.OTHER
- # Build the specification for the library to be created
- storage_backings = [StorageBacking(type=StorageBacking.Type.DATASTORE,
- datastore_id=datastore_id)]
- return storage_backings
-
- def create_iso_library_item(self, library_id, iso_item_name, iso_filename):
- """
- :param library_id: item will be created on this library
- :param iso_item_name: name of the iso item to be created
- :param iso_filename: name of the iso file to be uploaded
- :return: id of the item created
- """
- # Create a new library item in the content library for uploading the files
- library_item_id = self.create_library_item(library_id=library_id,
- item_name=iso_item_name,
- item_description='Sample iso file',
- item_type='iso')
- assert library_item_id is not None
- print('Library item created id: {0}'.format(library_item_id))
-
- # Upload an iso file to above library item, use the filename as the item_filename
- iso_files_map = self.get_iso_file_map(item_filename=iso_filename, disk_filename=iso_filename)
- self.upload_files(library_item_id=library_item_id, files_map=iso_files_map)
- print('Uploaded iso file to library item {0}'.format(library_item_id))
- return library_item_id
-
- def get_iso_file_map(self, item_filename, disk_filename):
- iso_files_map = {}
- iso_file_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)),
- self.ISO_FILE_RELATIVE_DIR + disk_filename))
- iso_files_map[item_filename] = iso_file_path
- return iso_files_map
-
- def get_libraryitem_spec(self, client_token, name, description, library_id, library_item_type):
- """
- Create library item spec
-
- """
- lib_item_spec = ItemModel()
- lib_item_spec.name = name
- lib_item_spec.description = description
- lib_item_spec.library_id = library_id
- lib_item_spec.type = library_item_type
- return lib_item_spec
-
- def create_library_item(self, library_id, item_name, item_description, item_type):
- """
- Create a library item in the specified library
-
- """
- lib_item_spec = self.get_libraryitem_spec(client_token=generate_random_uuid(),
- name=item_name,
- description=item_description,
- library_id=library_id,
- library_item_type=item_type)
- # Create a library item
- return self.client.library_item_service.create(create_spec=lib_item_spec,
- client_token=generate_random_uuid())
-
- def upload_files(self, library_item_id, files_map):
- """
- Upload a VM template to the published CL
-
- """
- # Create a new upload session for uploading the files
- session_id = self.client.upload_service.create(
- create_spec=UpdateSessionModel(library_item_id=library_item_id),
- client_token=generate_random_uuid())
- self.upload_files_in_session(files_map, session_id)
- self.client.upload_service.complete(session_id)
- self.client.upload_service.delete(session_id)
-
- def upload_files_in_session(self, files_map, session_id):
- for f_name, f_path in files_map.items():
- file_spec = self.client.upload_file_service.AddSpec(name=f_name,
- source_type=UpdateSessionFile.SourceType.PUSH,
- size=os.path.getsize(f_path))
- file_info = self.client.upload_file_service.add(session_id, file_spec)
- # Upload the file content to the file upload URL
- with open(f_path, 'rb') as local_file:
- request = urllib2.Request(file_info.upload_endpoint.uri, local_file)
- request.add_header('Cache-Control', 'no-cache')
- request.add_header('Content-Length', '{0}'.format(os.path.getsize(f_path)))
- request.add_header('Content-Type', 'text/ovf')
- if self.skip_verification and hasattr(ssl, '_create_unverified_context'):
- # Python 2.7.9 has stronger SSL certificate validation,
- # so we need to pass in a context when dealing with
- # self-signed certificates.
- context = ssl._create_unverified_context()
- urllib2.urlopen(request, context=context)
- else:
- # Don't pass context parameter since versions of Python
- # before 2.7.9 don't support it.
- urllib2.urlopen(request)
-
- def download_files(self, library_item_id, directory):
- """
- Download files from a library item
-
- Args:
- library_item_id: id for the library item to download files from
- directory: location on the client machine to download the files into
-
- """
- downloaded_files_map = {}
- # create a new download session for downloading the session files
- session_id = self.client.download_service.create(create_spec=DownloadSessionModel(
- library_item_id=library_item_id),
- client_token=generate_random_uuid())
- file_infos = self.client.download_file_service.list(session_id)
- for file_info in file_infos:
- self.client.download_file_service.prepare(session_id, file_info.name)
- download_info = self.wait_for_prepare(session_id, file_info.name)
- if self.skip_verification and hasattr(ssl, '_create_unverified_context'):
- # Python 2.7.9 has stronger SSL certificate validation,
- # so we need to pass in a context when dealing with self-signed
- # certificates.
- context = ssl._create_unverified_context()
- response = urllib2.urlopen(
- url=download_info.download_endpoint.uri,
- context=context)
- else:
- # Don't pass context parameter since versions of Python
- # before 2.7.9 don't support it.
- response = urllib2.urlopen(download_info.download_endpoint.uri)
- file_path = os.path.join(directory, file_info.name)
- with open(file_path, 'wb') as local_file:
- local_file.write(response.read())
- downloaded_files_map[file_info.name] = file_path
- self.client.download_service.delete(session_id)
- return downloaded_files_map
-
- def wait_for_prepare(self, session_id, file_name,
- status_list=(DownloadSessionFile.PrepareStatus.PREPARED,),
- timeout=30, sleep_interval=1):
- """
- Waits for a file to reach a status in the status list (default: prepared)
- This method will either timeout or return the result of
- downloadSessionFile.get(session_id, file_name)
-
- """
- start_time = time.time()
- while (time.time() - start_time) < timeout:
- file_info = self.client.download_file_service.get(session_id, file_name)
- if file_info.status in status_list:
- return file_info
- else:
- time.sleep(sleep_interval)
- raise Exception(
- 'timed out after waiting {0} seconds for file {1} to reach a terminal state'.format(
- timeout, file_name))
diff --git a/samples/vsphere/contentlibrary/lib/cls_sync_helper.py b/samples/vsphere/contentlibrary/lib/cls_sync_helper.py
deleted file mode 100644
index d9e77621..00000000
--- a/samples/vsphere/contentlibrary/lib/cls_sync_helper.py
+++ /dev/null
@@ -1,132 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-import time
-
-
-class ClsSyncHelper:
- """
- Helper class to wait for the subscribed libraries and items to be
- synchronized completely with the publisher.
- """
- wait_interval_sec = 1
- start_time = None
- sync_timeout_sec = None
-
- def __init__(self, cls_api_client, sync_timeout_sec):
- self.client = cls_api_client
- self.sync_timeout_sec = sync_timeout_sec
-
- def verify_library_sync(self, pub_lib_id, sub_lib):
- """
- Wait until the subscribed library and its items are synchronized with
- the published library.
- """
- self.start_time = time.time()
- if not self.verify_same_items(pub_lib_id, sub_lib.id):
- return False
-
- sub_item_ids = self.client.library_item_service.list(sub_lib.id)
- for sub_item_id in sub_item_ids:
- if not self.verify_item_sync(sub_item_id):
- return False
-
- if not self.verify_library_last_sync_time(sub_lib):
- return False
-
- return True
-
- def verify_item_sync(self, sub_item_id):
- """
- Wait until the subscribed item is synchronized with the published item.
- """
- self.start_time = time.time()
- is_synced = False
- pub_item_id = self.client.library_item_service.get(
- sub_item_id).source_id
- pub_item = self.client.library_item_service.get(pub_item_id)
-
- while self.not_timed_out():
- sub_item = self.client.library_item_service.get(sub_item_id)
- # Verify if the subscribed item is the latest
- if (sub_item.metadata_version == pub_item.metadata_version and
- sub_item.content_version == pub_item.content_version):
- is_synced = True
- break
- time.sleep(self.wait_interval_sec)
-
- return is_synced
-
- def verify_same_items(self, pub_lib_id, sub_lib_id):
- """
- Wait until the subscribed library has the same source item IDs as the
- published library.
- """
- is_synced = False
- pub_item_ids = self.client.library_item_service.list(pub_lib_id)
-
- while self.not_timed_out():
- sub_item_ids = self.client.library_item_service.list(sub_lib_id)
-
- if self.has_same_items(pub_item_ids, sub_item_ids):
- is_synced = True
- break
- time.sleep(self.wait_interval_sec)
-
- return is_synced
-
- def verify_library_last_sync_time(self, sub_lib):
- """
- Wait until the subscribed library's last sync time is populated.
- """
- is_synced = False
-
- while self.not_timed_out():
- # Get the subscribed library's updated information from server.
- refreshed_sub_lib = self.client.subscribed_library_service.get(
- sub_lib.id)
- if refreshed_sub_lib.last_sync_time is not None:
- if (sub_lib.last_sync_time is None or
- refreshed_sub_lib.last_sync_time > sub_lib.last_sync_time):
- is_synced = True
- break
- time.sleep(self.wait_interval_sec)
-
- return is_synced
-
- def has_same_items(self, pub_item_ids, sub_item_ids):
- """
- Check if the subscribed library contains the same items as the
- published library. The item versions are not checked.
- """
- if len(pub_item_ids) != len(sub_item_ids):
- return False
- synced_item_ids = []
- for sub_item_id in sub_item_ids:
- source_id = self.client.library_item_service.get(
- sub_item_id).source_id
- if source_id not in synced_item_ids and source_id in pub_item_ids:
- synced_item_ids.append(sub_item_id)
-
- return len(pub_item_ids) == len(synced_item_ids)
-
- def not_timed_out(self):
- """
- Check if sync is not timed out yet.
- """
- elasped_time = time.time() - self.start_time
- return elasped_time < self.sync_timeout_sec
diff --git a/samples/vsphere/contentlibrary/ovfdeploy/__init__.py b/samples/vsphere/contentlibrary/ovfdeploy/__init__.py
deleted file mode 100644
index 25885b63..00000000
--- a/samples/vsphere/contentlibrary/ovfdeploy/__init__.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/contentlibrary/ovfdeploy/deploy_ovf_template.py b/samples/vsphere/contentlibrary/ovfdeploy/deploy_ovf_template.py
deleted file mode 100644
index 4f67d704..00000000
--- a/samples/vsphere/contentlibrary/ovfdeploy/deploy_ovf_template.py
+++ /dev/null
@@ -1,171 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-try:
- import urllib2
-except ImportError:
- import urllib.request as urllib2
-
-import atexit
-
-from com.vmware.content.library_client import Item
-from com.vmware.vcenter.ovf_client import LibraryItem
-from pyVmomi import vim
-
-from samples.vsphere.common import sample_cli
-from samples.vsphere.common import sample_util
-from samples.vsphere.common.id_generator import generate_random_uuid
-from samples.vsphere.common.service_manager import ServiceManager
-from samples.vsphere.common.vim.helpers.vim_utils import (
- get_obj, get_obj_by_moId, poweron_vm, poweroff_vm, delete_object)
-from samples.vsphere.contentlibrary.lib.cls_api_client import ClsApiClient
-from samples.vsphere.contentlibrary.lib.cls_api_helper import ClsApiHelper
-
-
-class DeployOvfTemplate:
- """
- Demonstrates the workflow to deploy an OVF library item to a resource pool.
- Note: the sample needs an existing library item with an OVF template
- and an existing cluster with resources for deploying the VM.
- """
-
- def __init__(self):
- self.servicemanager = None
- self.client = None
- self.helper = None
- self.cluster_name = None
- self.lib_item_name = None
- self.vm_obj = None
- self.vm_name = None
-
- def setup(self):
- parser = sample_cli.build_arg_parser()
- parser.add_argument('-n', '--vm_name',
- action='store',
- help='Name of the testing vm')
- parser.add_argument('-clustername',
- '--clustername',
- help='The name of the cluster to be used.')
- parser.add_argument('-libitemname',
- '--libitemname',
- help='The name of the library item to deploy.'
- 'The library item should contain an OVF package.')
- args = sample_util.process_cli_args(parser.parse_args())
- self.lib_item_name = args.libitemname
- self.cluster_name = args.clustername
- self.vm_name = args.vm_name
-
- self.servicemanager = ServiceManager(args.server,
- args.username,
- args.password,
- args.skipverification)
- self.servicemanager.connect()
- atexit.register(self.servicemanager.disconnect)
-
- self.client = ClsApiClient(self.servicemanager)
- self.helper = ClsApiHelper(self.client, args.skipverification)
-
- # Default VM name
- self.vm_name = 'vm-' + str(generate_random_uuid())
-
- def execute(self):
-
- # Find the cluster's resource pool moid
- cluster_obj = get_obj(self.servicemanager.content,
- [vim.ClusterComputeResource], self.cluster_name)
- assert cluster_obj is not None
- print("Cluster Moref: {0}".format(cluster_obj))
-
- deployment_target = LibraryItem.DeploymentTarget(
- resource_pool_id=cluster_obj.resourcePool._GetMoId())
-
- # Find lib item id from given item name
- find_spec = Item.FindSpec()
- find_spec.name = self.lib_item_name
- item_ids = self.client.library_item_service.find(find_spec)
- assert (item_ids is not None and len(item_ids) > 0), ('No items found with name: {0}'
- .format(self.lib_item_name))
- lib_item_id = item_ids[0]
-
- ovf_summary = self.client.ovf_lib_item_service.filter(ovf_library_item_id=lib_item_id,
- target=deployment_target)
- print('Found an OVF template :{0} to deploy.'.format(ovf_summary.name))
-
- # Deploy the ovf template
- self.deploy_ovf_template(lib_item_id, ovf_summary, deployment_target)
-
- def deploy_ovf_template(self, lib_item_id, ovf_summary, deployment_target):
- # Build the deployment spec
- deployment_spec = LibraryItem.ResourcePoolDeploymentSpec(
- name=self.vm_name,
- annotation=ovf_summary.annotation,
- accept_all_eula=True,
- network_mappings=None,
- storage_mappings=None,
- storage_provisioning=None,
- storage_profile_id=None,
- locale=None,
- flags=None,
- additional_parameters=None,
- default_datastore_id=None)
-
- # Deploy the ovf template
- result = self.client.ovf_lib_item_service.deploy(lib_item_id,
- deployment_target,
- deployment_spec,
- client_token=generate_random_uuid())
-
- # The type and ID of the target deployment is available in the deployment result.
- if result.succeeded:
- print('Deployment successful. Result resource: {0}, ID: {1}'
- .format(result.resource_id.type, result.resource_id.id))
- self.vm_id = result.resource_id.id
- error = result.error
- if error is not None:
- for warning in error.warnings:
- print('OVF warning: {}'.format(warning.message))
-
- # Power on the VM and wait for the power on operation to be completed
- self.vm_obj = get_obj_by_moId(self.servicemanager.content,
- [vim.VirtualMachine], self.vm_id)
- assert self.vm_obj is not None
- poweron_vm(self.servicemanager.content, self.vm_obj)
-
- else:
- print('Deployment failed.')
- for error in result.error.errors:
- print('OVF error: {}'.format(error.message))
-
- def cleanup(self):
- if self.vm_obj is not None:
- # Power off the VM and wait for the power off operation to complete
- poweroff_vm(self.servicemanager.content, self.vm_obj)
- # Delete the VM
- delete_object(self.servicemanager.content, self.vm_obj)
-
-
-def main():
- deploy_ovf_sample = DeployOvfTemplate()
- deploy_ovf_sample.setup()
- deploy_ovf_sample.execute()
- deploy_ovf_sample.cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/contentlibrary/ovfimport/__init__.py b/samples/vsphere/contentlibrary/ovfimport/__init__.py
deleted file mode 100644
index 25885b63..00000000
--- a/samples/vsphere/contentlibrary/ovfimport/__init__.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/contentlibrary/ovfimport/ovf_import_export.py b/samples/vsphere/contentlibrary/ovfimport/ovf_import_export.py
deleted file mode 100644
index 23035dff..00000000
--- a/samples/vsphere/contentlibrary/ovfimport/ovf_import_export.py
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-import tempfile
-try:
- import urllib2
-except ImportError:
- import urllib.request as urllib2
-
-from com.vmware.content_client import LibraryModel
-from com.vmware.content.library_client import StorageBacking
-from samples.vsphere.common.id_generator import generate_random_uuid
-from samples.vsphere.common.sample_base import SampleBase
-from samples.vsphere.contentlibrary.lib.cls_api_client import ClsApiClient
-from samples.vsphere.contentlibrary.lib.cls_api_helper import ClsApiHelper
-from samples.vsphere.common.vim.helpers.get_datastore_by_name import get_datastore_id
-
-
-class OvfImportExport(SampleBase):
- """
- Demonstrates the workflow to import an OVF package into the content library,
- as well as download of an OVF template from the content library.
-
- Note: the workflow needs an existing VC DS with available storage.
- """
-
- def __init__(self):
- SampleBase.__init__(self, self.__doc__)
- self.servicemanager = None
- self.client = None
- self.helper = None
- self.datastore_name = None
- self.lib_name = "demo-lib"
- self.local_library = None
- self.lib_item_name = "simpleVmTemplate"
- self.library_item = None
-
- def _options(self):
- self.argparser.add_argument('-datastorename',
- '--datastorename',
- help='The name of the datastore.')
-
- def _setup(self):
- self.datastore_name = self.args.datastorename
- assert self.datastore_name is not None
-
- if not self.servicemanager:
- self.servicemanager = self.get_service_manager()
-
- self.client = ClsApiClient(self.servicemanager)
- self.helper = ClsApiHelper(self.client, self.skip_verification)
-
- def _execute(self):
- # Find the datastore by the given datastore name using property collector
- self.datastore_id = get_datastore_id(service_manager=self.servicemanager, datastore_name=self.datastore_name)
- assert self.datastore_id is not None
- print('DataStore: {0} ID: {1}'.format(self.datastore_name, self.datastore_id))
-
- # Build the storage backing for the library to be created
- storage_backings = []
- storage_backing = StorageBacking(type=StorageBacking.Type.DATASTORE, datastore_id=self.datastore_id)
- storage_backings.append(storage_backing)
-
- # Build the specification for the library to be created
- create_spec = LibraryModel()
- create_spec.name = self.lib_name
- create_spec.description = "Local library backed by VC datastore"
- create_spec.type = create_spec.LibraryType.LOCAL
- create_spec.storage_backings = storage_backings
-
- # Create a local content library backed the VC datastore using vAPIs
- library_id = self.client.local_library_service.create(create_spec=create_spec,
- client_token=generate_random_uuid())
- print('Local library created: ID: {0}'.format(library_id))
- self.local_library = self.client.local_library_service.get(library_id)
-
- # Create a new library item in the content library for uploading the files
- self.library_item_id = self.helper.create_library_item(library_id=self.local_library.id,
- item_name=self.lib_item_name,
- item_description='Sample simple VM template',
- item_type='ovf')
- assert self.library_item_id is not None
- assert self.client.library_item_service.get(self.library_item_id) is not None
- print('Library item created id: {0}'.format(self.library_item_id))
-
- # Upload a VM template to the CL
- ovf_files_map = self.helper.get_ovf_files_map(ClsApiHelper.SIMPLE_OVF_RELATIVE_DIR)
- self.helper.upload_files(library_item_id=self.library_item_id, files_map=ovf_files_map)
- print('Uploaded ovf and vmdk files to library item {0}'.format(self.library_item_id))
-
- # Download the library item from the CL
- temp_dir = tempfile.mkdtemp(prefix='simpleVmTemplate-')
- print('Downloading library item {0} to directory {1}'.format(self.library_item_id, temp_dir))
- downloaded_files_map = self.helper.download_files(library_item_id=self.library_item_id, directory=temp_dir)
- assert len(downloaded_files_map) == len(ovf_files_map)
-
- def _cleanup(self):
- if self.local_library:
- self.client.local_library_service.delete(library_id=self.local_library.id)
- print('Deleted Library Id: {0}'.format(self.local_library.id))
-
-
-def main():
- sample = OvfImportExport()
- sample.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/contentlibrary/publishsubscribe/__init__.py b/samples/vsphere/contentlibrary/publishsubscribe/__init__.py
deleted file mode 100644
index 25885b63..00000000
--- a/samples/vsphere/contentlibrary/publishsubscribe/__init__.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/contentlibrary/publishsubscribe/library_publish_subscribe.py b/samples/vsphere/contentlibrary/publishsubscribe/library_publish_subscribe.py
deleted file mode 100644
index 680758e6..00000000
--- a/samples/vsphere/contentlibrary/publishsubscribe/library_publish_subscribe.py
+++ /dev/null
@@ -1,202 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-try:
- import urllib2
-except ImportError:
- import urllib.request as urllib2
-
-from com.vmware.content_client import LibraryModel
-from com.vmware.content.library_client import (ItemModel, PublishInfo,
- StorageBacking, SubscriptionInfo)
-from samples.vsphere.common.id_generator import generate_random_uuid
-from samples.vsphere.common.sample_base import SampleBase
-from samples.vsphere.contentlibrary.lib.cls_api_client import ClsApiClient
-from samples.vsphere.contentlibrary.lib.cls_api_helper import ClsApiHelper
-from samples.vsphere.contentlibrary.lib.cls_sync_helper import ClsSyncHelper
-
-
-class LibraryPublishSubscribe(SampleBase):
- """
- Demonstrates the basic sync workflow to publish and subscribe content libraries.
- Note: the workflow needs an existing VC datastore with available storage.
- """
- VCSP_USERNAME = 'vcsp'
- DEMO_PASSWORD = 'Password!23'
- SYNC_TIMEOUT_SEC = 60
- DEMO_FILENAME = 'test.iso'
-
- def __init__(self):
- SampleBase.__init__(self, self.__doc__)
- self.servicemanager = None
- self.client = None
- self.helper = None
- self.datastore_name = None
- self.pub_lib_name = "demo-publib"
- self.sub_lib_name = "demo-sublib"
- self.pub_lib_id = None
- self.sub_lib_id = None
-
- def _options(self):
- self.argparser.add_argument('-datastorename',
- '--datastorename',
- help='The name of the datastore.')
-
- def _setup(self):
- self.datastore_name = self.args.datastorename
- assert self.datastore_name is not None
-
- self.servicemanager = self.get_service_manager()
- self.client = ClsApiClient(self.servicemanager)
- self.helper = ClsApiHelper(self.client, self.skip_verification)
-
- def _execute(self):
- storage_backings = self.helper.create_storage_backings(
- self.servicemanager,
- self.datastore_name)
-
- # Create a published library backed the VC datastore using vAPIs
- self.pub_lib_id = self.create_published_library(storage_backings)
- assert self.pub_lib_id is not None
- print('Published library created: ID: {0}'.format(self.pub_lib_id))
- pub_lib = self.client.local_library_service.get(self.pub_lib_id)
- pub_lib_url = pub_lib.publish_info.publish_url
- assert pub_lib_url is not None
- print('Publish URL : {0}'.format(pub_lib_url))
-
- # Create a library item in the published library
- pub_lib_item_id = self.helper.create_iso_library_item(self.pub_lib_id,
- 'item_1',
- self.DEMO_FILENAME)
- assert self.client.library_item_service.get(pub_lib_item_id) is not None
-
- # Create the subscribed library
- sub_lib, sub_spec = self.create_subcribed_library(storage_backings,
- pub_lib_url)
- assert self.sub_lib_id is not None
- print('Subscribed library created: ID: {0}'.format(self.sub_lib_id))
-
- # It is not mandatory to verify sync, it is just for demonstrating the sample workflow.
- assert (ClsSyncHelper(self.client, self.SYNC_TIMEOUT_SEC).
- verify_library_sync(self.pub_lib_id, sub_lib))
- sub_lib = self.client.subscribed_library_service.get(self.sub_lib_id)
- print('Subscribed library synced : {0}'.format(sub_lib.last_sync_time))
-
- sub_item_ids = self.client.library_item_service.list(self.sub_lib_id)
- assert len(sub_item_ids) == 1, 'Subscribed library must have one item'
-
- # Add another item to the published library
- self.helper.create_iso_library_item(self.pub_lib_id, 'item_2',
- self.DEMO_FILENAME)
-
- # Manually synchronize the subscribed library to get the latest changes immediately.
- self.client.subscribed_library_service.sync(self.sub_lib_id)
- # It is not mandatory to verify sync, it is just for demonstrating the sample workflow.
- assert (ClsSyncHelper(self.client, self.SYNC_TIMEOUT_SEC).
- verify_library_sync(self.pub_lib_id, sub_lib))
- sub_lib = self.client.subscribed_library_service.get(self.sub_lib_id)
- print('Subscribed library synced : {0}'.format(sub_lib.last_sync_time))
-
- # List the subscribed items.
- sub_item_ids = self.client.library_item_service.list(self.sub_lib_id)
- assert len(sub_item_ids) == 2, 'Subscribed library must have two items'
- for sub_item_id in sub_item_ids:
- sub_item = self.client.library_item_service.get(sub_item_id)
- print('Subscribed item : {0}'.format(sub_item.name))
-
- # Change the subscribed library to be on-demand
- sub_spec.subscription_info.on_demand = True
- self.client.subscribed_library_service.update(self.sub_lib_id, sub_spec)
-
- # Evict the cached content of the first subscribed library item
- self.client.subscribed_item_service.evict(sub_item_id)
- sub_item = self.client.library_item_service.get(sub_item_id)
- print('Subscribed item evicted : {0}'.format(sub_item.name))
- assert not sub_item.cached, 'Subscribed item must not be cached'
-
- # Force synchronize the subscribed library item to fetch and cache the content
- self.client.subscribed_item_service.sync(sub_item_id, True)
- # It is not mandatory to verify sync, it is just for demonstrating the sample workflow.
- assert (ClsSyncHelper(self.client, self.SYNC_TIMEOUT_SEC).
- verify_item_sync(sub_item_id))
- sub_item = self.client.library_item_service.get(sub_item_id)
- print('Subscribed item force sync : {0}'.format(sub_item.name))
- assert sub_item.cached, 'Subscribed item must be cached'
-
- def create_published_library(self, storage_backings):
- # Build the authenticated publish info.
- # Note: The username will be 'vcsp'.
- pub_info = PublishInfo()
- pub_info.published = True
- pub_info.authentication_method = PublishInfo.AuthenticationMethod.BASIC
- pub_info.password = self.DEMO_PASSWORD
-
- # Build the specification for the published library to be created
- pub_spec = LibraryModel()
- pub_spec.name = self.pub_lib_name
- pub_spec.description = "Published library backed by VC datastore"
- pub_spec.publish_info = pub_info
- pub_spec.type = pub_spec.LibraryType.LOCAL
- pub_spec.storage_backings = storage_backings
-
- pub_lib_id = self.client.local_library_service.create(
- create_spec=pub_spec, client_token=generate_random_uuid())
-
- return pub_lib_id
-
- def create_subcribed_library(self, storage_backings, pub_lib_url):
- # Build the subscription information using the publish URL of the published
- # library. The username must be 'vcsp'.
- sub_info = SubscriptionInfo()
- sub_info.authentication_method = SubscriptionInfo.AuthenticationMethod.BASIC
- sub_info.user_name = self.VCSP_USERNAME
- sub_info.password = self.DEMO_PASSWORD
- sub_info.on_demand = False
- sub_info.automatic_sync_enabled = True
- sub_info.subscription_url = pub_lib_url
-
- # Build the specification for the subscribed library
- sub_spec = LibraryModel()
- sub_spec.name = self.sub_lib_name
- sub_spec.type = sub_spec.LibraryType.SUBSCRIBED
- sub_spec.subscription_info = sub_info
- sub_spec.storage_backings = storage_backings
-
- self.sub_lib_id = self.client.subscribed_library_service.create(
- create_spec=sub_spec, client_token=generate_random_uuid())
- sub_lib = self.client.subscribed_library_service.get(self.sub_lib_id)
- return sub_lib, sub_spec
-
- def _cleanup(self):
- if self.sub_lib_id:
- self.client.subscribed_library_service.delete(self.sub_lib_id)
- print('Deleted subscribed library Id: {0}'.format(self.sub_lib_id))
-
- if self.pub_lib_id:
- self.client.local_library_service.delete(self.pub_lib_id)
- print('Deleted published library Id : {0}'.format(self.pub_lib_id))
-
-
-def main():
- sample = LibraryPublishSubscribe()
- sample.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/contentlibrary/resources/isoImages/test-2.iso b/samples/vsphere/contentlibrary/resources/isoImages/test-2.iso
deleted file mode 100644
index 0b6b878b..00000000
Binary files a/samples/vsphere/contentlibrary/resources/isoImages/test-2.iso and /dev/null differ
diff --git a/samples/vsphere/contentlibrary/resources/isoImages/test.iso b/samples/vsphere/contentlibrary/resources/isoImages/test.iso
deleted file mode 100644
index 0b6b878b..00000000
Binary files a/samples/vsphere/contentlibrary/resources/isoImages/test.iso and /dev/null differ
diff --git a/samples/vsphere/contentlibrary/resources/plainVmTemplate/plain-vm.ovf b/samples/vsphere/contentlibrary/resources/plainVmTemplate/plain-vm.ovf
deleted file mode 100644
index 695df363..00000000
--- a/samples/vsphere/contentlibrary/resources/plainVmTemplate/plain-vm.ovf
+++ /dev/null
@@ -1,115 +0,0 @@
-
-
-
-
-
-
- List of the virtual disks
-
-
-
- The list of logical networks
-
- The VM Network network
-
-
-
- A Virtual system
- Plain-VM
-
- The operating system installed
- Other Linux (64-bit)
-
-
- Virtual hardware requirements
-
- Virtual Hardware Family
- 0
- vmx-11
-
- -
- hertz * 10^6
- Number of Virtual CPUs
- 1 virtual CPU(s)
- 1
- 3
- 1
- 1
-
- -
- byte * 2^20
- Memory Size
- 100MB of memory
- 2
- 4
- 100
-
- -
- 0
- SCSI Controller
- SCSI Controller 1
- 3
- lsilogic
- 6
-
-
- -
- 1
- IDE Controller
- IDE Controller 1
- 4
- 5
-
- -
- 0
- Hard Disk 1
- ovf:/disk/vmdisk1
- 5
- 3
- 17
-
- -
- 0
- true
- CD/DVD Drive 1
- 6
- 4
- vmware.cdrom.remoteatapi
- 15
-
- -
- 0
- false
- Floppy Drive
- Floppy Drive 1
- 7
- vmware.floppy.remotedevice
- 14
-
- -
- 0
- true
- VM Network
- Network adapter 1
- 8
- E1000
- 10
-
-
-
-
- -
- Video card
- 9
- 24
-
-
-
-
-
-
-
-
-
-
-
diff --git a/samples/vsphere/contentlibrary/resources/plainVmTemplate/plain-vm.vmdk b/samples/vsphere/contentlibrary/resources/plainVmTemplate/plain-vm.vmdk
deleted file mode 100644
index 8eebf5dd..00000000
Binary files a/samples/vsphere/contentlibrary/resources/plainVmTemplate/plain-vm.vmdk and /dev/null differ
diff --git a/samples/vsphere/contentlibrary/resources/simpleVmTemplate/descriptor.ovf b/samples/vsphere/contentlibrary/resources/simpleVmTemplate/descriptor.ovf
deleted file mode 100644
index d13bc87c..00000000
--- a/samples/vsphere/contentlibrary/resources/simpleVmTemplate/descriptor.ovf
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
- A Virtual system
- vmBV8ly
-
- A human-readable annotation
-
-
-
- Virtual hardware requirements
-
- Virtual Hardware Family
- System
-
-
-
-
diff --git a/samples/vsphere/contentlibrary/resources/simpleVmTemplate/disk-0.vmdk b/samples/vsphere/contentlibrary/resources/simpleVmTemplate/disk-0.vmdk
deleted file mode 100644
index 8e63b6ed..00000000
Binary files a/samples/vsphere/contentlibrary/resources/simpleVmTemplate/disk-0.vmdk and /dev/null differ
diff --git a/samples/vsphere/contentlibrary/vmcapture/__init__.py b/samples/vsphere/contentlibrary/vmcapture/__init__.py
deleted file mode 100644
index f42a9c36..00000000
--- a/samples/vsphere/contentlibrary/vmcapture/__init__.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/contentlibrary/vmcapture/vm_template_capture.py b/samples/vsphere/contentlibrary/vmcapture/vm_template_capture.py
deleted file mode 100644
index 0ae92b7e..00000000
--- a/samples/vsphere/contentlibrary/vmcapture/vm_template_capture.py
+++ /dev/null
@@ -1,129 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2013, 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-try:
- import urllib2
-except ImportError:
- import urllib.request as urllib2
-from com.vmware.vcenter.ovf_client import LibraryItem
-from samples.vsphere.common.id_generator import generate_random_uuid
-from samples.vsphere.common.sample_base import SampleBase
-from samples.vsphere.contentlibrary.lib.cls_api_client import ClsApiClient
-from samples.vsphere.contentlibrary.lib.cls_api_helper import ClsApiHelper
-
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-
-class CaptureVMTemplateToContentLibrary(SampleBase):
- """
- Demonstrates the workflow to capture a virtual machine into a content library.
-
- Note: The sample needs an existing virtual machine to capture.
- """
-
- def __init__(self):
- SampleBase.__init__(self, self.__doc__)
- self.servicemanager = None
- self.datastore_name = None
- self.datastore_id = None
- self.cl_name = "LocalLibraryToCapture"
- self.vm_name = None
- self.vm_template_name = 'CapturedOvf'
- self.vm_template_description = 'Captured OVF description'
- self.deployable_resource_type = 'VirtualMachine' # Substitute 'VirtualApp' for vApp
-
- self.content_library = None
- self.library_item_id = None
-
- def _options(self):
- self.argparser.add_argument('-datastorename', '--datastorename',
- help='The name of the datastore for'
- ' content library backing (of type vmfs)')
- self.argparser.add_argument('-vmname', '--vmname',
- help='Name of the VM to be captured')
-
- def _setup(self):
- self.datastore_name = self.args.datastorename
- assert self.datastore_name is not None
-
- self.vm_name = self.args.vmname
- assert self.vm_name is not None
-
- if self.servicemanager is None:
- self.servicemanager = self.get_service_manager()
-
- self.client = ClsApiClient(self.servicemanager)
- self.helper = ClsApiHelper(self.client, self.skip_verification)
-
- def _execute(self):
- storage_backings = self.helper.create_storage_backings(
- self.servicemanager,
- self.datastore_name)
-
- print('Creating Content Library')
- # Create a content library
- library_id = self.helper.create_local_library(storage_backings,
- self.cl_name)
- self.content_library = self.client.local_library_service.get(library_id)
-
- vm_id = get_vm(self.servicemanager.stub_config, self.vm_name)
- assert vm_id is not None
-
- param = self.create_capture_param(self.content_library,
- self.vm_template_name,
- self.vm_template_description)
- self.library_item_id = self.capture_source_vm(vm_id, param)
- assert self.library_item_id is not None
- assert self.client.library_item_service.get(self.library_item_id) is not None
- print('The VM id : {0} is captured as vm template library item id : {1}'.format
- (vm_id, self.library_item_id))
-
- def capture_source_vm(self, vm_id, param):
- source = LibraryItem.DeployableIdentity(self.deployable_resource_type,
- vm_id)
- result = self.client.ovf_lib_item_service.create(source,
- param["target"],
- param["spec"],
- client_token=generate_random_uuid())
- return result.ovf_library_item_id
-
- def create_capture_param(self, library, name, description):
- spec = LibraryItem.CreateSpec(name=name,
- description=description)
- target = LibraryItem.CreateTarget(library_id=library.id,
- library_item_id=None)
- return {"target": target, "spec": spec}
-
- def _cleanup(self):
- # delete the local library.
- if self.content_library is not None:
- self.client.local_library_service.delete(
- library_id=self.content_library.id)
- print('Deleted Library Id: {0}'.format
- (self.content_library.id))
-
-
-def main():
- vm_template_capture = CaptureVMTemplateToContentLibrary()
- vm_template_capture.main()
-
-
-# Start program
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/sso/README.md b/samples/vsphere/sso/README.md
deleted file mode 100644
index 6e569261..00000000
--- a/samples/vsphere/sso/README.md
+++ /dev/null
@@ -1,13 +0,0 @@
-This directory contains samples for Platform Service Controller, SSO and Lookup Service APIs:
-
-The vSphere Automation SDK for Python samples use the vCenter Lookup Service
-to obtain the URLs for other vSphere Automation services (SSO, vAPI, VIM, SPBM, etc.).
-The SDK contains the Lookup Service WSDL files. The samples use the python SUDS client
-for accessing the lookup service. The Lookup Service WSDL files are located in wsdl/ directory.
-
-Running the samples
-```cmd
-$ python external_psc_sso_workflow.py --lsurl https:///lookupservice/sdk -u 'administrator@vsphere.local' -p 'Admin!23' -v
-```
-* Testbed Requirement:
- - 1 vCenter Server
diff --git a/samples/vsphere/sso/__init__.py b/samples/vsphere/sso/__init__.py
deleted file mode 100644
index a5f55463..00000000
--- a/samples/vsphere/sso/__init__.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
-
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
-
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/sso/embedded_psc_sso_workflow.py b/samples/vsphere/sso/embedded_psc_sso_workflow.py
deleted file mode 100644
index c6083ad5..00000000
--- a/samples/vsphere/sso/embedded_psc_sso_workflow.py
+++ /dev/null
@@ -1,134 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-import requests
-from com.vmware.cis.tagging_client import (Category, CategoryModel)
-from com.vmware.cis_client import Session
-from vmware.vapi.lib.connect import get_requests_connector
-from vmware.vapi.security.session import create_session_security_context
-from vmware.vapi.security.sso import create_saml_bearer_security_context
-from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
-
-from samples.vsphere.common import sample_cli
-from samples.vsphere.common import sample_util
-from samples.vsphere.common import sso
-from samples.vsphere.common.ssl_helper import get_unverified_context
-from samples.vsphere.common.vapiconnect import create_unverified_session
-
-
-class EmbeddedPscSsoWorkflow(object):
- """
- Demonstrates how to Login to vCenter vAPI service with
- embedded Platform Services Controller.
- """
-
- def __init__(self):
- self.args = None
- self.session = None
- self.session_id = None
- self.category_svc = None
- self.category_id = None
-
- def setup(self):
- parser = sample_cli.build_arg_parser()
- self.args = sample_util.process_cli_args(parser.parse_args())
-
- def run(self):
- print('\n\n#### Example: Login to vCenter server with '
- 'embedded Platform Services Controller')
-
- # Since the platform services controller is embedded, the sso server
- # is the same as the vCenter server.
- ssoUrl = 'https://{}/sts/STSService'.format(self.args.server)
-
- print('\nStep 1: Connect to the Single Sign-On URL and '
- 'retrieve the SAML bearer token.')
-
- authenticator = sso.SsoAuthenticator(ssoUrl)
- context = None
- if self.args.skipverification:
- context = get_unverified_context()
- bearer_token = authenticator.get_bearer_saml_assertion(
- self.args.username,
- self.args.password,
- delegatable=True,
- ssl_context=context)
-
- # Creating SAML Bearer Security Context
- sec_ctx = create_saml_bearer_security_context(bearer_token)
-
- print('\nStep 2. Login to vAPI services using the SAML bearer token.')
-
- # The URL for the stub requests are made against the /api HTTP endpoint
- # of the vCenter system.
- vapi_url = 'https://{}/api'.format(self.args.server)
-
- # Create an authenticated stub configuration object that can be used to
- # issue requests against vCenter.
- session = requests.Session()
- if self.args.skipverification:
- session = create_unverified_session(session)
- connector = get_requests_connector(session=session, url=vapi_url)
- connector.set_security_context(sec_ctx)
- stub_config = StubConfigurationFactory.new_std_configuration(
- connector)
- self.session = Session(stub_config)
-
- # Login to VAPI endpoint and get the session_id
- self.session_id = self.session.create()
-
- # Update the VAPI connection with session_id
- session_sec_ctx = create_session_security_context(self.session_id)
- connector.set_security_context(session_sec_ctx)
-
- # Create and Delete TagCategory to Verify connection is successful
- print('\nStep 3: Creating and Deleting Tag Category...\n')
- self.category_svc = Category(stub_config)
-
- self.category_id = self.create_tag_category('TestTagCat', 'TestTagDesc',
- CategoryModel.Cardinality.MULTIPLE)
- assert self.category_id is not None
- print('Tag category created; Id: {0}\n'.format(self.category_id))
-
- # Delete TagCategory
- self.category_svc.delete(self.category_id)
-
- self.session.delete()
- print('VAPI session disconnected successfully...')
-
- def create_tag_category(self, name, description, cardinality):
- """create a category. User who invokes this needs create category privilege."""
- create_spec = self.category_svc.CreateSpec()
- create_spec.name = name
- create_spec.description = description
- create_spec.cardinality = cardinality
- associableTypes = set()
- create_spec.associable_types = associableTypes
- return self.category_svc.create(create_spec)
-
-
-def main():
- embedded_psc_sso_workflow = EmbeddedPscSsoWorkflow()
- embedded_psc_sso_workflow.setup()
- embedded_psc_sso_workflow.run()
-
-
-# Start program
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/sso/external_psc_sso_workflow.py b/samples/vsphere/sso/external_psc_sso_workflow.py
deleted file mode 100644
index 350aee0e..00000000
--- a/samples/vsphere/sso/external_psc_sso_workflow.py
+++ /dev/null
@@ -1,213 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-import os
-import argparse
-import requests
-from pprint import pprint
-
-from six.moves.urllib import request, parse
-
-from com.vmware.cis_client import Session
-
-from vmware.vapi.lib.connect import get_requests_connector
-from vmware.vapi.security.session import create_session_security_context
-from vmware.vapi.security.sso import create_saml_bearer_security_context
-from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
-from com.vmware.cis.tagging_client import (Category, CategoryModel)
-
-from samples.vsphere.common import sso
-from samples.vsphere.common.lookup_service_helper import LookupServiceHelper
-from samples.vsphere.common.ssl_helper import get_unverified_context
-from samples.vsphere.common.vapiconnect import create_unverified_session
-
-
-class ExternalPscSsoWorkflow(object):
- """
- Demonstrates how to Login to vCenter vAPI service with
- external Platform Services Controller.
- """
-
- def __init__(self):
- self.lswsdl = None
- self.lsurl = None
- self.mgmtinstancename = None
- self.username = None
- self.password = None
- self.session = None
- self.session_id = None
- self.args = None
- self.argparser = None
- self.mgmtinstancename = None
- self.skip_verification = False
- self.category_svc = None
- self.category_id = None
-
- def options(self):
- self.argparser = argparse.ArgumentParser(description=self.__doc__)
- # setup the argument parser
- self.argparser.add_argument('-w', '--lswsdl',
- help='Path to the Lookup Service WSDL. '
- 'By default, lookupservice.wsdl in '
- '../wsdl will be used if the parameter'
- ' is absent')
- self.argparser.add_argument('-s', '--lsurl', help='Lookup service URL')
- self.argparser.add_argument('-m', '--mgmtinstancename',
- help='Instance name of the vCenter Server '
- 'management node. '
- 'When only one node is registered, '
- 'it is selected by default; otherwise,'
- ' omit the parameter to get a list of '
- 'available nodes.')
- self.argparser.add_argument('-u', '--username', help='SSO user name')
- self.argparser.add_argument('-p', '--password',
- help='SSO user password')
- self.argparser.add_argument('-v', '--skipverification',
- action='store_true',
- help='Do not verify server certificate')
- self.args = self.argparser.parse_args()
-
- def setup(self):
- if self.args.lswsdl:
- self.lswsdl = os.path.abspath(self.args.lswsdl)
- else:
- self.lswsdl = os.path.join(
- os.path.dirname(os.path.abspath(__file__)),
- 'wsdl',
- 'lookupservice.wsdl')
- assert self.lswsdl is not None
- print('lswsdl: {0}'.format(self.lswsdl))
-
- self.lsurl = self.args.lsurl
- assert self.lsurl is not None
- print('lsurl: {0}'.format(self.lsurl))
-
- self.username = self.args.username
- assert self.username is not None
-
- self.password = self.args.password
- assert self.password is not None
-
- self.mgmtinstancename = self.args.mgmtinstancename
- self.skip_verification = self.args.skipverification
-
- def run(self):
- print('\n\n#### Example: Login to vCenter server with '
- 'external Platform Services Controller')
-
- print('\nStep 1: Connect to the lookup service on the '
- 'Platform Services Controller node: {0}'.format(self.lsurl))
-
- # Convert wsdl path to url
- self.lswsdl = parse.urljoin('file:', request.pathname2url(self.lswsdl))
- lookupservicehelper = LookupServiceHelper(wsdl_url=self.lswsdl,
- soap_url=self.lsurl,
- skip_verification=self.skip_verification)
- lookupservicehelper.connect()
-
- if self.mgmtinstancename is None:
- self.mgmtinstancename, self.mgmtnodeid = lookupservicehelper.get_default_mgmt_node()
- elif self.mgmtnodeid is None:
- self.mgmtnodeid = lookupservicehelper.get_mgmt_node_id(
- self.mgmtinstancename)
- assert self.mgmtnodeid is not None
-
- print('\nStep 2: Discover the Single Sign-On service URL'
- ' from lookup service.')
- sso_url = lookupservicehelper.find_sso_url()
- print('Sso URL: {0}'.format(sso_url))
-
- print('\nStep 3: Connect to the Single Sign-On URL and '
- 'retrieve the SAML bearer token.')
- authenticator = sso.SsoAuthenticator(sso_url)
- context = None
- if self.skip_verification:
- context = get_unverified_context()
- bearer_token = authenticator.get_bearer_saml_assertion(
- self.username,
- self.password,
- delegatable=True,
- ssl_context=context)
-
- # Creating SAML Bearer Security Context
- sec_ctx = create_saml_bearer_security_context(bearer_token)
-
- print('\nStep 4. Discover the vAPI service URL from lookup service.')
- vapi_url = lookupservicehelper.find_vapi_url(self.mgmtnodeid)
- print('vAPI URL: {0}'.format(vapi_url))
-
- print('\nStep 5. Login to vAPI service using the SAML bearer token.')
-
- # Create an authenticated stub configuration object that can be used to
- # issue requests against vCenter.
- session = requests.Session()
- if self.skip_verification:
- session = create_unverified_session(session)
- connector = get_requests_connector(session=session, url=vapi_url)
- connector.set_security_context(sec_ctx)
- stub_config = StubConfigurationFactory.new_std_configuration(
- connector)
- self.session = Session(stub_config)
-
- # Login to VAPI endpoint and get the session_id
- self.session_id = self.session.create()
-
- # Update the VAPI connection with session_id
- session_sec_ctx = create_session_security_context(self.session_id)
- connector.set_security_context(session_sec_ctx)
-
- # Create and Delete TagCategory to Verify connection is successful
- print('\nStep 6: Creating and Deleting Tag Category...\n')
- self.category_svc = Category(stub_config)
-
- self.category_id = self.create_tag_category('TestTagCat', 'TestTagDesc',
- CategoryModel.Cardinality.MULTIPLE)
- assert self.category_id is not None
- print('Tag category created; Id: {0}\n'.format(self.category_id))
-
- # Delete TagCategory
- self.category_svc.delete(self.category_id)
-
- self.session.delete()
- print('VAPI session disconnected successfully...')
-
- def create_tag_category(self, name, description, cardinality):
- """create a category. User who invokes this needs create category privilege."""
- create_spec = self.category_svc.CreateSpec()
- create_spec.name = name
- create_spec.description = description
- create_spec.cardinality = cardinality
- associableTypes = set()
- create_spec.associable_types = associableTypes
- return self.category_svc.create(create_spec)
-
- self.session.delete()
- print('VAPI session disconnected successfully...')
-
-
-def main():
- external_psc_sso_workflow = ExternalPscSsoWorkflow()
- external_psc_sso_workflow.options()
- external_psc_sso_workflow.setup()
- external_psc_sso_workflow.run()
-
-
-# Start program
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/sso/wsdl/lookup.wsdl b/samples/vsphere/sso/wsdl/lookup.wsdl
deleted file mode 100644
index 9943f17f..00000000
--- a/samples/vsphere/sso/wsdl/lookup.wsdl
+++ /dev/null
@@ -1,922 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/samples/vsphere/sso/wsdl/lookupservice.wsdl b/samples/vsphere/sso/wsdl/lookupservice.wsdl
deleted file mode 100644
index 9217a8b6..00000000
--- a/samples/vsphere/sso/wsdl/lookupservice.wsdl
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/samples/vsphere/tagging/README.md b/samples/vsphere/tagging/README.md
deleted file mode 100644
index b9df6415..00000000
--- a/samples/vsphere/tagging/README.md
+++ /dev/null
@@ -1,10 +0,0 @@
-This directory contains samples for Tagging APIs:
-
-Running the samples
-
- $ python tagging_workflow.py --server --username --password --clustername --categoryname --categorydesc --tagname -tagdesc -v
-
-* Testbed Requirement:
- - 1 vCenter Server
- - 1 cluster
-
diff --git a/samples/vsphere/tagging/__init__.py b/samples/vsphere/tagging/__init__.py
deleted file mode 100644
index f42a9c36..00000000
--- a/samples/vsphere/tagging/__init__.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/tagging/tagging_workflow.py b/samples/vsphere/tagging/tagging_workflow.py
deleted file mode 100644
index ede4b894..00000000
--- a/samples/vsphere/tagging/tagging_workflow.py
+++ /dev/null
@@ -1,215 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2014, 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2014, 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.0+'
-
-import time
-
-from com.vmware.cis.tagging_client import (
- Category, CategoryModel, Tag, TagAssociation)
-from com.vmware.vapi.std_client import DynamicID
-
-from samples.vsphere.common.sample_base import SampleBase
-from samples.vsphere.common.vim.helpers.get_cluster_by_name import get_cluster_id
-
-
-class TaggingWorkflow(SampleBase):
- """
- Demonstrates tagging CRUD operations
- Step 1: Create a Tag category.
- Step 2: Create a Tag under the category.
- Step 3: Retrieve the managed object id of an existing cluster from its name.
- Step 4: Assign the tag to the cluster.
- Additional steps when clearData flag is set to TRUE:
- Step 5: Detach the tag from the cluster.
- Step 6: Delete the tag.
- Step 7: Delete the tag category.
- Note: the sample needs an existing cluster
- """
-
- def __init__(self):
- SampleBase.__init__(self, self.__doc__)
- self.servicemanager = None
-
- self.category_svc = None
- self.tag_svc = None
- self.tag_association = None
-
- self.category_name = None
- self.category_desc = None
- self.tag_name = None
- self.tag_desc = None
-
- self.cluster_name = None
- self.cluster_moid = None
- self.category_id = None
- self.tag_id = None
- self.tag_attached = False
- self.dynamic_id = None
-
- def _options(self):
- self.argparser.add_argument('-clustername', '--clustername', help='Name of the cluster to be tagged')
- self.argparser.add_argument('-categoryname', '--categoryname', help='Name of the Category to be created')
- self.argparser.add_argument('-categorydesc', '--categorydesc', help='Description of the Category to be created')
- self.argparser.add_argument('-tagname', '--tagname', help='Name of the tag to be created')
- self.argparser.add_argument('-tagdesc', '--tagdesc', help='Description of the tag to be created')
-
- def _setup(self):
- if self.cluster_name is None: # for testing
- self.cluster_name = self.args.clustername
- assert self.cluster_name is not None
- print('Cluster Name: {0}'.format(self.cluster_name))
-
- if self.category_name is None:
- self.category_name = self.args.categoryname
- assert self.category_name is not None
- print('Category Name: {0}'.format(self.category_name))
-
- if self.category_desc is None:
- self.category_desc = self.args.categorydesc
- assert self.category_desc is not None
- print('Category Description: {0}'.format(self.category_desc))
-
- if self.tag_name is None:
- self.tag_name = self.args.tagname
- assert self.tag_name is not None
- print('Tag Name: {0}'.format(self.tag_name))
-
- if self.tag_desc is None:
- self.tag_desc = self.args.tagdesc
- assert self.tag_desc is not None
- print('Tag Description: {0}'.format(self.tag_desc))
-
- if self.servicemanager is None:
- self.servicemanager = self.get_service_manager()
-
- # Sample is not failing if Clustername passed is not valid
- # Validating if Cluster Name passed is Valid
- print('finding the cluster {0}'.format(self.cluster_name))
- self.cluster_moid = get_cluster_id(service_manager=self.servicemanager, cluster_name=self.cluster_name)
- assert self.cluster_moid is not None
- print('Found cluster:{0} mo_id:{1}'.format(self.cluster_name, self.cluster_moid))
-
- self.category_svc = Category(self.servicemanager.stub_config)
- self.tag_svc = Tag(self.servicemanager.stub_config)
- self.tag_association = TagAssociation(self.servicemanager.stub_config)
-
- def _execute(self):
- print('List all the existing categories user has access to...')
- categories = self.category_svc.list()
- if len(categories) > 0:
- for category in categories:
- print('Found Category: {0}'.format(category))
- else:
- print('No Tag Category Found...')
-
- print('List all the existing tags user has access to...')
- tags = self.tag_svc.list()
- if len(tags) > 0:
- for tag in tags:
- print('Found Tag: {0}'.format(tag))
- else:
- print('No Tag Found...')
-
- print('creating a new tag category...')
- self.category_id = self.create_tag_category(self.category_name, self.category_desc,
- CategoryModel.Cardinality.MULTIPLE)
- assert self.category_id is not None
- print('Tag category created; Id: {0}'.format(self.category_id))
-
- print("creating a new Tag...")
- self.tag_id = self.create_tag(self.tag_name, self.tag_desc, self.category_id)
- assert self.tag_id is not None
- print('Tag created; Id: {0}'.format(self.tag_id))
-
- print('updating the tag...')
- date_time = time.strftime('%d/%m/%Y %H:%M:%S')
- self.update_tag(self.tag_id, 'Server Tag updated at ' + date_time)
- print('Tag updated; Id: {0}'.format(self.tag_id))
-
- print('Tagging the cluster {0}...'.format(self.cluster_name))
- self.dynamic_id = DynamicID(type='ClusterComputeResource', id=self.cluster_moid)
- self.tag_association.attach(tag_id=self.tag_id, object_id=self.dynamic_id)
- for tag_id in self.tag_association.list_attached_tags(self.dynamic_id):
- if tag_id == self.tag_id:
- self.tag_attached = True
- break
- assert self.tag_attached
- print('Tagged cluster: {0}'.format(self.cluster_moid))
-
- def _cleanup(self):
- try:
- if self.tag_attached:
- self.tag_association.detach(self.tag_id, self.dynamic_id)
- print('Removed tag from cluster: {0}'.format(self.cluster_moid))
-
- if self.tag_id is not None:
- self.delete_tag(self.tag_id)
- print('Tag deleted; Id: {0}'.format(self.tag_id))
-
- if self.category_id is not None:
- self.delete_tag_category(self.category_id)
- print('Tag category deleted; Id: {0}'.format(self.category_id))
- except Exception as e:
- raise Exception(e)
-
- def create_tag_category(self, name, description, cardinality):
- """create a category. User who invokes this needs create category privilege."""
- create_spec = self.category_svc.CreateSpec()
- create_spec.name = name
- create_spec.description = description
- create_spec.cardinality = cardinality
- associableTypes = set()
- create_spec.associable_types = associableTypes
- return self.category_svc.create(create_spec)
-
- def delete_tag_category(self, category_id):
- """Deletes an existing tag category; User who invokes this API needs
- delete privilege on the tag category.
- """
- self.category_svc.delete(category_id)
-
- def create_tag(self, name, description, category_id):
- """Creates a Tag"""
- create_spec = self.tag_svc.CreateSpec()
- create_spec.name = name
- create_spec.description = description
- create_spec.category_id = category_id
- return self.tag_svc.create(create_spec)
-
- def update_tag(self, tag_id, description):
- """Update the description of an existing tag.
- User who invokes this API needs edit privilege on the tag.
- """
- update_spec = self.tag_svc.UpdateSpec()
- update_spec.setDescription = description
- self.tag_svc.update(tag_id, update_spec)
-
- def delete_tag(self, tag_id):
- """Delete an existing tag.
- User who invokes this API needs delete privilege on the tag."""
- self.tag_svc.delete(tag_id)
-
-
-def main():
- tagging_workflow = TaggingWorkflow()
- tagging_workflow.main()
-
-
-# Start program
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/README.md b/samples/vsphere/vcenter/README.md
deleted file mode 100644
index ea701e42..00000000
--- a/samples/vsphere/vcenter/README.md
+++ /dev/null
@@ -1,15 +0,0 @@
-This directory contains samples for the vSphere infrastructure and virtual machine APIs. You have two options to run samples inside this package:
-
-* 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.
-
-* 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.
-
- For example, to run the create_default_vm sample in the vsphere.samples.vcenter.vm.create package:
-
- * with the testbed settings specified in testbed.py in a Linux machine:
-
- $ python samples/vsphere/vcenter/vm/create/create_default_vm.py -v
-
- * Or specify the credentials using command line parameters:
-
- $ python samples/vsphere/vcenter/vm/create/create_default_vm.py -s -u -p -v
diff --git a/samples/vsphere/vcenter/__init__.py b/samples/vsphere/vcenter/__init__.py
deleted file mode 100644
index 42b8a50b..00000000
--- a/samples/vsphere/vcenter/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/vcenter/helper/__init__.py b/samples/vsphere/vcenter/helper/__init__.py
deleted file mode 100644
index 42b8a50b..00000000
--- a/samples/vsphere/vcenter/helper/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/vcenter/helper/cluster_helper.py b/samples/vsphere/vcenter/helper/cluster_helper.py
deleted file mode 100644
index df26463c..00000000
--- a/samples/vsphere/vcenter/helper/cluster_helper.py
+++ /dev/null
@@ -1,46 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-from com.vmware.vcenter_client import Cluster
-
-from samples.vsphere.vcenter.helper import datacenter_helper
-
-
-def get_cluster(stub_config, datacenter_name, cluster_name):
- """
- Returns the identifier of a cluster
- Note: The method assumes only one cluster and datacenter
- with the mentioned name.
- """
-
- datacenter = datacenter_helper.get_datacenter(stub_config, datacenter_name)
- if not datacenter:
- print("Datacenter '{}' not found".format(datacenter_name))
- return None
-
- filter_spec = Cluster.FilterSpec(names=set([cluster_name]),
- datacenters=set([datacenter]))
-
- cluster_svc = Cluster(stub_config)
- cluster_summaries = cluster_svc.list(filter_spec)
- if len(cluster_summaries) > 0:
- cluster = cluster_summaries[0].cluster
- print("Detected cluster '{}' as {}".format(cluster_name, cluster))
- return cluster
- else:
- print("Cluster '{}' not found".format(cluster_name))
- return None
diff --git a/samples/vsphere/vcenter/helper/datacenter_helper.py b/samples/vsphere/vcenter/helper/datacenter_helper.py
deleted file mode 100644
index 24f8f70f..00000000
--- a/samples/vsphere/vcenter/helper/datacenter_helper.py
+++ /dev/null
@@ -1,35 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-from com.vmware.vcenter_client import Datacenter
-
-
-def get_datacenter(stub_config, datacenter_name):
- """
- Returns the identifier of a datacenter
- Note: The method assumes only one datacenter with the mentioned name.
- """
-
- filter_spec = Datacenter.FilterSpec(names=set([datacenter_name]))
-
- datacenter_svc = Datacenter(stub_config)
- datacenter_summaries = datacenter_svc.list(filter_spec)
- if len(datacenter_summaries) > 0:
- datacenter = datacenter_summaries[0].datacenter
- return datacenter
- else:
- return None
diff --git a/samples/vsphere/vcenter/helper/datastore_helper.py b/samples/vsphere/vcenter/helper/datastore_helper.py
deleted file mode 100644
index 3dc721e4..00000000
--- a/samples/vsphere/vcenter/helper/datastore_helper.py
+++ /dev/null
@@ -1,43 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-from com.vmware.vcenter_client import Datastore
-
-from samples.vsphere.vcenter.helper import datacenter_helper
-
-
-def get_datastore(stub_config, datacenter_name, datastore_name):
- """
- Returns the identifier of a datastore
- Note: The method assumes that there is only one datastore and datacenter
- with the mentioned names.
- """
- datacenter = datacenter_helper.get_datacenter(stub_config, datacenter_name)
- if not datacenter:
- print("Datacenter '{}' not found".format(datacenter_name))
- return None
-
- filter_spec = Datastore.FilterSpec(names=set([datastore_name]),
- datacenters=set([datacenter]))
-
- datastore_svc = Datastore(stub_config)
- datastore_summaries = datastore_svc.list(filter_spec)
- if len(datastore_summaries) > 0:
- datastore = datastore_summaries[0].datastore
- return datastore
- else:
- return None
diff --git a/samples/vsphere/vcenter/helper/folder_helper.py b/samples/vsphere/vcenter/helper/folder_helper.py
deleted file mode 100644
index b2bc1543..00000000
--- a/samples/vsphere/vcenter/helper/folder_helper.py
+++ /dev/null
@@ -1,46 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-from com.vmware.vcenter_client import Folder
-
-from samples.vsphere.vcenter.helper import datacenter_helper
-
-
-def get_folder(stub_config, datacenter_name, folder_name):
- """
- Returns the identifier of a folder
- Note: The method assumes that there is only one folder and datacenter
- with the mentioned names.
- """
- datacenter = datacenter_helper.get_datacenter(stub_config, datacenter_name)
- if not datacenter:
- print("Datacenter '{}' not found".format(datacenter_name))
- return None
-
- filter_spec = Folder.FilterSpec(type=Folder.Type.VIRTUAL_MACHINE,
- names=set([folder_name]),
- datacenters=set([datacenter]))
-
- folder_svc = Folder(stub_config)
- folder_summaries = folder_svc.list(filter_spec)
- if len(folder_summaries) > 0:
- folder = folder_summaries[0].folder
- print("Detected folder '{}' as {}".format(folder_name, folder))
- return folder
- else:
- print("Folder '{}' not found".format(folder_name))
- return None
diff --git a/samples/vsphere/vcenter/helper/network_helper.py b/samples/vsphere/vcenter/helper/network_helper.py
deleted file mode 100644
index 5893fdb5..00000000
--- a/samples/vsphere/vcenter/helper/network_helper.py
+++ /dev/null
@@ -1,82 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-from com.vmware.vcenter_client import Network
-
-from samples.vsphere.vcenter.helper import datacenter_helper
-
-
-def get_standard_network_backing(stub_config,
- std_porggroup_name,
- datacenter_name):
- """
- Gets a standard portgroup network backing for a given Datacenter
- Note: The method assumes that there is only one standard portgroup
- and datacenter with the mentioned names.
- """
- datacenter = datacenter_helper.get_datacenter(stub_config, datacenter_name)
- if not datacenter:
- print("Datacenter '{}' not found".format(datacenter_name))
- return None
-
- network_svc = Network(stub_config)
- filter = Network.FilterSpec(datacenters=set([datacenter]),
- names=set([std_porggroup_name]),
- types=set([Network.Type.STANDARD_PORTGROUP]))
- network_summaries = network_svc.list(filter=filter)
-
- network = None
- if len(network_summaries) > 0:
- network = network_summaries[0].network
- print("Selecting Standard Portgroup Network '{}' ({})".
- format(std_porggroup_name, network))
- return network
- else:
- print("Standard Portgroup Network not found in Datacenter '{}'".
- format(datacenter_name))
- return None
-
-
-def get_distributed_network_backing(stub_config,
- dv_portgroup_name,
- datacenter_name):
- """
- Gets a distributed portgroup network backing for a given Datacenter
- Note: The method assumes that there is only one distributed portgroup
- and datacenter with the mentioned names.
- """
- datacenter = datacenter_helper.get_datacenter(stub_config, datacenter_name)
- if not datacenter:
- print("Datacenter '{}' not found".format(datacenter_name))
- return None
-
- network_svc = Network(stub_config)
- filter = Network.FilterSpec(datacenters=set([datacenter]),
- names=set([dv_portgroup_name]),
- types=set([Network.Type.DISTRIBUTED_PORTGROUP]))
- network_summaries = network_svc.list(filter=filter)
-
- network = None
- if len(network_summaries) > 0:
- network = network_summaries[0].network
- print("Selecting Distributed Portgroup Network '{}' ({})".
- format(dv_portgroup_name, network))
- return network
- else:
- print("Distributed Portgroup Network not found in Datacenter '{}'".
- format(datacenter_name))
- return None
diff --git a/samples/vsphere/vcenter/helper/resource_pool_helper.py b/samples/vsphere/vcenter/helper/resource_pool_helper.py
deleted file mode 100644
index 76b63de6..00000000
--- a/samples/vsphere/vcenter/helper/resource_pool_helper.py
+++ /dev/null
@@ -1,43 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-from com.vmware.vcenter_client import ResourcePool
-
-from samples.vsphere.vcenter.helper import datacenter_helper
-
-
-def get_resource_pool(stub_config, datacenter_name):
- """
- Returns the identifier of the first resourcepool in the datacenter
- """
- datacenter = datacenter_helper.get_datacenter(stub_config, datacenter_name)
- if not datacenter:
- print("Datacenter '{}' not found".format(datacenter_name))
- return None
-
- filter_spec = ResourcePool.FilterSpec(datacenters=set([datacenter]))
-
- resource_pool_svc = ResourcePool(stub_config)
- resource_pool_summaries = resource_pool_svc.list(filter_spec)
- if len(resource_pool_summaries) > 0:
- resource_pool = resource_pool_summaries[0].resource_pool
- print("Selecting ResourcePool '{}'".format(resource_pool))
- return resource_pool
- else:
- print("ResourcePool not found in Datacenter '{}'".
- format(datacenter_name))
- return None
diff --git a/samples/vsphere/vcenter/helper/vm_helper.py b/samples/vsphere/vcenter/helper/vm_helper.py
deleted file mode 100644
index dd678827..00000000
--- a/samples/vsphere/vcenter/helper/vm_helper.py
+++ /dev/null
@@ -1,49 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-from com.vmware.vcenter_client import VM
-
-
-def get_vm(stub_config, vm_name):
- """
- Return the identifier of a vm
- Note: The method assumes that there is only one vm with the mentioned name.
- """
- vm_svc = VM(stub_config)
- names = set([vm_name])
- vms = vm_svc.list(VM.FilterSpec(names=names))
-
- if len(vms) == 0:
- print("VM with name ({}) not found".format(vm_name))
- return None
-
- vm = vms[0].vm
- print("Found VM '{}' ({})".format(vm_name, vm))
- return vm
-
-
-def get_vms(stub_config, vm_names):
- """Return identifiers of a list of vms"""
- vm_svc = VM(stub_config)
- vms = vm_svc.list(VM.FilterSpec(names=vm_names))
-
- if len(vms) == 0:
- print('No vm found')
- return None
-
- print("Found VMs '{}' ({})".format(vm_names, vms))
- return vms
diff --git a/samples/vsphere/vcenter/helper/vm_placement_helper.py b/samples/vsphere/vcenter/helper/vm_placement_helper.py
deleted file mode 100644
index 35464d2f..00000000
--- a/samples/vsphere/vcenter/helper/vm_placement_helper.py
+++ /dev/null
@@ -1,52 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-from com.vmware.vcenter_client import VM
-
-from samples.vsphere.vcenter.helper import datastore_helper
-from samples.vsphere.vcenter.helper import folder_helper
-from samples.vsphere.vcenter.helper import resource_pool_helper
-
-
-def get_placement_spec_for_resource_pool(stub_config,
- datacenter_name,
- vm_folder_name,
- datastore_name):
- """
- Returns a VM placement spec for a resourcepool. Ensures that the
- vm folder and datastore are all in the same datacenter which is specified.
- """
- resource_pool = resource_pool_helper.get_resource_pool(stub_config,
- datacenter_name)
-
- folder = folder_helper.get_folder(stub_config,
- datacenter_name,
- vm_folder_name)
-
- datastore = datastore_helper.get_datastore(stub_config,
- datacenter_name,
- datastore_name)
-
- # Create the vm placement spec with the datastore, resource pool and vm
- # folder
- placement_spec = VM.PlacementSpec(folder=folder,
- resource_pool=resource_pool,
- datastore=datastore)
-
- print("get_placement_spec_for_resource_pool: Result is '{}'".
- format(placement_spec))
- return placement_spec
diff --git a/samples/vsphere/vcenter/setup/README.md b/samples/vsphere/vcenter/setup/README.md
deleted file mode 100644
index b1239df9..00000000
--- a/samples/vsphere/vcenter/setup/README.md
+++ /dev/null
@@ -1,2 +0,0 @@
-This directory contains sample scripts to setup the testbed required to run
-the vCenter APIs samples. Refer see [README](../../../../README.md#running-the-sdk-sample-setup-script) for more details.
diff --git a/samples/vsphere/vcenter/setup/__init__.py b/samples/vsphere/vcenter/setup/__init__.py
deleted file mode 100644
index 42b8a50b..00000000
--- a/samples/vsphere/vcenter/setup/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/vcenter/setup/backend_directory.py b/samples/vsphere/vcenter/setup/backend_directory.py
deleted file mode 100644
index 4e1e1347..00000000
--- a/samples/vsphere/vcenter/setup/backend_directory.py
+++ /dev/null
@@ -1,92 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-from samples.vsphere.common.vim.file import (detect_directory,
- create_directory,
- delete_directory)
-
-
-def setup(context):
- """Setup directories used by vcenter samples."""
- create_directory(context, 'Disk',
- context.testbed.config['DISK_DATACENTER_NAME'],
- context.testbed.config['DISK_DATASTORE_ROOT_PATH'])
- create_directory(context, 'CDROM ISO',
- context.testbed.config['ISO_DATACENTER_NAME'],
- context.testbed.config['ISO_DATASTORE_ROOT_PATH'])
- create_directory(context, 'Serial Port',
- context.testbed.config['SERIAL_PORT_DATACENTER_NAME'],
- context.testbed.config['SERIAL_PORT_DATASTORE_ROOT_PATH'])
- create_directory(context, 'Parallel Port',
- context.testbed.config['PARALLEL_PORT_DATACENTER_NAME'],
- context.testbed.config[
- 'PARALLEL_PORT_DATASTORE_ROOT_PATH'])
- create_directory(context, 'Floppy',
- context.testbed.config['FLOPPY_DATACENTER_NAME'],
- context.testbed.config['FLOPPY_DATASTORE_ROOT_PATH'])
-
-
-def cleanup(context):
- """Cleanup directories after running vcenter samples"""
- delete_directory(context, 'Disk',
- context.testbed.config['DISK_DATACENTER_NAME'],
- context.testbed.config['DISK_DATASTORE_ROOT_PATH'])
-
- if context.option['DO_TESTBED_ISO_CLEANUP']:
- delete_directory(context, 'CDROM ISO',
- context.testbed.config['ISO_DATACENTER_NAME'],
- context.testbed.config['ISO_DATASTORE_ROOT_PATH'])
-
- delete_directory(context, 'Serial Port',
- context.testbed.config['SERIAL_PORT_DATACENTER_NAME'],
- context.testbed.config['SERIAL_PORT_DATASTORE_ROOT_PATH'])
- delete_directory(context, 'Parallel Port',
- context.testbed.config['PARALLEL_PORT_DATACENTER_NAME'],
- context.testbed.config[
- 'PARALLEL_PORT_DATASTORE_ROOT_PATH'])
- delete_directory(context, 'Floppy',
- context.testbed.config['FLOPPY_DATACENTER_NAME'],
- context.testbed.config['FLOPPY_DATASTORE_ROOT_PATH'])
-
- # Remove the top level Sample_Backends directory in the Datastore
- if context.option['DO_TESTBED_ISO_CLEANUP']:
- delete_directory(context, 'Backends',
- context.testbed.config['BACKENDS_DATACENTER_NAME'],
- context.testbed.config['BACKENDS_DATASTORE_ROOT_PATH'])
-
-
-def validate(context):
- """Validate if all required directories exist to run vcenter samples"""
- return (
- detect_directory(context, 'Disk',
- context.testbed.config['DISK_DATACENTER_NAME'],
- context.testbed.config['DISK_DATASTORE_ROOT_PATH']) and
- detect_directory(context, 'CDROM ISO',
- context.testbed.config['ISO_DATACENTER_NAME'],
- context.testbed.config['ISO_DATASTORE_ROOT_PATH']) and
- detect_directory(context, 'Serial Port',
- context.testbed.config['SERIAL_PORT_DATACENTER_NAME'],
- context.testbed.config[
- 'SERIAL_PORT_DATASTORE_ROOT_PATH']) and
- detect_directory(context, 'Parallel Port',
- context.testbed.config[
- 'PARALLEL_PORT_DATACENTER_NAME'],
- context.testbed.config[
- 'PARALLEL_PORT_DATASTORE_ROOT_PATH']) and
- detect_directory(context, 'Floppy',
- context.testbed.config['FLOPPY_DATACENTER_NAME'],
- context.testbed.config['FLOPPY_DATASTORE_ROOT_PATH']))
diff --git a/samples/vsphere/vcenter/setup/cluster.py b/samples/vsphere/vcenter/setup/cluster.py
deleted file mode 100644
index 19a15917..00000000
--- a/samples/vsphere/vcenter/setup/cluster.py
+++ /dev/null
@@ -1,148 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-import pyVim.task
-from com.vmware.vcenter_client import Cluster
-from pyVmomi import vim
-
-from samples.vsphere.vcenter.helper import cluster_helper
-
-
-def detect_cluster(context):
- """Find the cluster to run the vcenter samples"""
- cluster1_name = context.testbed.config['CLUSTER1_NAME']
- datacenter_name = context.testbed.config['VM_DATACENTER_NAME']
-
- cluster = cluster_helper.get_cluster(context.stub_config, datacenter_name,
- cluster1_name)
-
- if cluster:
- context.testbed.entities['CLUSTER_IDS'] = {}
- context.testbed.entities['CLUSTER_IDS'][cluster1_name] = cluster
- return True
- else:
- return False
-
-
-def cleanup_cluster(context):
- """Delete cluster after vcenter sample run"""
- cluster1_name = context.testbed.config['CLUSTER1_NAME']
- names = set([cluster1_name])
-
- cluster_svc = Cluster(context.stub_config)
- cluster_summaries = cluster_svc.list(Cluster.FilterSpec(names=names))
- print("Found '{}' Clusters matching names {}".
- format(len(cluster_summaries), ", ".join(["'{}'".
- format(n) for n in names])))
-
- if len(cluster_summaries) < 1:
- return
-
- # Delete the cluster using the managed object
- cluster = cluster_summaries[0].cluster
- cluster_mo = vim.ClusterComputeResource(cluster, context.soap_stub)
-
- print("Deleting Cluster '{}' ({})".format(cluster, cluster1_name))
- task = cluster_mo.Destroy()
- pyVim.task.WaitForTask(task)
-
-
-def setup_cluster_vapi1(context):
- """Create a cluster from the Datacenter managed object."""
- cluster1_name = context.testbed.config['CLUSTER1_NAME']
-
- # Get the host folder for the Datacenter2 using the save identifier
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
-
- # Create a managed object from the datacenter identifier
- datacenter_mo = vim.Datacenter(datacenter, context.soap_stub)
-
- # Using pyvmomi to get the host folder on which to create the cluster
- folder_mo = datacenter_mo.hostFolder
- cluster_mo = folder_mo.CreateClusterEx(cluster1_name,
- vim.cluster.ConfigSpecEx())
-
- print("Created Cluster '{}' ({})".format(cluster_mo._moId, cluster1_name))
-
- context.testbed.entities['CLUSTER_IDS'] = {
- cluster1_name: cluster_mo._moId
- }
-
-
-def setup_cluster_vapi2(context):
- """Create a cluster from the Folder managed object"""
- cluster1_name = context.testbed.config['CLUSTER1_NAME']
-
- # Get the host folder for the Datacenter2 using the folder query
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
-
- folder_svc = Folder(context.stub_config)
- folder_summaries = folder_svc.list(
- Folder.FilterSpec(type=Folder.Type.HOST, datacenters=set([datacenter])))
- folder = folder_summaries[0].folder
-
- # Create a managed object from the folder identifier
- folder_mo = vim.Folder(folder, context.soap_stub)
- cluster_mo = folder_mo.CreateClusterEx(cluster1_name,
- vim.cluster.ConfigSpecEx())
-
- print("Created Cluster '{}' ({})".format(cluster_mo._moId, cluster1_name))
-
- context.testbed.entities['CLUSTER_IDS'] = {
- cluster1_name: cluster_mo._moId
- }
-
-
-def setup_cluster_vim(context):
- """Create a cluster using only the VIM API"""
- cluster1_name = context.testbed.config['CLUSTER1_NAME']
-
- # Get the host folder for the Datacenter2 using the save identifier
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
-
- for entity in context.service_instance.content.rootFolder.childEntity:
- if isinstance(entity,
- vim.Datacenter) and entity.name == datacenter_name:
- folder_mo = entity.hostFolder
- cluster_mo = folder_mo.CreateClusterEx(cluster1_name,
- vim.cluster.ConfigSpecEx())
-
- print("Created Cluster '{}' ({})".format(cluster_mo._moId,
- cluster1_name))
-
- context.testbed.entities['CLUSTER_IDS'] = {
- cluster1_name: cluster_mo._moId
- }
- break
-
-
-def setup_cluster(context):
- setup_cluster_vim(context)
-
-
-def setup(context):
- setup_cluster(context)
-
-
-def cleanup(context):
- cleanup_cluster(context)
-
-
-def validate(context):
- return detect_cluster(context)
diff --git a/samples/vsphere/vcenter/setup/datacenter.py b/samples/vsphere/vcenter/setup/datacenter.py
deleted file mode 100644
index 1e5a6a92..00000000
--- a/samples/vsphere/vcenter/setup/datacenter.py
+++ /dev/null
@@ -1,117 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-from com.vmware.vcenter_client import (Datacenter, Folder)
-
-
-def folder_list_datacenter_folder(context):
- folder_svc = Folder(context.stub_config)
- return folder_svc.list(Folder.FilterSpec(type=Folder.Type.DATACENTER))
-
-
-def detect_datacenter(context, datacenter_name):
- """Find the datacenter with the given name"""
- datacenter_svc = Datacenter(context.stub_config)
-
- names = set([datacenter_name])
- datacenter_summaries = datacenter_svc.list(
- Datacenter.FilterSpec(names=names))
- if len(datacenter_summaries) > 0:
- datacenter = datacenter_summaries[0].datacenter
- print("Detected Datacenter '{}' as {}".
- format(datacenter_name, datacenter))
- context.testbed.entities['DATACENTER_IDS'][datacenter_name] = datacenter
- return True
- else:
- print("Datacenter '{}' missing".format(datacenter_name))
- return False
-
-
-def detect_datacenters(context):
- """Find datacenters to run the vcenter samples"""
- context.testbed.entities['DATACENTER_IDS'] = {}
-
- # Look for the two datacenters
- datacenter1_name = context.testbed.config['DATACENTER1_NAME']
- datacenter2_name = context.testbed.config['DATACENTER2_NAME']
-
- return (detect_datacenter(context, datacenter1_name) and
- detect_datacenter(context, datacenter2_name))
-
-
-def cleanup_datacenters(context):
- """Cleanup datacenters after sample run"""
- datacenter_svc = Datacenter(context.stub_config)
-
- # Look for the two datacenters
- datacenter1_name = context.testbed.config['DATACENTER1_NAME']
- datacenter2_name = context.testbed.config['DATACENTER2_NAME']
- names = set([datacenter1_name, datacenter2_name])
-
- datacenter_summaries = datacenter_svc.list(
- Datacenter.FilterSpec(names=names))
- print("Found {} Datacenters matching names {}".
- format(len(datacenter_summaries), ", ".
- join(["'{}'".format(n) for n in names])))
-
- for datacenter_summary in datacenter_summaries:
- datacenter = datacenter_summary.datacenter
- print("Deleting Datacenter '{}' ({})".
- format(datacenter, datacenter_summary.name))
- datacenter_svc.delete(datacenter, force=True)
-
-
-def setup_datacenters(context):
- """Create datacenters for running vcenter samples"""
- # Find a Folder in which to put the Datacenters
- folder_summaries = folder_list_datacenter_folder(context)
- folder = folder_summaries[0].folder
- print("Creating datacenters in Folder '{}' ({})".
- format(folder, folder_summaries[0].name))
-
- datacenter_svc = Datacenter(context.stub_config)
-
- # Create first datacenter
- datacenter1_name = context.testbed.config['DATACENTER1_NAME']
- datacenter1 = datacenter_svc.create(
- Datacenter.CreateSpec(name=datacenter1_name, folder=folder)
- )
- print("Created Datacenter '{}' ({})".format(datacenter1, datacenter1_name))
-
- # Create second datacenter
- datacenter2_name = context.testbed.config['DATACENTER2_NAME']
- datacenter2 = datacenter_svc.create(
- Datacenter.CreateSpec(name=datacenter2_name, folder=folder)
- )
- print("Created Datacenter '{}' ({})".format(datacenter2, datacenter2_name))
-
- # Save datacenter name to identifier mappings for later use
- context.testbed.entities['DATACENTER_IDS'] = {
- datacenter1_name: datacenter1,
- datacenter2_name: datacenter2
- }
-
-
-def cleanup(context):
- cleanup_datacenters(context)
-
-
-def setup(context):
- setup_datacenters(context)
-
-
-def validate(context):
- return detect_datacenters(context)
diff --git a/samples/vsphere/vcenter/setup/datastore.py b/samples/vsphere/vcenter/setup/datastore.py
deleted file mode 100644
index 8566edfe..00000000
--- a/samples/vsphere/vcenter/setup/datastore.py
+++ /dev/null
@@ -1,262 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-import pyVim.task
-from com.vmware.vcenter_client import Host
-from pyVmomi import vim
-
-
-def detect_nfs_datastore_on_host(context, host_name):
- """Find NFS datastore on host"""
- names = set([host_name])
- datastore_name = context.testbed.config['NFS_DATASTORE_NAME']
-
- # Use vAPI find the Host managed identities
- host_svc = Host(context.stub_config)
- host_summaries = host_svc.list(Host.FilterSpec(names=names))
-
- for host_summary in host_summaries:
- # Convert the host identifier into a ManagedObject
- host = host_summary.host
- host_mo = vim.HostSystem(host, context.soap_stub)
-
- for datastore_mo in host_mo.datastore:
- if (datastore_mo.name == datastore_name and
- datastore_mo.summary.type == 'NFS'):
- datastore = datastore_mo._moId
- print("Detected NFS Volume '{}' as {} on Host '{}' ({})".
- format(datastore_name, datastore, host_name, host))
- context.testbed.entities['HOST_NFS_DATASTORE_IDS'][host_name] \
- = datastore
- return True
-
- print("NFS Volume '{}' missing on Host '{}'".
- format(datastore_name, host_name))
- return False
-
-
-def detect_nfs_datastore(context):
- """Find NFS datastore used to run vcenter samples"""
- context.testbed.entities['HOST_NFS_DATASTORE_IDS'] = {}
- host1_name = context.testbed.config['ESX_HOST1']
- host2_name = context.testbed.config['ESX_HOST2']
- return (detect_nfs_datastore_on_host(context, host1_name) and
- detect_nfs_datastore_on_host(context, host2_name))
-
-
-def cleanup_nfs_datastore(context):
- """Cleanup NFS datastore after running vcenter samples"""
- # Remove NFS datastore from each Host
- host1_name = context.testbed.config['ESX_HOST1']
- host2_name = context.testbed.config['ESX_HOST2']
- names = set([host1_name, host2_name])
-
- datastore_name = context.testbed.config['NFS_DATASTORE_NAME']
-
- # Use vAPI find the Host managed identities
- host_svc = Host(context.stub_config)
- host_summaries = host_svc.list(Host.FilterSpec(names=names))
-
- for host_summary in host_summaries:
- # Convert the host identifier into a ManagedObject
- host = host_summary.host
- host_mo = vim.HostSystem(host, context.soap_stub)
-
- for datastore_mo in host_mo.datastore:
- if datastore_mo.name == datastore_name:
- datastore_system = host_mo.configManager.datastoreSystem
- datastore_system.RemoveDatastore(datastore_mo)
- print("Removed NFS Volume '{}' ({}) from Host '{}' ({})".
- format(datastore_name, datastore_mo._moId,
- host_mo.name, host_mo._moId))
-
- # Remote NFS Datastore at the vCenter level
- # TODO Do we need to do this?
-
-
-def setup_nfs_datastore(context):
- """Setup NFS datastore for running vcenter samples"""
- host1_name = context.testbed.config['ESX_HOST1']
- nfs_datastore1 = setup_nfs_datastore_on_host(context, host1_name)
-
- host2_name = context.testbed.config['ESX_HOST2']
- nfs_datastore2 = setup_nfs_datastore_on_host(context, host2_name)
-
- context.testbed.entities['HOST_NFS_DATASTORE_IDS'] = {
- host1_name: nfs_datastore1,
- host2_name: nfs_datastore2
- }
-
-
-def setup_nfs_datastore_on_host(context, host_name):
- """Mount the NFS volume on one ESX hosts using the VIM API."""
- nfs_host = context.testbed.config['NFS_HOST']
- remote_path = context.testbed.config['NFS_REMOTE_PATH']
- local_path = context.testbed.config['NFS_DATASTORE_NAME']
-
- host = context.testbed.entities['HOST_IDS'][host_name]
- host_mo = vim.HostSystem(host, context.soap_stub)
-
- datastore_system = host_mo.configManager.datastoreSystem
- try:
- datastore_mo = datastore_system.CreateNasDatastore(
- vim.host.NasVolume.Specification(remoteHost=nfs_host,
- remotePath=remote_path,
- localPath=local_path,
- accessMode=vim.host.MountInfo.AccessMode.readWrite,
- type=vim.host.FileSystemVolume.FileSystemType.NFS))
-
- print("Added NFS Volume '{}' ({}) to Host '{}' ({})".
- format(local_path, datastore_mo._moId, host_name, host))
- return datastore_mo._moId
- except vim.fault.AlreadyExists as e:
- print("NFS Volume '{}' already exists on Host '{}' ({})".
- format(local_path, host_name, host))
- for datastore_mo in host_mo.datastore:
- info = datastore_mo.info
- if (isinstance(info, vim.host.NasDatastoreInfo) and
- info.nas.remoteHost == nfs_host and
- info.nas.remotePath == remote_path):
- if info.name == local_path:
- print("Found NFS Volume '{}' ({}) on Host '{}' ({})".
- format(local_path, datastore_mo._moId,
- host_name, host_mo._moId))
- return datastore_mo._moId
- else:
- print("Found NFS remote host '{}' and path '{}' on Host '{}' ({}) as '{}'".
- format(nfs_host, remote_path, host_name,
- host_mo._moId, info.name))
-
- print("Renaming NFS Volume '{}' ({}) to '{}'".
- format(info.name, datastore_mo._moId, local_path))
- task = datastore_mo.Rename(local_path)
- pyVim.task.WaitForTask(task)
-
- # TODO Find the datastore identifier for the NFS volume and return it
- return None
-
-
-def detect_vmfs_datastore(context, host_name, datastore_name):
- """Find VMFS datastore given host and datastore names"""
- names = set([host_name])
-
- # Use vAPI find the Host managed identities
- host_svc = Host(context.stub_config)
- host_summaries = host_svc.list(Host.FilterSpec(names=names))
-
- for host_summary in host_summaries:
- # Convert the host identifier into a ManagedObject
- host = host_summary.host
- host_mo = vim.HostSystem(host, context.soap_stub)
-
- for datastore_mo in host_mo.datastore:
- if (datastore_mo.name == datastore_name and
- datastore_mo.summary.type == 'VMFS'):
- datastore = datastore_mo._moId
- print("Detected VMFS Volume '{}' as {} on Host '{}' ({})".
- format(datastore_name, datastore, host_name, host))
- context.testbed.entities['HOST_VMFS_DATASTORE_IDS'][host_name] \
- = datastore
- return True
-
- print("VMFS Volume '{}' missing on Host '{}'".
- format(datastore_name, host_name))
- return False
-
-
-def detect_vmfs_datastores(context):
- """Find VMFS datastore used to run vcenter samples"""
- context.testbed.entities['HOST_VMFS_DATASTORE_IDS'] = {}
-
- host1_name = context.testbed.config['ESX_HOST1']
- host1_vmfs_volume = context.testbed.config['ESX_HOST1_VMFS_DATASTORE']
-
- host2_name = context.testbed.config['ESX_HOST2']
- host2_vmfs_volume = context.testbed.config['ESX_HOST2_VMFS_DATASTORE']
-
- # From each host, look for the VMFS Volume
- return (detect_vmfs_datastore(context, host1_name, host1_vmfs_volume) and
- detect_vmfs_datastore(context, host2_name, host2_vmfs_volume))
-
-
-def setup_vmfs_datastore(context, host_name, datastore_name):
- """Find VMFS datastore given host and datastore names"""
- context.testbed.entities['HOST_VMFS_DATASTORE_IDS'] = {}
-
- names = set([host_name])
-
- # Use vAPI find the Host managed identities
- host_svc = Host(context.stub_config)
- host_summaries = host_svc.list(Host.FilterSpec(names=names))
-
- host_summary = host_summaries[0]
- # Convert the host identifier into a ManagedObject
- host = host_summary.host
- host_mo = vim.HostSystem(host, context.soap_stub)
-
- vmfs_datastores = dict([(datastore_mo.name, datastore_mo)
- for datastore_mo in host_mo.datastore
- if datastore_mo.summary.type == 'VMFS'])
-
- # The VMFS volume exists. No need to do anything
- if datastore_name in vmfs_datastores:
- datastore = vmfs_datastores[datastore_name]._moId
- print("Detected VMFS Volume '{}' as {} on Host '{}' ({})".
- format(datastore_name, datastore, host_name, host))
- context.testbed.entities['HOST_VMFS_DATASTORE_IDS'][host_name] \
- = datastore
- return True
-
- # Rename a VMFS datastore
- if len(vmfs_datastores) > 0:
- datastore_mo = list(vmfs_datastores.values())[0]
- datastore = datastore_mo._moId
- print("Renaming VMFS Volume '{}' ({}) on Host '{}' ({}) to '{}'".
- format(datastore_mo.name, datastore,
- host_name, host, datastore_name))
- task = datastore_mo.Rename(datastore_name)
- pyVim.task.WaitForTask(task)
- return True
-
- return False
-
-
-def setup_vmfs_datastores(context):
- """Setup VMFS datastore used to run vcenter samples"""
- host1_name = context.testbed.config['ESX_HOST1']
- host1_vmfs_volume = context.testbed.config['ESX_HOST1_VMFS_DATASTORE']
-
- host2_name = context.testbed.config['ESX_HOST2']
- host2_vmfs_volume = context.testbed.config['ESX_HOST2_VMFS_DATASTORE']
-
- # From each host, look for the VMFS Volume
- setup_vmfs_datastore(context, host1_name, host1_vmfs_volume)
- setup_vmfs_datastore(context, host2_name, host2_vmfs_volume)
-
-
-def setup(context):
- setup_nfs_datastore(context)
- setup_vmfs_datastores(context)
-
-
-def cleanup(context):
- cleanup_nfs_datastore(context)
-
-
-def validate(context):
- return (
- detect_nfs_datastore(context) and
- detect_vmfs_datastores(context))
diff --git a/samples/vsphere/vcenter/setup/floppy_image.py b/samples/vsphere/vcenter/setup/floppy_image.py
deleted file mode 100644
index 63ec9df8..00000000
--- a/samples/vsphere/vcenter/setup/floppy_image.py
+++ /dev/null
@@ -1,75 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-from samples.vsphere.common.vim.file import (detect_file, delete_file,
- parse_datastore_path)
-from samples.vsphere.common.vim.inventory import get_datastore_mo
-
-from samples.vsphere.common.vim import datastore_file
-
-
-def setup_floppy_image(context):
- """Copy floppy image used to run vcenter samples"""
- floppy_src_url = context.testbed.config['FLOPPY_SRC_URL']
- datacenter_name = context.testbed.config['FLOPPY_DATACENTER_NAME']
- datastore_path = context.testbed.config['FLOPPY_DATASTORE_PATH']
- (datastore_name, path) = parse_datastore_path(datastore_path)
-
- datastore_mo = get_datastore_mo(context.stub_config,
- context.service_instance._stub,
- datacenter_name,
- datastore_name)
- if not datastore_mo:
- raise Exception("Could not find datastore '{}'".format(datastore_name))
-
- # See if the Floppy image exists. Copy it into the system if it does not
- # exist
- dsfile = datastore_file.File(datastore_mo)
- if not dsfile.exists(datastore_path):
- print("Putting Floppy file from '{}' at '{}'".
- format(floppy_src_url, datastore_path))
- dsfile.put(path=path, src_url=floppy_src_url)
-
-
-def cleanup_floppy_image(context):
- """Delete floppy image after running samples"""
- datacenter_name = context.testbed.config['FLOPPY_DATACENTER_NAME']
- datastore_path = context.testbed.config['FLOPPY_DATASTORE_PATH']
- delete_file(context.stub_config,
- context.service_instance,
- 'Floppy Image',
- datacenter_name,
- datastore_path)
-
-
-def detect_floppy_image(context):
- """Find the floppy image used to run vcenter samples"""
- datacenter_name = context.testbed.config['FLOPPY_DATACENTER_NAME']
- datastore_path = context.testbed.config['FLOPPY_DATASTORE_PATH']
- return detect_file(context, 'Floppy Image', datacenter_name, datastore_path)
-
-
-def setup(context):
- setup_floppy_image(context)
-
-
-def cleanup(context):
- cleanup_floppy_image(context)
-
-
-def validate(context):
- return detect_floppy_image(context)
diff --git a/samples/vsphere/vcenter/setup/folder.py b/samples/vsphere/vcenter/setup/folder.py
deleted file mode 100644
index f677ce54..00000000
--- a/samples/vsphere/vcenter/setup/folder.py
+++ /dev/null
@@ -1,125 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-import pyVim.task
-from com.vmware.vcenter_client import (Folder)
-from pyVmomi import vim
-
-from samples.vsphere.vcenter.helper import datacenter_helper
-
-
-def detect_vm_folder(context, datacenter_name, folder_name):
- """Find vm folder based on datacenter and folder name"""
- datacenter = datacenter_helper.get_datacenter(context.stub_config,
- datacenter_name)
- if not datacenter:
- print("Datacenter '{}' not found".format(datacenter_name))
- return None
-
- folder_svc = Folder(context.stub_config)
- folder_summaries = folder_svc.list(
- Folder.FilterSpec(type=Folder.Type.VIRTUAL_MACHINE,
- names=set([folder_name]),
- datacenters=set([datacenter])))
- if len(folder_summaries) > 0:
- folder = folder_summaries[0].folder
- print("Detected VM Folder '{}' as {}".format(folder_name, folder))
- context.testbed.entities['VM_FOLDER_IDS'][folder_name] = folder
- return True
- else:
- print("VM Folder '{}' missing in Datacenter {}".
- format(folder_name, datacenter_name))
- return False
-
-
-def detect_vm_folders(context):
- """Find vm folder used to run vcenter samples"""
- context.testbed.entities['VM_FOLDER_IDS'] = {}
-
- folder1_name = context.testbed.config['VM_FOLDER1_NAME']
- datacenter1_name = context.testbed.config['DATACENTER1_NAME']
-
- folder2_name = context.testbed.config['VM_FOLDER2_NAME']
- datacenter2_name = context.testbed.config['DATACENTER2_NAME']
-
- return (detect_vm_folder(context, datacenter1_name, folder1_name) and
- detect_vm_folder(context, datacenter2_name, folder2_name))
-
-
-def delete_vm_folder(context, datacenter_name, folder_name):
- """Delete vm folder from given datacenter"""
- for datacenter_mo in context.service_instance.content.rootFolder\
- .childEntity:
- if (isinstance(datacenter_mo, vim.Datacenter) and
- datacenter_mo.name == datacenter_name):
-
- for folder_mo in datacenter_mo.vmFolder.childEntity:
- if folder_mo.name == folder_name:
- print("Deleting Folder '{}' ({})' in Datacenter '{}' ({})".
- format(folder_name, folder_mo._moId,
- datacenter_name, datacenter_mo._moId))
- task = folder_mo.Destroy()
- pyVim.task.WaitForTask(task)
-
-
-def create_vm_folder(context, datacenter_name, folder_name):
- """Create vm folder in given datacenter"""
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
- datacenter_mo = vim.Datacenter(datacenter, context.soap_stub)
- folder_mo = datacenter_mo.vmFolder.CreateFolder(folder_name)
- print("Created Folder '{}' ({}) in Datacenter '{}' ({})".
- format(folder_name, folder_mo._moId, datacenter_name, datacenter))
- return folder_mo._moId
-
-
-def cleanup_vm_folders(context):
- """Delete vm folder after sample run"""
- folder1_name = context.testbed.config['VM_FOLDER1_NAME']
- datacenter1_name = context.testbed.config['DATACENTER1_NAME']
- delete_vm_folder(context, datacenter1_name, folder1_name)
-
- folder2_name = context.testbed.config['VM_FOLDER2_NAME']
- datacenter2_name = context.testbed.config['DATACENTER2_NAME']
- delete_vm_folder(context, datacenter2_name, folder2_name)
-
-
-def setup_vm_folders(context):
- """Setup vm folder used to run vcenter samples"""
- folder1_name = context.testbed.config['VM_FOLDER1_NAME']
- datacenter1_name = context.testbed.config['DATACENTER1_NAME']
- folder1 = create_vm_folder(context, datacenter1_name, folder1_name)
-
- folder2_name = context.testbed.config['VM_FOLDER2_NAME']
- datacenter2_name = context.testbed.config['DATACENTER2_NAME']
- folder2 = create_vm_folder(context, datacenter2_name, folder2_name)
-
- context.testbed.entities['VM_FOLDER_IDS'] = {
- folder1_name: folder1,
- folder2_name: folder2,
- }
-
-
-def setup(context):
- setup_vm_folders(context)
-
-
-def cleanup(context):
- cleanup_vm_folders(context)
-
-
-def validate(context):
- return detect_vm_folders(context)
diff --git a/samples/vsphere/vcenter/setup/host.py b/samples/vsphere/vcenter/setup/host.py
deleted file mode 100644
index cbd9e7f9..00000000
--- a/samples/vsphere/vcenter/setup/host.py
+++ /dev/null
@@ -1,214 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-import pyVim.task
-from com.vmware.vcenter_client import (Folder, Host)
-from pyVmomi import vim
-
-
-def detect_host(context, host_name):
- """Find host based on host name"""
- host_svc = Host(context.stub_config)
- names = set([host_name])
-
- host_summaries = host_svc.list(Host.FilterSpec(names=names))
- if len(host_summaries) > 0:
- host = host_summaries[0].host
- print("Detected Host '{}' as {}".format(host_name, host))
- context.testbed.entities['HOST_IDS'][host_name] = host
- return True
- else:
- print("Host '{}' missing".format(host_name))
- return False
-
-
-def detect_hosts(context):
- """Find host used to run vcenter samples"""
- context.testbed.entities['HOST_IDS'] = {}
- host1_name = context.testbed.config['ESX_HOST1']
- host2_name = context.testbed.config['ESX_HOST2']
- return (detect_host(context, host1_name) and
- detect_host(context, host2_name))
-
-
-def cleanup_hosts(context):
- """Delete hosts after sample run"""
- host_svc = Host(context.stub_config)
-
- host1_name = context.testbed.config['ESX_HOST1']
- host2_name = context.testbed.config['ESX_HOST2']
- names = set([host1_name, host2_name])
-
- host_summaries = host_svc.list(Host.FilterSpec(names=names))
- print('Found {} Hosts matching names {}'.
- format(len(host_summaries), ', '.
- join(["'{}'".format(n) for n in names])))
-
- for host_summary in host_summaries:
- host = host_summary.host
- print("Deleting Host '{}' ({})".format(host_summary.name, host))
- host_svc.delete(host)
-
-
-def create_host_vapi(context, host_name, datacenter_name):
- """
- Adds a single Host to the vCenter inventory under the named Datacenter
- using vAPI.
- """
- host_svc = Host(context.stub_config)
-
- user = context.testbed.config['ESX_USER']
- pwd = context.testbed.config['ESX_PASS']
-
- # Get the host folder for the Datacenter1 using the folder query
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
-
- folder_svc = Folder(context.stub_config)
- folder_summaries = folder_svc.list(
- Folder.FilterSpec(type=Folder.Type.HOST, datacenters=set([datacenter])))
- folder = folder_summaries[0].folder
-
- create_spec = Host.CreateSpec(
- hostname=host_name,
- user_name=user,
- password=pwd,
- folder=folder,
- thumbprint_verification=Host.CreateSpec.ThumbprintVerification.NONE)
- host = host_svc.create(create_spec)
- print("Created Host '{}' ({})".format(host, host_name))
-
- return host
-
-
-def create_host_vim(context, host_name, datacenter_name):
- """
- Adds a single Host to the vCenter inventory under the named Datacenter
- using the VIM API.
- """
- user = context.testbed.config['ESX_USER']
- pwd = context.testbed.config['ESX_PASS']
-
- # Get the host folder for the Datacenter1 using the folder query
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
-
- for entity in context.service_instance.content.rootFolder.childEntity:
- if isinstance(entity, vim.Datacenter) and\
- entity.name == datacenter_name:
- datacenter_mo = entity
-
- folder_mo = datacenter_mo.hostFolder
- connect_spec = vim.host.ConnectSpec(hostName=host_name,
- userName=user,
- password=pwd,
- force=False)
- print("Creating Host ({})".format(host_name))
- task = folder_mo.AddStandaloneHost(connect_spec,
- vim.ComputeResource.ConfigSpec(),
- True)
- pyVim.task.WaitForTask(task)
-
- # Get host from task result
- host_mo = task.info.result.host[0]
- print("Created Host '{}' ({})".format(host_mo._moId, host_name))
-
- return host_mo._moId
-
-
-def move_host_into_cluster_vim(context, host_name, cluster_name):
- """Use vim api to move host to another cluster"""
- TIMEOUT = 30 # sec
-
- host = context.testbed.entities['HOST_IDS'][host_name]
- host_mo = vim.HostSystem(host, context.soap_stub)
-
- # Move the host into the cluster
- if not host_mo.runtime.inMaintenanceMode:
- task = host_mo.EnterMaintenanceMode(TIMEOUT)
- pyVim.task.WaitForTask(task)
- print("Host '{}' ({}) in maintenance mode".format(host, host_name))
-
- cluster = context.testbed.entities['CLUSTER_IDS'][cluster_name]
- cluster_mo = vim.ClusterComputeResource(cluster, context.soap_stub)
-
- task = cluster_mo.MoveInto([host_mo])
- pyVim.task.WaitForTask(task)
- print("Host '{}' ({}) moved into Cluster {} ({})".
- format(host, host_name, cluster, cluster_name))
-
- task = host_mo.ExitMaintenanceMode(TIMEOUT)
- pyVim.task.WaitForTask(task)
- print("Host '{}' ({}) out of maintenance mode".format(host, host_name))
-
-
-def setup_hosts_vapi(context):
- """Use vsphere automation API to setup host for sample run"""
- # Create Host1 as a standalone host in Datacenter1
- host1_name = context.testbed.config['ESX_HOST1']
- datacenter1_name = context.testbed.config['DATACENTER1_NAME']
- host1 = create_host_vapi(context, host1_name, datacenter1_name)
-
- # Create Host2 in a Cluster2
- host2_name = context.testbed.config['ESX_HOST2']
- datacenter2_name = context.testbed.config['DATACENTER2_NAME']
- host2 = create_host_vapi(context, host2_name, datacenter2_name)
-
- context.testbed.entities['HOST_IDS'] = {
- host1_name: host1,
- host2_name: host2
- }
-
- # Move Host2 into Cluster2
- cluster_name = context.testbed.config['CLUSTER1_NAME']
- move_host_into_cluster_vim(context, host2_name, cluster_name)
-
-
-def setup_hosts_vim(context):
- """Use vim API to setup host for sample run"""
- # Create Host1 as a standalone host in Datacenter1
- host1_name = context.testbed.config['ESX_HOST1']
- datacenter1_name = context.testbed.config['DATACENTER1_NAME']
- host1 = create_host_vim(context, host1_name, datacenter1_name)
-
- # Create Host2 in a Cluster2
- host2_name = context.testbed.config['ESX_HOST2']
- datacenter2_name = context.testbed.config['DATACENTER2_NAME']
- host2 = create_host_vim(context, host2_name, datacenter2_name)
-
- context.testbed.entities['HOST_IDS'] = {
- host1_name: host1,
- host2_name: host2
- }
-
- # Move Host2 into Cluster2
- cluster_name = context.testbed.config['CLUSTER1_NAME']
- move_host_into_cluster_vim(context, host2_name, cluster_name)
-
-
-def setup_hosts(context):
- setup_hosts_vapi(context)
-
-
-def setup(context):
- setup_hosts(context)
-
-
-def cleanup(context):
- cleanup_hosts(context)
-
-
-def validate(context):
- return detect_hosts(context)
diff --git a/samples/vsphere/vcenter/setup/iso_image.py b/samples/vsphere/vcenter/setup/iso_image.py
deleted file mode 100644
index f70eade3..00000000
--- a/samples/vsphere/vcenter/setup/iso_image.py
+++ /dev/null
@@ -1,73 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-from samples.vsphere.common.vim.file import (detect_file, delete_file,
- parse_datastore_path)
-from samples.vsphere.common.vim.inventory import get_datastore_mo
-
-from samples.vsphere.common.vim import datastore_file
-
-
-def setup_iso_image(context):
- """Copy iso image used to run vcenter samples"""
- iso_src_url = context.testbed.config['ISO_SRC_URL']
- datacenter_name = context.testbed.config['ISO_DATACENTER_NAME']
- datastore_path = context.testbed.config['ISO_DATASTORE_PATH']
- (datastore_name, path) = parse_datastore_path(datastore_path)
- datastore_mo = get_datastore_mo(context.stub_config,
- context.service_instance._stub,
- datacenter_name,
- datastore_name)
- if not datastore_mo:
- raise Exception("Could not find datastore '{}'".format(datastore_name))
-
- # See if the ISO image exists. Copy it into the system if it does not exist
- dsfile = datastore_file.File(datastore_mo)
- if not dsfile.exists(datastore_path):
- print("Putting ISO image file from '{}' at '{}'".
- format(iso_src_url, datastore_path))
- dsfile.put(path=path, src_url=iso_src_url)
-
-
-def cleanup_iso_image(context):
- """Cleanup iso image after sample run"""
- datacenter_name = context.testbed.config['ISO_DATACENTER_NAME']
- datastore_path = context.testbed.config['ISO_DATASTORE_PATH']
- delete_file(context.stub_config,
- context.service_instance,
- "ISO Image",
- datacenter_name,
- datastore_path)
-
-
-def detect_iso_image(context):
- """Find iso image used to run vcenter samples"""
- datacenter_name = context.testbed.config['ISO_DATACENTER_NAME']
- datastore_path = context.testbed.config['ISO_DATASTORE_PATH']
- return detect_file(context, "ISO Image", datacenter_name, datastore_path)
-
-
-def setup(context):
- setup_iso_image(context)
-
-
-def cleanup(context):
- cleanup_iso_image(context)
-
-
-def validate(context):
- return detect_iso_image(context)
diff --git a/samples/vsphere/vcenter/setup/main.py b/samples/vsphere/vcenter/setup/main.py
deleted file mode 100644
index 7330fd7e..00000000
--- a/samples/vsphere/vcenter/setup/main.py
+++ /dev/null
@@ -1,131 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-
-"""
-Script that runs through all the setup and samples.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-import pyVim.connect
-from samples.vsphere.common import sample_util
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.vcenter.setup import testbed
-from samples.vsphere.vcenter.setup.setup_cli import build_arg_parser
-from samples.vsphere.vcenter.setup.testbed_setup import cleanup as testbed_cleanup
-from samples.vsphere.vcenter.setup.testbed_setup import setup as testbed_setup
-from samples.vsphere.vcenter.setup.testbed_setup import validate as testbed_validate
-from samples.vsphere.vcenter.vm.main import VMSetup
-
-from samples.vsphere.common.ssl_helper import get_unverified_context
-
-
-# Parse command line params for setup script
-args = build_arg_parser().parse_args()
-
-_testbed = testbed.get()
-
-# If VC/ESX/NFS Server IPs are passed as arguments,
-# then override testbed.py values
-if (args.vcenterserver):
- _testbed.config['SERVER'] = args.vcenterserver
-if (args.vcenterpassword):
- _testbed.config['PASSWORD'] = args.vcenterpassword
-if (args.esxhost1):
- _testbed.config['ESX_HOST1'] = args.esxhost1
-if (args.esxhost2):
- _testbed.config['ESX_HOST2'] = args.esxhost2
-if (args.esxpassword):
- _testbed.config['ESX_PASS'] = args.esxpassword
-if (args.nfsserver):
- _testbed.config['NFS_HOST'] = args.nfsserver
-
-
-print(_testbed.to_config_string())
-
-# Connect to VIM API Endpoint on vCenter system
-context = None
-if args.skipverification:
- context = get_unverified_context()
-service_instance = pyVim.connect.SmartConnect(host=_testbed.config['SERVER'],
- user=_testbed.config['USERNAME'],
- pwd=_testbed.config['PASSWORD'],
- sslContext=context)
-
-# Connect to vAPI Endpoint on vCenter system
-stub_config = vapiconnect.connect(host=_testbed.config['SERVER'],
- user=_testbed.config['USERNAME'],
- pwd=_testbed.config['PASSWORD'],
- skip_verification=args.skipverification)
-
-context = sample_util.Context(_testbed, service_instance, stub_config)
-
-context.option['DO_TESTBED_SETUP'] = args.testbed_setup
-context.option['DO_TESTBED_VALIDATE'] = args.testbed_validate
-context.option['DO_TESTBED_CLEANUP'] = args.testbed_cleanup
-context.option['DO_TESTBED_ISO_CLEANUP'] = args.iso_cleanup
-context.option['DO_SAMPLES_SETUP'] = args.samples_setup
-context.option['DO_SAMPLES'] = args.samples
-context.option['DO_SAMPLES_INCREMENTAL'] = args.samples_incremental
-context.option['DO_SAMPLES_CLEANUP'] = args.samples_cleanup
-context.option['SKIP_VERIFICATION'] = args.skipverification
-print(context.to_option_string())
-
-###############################################################################
-# Testbed Setup
-###############################################################################
-
-vm_setup = VMSetup(context)
-
-# Setup testbed
-if context.option['DO_TESTBED_SETUP']:
- # Clean up in case of past failures
- vm_setup.cleanup()
- testbed_cleanup(context)
- testbed_setup(context)
-
-# Validate testbed
-if (context.option['DO_TESTBED_SETUP'] or
- context.option['DO_TESTBED_VALIDATE'] or
- context.option['DO_SAMPLES_SETUP'] or
- context.option['DO_SAMPLES']):
- if not testbed_validate(context):
- exit(0)
- print(context.testbed.to_entities_string())
-
-###############################################################################
-# Sample Run and Cleanup
-###############################################################################
-
-# Run Sample
-if context.option['DO_SAMPLES']:
- vm_setup.setup(context)
- vm_setup.run()
-
-# Cleanup after sample run
-if context.option['DO_SAMPLES_CLEANUP']:
- vm_setup.cleanup()
-
-###############################################################################
-# Testbed Cleanup
-###############################################################################
-
-# Teardown testbed.
-if context.option['DO_TESTBED_CLEANUP']:
- vm_setup.cleanup()
- testbed_cleanup(context)
diff --git a/samples/vsphere/vcenter/setup/network.py b/samples/vsphere/vcenter/setup/network.py
deleted file mode 100644
index 0b720a27..00000000
--- a/samples/vsphere/vcenter/setup/network.py
+++ /dev/null
@@ -1,283 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-import pyVim.task
-from com.vmware.vcenter_client import Host
-from pyVmomi import vim
-
-
-def detect_vdswitches(context):
- """Find distributed virtual switch used to run vcenter samples"""
- context.testbed.entities['DISTRIBUTED_SWITCH_IDS'] = {}
- context.testbed.entities['DISTRIBUTED_PORTGROUP_IDS'] = {}
-
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
- vdswitch_name = context.testbed.config['VDSWITCH1_NAME']
- vdswitch_mo = find_vdswitch(context, datacenter_name, vdswitch_name)
- if vdswitch_mo:
- vdswitch = vdswitch_mo._moId
- print("Detected Distributed Switch '{}' as {}".
- format(vdswitch_name, vdswitch))
- context.testbed.entities['DISTRIBUTED_SWITCH_IDS'][
- vdswitch_name] = vdswitch
-
- vdportgroup_name = context.testbed.config['VDPORTGROUP1_NAME']
- vdportgroup_mo = find_vdportgroup(context, datacenter_name,
- vdswitch_name, vdportgroup_name)
- if vdportgroup_mo:
- vdportgroup = vdportgroup_mo._moId
- print("Detected Distributed Portgroup '{}' as {}".
- format(vdportgroup_name, vdportgroup))
- context.testbed.entities['DISTRIBUTED_PORTGROUP_IDS'][
- vdportgroup_name] = vdportgroup
- else:
- print("Distributed Portgroup '{}' missing".format(vdportgroup_name))
- return False
- else:
- print("Distributed Switch '{}' missing".format(vdswitch_name))
- return False
- return True
-
-
-def cleanup_vdswitch(context):
- """Cleanup Distributed Switch after sampel run"""
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
- vdswitch_name = context.testbed.config['VDSWITCH1_NAME']
- vdswitch_mo = find_vdswitch(context, datacenter_name, vdswitch_name)
- if vdswitch_mo:
- vdportgroup_name = context.testbed.config['VDPORTGROUP1_NAME']
- vdportgroup_mo = find_vdportgroup(context, datacenter_name,
- vdswitch_name, vdportgroup_name)
-
- if vdportgroup_mo:
- print("Deleting Distributed Portgroup '{}' ({})".
- format(vdportgroup_name, vdportgroup_mo._moId))
- task = vdportgroup_mo.Destroy()
- pyVim.task.WaitForTask(task)
-
- host_name = context.testbed.config['ESX_HOST2']
- remove_host_from_vdswitch(context, vdswitch_mo, host_name)
-
- print("Deleting Distributed Switch '{}' ({})".
- format(vdswitch_name, vdswitch_mo._moId))
- task = vdswitch_mo.Destroy()
- pyVim.task.WaitForTask(task)
-
-
-def find_vdswitch(context, datacenter_name, vdswitch_name):
- """ Retrieve an existing Distributed Switch"""
- # TODO Ugly deep nesting.
- for datacenter_mo in context.service_instance.content.rootFolder \
- .childEntity:
- if (isinstance(datacenter_mo, vim.Datacenter) and
- datacenter_mo.name == datacenter_name):
- for vdswitch_mo in datacenter_mo.networkFolder.childEntity:
- if (isinstance(vdswitch_mo, vim.DistributedVirtualSwitch) and
- vdswitch_mo.summary.name == vdswitch_name):
- print("Found VDSwitch '{}' ({}) in Datacenter '{}' ({})".
- format(vdswitch_name, vdswitch_mo._moId,
- datacenter_name, datacenter_mo._moId))
- return vdswitch_mo
- return None
-
-
-def find_vdportgroup(context, datacenter_name, vdswitch_name, vdportgroup_name):
- """
- Find existing Distributed Switch portgroup based on datacenter,
- vds name and portgroup name
- """
- vdswitch_mo = find_vdswitch(context, datacenter_name, vdswitch_name)
- for vdportgroup_mo in vdswitch_mo.portgroup:
- if vdportgroup_mo.name == vdportgroup_name:
- print(
- "Found Distributed Portgroup '{}' ({}) on Distributed Switch '{}' ({})".
- format(vdportgroup_name, vdportgroup_mo._moId,
- vdswitch_name, vdswitch_mo._moId))
- return vdportgroup_mo
- return None
-
-
-def create_vdswitch(context, datacenter_name, vdswitch_name):
- """Create Distributed Switch in given datacenter"""
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
- datacenter_mo = vim.Datacenter(datacenter, context.soap_stub)
-
- spec = vim.DistributedVirtualSwitch.CreateSpec()
- spec.configSpec = vim.DistributedVirtualSwitch.ConfigSpec(
- name=vdswitch_name)
-
- task = datacenter_mo.networkFolder.CreateDistributedVirtualSwitch(spec)
- pyVim.task.WaitForTask(task)
- vdswitch_mo = task.info.result
- print("Created Distributed Switch '{}' ({})".
- format(vdswitch_name, vdswitch_mo._moId))
- return vdswitch_mo._moId
-
-
-def create_vdportgroup(context, vdswitch_name, vdportgroup_name):
- """Create Distributed Switch portgroup"""
- vdportgroup_type = "earlyBinding"
-
- vdswitch = context.testbed.entities['DISTRIBUTED_SWITCH_IDS'][vdswitch_name]
- vdswitch_mo = vim.DistributedVirtualSwitch(vdswitch, context.soap_stub)
-
- vdportgroup_spec = vim.dvs.DistributedVirtualPortgroup.ConfigSpec(
- name=vdportgroup_name, type=vdportgroup_type)
- vdportgroup_specs = [vdportgroup_spec]
-
- task = vdswitch_mo.AddPortgroups(vdportgroup_specs)
- pyVim.task.WaitForTask(task)
-
- # The AddPortgroup operation doesn't return any information about the
- # created portgroup, so look it up.
- vdportgroup = None
- for vdportgroup_mo in vdswitch_mo.portgroup:
- if vdportgroup_mo.name == vdportgroup_name:
- vdportgroup = vdportgroup_mo._moId
- print(
- "Created Distributed Portgroup '{}' ({}) on Distributed Switch '{}' ({})".
- format(vdportgroup_name, vdportgroup, vdswitch_name, vdswitch))
- return vdportgroup
-
-
-def add_host_to_vdswitch(context, vdswitch_name, host_name, pnic_names=None):
- """Add host to Distributed Switch"""
- host = context.testbed.entities['HOST_IDS'][host_name]
- host_mo = vim.HostSystem(host, context.soap_stub)
-
- vdswitch = context.testbed.entities['DISTRIBUTED_SWITCH_IDS'][vdswitch_name]
- vdswitch_mo = vim.DistributedVirtualSwitch(vdswitch, context.soap_stub)
-
- pnic_specs = []
- if pnic_names:
- for pnic in pnic_names:
- pnic_specs.append(vim.dvs.HostMember.PnicSpec(pnicDevice=pnic))
-
- dvs_member_config = vim.dvs.HostMember.ConfigSpec(
- operation="add",
- host=host_mo,
- backing=vim.dvs.HostMember.PnicBacking(pnicSpec=pnic_specs))
-
- dvs_config = vim.DistributedVirtualSwitch.ConfigSpec(
- configVersion=vdswitch_mo.config.configVersion,
- host=[dvs_member_config])
-
- task = vdswitch_mo.Reconfigure(dvs_config)
- pyVim.task.WaitForTask(task)
-
- print("Added Host '{}' ({}) to Distributed Switch '{}' ({})".
- format(host_name, host, vdswitch_name, vdswitch))
-
-
-def remove_host_from_vdswitch(context, vdswitch_mo, host_name):
- """Remove host from Distributed Switch"""
- for host_member in vdswitch_mo.config.host:
- if host_member.config.host.name == host_name:
- dvs_member_config = vim.dvs.HostMember.ConfigSpec(
- operation="remove",
- host=host_member.config.host)
-
- dvs_config = vim.DistributedVirtualSwitch.ConfigSpec(
- configVersion=vdswitch_mo.config.configVersion,
- host=[dvs_member_config])
-
- task = vdswitch_mo.Reconfigure(dvs_config)
- pyVim.task.WaitForTask(task)
-
- print("Removed Host '{}' ({}) from Distributed Switch '{}' ({})".
- format(host_name, host_member.config.host._moId,
- vdswitch_mo.summary.name, vdswitch_mo._moId))
-
-
-def setup_vdswitch(context):
- """Setup Distributed Switch used to run vcenter samples"""
- # Add a Distributed Switch
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
- vdswitch1_name = context.testbed.config['VDSWITCH1_NAME']
- vdswitch1 = create_vdswitch(context, datacenter_name, vdswitch1_name)
-
- context.testbed.entities['DISTRIBUTED_SWITCH_IDS'] = {
- vdswitch1_name: vdswitch1
- }
-
- # Add a Distributed Portgroup
- vdportgroup1_name = context.testbed.config['VDPORTGROUP1_NAME']
- vdportgroup1 = create_vdportgroup(context, vdswitch1_name,
- vdportgroup1_name)
-
- context.testbed.entities['DISTRIBUTED_PORTGROUP_IDS'] = {
- vdportgroup1_name: vdportgroup1
- }
-
- # Add a Host into the Distributed Switch
- host2_name = context.testbed.config['ESX_HOST2']
- add_host_to_vdswitch(context, vdswitch1_name, host2_name)
-
- # @TODO: Add Host Uplink
-
-
-def detect_stdportgroup(context, host_name, network_name):
- """Find Distributed Switch based on host and network name"""
- # Ensure the standard switch is available on the host
- names = set([host_name])
-
- # Use vAPI find the Host managed identities
- host_svc = Host(context.stub_config)
- host_summaries = host_svc.list(Host.FilterSpec(names=names))
-
- for host_summary in host_summaries:
- # Convert the host identifier into a ManagedObject
- host = host_summary.host
- host_mo = vim.HostSystem(host, context.soap_stub)
-
- for network_mo in host_mo.network:
- if (type(network_mo) == vim.Network and
- network_mo.name == network_name):
- network = network_mo._moId
- print(
- "Detected Standard Portgroup '{}' as {} on Host '{}' ({})".
- format(network_name, network, host_name, host))
- context.testbed.entities['HOST_STANDARD_SWITCH_IDS'][
- host_name] = network
- return True
-
- print("Standard Portgroup '{}' missing on Host '{}'".
- format(network_name, host_name))
- return False
-
-
-def detect_stdportgroups(context):
- """Find Distributed Switch used to run vcenter samples"""
- context.testbed.entities['HOST_STANDARD_SWITCH_IDS'] = {}
- network_name = context.testbed.config['STDPORTGROUP_NAME']
- host1_name = context.testbed.config['ESX_HOST1']
- host2_name = context.testbed.config['ESX_HOST2']
- return (detect_stdportgroup(context, host1_name, network_name) and
- detect_stdportgroup(context, host2_name, network_name))
-
-
-def setup(context):
- setup_vdswitch(context)
-
-
-def cleanup(context):
- cleanup_vdswitch(context)
-
-
-def validate(context):
- return (
- detect_vdswitches(context) and
- detect_stdportgroups(context))
diff --git a/samples/vsphere/vcenter/setup/setup_cli.py b/samples/vsphere/vcenter/setup/setup_cli.py
deleted file mode 100644
index 67016736..00000000
--- a/samples/vsphere/vcenter/setup/setup_cli.py
+++ /dev/null
@@ -1,119 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-"""
-This module implements simple helper functions for python samples
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-import argparse
-
-
-def build_arg_parser():
- """
- Builds a standard argument parser with arguments for executing sample
- setup script
-
- -s, --testbed_setup
- -t, --testbed_validate
- -c, --testbed_cleanup
- -o, --iso_cleanup
- -e, --samples_setup
- -r, --samples
- -i, --samples_incremental
- -l, --samples_cleanup
- -v, --skipverification
- -server, --vcenterserver
- -p, --vcenterpassword
- -e1, --esxhost1
- -e2, --esxhost2
- -epass, --esxpassword
- -n, --nfsserver
-
- """
- parser = argparse.ArgumentParser(
- description='Arguments for running sample setup script')
-
- parser.add_argument('-s', '--testbed_setup',
- action='store_true',
- help='Build the testbed. Will run cleanup before '
- 'trying to build in case there is '
- 'an intermediate failure')
-
- parser.add_argument('-t', '--testbed_validate',
- action='store_true',
- help='Validate if the testbed is ready for the samples')
-
- parser.add_argument('-c', '--testbed_cleanup',
- action='store_true',
- help='Tear down the testbed')
-
- parser.add_argument('-o', '--iso_cleanup',
- action='store_true',
- help='Delete iso during cleanup. ')
-
- parser.add_argument('-e', '--samples_setup',
- action='store_true',
- help='Run sample setup. ')
-
- parser.add_argument('-r', '--samples',
- action='store_true',
- help='Run samples. ')
-
- parser.add_argument('-i', '--samples_incremental',
- action='store_true',
- help='Runs samples that incrementally updates the VM '
- 'configuration. ')
-
- parser.add_argument('-l', '--samples_cleanup',
- action='store_true',
- help='Clean up after sample run. ')
-
- parser.add_argument('-v', '--skipverification',
- action='store_true',
- help='Verify server certificate when connecting to '
- 'vcenter. ')
-
- parser.add_argument('-server', '--vcenterserver',
- action='store',
- help='Vcenter server IP to prepare the testbed to run the samples.'
- 'If not passed as argument, update testbed.py file')
-
- parser.add_argument('-p', '--vcenterpassword',
- action='store',
- help='Vcenter server password'
- 'If not passed as argument, update testbed.py file')
-
- parser.add_argument('-e1', '--esxhost1',
- action='store',
- help='ESX HOST 1 IP to prepare the testbed to run the samples.'
- 'If not passed as argument, update testbed.py file')
-
- parser.add_argument('-e2', '--esxhost2',
- action='store',
- help='ESX HOST 2 IP to prepare the testbed to run the samples.'
- 'If not passed as argument, update testbed.py file')
-
- parser.add_argument('-epass', '--esxpassword',
- action='store',
- help='ESX Server password'
- 'If not passed as argument, update testbed.py file')
-
- parser.add_argument('-n', '--nfsserver',
- action='store',
- help='NFS Server IP to setup datastore for samples run.'
- 'If not passed as argument, update testbed.py file')
- return parser
diff --git a/samples/vsphere/vcenter/setup/testbed.py b/samples/vsphere/vcenter/setup/testbed.py
deleted file mode 100644
index dd8ea2fb..00000000
--- a/samples/vsphere/vcenter/setup/testbed.py
+++ /dev/null
@@ -1,141 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-config = {}
-config["SERVER"] = "10.192.248.66"
-config["USERNAME"] = "administrator@vsphere.local"
-config["PASSWORD"] = "Admin!23"
-
-config["ESX_HOST1"] = ""
-config["ESX_HOST2"] = ""
-config["ESX_USER"] = "root"
-config["ESX_PASS"] = ""
-
-config["USE_NFS"] = True
-config["NFS_HOST"] = ""
-config["NFS_REMOTE_PATH"] = "/store1"
-config["NFS_DATASTORE_NAME"] = "Shared_NFS_Volume"
-
-config["ESX_HOST1_VMFS_DATASTORE"] = "Local_VMFS_Volume_on_Host1"
-config["ESX_HOST2_VMFS_DATASTORE"] = "Local_VMFS_Volume_on_Host2"
-
-config["DATACENTER1_NAME"] = "Sample_DC_1"
-config["DATACENTER2_NAME"] = "Sample_DC_2"
-
-config["VM_FOLDER1_NAME"] = "Sample_VM_Folder_1"
-config["VM_FOLDER2_NAME"] = "Sample_VM_Folder_2"
-
-config["CLUSTER1_NAME"] = "Cluster1"
-
-config["VDSWITCH1_NAME"] = "DSwitch1"
-config["VDPORTGROUP1_NAME"] = "Static_Portgroup_on_DSwitch_1"
-
-config["STDPORTGROUP_NAME"] = "VM Network"
-
-# The main datacenter and datastore that will be used for the VM tests
-config["VM_DATACENTER_NAME"] = config["DATACENTER2_NAME"]
-config["VM_DATASTORE_NAME"] = config["NFS_DATASTORE_NAME"]
-
-# GestOS should be one of the enumeration values in com.vmware.vcenter.vm.GuestOS
-config["VM_GUESTOS"] = "WINDOWS_9_64"
-
-config["VM_NAME_DEFAULT"] = "Sample_Default_VM_for_Simple_Testbed"
-config["VM_NAME_BASIC"] = "Sample_Basic_VM_for_Simple_Testbed"
-config["VM_NAME_EXHAUSTIVE"] = "Sample_Exhaustive_VM_for_Simple_Testbed"
-
-config["BACKENDS_DATACENTER_NAME"] = config["VM_DATACENTER_NAME"]
-
-# Root datastore path where VM backend files not will be created for the
-# samples
-config["BACKENDS_DATASTORE_ROOT_PATH"] = "[{}] Sample_Backends".format(config["VM_DATASTORE_NAME"])
-
-config["DISK_DATACENTER_NAME"] = config["VM_DATACENTER_NAME"]
-config["DISK_DATASTORE_ROOT_PATH"] = config["BACKENDS_DATASTORE_ROOT_PATH"] + "/disk"
-
-config["ISO_SRC_URL"] = "https://dl.bintray.com/vmware/photon/iso/1.0TP2/x86_64/photon-minimal-1.0TP2.iso"
-config["ISO_DATACENTER_NAME"] = config["VM_DATACENTER_NAME"]
-config["ISO_DATASTORE_ROOT_PATH"] = config["BACKENDS_DATASTORE_ROOT_PATH"] + "/iso"
-config["ISO_DATASTORE_PATH"] = config["ISO_DATASTORE_ROOT_PATH"] + "/photonOS.iso"
-
-config["SERIAL_PORT_DATACENTER_NAME"] = config["VM_DATACENTER_NAME"]
-config["SERIAL_PORT_DATASTORE_ROOT_PATH"] = config["BACKENDS_DATASTORE_ROOT_PATH"] + "/serial"
-config["SERIAL_PORT_DATASTORE_PATH"] = config["SERIAL_PORT_DATASTORE_ROOT_PATH"] + "/serial.log"
-config["SERIAL_PORT_NETWORK_SERVER_LOCATION"] = "tcp://localhost:16000"
-config["SERIAL_PORT_NETWORK_CLIENT_LOCATION"] = "tcp://www.vmware.com:80"
-config["SERIAL_PORT_NETWORK_PROXY"] = None
-
-config["PARALLEL_PORT_DATACENTER_NAME"] = config["VM_DATACENTER_NAME"]
-config["PARALLEL_PORT_DATASTORE_ROOT_PATH"] = config["BACKENDS_DATASTORE_ROOT_PATH"] + "/parallel"
-config["PARALLEL_PORT_DATASTORE_PATH"] = config["PARALLEL_PORT_DATASTORE_ROOT_PATH"] + "/parallel.log"
-
-config["FLOPPY_SRC_URL"] = "http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.0/fdboot.img"
-config["FLOPPY_DATACENTER_NAME"] = config["VM_DATACENTER_NAME"]
-config["FLOPPY_DATASTORE_ROOT_PATH"] = config["BACKENDS_DATASTORE_ROOT_PATH"] + "/floppy"
-config["FLOPPY_DATASTORE_PATH"] = config["FLOPPY_DATASTORE_ROOT_PATH"] + "/fdboot.img"
-
-
-class Testbed(object):
- def __init__(self):
- self.config = {}
- self.entities = {}
-
- @property
- def config(self):
- return self._config
-
- @config.setter
- def config(self, value):
- """setting"""
- self._config = value
-
- @property
- def entities(self):
- return self._entities
-
- @entities.setter
- def entities(self, value):
- """setting"""
- self._entities = value
-
- def to_config_string(self):
- s = ["=" * 79,
- "Testbed Configuration:",
- "=" * 79]
- s += [" {}: {}".format(k, self.config[k])
- for k in sorted(self.config.keys())]
- s += ["=" * 79]
- return "\n".join(s)
-
- def to_entities_string(self):
- s = ["=" * 79,
- "Testbed Entities:",
- "=" * 79]
- s += [" {}: {}".format(k, self.entities[k])
- for k in sorted(self.entities.keys())]
- s += ["=" * 79]
- return "\n".join(s)
-
- def __str__(self):
- return "\n".join(self.to_config_string(),
- self.to_entities_string())
-
-
-_testbed = Testbed()
-_testbed.config.update(config)
-
-
-def get():
- return _testbed
diff --git a/samples/vsphere/vcenter/setup/testbed_setup.py b/samples/vsphere/vcenter/setup/testbed_setup.py
deleted file mode 100644
index b8d56d4a..00000000
--- a/samples/vsphere/vcenter/setup/testbed_setup.py
+++ /dev/null
@@ -1,111 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-import samples.vsphere.vcenter.setup.backend_directory as backend_directory
-import samples.vsphere.vcenter.setup.cluster as cluster
-import samples.vsphere.vcenter.setup.datacenter as datacenter
-import samples.vsphere.vcenter.setup.datastore as datastore
-import samples.vsphere.vcenter.setup.floppy_image as floppy_image
-import samples.vsphere.vcenter.setup.folder as folder
-import samples.vsphere.vcenter.setup.host as host
-import samples.vsphere.vcenter.setup.iso_image as iso_image
-import samples.vsphere.vcenter.setup.network as network
-
-"""
-Setup Simple Testbed: Which provides the prerequisites for using the VM API
-Inputs:
-* IP address or hostname of vCenter
-* IP address of 2 hosts
-* (IP address,server path) of a NFS Server
-
-* Assumes that all resources will be created off the root folders
- within each datacenter. No need to recursively traverse across
- different folders looking for the entities.
-
-* Two Datacenters
- * "Sample_DC_1"
- * "Sample_DC_2"
-* One Cluster
- * "Sample_Cluster"
-* 2 host environment
- * 1 host in Sample Cluster in Sample_DC_1
- * One network adapter per Host
- * Name of Host will be the IP address
-* 3 Datastores, any constraints?
- * Shared NFS Datastore
- * "Shared_NFS_Volume"
- * 2 Local VMFS Datastore (name the datastores based on the host)
- * "Local_VMFS_Datastore_on_"
-* 1 Standard Portgroups (verify)
- * "VM Network" (the default created per host)
-* 1 Distributed Switch ("DSwitch 1")
- * 1 non-uplink DvPortgroups
- * static ("Static Portgroup on DSwitch 1")
-* 2 created VM Folder, one in each Datacenter
- * "Sample VM Folder 1"
- * "Sample VM Folder 2"
-* Put an ISO image on a Datastore
-* Put a Floppy image on a Datastore
-"""
-
-
-def setup(context):
- print('Setup Testbed Start')
- datacenter.setup(context)
- folder.setup(context)
- cluster.setup(context)
- host.setup(context)
- datastore.setup(context)
- network.setup(context)
- backend_directory.setup(context)
- iso_image.setup(context)
- floppy_image.setup(context)
- print('Setup Testbed Complete\n')
-
-
-def cleanup(context):
- print('Cleanup Testbed Start')
- floppy_image.cleanup(context)
- if context.option['DO_TESTBED_ISO_CLEANUP']:
- iso_image.cleanup(context)
- backend_directory.cleanup(context)
- network.cleanup(context)
- datastore.cleanup(context)
- host.cleanup(context)
- cluster.cleanup(context)
- folder.cleanup(context)
- datacenter.cleanup(context)
- print('Cleanup Testbed Complete\n')
-
-
-def validate(context):
- print('Validating and Detecting Resources in Testbed')
- r = (datacenter.validate(context) and
- folder.validate(context) and
- cluster.validate(context) and
- host.validate(context) and
- datastore.validate(context) and
- network.validate(context) and
- backend_directory.validate(context) and
- iso_image.validate(context) and
- floppy_image.validate(context)
- )
- if r:
- print('==> Testbed validated')
- return True
- else:
- print('==> Testbed has errors')
- return False
diff --git a/samples/vsphere/vcenter/vm/README.md b/samples/vsphere/vcenter/vm/README.md
deleted file mode 100644
index 1556a388..00000000
--- a/samples/vsphere/vcenter/vm/README.md
+++ /dev/null
@@ -1,23 +0,0 @@
-This directory contains samples for vCenter virtual machine APIs:
-
-1. Virtual machine Create, Read and Delete operations:
- * Create a virtual machine with system provided defaults - create/create_default_vm.py
- * Create a basic virtual machine - create/create_basic_vm.py
- * Create a exhaustive virtual machine - create/create_exhaustive_vm.py
-
-2. Virtual machine power lifecycle (requires an existing virtual machine):
- * Manage virtual machine power state - power.py
-
-3. Update virtual machine hardware settings (requires an existing virtual machine):
- * Configure virtual SATA adapters of a virtual machine - hardware/adapter/sata.py
- * Configure virtual SCSI adapters of a virtual machine - hardware/adapter/scsi.py
- * Configure the booting settings for virtual machine - hardware/boot.py
- * Configure the boot devices used by a virtual machine - hardware/boot_device.py
- * Configure CD-ROM devices for a virtual machine - hardware/cdrom.py
- * Configure CPU settings for a virtual machine - hardware/cpu.py
- * Configure disk settings for a virtual machine - hardware/disk.py
- * Configure virtual ethernet adapters of a virtual machine - hardware/ethernet.py
- * Configure Floppy settings for a virtual machine - hardware/floppy.py
- * Configure Memory settings of a virtual machine - hardware/memory.py
- * Configure Parallel ports for a virtual machine - hardware/parallel.py
- * Configure Serial ports for a virtual machine - hardware/serial.py
\ No newline at end of file
diff --git a/samples/vsphere/vcenter/vm/__init__.py b/samples/vsphere/vcenter/vm/__init__.py
deleted file mode 100644
index 9bc6a0aa..00000000
--- a/samples/vsphere/vcenter/vm/__init__.py
+++ /dev/null
@@ -1,24 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/vcenter/vm/create/__init__.py b/samples/vsphere/vcenter/vm/create/__init__.py
deleted file mode 100644
index 42b8a50b..00000000
--- a/samples/vsphere/vcenter/vm/create/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/vcenter/vm/create/create_basic_vm.py b/samples/vsphere/vcenter/vm/create/create_basic_vm.py
deleted file mode 100644
index 7f0196f9..00000000
--- a/samples/vsphere/vcenter/vm/create/create_basic_vm.py
+++ /dev/null
@@ -1,173 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware.boot_client import Device as BootDevice
-from com.vmware.vcenter.vm.hardware_client import (
- Disk, Ethernet)
-from com.vmware.vcenter.vm.hardware_client import ScsiAddressSpec
-from com.vmware.vcenter.vm_client import (Power)
-from com.vmware.vcenter_client import VM
-
-from samples.vsphere.common import sample_cli
-from samples.vsphere.common import sample_util
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.common.service_manager import ServiceManager
-from samples.vsphere.vcenter.helper import network_helper
-from samples.vsphere.vcenter.helper import vm_placement_helper
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-from samples.vsphere.vcenter.setup import testbed
-
-
-class CreateBasicVM(object):
- """
- Demonstrates how to create a basic VM with following configuration:
- 2 disks, 1 nic
-
- Sample Prerequisites:
- - datacenter
- - vm folder
- - datastore
- - standard switch network
- """
-
- def __init__(self, stub_config=None, placement_spec=None):
- self.context = None
- self.service_manager = None
- self.stub_config = stub_config
- self.placement_spec = placement_spec
- self.vm_name = testbed.config['VM_NAME_BASIC']
- self.cleardata = None
-
- def setup(self):
- parser = sample_cli.build_arg_parser()
- parser.add_argument('-n', '--vm_name',
- action='store',
- help='Name of the testing vm')
- args = sample_util.process_cli_args(parser.parse_args())
- if args.vm_name:
- self.vm_name = args.vm_name
- self.cleardata = args.cleardata
-
- self.service_manager = ServiceManager(args.server,
- args.username,
- args.password,
- args.skipverification)
- self.service_manager.connect()
- atexit.register(self.service_manager.disconnect)
-
- self.stub_config = self.service_manager.stub_config
-
- def run(self):
- # Get a placement spec
- datacenter_name = testbed.config['VM_DATACENTER_NAME']
- vm_folder_name = testbed.config['VM_FOLDER2_NAME']
- datastore_name = testbed.config['VM_DATASTORE_NAME']
- std_portgroup_name = testbed.config['STDPORTGROUP_NAME']
-
- if not self.placement_spec:
- self.placement_spec = vm_placement_helper.get_placement_spec_for_resource_pool(
- self.stub_config,
- datacenter_name,
- vm_folder_name,
- datastore_name)
-
- # Get a standard network backing
- standard_network = network_helper.get_standard_network_backing(
- self.stub_config,
- std_portgroup_name,
- datacenter_name)
-
- """
- Create a basic VM.
-
- Using the provided PlacementSpec, create a VM with a selected Guest OS
- and provided name.
-
- Create a VM with the following configuration:
- * Create 2 disks and specify one of them on scsi0:0 since it's the boot disk
- * Specify 1 ethernet adapter using a Standard Portgroup backing
- * Setup for PXE install by selecting network as first boot device
-
- Use guest and system provided defaults for most configuration settings.
- """
- guest_os = testbed.config['VM_GUESTOS']
-
- boot_disk = Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI,
- scsi=ScsiAddressSpec(bus=0, unit=0),
- new_vmdk=Disk.VmdkCreateSpec())
- data_disk = Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec())
-
- nic = Ethernet.CreateSpec(
- start_connected=True,
- backing=Ethernet.BackingSpec(
- type=Ethernet.BackingType.STANDARD_PORTGROUP,
- network=standard_network))
-
- boot_device_order = [
- BootDevice.EntryCreateSpec(BootDevice.Type.ETHERNET),
- BootDevice.EntryCreateSpec(BootDevice.Type.DISK)]
-
- vm_create_spec = VM.CreateSpec(name=self.vm_name,
- guest_os=guest_os,
- placement=self.placement_spec,
- disks=[boot_disk, data_disk],
- nics=[nic],
- boot_devices=boot_device_order)
- print('\n# Example: create_basic_vm: Creating a VM using spec\n-----')
- print(pp(vm_create_spec))
- print('-----')
-
- vm_svc = VM(self.stub_config)
- vm = vm_svc.create(vm_create_spec)
-
- print("create_basic_vm: Created VM '{}' ({})".format(self.vm_name, vm))
-
- vm_info = vm_svc.get(vm)
- print('vm.get({}) -> {}'.format(vm, pp(vm_info)))
-
- return vm
-
- def cleanup(self):
- vm = get_vm(self.stub_config, self.vm_name)
- if vm:
- power_svc = Power(self.stub_config)
- vm_svc = VM(self.stub_config)
- state = power_svc.get(vm)
- if state == Power.Info(state=Power.State.POWERED_ON):
- power_svc.stop(vm)
- elif state == Power.Info(state=Power.State.SUSPENDED):
- power_svc.start(vm)
- power_svc.stop(vm)
- print("Deleting VM '{}' ({})".format(self.vm_name, vm))
- vm_svc.delete(vm)
-
-
-def main():
- create_basic_vm = CreateBasicVM()
- create_basic_vm.setup()
- create_basic_vm.cleanup()
- create_basic_vm.run()
- if create_basic_vm.cleardata:
- create_basic_vm.cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/create/create_default_vm.py b/samples/vsphere/vcenter/vm/create/create_default_vm.py
deleted file mode 100644
index 3872fd03..00000000
--- a/samples/vsphere/vcenter/vm/create/create_default_vm.py
+++ /dev/null
@@ -1,131 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm_client import (Power)
-from com.vmware.vcenter_client import VM
-
-from samples.vsphere.common import sample_cli
-from samples.vsphere.common import sample_util
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.common.service_manager import ServiceManager
-from samples.vsphere.vcenter.helper import vm_placement_helper
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-from samples.vsphere.vcenter.setup import testbed
-
-
-class CreateDefaultVM(object):
- """
- Demonstrates how to create a VM with system provided defaults
-
- Sample Prerequisites:
- - datacenter
- - vm folder
- - datastore
- """
-
- def __init__(self, stub_config=None, placement_spec=None):
- self.context = None
- self.service_manager = None
- self.stub_config = stub_config
- self.placement_spec = placement_spec
- self.vm_name = testbed.config['VM_NAME_DEFAULT']
- self.cleardata = None
-
- def setup(self):
- parser = sample_cli.build_arg_parser()
- parser.add_argument('-n', '--vm_name',
- action='store',
- help='Name of the testing vm')
- args = sample_util.process_cli_args(parser.parse_args())
- if args.vm_name:
- self.vm_name = args.vm_name
- self.cleardata = args.cleardata
-
- self.service_manager = ServiceManager(args.server,
- args.username,
- args.password,
- args.skipverification)
- self.service_manager.connect()
- atexit.register(self.service_manager.disconnect)
-
- self.stub_config = self.service_manager.stub_config
-
- def run(self):
- # Get a placement spec
- datacenter_name = testbed.config['VM_DATACENTER_NAME']
- vm_folder_name = testbed.config['VM_FOLDER2_NAME']
- datastore_name = testbed.config['VM_DATASTORE_NAME']
-
- if not self.placement_spec:
- self.placement_spec = vm_placement_helper.get_placement_spec_for_resource_pool(
- self.stub_config,
- datacenter_name,
- vm_folder_name,
- datastore_name)
-
- """
- Create a default VM.
-
- Using the provided PlacementSpec, create a VM with a selected Guest OS
- and provided name. Use all the guest and system provided defaults.
- """
- guest_os = testbed.config['VM_GUESTOS']
- vm_create_spec = VM.CreateSpec(name=self.vm_name,
- guest_os=guest_os,
- placement=self.placement_spec)
- print('\n# Example: create_default_vm: Creating a VM using spec\n-----')
- print(pp(vm_create_spec))
- print('-----')
-
- vm_svc = VM(self.stub_config)
- vm = vm_svc.create(vm_create_spec)
- print("create_default_vm: Created VM '{}' ({})".format(self.vm_name, vm))
-
- vm_info = vm_svc.get(vm)
- print('vm.get({}) -> {}'.format(vm, pp(vm_info)))
- return vm
-
- def cleanup(self):
- vm = get_vm(self.stub_config, self.vm_name)
- if vm:
- power_svc = Power(self.stub_config)
- vm_svc = VM(self.stub_config)
- state = power_svc.get(vm)
- if state == Power.Info(state=Power.State.POWERED_ON):
- power_svc.stop(vm)
- elif state == Power.Info(state=Power.State.SUSPENDED):
- power_svc.start(vm)
- power_svc.stop(vm)
- print("Deleting VM '{}' ({})".format(self.vm_name, vm))
- vm_svc.delete(vm)
-
-
-def main():
- create_default_vm = CreateDefaultVM()
- create_default_vm.setup()
- create_default_vm.cleanup()
- create_default_vm.run()
- if create_default_vm.cleardata:
- create_default_vm.cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/create/create_exhaustive_vm.py b/samples/vsphere/vcenter/vm/create/create_exhaustive_vm.py
deleted file mode 100644
index ee53e237..00000000
--- a/samples/vsphere/vcenter/vm/create/create_exhaustive_vm.py
+++ /dev/null
@@ -1,267 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware.boot_client import Device as BootDevice
-from com.vmware.vcenter.vm.hardware_client import (
- Cpu, Memory, Disk, Ethernet, Cdrom, Serial, Parallel, Floppy, Boot)
-from com.vmware.vcenter.vm.hardware_client import ScsiAddressSpec
-from com.vmware.vcenter.vm_client import (Hardware, Power)
-from com.vmware.vcenter_client import VM
-
-from samples.vsphere.common import sample_cli
-from samples.vsphere.common import sample_util
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.common.service_manager import ServiceManager
-from samples.vsphere.vcenter.helper import network_helper
-from samples.vsphere.vcenter.helper import vm_placement_helper
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-from samples.vsphere.vcenter.setup import testbed
-
-
-class CreateExhaustiveVM(object):
- """
- Demonstrates how to create a exhaustive VM with the below configuration:
- 3 disks, 2 nics, 2 vcpu, 2 GB, memory, boot=BIOS, 1 cdrom, 1 serial port,
- 1 parallel port, 1 floppy, boot_device=[CDROM, DISK, ETHERNET])
-
- Sample Prerequisites:
- - datacenter
- - vm folder
- - resource pool
- - datastore
- - standard switch network
- - distributed switch network
- - An iso file on the datastore mentioned above
- """
-
- def __init__(self, stub_config=None, placement_spec=None,
- standard_network=None, distributed_network=None):
- self.context = None
- self.service_manager = None
- self.stub_config = stub_config
- self.placement_spec = placement_spec
- self.standard_network = standard_network
- self.distributed_network = distributed_network
- self.vm_name = testbed.config['VM_NAME_EXHAUSTIVE']
- self.cleardata = None
-
- def setup(self):
- parser = sample_cli.build_arg_parser()
- parser.add_argument('-n', '--vm_name',
- action='store',
- help='Name of the testing vm')
- args = sample_util.process_cli_args(parser.parse_args())
- if args.vm_name:
- self.vm_name = args.vm_name
- self.cleardata = args.cleardata
-
- self.service_manager = ServiceManager(args.server,
- args.username,
- args.password,
- args.skipverification)
- self.service_manager.connect()
- atexit.register(self.service_manager.disconnect)
-
- self.stub_config = self.service_manager.stub_config
-
- def run(self):
- # Get a placement spec
- datacenter_name = testbed.config['VM_DATACENTER_NAME']
- vm_folder_name = testbed.config['VM_FOLDER2_NAME']
- datastore_name = testbed.config['VM_DATASTORE_NAME']
- std_portgroup_name = testbed.config['STDPORTGROUP_NAME']
- dv_portgroup_name = testbed.config['VDPORTGROUP1_NAME']
-
- if not self.placement_spec:
- self.placement_spec = vm_placement_helper.get_placement_spec_for_resource_pool(
- self.stub_config,
- datacenter_name,
- vm_folder_name,
- datastore_name)
-
- # Get a standard network backing
- if not self.standard_network:
- self.standard_network = network_helper.get_standard_network_backing(
- self.stub_config,
- std_portgroup_name,
- datacenter_name)
-
- # Get a distributed network backing
- if not self.distributed_network:
- self.distributed_network = network_helper.get_distributed_network_backing(
- self.stub_config,
- dv_portgroup_name,
- datacenter_name)
-
- """
- Create an exhaustive VM.
-
- Using the provided PlacementSpec, create a VM with a selected Guest OS
- and provided name.
-
- Create a VM with the following configuration:
- * Hardware Version = VMX_11 (for 6.0)
- * CPU (count = 2, coresPerSocket = 2, hotAddEnabled = false,
- hotRemoveEnabled = false)
- * Memory (size_mib = 2 GB, hotAddEnabled = false)
- * 3 Disks and specify each of the HBAs and the unit numbers
- * (capacity=40 GB, name=, spaceEfficient=true)
- * Specify 2 ethernet adapters, one using a Standard Portgroup backing and
- the
- other using a DISTRIBUTED_PORTGROUP networking backing.
- * nic1: Specify Ethernet (macType=MANUAL, macAddress=)
- * nic2: Specify Ethernet (macType=GENERATED)
- * 1 CDROM (type=ISO_FILE, file="os.iso", startConnected=true)
- * 1 Serial Port (type=NETWORK_SERVER, file="tcp://localhost/16000",
- startConnected=true)
- * 1 Parallel Port (type=HOST_DEVICE, startConnected=false)
- * 1 Floppy Drive (type=CLIENT_DEVICE)
- * Boot, type=BIOS
- * BootDevice order: CDROM, DISK, ETHERNET
-
- Use guest and system provided defaults for remaining configuration settings.
- """
- guest_os = testbed.config['VM_GUESTOS']
- iso_datastore_path = testbed.config['ISO_DATASTORE_PATH']
- serial_port_network_location = \
- testbed.config['SERIAL_PORT_NETWORK_SERVER_LOCATION']
-
- GiB = 1024 * 1024 * 1024
- GiBMemory = 1024
-
- vm_create_spec = VM.CreateSpec(
- guest_os=guest_os,
- name=self.vm_name,
- placement=self.placement_spec,
- hardware_version=Hardware.Version.VMX_11,
- cpu=Cpu.UpdateSpec(count=2,
- cores_per_socket=1,
- hot_add_enabled=False,
- hot_remove_enabled=False),
- memory=Memory.UpdateSpec(size_mib=2 * GiBMemory,
- hot_add_enabled=False),
- disks=[
- Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI,
- scsi=ScsiAddressSpec(bus=0, unit=0),
- new_vmdk=Disk.VmdkCreateSpec(name='boot',
- capacity=40 * GiB)),
- Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec(name='data1',
- capacity=10 * GiB)),
- Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec(name='data2',
- capacity=10 * GiB))
- ],
- nics=[
- Ethernet.CreateSpec(
- start_connected=True,
- mac_type=Ethernet.MacAddressType.MANUAL,
- mac_address='11:23:58:13:21:34',
- backing=Ethernet.BackingSpec(
- type=Ethernet.BackingType.STANDARD_PORTGROUP,
- network=self.standard_network)),
- Ethernet.CreateSpec(
- start_connected=True,
- mac_type=Ethernet.MacAddressType.GENERATED,
- backing=Ethernet.BackingSpec(
- type=Ethernet.BackingType.DISTRIBUTED_PORTGROUP,
- network=self.distributed_network)),
- ],
- cdroms=[
- Cdrom.CreateSpec(
- start_connected=True,
- backing=Cdrom.BackingSpec(type=Cdrom.BackingType.ISO_FILE,
- iso_file=iso_datastore_path)
- )
- ],
- serial_ports=[
- Serial.CreateSpec(
- start_connected=False,
- backing=Serial.BackingSpec(
- type=Serial.BackingType.NETWORK_SERVER,
- network_location=serial_port_network_location)
- )
- ],
- parallel_ports=[
- Parallel.CreateSpec(
- start_connected=False,
- backing=Parallel.BackingSpec(
- type=Parallel.BackingType.HOST_DEVICE)
- )
- ],
- floppies=[
- Floppy.CreateSpec(
- backing=Floppy.BackingSpec(
- type=Floppy.BackingType.CLIENT_DEVICE)
- )
- ],
- boot=Boot.CreateSpec(type=Boot.Type.BIOS,
- delay=0,
- enter_setup_mode=False
- ),
- # TODO Should DISK be put before CDROM and ETHERNET? Does the BIOS
- # automatically try the next device if the DISK is empty?
- boot_devices=[
- BootDevice.EntryCreateSpec(BootDevice.Type.CDROM),
- BootDevice.EntryCreateSpec(BootDevice.Type.DISK),
- BootDevice.EntryCreateSpec(BootDevice.Type.ETHERNET)
- ]
- )
- print(
- '# Example: create_exhaustive_vm: Creating a VM using spec\n-----')
- print(pp(vm_create_spec))
- print('-----')
-
- vm_svc = VM(self.stub_config)
- vm = vm_svc.create(vm_create_spec)
-
- print("create_exhaustive_vm: Created VM '{}' ({})".format(self.vm_name,
- vm))
-
- vm_info = vm_svc.get(vm)
- print('vm.get({}) -> {}'.format(vm, pp(vm_info)))
-
- return vm
-
- def cleanup(self):
- vm = get_vm(self.stub_config, self.vm_name)
- if vm:
- power_svc = Power(self.stub_config)
- vm_svc = VM(self.stub_config)
- state = power_svc.get(vm)
- if state == Power.Info(state=Power.State.POWERED_ON):
- power_svc.stop(vm)
- elif state == Power.Info(state=Power.State.SUSPENDED):
- power_svc.start(vm)
- power_svc.stop(vm)
- print("Deleting VM '{}' ({})".format(self.vm_name, vm))
- vm_svc.delete(vm)
-
-
-def main():
- create_exhaustive_vm = CreateExhaustiveVM()
- create_exhaustive_vm.setup()
- create_exhaustive_vm.cleanup()
- create_exhaustive_vm.run()
- if create_exhaustive_vm.cleardata:
- create_exhaustive_vm.cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/delete_vm.py b/samples/vsphere/vcenter/vm/delete_vm.py
deleted file mode 100644
index 472113b0..00000000
--- a/samples/vsphere/vcenter/vm/delete_vm.py
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm_client import Power
-from com.vmware.vcenter_client import VM
-
-from samples.vsphere.common import sample_cli
-from samples.vsphere.common import sample_util
-from samples.vsphere.common.service_manager import ServiceManager
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-
-class DeleteVM(object):
- """
- Demonstrates Deleting User specified Virtual Machine (VM)
- Sample Prerequisites:
- vCenter/ESX
- """
-
- def __init__(self):
- self.service_manager = None
- self.vm_name = None
-
- def setup(self):
- parser = sample_cli.build_arg_parser()
- parser.add_argument('-n', '--vm_name',
- action='store',
- default='Sample_Default_VM_for_Simple_Testbed',
- help='Name of the testing vm')
- args = sample_util.process_cli_args(parser.parse_args())
- self.vm_name = args.vm_name
-
- self.service_manager = ServiceManager(args.server,
- args.username,
- args.password,
- args.skipverification)
- self.service_manager.connect()
- atexit.register(self.service_manager.disconnect)
-
- def run(self):
- """
- Delete User specified VM from Server
- """
- vm_svc = VM(self.service_manager.stub_config)
- power_svc = Power(self.service_manager.stub_config)
- vm = get_vm(self.service_manager.stub_config, self.vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}).'
- 'Please create the vm first.'.format(vm_name))
- print("Deleting VM -- '{}-({})')".format(self.vm_name, vm))
- state = power_svc.get(vm)
- if state == Power.Info(state=Power.State.POWERED_ON):
- power_svc.stop(vm)
- elif state == Power.Info(state=Power.State.SUSPENDED):
- power_svc.start(vm)
- power_svc.stop(vm)
- vm_svc.delete(vm)
- print("Deleted VM -- '{}-({})".format(self.vm_name, vm))
-
-
-def main():
- delete_vm = DeleteVM()
- delete_vm.setup()
- delete_vm.run()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/__init__.py b/samples/vsphere/vcenter/vm/hardware/__init__.py
deleted file mode 100644
index 42b8a50b..00000000
--- a/samples/vsphere/vcenter/vm/hardware/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/vcenter/vm/hardware/adapter/__init__.py b/samples/vsphere/vcenter/vm/hardware/adapter/__init__.py
deleted file mode 100644
index 42b8a50b..00000000
--- a/samples/vsphere/vcenter/vm/hardware/adapter/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""
-* *******************************************************
-* Copyright VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-
-# Required to distribute different parts of this
-# package as multiple distribution
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__) # @ReservedAssignment
diff --git a/samples/vsphere/vcenter/vm/hardware/adapter/sata.py b/samples/vsphere/vcenter/vm/hardware/adapter/sata.py
deleted file mode 100644
index 3b39ff4a..00000000
--- a/samples/vsphere/vcenter/vm/hardware/adapter/sata.py
+++ /dev/null
@@ -1,139 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware.adapter_client import Sata
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import pp, \
- parse_cli_args_vm
-from samples.vsphere.vcenter.setup import testbed
-
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-"""
-Demonstrates how to configure virtual SATA adapters of a virtual machine.
-
-Sample Prerequisites:
-The sample needs an existing VM.
-"""
-
-vm = None
-vm_name = None
-stub_config = None
-sata_svc = None
-cleardata = False
-satas_to_delete = []
-orig_sata_summaries = None
-
-
-def setup(context=None):
- global vm, vm_name, stub_config, cleardata
- if context:
- # Run sample suite via setup script
- stub_config = context.stub_config
- vm_name = testbed.config['VM_NAME_DEFAULT']
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
-
-def run():
- global vm
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for SATA Sample".format(vm_name, vm))
-
- # Create SATA adapter stub used for making requests
- global sata_svc
- sata_svc = Sata(stub_config)
-
- print('\n# Example: List all SATA adapters for a VM')
- sata_summaries = sata_svc.list(vm=vm)
- print('vm.hardware.adapter.Sata.list({}) -> {}'.format(vm, sata_summaries))
-
- # Save current list of SATA adapters to verify that we have cleaned up
- # properly
- global orig_sata_summaries
- orig_sata_summaries = sata_summaries
-
- # Get information for each SATA adapter on the VM
- for sata_summary in sata_summaries:
- sata = sata_summary.adapter
- sata_info = sata_svc.get(vm=vm, adapter=sata)
- print('vm.hardware.adapter.Sata.get({}, {}) -> {}'.
- format(vm, sata, pp(sata_info)))
-
- global satas_to_delete
-
- print('\n# Example: Create SATA adapter with defaults')
- sata_create_spec = Sata.CreateSpec()
- sata = sata_svc.create(vm, sata_create_spec)
- print('vm.hardware.adapter.Sata.create({}, {}) -> {}'.
- format(vm, sata_create_spec, sata))
- satas_to_delete.append(sata)
- sata_info = sata_svc.get(vm, sata)
- print('vm.hardware.adapter.Sata.get({}, {}) -> {}'.
- format(vm, sata, pp(sata_info)))
-
- print('\n# Example: Create SATA adapter with a specific bus')
- sata_create_spec = Sata.CreateSpec(bus=2)
- sata = sata_svc.create(vm, sata_create_spec)
- print('vm.hardware.adapter.Sata.create({}, {}) -> {}'.
- format(vm, sata_create_spec, sata))
- satas_to_delete.append(sata)
- sata_info = sata_svc.get(vm, sata)
- print('vm.hardware.adapter.Sata.get({}, {}) -> {}'.
- format(vm, sata, pp(sata_info)))
-
- # List all SATA adapters for a VM
- sata_summaries = sata_svc.list(vm=vm)
- print('vm.hardware.adapter.Sata.list({}) -> {}'.format(vm, sata_summaries))
-
-
-def cleanup():
- print('\n# Cleanup: Delete VM SATA adapters that were added')
- for sata in satas_to_delete:
- sata_svc.delete(vm, sata)
- print('vm.hardware.adapter.Sata.delete({}, {})'.format(vm, sata))
-
- sata_summaries = sata_svc.list(vm)
- print('vm.hardware.adapter.Sata.list({}) -> {}'.format(vm, sata_summaries))
- if set(orig_sata_summaries) != set(sata_summaries):
- print('vm.hardware.adapter.Sata WARNING: '
- 'Final SATA adapters info does not match original')
-
-
-def main():
- setup()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/adapter/scsi.py b/samples/vsphere/vcenter/vm/hardware/adapter/scsi.py
deleted file mode 100644
index a773f64f..00000000
--- a/samples/vsphere/vcenter/vm/hardware/adapter/scsi.py
+++ /dev/null
@@ -1,150 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware.adapter_client import Scsi
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import pp, \
- parse_cli_args_vm
-from samples.vsphere.vcenter.setup import testbed
-
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-"""
-Demonstrates how to configure virtual SCSI adapters of a virtual machine.
-
-Sample Prerequisites:
-The sample needs an existing VM.
-"""
-
-vm = None
-vm_name = None
-stub_config = None
-scsi_svc = None
-cleardata = False
-scsis_to_delete = []
-orig_scsi_summaries = None
-
-
-def setup(context=None):
- global vm, vm_name, stub_config, cleardata
- if context:
- # Run sample suite via setup script
- stub_config = context.stub_config
- vm_name = testbed.config['VM_NAME_DEFAULT']
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
-
-def run():
- global vm
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for SCSI Sample".format(vm_name, vm))
-
- # Create SCSI adapter stub used for making requests
- global scsi_svc
- scsi_svc = Scsi(stub_config)
-
- print('\n# Example: List all SCSI adapters for a VM')
- scsi_summaries = scsi_svc.list(vm=vm)
- print('vm.hardware.adapter.Scsi.list({}) -> {}'.format(vm, scsi_summaries))
-
- # Save current list of SCSI adapters to verify that we have cleaned up
- # properly
- global orig_scsi_summaries
- orig_scsi_summaries = scsi_summaries
-
- # Get information for each SCSI adapter on the VM
- for scsi_summary in scsi_summaries:
- scsi = scsi_summary.adapter
- scsi_info = scsi_svc.get(vm=vm, adapter=scsi)
- print('vm.hardware.adapter.Scsi.get({}, {}) -> {}'.
- format(vm, scsi, pp(scsi_info)))
-
- global scsis_to_delete
-
- print('\n# Example: Create SCSI adapter with defaults')
- scsi_create_spec = Scsi.CreateSpec()
- scsi = scsi_svc.create(vm, scsi_create_spec)
- print('vm.hardware.adapter.Scsi.create({}, {}) -> {}'.
- format(vm, scsi_create_spec, scsi))
- scsis_to_delete.append(scsi)
- scsi_info = scsi_svc.get(vm, scsi)
- print('vm.hardware.adapter.Scsi.get({}, {}) -> {}'.
- format(vm, scsi, pp(scsi_info)))
-
- print('\n# Example: Create SCSI adapter with a specific bus '
- 'and sharing=True')
- scsi_create_spec = Scsi.CreateSpec(bus=2,
- sharing=Scsi.Sharing.VIRTUAL)
- scsi = scsi_svc.create(vm, scsi_create_spec)
- print('vm.hardware.adapter.Scsi.create({}, {}) -> {}'.
- format(vm, scsi_create_spec, scsi))
- scsis_to_delete.append(scsi)
- scsi_info = scsi_svc.get(vm, scsi)
- print('vm.hardware.adapter.Scsi.get({}, {}) -> {}'.
- format(vm, scsi, pp(scsi_info)))
-
- print('\n# Example: Update SCSI adapter by setting sharing=False')
- scsi_update_spec = Scsi.UpdateSpec(sharing=Scsi.Sharing.NONE)
- scsi_svc.update(vm, scsi, scsi_update_spec)
- print('vm.hardware.adapter.Scsi.update({}, {}, {})'.
- format(vm, scsi, scsi_create_spec))
- scsi_info = scsi_svc.get(vm, scsi)
- print('vm.hardware.adapter.Scsi.get({}, {}) -> {}'.
- format(vm, scsi, pp(scsi_info)))
-
- # List all SCSI adapters for a VM
- scsi_summaries = scsi_svc.list(vm=vm)
- print('vm.hardware.adapter.Scsi.list({}) -> {}'.format(vm, scsi_summaries))
-
-
-def cleanup():
- print('\n# Cleanup: Delete VM SCSI adapters that were added')
- for scsi in scsis_to_delete:
- scsi_svc.delete(vm, scsi)
- print('vm.hardware.adapter.Scsi.delete({}, {})'.format(vm, scsi))
-
- scsi_summaries = scsi_svc.list(vm)
- print('vm.hardware.adapter.Scsi.list({}) -> {}'.format(vm, scsi_summaries))
- if set(orig_scsi_summaries) != set(scsi_summaries):
- print('vm.hardware.adapter.Scsi WARNING: '
- 'Final SCSI adapters info does not match original')
-
-
-def main():
- setup()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/boot.py b/samples/vsphere/vcenter/vm/hardware/boot.py
deleted file mode 100644
index 2669e278..00000000
--- a/samples/vsphere/vcenter/vm/hardware/boot.py
+++ /dev/null
@@ -1,139 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware_client import Boot
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import parse_cli_args_vm
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.vcenter.setup import testbed
-
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-"""
-Demonstrates how to configure the settings used when booting a virtual machine.
-
-Sample Prerequisites:
-The sample needs an existing VM.
-"""
-
-vm = None
-vm_name = None
-stub_config = None
-boot_svc = None
-cleardata = False
-orig_boot_info = None
-
-
-def setup(context=None):
- global vm, vm_name, stub_config, cleardata
- if context:
- # Run sample suite via setup script
- stub_config = context.stub_config
- vm_name = testbed.config['VM_NAME_DEFAULT']
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
-
-def run():
- global vm
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for Boot Sample".format(vm_name, vm))
-
- # Create Boot stub used for making requests
- global boot_svc
- boot_svc = Boot(stub_config)
-
- print('\n# Example: Get current Boot configuration')
- boot_info = boot_svc.get(vm)
- print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info)))
-
- # Save current Boot info to verify that we have cleaned up properly
- global orig_boot_info
- orig_boot_info = boot_info
-
- print('\n# Example: Update firmware to EFI for Boot configuration')
- update_spec = Boot.UpdateSpec(type=Boot.Type.EFI)
- print('vm.hardware.Boot.update({}, {})'.format(vm, update_spec))
- boot_svc.update(vm, update_spec)
- boot_info = boot_svc.get(vm)
- print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info)))
-
- print('\n# Example: Update boot firmware to tell it to enter setup mode on '
- 'next boot')
- update_spec = Boot.UpdateSpec(enter_setup_mode=True)
- print('vm.hardware.Boot.update({}, {})'.format(vm, update_spec))
- boot_svc.update(vm, update_spec)
- boot_info = boot_svc.get(vm)
- print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info)))
-
- print('\n# Example: Update boot firmware to introduce a delay in boot'
- ' process and to reboot')
- print('# automatically after a failure to boot. '
- '(delay=10000 ms, retry=True,')
- print('# retry_delay=30000 ms')
- update_spec = Boot.UpdateSpec(delay=10000,
- retry=True,
- retry_delay=30000)
- print('vm.hardware.Boot.update({}, {})'.format(vm, update_spec))
- boot_svc.update(vm, update_spec)
- boot_info = boot_svc.get(vm)
- print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info)))
-
-
-def cleanup():
- print('\n# Cleanup: Revert Boot configuration')
- update_spec = \
- Boot.UpdateSpec(type=orig_boot_info.type,
- efi_legacy_boot=orig_boot_info.efi_legacy_boot,
- network_protocol=orig_boot_info.network_protocol,
- delay=orig_boot_info.delay,
- retry=orig_boot_info.retry,
- retry_delay=orig_boot_info.retry_delay,
- enter_setup_mode=orig_boot_info.enter_setup_mode)
- print('vm.hardware.Boot.update({}, {})'.format(vm, update_spec))
- boot_svc.update(vm, update_spec)
- boot_info = boot_svc.get(vm)
- print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info)))
-
- if boot_info != orig_boot_info:
- print('vm.hardware.Boot WARNING: '
- 'Final Boot info does not match original')
-
-
-def main():
- setup()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/boot_device.py b/samples/vsphere/vcenter/vm/hardware/boot_device.py
deleted file mode 100644
index 987daec2..00000000
--- a/samples/vsphere/vcenter/vm/hardware/boot_device.py
+++ /dev/null
@@ -1,139 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware.boot_client import Device as BootDevice
-from com.vmware.vcenter.vm.hardware_client import (Disk, Ethernet)
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import parse_cli_args_vm
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.vcenter.setup import testbed
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-"""
-Demonstrates how to modify the boot devices used by a virtual machine, and in
-what order they are tried.
-
-Sample Prerequisites:
-The sample needs an existing VM with the following configuration:
- 1 Ethernet adapter
- 1 Cdrom
- 1 Floppy drive
- 3 Disks
-"""
-
-vm = None
-vm_name = None
-stub_config = None
-boot_device_svc = None
-cleardata = False
-orig_boot_device_entries = None
-
-
-def setup(context=None):
- global vm, vm_name, stub_config, cleardata
- if context:
- # Run sample suite via setup script
- stub_config = context.stub_config
- vm_name = testbed.config['VM_NAME_EXHAUSTIVE']
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_EXHAUSTIVE'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
-
-def run():
- global vm
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for BootDevice Sample".format(vm_name, vm))
-
- # Create BootDevice stub used for making requests
- global boot_device_svc
- boot_device_svc = BootDevice(stub_config)
-
- print('\n# Example: Get current BootDevice configuration')
- boot_device_entries = boot_device_svc.get(vm)
- print('vm.hardware.boot.Device.get({}) -> {}'.
- format(vm, pp(boot_device_entries)))
-
- # Save current BootDevice info to verify that we have cleaned up properly
- global orig_boot_device_entries
- orig_boot_device_entries = boot_device_entries
-
- # Get device identifiers for Disks
- disk_svc = Disk(stub_config)
- disk_summaries = disk_svc.list(vm)
- print('vm.hardware.Disk.list({}) -> {}'.format(vm, pp(disk_summaries)))
- disks = [disk_summary.disk for disk_summary in disk_summaries]
-
- # Get device identifiers for Ethernet nics
- ethernet_svc = Ethernet(stub_config)
- nic_summaries = ethernet_svc.list(vm)
- print('vm.hardware.Ethernet.list({}) -> {}'.format(vm, pp(nic_summaries)))
- nics = [nic_summary.nic for nic_summary in nic_summaries]
-
- print('\n# Example: Set Boot Order to be Floppy, '
- 'Disk1, Disk2, Disk3, Cdrom,')
- print('# Network (nic0), Network (nic1).')
- boot_device_entries = [
- BootDevice.Entry(BootDevice.Type.FLOPPY),
- BootDevice.Entry(BootDevice.Type.DISK, disks=disks),
- BootDevice.Entry(BootDevice.Type.CDROM)]
- for nic in nics:
- boot_device_entries.append(
- BootDevice.Entry(BootDevice.Type.ETHERNET, nic=nic))
- print('vm.hardware.boot.Device.set({}, {})'.format(vm, boot_device_entries))
- boot_device_svc.set(vm, boot_device_entries)
- boot_device_entries = boot_device_svc.get(vm)
- print('vm.hardware.boot.Device.get({}) -> {}'.
- format(vm, pp(boot_device_entries)))
-
-
-def cleanup():
- print('\n# Cleanup: Revert BootDevice configuration')
- boot_device_entries = orig_boot_device_entries
- print('vm.hardware.boot.Device.set({}, {})'.format(vm, boot_device_entries))
- boot_device_svc.set(vm, boot_device_entries)
- boot_device_entries = boot_device_svc.get(vm)
- print('vm.hardware.boot.Device.get({}) -> {}'.
- format(vm, pp(boot_device_entries)))
-
- if boot_device_entries != orig_boot_device_entries:
- print('vm.hardware.boot.Device WARNING: '
- 'Final BootDevice info does not match original')
-
-
-def main():
- setup()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/cdrom.py b/samples/vsphere/vcenter/vm/hardware/cdrom.py
deleted file mode 100644
index 416ad34d..00000000
--- a/samples/vsphere/vcenter/vm/hardware/cdrom.py
+++ /dev/null
@@ -1,292 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware.adapter_client import Sata
-from com.vmware.vcenter.vm.hardware_client import (Cdrom,
- IdeAddressSpec,
- SataAddressSpec)
-from com.vmware.vcenter.vm_client import Power
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import parse_cli_args_vm
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.vcenter.setup import testbed
-
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-"""
-Demonstrates how to configure CD-ROM devices for a VM.
-
-Sample Prerequisites:
-The sample needs an existing VM.
-"""
-
-vm = None
-vm_name = None
-sata = None
-stub_config = None
-cdrom_svc = None
-vm_power_svc = None
-sata_svc = None
-cleardata = False
-cdroms_to_delete = []
-orig_cdrom_summaries = None
-
-
-def setup(context=None):
- global vm, vm_name, stub_config, cleardata
- if context:
- # Run sample suite via setup script
- stub_config = context.stub_config
- vm_name = testbed.config['VM_NAME_DEFAULT']
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
-
-def run():
- global vm
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for CD-ROM Sample".format(vm_name, vm))
- iso_datastore_path = testbed.config['ISO_DATASTORE_PATH']
-
- # Create CD-ROM stub used for making requests
- global cdrom_svc, vm_power_svc, sata_svc
- cdrom_svc = Cdrom(stub_config)
- vm_power_svc = Power(stub_config)
-
- # Create SATA controller
- print('\n# Setup: Create a SATA controller')
- sata_svc = Sata(stub_config)
- sata_create_spec = Sata.CreateSpec()
- print('# Adding SATA controller for SATA Disk samples')
- global sata
- sata = sata_svc.create(vm, sata_create_spec)
- print('vm.hardware.adapter.Sata.create({}, {}) -> {}'.
- format(vm, sata_create_spec, sata))
-
- print('\n# Example: List all Cdroms for a VM')
- cdrom_summaries = cdrom_svc.list(vm=vm)
- print('vm.hardware.Cdrom.list({}) -> {}'.format(vm, cdrom_summaries))
-
- # Save current list of Cdroms to verify that we have cleaned up properly
- global orig_cdrom_summaries
- orig_cdrom_summaries = cdrom_summaries
-
- # Get information for each CD-ROM on the VM
- for cdrom_summary in cdrom_summaries:
- cdrom = cdrom_summary.cdrom
- cdrom_info = cdrom_svc.get(vm=vm, cdrom=cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- global cdroms_to_delete
-
- print('\n# Example: Create CD-ROM with ISO_FILE backing')
- cdrom_create_spec = Cdrom.CreateSpec(
- start_connected=True,
- backing=Cdrom.BackingSpec(type=Cdrom.BackingType.ISO_FILE,
- iso_file=iso_datastore_path))
- cdrom = cdrom_svc.create(vm, cdrom_create_spec)
- cdroms_to_delete.append(cdrom)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Example: Create CD-ROM with CLIENT_DEVICE backing')
- cdrom_create_spec = Cdrom.CreateSpec(
- backing=Cdrom.BackingSpec(type=Cdrom.BackingType.CLIENT_DEVICE))
- cdrom = cdrom_svc.create(vm, cdrom_create_spec)
- print('vm.hardware.Cdrom.create({}, {}) -> {}'.
- format(vm, cdrom_create_spec, cdrom))
- cdroms_to_delete.append(cdrom)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Example: Create CD-ROM using auto-detect HOST_DEVICE backing')
- cdrom_create_spec = Cdrom.CreateSpec(
- backing=Cdrom.BackingSpec(type=Cdrom.BackingType.HOST_DEVICE))
- cdrom = cdrom_svc.create(vm, cdrom_create_spec)
- print('vm.hardware.Cdrom.create({}, {}) -> {}'.
- format(vm, cdrom_create_spec, cdrom))
- cdroms_to_delete.append(cdrom)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Example: Create SATA CD-ROM using CLIENT_DEVICE backing')
- cdrom_create_spec = Cdrom.CreateSpec(
- type=Cdrom.HostBusAdapterType.SATA,
- backing=Cdrom.BackingSpec(type=Cdrom.BackingType.CLIENT_DEVICE))
- cdrom = cdrom_svc.create(vm, cdrom_create_spec)
- print('vm.hardware.Cdrom.create({}, {}) -> {}'.
- format(vm, cdrom_create_spec, cdrom))
- cdroms_to_delete.append(cdrom)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Example: Create SATA CD-ROM on specific bus using '
- 'CLIENT_DEVICE backing')
- cdrom_create_spec = Cdrom.CreateSpec(
- type=Cdrom.HostBusAdapterType.SATA,
- sata=SataAddressSpec(bus=0),
- backing=Cdrom.BackingSpec(type=Cdrom.BackingType.CLIENT_DEVICE))
- cdrom = cdrom_svc.create(vm, cdrom_create_spec)
- print('vm.hardware.Cdrom.create({}, {}) -> {}'.
- format(vm, cdrom_create_spec, cdrom))
- cdroms_to_delete.append(cdrom)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Example: Create SATA CD-ROM on specific bus and unit using '
- 'CLIENT_DEVICE backing')
- cdrom_create_spec = Cdrom.CreateSpec(
- type=Cdrom.HostBusAdapterType.SATA,
- sata=SataAddressSpec(bus=0, unit=10),
- backing=Cdrom.BackingSpec(type=Cdrom.BackingType.CLIENT_DEVICE))
- cdrom = cdrom_svc.create(vm, cdrom_create_spec)
- print('vm.hardware.Cdrom.create({}, {}) -> {}'.
- format(vm, cdrom_create_spec, cdrom))
- cdroms_to_delete.append(cdrom)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Example: Create IDE CD-ROM using CLIENT_DEVICE backing')
- cdrom_create_spec = Cdrom.CreateSpec(
- type=Cdrom.HostBusAdapterType.IDE,
- backing=Cdrom.BackingSpec(type=Cdrom.BackingType.CLIENT_DEVICE))
- cdrom = cdrom_svc.create(vm, cdrom_create_spec)
- print('vm.hardware.Cdrom.create({}, {}) -> {}'.
- format(vm, cdrom_create_spec, cdrom))
- cdroms_to_delete.append(cdrom)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Example: Create IDE CD-ROM on specific bus and unit using '
- 'CLIENT_DEVICE backing')
- cdrom_create_spec = Cdrom.CreateSpec(
- type=Cdrom.HostBusAdapterType.IDE,
- ide=IdeAddressSpec(False, True),
- backing=Cdrom.BackingSpec(type=Cdrom.BackingType.CLIENT_DEVICE))
- cdrom = cdrom_svc.create(vm, cdrom_create_spec)
- print('vm.hardware.Cdrom.create({}, {}) -> {}'.
- format(vm, cdrom_create_spec, cdrom))
- cdroms_to_delete.append(cdrom)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- # Change the last cdrom that was created
-
- print('\n# Example: Update backing from CLIENT_DEVICE to ISO_FILE')
- cdrom_update_spec = Cdrom.UpdateSpec(
- backing=Cdrom.BackingSpec(type=Cdrom.BackingType.ISO_FILE,
- iso_file=iso_datastore_path))
- print('vm.hardware.Cdrom.update({}, {}, {})'.
- format(vm, cdrom, cdrom_update_spec))
- cdrom_svc.update(vm, cdrom, cdrom_update_spec)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Example: Update start_connected=False, '
- 'allow_guest_control=False')
- cdrom_update_spec = Cdrom.UpdateSpec(
- start_connected=False, allow_guest_control=False)
- print('vm.hardware.Cdrom.update({}, {}, {})'.
- format(vm, cdrom, cdrom_update_spec))
- cdrom_svc.update(vm, cdrom, cdrom_update_spec)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Starting VM to run connect/disconnect sample')
- print('vm.Power.start({})'.format(vm))
- vm_power_svc.start(vm)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Example: Connect CD-ROM after powering on VM')
- cdrom_svc.connect(vm, cdrom)
- print('vm.hardware.Cdrom.connect({}, {})'.format(vm, cdrom))
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Example: Disconnect CD-ROM while VM is powered on')
- cdrom_svc.disconnect(vm, cdrom)
- print('vm.hardware.Cdrom.disconnect({}, {})'.format(vm, cdrom))
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- print('\n# Stopping VM after connect/disconnect sample')
- print('vm.Power.start({})'.format(vm))
- vm_power_svc.stop(vm)
- cdrom_info = cdrom_svc.get(vm, cdrom)
- print('vm.hardware.Cdrom.get({}, {}) -> {}'.
- format(vm, cdrom, pp(cdrom_info)))
-
- # List all Cdroms for a VM
- cdrom_summaries = cdrom_svc.list(vm=vm)
- print('vm.hardware.Cdrom.list({}) -> {}'.format(vm, cdrom_summaries))
-
-
-def cleanup():
- print('\n# Cleanup: Delete VM Cdroms that were added')
- for cdrom in cdroms_to_delete:
- cdrom_svc.delete(vm, cdrom)
- print('vm.hardware.Cdrom.delete({}, {})'.format(vm, cdrom))
-
- print('\n# Cleanup: Remove SATA controller')
- print('vm.hardware.adapter.Sata.delete({}, {})'.format(vm, sata))
- sata_svc.delete(vm, sata)
-
- cdrom_summaries = cdrom_svc.list(vm)
- print('vm.hardware.Cdrom.list({}) -> {}'.format(vm, cdrom_summaries))
- if set(orig_cdrom_summaries) != set(cdrom_summaries):
- print('vm.hardware.Cdrom WARNING: '
- 'Final CD-ROM info does not match original')
-
-
-def main():
- setup()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/cpu.py b/samples/vsphere/vcenter/vm/hardware/cpu.py
deleted file mode 100644
index 655c6f77..00000000
--- a/samples/vsphere/vcenter/vm/hardware/cpu.py
+++ /dev/null
@@ -1,127 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware_client import Cpu
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import parse_cli_args_vm
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.vcenter.setup import testbed
-
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-"""
-Demonstrates how to configure CPU settings for a VM.
-
-Sample Prerequisites:
-The sample needs an existing VM.
-"""
-
-vm = None
-vm_name = None
-stub_config = None
-cpu_svc = None
-cleardata = False
-orig_cpu_info = None
-
-
-def setup(context=None):
- global vm, vm_name, stub_config, cleardata
- if context:
- # Run sample suite via setup script
- stub_config = context.stub_config
- vm_name = testbed.config['VM_NAME_DEFAULT']
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
-
-def run():
- global vm
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for Cpu Sample".format(vm_name, vm))
-
- # Create Cpu stub used for making requests
- global cpu_svc
- cpu_svc = Cpu(stub_config)
-
- print('\n# Example: Get current Cpu configuration')
- cpu_info = cpu_svc.get(vm)
- print('vm.hardware.Cpu.get({}) -> {}'.format(vm, pp(cpu_info)))
-
- # Save current Cpu info to verify that we have cleaned up properly
- global orig_cpu_info
- orig_cpu_info = cpu_info
-
- print('\n# Example: Update cpu field of Cpu configuration')
- update_spec = Cpu.UpdateSpec(count=2)
- print('vm.hardware.Cpu.update({}, {})'.format(vm, update_spec))
- cpu_svc.update(vm, update_spec)
-
- # Get new Cpu configuration
- cpu_info = cpu_svc.get(vm)
- print('vm.hardware.Cpu.get({}) -> {}'.format(vm, pp(cpu_info)))
-
- print('\n# Example: Update other less likely used fields of Cpu configuration')
- update_spec = Cpu.UpdateSpec(cores_per_socket=2, hot_add_enabled=True)
- print('vm.hardware.Cpu.update({}, {})'.format(vm, update_spec))
- cpu_svc.update(vm, update_spec)
-
- # Get new Cpu configuration
- cpu_info = cpu_svc.get(vm)
- print('vm.hardware.Cpu.get({}) -> {}'.format(vm, pp(cpu_info)))
-
-
-def cleanup():
- print('\n# Cleanup: Revert Cpu configuration')
- update_spec = \
- Cpu.UpdateSpec(count=orig_cpu_info.count,
- cores_per_socket=orig_cpu_info.cores_per_socket,
- hot_add_enabled=orig_cpu_info.hot_add_enabled,
- hot_remove_enabled=orig_cpu_info.hot_remove_enabled)
- print('vm.hardware.Cpu.update({}, {})'.format(vm, update_spec))
- cpu_svc.update(vm, update_spec)
-
- # Get final Cpu configuration
- cpu_info = cpu_svc.get(vm)
- print('vm.hardware.Cpu.get({}) -> {}'.format(vm, pp(cpu_info)))
-
- if cpu_info != orig_cpu_info:
- print('vm.hardware.Cpu WARNING: Final Cpu info does not match original')
-
-
-def main():
- setup()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/disk.py b/samples/vsphere/vcenter/vm/hardware/disk.py
deleted file mode 100644
index c07fdd73..00000000
--- a/samples/vsphere/vcenter/vm/hardware/disk.py
+++ /dev/null
@@ -1,403 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware.adapter_client import Sata
-from com.vmware.vcenter.vm.hardware_client import Disk
-from com.vmware.vcenter.vm.hardware_client import (IdeAddressSpec,
- SataAddressSpec,
- ScsiAddressSpec)
-from pyVim.connect import SmartConnect, Disconnect
-from samples.vsphere.common.vim.vmdk import (create_vmdk, delete_vmdk, detect_vmdk)
-
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import parse_cli_args_vm
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.common.ssl_helper import get_unverified_context
-from samples.vsphere.common.vim.inventory import \
- (get_datacenter_for_datastore, get_datastore_mo)
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-from samples.vsphere.vcenter.setup import testbed
-
-"""
-Demonstrates how to configure disk settings for a VM.
-
-Sample Prerequisites:
-The sample needs an existing VM.
-"""
-
-vm = None
-stub_config = None
-soap_stub = None
-service_instance = None
-sata_svc = None
-disk_svc = None
-cleardata = False
-saved_disk_info = None
-datacenter_mo = None
-disks_to_delete = []
-orig_disk_summaries = None
-
-
-def setup(context=None):
- global stub_config, service_instance, cleardata
- if context:
- # Run sample suite via setup script
- vm_name = testbed.config['VM_NAME_DEFAULT']
- stub_config = context.stub_config
- service_instance = context.service_instance
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
-
- # Connect to vAPI Endpoint on vCenter system
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
- # Connect to VIM API Endpoint on vCenter system
- context = None
- if skip_verification:
- context = get_unverified_context()
- service_instance = SmartConnect(host=server,
- user=username,
- pwd=password,
- sslContext=context)
- atexit.register(Disconnect, service_instance)
-
- global vm, datacenter_name, datastore_name
- global datastore_mo, datacenter_mo, datastore_root_path
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for Disk Sample".format(vm_name, vm))
-
- # Get the datacenter and datastore managed objects to be able to create and
- # delete VMDKs, which are backings for a VM Disk.
- datacenter_name = testbed.config['VM_DATACENTER_NAME']
- datastore_name = testbed.config['VM_DATASTORE_NAME']
- datastore_mo = get_datastore_mo(stub_config,
- service_instance._stub,
- datacenter_name,
- datastore_name)
- datacenter_mo = get_datacenter_for_datastore(datastore_mo)
-
- # The datastore_root_path is path in the datastore where the additional
- # VMDK files will be created for this sample.
- datastore_root_path = testbed.config['DISK_DATASTORE_ROOT_PATH']
-
-
-def run():
- GiB = 1024 * 1024 * 1024
-
- # Create Disk stub used for making requests
- global disk_svc
- disk_svc = Disk(stub_config)
-
- print('\n# Example: List all Disks for a VM')
- disk_summaries = disk_svc.list(vm=vm)
- print('vm.hardware.Disk.list({}) -> {}'.format(vm, disk_summaries))
-
- # Save current list of disks to verify that we have cleaned up properly
- global orig_disk_summaries
- orig_disk_summaries = disk_summaries
-
- # Get information for each Disk on the VM
- for disk_summary in disk_summaries:
- disk = disk_summary.disk
- disk_info = disk_svc.get(vm=vm, disk=disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.
- format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Create a new Disk using default settings')
- disk_create_spec = Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec())
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- global disks_to_delete
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.
- format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Create a new Disk specifying the capacity in bytes \n' +
- '# and that the flat format (ie. SeSparse format) should be used.')
- disk_create_spec = Disk.CreateSpec(
- new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Create a new SCSI Disk')
- disk_create_spec = Disk.CreateSpec(
- type=Disk.HostBusAdapterType.SCSI,
- new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.
- format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Create a new SCSI Disk on a specific bus')
- disk_create_spec = Disk.CreateSpec(
- type=Disk.HostBusAdapterType.SCSI,
- scsi=ScsiAddressSpec(bus=0),
- new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
-
- print(
- '\n# Example: Create a new SCSI Disk on a specific bus and unit number')
- disk_create_spec = Disk.CreateSpec(
- type=Disk.HostBusAdapterType.SCSI,
- scsi=ScsiAddressSpec(bus=0, unit=10),
- new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Create a SATA controller')
- global sata_svc
- sata_svc = Sata(stub_config)
- sata_create_spec = Sata.CreateSpec()
- print('# Adding SATA controller for SATA Disk')
- global sata
- sata = sata_svc.create(vm, sata_create_spec)
- print('vm.hardware.adapter.Sata.create({}, {}) -> {}'.
- format(vm, sata_create_spec, sata))
-
- print('\n# Example: Create a new SATA disk')
- disk_create_spec = Disk.CreateSpec(
- type=Disk.HostBusAdapterType.SATA,
- new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Create a new SATA disk on a specific bus')
- disk_create_spec = Disk.CreateSpec(
- type=Disk.HostBusAdapterType.SATA,
- sata=SataAddressSpec(bus=0),
- new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Create a new SATA disk on a specific bus and specific '
- 'unit')
- disk_create_spec = Disk.CreateSpec(
- type=Disk.HostBusAdapterType.SATA,
- sata=SataAddressSpec(bus=0, unit=20),
- new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.
- format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Create a new IDE disk')
- disk_create_spec = Disk.CreateSpec(
- type=Disk.HostBusAdapterType.IDE,
- new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Create a new IDE disk on a specific bus and '
- 'specific unit')
- disk_create_spec = Disk.CreateSpec(
- type=Disk.HostBusAdapterType.IDE,
- ide=IdeAddressSpec(False, False),
- new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Attach an existing VMDK using the default bus and unit')
- datastore_path = datastore_root_path + '/attach-defaults.vmdk'
- delete_vmdk_if_exist(stub_config, service_instance._stub, datacenter_name,
- datastore_name, datastore_path)
- create_vmdk(service_instance, datacenter_mo, datastore_path)
- disk_create_spec = Disk.CreateSpec(
- backing=Disk.BackingSpec(type=Disk.BackingType.VMDK_FILE,
- vmdk_file=datastore_path))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Attach an existing VMDK as a SCSI disk')
- datastore_path = datastore_root_path + '/attach-scsi.vmdk'
- delete_vmdk_if_exist(stub_config, service_instance._stub, datacenter_name,
- datastore_name, datastore_path)
- create_vmdk(service_instance, datacenter_mo, datastore_path)
-
- disk_create_spec = Disk.CreateSpec(
- type=Disk.HostBusAdapterType.SCSI,
- backing=Disk.BackingSpec(type=Disk.BackingType.VMDK_FILE,
- vmdk_file=datastore_path))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.
- format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Attach an existing VMDK as a SCSI disk '
- 'to a specific bus')
- datastore_path = datastore_root_path + '/attach-scsi0.vmdk'
- delete_vmdk_if_exist(stub_config, service_instance._stub, datacenter_name,
- datastore_name, datastore_path)
- create_vmdk(service_instance, datacenter_mo, datastore_path)
- disk_create_spec = Disk.CreateSpec(
- type=Disk.HostBusAdapterType.SCSI,
- scsi=ScsiAddressSpec(bus=0),
- backing=Disk.BackingSpec(type=Disk.BackingType.VMDK_FILE,
- vmdk_file=datastore_path))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
-
- print('\n# Example: Attach an existing VMDK as a SCSI disk '
- 'to a specific bus and specific unit')
- datastore_path = datastore_root_path + '/attach-scsi0:11.vmdk'
- delete_vmdk_if_exist(stub_config, service_instance._stub, datacenter_name,
- datastore_name, datastore_path)
- create_vmdk(service_instance, datacenter_mo, datastore_path)
- disk_create_spec = Disk.CreateSpec(
- type=Disk.HostBusAdapterType.SCSI,
- scsi=ScsiAddressSpec(bus=0, unit=11),
- backing=Disk.BackingSpec(type=Disk.BackingType.VMDK_FILE,
- vmdk_file=datastore_path))
- disk = disk_svc.create(vm=vm, spec=disk_create_spec)
- print('vm.hardware.Disk.create({}, {}) -> {}'.
- format(vm, disk_create_spec, disk))
- disks_to_delete.append(disk)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
-
- # Samples to update operation to change backing
- # Save the disk_info so we can delete the VMDK
- global saved_disk_info
- saved_disk_info = disk_info
- print(
- '\n# Example: Change the backing of the last disk to a new VMDK file.')
- datastore_path = datastore_root_path + '/update-scsi0:11.vmdk'
- delete_vmdk_if_exist(stub_config, service_instance._stub, datacenter_name,
- datastore_name, datastore_path)
- create_vmdk(service_instance, datacenter_mo, datastore_path)
- disk_update_spec = Disk.UpdateSpec(
- backing=Disk.BackingSpec(type=Disk.BackingType.VMDK_FILE,
- vmdk_file=datastore_path))
- print('vm.hardware.Disk.update({}, {}, {})'.
- format(vm, disk, disk_update_spec))
- disk_svc.update(vm=vm, disk=disk, spec=disk_update_spec)
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
-
-
-def cleanup():
- # Clean up the saved disk from the update sample
- vmdk_file = saved_disk_info.backing.vmdk_file
- print("\n# Cleanup: Delete VMDK '{}'".format(vmdk_file))
- delete_vmdk(service_instance, datacenter_mo, vmdk_file)
-
- # List all Disks for a VM
- disk_summaries = disk_svc.list(vm=vm)
- print('vm.hardware.Disk.list({}) -> {}'.format(vm, disk_summaries))
-
- print('\n# Cleanup: Delete VM Disks that were added')
- for disk in disks_to_delete:
- disk_info = disk_svc.get(vm, disk)
- print('vm.hardware.Disk.get({}, {}) -> {}'.
- format(vm, disk, pp(disk_info)))
- vmdk_file = disk_info.backing.vmdk_file
-
- disk_svc.delete(vm, disk)
- print('vm.hardware.Disk.delete({}, {})'.format(vm, disk))
-
- print("\n# Cleanup: Delete VMDK '{}'".format(vmdk_file))
- delete_vmdk(service_instance, datacenter_mo, vmdk_file)
-
- print('\n# Cleanup: Remove SATA controller')
- print('vm.hardware.adapter.Sata.delete({}, {})'.format(vm, sata))
- sata_svc.delete(vm, sata)
-
- disk_summaries = disk_svc.list(vm)
- print('vm.hardware.Disk.list({}) -> {}'.format(vm, disk_summaries))
- if set(orig_disk_summaries) != set(disk_summaries):
- print(
- 'vm.hardware.Disk WARNING: Final Disk info does not match original')
-
-
-def delete_vmdk_if_exist(stub_config, soap_stub, datacenter_name,
- datastore_name, datastore_path):
- if detect_vmdk(stub_config, soap_stub, datacenter_name,
- datastore_name, datastore_path):
- print("Detected VMDK '{}' {}".format(datastore_name, datastore_path))
- delete_vmdk(service_instance, datacenter_mo, datastore_path)
- print("Deleted VMDK '{}'".format(datastore_path))
-
-
-def main():
- setup()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/ethernet.py b/samples/vsphere/vcenter/vm/hardware/ethernet.py
deleted file mode 100644
index 9edc1619..00000000
--- a/samples/vsphere/vcenter/vm/hardware/ethernet.py
+++ /dev/null
@@ -1,260 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware_client import Ethernet
-from com.vmware.vcenter.vm_client import Power
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import parse_cli_args_vm
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.vcenter.helper import network_helper
-from samples.vsphere.vcenter.setup import testbed
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-"""
-Demonstrates how to configure virtual ethernet adapters of a virtual machine.
-
-Sample Prerequisites:
-The sample needs an existing VM.
-"""
-
-vm = None
-vm_name = None
-stub_config = None
-ethernet_svc = None
-cleardata = False
-nics_to_delete = []
-orig_nic_summaries = None
-
-
-def setup(context=None):
- global vm, vm_name, stub_config, cleardata
- if context:
- # Run sample suite via setup script
- stub_config = context.stub_config
- vm_name = testbed.config['VM_NAME_DEFAULT']
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
-
-def run():
- global vm
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for Disk Sample".format(vm_name, vm))
-
- # Get standard portgroup to use as backing for sample
- standard_network = network_helper.get_standard_network_backing(
- stub_config,
- testbed.config['STDPORTGROUP_NAME'],
- testbed.config['VM_DATACENTER_NAME'])
-
- # Get distributed portgroup to use as backing for sample
- distributed_network = network_helper.get_distributed_network_backing(
- stub_config,
- testbed.config['VDPORTGROUP1_NAME'],
- testbed.config['VM_DATACENTER_NAME'])
-
- # Create Ethernet stub used for making requests
- global ethernet_svc
- ethernet_svc = Ethernet(stub_config)
- vm_power_svc = Power(stub_config)
-
- print('\n# Example: List all Ethernet adapters for a VM')
- nic_summaries = ethernet_svc.list(vm=vm)
- print('vm.hardware.Ethernet.list({}) -> {}'.format(vm, nic_summaries))
-
- # Save current list of Ethernet adapters to verify that we have cleaned
- # up properly
- global orig_nic_summaries
- orig_nic_summaries = nic_summaries
-
- # Get information for each Ethernet on the VM
- for nic_summary in nic_summaries:
- nic = nic_summary.nic
- nic_info = ethernet_svc.get(vm=vm, nic=nic)
- print('vm.hardware.Ethernet.get({}, {}) -> {}'.
- format(vm, nic, nic_info))
-
- global nics_to_delete
-
- print('\n# Example: Create Ethernet Nic using STANDARD_PORTGROUP with '
- 'default settings')
- nic_create_spec = Ethernet.CreateSpec(
- backing=Ethernet.BackingSpec(
- type=Ethernet.BackingType.STANDARD_PORTGROUP,
- network=standard_network))
- nic = ethernet_svc.create(vm, nic_create_spec)
- print('vm.hardware.Ethernet.create({}, {}) -> {}'.
- format(vm, nic_create_spec, nic))
- nics_to_delete.append(nic)
- nic_info = ethernet_svc.get(vm, nic)
- print('vm.hardware.Ethernet.get({}, {}) -> {}'.
- format(vm, nic, pp(nic_info)))
-
- print('\n# Example: Create Ethernet Nic using DISTRIBUTED_PORTGROUP '
- 'with defaults')
- nic_create_spec = Ethernet.CreateSpec(
- backing=Ethernet.BackingSpec(
- type=Ethernet.BackingType.DISTRIBUTED_PORTGROUP,
- network=distributed_network))
- nic = ethernet_svc.create(vm, nic_create_spec)
- print('vm.hardware.Ethernet.create({}, {}) -> {}'.
- format(vm, nic_create_spec, nic))
- nics_to_delete.append(nic)
- nic_info = ethernet_svc.get(vm, nic)
- print('vm.hardware.Ethernet.get({}, {}) -> {}'.
- format(vm, nic, pp(nic_info)))
-
- print('\n# Example: Create Ethernet Nic using STANDARD_'
- 'PORTGROUP specifying')
- print('# start_connected=True, allow_guest_control=True,')
- print('# mac_type, mac_Address, wake_on_lan_enabled')
- nic_create_spec = Ethernet.CreateSpec(
- start_connected=True,
- allow_guest_control=True,
- mac_type=Ethernet.MacAddressType.MANUAL,
- mac_address='01:23:45:67:89:10',
- wake_on_lan_enabled=True,
- backing=Ethernet.BackingSpec(
- type=Ethernet.BackingType.STANDARD_PORTGROUP,
- network=standard_network))
- nic = ethernet_svc.create(vm, nic_create_spec)
- print('vm.hardware.Ethernet.create({}, {}) -> {}'.
- format(vm, nic_create_spec, nic))
- nics_to_delete.append(nic)
- nic_info = ethernet_svc.get(vm, nic)
- print('vm.hardware.Ethernet.get({}, {}) -> {}'.
- format(vm, nic, pp(nic_info)))
-
- print('\n# Example: Create Ethernet Nic using DISTRIBUTED_PORTGROUP '
- 'specifying')
- print('# start_connected=True, allow_guest_control=True,')
- print('# mac_type, mac_Address, wake_on_lan_enabled')
- nic_create_spec = Ethernet.CreateSpec(
- start_connected=True,
- allow_guest_control=True,
- mac_type=Ethernet.MacAddressType.MANUAL,
- mac_address='24:68:10:12:14:16',
- wake_on_lan_enabled=True,
- backing=Ethernet.BackingSpec(
- type=Ethernet.BackingType.DISTRIBUTED_PORTGROUP,
- network=distributed_network))
- nic = ethernet_svc.create(vm, nic_create_spec)
- print('vm.hardware.Ethernet.create({}, {}) -> {}'.
- format(vm, nic_create_spec, nic))
- nics_to_delete.append(nic)
- nic_info = ethernet_svc.get(vm, nic)
- print('vm.hardware.Ethernet.get({}, {}) -> {}'.
- format(vm, nic, pp(nic_info)))
-
- # Change the last nic that was created
- print('\n# Example: Update Ethernet Nic with different backing')
- nic_update_spec = Ethernet.UpdateSpec(
- backing=Ethernet.BackingSpec(
- type=Ethernet.BackingType.STANDARD_PORTGROUP,
- network=standard_network))
- print('vm.hardware.Ethernet.update({}, {}, {})'.
- format(vm, nic, nic_update_spec))
- ethernet_svc.update(vm, nic, nic_update_spec)
- nic_info = ethernet_svc.get(vm, nic)
- print('vm.hardware.Ethernet.get({}, {}) -> {}'.
- format(vm, nic, pp(nic_info)))
-
- print('\n# Example: Update Ethernet Nic wake_on_lan_enabled=False')
- print('# mac_type=GENERATED,')
- print('# start_connected=False,')
- print('# allow_guest_control=False')
- nic_update_spec = Ethernet.UpdateSpec(
- wake_on_lan_enabled=False,
- mac_type=Ethernet.MacAddressType.GENERATED,
- start_connected=False,
- allow_guest_control=False)
- print('vm.hardware.Ethernet.update({}, {}, {})'.
- format(vm, nic, nic_update_spec))
- ethernet_svc.update(vm, nic, nic_update_spec)
- nic_info = ethernet_svc.get(vm, nic)
- print('vm.hardware.Ethernet.get({}, {}) -> {}'.
- format(vm, nic, pp(nic_info)))
-
- print('\n# Starting VM to run connect/disconnect sample')
- print('vm.Power.start({})'.format(vm))
- vm_power_svc.start(vm)
- nic_info = ethernet_svc.get(vm, nic)
- print('vm.hardware.Ethernet.get({}, {}) -> {}'.
- format(vm, nic, pp(nic_info)))
-
- print('\n# Example: Connect Ethernet Nic after powering on VM')
- ethernet_svc.connect(vm, nic)
- print('vm.hardware.Ethernet.connect({}, {})'.format(vm, nic))
- nic_info = ethernet_svc.get(vm, nic)
- print('vm.hardware.Ethernet.get({}, {}) -> {}'.
- format(vm, nic, pp(nic_info)))
-
- print('\n# Example: Disconnect Ethernet Nic while VM is powered on')
- ethernet_svc.disconnect(vm, nic)
- print('vm.hardware.Ethernet.disconnect({}, {})'.format(vm, nic))
- nic_info = ethernet_svc.get(vm, nic)
- print('vm.hardware.Ethernet.get({}, {}) -> {}'.
- format(vm, nic, pp(nic_info)))
-
- print('\n# Stopping VM after connect/disconnect sample')
- print('vm.Power.start({})'.format(vm))
- vm_power_svc.stop(vm)
- nic_info = ethernet_svc.get(vm, nic)
- print('vm.hardware.Ethernet.get({}, {}) -> {}'.
- format(vm, nic, pp(nic_info)))
-
- # List all Nics for a VM
- nic_summaries = ethernet_svc.list(vm=vm)
- print('vm.hardware.Ethernet.list({}) -> {}'.format(vm, nic_summaries))
-
-
-def cleanup():
- print('\n# Cleanup: Delete VM Nics that were added')
- for nic in nics_to_delete:
- ethernet_svc.delete(vm, nic)
- print('vm.hardware.Ethernet.delete({}, {})'.format(vm, nic))
-
- nic_summaries = ethernet_svc.list(vm)
- print('vm.hardware.Ethernet.list({}) -> {}'.format(vm, nic_summaries))
- if set(orig_nic_summaries) != set(nic_summaries):
- print('vm.hardware.Ethernet WARNING: '
- 'Final Nic info does not match original')
-
-
-def main():
- setup()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/floppy.py b/samples/vsphere/vcenter/vm/hardware/floppy.py
deleted file mode 100644
index 2ce04d3c..00000000
--- a/samples/vsphere/vcenter/vm/hardware/floppy.py
+++ /dev/null
@@ -1,198 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware_client import Floppy
-from com.vmware.vcenter.vm_client import Power
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import parse_cli_args_vm
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.vcenter.setup import testbed
-
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-"""
-Demonstrates how to configure Floppy settings for a VM.
-
-Sample Prerequisites:
-The sample needs an existing VM.
-"""
-
-vm = None
-vm_name = None
-floppy = None
-stub_config = None
-cleardata = False
-orig_floppy_summaries = None
-
-
-def setup(context=None):
- global vm, vm_name, stub_config, cleardata
- if context:
- # Run sample suite via setup script
- stub_config = context.stub_config
- vm_name = testbed.config['VM_NAME_DEFAULT']
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
-
-def run():
- # * Floppy images must be pre-existing. This API does not expose
- # a way to create new floppy images.
- global vm
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for Floppy Sample".format(vm_name, vm))
- img_datastore_path = testbed.config['FLOPPY_DATASTORE_PATH']
-
- # Create Floppy stub used for making requests
- global floppy_svc
- floppy_svc = Floppy(stub_config)
- vm_power_svc = Power(stub_config)
-
- print('\n# Example: List all Floppys for a VM')
- floppy_summaries = floppy_svc.list(vm=vm)
- print('vm.hardware.Floppy.list({}) -> {}'.format(vm, floppy_summaries))
-
- # Save current list of Floppys to verify that we have cleaned up properly
- global orig_floppy_summaries
- orig_floppy_summaries = floppy_summaries
-
- # Get information for each Floppy on the VM
- global floppy
- for floppy_summary in floppy_summaries:
- floppy = floppy_summary.floppy
- floppy_info = floppy_svc.get(vm=vm, floppy=floppy)
- print('vm.hardware.Floppy.get({}, {}) -> {}'.
- format(vm, floppy, pp(floppy_info)))
-
- # Maximum 2 Floppy devices allowed so delete them as they are created except
- # for the last one which will be deleted at the end
-
- print('\n# Example: Create Floppy port with defaults')
- floppy_create_spec = Floppy.CreateSpec()
- floppy = floppy_svc.create(vm, floppy_create_spec)
- print('vm.hardware.Floppy.create({}, {}) -> {}'.
- format(vm, floppy_create_spec, floppy))
- floppy_info = floppy_svc.get(vm, floppy)
- print('vm.hardware.Floppy.get({}, {}) -> {}'.
- format(vm, floppy, pp(floppy_info)))
- floppy_svc.delete(vm, floppy)
- print('vm.hardware.Floppy.delete({}, {})'.format(vm, floppy))
-
- print('\n# Example: Create Floppy with CLIENT_DEVICE backing')
- floppy_create_spec = Floppy.CreateSpec(
- backing=Floppy.BackingSpec(type=Floppy.BackingType.CLIENT_DEVICE))
- floppy = floppy_svc.create(vm, floppy_create_spec)
- print('vm.hardware.Floppy.create({}, {}) -> {}'.
- format(vm, floppy_create_spec, floppy))
- floppy_info = floppy_svc.get(vm, floppy)
- print('vm.hardware.Floppy.get({}, {}) -> {}'.
- format(vm, floppy, pp(floppy_info)))
- floppy_svc.delete(vm, floppy)
- print('vm.hardware.Floppy.delete({}, {})'.format(vm, floppy))
-
- print('\n# Example: Create Floppy with IMAGE_FILE backing, '
- 'start_connected=True,')
- print(' allow_guest_control=True')
- floppy_create_spec = Floppy.CreateSpec(
- allow_guest_control=True,
- start_connected=True,
- backing=Floppy.BackingSpec(type=Floppy.BackingType.IMAGE_FILE,
- image_file=img_datastore_path))
- floppy = floppy_svc.create(vm, floppy_create_spec)
- floppy_info = floppy_svc.get(vm, floppy)
- print('vm.hardware.Floppy.get({}, {}) -> {}'.
- format(vm, floppy, pp(floppy_info)))
-
- print('\n# Example: Update start_connected=False, '
- 'allow_guest_control=False')
- floppy_update_spec = Floppy.UpdateSpec(
- start_connected=False, allow_guest_control=False)
- print('vm.hardware.Floppy.update({}, {}, {})'.
- format(vm, floppy, floppy_update_spec))
- floppy_svc.update(vm, floppy, floppy_update_spec)
- floppy_info = floppy_svc.get(vm, floppy)
- print('vm.hardware.Floppy.get({}, {}) -> {}'.
- format(vm, floppy, pp(floppy_info)))
-
- print('\n# Starting VM to run connect/disconnect sample')
- print('vm.Power.start({})'.format(vm))
- vm_power_svc.start(vm)
- floppy_info = floppy_svc.get(vm, floppy)
- print('vm.hardware.Floppy.get({}, {}) -> {}'.
- format(vm, floppy, pp(floppy_info)))
-
- print('\n# Example: Connect Floppy after powering on VM')
- floppy_svc.connect(vm, floppy)
- print('vm.hardware.Floppy.connect({}, {})'.format(vm, floppy))
- floppy_info = floppy_svc.get(vm, floppy)
- print('vm.hardware.Floppy.get({}, {}) -> {}'.
- format(vm, floppy, pp(floppy_info)))
-
- print('\n# Example: Disconnect Floppy while VM is powered on')
- floppy_svc.disconnect(vm, floppy)
- print('vm.hardware.Floppy.disconnect({}, {})'.format(vm, floppy))
- floppy_info = floppy_svc.get(vm, floppy)
- print('vm.hardware.Floppy.get({}, {}) -> {}'.
- format(vm, floppy, pp(floppy_info)))
-
- print('\n# Stopping VM after connect/disconnect sample')
- print('vm.Power.start({})'.format(vm))
- vm_power_svc.stop(vm)
- floppy_info = floppy_svc.get(vm, floppy)
- print('vm.hardware.Floppy.get({}, {}) -> {}'.
- format(vm, floppy, pp(floppy_info)))
-
- # List all Floppys for a VM
- floppy_summaries = floppy_svc.list(vm=vm)
- print('vm.hardware.Floppy.list({}) -> {}'.format(vm, floppy_summaries))
-
-
-def cleanup():
- print('\n# Cleanup: Delete VM Floppys that were added')
- floppy_svc.delete(vm, floppy)
- print('vm.hardware.Floppy.delete({}, {})'.format(vm, floppy))
-
- floppy_summaries = floppy_svc.list(vm)
- print('vm.hardware.Floppy.list({}) -> {}'.format(vm, floppy_summaries))
- if set(orig_floppy_summaries) != set(floppy_summaries):
- print('vm.hardware.Floppy WARNING: '
- 'Final Floppy info does not match original')
-
-
-def main():
- setup()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/main.py b/samples/vsphere/vcenter/vm/hardware/main.py
deleted file mode 100644
index 21a18f48..00000000
--- a/samples/vsphere/vcenter/vm/hardware/main.py
+++ /dev/null
@@ -1,132 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import samples.vsphere.vcenter.vm.hardware.adapter.sata
-import samples.vsphere.vcenter.vm.hardware.adapter.scsi
-import samples.vsphere.vcenter.vm.hardware.boot
-import samples.vsphere.vcenter.vm.hardware.boot_device
-import samples.vsphere.vcenter.vm.hardware.cdrom
-import samples.vsphere.vcenter.vm.hardware.cpu
-import samples.vsphere.vcenter.vm.hardware.disk
-import samples.vsphere.vcenter.vm.hardware.ethernet
-import samples.vsphere.vcenter.vm.hardware.floppy
-import samples.vsphere.vcenter.vm.hardware.memory
-import samples.vsphere.vcenter.vm.hardware.parallel
-import samples.vsphere.vcenter.vm.hardware.serial
-from samples.vsphere.vcenter.setup import testbed
-
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-
-def setup(context):
- print('Setup vcenter.vm.hardware Samples Started')
- samples.vsphere.vcenter.vm.hardware.cpu.setup(context)
- samples.vsphere.vcenter.vm.hardware.memory.setup(context)
- samples.vsphere.vcenter.vm.hardware.disk.setup(context)
- samples.vsphere.vcenter.vm.hardware.adapter.sata.setup(context)
- samples.vsphere.vcenter.vm.hardware.adapter.scsi.setup(context)
- samples.vsphere.vcenter.vm.hardware.boot.setup(context)
- samples.vsphere.vcenter.vm.hardware.boot_device.setup(context)
- samples.vsphere.vcenter.vm.hardware.cdrom.setup(context)
- samples.vsphere.vcenter.vm.hardware.ethernet.setup(context)
- samples.vsphere.vcenter.vm.hardware.floppy.setup(context)
- samples.vsphere.vcenter.vm.hardware.serial.setup(context)
- samples.vsphere.vcenter.vm.hardware.parallel.setup(context)
- print('Setup vcenter.vm.hardware Samples Complete\n')
-
-
-def cleanup():
- print('Cleanup vcenter.vm.hardware Samples Started')
- samples.vsphere.vcenter.vm.hardware.cpu.cleanup()
- samples.vsphere.vcenter.vm.hardware.memory.cleanup()
- samples.vsphere.vcenter.vm.hardware.disk.cleanup()
- samples.vsphere.vcenter.vm.hardware.adapter.sata.cleanup()
- samples.vsphere.vcenter.vm.hardware.adapter.scsi.cleanup()
- samples.vsphere.vcenter.vm.hardware.boot.cleanup()
- samples.vsphere.vcenter.vm.hardware.boot_device.cleanup()
- samples.vsphere.vcenter.vm.hardware.cdrom.cleanup()
- samples.vsphere.vcenter.vm.hardware.ethernet.cleanup()
- samples.vsphere.vcenter.vm.hardware.floppy.cleanup()
- samples.vsphere.vcenter.vm.hardware.serial.cleanup()
- samples.vsphere.vcenter.vm.hardware.parallel.cleanup()
- print('Cleanup vcenter.vm.hardware Samples Complete\n')
-
-
-def validate(context):
- print('Validating and Detecting Resources in vcenter.vm.hardware Samples')
- names = set([testbed.config['VM_NAME_DEFAULT'],
- testbed.config['VM_NAME_BASIC'],
- testbed.config['VM_NAME_EXHAUSTIVE']])
- valid = True
- for name in names:
- if not get_vm(context.stub_config, name):
- valid = False
- if not valid:
- raise Exception('==> Samples Setup validation failed: '
- 'Missing VMs required to run hardware samples')
- print('==> Samples Setup validated')
-
-
-def run():
- ###########################################################################
- # Incremental device CRUDE + connect/disconnect samples
- #
- # Choose any combination of the following incremental hardware examples.
- # Each one will return the VM to its original configuration.
- #
- # * CPU update sample
- # * Memory update sample
- # * Disk CRUD sample
- # * Ethernet CRUD sample
- # * CDROM CRUD sample
- # * SCSI adapter sample
- # * SATA adapter sample
- # * Serial Port CRUD sample
- # * Parallel Port CRUD sample
- # * Floppy CRUD sample
- # * Boot configuration sample
- # * Boot Device configuration sample
- ###########################################################################
- print('#' * 79)
- print('# vcenter.vm.hardware Samples')
- print('#' * 79)
- samples.vsphere.vcenter.vm.hardware.cpu.run()
- samples.vsphere.vcenter.vm.hardware.memory.run()
- samples.vsphere.vcenter.vm.hardware.disk.run()
- samples.vsphere.vcenter.vm.hardware.adapter.sata.run()
- samples.vsphere.vcenter.vm.hardware.adapter.scsi.run()
- samples.vsphere.vcenter.vm.hardware.boot.run()
- samples.vsphere.vcenter.vm.hardware.boot_device.run()
- samples.vsphere.vcenter.vm.hardware.cdrom.run()
- samples.vsphere.vcenter.vm.hardware.ethernet.run()
- samples.vsphere.vcenter.vm.hardware.floppy.run()
- samples.vsphere.vcenter.vm.hardware.serial.run()
- samples.vsphere.vcenter.vm.hardware.parallel.run()
-
- ###########################################################################
- # Virtual Hardware Upgrade Sample
- #
- # TODO Not implemented
- ###########################################################################
-
- ###########################################################################
- # Hot Add Samples
- # * Hot add disk
- # * Hot add cdrom
- # * ...
- # TODO Not implemented
- ###########################################################################
diff --git a/samples/vsphere/vcenter/vm/hardware/memory.py b/samples/vsphere/vcenter/vm/hardware/memory.py
deleted file mode 100644
index c7239972..00000000
--- a/samples/vsphere/vcenter/vm/hardware/memory.py
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware_client import Memory
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import parse_cli_args_vm
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.vcenter.setup import testbed
-
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-"""
-Demonstrates how to configure the memory related settings of a virtual machine.
-
-Sample Prerequisites:
-The sample needs an existing VM.
-"""
-
-vm = None
-vm_name = None
-stub_config = None
-memory_svc = None
-cleardata = False
-orig_memory_info = None
-
-
-def setup(context=None):
- global vm, vm_name, stub_config, cleardata
- if context:
- # Run sample suite via setup script
- stub_config = context.stub_config
- vm_name = testbed.config['VM_NAME_DEFAULT']
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
-
-def run():
- global vm
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for Memory Sample".format(vm_name, vm))
-
- # Create Memory stub used for making requests
- global memory_svc
- memory_svc = Memory(stub_config)
-
- print('\n# Example: Get current Memory configuration')
- memory_info = memory_svc.get(vm)
- print('vm.hardware.Memory.get({}) -> {}'.format(vm, pp(memory_info)))
-
- # Save current Memory info to verify that we have cleaned up properly
- global orig_memory_info
- orig_memory_info = memory_info
-
- print('\n# Example: Update memory size_mib field of Memory configuration')
- update_spec = Memory.UpdateSpec(size_mib=8 * 1024)
- print('vm.hardware.Memory.update({}, {})'.format(vm, update_spec))
- memory_svc.update(vm, update_spec)
-
- # Get new Memory configuration
- memory_info = memory_svc.get(vm)
- print('vm.hardware.Memory.get({}) -> {}'.format(vm, pp(memory_info)))
-
- print('\n# Example: Update hot_add_enabled field of Memory configuration')
- update_spec = Memory.UpdateSpec(hot_add_enabled=True)
- print('vm.hardware.Memory.update({}, {})'.format(vm, update_spec))
- memory_svc.update(vm, update_spec)
-
- # Get new Memory configuration
- memory_info = memory_svc.get(vm)
- print('vm.hardware.Memory.get({}) -> {}'.format(vm, pp(memory_info)))
-
-
-def cleanup():
- print('\n# Cleanup: Revert Memory configuration')
- update_spec = Memory.UpdateSpec(size_mib=orig_memory_info.size_mib,
- hot_add_enabled=orig_memory_info.
- hot_add_enabled)
- print('vm.hardware.Memory.update({}, {})'.format(vm, update_spec))
- memory_svc.update(vm, update_spec)
-
- # Get final Memory configuration
- memory_info = memory_svc.get(vm)
- print('vm.hardware.Memory.get({}) -> {}'.format(vm, pp(memory_info)))
-
- if memory_info != orig_memory_info:
- print('vm.hardware.Memory WARNING: '
- 'Final Memory info does not match original')
-
-
-def main():
- setup()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/parallel.py b/samples/vsphere/vcenter/vm/hardware/parallel.py
deleted file mode 100644
index b7764e7a..00000000
--- a/samples/vsphere/vcenter/vm/hardware/parallel.py
+++ /dev/null
@@ -1,231 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware_client import Parallel
-from com.vmware.vcenter.vm_client import Power
-from pyVim.connect import SmartConnect, Disconnect
-
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import parse_cli_args_vm
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.common.ssl_helper import get_unverified_context
-from samples.vsphere.common.vim.file import delete_file
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-from samples.vsphere.vcenter.setup import testbed
-
-"""
-Demonstrates how to configure Parallel ports for a VM.
-
-Sample Prerequisites:
-The sample needs an existing VM.
-"""
-
-vm = None
-vm_name = None
-stub_config = None
-service_instance = None
-parallel_svc = None
-cleardata = False
-parallels_to_delete = []
-orig_parallel_summaries = None
-
-
-def setup(context=None):
- global vm_name, stub_config, service_instance, cleardata
- if context:
- # Run sample suite via setup script
- stub_config = context.stub_config
- vm_name = testbed.config['VM_NAME_DEFAULT']
- service_instance = context.service_instance
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
- context = None
- if skip_verification:
- context = get_unverified_context()
- service_instance = SmartConnect(host=server,
- user=username,
- pwd=password,
- sslContext=context)
- atexit.register(Disconnect, service_instance)
-
-
-def run():
- global vm, parallel_svc
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for Parallel Sample".format(vm_name, vm))
-
- # Create Parallel port stub used for making requests
- parallel_svc = Parallel(stub_config)
- vm_power_svc = Power(stub_config)
-
- print('\n# Example: List all Parallel ports for a VM')
- parallel_summaries = parallel_svc.list(vm=vm)
- print('vm.hardware.Parallel.list({}) -> {}'.format(vm, parallel_summaries))
-
- # Save current list of Parallel ports to verify that we have cleaned up
- # properly
- global orig_parallel_summaries
- orig_parallel_summaries = parallel_summaries
-
- # Get information for each Parallel port on the VM
- for parallel_summary in parallel_summaries:
- parallel = parallel_summary.port
- parallel_info = parallel_svc.get(vm=vm, port=parallel)
- print('vm.hardware.Parallel.get({}, {}) -> {}'.format(vm, parallel, pp(
- parallel_info)))
-
- # Make sure output file doesn't exist already
- cleanup_backends()
-
- print('\n# Example: Create Parallel port with defaults')
- parallel_create_spec = Parallel.CreateSpec()
- parallel = parallel_svc.create(vm, parallel_create_spec)
- print('vm.hardware.Parallel.create({}, {}) -> {}'.
- format(vm, parallel_create_spec, parallel))
- global parallels_to_delete
- parallels_to_delete.append(parallel)
- parallel_info = parallel_svc.get(vm, parallel)
- print('vm.hardware.Parallel.get({}, {}) -> {}'.format(vm, parallel,
- pp(parallel_info)))
-
- print('\n# Example: Create Parallel port with FILE backing')
- parallel_port_datastore_path = testbed.config[
- 'PARALLEL_PORT_DATASTORE_PATH']
- parallel_create_spec = Parallel.CreateSpec(
- start_connected=True,
- allow_guest_control=True,
- backing=Parallel.BackingSpec(type=Parallel.BackingType.FILE,
- file=parallel_port_datastore_path))
- parallel = parallel_svc.create(vm, parallel_create_spec)
- print('vm.hardware.Parallel.create({}, {}) -> {}'.
- format(vm, parallel_create_spec, parallel))
- parallels_to_delete.append(parallel)
- parallel_info = parallel_svc.get(vm, parallel)
- print('vm.hardware.Parallel.get({}, {}) -> {}'.
- format(vm, parallel, pp(parallel_info)))
-
- print('\n# Example: Update Parallel port with same file but '
- 'start_connected=False')
- print('# and allow_guest_control=False')
- parallel_port_datastore_path = testbed.config[
- 'PARALLEL_PORT_DATASTORE_PATH']
- parallel_update_spec = Parallel.UpdateSpec(
- start_connected=False,
- allow_guest_control=False,
- backing=Parallel.BackingSpec(type=Parallel.BackingType.FILE,
- file=parallel_port_datastore_path))
- parallel_svc.update(vm, parallel, parallel_update_spec)
- print('vm.hardware.Parallel.update({}, {}) -> {}'.
- format(vm, parallel_update_spec, parallel))
- parallel_info = parallel_svc.get(vm, parallel)
- print('vm.hardware.Parallel.get({}, {}) -> {}'.
- format(vm, parallel, pp(parallel_info)))
-
- print('\n# Starting VM to run connect/disconnect sample')
- print('vm.Power.start({})'.format(vm))
- vm_power_svc.start(vm)
- parallel_info = parallel_svc.get(vm, parallel)
- print('vm.hardware.Parallel.get({}, {}) -> {}'.
- format(vm, parallel, pp(parallel_info)))
-
- print('\n# Example: Connect Parallel port after powering on VM')
- parallel_svc.connect(vm, parallel)
- print('vm.hardware.Parallel.connect({}, {})'.format(vm, parallel))
- parallel_info = parallel_svc.get(vm, parallel)
- print('vm.hardware.Parallel.get({}, {}) -> {}'.
- format(vm, parallel, pp(parallel_info)))
-
- print('\n# Example: Disconnect Parallel port while VM is powered on')
- parallel_svc.disconnect(vm, parallel)
- print('vm.hardware.Parallel.disconnect({}, {})'.format(vm, parallel))
- parallel_info = parallel_svc.get(vm, parallel)
- print('vm.hardware.Parallel.get({}, {}) -> {}'.
- format(vm, parallel, pp(parallel_info)))
-
- print('\n# Stopping VM after connect/disconnect sample')
- print('vm.Power.start({})'.format(vm))
- vm_power_svc.stop(vm)
- parallel_info = parallel_svc.get(vm, parallel)
- print('vm.hardware.Parallel.get({}, {}) -> {}'.
- format(vm, parallel, pp(parallel_info)))
-
- # List all Parallel ports for a VM
- parallel_summaries = parallel_svc.list(vm=vm)
- print('vm.hardware.Parallel.list({}) -> {}'.
- format(vm, parallel_summaries))
-
- # Always cleanup output file so the VM can be powered on next time
- cleanup_backends()
-
-
-def cleanup():
- print('\n# Cleanup: Delete VM Parallel ports that were added')
- for parallel in parallels_to_delete:
- parallel_svc.delete(vm, parallel)
- print('vm.hardware.Parallel.delete({}, {})'.format(vm, parallel))
-
- parallel_summaries = parallel_svc.list(vm)
- print('vm.hardware.Parallel.list({}) -> {}'.format(vm, parallel_summaries))
- if set(orig_parallel_summaries) != set(parallel_summaries):
- print('vm.hardware.Parallel WARNING: '
- 'Final Parallel ports info does not match original')
-
-
-def cleanup_backends():
- """
- Cleanup after the parallel port samples.
-
- The files backing the serial port file backing needs to be removed or else
- the next time the VM is powered on and connected to the parallel port, the
- VM will post a question asking if the file should be Replaced or Appended.
-
- This is only an issue for backings that are write-only.
- """
- datacenter_name = testbed.config['PARALLEL_PORT_DATACENTER_NAME']
- datastore_path = testbed.config['PARALLEL_PORT_DATASTORE_PATH']
- delete_file(stub_config,
- service_instance,
- 'Parallel Port',
- datacenter_name,
- datastore_path)
-
-
-def main():
- setup()
- cleanup_backends()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/hardware/serial.py b/samples/vsphere/vcenter/vm/hardware/serial.py
deleted file mode 100644
index 3e9d9286..00000000
--- a/samples/vsphere/vcenter/vm/hardware/serial.py
+++ /dev/null
@@ -1,262 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-
-import atexit
-
-from com.vmware.vcenter.vm.hardware_client import Serial
-from com.vmware.vcenter.vm_client import Power
-from pyVim.connect import SmartConnect, Disconnect
-
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import parse_cli_args_vm
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.common.ssl_helper import get_unverified_context
-from samples.vsphere.common.vim.file import delete_file
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-from samples.vsphere.vcenter.setup import testbed
-
-"""
-Demonstrates how to configure Serial ports for a VM.
-
-Sample Prerequisites:
-The sample needs an existing VM.
-
-Note:
-The sample adds new serial ports to the existing VM. If you re-run the sample
-without cleaning up the previous created serial ports, the VM may be stuck at
-power on stage as there will be multiple serial ports using the same output
-file. In such case, you will see a question in vCenter UI asking if the file
-should be Replaced or Appended.
-To avoid this, make sure to pass -c to clean up the serial ports or manually
-delete them after running the sample.
-"""
-
-vm = None
-vm_name = None
-stub_config = None
-service_instance = None
-serial_svc = None
-cleardata = False
-serials_to_delete = []
-orig_serial_summaries = None
-
-
-def setup(context=None):
- global vm_name, stub_config, service_instance, cleardata
- if context:
- # Run sample suite via setup script
- stub_config = context.stub_config
- vm_name = testbed.config['VM_NAME_DEFAULT']
- service_instance = context.service_instance
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
- context = None
- if skip_verification:
- context = get_unverified_context()
- service_instance = SmartConnect(host=server,
- user=username,
- pwd=password,
- sslContext=context)
- atexit.register(Disconnect, service_instance)
-
-
-def run():
- # * Backings types are FILE, HOST_DEVICE, PIPE_SERVER, PIPE_CLIENT,
- # NETWORK_SERVER, NETWORK_CLIENT
- # * NetworkLocation: See
- # https://kb.vmware.com/selfservice/microsites/search.do?language=en_US
- # &cmd=displayKC&externalId=2004954
- # * Proxy: https://www.vmware.com/support/developer/vc-sdk/visdk41pubs
- # /vsp41_usingproxy_virtual_serial_ports.pdf
-
- global vm, serial_svc
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}). '
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for Serial Sample".format(vm_name, vm))
-
- # Create Serial port stub used for making requests
- serial_svc = Serial(stub_config)
- vm_power_svc = Power(stub_config)
-
- print('\n# Example: List all Serial ports for a VM')
- serial_summaries = serial_svc.list(vm=vm)
- print('vm.hardware.Serial.list({}) -> {}'.format(vm, serial_summaries))
-
- # Save current list of Serial ports to verify that we have cleaned up
- # properly
- global orig_serial_summaries
- orig_serial_summaries = serial_summaries
-
- # Get information for each Serial port on the VM
- for serial_summary in serial_summaries:
- serial = serial_summary.port
- serial_info = serial_svc.get(vm=vm, port=serial)
- print('vm.hardware.Serial.get({}, {}) -> {}'.format(vm, serial,
- pp(serial_info)))
-
- global serials_to_delete
-
- print('\n# Example: Create Serial port with defaults')
- serial_create_spec = Serial.CreateSpec()
- serial = serial_svc.create(vm, serial_create_spec)
- print('vm.hardware.Serial.create({}, {}) -> {}'.
- format(vm, serial_create_spec, serial))
- serials_to_delete.append(serial)
- serial_info = serial_svc.get(vm, serial)
- print('vm.hardware.Serial.get({}, {}) -> {}'.
- format(vm, serial, pp(serial_info)))
-
- # Make sure output file doesn't exist already
- cleanup_backends()
-
- print('\n# Example: Create Serial port with FILE backing')
- serial_port_datastore_path = testbed.config['SERIAL_PORT_DATASTORE_PATH']
- serial_create_spec = Serial.CreateSpec(
- start_connected=True,
- allow_guest_control=True,
- backing=Serial.BackingSpec(type=Serial.BackingType.FILE,
- file=serial_port_datastore_path))
- serial = serial_svc.create(vm, serial_create_spec)
- print('vm.hardware.Serial.create({}, {}) -> {}'.
- format(vm, serial_create_spec, serial))
- serials_to_delete.append(serial)
- serial_info = serial_svc.get(vm, serial)
- print('vm.hardware.Serial.get({}, {}) -> {}'.
- format(vm, serial, pp(serial_info)))
-
- print('\n# Example: Create Serial port to use NETWORK_SERVER')
- serial_port_network_server_location = \
- testbed.config['SERIAL_PORT_NETWORK_SERVER_LOCATION']
- serial_create_spec = Serial.CreateSpec(
- start_connected=True,
- allow_guest_control=True,
- backing=Serial.BackingSpec(type=Serial.BackingType.NETWORK_SERVER,
- network_location=serial_port_network_server_location))
- serial = serial_svc.create(vm, serial_create_spec)
- print('vm.hardware.Serial.create({}, {}) -> {}'.
- format(vm, serial_create_spec, serial))
- serials_to_delete.append(serial)
- serial_info = serial_svc.get(vm, serial)
- print('vm.hardware.Serial.get({}, {}) -> {}'.
- format(vm, serial, pp(serial_info)))
-
- print('\n# Example: Update Serial port to use NETWORK_CLIENT')
- serial_port_network_client_location = \
- testbed.config['SERIAL_PORT_NETWORK_CLIENT_LOCATION']
- serial_port_network_proxy = testbed.config['SERIAL_PORT_NETWORK_PROXY']
- serial_update_spec = Serial.UpdateSpec(
- start_connected=False,
- allow_guest_control=False,
- backing=Serial.BackingSpec(type=Serial.BackingType.NETWORK_CLIENT,
- network_location=serial_port_network_client_location,
- proxy=serial_port_network_proxy))
- serial_svc.update(vm, serial, serial_update_spec)
- print('vm.hardware.Serial.update({}, {}) -> {}'.
- format(vm, serial_update_spec, serial))
- serial_info = serial_svc.get(vm, serial)
- print('vm.hardware.Serial.get({}, {}) -> {}'.
- format(vm, serial, pp(serial_info)))
-
- print('\n# Starting VM to run connect/disconnect sample')
- print('vm.Power.start({})'.format(vm))
- vm_power_svc.start(vm)
- serial_info = serial_svc.get(vm, serial)
- print('vm.hardware.Serial.get({}, {}) -> {}'.
- format(vm, serial, pp(serial_info)))
-
- print('\n# Example: Connect Serial port after powering on VM')
- serial_svc.connect(vm, serial)
- print('vm.hardware.Serial.connect({}, {})'.format(vm, serial))
- serial_info = serial_svc.get(vm, serial)
- print('vm.hardware.Serial.get({}, {}) -> {}'.
- format(vm, serial, pp(serial_info)))
-
- print('\n# Example: Disconnect Serial port while VM is powered on')
- serial_svc.disconnect(vm, serial)
- print('vm.hardware.Serial.disconnect({}, {})'.format(vm, serial))
- serial_info = serial_svc.get(vm, serial)
- print('vm.hardware.Serial.get({}, {}) -> {}'.
- format(vm, serial, pp(serial_info)))
-
- print('\n# Stopping VM after connect/disconnect sample')
- print('vm.Power.start({})'.format(vm))
- vm_power_svc.stop(vm)
- serial_info = serial_svc.get(vm, serial)
- print('vm.hardware.Serial.get({}, {}) -> {}'.
- format(vm, serial, pp(serial_info)))
-
- # List all Serial ports for a VM
- serial_summaries = serial_svc.list(vm=vm)
- print('vm.hardware.Serial.list({}) -> {}'.format(vm, serial_summaries))
-
- # Always cleanup output file so the VM can be powered on next time
- cleanup_backends()
-
-
-def cleanup():
- print('\n# Delete VM Serial ports that were added')
- for serial in serials_to_delete:
- serial_svc.delete(vm, serial)
- print('vm.hardware.Serial.delete({}, {})'.format(vm, serial))
-
- serial_summaries = serial_svc.list(vm)
- print('vm.hardware.Serial.list({}) -> {}'.format(vm, serial_summaries))
- if set(orig_serial_summaries) != set(serial_summaries):
- print('vm.hardware.Serial WARNING: '
- 'Final Serial ports info does not match original')
-
-
-def cleanup_backends():
- """
- Cleanup after the serial port samples.
-
- The files backing the serial port file backing needs to be removed or else
- the next time the VM is powered on and connected to the serial port, the VM
- will post a question asking if the file should be Replaced or Appended.
-
- This is only an issue for backings that are write-only.
- """
- datacenter_name = testbed.config['SERIAL_PORT_DATACENTER_NAME']
- datastore_path = testbed.config['SERIAL_PORT_DATASTORE_PATH']
- delete_file(stub_config,
- service_instance,
- 'Serial Port',
- datacenter_name,
- datastore_path)
-
-
-def main():
- setup()
- cleanup_backends()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/list_vms.py b/samples/vsphere/vcenter/vm/list_vms.py
deleted file mode 100644
index 365fc8a9..00000000
--- a/samples/vsphere/vcenter/vm/list_vms.py
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter_client import VM
-
-from samples.vsphere.common import sample_cli
-from samples.vsphere.common import sample_util
-from samples.vsphere.common.service_manager import ServiceManager
-from pprint import pprint
-
-
-class ListVM(object):
- """
- Demonstrates getting list of VMs present in vCenter
- Sample Prerequisites:
- vCenter/ESX
- """
-
- def __init__(self):
- self.service_manager = None
-
- def setup(self):
- parser = sample_cli.build_arg_parser()
- args = sample_util.process_cli_args(parser.parse_args())
-
- self.service_manager = ServiceManager(args.server,
- args.username,
- args.password,
- args.skipverification)
- self.service_manager.connect()
- atexit.register(self.service_manager.disconnect)
-
- def run(self):
- """
- List VMs present in server
- """
- vm_svc = VM(self.service_manager.stub_config)
- list_of_vms = vm_svc.list()
- print("----------------------------")
- print("List Of VMs")
- print("----------------------------")
- pprint(list_of_vms)
- print("----------------------------")
-
-
-def main():
- list_vm = ListVM()
- list_vm.setup()
- list_vm.run()
-
-
-if __name__ == '__main__':
- main()
diff --git a/samples/vsphere/vcenter/vm/main.py b/samples/vsphere/vcenter/vm/main.py
deleted file mode 100644
index 37f15f87..00000000
--- a/samples/vsphere/vcenter/vm/main.py
+++ /dev/null
@@ -1,138 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import samples.vsphere.vcenter.helper.network_helper
-import samples.vsphere.vcenter.vm.hardware.main
-import samples.vsphere.vcenter.vm.placement
-import samples.vsphere.vcenter.vm.power
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.vcenter.setup import testbed_setup
-from samples.vsphere.vcenter.setup import testbed
-from samples.vsphere.vcenter.vm.create.create_default_vm import CreateDefaultVM
-from samples.vsphere.vcenter.vm.create.create_basic_vm import CreateBasicVM
-from samples.vsphere.vcenter.vm.create.create_exhaustive_vm import \
- CreateExhaustiveVM
-
-
-class VMSetup(object):
- def __init__(self, context=None):
- self.context = context
- self.basic_vm = None
- self.default_vm = None
- self.exhaustive_vm = None
-
- def setup(self, context):
- print('Setup Samples Started')
-
- self.context = context
-
- ###########################################################################
- # Getting a PlacementSpec
- ###########################################################################
- placement_spec = samples.vsphere.vcenter.vm.placement.get_placement_spec_for_resource_pool(context)
- print('=' * 79)
- print('= Resource selection')
- print('=' * 79)
- print('placement_spec={}'.format(pp(placement_spec)))
-
- ###########################################################################
- # Getting a Network
- # Choose one of the following ways to get the PlacementSpec
- # 1. STANDARD_PORTGROUP on DATACENTER2
- # 2. DISTRIBUTED_PORTGROUP on DATACENTER2
- ###########################################################################
- standard_network = samples.vsphere.vcenter.helper \
- .network_helper.get_standard_network_backing(
- context.stub_config,
- context.testbed.config['STDPORTGROUP_NAME'],
- context.testbed.config['VM_DATACENTER_NAME'])
- print('standard_network={}'.format(standard_network))
-
- distributed_network = samples.vsphere.vcenter.helper \
- .network_helper.get_distributed_network_backing(
- context.stub_config,
- context.testbed.config['VDPORTGROUP1_NAME'],
- context.testbed.config['VM_DATACENTER_NAME'])
- print('distributed_network={}'.format(distributed_network))
-
- print('=' * 79)
-
- self.default_vm = CreateDefaultVM(context.stub_config,
- placement_spec)
- self.basic_vm = CreateBasicVM(context.stub_config, placement_spec)
- self.exhaustive_vm = CreateExhaustiveVM(context.stub_config,
- placement_spec,
- standard_network,
- distributed_network)
-
- print('Setup Samples Complete')
-
- def cleanup(self):
-
- print('Cleanup Samples Started')
- CreateDefaultVM(self.context.stub_config).cleanup()
- CreateBasicVM(self.context.stub_config).cleanup()
- CreateExhaustiveVM(self.context.stub_config).cleanup()
- print('Cleanup Samples Complete\n')
-
- def validate(self):
- print('Validating and Detecting Resources in vcenter.vm Samples')
- r = testbed_setup.validate(self.context)
- if r:
- print('==> Samples Setup validated')
- return True
- else:
- print('==> Samples Setup has errors')
- return False
-
- def run(self):
- # Clean up in case of past failures
- self.cleanup()
-
- # Check that sample is ready to run
- if self.context.option['DO_SAMPLES']:
- if not self.validate():
- exit(0)
-
- ###########################################################################
- # Create VM samples
- #
- # Choose one of the following ways to create the VM
- # 1. Default
- # 2. Basic (2 disks, 1 nic)
- # 3. Exhaustive (3 disks, 2 nics, 2 vcpu, 2 GB memory, boot=BIOS, 1 cdrom,
- # 1 serial port, 1 parallel port, 1 floppy,
- # boot_devices= [CDROM, DISK, ETHERNET])
- ###########################################################################
- self.default_vm.run()
- self.basic_vm.run()
- self.exhaustive_vm.run()
-
- ###########################################################################
- # Incremental device CRUDE + connect/disconnect samples
- #
- ###########################################################################
- if self.context.option['DO_SAMPLES_INCREMENTAL']:
- samples.vsphere.vcenter.vm.hardware.main.setup(self.context)
- samples.vsphere.vcenter.vm.hardware.main.validate(self.context)
- samples.vsphere.vcenter.vm.hardware.main.run()
- if self.context.option['DO_SAMPLES_CLEANUP']:
- samples.vsphere.vcenter.vm.hardware.main.cleanup()
-
- # Sample cleanup
- if self.context.option['DO_SAMPLES_CLEANUP']:
- self.cleanup()
diff --git a/samples/vsphere/vcenter/vm/placement.py b/samples/vsphere/vcenter/vm/placement.py
deleted file mode 100644
index 38431cbb..00000000
--- a/samples/vsphere/vcenter/vm/placement.py
+++ /dev/null
@@ -1,188 +0,0 @@
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-from com.vmware.vcenter_client import (Cluster, Datastore, Folder, ResourcePool,
- VM)
-
-from samples.vsphere.vcenter.helper import vm_placement_helper
-
-
-#####################################################################
-# Placement samples: How to get a valid PlacementSpec to create a VM
-#####################################################################
-
-# Place to a Cluster
-#
-# a. Datacenter based flow:
-# * Use vcenter.Datacenter#list() to find a datacenter
-# * Find a compute resource that is in the selected Datacenter
-# * 1. Cluster:
-# * Use the cluster list operation to find a cluster in a
-# datacenter with a specific name
-#
-
-def get_placement_spec_for_cluster(context):
- """
- Cluster names are not guaranteed to be unique within a vCenter instance,
- so we qualify our search using the Datacenter. If Folders are used, the
- search must be qualified using Folders since a Cluster name is not
- guaranteed to be unique across different Folders within a Datacenter.
- """
- # Select a Cluster meeting our requirements
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
-
- cluster_name = context.testbed.config['CLUSTER1_NAME']
- names = set([cluster_name])
-
- cluster_svc = Cluster(context.stub_config)
- filter = Cluster.FilterSpec(
- names=set([cluster_name]),
- datacenters=set([datacenter]))
- cluster_summaries = cluster_svc.list(filter=filter)
-
- cluster = None
- if len(cluster_summaries) > 0:
- cluster = cluster_summaries[0].cluster
- print("Selecting Cluster '{}' ({})".format(cluster_name, cluster))
- else:
- print("Cluster '{}' not found".format(cluster_name))
- return None
-
- # Select a Folder meeting our requirements.
- #
- # Must be in the same Datacenter as the Cluster that was chosen.
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
-
- folder_name = context.testbed.config['VM_FOLDER2_NAME']
-
- folder_svc = Folder(context.stub_config)
- filter = Folder.FilterSpec(
- names=set([folder_name]),
- datacenters=set([datacenter]))
- folder_summaries = folder_svc.list(filter=filter)
-
- folder = None
- if len(folder_summaries) > 0:
- folder = folder_summaries[0].folder
- print("Selecting Folder '{}' ({})".format(folder_name, folder))
- else:
- print("Folder '{}' not found".format(folder_name))
- return None
-
- # Select a Datastore meeting our requirements.
- #
- # Must be in the same Datacenter as the Cluster that was chosen.
- # TODO No way to validate that Cluster is connected to Datastore
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
-
- # TODO Parameterize based on NFS or VMFS
- datastore_name = context.testbed.config['NFS_DATASTORE_NAME']
-
- datastore_svc = Datastore(context.stub_config)
- filter = Datastore.FilterSpec(
- names=set([datastore_name]),
- datacenters=set([datacenter]))
- datastore_summaries = datastore_svc.list(filter=filter)
-
- datastore = None
- if len(datastore_summaries) > 0:
- datastore = datastore_summaries[0].datastore
- print("Selecting Datastore '{}' ({})".format(datastore_name, datastore))
- else:
- print("Datastore '{}' not found".format(datastore_name))
- return None
-
- placement_spec = VM.PlacementSpec(folder=folder,
- cluster=cluster,
- datastore=datastore)
- print("get_placement_spec_for_cluster: Result is '{}'".
- format(placement_spec))
- return placement_spec
-
-
-def get_placement_spec_for_resource_pool(context):
- # Select a ResourcePool meeting our requirements
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
-
- resource_pool_svc = ResourcePool(context.stub_config)
- filter = ResourcePool.FilterSpec(datacenters=set([datacenter]))
- resource_pool_summaries = resource_pool_svc.list(filter=filter)
-
- resource_pool = None
- if len(resource_pool_summaries) > 0:
- resource_pool = resource_pool_summaries[0].resource_pool
- print('Selecting ResourcePool ({})'.format(resource_pool))
- else:
- print("ResourcePool not found in Datacenter '{}'".
- format(datacenter_name))
- return None
-
- # Select a Folder meeting our requirements.
- #
- # Must be in the same Datacenter as the ResourcePool that was chosen.
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
-
- folder_name = context.testbed.config['VM_FOLDER2_NAME']
-
- folder_svc = Folder(context.stub_config)
- filter = Folder.FilterSpec(
- names=set([folder_name]),
- datacenters=set([datacenter]))
- folder_summaries = folder_svc.list(filter=filter)
-
- folder = None
- if len(folder_summaries) > 0:
- folder = folder_summaries[0].folder
- print("Selecting Folder '{}' ({})".format(folder_name, folder))
- else:
- print("Folder '{}' not found".format(folder_name))
- return None
-
- # Select a Datastore meeting our requirements.
- #
- # Must be in the same Datacenter as the ResourcePool that was chosen.
- datacenter_name = context.testbed.config['DATACENTER2_NAME']
- datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
-
- # TODO Parameterize based on NFS or VMFS
- datastore_name = context.testbed.config['NFS_DATASTORE_NAME']
-
- datastore_svc = Datastore(context.stub_config)
- filter = Datastore.FilterSpec(
- names=set([datastore_name]),
- datacenters=set([datacenter]))
- datastore_summaries = datastore_svc.list(filter=filter)
-
- datastore = None
- if len(datastore_summaries) > 0:
- datastore = datastore_summaries[0].datastore
- print("Selecting Datastore '{}' ({})".format(datastore_name, datastore))
- else:
- print("Datastore '{}' not found".format(datastore_name))
- return None
-
- placement_spec = VM.PlacementSpec(folder=folder,
- resource_pool=resource_pool,
- datastore=datastore)
- print("get_placement_spec_for_resourcepool: Result is '{}'".
- format(placement_spec))
- return placement_spec
diff --git a/samples/vsphere/vcenter/vm/power.py b/samples/vsphere/vcenter/vm/power.py
deleted file mode 100644
index 83286311..00000000
--- a/samples/vsphere/vcenter/vm/power.py
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/env python
-
-"""
-* *******************************************************
-* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
-* SPDX-License-Identifier: MIT
-* *******************************************************
-*
-* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
-* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
-* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
-* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
-"""
-
-__author__ = 'VMware, Inc.'
-__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
-__vcenter_version__ = '6.5+'
-
-import atexit
-
-from com.vmware.vcenter.vm_client import Power
-from samples.vsphere.common import vapiconnect
-from samples.vsphere.common.sample_util import parse_cli_args_vm
-from samples.vsphere.common.sample_util import pp
-from samples.vsphere.vcenter.setup import testbed
-
-from samples.vsphere.vcenter.helper.vm_helper import get_vm
-
-"""
-Demonstrates the virtual machine power lifecycle
-
-Sample Prerequisites:
-The sample needs an existing VM.
-"""
-
-vm = None
-vm_name = None
-stub_config = None
-vm_power_svc = None
-cleardata = False
-
-
-def setup(context=None):
- global stub_config, cleardata, vm_name
- if context:
- # Run sample suite via setup script
- vm_name = testbed.config['VM_NAME_DEFAULT']
- stub_config = context.stub_config
- else:
- # Run sample in standalone mode
- server, username, password, cleardata, skip_verification, vm_name = \
- parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
- stub_config = vapiconnect.connect(server,
- username,
- password,
- skip_verification)
- atexit.register(vapiconnect.logout, stub_config)
-
-
-def run():
- global vm
- vm = get_vm(stub_config, vm_name)
- if not vm:
- raise Exception('Sample requires an existing vm with name ({}).'
- 'Please create the vm first.'.format(vm_name))
- print("Using VM '{}' ({}) for Power Sample".format(vm_name, vm))
-
- # Create Power stub used for making requests
- global vm_power_svc
- vm_power_svc = Power(stub_config)
-
- # Get the vm power state
- print('\n# Example: Get current vm power state')
- status = vm_power_svc.get(vm)
- print('vm.Power.get({}) -> {}'.format(vm, pp(status)))
-
- # Power off the vm if it is on
- if status == Power.Info(state=Power.State.POWERED_ON):
- print('\n# Example: VM is powered on, power it off')
- vm_power_svc.stop(vm)
- print('vm.Power.stop({})'.format(vm))
-
- # Power on the vm
- print('# Example: Power on the vm')
- vm_power_svc.start(vm)
- print('vm.Power.start({})'.format(vm))
-
- # Suspend the vm
- print('\n# Example: Suspend the vm')
- vm_power_svc.suspend(vm)
- print('vm.Power.suspend({})'.format(vm))
-
- # Resume the vm
- print('\n# Example: Resume the vm')
- vm_power_svc.start(vm)
- print('vm.Power.start({})'.format(vm))
-
- # Reset the vm
- print('\n# Example: Reset the vm')
- vm_power_svc.reset(vm)
- print('vm.Power.reset({})'.format(vm))
-
-
-def cleanup():
- # Power off the vm
- print('\n# Cleanup: Power off the vm')
- vm_power_svc.stop(vm)
- print('vm.Power.stop({})'.format(vm))
- status = vm_power_svc.get(vm)
- if status == Power.Info(state=Power.State.POWERED_OFF,
- clean_power_off=True):
- print('VM is powered off')
- else:
- print('vm.Power Warning: Could not power off vm')
-
-
-def main():
- setup()
- run()
- if cleardata:
- cleanup()
-
-
-if __name__ == '__main__':
- main()
diff --git a/setup.cfg b/setup.cfg
deleted file mode 100644
index e445209e..00000000
--- a/setup.cfg
+++ /dev/null
@@ -1,2 +0,0 @@
-[pycodestyle]
-ignore = E402, E501, E122, E126, E127, E128, E129, E131
\ No newline at end of file
diff --git a/test-requirements.txt b/test-requirements.txt
deleted file mode 100644
index 40c8478e..00000000
--- a/test-requirements.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-testtools>=0.9.34
-vcrpy
diff --git a/vmworld2017/README.md b/vmworld2017/README.md
deleted file mode 100644
index aa39b774..00000000
--- a/vmworld2017/README.md
+++ /dev/null
@@ -1,37 +0,0 @@
-# VMTN6720U - Hackathon Training: Getting started with the vSphere Automation SDK for Python
-**Date:** 08/28/17 6:30PM-8:00PM
-
-# Agenda
-* Introduction to vSphere REST API
-* vSphere Automation SDKs
-* Getting Started Using the Python SDK
-* Lab
-
-# Introduction to vSphere REST API
-* Consume from SDKs, CLI’s
-* NOTE: Need bullets from Alan
-
-# vSphere Automation SDKs
-* Supported Languages
- * Python, Java, Ruby, Perl, .NET, REST (JavaScript/Postman)
-* Open Source on Github
- * SDK Includes:
- * Runtime
- * Serialization
- * Language Binding
- * Python Wrapper around REST API
- * API Reference Documentation (for offline usage)
-
-# [Labs](lab.md)
-
-**Wifi**: VMworld-Hackathon-Training-4
-**Wifi Password**: Hackathon2017
-
-Connect to VC matching first letter of your last name (poorman’s load balance):
-
-**VC1**: [192.168.104.11](https://192.168.104.11) (A-H)
-**VC2**: [192.168.104.13](https://192.168.104.13) (I-Q)
-**VC3**: [192.168.104.13](https://192.168.104.13) (R-Z)
-
-**VC Username**: administrator@vsphere.local
-**VC Password**: VMware1!