import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkgsl.v3.gsl_client import GslClient
from huaweicloudsdkgsl.v3.model.list_sim_pool_members_request import ListSimPoolMembersRequest
from huaweicloudsdkgsl.v3.model.list_sim_pools_request import ListSimPoolsRequest
from huaweicloudsdkgsl.v3.region.gsl_region import GslRegion
class SimPoolApplication:
__AK = os.environ["HUAWEICLOUD_SDK_AK"]
__SK = os.environ["HUAWEICLOUD_SDK_SK"]
__IAM_ENDPOINT = "https://<IamEndpoint>"
def __init__(self):
pass
@staticmethod
def main(args):
auth = BasicCredentials(
ak=SimPoolApplication.__AK,
sk=SimPoolApplication.__SK,
).with_iam_endpoint(endpoint=SimPoolApplication.__IAM_ENDPOINT)
gsl_client = GslClient.new_builder() \
.with_credentials(credentials=auth) \
.with_region(region=GslRegion.CN_NORTH_4) \
.build()
SimPoolApplication.__list_sim_pool_members(gsl_client)
SimPoolApplication.__list_sim_pools(gsl_client)
@staticmethod
def __list_sim_pool_members(gsl_client):
sim_pool_id = 3639843601089537
cid = "8986031746205479425"
limit = 10
offset = 1
billing_cycle = "2021-08"
try:
response = gsl_client.list_sim_pool_members(
ListSimPoolMembersRequest(
sim_pool_id=sim_pool_id,
limit=limit,
offset=offset,
cid=cid,
billing_cycle=billing_cycle
)
)
print(response)
except exceptions.ClientRequestException as e:
SimPoolApplication.__handle_exception(e)
@staticmethod
def __list_sim_pools(gsl_client):
pool_name = "本地测试流量池"
limit = 10
offset = 1
billing_cycle = "2022-04"
try:
response = gsl_client.list_sim_pools(
ListSimPoolsRequest(
billing_cycle=billing_cycle,
limit=limit,
offset=offset,
pool_name=pool_name
)
)
print(response)
except exceptions.ClientRequestException as e:
SimPoolApplication.__handle_exception(e)
@staticmethod
def __handle_exception(e):
print(e.status_code)
print(e.request_id)
print(e.error_code)
print(e.error_msg)
if __name__ == "__main__":
SimPoolApplication().main(any)