Skip to content

Commit

Permalink
Add doc page and examples for Aliyun ecs
Browse files Browse the repository at this point in the history
  • Loading branch information
samsong8610 committed Mar 11, 2016
1 parent 9d834da commit 78ea780
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 18 deletions.
101 changes: 101 additions & 0 deletions docs/compute/drivers/aliyun_ecs.rst
@@ -0,0 +1,101 @@
Aliyun(AliCloud) ECS Driver Documentation
=========================================

`Aliyun(AliCloud) Elastic Compute Service (ECS)`_ is a simple and efficient computing service, whose processing capacity is scalable. It can help you quickly build a more stable and secure application. It helps you improve the efficiency of operation and maintenance, and reduce the cost of IT. ECS enables you to focus on core business innovation.

Regions
-------

The Aliyun supports mutiple regions, which indicates the distinct physical location all over the world. The current available regions in China are Hangzhou, Qingdao, Beijing, and Shenzhen. Other regions available outside of Chinese Mainland are Hong Kong, Singapore, and United States.

You can select the AliCloud region according to the customer base, cost effectiveness, disaster recovery site, or any compliance requirements. ECS instances in the same region can communicate with each other over intranet, whereas cross-region ECS communication requires the internet connection.

A region equals to `NodeLocation` in libcloud. Users can list all available regions, for example:

.. literalinclude:: /examples/compute/ecs/list_locations.py
:language: python

ECS Instance Types
------------------

An instance type defines some computing capabilities, including CPU, memory, associated with a set of ECS instances.

Aliyun provides two generations, three instance type families, and more than ten instance types to support different usecases.

For more information, please refer to the `Instance Generations`_ section, `Instance Type Families`_ section and `Instance Type`_ section of the official documentation.

An instance type equals to the `NodeSize` in libcloud. Users can list all available instance types, for example:

.. literalinclude:: /examples/compute/ecs/list_sizes.py
:language: python

Security Groups
---------------

A security group is a logical grouping which groups instances in the same region with the same security requirements and mutual trust. Security groups, like firewalls, are used to configure network access controls for one or more ECS instances.

Each instance belongs to at least one security group and this must be specified at the time of creation.

Users can list all defined security groups, for example:

.. literalinclude:: /examples/compute/ecs/ex_list_security_groups.py
:language: python

For more information, please refer to the `Security Groups`_ section of the official documentation.

Images
------

An image is an ECS instance operating environment template. It generally includes the operating system and preloaded software. It equals to `NodeImage` in libcloud.

Users can list all available images, for example:

.. literalinclude:: /examples/compute/ecs/list_images.py
:language: python

Storage
-------

Aliyun ECS provides multiple types of storage disks for instances to meet the requirements of different application scenarios. An instance can use all these types of volumes independently.

There are three types of disks: general cloud disk, SSD cloud disk and ephemeral SSD disk.

Aliyun provides the snapshot mechanism. This creates a snapshot that retains a copy of the data on a disk at a certain time point manually or automatically.

Aliyun storage disks equal to `StorageVolume` in libcloud. Users can manage volumes and snapshots, for example:

.. literalinclude:: /examples/compute/ecs/manage_volumes_and_snapshots.py
:language: python

For more information, please refer to the `Storage`_ section of the official documentation.

IP Address
----------

IP addresses are an important means for users to access ECS instances and for ECS instances to provide external services. Each instance will be allocated a private network card and bound to a specific private IP and a public network card by default.

Private IPs can be used for SLB load balancing, intranet mutual access between ECS instances or between an ECS instance and another cloud service within the same region. Data traffic through private IPs between instances in the same region is free.

Public IPs are used to access the instance from the internet. Public network traffic is not free.

Users can select different internet charge type and bandwidth limitations.

Instance lifecycle management
-----------------------------

.. literalinclude:: /examples/compute/ecs/manage_nodes.py
:language: python

API Reference
-------------

.. autoclass:: libcloud.compute.drivers.ecs.ECSDriver
:members:
:inherited-members:

.. _`Aliyun(AliCloud) Elastic Compute Service (ECS)`: https://www.aliyun.com/product/ecs/?lang=en
.. _`Instance Generations`: https://docs.aliyun.com/en#/pub/ecs_en_us/product-introduction/instance&instancegeneration
.. _`Instance Type Families`: https://docs.aliyun.com/en#/pub/ecs_en_us/product-introduction/instance&instancetypefamily
.. _`Instance Type`: https://docs.aliyun.com/en#/pub/ecs_en_us/product-introduction/instance&type
.. _`Security Groups`: https://docs.aliyun.com/en#/pub/ecs_en_us/product-introduction/network&securitygroup
.. _`Storage`: https://docs.aliyun.com/en#/pub/ecs_en_us/product-introduction/storage&summary
15 changes: 15 additions & 0 deletions docs/examples/compute/ecs/ex_list_security_groups.py
@@ -0,0 +1,15 @@
import pprint

from libcloud.compute.providers import get_driver
from libcloud.compute.types import Provider

ECSDriver = get_driver(Provider.ALIYUN_ECS)

region = 'cn-hangzhou'
access_key_id = 'gdsuDaEBZcFljdXH'
access_key_secret = 'n8MjIouCRMZiSZXTQT7N0Q4LqPUbvX'

driver = ECSDriver(access_key_id, access_key_secret, region=region)

sec_groups = driver.ex_list_security_groups()
pprint.pprint(sec_groups)
15 changes: 15 additions & 0 deletions docs/examples/compute/ecs/list_images.py
@@ -0,0 +1,15 @@
import pprint

from libcloud.compute.providers import get_driver
from libcloud.compute.types import Provider

ECSDriver = get_driver(Provider.ALIYUN_ECS)

region = 'cn-hangzhou'
access_key_id = 'gdsuDaEBZcFljdXH'
access_key_secret = 'n8MjIouCRMZiSZXTQT7N0Q4LqPUbvX'

driver = ECSDriver(access_key_id, access_key_secret, region=region)

images = driver.list_images()
pprint.pprint(images)
14 changes: 14 additions & 0 deletions docs/examples/compute/ecs/list_locations.py
@@ -0,0 +1,14 @@
from libcloud.compute.providers import get_driver
from libcloud.compute.types import Provider

ECSDriver = get_driver(Provider.ALIYUN_ECS)

region = 'cn-hangzhou'
access_key_id = 'gdsuDaEBZcFljdXH'
access_key_secret = 'n8MjIouCRMZiSZXTQT7N0Q4LqPUbvX'

driver = ECSDriver(access_key_id, access_key_secret, region=region)

locations = driver.list_locations()
for each in locations:
print('id: {0:>16s}'.format(each.id))
15 changes: 15 additions & 0 deletions docs/examples/compute/ecs/list_sizes.py
@@ -0,0 +1,15 @@
import pprint

from libcloud.compute.providers import get_driver
from libcloud.compute.types import Provider

ECSDriver = get_driver(Provider.ALIYUN_ECS)

region = 'cn-hangzhou'
access_key_id = 'gdsuDaEBZcFljdXH'
access_key_secret = 'n8MjIouCRMZiSZXTQT7N0Q4LqPUbvX'

driver = ECSDriver(access_key_id, access_key_secret, region=region)

sizes = driver.list_sizes()
pprint.pprint(sizes)
57 changes: 57 additions & 0 deletions docs/examples/compute/ecs/manage_nodes.py
@@ -0,0 +1,57 @@
import pprint

from libcloud.compute.base import NodeAuthPassword
from libcloud.compute.providers import get_driver
from libcloud.compute.types import Provider

ECSDriver = get_driver(Provider.ALIYUN_ECS)

region = 'cn-hangzhou'
access_key_id = 'gdsuDaEBZcFljdXH'
access_key_secret = 'n8MjIouCRMZiSZXTQT7N0Q4LqPUbvX'

driver = ECSDriver(access_key_id, access_key_secret, region=region)

# Query the size ecs.t1.small
sizes = driver.list_sizes()
t1_small = sizes[1]
# Query the first ubuntu OS image
images = driver.list_images()
for each in images:
if 'ubuntu' in each.id.lower():
ubuntu = each
break
else:
ubuntu = images[0]
# Query the default security group
sg = driver.ex_list_security_groups()[0]

# Create a cloud type data disk which is 5GB and deleted with the node
data_disk = {
'size': 5,
'category': driver.disk_categories.CLOUD,
'disk_name': 'data_disk1',
'delete_with_instance': True}

# Set a password to access the guest OS
auth = NodeAuthPassword('P@$$w0rd')

# Create the node
node = driver.create_node(image=ubuntu, size=t1_small, name='test_node',
ex_security_group_id=sg.id,
ex_internet_charge_type=driver.internet_charge_types.BY_TRAFFIC,
ex_internet_max_bandwidth_out=1,
ex_data_disks=data_disk,
auth=auth)

# Reboot the node
node.reboot()

# Stop the node
driver.ex_stop_node(node)

# Start the node
driver.ex_start_node(node)

# Destroy the node
node.destroy()
26 changes: 26 additions & 0 deletions docs/examples/compute/ecs/manage_volumes_and_snapshots.py
@@ -0,0 +1,26 @@
import pprint
import time

from libcloud.compute.providers import get_driver
from libcloud.compute.types import Provider

ECSDriver = get_driver(Provider.ALIYUN_ECS)

region = 'cn-hangzhou'
access_key_id = 'gdsuDaEBZcFljdXH'
access_key_secret = 'n8MjIouCRMZiSZXTQT7N0Q4LqPUbvX'

driver = ECSDriver(access_key_id, access_key_secret, region=region)

node = driver.list_nodes()[0]
zone = driver.ex_list_zones()[0]

new_volume = driver.create_volume(size=5, name='data_volume1',
ex_zone_id=zone.id,
ex_disk_category=driver.disk_categories.CLOUD)
driver.attach_volume(node, new_volume)
# Wait 10s for attaching finished
time.sleep(10)

snapshot = driver.create_volume_snapshot(new_volume,
name='data_volume1_snapshot1')

0 comments on commit 78ea780

Please sign in to comment.