|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +* ******************************************************* |
| 5 | +* Copyright (c) VMware, Inc. 2019. All Rights Reserved. |
| 6 | +* SPDX-License-Identifier: MIT |
| 7 | +* ******************************************************* |
| 8 | +* |
| 9 | +* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT |
| 10 | +* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN, |
| 11 | +* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED |
| 12 | +* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, |
| 13 | +* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. |
| 14 | +""" |
| 15 | + |
| 16 | +__author__ = 'TODO: <your name and email>' |
| 17 | +__vcenter_version__ = 'TODO: <compatible vcenter versions>' |
| 18 | + |
| 19 | +from com.vmware.vcenter_client import VM |
| 20 | +from vmware.vapi.vsphere.client import create_vsphere_client |
| 21 | + |
| 22 | +from samples.vsphere.common import sample_cli |
| 23 | +from samples.vsphere.common import sample_util |
| 24 | +from samples.vsphere.common.ssl_helper import get_unverified_session |
| 25 | + |
| 26 | + |
| 27 | +""" |
| 28 | +TODO: Sample description and prerequisites. |
| 29 | +e.g. Demonstrates getting list of VMs present in vCenter |
| 30 | +
|
| 31 | +Sample Prerequisites: |
| 32 | + - vCenter |
| 33 | +""" |
| 34 | + |
| 35 | +# Create argument parser for standard inputs: |
| 36 | +# server, username, password, cleanup and skipverification |
| 37 | +parser = sample_cli.build_arg_parser() |
| 38 | + |
| 39 | +# Add your custom input arguments |
| 40 | +parser.add_argument('--vm_name', |
| 41 | + action='store', |
| 42 | + default='Sample_Default_VM_for_Simple_Testbed', |
| 43 | + help='Name of the testing vm') |
| 44 | + |
| 45 | +args = sample_util.process_cli_args(parser.parse_args()) |
| 46 | + |
| 47 | +# Skip server cert verification if needed. |
| 48 | +# This is not recommended in production code. |
| 49 | +session = get_unverified_session() if args.skipverification else None |
| 50 | + |
| 51 | +# Connect to vSphere client |
| 52 | +client = create_vsphere_client(server=args.server, |
| 53 | + username=args.username, |
| 54 | + password=args.password, |
| 55 | + session=session) |
| 56 | + |
| 57 | +# List VMs |
| 58 | +filter_spec = VM.FilterSpec(names=set([args.vm_name])) |
| 59 | +vms = client.vcenter.VM.list(filter_spec) |
| 60 | +print(vms) |
0 commit comments