Skip to content

happylin0x29a/alibabacloud-python-sdk-v2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alibaba Cloud Python SDK 2.0

PyPI Release Build Status Code Coverage

Alibaba Cloud Python SDK 2.0 is aimed to provide a Pythonic, object-oriented interface of Alibaba Cloud APIs. Now it's still under development, with a few ECS functions and resources available. By using it, developers can make use of ECS APIs to manage resources including instances, with a much better programming experience than the current aliyun-openapi-python-sdk.

Installation

Install the SDK from PYPI:

pip install alibaba-cloud-python-sdk-v2

If you prefer installing the SDK from source:

git clone git://github.com/aliyun/alibabacloud-python-sdk-v2.git
cd alibabacloud-python-sdk-v2
python setup.py install

Usage

  1. Initialize a ECS resource
import alibabacloud

ecs = alibabacloud.get_resource(
    'ecs',
    access_key_id="your Access Key ID",
    access_key_secret="your Access Key Secret",
    region_id="your Region ID",
)

Note: Credentials information will be moved to configuration files in the future versions.

  1. Create an ECS instance, and start, stop it.
from alibabacloud.services.ecs import ECSInstanceResource

# Assume you already have a ECS resource name 'ecs'

instance = ecs.create_instance(
    ImageId="coreos_1745_7_0_64_30G_alibase_20180705.vhd",
    InstanceType="ecs.n2.small",
)

print(instance.instance_id)

instance.start()
instance.wait_until(ECSInstanceResource.STATUS_RUNNING)

instance.stop()
instance.wait_until(ECSInstanceResource.STATUS_STOPPED)
  1. Get all instances attributes
# Assume you already have a ECS resource name 'ecs'
for instance in ecs.instances.all():
    print(instance.instance_id)
    print(instance.instance_type)
    print(instance.status)
  1. Find all instances which status is running, and let PageNumber of DescribeInstances API to be 100, and limit results number to 100.
# Assume you already have a ECS resource name 'ecs'
for instance in ecs.instances.filter(Status='Running').page_size(100).limit(200):
    print(instance.instance_id)
    print(instance.instance_type)
    print(instance.status)

Getting Help

Alibaba Cloud Python SDK 2.0 is still under development. If you have suggestions or find a bug, please open an issue.

About

Alibaba Cloud Python SDK 2.0

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 96.2%
  • Shell 3.8%