kes.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # -*- encoding:utf-8 -*-
  2. from kscore.exceptions import ClientError
  3. from kscore.session import get_session
  4. from pprint import pprint
  5. if __name__ == "__main__":
  6. s = get_session() # 创建会话
  7. client = s.create_client("kes", "cn-shanghai-3", use_ssl=False) # 一个 kscore 客户端实例(kes)
  8. param = {
  9. "ChargeType": "HourlyInstantSettlement",
  10. "AvailabilityZone": "cn-shanghai-3a",
  11. "MainVersion": "7.4.2",
  12. "InstanceGroups": [
  13. {
  14. "InstanceGroupType": "DATA",
  15. "InstanceCount": 3,
  16. "InstanceType": "ES.ssd.3C3G",
  17. "VolumeType": "Local_SSD",
  18. "VolumeSize": 20
  19. }
  20. ],
  21. "VpcDomainId": "XXXXXXXXXXXXXXXXXXXXX",
  22. "VpcSubnetId": "XXXXXXXXXXXXXXXXXXXXX"
  23. }
  24. resp = client.launch_cluster(**param)
  25. print(resp)
  26. '''
  27. ListClusters 查看所有集群的信息
  28. Parameters:
  29. Marker string 分页信息,示例limit=10&offset=0
  30. Returns:
  31. <type json>
  32. '''
  33. # param = {
  34. # "Marker": "limit=50&offset=0"
  35. # }
  36. # resp = client.list_clusters(**param)
  37. # print(resp)
  38. '''
  39. LaunchCluster 创建集群
  40. Parameters:
  41. VpcSubnetId string 账号下同数据中心同可用区可用云服务器子网(云服务器网络,节点资源有KEC资源则必填)
  42. VpcEpcSubnetId string 账号下同数据中心同可用区可用裸金属服务器子网(云物理机网络,节点资源有裸金属资源则必填)
  43. VpcDomainId string 账号下同数据中心可用VPC网络(VPC网络)
  44. SecurityGroupId string 账号下KES产品线可用安全组。标准UUID格式,形如[1]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$(安全组ID,若不填则默认创建新的安全组)
  45. PurchaseTime int 1-36(购买时长,当计费类型为Monthly(包年包月)时,需要传此参数,其他计费类型时不需要)
  46. ProjectId long 账号有权限的所有项目ID,0为默认项目(项目ID)
  47. MainVersion string 7.4.2,6.8.4,5.6.16(ES版本)
  48. EipLineId string UUID(EIP链路,购买弹性IP时必填)
  49. InstanceGroups object [] 节点组列表标识()
  50. EnableEip boolean true,false(是否开启EIP,不传默认为false)
  51. EipId 绑定,EIPID()
  52. ClusterName string 长度限制为1-25个字符,支持数字、大小写字母、减号和下划线(集群名称,如果未指定,则自动生成)
  53. ...
  54. Returns:
  55. <type json>
  56. '''
  57. # param = {
  58. # "ChargeType":"HourlyInstantSettlement",
  59. # "AvailabilityZone":"cn-shanghai-3a",
  60. # "MainVersion":"7.4.2",
  61. # "InstanceGroups":[
  62. # {
  63. # "InstanceGroupType":"DATA",
  64. # "InstanceCount":3,
  65. # "InstanceType":"ES.ssd.3C3G",
  66. # "VolumeType":"Local_SSD",
  67. # "VolumeSize":20
  68. # }
  69. # ],
  70. # "VpcDomainId":"XXXXXXXXXXXXXXXXXXXXX",
  71. # "VpcSubnetId":"XXXXXXXXXXXXXXXXXXXXX"
  72. # }
  73. # resp = client.launch_cluster(**param)
  74. # print(resp)
  75. '''
  76. DescribeCluster 查看指定集群详情信息
  77. Parameters:
  78. ClusterId string 集群ID
  79. Returns:
  80. <type json>
  81. '''
  82. # param = {
  83. # "ClusterId":"XXXXXXXXXXXXXXXXXXXXX"
  84. # }
  85. # resp = client.describe_cluster(**param)
  86. # print(resp)
  87. '''
  88. RestartCluster 重启指定的金山云KES集群
  89. Parameters:
  90. ClusterId string 集群ID
  91. Rolling boolean 为1时,滚动重启,为0时强制启动
  92. RollingInterval 节点重启间隔时间
  93. Returns:
  94. <type json>
  95. '''
  96. # param = {
  97. # "ClusterId":"XXXXXXXXXXXXXXXXXXXXX"
  98. # }
  99. # resp = client.restart_cluster(**param)
  100. # print(resp)
  101. '''
  102. ScaleOutInstanceGroups 完成现有集群扩容操作
  103. Parameters:
  104. ClusterId string 集群ID
  105. InstanceGroups string[] 扩容节点组标识
  106. InstanceGroupType boolean 是否新开节点组
  107. InstanceType string 节点组套餐code,已有节点组扩容该参数无效,新开节点组必填
  108. InstanceCount int 扩容数量,若已有节点组为新增数量,新开节点组为节点组内节点数量
  109. VolumeType string 磁盘类型
  110. VolumeSize int 数据盘大小
  111. ProjectId long 账号有权限的所有项目ID,0为默认项目
  112. Returns:
  113. <type json>
  114. '''
  115. # param = {
  116. # "ClusterId":"XXXXXXXXXXXXXXXXXXXXX",
  117. # "InstanceGroups":[
  118. # {
  119. # "InstanceGroupType":"DATA",
  120. # "InstanceCount":1
  121. # }
  122. # ]
  123. # }
  124. # resp = client.scale_out_instance_groups(**param)
  125. # print(resp)