import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkgsl.v3.gsl_client import GslClient
from huaweicloudsdkgsl.v3.model.add_or_modify_attribute_req import AddOrModifyAttributeReq
from huaweicloudsdkgsl.v3.model.attribute_req import AttributeReq
from huaweicloudsdkgsl.v3.model.batch_set_attributes_req import BatchSetAttributesReq
from huaweicloudsdkgsl.v3.model.batch_set_attributes_request import BatchSetAttributesRequest
from huaweicloudsdkgsl.v3.model.create_attribute_request import CreateAttributeRequest
from huaweicloudsdkgsl.v3.model.disable_attribute_request import DisableAttributeRequest
from huaweicloudsdkgsl.v3.model.enable_attribute_request import EnableAttributeRequest
from huaweicloudsdkgsl.v3.model.list_attributes_request import ListAttributesRequest
from huaweicloudsdkgsl.v3.model.update_attribute_request import UpdateAttributeRequest
from huaweicloudsdkgsl.v3.region.gsl_region import GslRegion
class SimAttributesApplication:
__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=SimAttributesApplication.__AK,
sk=SimAttributesApplication.__SK,
).with_iam_endpoint(endpoint=SimAttributesApplication.__IAM_ENDPOINT)
gsl_client = GslClient.new_builder() \
.with_credentials(credentials=auth) \
.with_region(region=GslRegion.CN_NORTH_4) \
.build()
SimAttributesApplication.__create_attribute(gsl_client)
SimAttributesApplication.__list_attributes(gsl_client)
SimAttributesApplication.__batch_set_attributes(gsl_client)
SimAttributesApplication.__enable_attribute(gsl_client)
SimAttributesApplication.__update_attribute(gsl_client)
SimAttributesApplication.__disable_attribute(gsl_client)
@staticmethod
def __create_attribute(gsl_client):
cust_attr_name = "SDK测试自定义属性"
try:
response = gsl_client.create_attribute(
CreateAttributeRequest(
body=AddOrModifyAttributeReq(
cust_attr_name=cust_attr_name
)
)
)
print(response)
except exceptions.ClientRequestException as e:
SimAttributesApplication.__handle_exception(e)
@staticmethod
def __list_attributes(gsl_client):
cust_attr_name = "SDK测试自定义属性"
limit = 10
offset = 1
status = 0
try:
response = gsl_client.list_attributes(
ListAttributesRequest(
cust_attr_name=cust_attr_name,
limit=limit,
offset=offset,
status=status
)
)
print(response)
except exceptions.ClientRequestException as e:
SimAttributesApplication.__handle_exception(e)
@staticmethod
def __batch_set_attributes(gsl_client):
attributes = []
attribute_req1 = AttributeReq()
attribute_req1.sim_card_id = 1234567
attribute_req1.customer_attribute1 = "自定义属性1测试"
attribute_req1.customer_attribute2 = "自定义属性2测试"
attribute_req1.customer_attribute3 = "自定义属性3测试"
attribute_req1.customer_attribute4 = "自定义属性4测试"
attribute_req1.customer_attribute5 = "自定义属性5测试"
attribute_req1.customer_attribute6 = "自定义属性6测试"
attributes.append(attribute_req1)
try:
response = gsl_client.batch_set_attributes(
BatchSetAttributesRequest(
body=BatchSetAttributesReq(
attributes=attributes
)
)
)
print(response)
except exceptions.ClientRequestException as e:
SimAttributesApplication.__handle_exception(e)
@staticmethod
def __enable_attribute(gsl_client):
attribute_id = 12
try:
response = gsl_client.enable_attribute(
EnableAttributeRequest(
attribute_id=attribute_id
)
)
print(response)
except exceptions.ClientRequestException as e:
SimAttributesApplication.__handle_exception(e)
@staticmethod
def __update_attribute(gsl_client):
attribute_id = 12
cust_attr_name = "SDK测试自定义属性新"
try:
response = gsl_client.update_attribute(
UpdateAttributeRequest(
attribute_id=attribute_id,
body=AddOrModifyAttributeReq(
cust_attr_name=cust_attr_name
)
)
)
print(response)
except exceptions.ClientRequestException as e:
SimAttributesApplication.__handle_exception(e)
@staticmethod
def __disable_attribute(gsl_client):
attribute_id = 12
try:
response = gsl_client.disable_attribute(
DisableAttributeRequest(
attribute_id=attribute_id
)
)
print(response)
except exceptions.ClientRequestException as e:
SimAttributesApplication.__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__":
SimAttributesApplication().main(any)