python 调用阿里云服务器api创建服务器

首先安装阿里云SDK

pip install aliyun-python-sdk-core

pip install aliyun-python-sdk-ecs

可以配合jenkins传递参数

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2018/1/26 0026 12:01
# @Author  : sanmuyan
# @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.do_action_with_exception(request)
   print(response,'\n',"INFO:Starting results")

def ecs_des(InstanceId):
   request = DescribeInstancesRequest.DescribeInstancesRequest()
   request.set_InstanceIds(InstanceId)
   response = client.do_action_with_exception(request)
   data = json.loads(response)
   data = json.dumps(data, sort_keys=True, indent=2)
   print(data)

def ecs_cre():
    request = CreateInstanceRequest.CreateInstanceRequest()
    request.set_ImageId(ImageId)
    request.set_InstanceType(InstanceType)
    request.set_SecurityGroupId(SecurityGroupId)
    request.set_ZoneId(ZoneId)
    request.set_InstanceName(InstanceName)
    request.set_HostName(HostName)
    request.set_Password(Password)
    request.set_SystemDiskCategory(SystemDiskCategory)
    request.set_DataDisks(({'DataDisk':'1'},{'Size':DataDiskSize},{'Category':'cloud_efficiency'}))
    request.set_SystemDiskSize(SystemDiskSize)
    request.set_VSwitchId(VSwitchId)
    request.set_InstanceChargeType(InstanceChargeType)
    request.set_Period(Period)
    if (Period == "PrePaid"):
        request.set_AutoRenew(AutoRenew)
        request.set_AutoRenewPeriod(AutoRenewPeriod)
        response = client.do_action_with_exception(request)
        
    response = client.do_action_with_exception(request)   
    data = json.loads(response)
    print(data,'\n'"INFO:Create success")
    InstanceId = (data['InstanceId'])
    time.sleep(10)
    ecs_start(InstanceId=InstanceId)
    time.sleep(20)
    ecs_des(InstanceId=[InstanceId])

if __name__ == '__main__':

    ImageId = os.environ.get('ImageId')                                   # 镜像
    InstanceType = os.environ.get('InstanceType')                         # 实例规格
    SecurityGroupId = os.environ.get('SecurityGroupId')                   # 安全组
    ZoneId = os.environ.get('ZoneId')                                   # 可用区
    InstanceName = os.environ.get('InstanceName')                        # 实例名
    HostName = os.environ.get('HostName')                                 # 主机名
    Password = os.environ.get('Password')                                 # 主机密码
    SystemDiskCategory = os.environ.get('SystemDiskCategory')              # 系统盘类型
    SystemDiskSize = os.environ.get('SystemDiskSize')                   # 系统盘大小
    DataDiskSize = os.environ.get('DataDiskSize')                       # 数据盘大小
    VSwitchId = os.environ.get('VSwitchId')                                # 交换机
    InstanceChargeType = os.environ.get('InstanceChargeType')           # 实例付费类型
    Period = os.environ.get('Period')                                   # 购买时长
    AutoRenew = os.environ.get('AutoRenew')                                # 是否开启自动续费
    AutoRenewPeriod = os.environ.get('AutoRenewPeriod')                    # 自动续费时长
    ecs_cre()

 

转载于:https://www.cnblogs.com/37yan/p/8418751.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Editorial Reviews Amazon.com The OpenGL graphics libraries offer programmers the ability to construct and render remarkably realistic 3-D scenes that can incorporate multiple lighting sources, various types of perspective, and various special effects. The OpenGL Programming Guide is a comprehensive and definitive resource on using the extensive capabilities offered by OpenGL. Beginning with coverage of basic OpenGL objects--points, lines, and polygons--it advances through functions for selecting colors, lighting, reflective properties, texture, atmospheric haze, and more. Basic concepts of 3-D graphics are made accessible with analogies to cameras, and advanced sidebars and appendices go into deep detail about OpenGL. Book Description OpenGL is a powerful software interface for graphics hardware that allows graphics programmers to produce high-quality color images of 3D objects. The functions in the OpenGL library enable programmers to build geometric models, view models interactively in 3D space, control color and lighting, manipulate pixels, and perform such tasks as alpha blending, antialiasing, creating atmospheric effects, and texture mapping. The OpenGL Programming Guide, Second Edition, shows how to create graphics programs, many of which highlight features of the latest OpenGL release. Assuming users have a background in C programming, the book discusses the architecture and functions of OpenGL, Version 1.1. The second edition contains the following additions and improvements: coverage of the new features of OpenGL, Version 1.1, including all texturing changes, vertex arrays, polygon offset, and RGBA logical operations the incorporation of the OpenGL Utility Toolkit, GLUT, in all programming examples, an overview of the OpenGL rendering pipeline and state machine, enhanced coverage of polygon tessellation, quadric surfaces, pixel operations, and error handling, more performance tips, a greatly expanded index. The OpenGL Technical Library provides tutorial an

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值