mirror of
https://github.com/vmware/vsphere-automation-sdk-python.git
synced 2024-11-24 10:19:59 -05:00
add cancel task sample
Signed-off-by: Tianhao He <het@vmware.com>
This commit is contained in:
parent
e15ee32793
commit
e610a71b97
50
samples/vmc/tasks/cancel_task.py
Normal file
50
samples/vmc/tasks/cancel_task.py
Normal file
@ -0,0 +1,50 @@
|
||||
"""
|
||||
* *******************************************************
|
||||
* 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 cancel a running task
|
||||
|
||||
Sample Prerequisites:
|
||||
- VMware Cloud on AWS console API access
|
||||
- A running task
|
||||
"""
|
||||
|
||||
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-id',
|
||||
required=True,
|
||||
help='Task ID to be cancelled')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
vmc_client = create_vmc_client(args.refresh_token)
|
||||
|
||||
vmc_client.orgs.Tasks.update(org=args.org_id, task=args.task_id, action='cancel')
|
||||
|
||||
print('Task "{}" is cancelled'.format(args.task_id))
|
Loading…
Reference in New Issue
Block a user