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_flow_by_sim_cards_req import ListFlowBySimCardsReq
from huaweicloudsdkgsl.v3.model.list_flow_by_sim_cards_request import ListFlowBySimCardsRequest
from huaweicloudsdkgsl.v3.model.list_sim_price_plans_request import ListSimPricePlansRequest
from huaweicloudsdkgsl.v3.region.gsl_region import GslRegion
class SimPricePlansApplication:
__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=SimPricePlansApplication.__AK,
sk=SimPricePlansApplication.__SK,
).with_iam_endpoint(endpoint=SimPricePlansApplication.__IAM_ENDPOINT)
gsl_client = GslClient.new_builder() \
.with_credentials(credentials=auth) \
.with_region(region=GslRegion.CN_NORTH_4) \
.build()
SimPricePlansApplication.__list_flow_by_sim_cards(gsl_client)
SimPricePlansApplication.__list_sim_price_plans(gsl_client)
@staticmethod
def __list_flow_by_sim_cards(gsl_client):
iccids = []
iccids.append("898602B4151880002907")
iccids.append("89860317422045106999")
iccids.append("898602B4151880002849")
try:
response = gsl_client.list_flow_by_sim_cards(
ListFlowBySimCardsRequest(
body=ListFlowBySimCardsReq(
iccids=iccids
)
)
)
print(response)
except exceptions.ClientRequestException as e:
SimPricePlansApplication.__handle_exception(e)
@staticmethod
def __list_sim_price_plans(gsl_client):
sim_card_id = 13
real_time = False
limit = 10
offset = 1
try:
response = gsl_client.list_sim_price_plans(
ListSimPricePlansRequest(
limit=limit,
offset=offset,
real_time=real_time,
sim_card_id=sim_card_id
)
)
print(response)
except exceptions.ClientRequestException as e:
SimPricePlansApplication.__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__":
SimPricePlansApplication().main(any)