1
0
mirror of https://github.com/vmware/vsphere-automation-sdk-python.git synced 2024-11-21 17:29:59 -05:00

differentiating required and optional arguments in the help text for … (#175)

* differentiating required and optional arguments in the help text for vmc samples
Signed-off-by: Anusha Hegde <hegdeanusha25@gmail.com>
This commit is contained in:
Anusha Hegde 2019-08-20 12:24:24 +05:30 committed by Tianhao He
parent 206ca3dc16
commit 2d2f32b923
27 changed files with 201 additions and 412 deletions

View File

@ -0,0 +1,48 @@
"""
* *******************************************************
* Copyright (c) VMware, Inc. 2019. 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 2019 VMware, Inc. All rights reserved.'
import argparse
"""
Builds a standard argument parser with required and optional argument groups
Most of the VMC samples require these three standard required arguments.
If any of these arguments are not required, then build your own parser
--refresh_token
--org_id
--sddc_id
"""
parser = argparse.ArgumentParser()
required_args = parser.add_argument_group(
'required arguments')
optional_args = parser.add_argument_group(
'optional arguments')
required_args.add_argument(
'--refresh_token',
required=True,
help='Refresh token obtained from CSP')
required_args.add_argument(
'--org_id',
required=True,
help='Orgization ID')
required_args.add_argument(
'--sddc_id',
required=True,
help='SDDC ID')

View File

@ -16,8 +16,8 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
__vcenter_version__ = '6.8.0+' __vcenter_version__ = '6.8.0+'
import argparse
import requests import requests
from samples.vmc.helpers.sample_cli import parser
from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
from com.vmware.nsx_policy.model_client import IPAddressExpression from com.vmware.nsx_policy.model_client import IPAddressExpression
from com.vmware.nsx_policy.model_client import Group from com.vmware.nsx_policy.model_client import Group
@ -36,21 +36,6 @@ class NSXPolicyCGWFirewall(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh_token',
required=True,
help='Refresh token obtained from CSP')
parser.add_argument('--org_id',
required=True,
help='Orgization ID')
parser.add_argument('--sddc_id',
required=True,
help='Sddc ID')
args = parser.parse_args() args = parser.parse_args()
self.nsx_client = create_nsx_policy_client_for_vmc( self.nsx_client = create_nsx_policy_client_for_vmc(

View File

@ -16,8 +16,8 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
__vcenter_version__ = '6.8.0+' __vcenter_version__ = '6.8.0+'
import argparse
import requests import requests
from samples.vmc.helpers.sample_cli import parser
from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
from com.vmware.nsx_policy.model_client import IPAddressExpression from com.vmware.nsx_policy.model_client import IPAddressExpression
from com.vmware.nsx_policy.model_client import Group from com.vmware.nsx_policy.model_client import Group
@ -38,21 +38,6 @@ class NSXPolicyDFWFirewall(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh_token',
required=True,
help='Refresh token obtained from CSP')
parser.add_argument('--org_id',
required=True,
help='Orgization ID')
parser.add_argument('--sddc_id',
required=True,
help='Sddc ID')
args = parser.parse_args() args = parser.parse_args()
self.nsx_client = create_nsx_policy_client_for_vmc( self.nsx_client = create_nsx_policy_client_for_vmc(

View File

@ -15,9 +15,8 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse
import pprint import pprint
from samples.vmc.helpers.sample_cli import parser
from com.vmware.nsx_policy_client_for_vmc import ( from com.vmware.nsx_policy_client_for_vmc import (
create_nsx_policy_client_for_vmc) create_nsx_policy_client_for_vmc)
@ -33,20 +32,6 @@ class AuthExample(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-r', '--refresh-token',
required=True,
help='VMware Cloud API refresh token')
parser.add_argument('-o', '--org-id',
required=True,
help='Organization identifier.')
parser.add_argument('-s', '--sddc-id',
required=True,
help='Sddc Identifier.')
args = parser.parse_args() args = parser.parse_args()
self.org_id = args.org_id self.org_id = args.org_id

View File

@ -15,7 +15,7 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse from samples.vmc.helpers.sample_cli import parser, required_args
from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
from vmware.vapi.bindings.struct import PrettyPrinter as NsxPrettyPrinter from vmware.vapi.bindings.struct import PrettyPrinter as NsxPrettyPrinter
from com.vmware.nsx_policy.model_client import ApiError from com.vmware.nsx_policy.model_client import ApiError
@ -39,26 +39,11 @@ class NSXPolicyL3VPN(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser( required_args.add_argument('--remote_endpoint_public_ip',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh_token',
required=True,
help='Refresh token obtained from CSP')
parser.add_argument('--org_id',
required=True,
help='Orgization ID')
parser.add_argument('--sddc_id',
required=True,
help='Sddc ID')
parser.add_argument('--remote_endpoint_public_ip',
required=True, required=True,
help='L3 VPN Remote end point\'s public ip') help='L3 VPN Remote end point\'s public ip')
parser.add_argument('--passphrase', required_args.add_argument('--passphrase',
required=True, required=True,
help='Passphrase used for VPN') help='Passphrase used for VPN')

View File

@ -16,8 +16,9 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
__vcenter_version__ = '6.8.1+' __vcenter_version__ = '6.8.1+'
import argparse
import requests import requests
from samples.vmc.helpers.sample_cli import parser
from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
from com.vmware.nsx_vmc_app_client_for_vmc import create_nsx_vmc_app_client_for_vmc from com.vmware.nsx_vmc_app_client_for_vmc import create_nsx_vmc_app_client_for_vmc
from com.vmware.nsx_vmc_app.model_client import PublicIp from com.vmware.nsx_vmc_app.model_client import PublicIp
@ -36,21 +37,6 @@ class NSXPolicyNAT(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh_token',
required=True,
help='Refresh token obtained from CSP')
parser.add_argument('--org_id',
required=True,
help='Orgization ID')
parser.add_argument('--sddc_id',
required=True,
help='Sddc ID')
args = parser.parse_args() args = parser.parse_args()
self.nsx_client = create_nsx_policy_client_for_vmc( self.nsx_client = create_nsx_policy_client_for_vmc(

View File

@ -15,10 +15,11 @@
__author__ = 'VMware, Inc' __author__ = 'VMware, Inc'
__vcenter_version__ = 'VMware Cloud on AWS' __vcenter_version__ = 'VMware Cloud on AWS'
import argparse
import random import random
import requests import requests
from samples.vmc.helpers.sample_cli import parser, required_args, optional_args
from com.vmware.nsx_policy.infra_client import Domains from com.vmware.nsx_policy.infra_client import Domains
from com.vmware.nsx_policy.model_client import (Expression, Group, from com.vmware.nsx_policy.model_client import (Expression, Group,
IPAddressExpression) IPAddressExpression)
@ -35,34 +36,19 @@ Create a new NSX-T Group on MGW or CGW
Sample Prerequisites: Sample Prerequisites:
- SDDC deployed in VMware Cloud on AWS - SDDC deployed in VMware Cloud on AWS
""" """
parser = argparse.ArgumentParser( optional_args.add_argument('--gateway_type',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh_token',
required=True,
help='Refresh token obtained from CSP')
parser.add_argument('--org_id',
required=True,
help='Orgization ID')
parser.add_argument('--sddc_id',
required=True,
help='Sddc ID')
parser.add_argument('--gateway_type',
default='mgw', default='mgw',
help='Gateway type. Either mgw or cgw') help='Gateway type. Either mgw or cgw')
parser.add_argument('--name', required_args.add_argument('--name',
required=True, required=True,
help='Name of the security group to be created') help='Name of the security group to be created')
parser.add_argument('--ip_address', optional_args.add_argument('--ip_address',
default='172.31.0.0/24', default='172.31.0.0/24',
help='IP address for the expression') help='IP address for the expression')
parser.add_argument('--group_id', optional_args.add_argument('--group_id',
help='ID of the group. A random ID will be used by default') help='ID of the group. A random ID will be used by default')
args = parser.parse_args() args = parser.parse_args()

View File

@ -16,10 +16,10 @@
__author__ = 'VMware, Inc' __author__ = 'VMware, Inc'
__vcenter_version__ = 'VMware Cloud on AWS' __vcenter_version__ = 'VMware Cloud on AWS'
import argparse
import random import random
import requests import requests
from samples.vmc.helpers.sample_cli import parser, optional_args
from com.vmware.nsx_policy.infra_client import Domains from com.vmware.nsx_policy.infra_client import Domains
from com.vmware.nsx_policy.model_client import (Expression, Group, from com.vmware.nsx_policy.model_client import (Expression, Group,
IPAddressExpression) IPAddressExpression)
@ -39,26 +39,11 @@ Sample Prerequisites:
- SDDC deployed in VMware Cloud on AWS - SDDC deployed in VMware Cloud on AWS
- A NSX-T security group - A NSX-T security group
""" """
parser = argparse.ArgumentParser( optional_args.add_argument('--gateway_type',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh_token',
required=True,
help='Refresh token obtained from CSP')
parser.add_argument('--org_id',
required=True,
help='Orgization ID')
parser.add_argument('--sddc_id',
required=True,
help='Sddc ID')
parser.add_argument('--gateway_type',
default='mgw', default='mgw',
help='Gateway type. Either mgw or cgw') help='Gateway type. Either mgw or cgw')
parser.add_argument('--group_id', optional_args.add_argument('--group_id',
help='ID of the group to be deleted') help='ID of the group to be deleted')
args = parser.parse_args() args = parser.parse_args()

View File

@ -17,8 +17,8 @@ __author__ = 'VMware, Inc'
__vcenter_version__ = 'VMware Cloud on AWS' __vcenter_version__ = 'VMware Cloud on AWS'
import requests import requests
import argparse
from samples.vmc.helpers.sample_cli import parser, optional_args
from com.vmware.nsx_policy.infra_client import Domains from com.vmware.nsx_policy.infra_client import Domains
from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
from vmware.vapi.bindings.struct import PrettyPrinter from vmware.vapi.bindings.struct import PrettyPrinter
@ -34,22 +34,7 @@ List all Network Security Groups
Sample Prerequisites: Sample Prerequisites:
- SDDC deployed in VMware Cloud on AWS - SDDC deployed in VMware Cloud on AWS
""" """
parser = argparse.ArgumentParser( optional_args.add_argument('--gateway_type',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh_token',
required=True,
help='Refresh token obtained from CSP')
parser.add_argument('--org_id',
required=True,
help='Orgization ID')
parser.add_argument('--sddc_id',
required=True,
help='Sddc ID')
parser.add_argument('--gateway_type',
default='mgw', default='mgw',
help='Gateway type. Either mgw or cgw') help='Gateway type. Either mgw or cgw')

View File

@ -16,10 +16,10 @@
__author__ = 'VMware, Inc' __author__ = 'VMware, Inc'
__vcenter_version__ = 'VMware Cloud on AWS' __vcenter_version__ = 'VMware Cloud on AWS'
import argparse
import random import random
import requests import requests
from samples.vmc.helpers.sample_cli import parser, required_args, optional_args
from com.vmware.nsx_policy.infra_client import Domains from com.vmware.nsx_policy.infra_client import Domains
from com.vmware.nsx_policy.model_client import (Expression, Group, from com.vmware.nsx_policy.model_client import (Expression, Group,
IPAddressExpression) IPAddressExpression)
@ -40,29 +40,14 @@ Sample Prerequisites:
- SDDC deployed in VMware Cloud on AWS - SDDC deployed in VMware Cloud on AWS
- A NSX-T security group - A NSX-T security group
""" """
parser = argparse.ArgumentParser( optional_args.add_argument('--gateway_type',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh_token',
required=True,
help='Refresh token obtained from CSP')
parser.add_argument('--org_id',
required=True,
help='Orgization ID')
parser.add_argument('--sddc_id',
required=True,
help='Sddc ID')
parser.add_argument('--gateway_type',
default='mgw', default='mgw',
help='Gateway type. Either mgw or cgw') help='Gateway type. Either mgw or cgw')
parser.add_argument('--group_id', optional_args.add_argument('--group_id',
help='ID of the group to be updated') help='ID of the group to be updated')
parser.add_argument('--name', required_args.add_argument('--name',
required=True, required=True,
help='New name of the security group to be updated') help='New name of the security group to be updated')

View File

@ -15,9 +15,8 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse
import requests import requests
from samples.vmc.helpers.sample_cli import parser
from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
from com.vmware.nsx_policy.model_client import Rule from com.vmware.nsx_policy.model_client import Rule
from vmware.vapi.bindings.struct import PrettyPrinter as NsxPrettyPrinter from vmware.vapi.bindings.struct import PrettyPrinter as NsxPrettyPrinter
@ -34,21 +33,6 @@ class NSXPolicySegmentFirewall(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh_token',
required=True,
help='Refresh token obtained from CSP')
parser.add_argument('--org_id',
required=True,
help='Orgization ID')
parser.add_argument('--sddc_id',
required=True,
help='Sddc ID')
args = parser.parse_args() args = parser.parse_args()
self.nsx_client = create_nsx_policy_client_for_vmc( self.nsx_client = create_nsx_policy_client_for_vmc(

View File

@ -15,8 +15,7 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse from samples.vmc.helpers.sample_cli import parser, optional_args
from com.vmware.vmc.model_client import DnsForwarders from com.vmware.vmc.model_client import DnsForwarders
from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.vmc.client import create_vmc_client
@ -31,27 +30,13 @@ class DNSCrud(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser( optional_args.add_argument('--use-compute-gateway',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-r', '--refresh-token',
required=True,
help='VMware Cloud API refresh token')
parser.add_argument('-o', '--org-id',
required=True,
help='Organization identifier.')
parser.add_argument('-s', '--sddc-id',
required=True,
help='Sddc Identifier.')
parser.add_argument('--use-compute-gateway',
action='store_true', action='store_true',
default=False, default=False,
help='Use compute gateway. Default is using ' help='Use compute gateway. Default is using '
'management gateway') 'management gateway')
parser.add_argument('-c', '--cleardata', optional_args.add_argument('--cleardata',
action='store_true', action='store_true',
help='Clean up after sample run') help='Clean up after sample run')
args = parser.parse_args() args = parser.parse_args()

View File

@ -16,9 +16,9 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
__vcenter_version__ = 'VMware Cloud on AWS' __vcenter_version__ = 'VMware Cloud on AWS'
import argparse
import random import random
from samples.vmc.helpers.sample_cli import parser, required_args, optional_args
from com.vmware.vmc.model_client import * from com.vmware.vmc.model_client import *
from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.vmc.client import create_vmc_client
from samples.vmc.helpers.vmc_task_helper import wait_for_task from samples.vmc.helpers.vmc_task_helper import wait_for_task
@ -36,37 +36,23 @@ class ExposePublicIP(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser( optional_args.add_argument('--notes',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-r', '--refresh-token',
required=True,
help='VMware Cloud API refresh token')
parser.add_argument('-o', '--org-id',
required=True,
help='Organization identifier.')
parser.add_argument('-s', '--sddc-id',
required=True,
help='Sddc Identifier.')
parser.add_argument('--notes',
default='Sample public IP ' + str(random.randint(0, 100)), default='Sample public IP ' + str(random.randint(0, 100)),
help='Notes of the new public IP') help='Notes of the new public IP')
parser.add_argument('--fw-rule-name', optional_args.add_argument('--fw-rule-name',
default='Sample firewall rule ' + str(random.randint(0, 100)), default='Sample firewall rule ' + str(random.randint(0, 100)),
help='Name of the compute gae') help='Name of the compute gae')
parser.add_argument('--nat-rule-description', optional_args.add_argument('--nat-rule-description',
default='Sample NAT rule ' + str(random.randint(0, 100)), default='Sample NAT rule ' + str(random.randint(0, 100)),
help='Description for the NAT rule') help='Description for the NAT rule')
parser.add_argument('--internal-ip', required_args.add_argument('--internal-ip',
required=True, required=True,
help='Private IP of the VM') help='Private IP of the VM')
parser.add_argument('-c', '--cleardata', optional_args.add_argument('--cleardata',
action='store_true', action='store_true',
help='Clean up after sample run') help='Clean up after sample run')
args = parser.parse_args() args = parser.parse_args()

View File

@ -14,8 +14,7 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse from samples.vmc.helpers.sample_cli import parser, optional_args
from com.vmware.vmc.model_client import (AddressFWSourceDestination, from com.vmware.vmc.model_client import (AddressFWSourceDestination,
Application, FirewallRules, Application, FirewallRules,
Nsxfirewallrule, Nsxfirewallservice) Nsxfirewallrule, Nsxfirewallservice)
@ -32,34 +31,19 @@ class FirewallRulesCrud(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser( optional_args.add_argument(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'-r',
'--refresh-token',
required=True,
help='VMware Cloud API refresh token')
parser.add_argument(
'-o', '--org-id', required=True, help='Organization identifier.')
parser.add_argument(
'-s', '--sddc-id', required=True, help='Sddc Identifier.')
parser.add_argument(
'--rule-name', '--rule-name',
default='Sample Firewall Rule', default='Sample Firewall Rule',
help='Name of the new firewall rule') help='Name of the new firewall rule')
parser.add_argument( optional_args.add_argument(
'--use-compute-gateway', '--use-compute-gateway',
action='store_true', action='store_true',
default=False, default=False,
help='Use compute gateway. Default is using ' help='Use compute gateway. Default is using '
'management gateway') 'management gateway')
parser.add_argument( optional_args.add_argument(
'-c',
'--cleardata', '--cleardata',
action='store_true', action='store_true',
help='Clean up after sample run') help='Clean up after sample run')

View File

@ -14,8 +14,7 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse from samples.vmc.helpers.sample_cli import parser, optional_args
from com.vmware.vmc.model_client import Ipsec, IpsecSite, IpsecSites, Subnets from com.vmware.vmc.model_client import Ipsec, IpsecSite, IpsecSites, Subnets
from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.vmc.client import create_vmc_client
@ -30,59 +29,44 @@ class IpsecVPNsCrud(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser( optional_args.add_argument(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'-r',
'--refresh-token',
required=True,
help='VMware Cloud API refresh token')
parser.add_argument(
'-o', '--org-id', required=True, help='Organization identifier.')
parser.add_argument(
'-s', '--sddc-id', required=True, help='Sddc Identifier.')
parser.add_argument(
'--use-compute-gateway', '--use-compute-gateway',
action='store_true', action='store_true',
default=False, default=False,
help='Use compute gateway. Default is using ' help='Use compute gateway. Default is using '
'management gateway') 'management gateway')
parser.add_argument( optional_args.add_argument(
'--vpn-name', '--vpn-name',
default='Sample IPsec VPN', default='Sample IPsec VPN',
help='Name of the new VPN') help='Name of the new VPN')
parser.add_argument( optional_args.add_argument(
'--public-ip', '--public-ip',
default='10.10.10.10', default='10.10.10.10',
help='IP (IPv4) address or FQDN of the Peer') help='IP (IPv4) address or FQDN of the Peer')
parser.add_argument( optional_args.add_argument(
'--private-ip', '--private-ip',
default='192.168.10.10', default='192.168.10.10',
help='Local IP of the IPsec Site') help='Local IP of the IPsec Site')
parser.add_argument( optional_args.add_argument(
'--remote-networks', '--remote-networks',
default='192.168.20.10/24', default='192.168.20.10/24',
help='Peer subnets for which VPN is configured') help='Peer subnets for which VPN is configured')
parser.add_argument( optional_args.add_argument(
'--local-networks', '--local-networks',
default='192.168.30.10/24', default='192.168.30.10/24',
help='Local subnets for which VPN is configured') help='Local subnets for which VPN is configured')
parser.add_argument( optional_args.add_argument(
'--key', '--key',
default='00000000', default='00000000',
help='Pre Shared Key for the IPsec Site') help='Pre Shared Key for the IPsec Site')
parser.add_argument( optional_args.add_argument(
'-c',
'--cleardata', '--cleardata',
action='store_true', action='store_true',
help='Clean up after sample run') help='Clean up after sample run')

View File

@ -14,8 +14,7 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse from samples.vmc.helpers.sample_cli import parser, optional_args
from com.vmware.vmc.model_client import (L2Extension, SddcNetwork, from com.vmware.vmc.model_client import (L2Extension, SddcNetwork,
SddcNetworkAddressGroups, SddcNetworkAddressGroups,
SddcNetworkAddressGroup, SddcNetworkAddressGroup,
@ -34,37 +33,22 @@ class LogicalNetworkCrud(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser( optional_args.add_argument(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'-r',
'--refresh-token',
required=True,
help='VMware Cloud API refresh token')
parser.add_argument(
'-o', '--org-id', required=True, help='Organization identifier.')
parser.add_argument(
'-s', '--sddc-id', required=True, help='Sddc Identifier.')
parser.add_argument(
'--network-name', '--network-name',
default='Sample Logical Network', default='Sample Logical Network',
help='Name of the new logical network') help='Name of the new logical network')
parser.add_argument( optional_args.add_argument(
'--subnet', '--subnet',
default='192.168.100.1/24', default='192.168.100.1/24',
help='Logical network subnet') help='Logical network subnet')
parser.add_argument( optional_args.add_argument(
'--dhcp-range', '--dhcp-range',
default='192.168.100.2-192.168.100.254', default='192.168.100.2-192.168.100.254',
help='DHCP IP range for the logical network') help='DHCP IP range for the logical network')
parser.add_argument( optional_args.add_argument(
'-c',
'--cleardata', '--cleardata',
action='store_true', action='store_true',
help='Clean up after sample run') help='Clean up after sample run')

View File

@ -14,7 +14,7 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse from samples.vmc.helpers.sample_cli import parser, optional_args
from com.vmware.vmc.model_client import Nsxnatrule, NatRules from com.vmware.vmc.model_client import Nsxnatrule, NatRules
from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.vmc.client import create_vmc_client
@ -29,35 +29,20 @@ class NatRuleCrud(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser( optional_args.add_argument(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'-r',
'--refresh-token',
required=True,
help='VMware Cloud API refresh token')
parser.add_argument(
'-o', '--org-id', required=True, help='Organization identifier.')
parser.add_argument(
'-s', '--sddc-id', required=True, help='Sddc Identifier.')
parser.add_argument(
'--public-ip', help='Public IP range for the NAT rule') '--public-ip', help='Public IP range for the NAT rule')
parser.add_argument( optional_args.add_argument(
'--rule-description', '--rule-description',
default='Sample NAT rule', default='Sample NAT rule',
help='Description for the rule') help='Description for the rule')
parser.add_argument( optional_args.add_argument(
'--internal-ip', '--internal-ip',
default='192.168.200.1/24', default='192.168.200.1/24',
help='NAT rule subnet') help='NAT rule subnet')
parser.add_argument( optional_args.add_argument(
'-c',
'--cleardata', '--cleardata',
action='store_true', action='store_true',
help='Clean up after sample run') help='Clean up after sample run')

View File

@ -14,7 +14,7 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse from samples.vmc.helpers.sample_cli import parser, optional_args
from com.vmware.vmc.model_client import SddcAllocatePublicIpSpec from com.vmware.vmc.model_client import SddcAllocatePublicIpSpec
from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.vmc.client import create_vmc_client
@ -31,27 +31,12 @@ class PublicIPsCrud(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser( optional_args.add_argument(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'-r',
'--refresh-token',
required=True,
help='VMware Cloud API refresh token')
parser.add_argument(
'-o', '--org-id', required=True, help='Organization identifier.')
parser.add_argument(
'-s', '--sddc-id', required=True, help='Sddc Identifier.')
parser.add_argument(
'--notes', '--notes',
default='Sample public IP', default='Sample public IP',
help='Notes of the new public IP') help='Notes of the new public IP')
parser.add_argument( optional_args.add_argument(
'-c',
'--cleardata', '--cleardata',
action='store_true', action='store_true',
help='Clean up after sample run') help='Clean up after sample run')

View File

@ -38,10 +38,10 @@ class OperationsOnOrganizations(object):
def options(self): def options(self):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter) formatter_class=argparse.ArgumentDefaultsHelpFormatter)
required_args = parser.add_argument_group(
parser.add_argument( 'required arguments')
'-r', required_args.add_argument(
'--refresh-token', '--refresh_token',
required=True, required=True,
help='VMware Cloud API refresh token') help='VMware Cloud API refresh token')

View File

@ -15,10 +15,10 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse
import atexit import atexit
import requests import requests
from samples.vmc.helpers.sample_cli import parser, optional_args
from com.vmware.vmc.model_client import EsxConfig, ErrorResponse from com.vmware.vmc.model_client import EsxConfig, ErrorResponse
from com.vmware.vapi.std.errors_client import InvalidRequest from com.vmware.vapi.std.errors_client import InvalidRequest
from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.vmc.client import create_vmc_client
@ -43,22 +43,7 @@ class AddRemoveHosts(object):
self.interval_sec = None self.interval_sec = None
def options(self): def options(self):
parser = argparse.ArgumentParser( optional_args.add_argument('--interval-sec',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-r', '--refresh-token',
required=True,
help='VMware Cloud API refresh token')
parser.add_argument('-o', '--org-id',
required=True,
help='Organization identifier.')
parser.add_argument('-s', '--sddc-id',
required=True,
help='Sddc Identifier.')
parser.add_argument('-i', '--interval-sec',
default=60, default=60,
help='Task pulling interval in sec') help='Task pulling interval in sec')

View File

@ -15,11 +15,11 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
__vcenter_version__ = 'VMware Cloud on AWS' __vcenter_version__ = 'VMware Cloud on AWS'
import argparse
from com.vmware.vapi.std.errors_client import NotFound from com.vmware.vapi.std.errors_client import NotFound
from com.vmware.vmc.model_client import ErrorResponse from com.vmware.vmc.model_client import ErrorResponse
from six.moves.urllib import parse from six.moves.urllib import parse
from samples.vmc.helpers.sample_cli import parser
from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.vmc.client import create_vmc_client
from vmware.vapi.vsphere.client import create_vsphere_client from vmware.vapi.vsphere.client import create_vsphere_client
@ -35,18 +35,6 @@ class ConnectTovSphereWithDefaultCredentials(object):
""" """
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser()
parser.add_argument(
'-r',
'--refresh-token',
required=True,
help='VMware Cloud API refresh token')
parser.add_argument(
'-o', '--org-id', required=True, help='Organization identifier.')
parser.add_argument(
'-s', '--sddc-id', required=True, help='Sddc Identifier.')
args = parser.parse_args() args = parser.parse_args()
self.refresh_token = args.refresh_token self.refresh_token = args.refresh_token

View File

@ -41,28 +41,30 @@ class DeployOvfTemplate:
self.vm_name = 'deployed-vm-' + str(generate_random_uuid()) self.vm_name = 'deployed-vm-' + str(generate_random_uuid())
parser = sample_cli.build_arg_parser() parser = sample_cli.build_arg_parser()
parser.add_argument('--libitemname', required_args = parser.add_argument_group(
'required arguments')
required_args.add_argument('--libitemname',
required=True, required=True,
help='(Required) The name of the library item to deploy. ' help='The name of the library item to deploy. '
'The library item should contain an OVF package.') 'The library item should contain an OVF package.')
parser.add_argument('--vmname', parser.add_argument('--vmname',
default=self.vm_name, default=self.vm_name,
help='(Optional) The name of the Virtual Machine to be deployed. ' help='The name of the Virtual Machine to be deployed. '
'Default: "{}"'.format(self.vm_name)) 'Default: "{}"'.format(self.vm_name))
parser.add_argument('--resourcepoolname', parser.add_argument('--resourcepoolname',
default='Compute-ResourcePool', default='Compute-ResourcePool',
help='(Optional) The name of the resource pool to be used. ' help='The name of the resource pool to be used. '
'Default: "Compute-ResourcePool"') 'Default: "Compute-ResourcePool"')
parser.add_argument('--foldername', parser.add_argument('--foldername',
default='Workloads', default='Workloads',
help='(Optional) The name of the folder to be used. ' help='The name of the folder to be used. '
'Default: "Workloads"') 'Default: "Workloads"')
parser.add_argument('--opaquenetworkname', parser.add_argument('--opaquenetworkname',
help='(Optional) The name of the opaque network to be added ' help='The name of the opaque network to be added '
'to the deployed vm') 'to the deployed vm')
args = sample_util.process_cli_args(parser.parse_args()) args = sample_util.process_cli_args(parser.parse_args())

View File

@ -14,14 +14,13 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse
import os import os
from random import randrange from random import randrange
import argparse
from com.vmware.vapi.std.errors_client import InvalidRequest from com.vmware.vapi.std.errors_client import InvalidRequest
from com.vmware.vmc.model_client import AwsSddcConfig, ErrorResponse, AccountLinkSddcConfig, SddcConfig from com.vmware.vmc.model_client import AwsSddcConfig, ErrorResponse, AccountLinkSddcConfig, SddcConfig
from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.vmc.client import create_vmc_client
from samples.vmc.helpers.vmc_task_helper import wait_for_task from samples.vmc.helpers.vmc_task_helper import wait_for_task
@ -36,49 +35,49 @@ class CreateDeleteSDDC(object):
def __init__(self): def __init__(self):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( required_args = parser.add_argument_group(
'-r', 'required arguments')
'--refresh-token', optional_args = parser.add_argument_group(
'optional arguments')
required_args.add_argument(
'--refresh_token',
required=True, required=True,
help='VMware Cloud API refresh token') help='Refresh token obtained from CSP')
parser.add_argument( required_args.add_argument(
'-o', '--org-id', required=True, help='Organization identifier.') '--org_id',
required=True,
help='Organization identifier.')
parser.add_argument( optional_args.add_argument(
'-sn',
'--sddc-name', '--sddc-name',
help="Name of the SDDC to be created. " help="Name of the SDDC to be created. "
"Default is 'Sample SDDC xx'") "Default is 'Sample SDDC xx'")
parser.add_argument('--region', default='US_WEST_2', help='AWS Region') optional_args.add_argument('--region', default='US_WEST_2', help='AWS Region')
parser.add_argument( optional_args.add_argument(
'-i',
'--interval-sec', '--interval-sec',
default=60, default=60,
help='Task pulling interval in sec') help='Task pulling interval in sec')
parser.add_argument( optional_args.add_argument(
'-ls',
'--listsddc', '--listsddc',
action='store_true', action='store_true',
help='List SDDCs in the specified Org') help='List SDDCs in the specified Org')
parser.add_argument( optional_args.add_argument(
'-cs',
'--createsddc', '--createsddc',
action='store_true', action='store_true',
help='Create an SDDC in the specified Org') help='Create an SDDC in the specified Org')
parser.add_argument( optional_args.add_argument(
'-ds',
'--deletesddc', '--deletesddc',
action='store_true', action='store_true',
help='Deletes the SDDC in the specified Org ') help='Deletes the SDDC in the specified Org ')
parser.add_argument( optional_args.add_argument(
'-c',
'--cleardata', '--cleardata',
action='store_true', action='store_true',
help='Clean up after sample run') help='Clean up after sample run')

View File

@ -14,7 +14,6 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse import argparse
from com.vmware.vmc.model_client import Task from com.vmware.vmc.model_client import Task
from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.vmc.client import create_vmc_client
@ -27,19 +26,25 @@ Sample Prerequisites:
""" """
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter) formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh-token', required_args = parser.add_argument_group(
required=True, 'required arguments')
help='VMware Cloud API refresh token')
parser.add_argument('--org-id', required_args.add_argument(
required=True, '--refresh_token',
help='Organization identifier.') required=True,
help='Refresh token obtained from CSP')
parser.add_argument('--task-id', required_args.add_argument(
required=True, '--org-id',
help='Task ID to be cancelled') required=True,
help='Organization identifier.')
required_args.add_argument(
'--task-id',
required=True,
help='Task ID to be cancelled')
args = parser.parse_args() args = parser.parse_args()

View File

@ -14,7 +14,6 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse import argparse
from com.vmware.vmc.model_client import Task from com.vmware.vmc.model_client import Task
from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.vmc.client import create_vmc_client
@ -28,19 +27,25 @@ Sample Prerequisites:
accepted = [Task.STATUS_STARTED, Task.STATUS_CANCELING, Task.STATUS_FINISHED, accepted = [Task.STATUS_STARTED, Task.STATUS_CANCELING, Task.STATUS_FINISHED,
Task.STATUS_FAILED, Task.STATUS_CANCELED] Task.STATUS_FAILED, Task.STATUS_CANCELED]
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh-token', required_args = parser.add_argument_group(
required=True, 'required arguments')
help='VMware Cloud API refresh token')
parser.add_argument('--org-id', required_args.add_argument(
required=True, '--refresh_token',
help='Organization identifier.') required=True,
help='Refresh token obtained from CSP')
required_args.add_argument(
'--org-id',
required=True,
help='Organization identifier.')
parser.add_argument('--task-status', required_args.add_argument(
help='Task status to filter. Possible values are: {} \ '--task-status',
Show all tasks if no value is passed'.format(accepted)) help='Task status to filter. Possible values are: {} \
Show all tasks if no value is passed'.format(accepted))
args = parser.parse_args() args = parser.parse_args()

View File

@ -14,7 +14,6 @@
__author__ = 'VMware, Inc.' __author__ = 'VMware, Inc.'
import argparse import argparse
from com.vmware.vmc.model_client import Task from com.vmware.vmc.model_client import Task
from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.vmc.client import create_vmc_client
@ -28,19 +27,28 @@ Sample Prerequisites:
accepted = [Task.STATUS_STARTED, Task.STATUS_CANCELING, Task.STATUS_FINISHED, accepted = [Task.STATUS_STARTED, Task.STATUS_CANCELING, Task.STATUS_FINISHED,
Task.STATUS_FAILED, Task.STATUS_CANCELED] Task.STATUS_FAILED, Task.STATUS_CANCELED]
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--refresh-token', required_args = parser.add_argument_group(
required=True, 'required arguments')
help='VMware Cloud API refresh token') optional_args = parser.add_argument_group(
'optional arguments')
parser.add_argument('--org-id', required_args.add_argument(
required=True, '--refresh_token',
help='Organization identifier.') required=True,
help='Refresh token obtained from CSP')
parser.add_argument('--task-status', required_args.add_argument(
help='Task status to filter. Possible values are: {} \ '--org-id',
Show all tasks if no value is passed'.format(accepted)) required=True,
help='Organization identifier.')
optional_args.add_argument(
'--task-status',
help='Task status to filter. Possible values are: {} \
Show all tasks if no value is passed'.format(accepted))
args = parser.parse_args() args = parser.parse_args()

View File

@ -31,16 +31,21 @@ def build_arg_parser():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Standard Arguments for talking to vCenter') description='Standard Arguments for talking to vCenter')
parser.add_argument('-s', '--server', required_args = parser.add_argument_group(
'required arguments')
required_args.add_argument('-s', '--server',
action='store', action='store',
required=True,
help='vSphere service IP to connect to') help='vSphere service IP to connect to')
parser.add_argument('-u', '--username', required_args.add_argument('-u', '--username',
action='store', action='store',
required=True,
help='Username to use when connecting to vc') help='Username to use when connecting to vc')
parser.add_argument('-p', '--password', required_args.add_argument('-p', '--password',
action='store', action='store',
required=True,
help='Password to use when connecting to vc') help='Password to use when connecting to vc')
parser.add_argument('-c', '--cleardata', parser.add_argument('-c', '--cleardata',