描述
列举所有(easy_list
)。
参数说明
属性 | 类型 | 描述 |
---|---|---|
resource_type | str | 资源类型,目前仅允许列举”jobs”, “clusters”, “tasks”, “instances”。 |
*resource_info | tuple | 位置参数,包含列举资源需要提供的其他所有信息,如列举”instances”时需要提供job_id和task_name。 |
**filters | dict | 键值对参数,可以设置多个资源过滤条件。 |
返回值说明
easy_list方法返回一个 list
对象,其中包含了 resource_type
中所有符合过滤条件的资源实例。
示例
try:
client = Client(...
...
# List all jobs which named "PythonSDK" and have a description of "test list job".
for job in client.easy_list("jobs", Name="PythonSDK", Description="test list job"):
print (job.Name, job.Id)
# List all jobs which named "PythonSDK" and have a description of "test list job".
# filters can be also unpacked from a dict.
job_filters = {
"Name": "PythonSDK",
"Description": "test list job"
}
for job in client.easy_list("jobs", **job_filters):
print (job.Name, job.Id)
# List all jobs whose state is "Waiting" or "Running".
# `filetrs` with a tuple value also available.
for job in client.easy_list('jobs', State=['Waiting', 'Running']):
print (job.Name, job.Id)
# List all jobs whose state is "Waiting" or "Running".
# `filters` with a function value defined by users.
state_filter = lambda state: state in ['Waiting', 'Running']
for job in client.easy_list('jobs', State=state_filter):
print (job.Name, job.Id)
# List all "Runing" tasks in a job.
job_id = 'job-xxx'
client.easy_list('tasks', job_id, State='Running')
# List all "Running" instances in a task.
job_id = 'job-xxx'
task_name = 'Echo'
client.easy_list('instances', job_id, task_name, State='Running')
except ClientError, e:
print(e)