首先安装阿里云SDK
pip install aliyun-python-sdk-core
pip install aliyun-python-sdk-ecs
可以配合jenkins传递参数
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2018/9/26 0026 12:01
# @Author : peter
# @FileName: aliyun_ecs_cre.py
import json,time,os
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkecs.request.v20140526 import CreateInstanceRequest,StartInstanceRequest,DescribeInstancesRequest
AccessKey = os.environ.get('AccessKey')
Secret = os.environ.get('Secret')
Regions = os.environ.get('Regions')
# 创建 AcsClient 实例
client = AcsClient(
AccessKey,
Secret,
Regions
);
def ecs_start(InstanceId):
request = StartInstanceRequest.StartInstanceRequest()
request.set_InstanceId(InstanceId)
response = client.d