当前位置:网站首页>使用API快捷创建ECS
使用API快捷创建ECS
2022-06-28 10:52:00 【华为云】
有时候会有不断重复的创建某个特定配置的ECS的需求,在第一次控制台页面上创建时,在快结束时,可以将调用代码保存下来,这样以后就可以直接调用快速创建。
比如,保存的创建某个8C32G、镜像CentOS7.9、设置好VPC,ROOT密码的ECS,它的python代码如下,这个是调用 huaweicloudsdkcore 和 huaweicloudsdkecs 提供的SDK/API来实现ECS创建。
# coding: utf-8from huaweicloudsdkcore.auth.credentials import BasicCredentialsfrom huaweicloudsdkecs.v2.region.ecs_region import EcsRegionfrom huaweicloudsdkcore.exceptions import exceptionsfrom huaweicloudsdkecs.v2 import *if __name__ == "__main__": ak = "??RYLI??" sk = "??s7gcg3??" credentials = BasicCredentials(ak, sk) \ client = EcsClient.new_builder() \ .with_credentials(credentials) \ .with_region(EcsRegion.value_of("cn-south-1")) \ .build() try: request = CreateServersRequest() listPrePaidServerTagServerTagsServer = [] listPrePaidServerMetadataServer = { "op_svc_userid": "???7ad4a00f2d41f5bc00a59???", "admin_pass": "", "__support_agent_list": "hss,ces" } extendparamPrePaidServerExtendParam = PrePaidServerExtendParam( charging_mode="0", region_id="cn-south-1" ) listPrePaidServerSecurityGroupSecurityGroupsServer = [ PrePaidServerSecurityGroup( id="???-4396-4e74-a148-???" ) ] listPrePaidServerDataVolumeDataVolumesServer = [] extendparamPrePaidServerRootVolumeExtendParam = PrePaidServerRootVolumeExtendParam( resource_spec_code="GPSSD", resource_type="3" ) rootVolumePrePaidServerRootVolume = PrePaidServerRootVolume( volumetype="GPSSD", size=40, extendparam=extendparamPrePaidServerRootVolumeExtendParam, hwpassthrough=False ) listPrePaidServerNicNicsServer = [ PrePaidServerNic( subnet_id="???-a0ca-4df7-b865-5ca84ad2a7ee", ip_address="" ) ] serverPrePaidServer = PrePaidServer( image_ref="???-ab5e-4b0c-bcc0-52949077090c", flavor_ref="t6.2xlarge.4", name="tas", user_data="???KZWNobyAncm9vdDokNiREcEJabFpMTSRnMGY2OU9qSm9aYWE5blBXLnRMejNQMlRGaTZvcXlmclNSOFk0amJsV3JjQnNJeDM3aDlWZFhSczAwTDc4VGNZcnFpZmdhSWNIaDdSNG94M3FUQi5XMScgfCBjaHBhc3N3ZCAtZTs=", vpcid="???-825b-4ce5-874f-f302e08257bc", nics=listPrePaidServerNicNicsServer, count=1, is_auto_rename=False, root_volume=rootVolumePrePaidServerRootVolume, data_volumes=listPrePaidServerDataVolumeDataVolumesServer, security_groups=listPrePaidServerSecurityGroupSecurityGroupsServer, availability_zone="cn-south-1c", extendparam=extendparamPrePaidServerExtendParam, metadata=listPrePaidServerMetadataServer, server_tags=listPrePaidServerTagServerTagsServer, description="" ) request.body = CreateServersRequestBody( server=serverPrePaidServer ) response = client.create_servers(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)然后在运行这个python3脚本前,先安装一下SDK:pip3 install huaweicloudsdkcore huaweicloudsdkecs
然后运行就可以了,很快可以在页面上看到一台ECS在创建中,一会就创建好了。

边栏推荐
猜你喜欢

MySQL cannot be opened. Flash back

论文阅读 (59):Keyword-Based Diverse Image Retrieval with Variational Multiple Instance Graph

无线通信模块定点传输-点对多点的具体传输应用

How to use output in katalon

Realize an air conditioner with compose to bring you cool in summer

Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface

ruoyi集成积木报表(nice)

BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比

Metersphere实现UI自动化元素不可点击(部分遮挡)

Installing MySQL database (CentOS) in Linux source code
随机推荐
数据库系列:有什么办法对数据库的业务表进行无缝升级
Mysql database overview and installation process
【agora】get 一个 agora_refptr 对象的用法示例
DataEase安装升级
【力扣——动态规划】整理题目1:基础题目:509、70、746、62、63、343、96(附链接、题目描述、解题方法及代码)
无线通信模块定点传输-点对多点的具体传输应用
论文阅读 (59):Keyword-Based Diverse Image Retrieval with Variational Multiple Instance Graph
How to use K-line diagram for technical analysis
实体转JSON时,值为null的字段的丢失问题
Guangzhou Customs supports the stable supply of food, agricultural products, traditional Chinese medicine and other civilian and biological resources to Hong Kong
How does ETF position affect spot gold price?
[practice] 1364- implement a perfect waterfall flow component on the mobile terminal (with source code)
GDB简介
关于FTP的协议了解
建立自己的网站(11)
如何利用k线图做技术分析
[unity][ecs] learning notes (II)
Katalon框架测试web(二十)自定义关键字以及上传弹窗操作
Secretary of the Ukrainian national security and National Defense Commission: will carry out precision strikes against targets in Russia
Hystrix deployment