Skip to content

Commit 1884e64

Browse files
author
Tianhao He
committed
Add get sddc id by name when deleting sddc
Don't print region as some testing sddcs don't have region info.
1 parent 8799c5d commit 1884e64

File tree

2 files changed

+79
-4
lines changed

2 files changed

+79
-4
lines changed

samples/vmc/sddc/sddc_crud.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
"""
33
* *******************************************************
4-
* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
4+
* Copyright (c) VMware, Inc. 2017-2019. All Rights Reserved.
55
* SPDX-License-Identifier: MIT
66
* *******************************************************
77
*
@@ -118,7 +118,7 @@ def create_sddc(self):
118118
account_ids = self.vmc_client.orgs.account_link.ConnectedAccounts.get(
119119
self.org_id)
120120

121-
if len(account_ids) > 0 :
121+
if len(account_ids) > 0:
122122
account_id = account_ids[0].id
123123

124124
vpc_map = self.vmc_client.orgs.account_link.CompatibleSubnets.get(
@@ -161,6 +161,15 @@ def create_sddc(self):
161161
self.print_output([sddc])
162162

163163
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+
164173
print('\n# Example: Delete SDDC {} from org {}'.format(
165174
self.sddc_id, self.org_id))
166175

@@ -192,8 +201,7 @@ def list_sddc(self):
192201

193202
def print_output(self, sddcs):
194203
for sddc in sddcs:
195-
print('ID: {}, Name: {}, AWS Region: {}'.format(
196-
sddc.id, sddc.name, sddc.resource_config.region))
204+
print('ID: {}, Name: {}'.format(sddc.id, sddc.name))
197205

198206
def get_subnet_id(self, vpc_map):
199207
for v in vpc_map.values():

samples/vmc/tasks/list_tasks_stg.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
16+
import argparse
17+
18+
from com.vmware.vmc.model_client import Task
19+
from vmware.vapi.vmc.client import create_vmc_client
20+
21+
"""
22+
Demonstrates how to list tasks with given status
23+
24+
Sample Prerequisites:
25+
- VMware Cloud on AWS console API access
26+
"""
27+
28+
accepted = [Task.STATUS_STARTED, Task.STATUS_CANCELING, Task.STATUS_FINISHED,
29+
Task.STATUS_FAILED, Task.STATUS_CANCELED]
30+
31+
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
32+
33+
parser.add_argument('--refresh-token',
34+
required=True,
35+
help='VMware Cloud API refresh token')
36+
37+
parser.add_argument('--org-id',
38+
required=True,
39+
help='Organization identifier.')
40+
41+
parser.add_argument('--task-status',
42+
help='Task status to filter. Possible values are: {} \
43+
Show all tasks if no value is passed'.format(accepted))
44+
45+
args = parser.parse_args()
46+
47+
vmc_client = create_vmc_client(args.refresh_token)
48+
49+
tasks = []
50+
51+
if args.task_status:
52+
status = args.task_status.upper()
53+
54+
if status not in accepted:
55+
raise ValueError('Status "{}" is invalid, accept values are {}'.
56+
format(args.task_status, accepted))
57+
58+
tasks = vmc_client.orgs.Tasks.list(
59+
org=args.org_id, filter="(status eq '{}')".format(status))
60+
61+
print('# List all "{}" tasks:\n'.format(status))
62+
else:
63+
tasks = vmc_client.orgs.Tasks.list(org=args.org_id)
64+
print('# List all tasks:\n')
65+
66+
for task in tasks:
67+
print('{}\n'.format(task))

0 commit comments

Comments
 (0)