Skip to content

Commit 2d2f32b

Browse files
anusha94tianhao64
authored andcommitted
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 <[email protected]>
1 parent 206ca3d commit 2d2f32b

27 files changed

+204
-415
lines changed

samples/vmc/helpers/sample_cli.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
* *******************************************************
3+
* Copyright (c) VMware, Inc. 2019. All Rights Reserved.
4+
* SPDX-License-Identifier: MIT
5+
* *******************************************************
6+
*
7+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12+
"""
13+
14+
__author__ = 'VMware, Inc.'
15+
__copyright__ = 'Copyright 2019 VMware, Inc. All rights reserved.'
16+
17+
import argparse
18+
19+
"""
20+
Builds a standard argument parser with required and optional argument groups
21+
22+
Most of the VMC samples require these three standard required arguments.
23+
If any of these arguments are not required, then build your own parser
24+
25+
--refresh_token
26+
--org_id
27+
--sddc_id
28+
29+
"""
30+
parser = argparse.ArgumentParser()
31+
32+
required_args = parser.add_argument_group(
33+
'required arguments')
34+
optional_args = parser.add_argument_group(
35+
'optional arguments')
36+
37+
required_args.add_argument(
38+
'--refresh_token',
39+
required=True,
40+
help='Refresh token obtained from CSP')
41+
required_args.add_argument(
42+
'--org_id',
43+
required=True,
44+
help='Orgization ID')
45+
required_args.add_argument(
46+
'--sddc_id',
47+
required=True,
48+
help='SDDC ID')

samples/vmc/networks_nsxt/cgw_firewall_crud.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
__author__ = 'VMware, Inc.'
1717
__vcenter_version__ = '6.8.0+'
1818

19-
import argparse
2019
import requests
20+
from samples.vmc.helpers.sample_cli import parser
2121
from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
2222
from com.vmware.nsx_policy.model_client import IPAddressExpression
2323
from com.vmware.nsx_policy.model_client import Group
@@ -36,21 +36,6 @@ class NSXPolicyCGWFirewall(object):
3636
"""
3737

3838
def __init__(self):
39-
parser = argparse.ArgumentParser(
40-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
41-
42-
parser.add_argument('--refresh_token',
43-
required=True,
44-
help='Refresh token obtained from CSP')
45-
46-
parser.add_argument('--org_id',
47-
required=True,
48-
help='Orgization ID')
49-
50-
parser.add_argument('--sddc_id',
51-
required=True,
52-
help='Sddc ID')
53-
5439
args = parser.parse_args()
5540

5641
self.nsx_client = create_nsx_policy_client_for_vmc(

samples/vmc/networks_nsxt/dfw_firewall_crud.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
__author__ = 'VMware, Inc.'
1717
__vcenter_version__ = '6.8.0+'
1818

19-
import argparse
2019
import requests
20+
from samples.vmc.helpers.sample_cli import parser
2121
from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
2222
from com.vmware.nsx_policy.model_client import IPAddressExpression
2323
from com.vmware.nsx_policy.model_client import Group
@@ -38,21 +38,6 @@ class NSXPolicyDFWFirewall(object):
3838
"""
3939

4040
def __init__(self):
41-
parser = argparse.ArgumentParser(
42-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
43-
44-
parser.add_argument('--refresh_token',
45-
required=True,
46-
help='Refresh token obtained from CSP')
47-
48-
parser.add_argument('--org_id',
49-
required=True,
50-
help='Orgization ID')
51-
52-
parser.add_argument('--sddc_id',
53-
required=True,
54-
help='Sddc ID')
55-
5641
args = parser.parse_args()
5742

5843
self.nsx_client = create_nsx_policy_client_for_vmc(

samples/vmc/networks_nsxt/hello_world.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515

1616
__author__ = 'VMware, Inc.'
1717

18-
import argparse
1918
import pprint
20-
19+
from samples.vmc.helpers.sample_cli import parser
2120
from com.vmware.nsx_policy_client_for_vmc import (
2221
create_nsx_policy_client_for_vmc)
2322

@@ -33,20 +32,6 @@ class AuthExample(object):
3332
"""
3433

3534
def __init__(self):
36-
parser = argparse.ArgumentParser(
37-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
38-
parser.add_argument('-r', '--refresh-token',
39-
required=True,
40-
help='VMware Cloud API refresh token')
41-
42-
parser.add_argument('-o', '--org-id',
43-
required=True,
44-
help='Organization identifier.')
45-
46-
parser.add_argument('-s', '--sddc-id',
47-
required=True,
48-
help='Sddc Identifier.')
49-
5035
args = parser.parse_args()
5136

5237
self.org_id = args.org_id

samples/vmc/networks_nsxt/l3_vpn_crud.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
__author__ = 'VMware, Inc.'
1717

18-
import argparse
18+
from samples.vmc.helpers.sample_cli import parser, required_args
1919
from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
2020
from vmware.vapi.bindings.struct import PrettyPrinter as NsxPrettyPrinter
2121
from com.vmware.nsx_policy.model_client import ApiError
@@ -39,26 +39,11 @@ class NSXPolicyL3VPN(object):
3939
"""
4040

4141
def __init__(self):
42-
parser = argparse.ArgumentParser(
43-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
44-
45-
parser.add_argument('--refresh_token',
46-
required=True,
47-
help='Refresh token obtained from CSP')
48-
49-
parser.add_argument('--org_id',
50-
required=True,
51-
help='Orgization ID')
52-
53-
parser.add_argument('--sddc_id',
54-
required=True,
55-
help='Sddc ID')
56-
57-
parser.add_argument('--remote_endpoint_public_ip',
42+
required_args.add_argument('--remote_endpoint_public_ip',
5843
required=True,
5944
help='L3 VPN Remote end point\'s public ip')
6045

61-
parser.add_argument('--passphrase',
46+
required_args.add_argument('--passphrase',
6247
required=True,
6348
help='Passphrase used for VPN')
6449

samples/vmc/networks_nsxt/nat_crud.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
__author__ = 'VMware, Inc.'
1717
__vcenter_version__ = '6.8.1+'
1818

19-
import argparse
2019
import requests
20+
21+
from samples.vmc.helpers.sample_cli import parser
2122
from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
2223
from com.vmware.nsx_vmc_app_client_for_vmc import create_nsx_vmc_app_client_for_vmc
2324
from com.vmware.nsx_vmc_app.model_client import PublicIp
@@ -36,21 +37,6 @@ class NSXPolicyNAT(object):
3637
"""
3738

3839
def __init__(self):
39-
parser = argparse.ArgumentParser(
40-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
41-
42-
parser.add_argument('--refresh_token',
43-
required=True,
44-
help='Refresh token obtained from CSP')
45-
46-
parser.add_argument('--org_id',
47-
required=True,
48-
help='Orgization ID')
49-
50-
parser.add_argument('--sddc_id',
51-
required=True,
52-
help='Sddc ID')
53-
5440
args = parser.parse_args()
5541

5642
self.nsx_client = create_nsx_policy_client_for_vmc(

samples/vmc/networks_nsxt/security_group_create.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
__author__ = 'VMware, Inc'
1616
__vcenter_version__ = 'VMware Cloud on AWS'
1717

18-
import argparse
1918
import random
2019

2120
import requests
21+
22+
from samples.vmc.helpers.sample_cli import parser, required_args, optional_args
2223
from com.vmware.nsx_policy.infra_client import Domains
2324
from com.vmware.nsx_policy.model_client import (Expression, Group,
2425
IPAddressExpression)
@@ -35,34 +36,19 @@
3536
Sample Prerequisites:
3637
- SDDC deployed in VMware Cloud on AWS
3738
"""
38-
parser = argparse.ArgumentParser(
39-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
40-
41-
parser.add_argument('--refresh_token',
42-
required=True,
43-
help='Refresh token obtained from CSP')
44-
45-
parser.add_argument('--org_id',
46-
required=True,
47-
help='Orgization ID')
48-
49-
parser.add_argument('--sddc_id',
50-
required=True,
51-
help='Sddc ID')
52-
53-
parser.add_argument('--gateway_type',
39+
optional_args.add_argument('--gateway_type',
5440
default='mgw',
5541
help='Gateway type. Either mgw or cgw')
5642

57-
parser.add_argument('--name',
43+
required_args.add_argument('--name',
5844
required=True,
5945
help='Name of the security group to be created')
6046

61-
parser.add_argument('--ip_address',
47+
optional_args.add_argument('--ip_address',
6248
default='172.31.0.0/24',
6349
help='IP address for the expression')
6450

65-
parser.add_argument('--group_id',
51+
optional_args.add_argument('--group_id',
6652
help='ID of the group. A random ID will be used by default')
6753

6854
args = parser.parse_args()

samples/vmc/networks_nsxt/security_group_delete.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
__author__ = 'VMware, Inc'
1717
__vcenter_version__ = 'VMware Cloud on AWS'
1818

19-
import argparse
2019
import random
2120

2221
import requests
22+
from samples.vmc.helpers.sample_cli import parser, optional_args
2323
from com.vmware.nsx_policy.infra_client import Domains
2424
from com.vmware.nsx_policy.model_client import (Expression, Group,
2525
IPAddressExpression)
@@ -39,26 +39,11 @@
3939
- SDDC deployed in VMware Cloud on AWS
4040
- A NSX-T security group
4141
"""
42-
parser = argparse.ArgumentParser(
43-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
44-
45-
parser.add_argument('--refresh_token',
46-
required=True,
47-
help='Refresh token obtained from CSP')
48-
49-
parser.add_argument('--org_id',
50-
required=True,
51-
help='Orgization ID')
52-
53-
parser.add_argument('--sddc_id',
54-
required=True,
55-
help='Sddc ID')
56-
57-
parser.add_argument('--gateway_type',
42+
optional_args.add_argument('--gateway_type',
5843
default='mgw',
5944
help='Gateway type. Either mgw or cgw')
6045

61-
parser.add_argument('--group_id',
46+
optional_args.add_argument('--group_id',
6247
help='ID of the group to be deleted')
6348

6449
args = parser.parse_args()

samples/vmc/networks_nsxt/security_group_list.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
__vcenter_version__ = 'VMware Cloud on AWS'
1818

1919
import requests
20-
import argparse
2120

21+
from samples.vmc.helpers.sample_cli import parser, optional_args
2222
from com.vmware.nsx_policy.infra_client import Domains
2323
from com.vmware.nsx_policy_client_for_vmc import create_nsx_policy_client_for_vmc
2424
from vmware.vapi.bindings.struct import PrettyPrinter
@@ -34,22 +34,7 @@
3434
Sample Prerequisites:
3535
- SDDC deployed in VMware Cloud on AWS
3636
"""
37-
parser = argparse.ArgumentParser(
38-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
39-
40-
parser.add_argument('--refresh_token',
41-
required=True,
42-
help='Refresh token obtained from CSP')
43-
44-
parser.add_argument('--org_id',
45-
required=True,
46-
help='Orgization ID')
47-
48-
parser.add_argument('--sddc_id',
49-
required=True,
50-
help='Sddc ID')
51-
52-
parser.add_argument('--gateway_type',
37+
optional_args.add_argument('--gateway_type',
5338
default='mgw',
5439
help='Gateway type. Either mgw or cgw')
5540

samples/vmc/networks_nsxt/security_group_update.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
__author__ = 'VMware, Inc'
1717
__vcenter_version__ = 'VMware Cloud on AWS'
1818

19-
import argparse
2019
import random
2120

2221
import requests
22+
from samples.vmc.helpers.sample_cli import parser, required_args, optional_args
2323
from com.vmware.nsx_policy.infra_client import Domains
2424
from com.vmware.nsx_policy.model_client import (Expression, Group,
2525
IPAddressExpression)
@@ -40,29 +40,14 @@
4040
- SDDC deployed in VMware Cloud on AWS
4141
- A NSX-T security group
4242
"""
43-
parser = argparse.ArgumentParser(
44-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
45-
46-
parser.add_argument('--refresh_token',
47-
required=True,
48-
help='Refresh token obtained from CSP')
49-
50-
parser.add_argument('--org_id',
51-
required=True,
52-
help='Orgization ID')
53-
54-
parser.add_argument('--sddc_id',
55-
required=True,
56-
help='Sddc ID')
57-
58-
parser.add_argument('--gateway_type',
43+
optional_args.add_argument('--gateway_type',
5944
default='mgw',
6045
help='Gateway type. Either mgw or cgw')
6146

62-
parser.add_argument('--group_id',
47+
optional_args.add_argument('--group_id',
6348
help='ID of the group to be updated')
6449

65-
parser.add_argument('--name',
50+
required_args.add_argument('--name',
6651
required=True,
6752
help='New name of the security group to be updated')
6853

0 commit comments

Comments
 (0)