From e1093196cca2c8984bf0334d872a92dcd1c625a6 Mon Sep 17 00:00:00 2001 From: Jobin George Date: Thu, 14 Nov 2019 07:52:06 +0530 Subject: [PATCH] Modified sddc_crud sample to fix multiple issues. (#196) * Modified sddc_crud sample to fix multiple issues. Signed-off-by: Jobin George * Update sddc_crud.py * Modified sddc_crud sample to fix multiple issues. Signed-off-by: Jobin George Update sddc_crud.py Signed-off-by: Jobin George --- samples/vmc/sddc/sddc_crud.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/samples/vmc/sddc/sddc_crud.py b/samples/vmc/sddc/sddc_crud.py index d7f3ad88..f96f1956 100644 --- a/samples/vmc/sddc/sddc_crud.py +++ b/samples/vmc/sddc/sddc_crud.py @@ -41,27 +41,35 @@ class CreateDeleteSDDC(object): 'optional arguments') required_args.add_argument( - '--refresh_token', + '--refresh-token', required=True, help='Refresh token obtained from CSP') required_args.add_argument( - '--org_id', + '--org-id', required=True, help='Organization identifier.') optional_args.add_argument( '--sddc-name', - help="Name of the SDDC to be created. " + help="Name of the SDDC to be created." "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( '--interval-sec', default=60, 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( '--listsddc', action='store_true', @@ -95,6 +103,7 @@ class CreateDeleteSDDC(object): self.sddc_name = args.sddc_name or 'Sample SDDC {}'.format( randrange(100)) self.interval_sec = int(args.interval_sec) + self.num_hosts = int(args.num_hosts) # Login to VMware Cloud on AWS self.vmc_client = create_vmc_client(self.refresh_token) @@ -121,7 +130,7 @@ class CreateDeleteSDDC(object): account_id = account_ids[0].id 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) if not customer_subnet_id: @@ -137,7 +146,7 @@ class CreateDeleteSDDC(object): name=self.sddc_name, account_link_sddc_config=[account_linking_config] if account_linking_config else None, provider=os.environ.get('VMC_PROVIDER', SddcConfig.PROVIDER_AWS), - num_hosts=4, + num_hosts=self.num_hosts, deployment_type=SddcConfig.DEPLOYMENT_TYPE_SINGLEAZ) try: @@ -167,7 +176,7 @@ class CreateDeleteSDDC(object): self.sddc_id = sddc.id break 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( self.sddc_id, self.org_id)) @@ -205,7 +214,9 @@ class CreateDeleteSDDC(object): def get_subnet_id(self, vpc_map): for v in vpc_map.values(): 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