Java SDK样例代码有什么?
集群列表
- #!/usr/bin/python
- from aliyunsdkcore import client
- from aliyunsdkemr.request.v20160408 import ListClustersRequest
- clt = client.AcsClient('SFAW************','Nc2nZ6dQoiqck0*************', ,'cn-hangzhou') # set acessId and accessKey
- request = ListClustersRequest.ListClustersRequest()
- request.set_accept_format('xml') # xml or json
- # 设置状态过滤,只查找RUNNING和IDLE的集群,注意该参数为选填参数,可以不设置
- request.add_query_param('StatusList.1', 'RUNNING')
- request.add_query_param('StatusList.2', 'IDLE')
- result = clt.do_action(request)
- print result
创建集群
- #!/usr/bin/python
- from aliyunsdkcore import client
- from aliyunsdkemr.request.v20160408 import CreateClusterRequest
- clt = client.AcsClient('SFAW************','Nc2nZ6dQoiqck0*************', ,'cn-hangzhou') # set acessId and accessKey
- request = CreateClusterRequest.CreateClusterRequest()
- request.set_Name("pydemo")
- request.set_ZoneId("cn-hangzhou-b")
- request.set_LogEnable(False)
- request.set_SecurityGroupId("sg-********")
- request.set_IsOpenPublicIp(True)
- request.set_ChargeType("PostPaid")
- request.set_EmrVer("EMR-1.3.0")
- request.set_ClusterType("HADOOP")
- request.set_IoOptimized(True)
- request.set_InstanceGeneration("ecs-2")
- # set EcsOrder
- request.add_query_param('EcsOrder.1.NodeCount', '1')
- request.add_query_param('EcsOrder.1.NodeType', 'MASTER')
- request.add_query_param('EcsOrder.1.InstanceType', 'ecs.n1.large')
- request.add_query_param('EcsOrder.1.DiskType', 'CLOUD_EFFICIENCY')
- request.add_query_param('EcsOrder.1.DiskCapacity', '80')
- request.add_query_param('EcsOrder.1.DiskCount', '1')
- request.add_query_param('EcsOrder.1.Index', '1')
- request.add_query_param('EcsOrder.2.NodeCount', '3')
- request.add_query_param('EcsOrder.2.NodeType', 'CORE')
- request.add_query_param('EcsOrder.2.InstanceType', 'ecs.n1.large')
- request.add_query_param('EcsOrder.2.DiskType', 'CLOUD_EFFICIENCY')
- request.add_query_param('EcsOrder.2.DiskCapacity', '80')
- request.add_query_param('EcsOrder.2.DiskCount', '4')
- request.add_query_param('EcsOrder.2.Index', '2')
- request.set_accept_format('json')
- result = clt.do_action(request)
- print result
注意,由于阿里云产品众多,所有SDK的生成是通过程序自动生成的,所以有些SDK的使用比较不方便,特别地,在目前PythonSDK中,对入参是List(不管是基本类型的List还是复杂对象的List)支持不好,需要特殊处理。如果是基本类型的List入参,请参考“集群列表”示例代码中对StatusList参数的设置,如果是复杂对象的List入参,请参考“创建集群”示例代码中对EcsOrder参数的设置。其它List入参,例如BootstrapAction参数如果需要使用的话,处理方式类似。JavaSDK没有类似问题,使用起来会更加方便,我们优先 推荐您使用Java SDK。
其它接口操作类似,具体参考:https://help.aliyun.com/document_detail/28140.html
收起
0
条回答
写回答
取消
提交回答