Skip to content

Commit 8799c5d

Browse files
author
Tianhao He
committed
Don't pass account link sddc config when no connected account available
1 parent c60d430 commit 8799c5d

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

samples/vmc/sddc/sddc_crud.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,27 +112,33 @@ def create_sddc(self):
112112
print('\n# Example: Create a SDDC ({}) in org {}:'.format(
113113
self.sddc_name, self.org_id))
114114

115-
account_id = self.vmc_client.orgs.account_link.ConnectedAccounts.get(
116-
self.org_id)[0].id
115+
account_linking_config = None
117116

118-
vpc_map = self.vmc_client.orgs.account_link.CompatibleSubnets.get(
119-
org=self.org_id, linked_account_id=account_id).vpc_map
117+
# Get connected accounts if any
118+
account_ids = self.vmc_client.orgs.account_link.ConnectedAccounts.get(
119+
self.org_id)
120120

121-
customer_subnet_id = self.get_subnet_id(vpc_map)
122-
if not customer_subnet_id:
123-
raise ValueError('No available subnet for region {}'.format(
124-
self.region))
121+
if len(account_ids) > 0 :
122+
account_id = account_ids[0].id
123+
124+
vpc_map = self.vmc_client.orgs.account_link.CompatibleSubnets.get(
125+
org=self.org_id, linked_account_id=account_id).vpc_map
126+
127+
customer_subnet_id = self.get_subnet_id(vpc_map)
128+
if not customer_subnet_id:
129+
raise ValueError('No available subnet for region {}'.format(
130+
self.region))
131+
132+
account_linking_config = AccountLinkSddcConfig(
133+
customer_subnet_ids=[customer_subnet_id],
134+
connected_account_id=account_id)
125135

126136
sddc_config = AwsSddcConfig(
127137
region=self.region,
128138
name=self.sddc_name,
129-
account_link_sddc_config=[
130-
AccountLinkSddcConfig(
131-
customer_subnet_ids=[customer_subnet_id],
132-
connected_account_id=account_id)
133-
],
139+
account_link_sddc_config=[account_linking_config] if account_linking_config else None,
134140
provider=os.environ.get('VMC_PROVIDER', SddcConfig.PROVIDER_AWS),
135-
num_hosts=1,
141+
num_hosts=4,
136142
deployment_type=SddcConfig.DEPLOYMENT_TYPE_SINGLEAZ)
137143

138144
try:

0 commit comments

Comments
 (0)