Cloudforms.TaskManager¶
Task Manager
license: | MIT, see LICENSE for more details. |
---|
-
class
Cloudforms.managers.task.
TaskManager
(client)[source]¶ Manages Tasks.
Parameters: client (Cloudforms.API.Client) – an API client instance Example:
import Cloudforms client = Cloudforms.Client() task_mgr = Cloudforms.TaskManager(client)
-
get
(_id, params=None)[source]¶ Retrieve details about a task on the account
Parameters: - _id (string) – Specifies which task the request is for
- params (dict) – response-level options (attributes, limit, etc.)
Returns: Dictionary representing the matching task
Example:
# Gets a list of all tasks (returns IDs only) tasks = task_mgr.list({'attributes': 'id'}) for task in tasks: task_details = task_mgr.get(task['id'])
-
list
(params=None)[source]¶ Retrieve a list of all tasks on the account
Parameters: params (dict) – response-level options (attributes, limit, etc.) Returns: List of dictionaries representing the matching tasks Example:
# Gets a list of all tasks (returns IDs only) tasks = task_mgr.list({'attributes': 'id'})
-
wait
(_id, timeout=30, state='finished', params=None)[source]¶ Waits for a task to reach a certain state
Parameters: - state (string) – wait until the task reaches this state (case insensitive)
- timeout (integer) – operation timeout (in seconds)
- params (dict) – response-level options (attributes, limit, etc.)
Returns bool: True on success, False on error or timeout
Example:
# Gets a list of all virtual servers vms = vs_mgr.list() for vm in vms: # Send a request to stop the virtual server task = vs_mgr.stop(vms.get('id')) # Wait for the task to finish and collect the result task_succeeded = task_mgr.wait(task.get('task_id'))
-