Parameter description
All classes of parameters are converted to dictionary objects containing the attribute information.
Parameter |
Type |
Description |
cluster_desc |
ClusterDescription object, str, dict |
Description of the cluster |
Response description
- The create_cluster method returns a
CreateResponse
object. The following lists the attributes of the CreateResponse
object. - You can use
response.Id
to obtain the ID of the new cluster.
Attribute |
Type |
Description |
Id |
str |
ID of the new cluster |
Example
try:
# Init a Client object.
client = ...
# Refer to ClusterDescription.
cluster_desc = ClusterDescription(...)
cluster = client.create_cluster(cluster_desc)
# Print out the cluster id.
print (cluster.Id)
except ClientError, e:
print (e)
ClusterDescription class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, ClusterDescription object |
Object that contains the cluster description |
Attribute description
For information about Groups, see the description of the GroupDescription class.
Attribute |
Type |
Description |
Name |
str |
Cluster name |
Description |
str |
Brief description of the cluster |
ImageId |
str |
Image ID. Currently, only the ECS image ID is supported |
UserData |
dict |
Key-Value mapping, which is defined by the user and obtained by using metaserver of the ECS instance |
Groups |
GroupDescription object |
Information about instance groups in the cluster, which is described using the JSON format |
Configs |
Configs object |
Cluster configurations |
Notification |
Notification object |
Notification message configuration |
Method description
Method |
Description |
add_group(group_name, group) |
Adds an instance group |
get_group(group_name) |
Obtains information about an instance group based on the name of this instance group |
delete_group(group_name) |
Deletes an instance group |
GroupDescription class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, GroupDescription object |
Information about instance groups in the cluster |
Attribute description
Attribute |
Type |
Description |
DesiredVMCount |
int |
Expected number of instances |
InstanceType |
str |
Cluster instance type |
ResourceType |
str |
Resource type. Optional values include OnDemand and Spot |
SpotStrategy |
str |
Spot strategy for an instance. It takes effect only when ResourceType is Spot. Values: SpotWithPriceLimit (Set the maximum price for the spot instance) and SpotAsPriceGo (The system provides a price automatically, and the maximum value is the Pay-As-You-Go price) |
SpotPriceLimit |
float |
Maximum price of an instance per hour (the price of each instance type, not the price per core*hour). The value can contain at most three decimals. It takes effect when SpotStrategy is SpotWithPriceLimit |
Configs class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, GroupDescription object |
Cluster configurations |
Attribute description
Attribute |
Type |
Description |
Disks |
Disks object |
Disk configurations of instances in a cluster |
Mounts |
Object |
Network disk mounting configurations when a cluster is created |
Networks |
Networks object |
Network configurations of instances in a cluster, which are described by Networks |
Method description
Method |
Description |
addsystem_disk(size, type) |
Sets the size and type of a system disk. Currently, supported types include cloud and ephemeral |
adddata_disk(size, type, mount_point) |
Adds and sets a data disk. Currently, supported types include cloud and ephemeral |
Disks class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, Disks object |
Disk configurations of the cluster |
Attribute description
Attribute |
Type |
Description |
SystemDisk |
SystemDisk object |
System disk configurations |
DataDisk |
DataDisk object |
Data disk configurations |
SystemDisk class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, SystemDisk object |
System disk configurations |
Attribute description
Attribute |
Type |
Description |
Size |
int |
Size of the system disk |
Type |
str |
Type of the data disk |
DataDisk class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, DataDisk object |
Data disk configurations |
Attribute description
Attribute |
Type |
Description |
Size |
int |
Size of the system disk |
Type |
str |
Type of the data disk |
MountPoint |
str |
Directory to which the data disk must be mounted in the Linux system |
Notification class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, Command object |
Command line parameters related to a user program |
Attribute description
Attribute |
Type |
Description |
Topic |
Topic Object |
Message topic |
Topic class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, Command object |
Command line parameters related to a user program |
Attribute description
Mounts class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, Command object |
Network disk mounting configurations when a cluster is created |
Attribute description
Attribute |
Type |
Description |
Entries |
array |
List of network disk mount points, which is described by MountPoint |
Locale |
str |
Language used when OSS or NAS storage is mounted |
Lock |
bool |
Specifies whether the file lock is supported when OSS or NAS storage is mounted |
NAS |
dict |
NAS configuration |
OSS |
dict |
OSS configuration |
MountPoint class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, Command object |
Network mount point |
Attribute description
Attribute |
Type |
Description |
Source |
str |
Source directory for network disk mounting. It can be a string starting with “nas://“ or “oss://“ |
Destination |
str |
Local mount point directory of the network disk |
WriteSupport |
bool |
Specifies whether the mount point is writable |
NAS class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, Command object |
NAS configuration |
Attribute description
Attribute |
Type |
Description |
AccessGroup |
list |
NAS access group to which the cluster instance must be added |
FileSystem |
list |
File system to be accessed |
OSS class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, Command object |
OSS configuration |
Attribute description
Attribute |
Type |
Description |
AccessKeyId |
str |
AccessKey ID used for OSS mounting |
AccessKeySecret |
str |
AccessKey Secret used for OSS mounting |
SecurityToken |
str |
Security token used for OSS mounting |
Note: Take the following precautions for Mounts:
- The Job-level Mounts configuration will overwrite the cluster-level Mounts configuration.
- After a cluster is modified, the RecreateInstance interface must be called to make the new Mounts configuration take effect.
- During NAS mounting, the source directory must start with “nas:”. Otherwise, an error occurs.
Networks class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, Command object |
Network configurations when the cluster is created |
Attribute description
Attribute |
Type |
Description |
Classic |
dict |
Classic network configurations, which is described by Classic |
Classic class
Parameter description
Parameter |
Type |
Description |
properties |
dict, str, Command object |
Classic network configurations |
Attribute description
Attribute |
Type |
Description |
AllowIpAddress |
list |
IP address that allows the inbound traffic |
AllowIpAddressEgress |
list |
IP address that allows the outbound traffic |
AllowSecurityGroup |
list |
Security group that allows the inbound traffic |
AllowSecurityGroupEgress |
list |
Security group that allows the outbound traffic |
For example:
try:
# some other codes here
Client = Client(...
...
cluster_desc = ClusterDescription()
group_desc = GroupDescription()
configs = Configs()
group_desc.DesiredVMCount = 1
group_desc.InstanceType = "ecs.t1.small"
cluster_desc.add_group("group1", group_desc)
configs.add_system_disk(40, 'ephemeral')
configs.add_data_disk(40, 'ephemeral')
cluster_desc.Configs = configs
cluster_desc.Name = "BatchcomputePythonSDK"
# image_id is a image created in batchcompute service before.
# or an Ecs image Id.
cluster_desc.ImageId = image_id
print cluster_desc.Configs.Disks.SystemDisk.Type
print cluster_desc.Configs.Disks.SystemDisk.Size
print cluster_desc.Configs.Disks.DataDisk.Type
print cluster_desc.Configs.Disks.DataDisk.Size
print client.create_cluster(cluster_desc).Id
except ClientError, e:
print (e.get_status_code(), e.get_code(), e.get_requestid(), e.get_msg())