全部产品

创建App

更新时间:2018-12-19 10:07:09

接口

create_app

参数

所有类型的参数将被转换为包含属性信息的字典对象。

参数 类型 是否必须 描述
app_desc AppDescription App 的描述信息

返回值

create_app 方法将返回一个CreateResponse对象。可以通过 response.Id 的方式获取 App 标识符。

例子

Python 源码:

  1. import time
  2. import string
  3. import random
  4. import batchcompute
  5. from batchcompute import CN_SHENZHEN as REGION
  6. from batchcompute import Client, ClientError
  7. from batchcompute.resources import (AppDescription, InputParameter, OutputParameter)
  8. ACCESS_KEY_ID = 'Your Access Key Id'
  9. ACCESS_KEY_SECRET = 'Your Access Key Secret'
  10. client = Client(REGION, ACCESS_KEY_ID, ACCESS_KEY_SECRET)
  11. def create_app(idempotent_token=''):
  12. try:
  13. app_desc = AppDescription()
  14. app_desc.Name = 'test-copy' # or app_desc.setproperty('Name', '')
  15. app_desc.Description = "Copy input file to output file"
  16. app_desc.CommandLine = "cp ${inputFile} ${outputFile}"
  17. app_desc.Daemonize = False
  18. input = InputParameter()
  19. input.Description = 'Input param 1'
  20. input.Type = 'String'
  21. input.Default = ''
  22. input.LocalPath = '/tmp/infile/'
  23. output = OutputParameter()
  24. output.Description = 'Output param'
  25. output.Type = 'String'
  26. output.LocalPath = '/tmp/outfile/'
  27. app_desc.add_input_parameter('inputFile', input)
  28. app_desc.add_output_parameter('outputFile', output)
  29. app_desc.EnvVars = {'env-k1': 'env-v1', 'env-k2': 'env-v2'}
  30. #app_desc.Docker.Image = "localhost:5000/myubuntu11082105"
  31. #app_desc.Docker.RegistryOSSPath = "oss://shengpeng/dockers/"
  32. app_desc.VM.ECSImageId = 'img-ubuntu'
  33. app_desc.set_resource_type('OnDemand', True, "Resource type")
  34. app_desc.set_instance_type('ecs.sn2ne.large', True, "Instance type")
  35. app_desc.set_instance_count(1, True, "Instance count")
  36. app_desc.set_min_disk_size(40, True, "Min System Disk size")
  37. app_desc.set_disk_type('cloud_efficiency', True, "System Disk type")
  38. app_desc.set_min_data_disk_size(100, True, "Min Data Disk size")
  39. app_desc.set_data_disk_type('cloud_efficiency', True, "Data Disk type")
  40. app_desc.set_data_disk_mount_point('/home/mount/', True, "Data Disk mount point")
  41. app_desc.set_max_retry_count(3, True, "Max retry count")
  42. app_desc.set_timeout(6000, True, "Time out")
  43. rsp = client.create_app(app_desc, idempotent_token)
  44. print rsp
  45. return True
  46. except ClientError, e:
  47. print (e.get_status_code(), e.get_code(), e.get_requestid(), e.get_msg())
  48. return False
  49. if __name__ == '__main__':
  50. #Not Use idempotent token
  51. #create_app()
  52. #Use idempotent token
  53. str_list = [random.choice(string.digits + string.ascii_letters) for i in range(32)]
  54. random_str = ''.join(str_list)
  55. #print random_str
  56. ret = False
  57. loop = 0
  58. while loop < 5 and ret == False:
  59. ret = create_app(random_str)
  60. loop += 1

执行结果:

  1. {
  2. "Date": "Sat, 10 Nov 2018 07:35:48 GMT",
  3. "Name": "PythonSdkTest",
  4. "Id": "PythonSdkTest",
  5. "RequestId": "A568AF98-3056-4C29-9AA3-BB0CF013F4C0",
  6. "StatusCode": 201
  7. }