全部产品
云市场

修改集群

更新时间:2018-11-18 12:15:22

接口

modify_cluster

参数

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

参数 类型 是否必须 描述
cluster_id str 集群的标识符
cluster_desc ModifyClusterDescription 修改集群的描述信息。

返回值

modify_cluster 返回 ActionResponse 对象。

例子

下面是一个修改集群集群的例子,我们把集群能修改的所有属性都已经做了示例,您可以根据需要裁剪掉不需要修改的内容来修改数据。另外我们还提供有更简单的修改单个实例的接口

Python 源码:

  1. import time
  2. import batchcompute
  3. from batchcompute import CN_SHENZHEN as REGION
  4. from batchcompute import Client, ClientError
  5. from batchcompute.resources import (
  6. Mounts, ModifyClusterDescription, ModifyConfigs, ModifyGroupDescription
  7. )
  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 modify_cluster():
  12. try:
  13. modify_body = ModifyClusterDescription()
  14. #Modify image
  15. modify_body.ImageId = 'img-centos'
  16. #Modify Group
  17. group_desc = ModifyGroupDescription()
  18. group_desc.DesiredVMCount = 1
  19. group_desc.InstanceType = 'ecs.sn2ne.large'
  20. #group_desc.SpotStrategy = 'SpotAsPriceGo'
  21. #group_desc.SpotPriceLimit = 0.0
  22. modify_body.add_group("group1", group_desc)
  23. #Modify UserData
  24. modify_body.UserData = {
  25. "k1": "v1"
  26. }
  27. #Modify EvnVars
  28. modify_body.EnvVars = {
  29. "k2": "v2"
  30. }
  31. #Modify Configs
  32. configs = ModifyConfigs()
  33. mounts = Mounts();
  34. nas_entry = {'Source': 'nas://26a174a62f-sfi98.cn-shenzhen.nas.aliyuncs.com:/',
  35. 'Destination': '/home/admin/modify-dir1/',
  36. 'WriteSupport': True}
  37. oss_entry = {'Source': 'oss://my-test-bk/',
  38. 'Destination': '/home/admin/modify-dir3/',
  39. 'WriteSupport': True}
  40. mounts.Entries = [nas_entry, oss_entry]
  41. configs.Mounts = mounts
  42. modify_body.Configs = configs
  43. print modify_body
  44. cluster_id = "cls-xxx"
  45. rsp = client.modify_cluster(cluster_id, modify_body)
  46. print rsp
  47. except ClientError, e:
  48. print (e.get_status_code(), e.get_code(), e.get_requestid(), e.get_msg())
  49. if __name__ == '__main__':
  50. modify_cluster()

执行结果:

  1. {
  2. "Date": "Thu, 08 Nov 2018 11:51:55 GMT",
  3. "RequestId": "A1004FC2-712C-4F51-94F4-8CB2BD661933",
  4. "StatusCode": 200
  5. }

扩展接口

另外我们还提供了以下几个简单的函数来修改集群的单项属性,您可以参考 SDK 代码。

  1. cluster_id = "cls-xxx"
  2. #Change the desired vm count of a existing cluster.
  3. client.change_cluster_desired_vm_count(cluster_id, group1=3, group2=4)
  4. #Change the spot config of an existing cluster.
  5. client.change_cluster_spot_config(cluster_Id, group_name="group1", strategy="SpotWithPriceLimit", price_limit=0.9)
  6. #Change the user meta of a existing cluster.
  7. client.change_cluster_user_data(cluster_Id, {"k1": "v1", "k2": "v2"})