创建App
接口
create_app
参数
所有类型的参数将被转换为包含属性信息的字典对象。
参数 | 类型 | 是否必须 | 描述 |
---|---|---|---|
app_desc | AppDescription | 是 | App 的描述信息 |
返回值
create_app 方法将返回一个CreateResponse
对象。可以通过 response.Id
的方式获取 App 标识符。
例子
Python 源码:
import time
import string
import random
import batchcompute
from batchcompute import CN_SHENZHEN as REGION
from batchcompute import Client, ClientError
from batchcompute.resources import (AppDescription, InputParameter, OutputParameter)
ACCESS_KEY_ID = 'Your Access Key Id'
ACCESS_KEY_SECRET = 'Your Access Key Secret'
client = Client(REGION, ACCESS_KEY_ID, ACCESS_KEY_SECRET)
def create_app(idempotent_token=''):
try:
app_desc = AppDescription()
app_desc.Name = 'test-copy' # or app_desc.setproperty('Name', '')
app_desc.Description = "Copy input file to output file"
app_desc.CommandLine = "cp ${inputFile} ${outputFile}"
app_desc.Daemonize = False
input = InputParameter()
input.Description = 'Input param 1'
input.Type = 'String'
input.Default = ''
input.LocalPath = '/tmp/infile/'
output = OutputParameter()
output.Description = 'Output param'
output.Type = 'String'
output.LocalPath = '/tmp/outfile/'
app_desc.add_input_parameter('inputFile', input)
app_desc.add_output_parameter('outputFile', output)
app_desc.EnvVars = {'env-k1': 'env-v1', 'env-k2': 'env-v2'}
#app_desc.Docker.Image = "localhost:5000/myubuntu11082105"
#app_desc.Docker.RegistryOSSPath = "oss://shengpeng/dockers/"
app_desc.VM.ECSImageId = 'img-ubuntu'
app_desc.set_resource_type('OnDemand', True, "Resource type")
app_desc.set_instance_type('ecs.sn2ne.large', True, "Instance type")
app_desc.set_instance_count(1, True, "Instance count")
app_desc.set_min_disk_size(40, True, "Min System Disk size")
app_desc.set_disk_type('cloud_efficiency', True, "System Disk type")
app_desc.set_min_data_disk_size(100, True, "Min Data Disk size")
app_desc.set_data_disk_type('cloud_efficiency', True, "Data Disk type")
app_desc.set_data_disk_mount_point('/home/mount/', True, "Data Disk mount point")
app_desc.set_max_retry_count(3, True, "Max retry count")
app_desc.set_timeout(6000, True, "Time out")
rsp = client.create_app(app_desc, idempotent_token)
print rsp
return True
except ClientError, e:
print (e.get_status_code(), e.get_code(), e.get_requestid(), e.get_msg())
return False
if __name__ == '__main__':
#Not Use idempotent token
#create_app()
#Use idempotent token
str_list = [random.choice(string.digits + string.ascii_letters) for i in range(32)]
random_str = ''.join(str_list)
#print random_str
ret = False
loop = 0
while loop < 5 and ret == False:
ret = create_app(random_str)
loop += 1
执行结果:
{
"Date": "Sat, 10 Nov 2018 07:35:48 GMT",
"Name": "PythonSdkTest",
"Id": "PythonSdkTest",
"RequestId": "A568AF98-3056-4C29-9AA3-BB0CF013F4C0",
"StatusCode": 201
}