Sample

Last Updated: Mar 29, 2017

Cluster list

  1. #!/usr/bin/python
  2. from aliyunsdkcore import client
  3. from aliyunsdkemr.request.v20160408 import ListClustersRequest
  4. clt = client.AcsClient('SFAW************','Nc2nZ6dQoiqck0*************', ,'cn-hangzhou') # set acessId and accessKey
  5. request = ListClustersRequest.ListClustersRequest()
  6. request.set_accept_format('xml') # xml or json
  7. result = clt.do_action(request)
  8. print result

Create a cluster

  1. #!/usr/bin/python
  2. from aliyunsdkcore import client
  3. from aliyunsdkemr.request.v20160408 import CreateClusterRequest
  4. clt = client.AcsClient('SFAW************','Nc2nZ6dQoiqck0*************', ,'cn-hangzhou') # set acessId and accessKey
  5. request = CreateClusterRequest.CreateClusterRequest()
  6. request.set_Name("pydemo")
  7. request.set_ZoneId("cn-hangzhou-b")
  8. request.set_LogEnable(False)
  9. request.set_SecurityGroupId("sg-********")
  10. request.set_IsOpenPublicIp(True)
  11. request.set_ChargeType("PostPaid")
  12. request.set_EmrVer("EMR-1.3.0")
  13. request.set_ClusterType("HADOOP")
  14. request.set_IoOptimized(True)
  15. request.set_InstanceGeneration("ecs-2")
  16. # set EcsOrder
  17. request.add_query_param('EcsOrder.1.NodeCount', '1')
  18. request.add_query_param('EcsOrder.1.NodeType', 'MASTER')
  19. request.add_query_param('EcsOrder.1.InstanceType', 'ecs.n1.large')
  20. request.add_query_param('EcsOrder.1.DiskType', 'CLOUD_EFFICIENCY')
  21. request.add_query_param('EcsOrder.1.DiskCapacity', '80')
  22. request.add_query_param('EcsOrder.1.DiskCount', '1')
  23. request.add_query_param('EcsOrder.1.Index', '1')
  24. request.add_query_param('EcsOrder.2.NodeCount', '3')
  25. request.add_query_param('EcsOrder.2.NodeType', 'CORE')
  26. request.add_query_param('EcsOrder.2.InstanceType', 'ecs.n1.large')
  27. request.add_query_param('EcsOrder.2.DiskType', 'CLOUD_EFFICIENCY')
  28. request.add_query_param('EcsOrder.2.DiskCapacity', '80')
  29. request.add_query_param('EcsOrder.2.DiskCount', '4')
  30. request.add_query_param('EcsOrder.2.Index', '2')
  31. request.set_accept_format('json')
  32. result = clt.do_action(request)
  33. print result

Note: In Python SDK, the support for lists with input parameters of complicated objects is poor, so you need to process all the EcsOrder parameters specially. If you want to use the BootstrapAction parameter, follow similar processing methods.

For other interface operations, refer to here.

Thank you! We've received your feedback.