huaweicloud-sdk-python-v3/examples/vpc/v2/test_vpc.py

38 lines
997 B
Python
Raw Normal View History

2020-05-18 07:34:40 +00:00
# coding: utf-8
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcore.http.http_config import HttpConfig
from huaweicloudsdkvpc.v2 import VpcClient
def list_vpc(client):
try:
response = client.list_vpcs()
print(response)
except exceptions.ClientRequestException as e:
print(e.status_code)
print(e.request_id)
print(e.error_code)
print(e.error_msg)
if __name__ == "__main__":
ak = "{your ak string}"
sk = "{your sk string}"
endpoint = "{your endpoint}"
project_id = "{your project id}"
config = HttpConfig.get_default_config()
config.ignore_ssl_verification = True
credentials = BasicCredentials(ak, sk, project_id)
vpc_client = VpcClient.new_builder(VpcClient) \
.with_config(config) \
.with_credentials(credentials) \
.with_endpoint(endpoint) \
.build()
list_vpc(vpc_client)