Skip to content

Commit 6195ed7

Browse files
author
Tianhao He
committed
add list vmc task sample
Signed-off-by: Tianhao He <[email protected]>
1 parent e610a71 commit 6195ed7

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

samples/vmc/networks_nsxt/hello_world.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ def main():
6464
auth_example = AuthExample()
6565
auth_example.get_domains()
6666

67+
6768
if __name__ == '__main__':
6869
main()

samples/vmc/tasks/list_tasks.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)