mirror of
https://github.com/vmware/vsphere-automation-sdk-python.git
synced 2024-11-23 18:10:00 -05:00
Added samples for 8.0 GA
Signed-off-by: Ankit Agrawal <aagrawal3@vmware.com>
This commit is contained in:
parent
d92fea8873
commit
635750b5b2
12
README.md
12
README.md
@ -50,9 +50,17 @@ SDK package installation commands may differ depending on the environment where
|
||||
##### 1. Typical Installation
|
||||
This is the recommended way to install the SDK. The installation is done from [PyPI](https://pypi.org/) and [Automation SDK Python Github](https://github.com/vmware/vsphere-automation-sdk-python) repositories.
|
||||
|
||||
Install/Update latest setuptools from PyPI
|
||||
Install/Update latest pip from PyPI
|
||||
```cmd
|
||||
pip install --upgrade pip setuptools
|
||||
pip install --upgrade pip
|
||||
```
|
||||
Install/Update setuptools to version 62.0.0 for python version > 3.6
|
||||
```cmd
|
||||
pip install --upgrade setuptools==62.0.0
|
||||
```
|
||||
for older python versions Install/Update setuptools to version 36.2.0
|
||||
```cmd
|
||||
pip install --upgrade setuptools==36.2.0
|
||||
```
|
||||
Install SDK packages from Github.
|
||||
```cmd
|
||||
|
@ -1,4 +1,4 @@
|
||||
###### This requirements file is used for local installation, where access to GitHub is restricted ######
|
||||
###### This requirements file is used for local installation where access to GitHub is restricted ######
|
||||
###### Common requirements ######
|
||||
lxml >= 4.3.0
|
||||
pyVmomi >= 6.7
|
||||
|
32
samples/vsphere/appliances/patching/README.md
Normal file
32
samples/vsphere/appliances/patching/README.md
Normal file
@ -0,0 +1,32 @@
|
||||
This Directory contains samples for Patching API - applmgmt APIs
|
||||
For more information, please review the official release notes.
|
||||
|
||||
Applmgmt having the followings APIs:
|
||||
* Pending: Performs patching for pending updates
|
||||
* Update: Status of update operation
|
||||
|
||||
Overview of the directory code samples:
|
||||
|
||||
* update_sample.py - running a simple workflow to update the vc/component . It's having below APIs.
|
||||
GET https://{server}/rest/appliance/update/pending
|
||||
GET https://{server}/rest/appliance/update/pending/{{update_id}}/components
|
||||
GET https://{server}/rest/appliance/update/pending/{{update_id}}?component={component}
|
||||
POST https://{server}/rest/appliance/update/pending/{{update_id}}?action=precheck
|
||||
POST https://{server}/rest/appliance/update/pending/{{update_id}}?action=validate
|
||||
POST https://{server}/rest/appliance/update/pending/{{update_id}}?action=stage
|
||||
POST https://{server}/rest/appliance/update/pending/{{update_id}}?action=install
|
||||
|
||||
|
||||
To view the available command-line options:
|
||||
|
||||
$ python update_sample.py --help
|
||||
|
||||
Running the samples:
|
||||
|
||||
$ python update_sample.py --server <vCenter Server IP> --username <username> --password <password> --url <customurl> --component <component> --skipverification
|
||||
|
||||
|
||||
Testbed Requirement:
|
||||
|
||||
* vCenter Server appliance version 8.0 or above are supported for component update.
|
||||
* vCenter Server appliance version 6.7 or above are supported for full patch.
|
26
samples/vsphere/appliances/patching/__init__.py
Normal file
26
samples/vsphere/appliances/patching/__init__.py
Normal file
@ -0,0 +1,26 @@
|
||||
"""
|
||||
* *******************************************************
|
||||
* Copyright VMware, Inc. 2022. 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 2022 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
|
145
samples/vsphere/appliances/patching/update_sample.py
Normal file
145
samples/vsphere/appliances/patching/update_sample.py
Normal file
@ -0,0 +1,145 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
* *******************************************************
|
||||
* Copyright (c) VMware, Inc. 2022. 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.'
|
||||
__vcenter_version__ = '8.0'
|
||||
|
||||
from com.vmware.appliance.update_client import Pending, Staged
|
||||
from com.vmware.appliance_client import Update
|
||||
|
||||
from samples.vsphere.common import sample_cli, sample_util
|
||||
from samples.vsphere.common.ssl_helper import get_unverified_session
|
||||
from samples.vsphere.vcenter.hcl.utils import get_configuration
|
||||
import time
|
||||
|
||||
|
||||
class SampleUpdate(object):
|
||||
"""
|
||||
Sample demonstrating Patching APIs
|
||||
Sample Prerequisites:
|
||||
vCenter on linux platform
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
parser = sample_cli.build_arg_parser()
|
||||
parser.add_argument('-com', '--component',
|
||||
action='store',
|
||||
required=False,
|
||||
help='Component to be updated.')
|
||||
|
||||
parser.add_argument('-url', '--url',
|
||||
action='store',
|
||||
required=False,
|
||||
help='Custom target url.')
|
||||
args = sample_util.process_cli_args(parser.parse_args())
|
||||
# cis session
|
||||
session = get_unverified_session() if args.skipverification else None
|
||||
stub_config = get_configuration(
|
||||
args.server, args.username, args.password,
|
||||
session)
|
||||
self.url = args.url if args.url else None
|
||||
self.component = args.component if args.component else None
|
||||
self.pending_client = Pending(stub_config)
|
||||
self.staged_client = Staged(stub_config)
|
||||
self.appliance_client = Update(stub_config)
|
||||
self.password = args.password
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Access the Pending APIs to list and do a pending update
|
||||
"""
|
||||
|
||||
version_list = self.pending_client.list("LOCAL_AND_ONLINE", self.url)
|
||||
print("\nFull patch update list: \n", version_list)
|
||||
version = version_list[0].version
|
||||
|
||||
# Upgradeable Component List
|
||||
if self.component:
|
||||
component_list = self.pending_client.list_upgradeable_components(version)
|
||||
# component = component_list[0]["component"]
|
||||
print("\nUpgradeable Component list: \n", component_list)
|
||||
|
||||
# get Update info
|
||||
update_info = self.pending_client.get(version, self.component)
|
||||
print("\nGet Information of Update: ")
|
||||
ServicesToBeStopped = [x.service for x in update_info.services_will_be_stopped]
|
||||
print("name: ", update_info.name)
|
||||
print("services_will_be_stopped: ", ServicesToBeStopped)
|
||||
print("staged: ", update_info.staged)
|
||||
print("knowledge_base: ", update_info.knowledge_base)
|
||||
print("priority: ", update_info.priority)
|
||||
print("severity: ", update_info.severity)
|
||||
print("update_type: ", update_info.update_type)
|
||||
print("release_date: ", update_info.release_date)
|
||||
print("reboot_required: ", update_info.reboot_required)
|
||||
print("size: ", update_info.size)
|
||||
|
||||
user_data = {"vmdir.password": self.password}
|
||||
# Precheck Update
|
||||
precheck_result = self.pending_client.precheck(version, self.component)
|
||||
print("\nPrecheck result : \n", precheck_result)
|
||||
for question in precheck_result.questions:
|
||||
print("Please provide answer to following question")
|
||||
print(question.text.default_message)
|
||||
print("Question Description : ", question.description.default_message)
|
||||
print("Provide your answer: ")
|
||||
ans = str(input())
|
||||
user_data[question.data_item] = ans
|
||||
|
||||
# Validate an Update
|
||||
validate_result = self.pending_client.validate(version, user_data, self.component)
|
||||
print("\nValidate result for update: \n", validate_result)
|
||||
|
||||
# Stage an Update
|
||||
|
||||
self.pending_client.stage(version, self.component)
|
||||
print("Staging the update")
|
||||
|
||||
# Monitor Stage
|
||||
monitor_stage = self.appliance_client.get()
|
||||
while monitor_stage.task.status == "RUNNING":
|
||||
time.sleep(50)
|
||||
monitor_stage = self.appliance_client.get()
|
||||
|
||||
print("State: ", monitor_stage.state)
|
||||
print("Status: ", monitor_stage.task.status)
|
||||
if monitor_stage.task.status == "FAILED":
|
||||
print("")
|
||||
return
|
||||
print("\nStage result: \n", monitor_stage)
|
||||
|
||||
staged_result = self.staged_client.get()
|
||||
print("\nStaged Update: ", staged_result)
|
||||
|
||||
# Install an update
|
||||
self.pending_client.install(version, user_data, self.component)
|
||||
|
||||
# Monitor Install
|
||||
print("Installing the update")
|
||||
monitor_install = self.appliance_client.get()
|
||||
while monitor_install.task.status == "RUNNING":
|
||||
monitor_install = self.appliance_client.get()
|
||||
print("\nInstall result: \n", monitor_install)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Entry point for the sample client
|
||||
"""
|
||||
pending_update = SampleUpdate()
|
||||
pending_update.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
4
samples/vsphere/vcenter/vlcm/README.md
Normal file
4
samples/vsphere/vcenter/vlcm/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
This directory organizes the different types of available sample vLCM APIs.
|
||||
|
||||
1. Hardware Compatibilty Details Operations:
|
||||
* Get the cluster hardware compatibility details - cluster/hcl/hw_compatibility_details_sample.py
|
25
samples/vsphere/vcenter/vlcm/__init__.py
Normal file
25
samples/vsphere/vcenter/vlcm/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
"""
|
||||
* *******************************************************
|
||||
* Copyright VMware, Inc. 2022. 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 2022 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
|
1
samples/vsphere/vcenter/vlcm/cluster/README.md
Normal file
1
samples/vsphere/vcenter/vlcm/cluster/README.md
Normal file
@ -0,0 +1 @@
|
||||
This directory organizes the different types of cluster level sample vLCM APIs.
|
25
samples/vsphere/vcenter/vlcm/cluster/__init__.py
Normal file
25
samples/vsphere/vcenter/vlcm/cluster/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
"""
|
||||
* *******************************************************
|
||||
* Copyright VMware, Inc. 2022. 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 2022 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
|
26
samples/vsphere/vcenter/vlcm/cluster/hcl/README.md
Normal file
26
samples/vsphere/vcenter/vlcm/cluster/hcl/README.md
Normal file
@ -0,0 +1,26 @@
|
||||
#vLCM/Cluster/HCL
|
||||
|
||||
This directory contains samples of cluster level vLCM HCL APIs.
|
||||
|
||||
The hardware compatibility service provides a way to ensure that the various driver and firmware components that are going to be installed on certain HW components (which are in use by vSAN) are certified against the ESXi version and present in the vSAN VCG.
|
||||
|
||||
The Hardware Compatibility Details provides information such as the overall compliance status of the cluster, the base image version, pci device compliance, and storage device compliance. Within the more specific sections of the hardware compatibility details, one can find the corresponding supported devices.
|
||||
|
||||
##Supported Features by Release:
|
||||
|
||||
7.0 : IO Controllers
|
||||
7.0 U3 : IO Controllers, Directly Attached Storage Devices, Storage Devices Configured With RAID Controller
|
||||
8.0 : IO Controllers, Directly Attached Storage Devices, Storage Devices Configured With RAID Controller, Intel VMD NVMe, RDMA NIC
|
||||
|
||||
##APIs
|
||||
GET Hardware Compatibility Details - Returns the HCL validation check detailed results.
|
||||
|
||||
##Running the Samples:
|
||||
|
||||
To view the available command-line options:
|
||||
|
||||
$ python hw_compatibility_details_sample.py --help
|
||||
|
||||
Run the samples:
|
||||
|
||||
$ python hw_compatibility_details_sample.py --server <Vcenter Server IP> --username <username> --password <password> --skipverification --cluster <MOID of cluster>
|
25
samples/vsphere/vcenter/vlcm/cluster/hcl/__init__.py
Normal file
25
samples/vsphere/vcenter/vlcm/cluster/hcl/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
"""
|
||||
* *******************************************************
|
||||
* Copyright VMware, Inc. 2022. 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 2022 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
|
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
* *******************************************************
|
||||
* Copyright (c) VMware, Inc. 2022. 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.'
|
||||
__vcenter_version__ = '7.0+'
|
||||
|
||||
from com.vmware.esx.settings.clusters.software.reports.hardware_compatibility_client import Details
|
||||
from samples.vsphere.vcenter.hcl.utils import get_configuration
|
||||
from samples.vsphere.common import sample_util, sample_cli
|
||||
|
||||
|
||||
class HWCompatibilityDetailsSample(object):
|
||||
"""
|
||||
Sample demonstrating vCenter HCL Get HW Compatibility Details Operation
|
||||
Sample Prerequisites:
|
||||
vCenter on linux platform
|
||||
The vCenter should have HCL DataStore(Compatibility Data) Populated
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
parser = sample_cli.build_arg_parser()
|
||||
parser.add_argument('-id', '--cluster',
|
||||
required=True,
|
||||
help='MOID of the source cluster for eg "domain-c92"')
|
||||
args = sample_util.process_cli_args(parser.parse_args())
|
||||
self.cluster_id = args.cluster
|
||||
config = get_configuration(args.server, args.username,
|
||||
args.password,
|
||||
args.skipverification)
|
||||
|
||||
self.api_client = Details(config)
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Access the HCL Hardware Compatibility Details GET API to get the task id
|
||||
"""
|
||||
report_info = self.api_client.get(self.cluster_id)
|
||||
print("Hardware Compatibility Details : ", report_info)
|
||||
print("Storage Device Details: ", report_info.storage_device_compliance)
|
||||
print("PCI Device Details : ", report_info.pci_device_compliance)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Entry point for the CompatibilityReportSample client
|
||||
"""
|
||||
detailsSample = HWCompatibilityDetailsSample()
|
||||
detailsSample.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
11
samples/vsphere/vcenter/wcp/README.md
Normal file
11
samples/vsphere/vcenter/wcp/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
This directory contains samples for WCP service APIs:
|
||||
|
||||
* Enable supervisor on zones
|
||||
* Get/List of supervisor's summary
|
||||
|
||||
Running the samples
|
||||
|
||||
$ python <sample-dir>/<sample>.py --server <vCenter Server IP> --username <username> --password <password> <additional-sample-parameters>
|
||||
|
||||
* Testbed Requirement:
|
||||
- 1 vCenter Server >= 8.0.0+
|
193
samples/vsphere/vcenter/wcp/enable_on_zones.py
Normal file
193
samples/vsphere/vcenter/wcp/enable_on_zones.py
Normal file
@ -0,0 +1,193 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
* *******************************************************
|
||||
* Copyright (c) VMware, Inc. 2022. 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 2022 VMware, Inc. All rights reserved.'
|
||||
__vcenter_version__ = '8.0.0+'
|
||||
|
||||
import typing
|
||||
|
||||
from com.vmware.vcenter.namespace_management_client import Supervisors
|
||||
from com.vmware.vcenter.namespace_management.supervisors_client import ControlPlane, Workloads, SizingHint
|
||||
from com.vmware.vcenter.namespace_management.networks_client import Network, VSphereNetwork, NetworkType
|
||||
import com.vmware.vcenter.namespace_management.networks_client as net
|
||||
import com.vmware.vcenter.namespace_management.networks.service_client as net_svc
|
||||
from com.vmware.vcenter.namespace_management.networks.edges_client import Edge, HAProxyConfig, EdgeProvider, Server
|
||||
|
||||
from samples.vsphere.common import sample_cli
|
||||
from samples.vsphere.common import sample_util
|
||||
from samples.vsphere.common.ssl_helper import get_unverified_session
|
||||
from samples.vsphere.vcenter.hcl.utils import get_configuration
|
||||
|
||||
NTP_SERVERS = ["pool.ntp.org"]
|
||||
|
||||
|
||||
def dns_servers(args) -> typing.Optional[net_svc.DNS]:
|
||||
dns_spec = None
|
||||
servers = args.split(",")
|
||||
if not servers:
|
||||
dns_spec = net_svc.DNS(servers=servers, search_domains=[])
|
||||
return dns_spec
|
||||
|
||||
|
||||
def create_zones_enable_spec(args) -> Supervisors.EnableOnZonesSpec:
|
||||
"""
|
||||
Creates an enablement spec for WCP across multiple zones using VDS for workload networking.
|
||||
"""
|
||||
control_plane_spec = ControlPlane(
|
||||
size=SizingHint.TINY, # Tests assume this is set to TINY. It is later updated to SMALL.
|
||||
login_banner='Welcome to Supervisor on vSphere Zones!',
|
||||
storage_policy=args.control_plane_storage_policy,
|
||||
floating_ip_address=args.control_plane_floating_ip_address,
|
||||
network=Network(
|
||||
network=NetworkType.VSPHERE,
|
||||
vsphere=VSphereNetwork(
|
||||
dvpg=args.control_plane_network_vsphere_dvpg
|
||||
),
|
||||
services=net.Services(
|
||||
dns=dns_servers(args.control_plane_network_services_dns_servers),
|
||||
ntp=net_svc.NTP(servers=NTP_SERVERS)
|
||||
),
|
||||
)
|
||||
)
|
||||
workload_spec = Workloads(
|
||||
network=Network(
|
||||
network=NetworkType.VSPHERE,
|
||||
ip_management=net.IPManagement(
|
||||
dhcp_enabled=False,
|
||||
gateway_address="192.168.1.1/16",
|
||||
ip_assignments=[
|
||||
net.IPAssignment(
|
||||
assignee=net.IPAssignment.Assignment.SERVICE,
|
||||
ranges=[net.IPRange(
|
||||
address="172.24.0.0",
|
||||
count=65536
|
||||
)]
|
||||
),
|
||||
net.IPAssignment(
|
||||
assignee=net.IPAssignment.Assignment.NODE,
|
||||
ranges=[net.IPRange(
|
||||
address="192.168.128.0",
|
||||
count=256
|
||||
)]
|
||||
)
|
||||
]
|
||||
),
|
||||
vsphere=VSphereNetwork(
|
||||
dvpg=args.workloads_network_vsphere_dvpg
|
||||
),
|
||||
services=net.Services(
|
||||
dns=dns_servers(args.workloads_network_services_dns_servers),
|
||||
ntp=net_svc.NTP(servers=NTP_SERVERS)
|
||||
),
|
||||
),
|
||||
edge=Edge(
|
||||
id="lb-1",
|
||||
load_balancer_address_ranges=[net.IPRange(
|
||||
address="192.168.0.1",
|
||||
count=256
|
||||
)],
|
||||
provider=EdgeProvider.HAPROXY,
|
||||
haproxy=HAProxyConfig(
|
||||
servers=[Server(
|
||||
host=args.workloads_edge_haproxy_servers,
|
||||
port=5556
|
||||
)],
|
||||
username=args.workloads_edge_haproxy_username,
|
||||
password=args.workloads_edge_haproxy_password,
|
||||
certificate_authority_chain=args.workloads_edge_haproxy_certificate_authority_chain,
|
||||
)
|
||||
)
|
||||
)
|
||||
return Supervisors.EnableOnZonesSpec(
|
||||
name=args.name,
|
||||
zones=args.zones,
|
||||
control_plane=control_plane_spec,
|
||||
workloads=workload_spec
|
||||
)
|
||||
|
||||
|
||||
class EnableSupervisorsOnZones(object):
|
||||
"""
|
||||
Demonstrates enabling Supervisors on given zones.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
parser = sample_cli.build_arg_parser()
|
||||
parser.add_argument('--name',
|
||||
required=True,
|
||||
help='A user-friendly identifier for this Supervisor.')
|
||||
parser.add_argument('--zones',
|
||||
required=True,
|
||||
help='List of consumption fault domain zones available for Supervisors and its workloads.')
|
||||
|
||||
# control plane enable configuration
|
||||
parser.add_argument('--control-plane-storage-policy',
|
||||
required=True,
|
||||
help='Identifies the storage policy backing the Supervisor Kubernetes API server.')
|
||||
parser.add_argument('--control-plane-floating-ip-address',
|
||||
required=True,
|
||||
help='Floating IP address for supervisors')
|
||||
parser.add_argument('--control-plane-network-vsphere-dvpg',
|
||||
required=True,
|
||||
help='The Managed Object ID of a vSphere Distributed Virtual Port Group for Control Plane.')
|
||||
parser.add_argument('--control-plane-network-services-dns-servers',
|
||||
required=True,
|
||||
help='List of control plane DNS servers')
|
||||
|
||||
# workloads enable configuration
|
||||
parser.add_argument('--workloads-network-vsphere-dvpg',
|
||||
required=True,
|
||||
help='The Managed Object ID of a vSphere Distributed Virtual Switch for workloads.')
|
||||
parser.add_argument('--workloads-network-services-dns-servers',
|
||||
required=True,
|
||||
help='List of workloads DNS servers.')
|
||||
|
||||
# load balancer enable configuration
|
||||
parser.add_argument('--workloads-edge-haproxy-servers',
|
||||
required=True,
|
||||
help='List of the addresses for the data plane API servers used to configure Virtual '
|
||||
'Servers.')
|
||||
parser.add_argument('--workloads-edge-haproxy-username',
|
||||
required=True,
|
||||
help='Used by the HAProxy Kubernetes Operator to program the HAProxy Controller.')
|
||||
parser.add_argument('--workloads-edge-haproxy-password',
|
||||
required=True,
|
||||
help='Used for securing HAProxy username.')
|
||||
parser.add_argument('--workloads-edge-haproxy-certificate-authority-chain',
|
||||
required=True,
|
||||
help='PEM-encoded CA chain which is used to verify x509 certificates received from the '
|
||||
'server.')
|
||||
|
||||
args = sample_util.process_cli_args(parser.parse_args())
|
||||
session = get_unverified_session() if args.skipverification else None
|
||||
stub_config = get_configuration(
|
||||
args.server, args.username, args.password,
|
||||
session)
|
||||
self.supervisor_enable_on_zones = Supervisors(stub_config)
|
||||
self.spec = create_zones_enable_spec(args)
|
||||
|
||||
def run(self):
|
||||
supervisor_id = self.supervisor_enable_on_zones.enable_on_zones(self.spec)
|
||||
print('supervisor_id: {0}'.format(supervisor_id))
|
||||
|
||||
|
||||
def main():
|
||||
list_cl = EnableSupervisorsOnZones()
|
||||
list_cl.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
63
samples/vsphere/vcenter/wcp/get_supervisor_summary.py
Normal file
63
samples/vsphere/vcenter/wcp/get_supervisor_summary.py
Normal file
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
* *******************************************************
|
||||
* Copyright (c) VMware, Inc. 2022. 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 2022 VMware, Inc. All rights reserved.'
|
||||
__vcenter_version__ = '8.0.0+'
|
||||
|
||||
from com.vmware.vcenter.namespace_management.supervisors_client import Summary
|
||||
from samples.vsphere.common import sample_cli
|
||||
from samples.vsphere.common import sample_util
|
||||
from samples.vsphere.common.ssl_helper import get_unverified_session
|
||||
from samples.vsphere.vcenter.hcl.utils import get_configuration
|
||||
|
||||
|
||||
class GetSupervisorsSummary(object):
|
||||
"""
|
||||
Demonstrates looking up a Supervisor Summary on a given Supervisor Cluster.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
parser = sample_cli.build_arg_parser()
|
||||
parser.add_argument('--supervisor',
|
||||
required=True,
|
||||
help='The MoID of the Supervisor to query.')
|
||||
|
||||
args = sample_util.process_cli_args(parser.parse_args())
|
||||
session = get_unverified_session() if args.skipverification else None
|
||||
stub_config = get_configuration(
|
||||
args.server, args.username, args.password,
|
||||
session)
|
||||
self.supervisor_summary = Summary(stub_config)
|
||||
self.supervisor = args.supervisor
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Get Supervisor Summary on vCenter Server.
|
||||
"""
|
||||
summary = self.supervisor_summary.get(self.supervisor)
|
||||
print('name: {0}'.format(summary.name))
|
||||
print('config_status: {0}'.format(summary.config_status))
|
||||
print('kubernetes_status: {0}'.format(summary.kubernetes_status))
|
||||
print('stats: {0}\n'.format(summary.stats))
|
||||
|
||||
|
||||
def main():
|
||||
list_cl = GetSupervisorsSummary()
|
||||
list_cl.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
63
samples/vsphere/vcenter/wcp/list_supervisor_summary.py
Normal file
63
samples/vsphere/vcenter/wcp/list_supervisor_summary.py
Normal file
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
* *******************************************************
|
||||
* Copyright (c) VMware, Inc. 2022. 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 2022 VMware, Inc. All rights reserved.'
|
||||
__vcenter_version__ = '8.0.0+'
|
||||
|
||||
from com.vmware.vcenter.namespace_management.supervisors_client import \
|
||||
Summary
|
||||
|
||||
from samples.vsphere.common import sample_cli
|
||||
from samples.vsphere.common import sample_util
|
||||
from samples.vsphere.common.ssl_helper import get_unverified_session
|
||||
from samples.vsphere.vcenter.hcl.utils import get_configuration
|
||||
|
||||
|
||||
class ListClusterSupervisorServices(object):
|
||||
"""
|
||||
Demonstrates looking up a list of Supervisor Summary.
|
||||
"""
|
||||
def __init__(self):
|
||||
parser = sample_cli.build_arg_parser()
|
||||
args = sample_util.process_cli_args(parser.parse_args())
|
||||
session = get_unverified_session() if args.skipverification else None
|
||||
stub_config = get_configuration(
|
||||
args.server, args.username, args.password,
|
||||
session)
|
||||
self.supervisor_summary = Summary(stub_config)
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
List Supervisor Summary on vCenter Server.
|
||||
"""
|
||||
summaries = self.supervisor_summary.list()
|
||||
print('items:')
|
||||
for s in summaries.items:
|
||||
print('- supervisor: {0}'.format(s.supervisor))
|
||||
print(' info:')
|
||||
print(' name: {0}'.format(s.info.name))
|
||||
print(' config_status: {0}'.format(s.info.config_status))
|
||||
print(' kubernetes_status: {0}'.format(s.info.kubernetes_status))
|
||||
print(' stats: {0}\n'.format(s.info.stats))
|
||||
|
||||
|
||||
def main():
|
||||
list_cl = ListClusterSupervisorServices()
|
||||
list_cl.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user