修改集群

接口

modify_cluster

参数

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

参数

类型

是否必须

描述

cluster_id

str

集群的标识符

cluster_desc

ModifyClusterDescription

修改集群的描述信息。

返回值

modify_cluster 返回 ActionResponse 对象。

例子

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

Python 源码:

import time
import batchcompute
from batchcompute import CN_SHENZHEN as REGION
from batchcompute import Client, ClientError
from batchcompute.resources import (
    Mounts, ModifyClusterDescription, ModifyConfigs, ModifyGroupDescription
)

ACCESS_KEY_ID = 'Your Access Key Id'
ACCESS_KEY_SECRET = 'Your Access Key Secret'

client = Client(REGION, ACCESS_KEY_ID, ACCESS_KEY_SECRET)

def modify_cluster():
    try:
        modify_body = ModifyClusterDescription()

        #Modify image
        modify_body.ImageId = 'img-centos'

        #Modify Group
        group_desc = ModifyGroupDescription()
        group_desc.DesiredVMCount = 1
        group_desc.InstanceType = 'ecs.sn2ne.large'
        #group_desc.SpotStrategy = 'SpotAsPriceGo'
        #group_desc.SpotPriceLimit = 0.0
        modify_body.add_group("group1", group_desc)

        #Modify UserData
        modify_body.UserData = {
           "k1": "v1"
        }

        #Modify EvnVars
        modify_body.EnvVars = {
            "k2": "v2"
        }

        #Modify Configs
        configs = ModifyConfigs()
        mounts = Mounts();
        nas_entry = {'Source': 'nas://26a174a62f-sfi98.cn-shenzhen.nas.aliyuncs.com:/',
                  'Destination': '/home/admin/modify-dir1/',
                  'WriteSupport': True}
        oss_entry = {'Source': 'oss://my-test-bk/',
                  'Destination': '/home/admin/modify-dir3/',
                  'WriteSupport': True}
        mounts.Entries = [nas_entry, oss_entry]
        configs.Mounts = mounts

        modify_body.Configs = configs

        print modify_body
        cluster_id = "cls-xxx"
        rsp = client.modify_cluster(cluster_id, modify_body)
        print rsp
    except ClientError, e:
        print (e.get_status_code(), e.get_code(), e.get_requestid(), e.get_msg())

if __name__ == '__main__':
    modify_cluster()

执行结果:

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

扩展接口

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

cluster_id = "cls-xxx"

#Change the desired vm count of a existing cluster. 
client.change_cluster_desired_vm_count(cluster_id, group1=3, group2=4)

#Change the spot config of an existing cluster.
client.change_cluster_spot_config(cluster_Id, group_name="group1", strategy="SpotWithPriceLimit", price_limit=0.9)

#Change the user meta of a existing cluster.
client.change_cluster_user_data(cluster_Id, {"k1": "v1", "k2": "v2"})