-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tianhao He <het@vmware.com>
- Loading branch information
Tianhao He
committed
Mar 14, 2019
1 parent
e610a71
commit 6195ed7
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,5 +64,6 @@ def main(): | |
auth_example = AuthExample() | ||
auth_example.get_domains() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
* ******************************************************* | ||
* Copyright (c) VMware, Inc. 2019. All Rights Reserved. | ||
* SPDX-License-Identifier: MIT | ||
* ******************************************************* | ||
* | ||
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN, | ||
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED | ||
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, | ||
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. | ||
""" | ||
|
||
__author__ = 'VMware, Inc.' | ||
|
||
import argparse | ||
|
||
from com.vmware.vmc.model_client import Task | ||
from vmware.vapi.vmc.client import create_vmc_client | ||
|
||
""" | ||
Demonstrates how to list tasks with given status | ||
Sample Prerequisites: | ||
- VMware Cloud on AWS console API access | ||
""" | ||
|
||
accepted = [Task.STATUS_STARTED, Task.STATUS_CANCELING, Task.STATUS_FINISHED, | ||
Task.STATUS_FAILED, Task.STATUS_CANCELED] | ||
|
||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
||
parser.add_argument('--refresh-token', | ||
required=True, | ||
help='VMware Cloud API refresh token') | ||
|
||
parser.add_argument('--org-id', | ||
required=True, | ||
help='Organization identifier.') | ||
|
||
parser.add_argument('--task-status', | ||
help='Task status to filter. Possible values are: {} \ | ||
Show all tasks if no value is passed'.format(accepted)) | ||
|
||
args = parser.parse_args() | ||
|
||
vmc_client = create_vmc_client(args.refresh_token) | ||
|
||
tasks = [] | ||
|
||
if args.task_status: | ||
status = args.task_status.upper() | ||
|
||
if status not in accepted: | ||
raise ValueError('Status "{}" is invalid, accept values are {}'. | ||
format(args.task_status, accepted)) | ||
|
||
tasks = vmc_client.orgs.Tasks.list( | ||
org=args.org_id, filter="(status eq '{}')".format(status)) | ||
|
||
print('# List all "{}" tasks:\n'.format(status)) | ||
else: | ||
tasks = vmc_client.orgs.Tasks.list(org=args.org_id) | ||
print('# List all tasks:\n') | ||
|
||
for task in tasks: | ||
print('{}\n'.format(task)) |