All Products
Search
Document Center

create_cluster

Last Updated: May 14, 2018

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

  1. try:
  2. # Init a Client object.
  3. client = ...
  4. # Refer to ClusterDescription.
  5. cluster_desc = ClusterDescription(...)
  6. cluster = client.create_cluster(cluster_desc)
  7. # Print out the cluster id.
  8. print (cluster.Id)
  9. except ClientError, e:
  10. 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

Attribute Type Description
Endpoint str Endpoint of the MNS region. The format is http://${your_user_id}.mns.${region}-internal.aliyuncs.com/. Use the intranet endpoint whenever possible
Name str Topic name
Events list List of events. Make sure that you enter the cluster related events

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:

  1. The Job-level Mounts configuration will overwrite the cluster-level Mounts configuration.
  2. After a cluster is modified, the RecreateInstance interface must be called to make the new Mounts configuration take effect.
  3. 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:

  1. try:
  2. # some other codes here
  3. Client = Client(...
  4. ...
  5. cluster_desc = ClusterDescription()
  6. group_desc = GroupDescription()
  7. configs = Configs()
  8. group_desc.DesiredVMCount = 1
  9. group_desc.InstanceType = "ecs.t1.small"
  10. cluster_desc.add_group("group1", group_desc)
  11. configs.add_system_disk(40, 'ephemeral')
  12. configs.add_data_disk(40, 'ephemeral')
  13. cluster_desc.Configs = configs
  14. cluster_desc.Name = "BatchcomputePythonSDK"
  15. # image_id is a image created in batchcompute service before.
  16. # or an Ecs image Id.
  17. cluster_desc.ImageId = image_id
  18. print cluster_desc.Configs.Disks.SystemDisk.Type
  19. print cluster_desc.Configs.Disks.SystemDisk.Size
  20. print cluster_desc.Configs.Disks.DataDisk.Type
  21. print cluster_desc.Configs.Disks.DataDisk.Size
  22. print client.create_cluster(cluster_desc).Id
  23. except ClientError, e:
  24. print (e.get_status_code(), e.get_code(), e.get_requestid(), e.get_msg())