skd——server——group
【摘要】 # coding: utf-8from huaweicloudsdkcore.auth.credentials import BasicCredentialsfrom huaweicloudsdkecs.v2.region.ecs_region import EcsRegionfrom huaweicloudsdkcore.exceptions import exceptionsfrom h...
# coding: utf-8
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkecs.v2.region.ecs_region import EcsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkecs.v2 import *
if __name__ == "__main__":
# The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
# In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
ak = ""
sk = ""
credentials = BasicCredentials(ak, sk) \
client = EcsClient.new_builder() \
.with_credentials(credentials) \
.with_region(EcsRegion.value_of("cn-north-4")) \
.build()
try:
request = ListServerGroupsRequest()
response = client.list_server_groups(request)
for i in response.server_groups:
if i.name == "chinaskills_server_group":
try:
request = DeleteServerGroupRequest()
request.server_group_id = i.id
response = client.delete_server_group(request)
except exceptions.ClientRequestException as e:
pass
try:
request = CreateServerGroupRequest()
listPoliciesServerGroup = [
"anti-affinity"
]
serverGroupbody = CreateServerGroupOption(
name="chinaskills_server_group",
policies=listPoliciesServerGroup
)
request.body = CreateServerGroupRequestBody(
server_group=serverGroupbody
)
response = client.create_server_group(request)
try:
request = ListServerGroupsRequest()
response = client.list_server_groups(request)
for i in response.server_groups:
if i.name == "chinaskills_server_group":
try:
request = ShowServerGroupRequest()
request.server_group_id = i.id
response = client.show_server_group(request)
print(response)
except exceptions.ClientRequestException as e:
pass
except exceptions.ClientRequestException as e:
pass
except exceptions.ClientRequestException as e:
pass
except exceptions.ClientRequestException as e:
pass
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)