mirror of
https://github.com/vmware/vsphere-automation-sdk-python.git
synced 2024-11-22 01:39:58 -05:00
Modified sddc_crud sample to fix multiple issues. (#196)
* Modified sddc_crud sample to fix multiple issues. Signed-off-by: Jobin George<jgeorge@vmware.com> * Update sddc_crud.py * Modified sddc_crud sample to fix multiple issues. Signed-off-by: Jobin George<jgeorge@vmware.com> Update sddc_crud.py Signed-off-by: Jobin George<jgeorge@vmware.com>
This commit is contained in:
parent
d4b88d2ed6
commit
e1093196cc
@ -41,27 +41,35 @@ class CreateDeleteSDDC(object):
|
|||||||
'optional arguments')
|
'optional arguments')
|
||||||
|
|
||||||
required_args.add_argument(
|
required_args.add_argument(
|
||||||
'--refresh_token',
|
'--refresh-token',
|
||||||
required=True,
|
required=True,
|
||||||
help='Refresh token obtained from CSP')
|
help='Refresh token obtained from CSP')
|
||||||
|
|
||||||
required_args.add_argument(
|
required_args.add_argument(
|
||||||
'--org_id',
|
'--org-id',
|
||||||
required=True,
|
required=True,
|
||||||
help='Organization identifier.')
|
help='Organization identifier.')
|
||||||
|
|
||||||
optional_args.add_argument(
|
optional_args.add_argument(
|
||||||
'--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'")
|
||||||
|
|
||||||
optional_args.add_argument('--region', default='US_WEST_2', help='AWS Region')
|
optional_args.add_argument(
|
||||||
|
'--region',
|
||||||
|
default='US_EAST_1',
|
||||||
|
help='AWS Region')
|
||||||
|
|
||||||
optional_args.add_argument(
|
optional_args.add_argument(
|
||||||
'--interval-sec',
|
'--interval-sec',
|
||||||
default=60,
|
default=60,
|
||||||
help='Task pulling interval in sec')
|
help='Task pulling interval in sec')
|
||||||
|
|
||||||
|
optional_args.add_argument(
|
||||||
|
'--num-hosts',
|
||||||
|
default=3,
|
||||||
|
help='Number of Hosts for the SDDC Deployment')
|
||||||
|
|
||||||
optional_args.add_argument(
|
optional_args.add_argument(
|
||||||
'--listsddc',
|
'--listsddc',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -95,6 +103,7 @@ class CreateDeleteSDDC(object):
|
|||||||
self.sddc_name = args.sddc_name or 'Sample SDDC {}'.format(
|
self.sddc_name = args.sddc_name or 'Sample SDDC {}'.format(
|
||||||
randrange(100))
|
randrange(100))
|
||||||
self.interval_sec = int(args.interval_sec)
|
self.interval_sec = int(args.interval_sec)
|
||||||
|
self.num_hosts = int(args.num_hosts)
|
||||||
|
|
||||||
# Login to VMware Cloud on AWS
|
# Login to VMware Cloud on AWS
|
||||||
self.vmc_client = create_vmc_client(self.refresh_token)
|
self.vmc_client = create_vmc_client(self.refresh_token)
|
||||||
@ -121,7 +130,7 @@ class CreateDeleteSDDC(object):
|
|||||||
account_id = account_ids[0].id
|
account_id = account_ids[0].id
|
||||||
|
|
||||||
vpc_map = self.vmc_client.orgs.account_link.CompatibleSubnets.get(
|
vpc_map = self.vmc_client.orgs.account_link.CompatibleSubnets.get(
|
||||||
org=self.org_id, linked_account_id=account_id).vpc_map
|
org=self.org_id, linked_account_id=account_id, region=self.region).vpc_map
|
||||||
|
|
||||||
customer_subnet_id = self.get_subnet_id(vpc_map)
|
customer_subnet_id = self.get_subnet_id(vpc_map)
|
||||||
if not customer_subnet_id:
|
if not customer_subnet_id:
|
||||||
@ -137,7 +146,7 @@ class CreateDeleteSDDC(object):
|
|||||||
name=self.sddc_name,
|
name=self.sddc_name,
|
||||||
account_link_sddc_config=[account_linking_config] if account_linking_config else None,
|
account_link_sddc_config=[account_linking_config] if account_linking_config else None,
|
||||||
provider=os.environ.get('VMC_PROVIDER', SddcConfig.PROVIDER_AWS),
|
provider=os.environ.get('VMC_PROVIDER', SddcConfig.PROVIDER_AWS),
|
||||||
num_hosts=4,
|
num_hosts=self.num_hosts,
|
||||||
deployment_type=SddcConfig.DEPLOYMENT_TYPE_SINGLEAZ)
|
deployment_type=SddcConfig.DEPLOYMENT_TYPE_SINGLEAZ)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -167,7 +176,7 @@ class CreateDeleteSDDC(object):
|
|||||||
self.sddc_id = sddc.id
|
self.sddc_id = sddc.id
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise ValueError('Cannot find sddc "{}"'.format(sddc_name))
|
raise ValueError('Cannot find sddc "{}"'.format(self.sddc_name))
|
||||||
|
|
||||||
print('\n# Example: Delete SDDC {} from org {}'.format(
|
print('\n# Example: Delete SDDC {} from org {}'.format(
|
||||||
self.sddc_id, self.org_id))
|
self.sddc_id, self.org_id))
|
||||||
@ -205,7 +214,9 @@ class CreateDeleteSDDC(object):
|
|||||||
def get_subnet_id(self, vpc_map):
|
def get_subnet_id(self, vpc_map):
|
||||||
for v in vpc_map.values():
|
for v in vpc_map.values():
|
||||||
for subnet in v.subnets:
|
for subnet in v.subnets:
|
||||||
if subnet.region_name.lower() == self.region.lower():
|
# Compare the AWS SDDC Region with the compatible subnet region
|
||||||
|
if subnet.region_name.lower() == self.region.replace("_", "-").lower() \
|
||||||
|
and subnet.compatible:
|
||||||
return subnet.subnet_id
|
return subnet.subnet_id
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user