1
1
#!/usr/bin/env python
2
2
"""
3
3
* *******************************************************
4
- * Copyright (c) VMware, Inc. 2017. All Rights Reserved.
4
+ * Copyright (c) VMware, Inc. 2017-2019 . All Rights Reserved.
5
5
* SPDX-License-Identifier: MIT
6
6
* *******************************************************
7
7
*
@@ -112,27 +112,33 @@ def create_sddc(self):
112
112
print ('\n # Example: Create a SDDC ({}) in org {}:' .format (
113
113
self .sddc_name , self .org_id ))
114
114
115
- account_id = self .vmc_client .orgs .account_link .ConnectedAccounts .get (
116
- self .org_id )[0 ].id
115
+ account_linking_config = None
117
116
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 )
120
120
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 )
125
135
126
136
sddc_config = AwsSddcConfig (
127
137
region = self .region ,
128
138
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 ,
134
140
provider = os .environ .get ('VMC_PROVIDER' , SddcConfig .PROVIDER_AWS ),
135
- num_hosts = 1 ,
141
+ num_hosts = 4 ,
136
142
deployment_type = SddcConfig .DEPLOYMENT_TYPE_SINGLEAZ )
137
143
138
144
try :
@@ -155,6 +161,15 @@ def create_sddc(self):
155
161
self .print_output ([sddc ])
156
162
157
163
def delete_sddc (self ):
164
+ # Get SDDC ID by name
165
+ sddcs = self .vmc_client .orgs .Sddcs .list (self .org_id )
166
+ for sddc in sddcs :
167
+ if sddc .name == self .sddc_name :
168
+ self .sddc_id = sddc .id
169
+ break
170
+ else :
171
+ raise ValueError ('Cannot find sddc "{}"' .format (sddc_name ))
172
+
158
173
print ('\n # Example: Delete SDDC {} from org {}' .format (
159
174
self .sddc_id , self .org_id ))
160
175
@@ -186,8 +201,7 @@ def list_sddc(self):
186
201
187
202
def print_output (self , sddcs ):
188
203
for sddc in sddcs :
189
- print ('ID: {}, Name: {}, AWS Region: {}' .format (
190
- sddc .id , sddc .name , sddc .resource_config .region ))
204
+ print ('ID: {}, Name: {}' .format (sddc .id , sddc .name ))
191
205
192
206
def get_subnet_id (self , vpc_map ):
193
207
for v in vpc_map .values ():
0 commit comments