当前位置:网站首页>Create ECS using API shortcut
Create ECS using API shortcut
2022-06-28 10:58:00 【Hua Weiyun】
Sometimes there will be repeated creation of a specific configuration ECS The needs of , When created on the first console page , Towards the end , You can save the calling code , In this way, you can directly call the quick create .
such as , Saved create a 8C32G、 Mirror image CentOS7.9、 Set it up VPC,ROOT Cryptographically ECS, its python The code is as follows , This is calling huaweicloudsdkcore and huaweicloudsdkecs Provided SDK/API To achieve ECS establish .
# 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) Then run this python3 Before script , Install it first SDK:pip3 install huaweicloudsdkcore huaweicloudsdkecs
Then run it , You'll soon see one on the page ECS In creation , It will be created in a moment .

边栏推荐
猜你喜欢
随机推荐
Threads and thread pools
将浏览器中的文件 url转换为File流
Décompression par compression
Mongo database
移动命令
appliedzkp zkevm(9)中的Bytecode Proof
使用API快捷创建ECS
Knowing the details of redis RDB, you can step on many holes less
ProCAST有限元铸造工艺模拟软件
知道 Redis RDB 这些细节,可以少踩很多坑
MySQL general binary installation method
Guangzhou Customs supports the stable supply of food, agricultural products, traditional Chinese medicine and other civilian and biological resources to Hong Kong
Wireless communication module fixed-point transmission - point to multipoint specific transmission application
Internet of things application case of wireless module transparent transmission technology
Compression and decompression
AQS理解
Katalon framework tests web (XX) custom keywords and upload pop-up operations
【LeetCode每日一题】【2021/12/19】997. 找到小镇的法官
Redis数据库
JS基础3









