Skip to content

Commit e610a71

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

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

samples/vmc/tasks/cancel_task.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 cancel a running task
23+
24+
Sample Prerequisites:
25+
- VMware Cloud on AWS console API access
26+
- A running task
27+
"""
28+
29+
parser = argparse.ArgumentParser(
30+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
31+
32+
parser.add_argument('--refresh-token',
33+
required=True,
34+
help='VMware Cloud API refresh token')
35+
36+
parser.add_argument('--org-id',
37+
required=True,
38+
help='Organization identifier.')
39+
40+
parser.add_argument('--task-id',
41+
required=True,
42+
help='Task ID to be cancelled')
43+
44+
args = parser.parse_args()
45+
46+
vmc_client = create_vmc_client(args.refresh_token)
47+
48+
vmc_client.orgs.Tasks.update(org=args.org_id, task=args.task_id, action='cancel')
49+
50+
print('Task "{}" is cancelled'.format(args.task_id))

0 commit comments

Comments
 (0)