def create_router_interface(self, params):
        """
        create_router_interface: 创建路由器接口
        官网API参考: https://help.aliyun.com/document_detail/36032.html
        """
        try:
            request = CreateRouterInterfaceRequest.CreateRouterInterfaceRequest()
            # 路由器接口的规格
            request.set_Spec(params['spec'])
            # 路由器接口的角色
            request.set_Role(params['role'])
            # 路由器接口关联的路由器ID
            request.set_RouterId(params['router_id'])
            # 路由器接口关联的路由器类型
            request.set_RouterType(params['router_type'])
            # 连接接收端所在的地域ID
            request.set_OppositeRegionId(params['opposite_region_id'])
            # 对端路由器接口关联的路由器类型
            request.set_OppositeRouterType(params['opposite_router_type'])

            response = self.client.do_action_with_exception(request)
            response_json = json.loads(response)
            # 判断Router Interface状态是否可用
            if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,
                                        self.describe_ri_status,
                                        'Idle', response_json['RouterInterfaceId']):
                return response_json
        except ServerException as e:
            ExceptionHandler.server_exception(e)
        except ClientException as e:
            ExceptionHandler.client_exception(e)
示例#2
0
def set_https_listener_attribute(params):
    '''
    set_https_listener_attribute:修改HTTPS监听的配置
    官网API参考链接: https://help.aliyun.com/document_detail/27603.html
    '''
    counter = 0
    while counter < TRY_TIME:
        try:
            request = SetLoadBalancerHTTPSListenerAttributeRequest.SetLoadBalancerHTTPSListenerAttributeRequest(
            )
            # 负载均衡实例的ID
            request.set_LoadBalancerId(params["load_balancer_id"])
            # 监听的带宽峰值
            request.set_Bandwidth(params["bandwidth"])
            # 负载均衡实例前端使用的端口
            request.set_ListenerPort(params["listener_port"])
            # 是否开启健康检查
            request.set_HealthCheck(params["health_check"])
            # 是否开启会话保持
            request.set_StickySession(params["sticky_session"])
            # 服务器证书的ID
            request.set_ServerCertificateId(params["server_certificate_id"])
            # 发送调用请求并接收返回数据
            response = ACS_CLIENT.do_action_with_exception(request)
            response_json = json.loads(response)
            # 返回结果
            return response_json
        except ServerException as e:
            ExceptionHandler.server_exception(e)
        except ClientException as e:
            ExceptionHandler.client_exception(e)
        finally:
            counter += 1
    def create_virtual_border_router(self, params):
        """
        create_virtual_border_router: 新建边界路由器
        官网API参考: https://help.aliyun.com/document_detail/36023.html
        """
        try:
            request = CreateVirtualBorderRouterRequest.CreateVirtualBorderRouterRequest()
            # 物理专线的ID
            request.set_PhysicalConnectionId(params['physical_connection_id'])
            # VBR的阿里云侧互联IP
            request.set_LocalGatewayIp(params['local_gateway_ip'])
            # VBR专线侧接口对端的IP地址
            request.set_PeerGatewayIp(params['peer_gateway_ip'])
            # VBR的阿里云侧和客户侧互联IP的子网掩码
            request.set_PeeringSubnetMask(params['peering_subnet_mask'])
            # VBR的VLAN ID
            request.set_VlanId(params['vlan_id'])

            response = self.client.do_action_with_exception(request)
            response_json = json.loads(response)
            # 判断Vbr状态是否可用
            if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,
                                        self.describe_vbr_status,
                                        'active', response_json['VbrId']):
                return response_json
        except ServerException as e:
            ExceptionHandler.server_exception(e)
        except ClientException as e:
            ExceptionHandler.client_exception(e)
def create_alarm(params):
    '''
    create_alarm:创建报警规则,可以为某一个实例创建报警规则,也可以为多个实例同时创建报警规则
    官网API参考链接: https://help.aliyun.com/document_detail/51910.html
    '''
    counter = 0
    while counter < TRY_TIME:
        try:
            request = CreateAlarmRequest.CreateAlarmRequest()

            # 产品名称,参考各产品对应的project
            request.set_Namespace(params["name_space"])
            # 报警规则名称
            request.set_Name(params["name"])
            # 相应产品对应的监控项名称,参考各产品metric定义
            request.set_MetricName(params["metric_name"])
            # 报警规则对应实例列表
            request.set_Dimensions(params["dimensions"])
            # 统计方法,必须与定义的metric一致
            request.set_Statistics(params["statistics"])
            # 报警比较符
            request.set_ComparisonOperator(params["comparison_operator"])
            # 报警阈值,目前只开放数值类型功能
            request.set_Threshold(params["threshold"])
            response = ACS_CLIENT.do_action_with_exception(request)
            response_json = json.loads(response)
            return response_json
        except ServerException as e:
            ExceptionHandler.server_exception(e)
        except ClientException as e:
            ExceptionHandler.client_exception(e)
        finally:
            counter += 1
 def create_route_entry(self, params):
     """
     create_route_entry: 创建route_entry路由条目
     官网API参考链接: https://help.aliyun.com/document_detail/36012.html
     """
     try:
         request = CreateRouteEntryRequest.CreateRouteEntryRequest()
         # 路由表ID
         request.set_RouteTableId(params['route_table_id'])
         # 自定义路由条目的目标网段
         request.set_DestinationCidrBlock(params['destination_cidr_block'])
         # 下一跳的类型
         request.set_NextHopType(params['nexthop_type'])
         # 下一跳实例的ID
         request.set_NextHopId(params['nexthop_id'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断router entry状态是否可用
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,
                                     self.describe_route_entry_status,
                                     AVAILABLE, params['route_table_id']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
 def modify_router_interface_attribute(self, params):
     """
     modify_router_interface_attribute: 修改路由器接口的配置
     官网API参考: https://help.aliyun.com/document_detail/36036.html
     """
     try:
         request = ModifyRouterInterfaceAttributeRequest.ModifyRouterInterfaceAttributeRequest()
         # 路由器接口的ID
         request.set_RouterInterfaceId(params['router_interface_id'])
         # 对端路由器接口ID
         request.set_OppositeInterfaceId(params['opposite_interface_id'])
         # 对端的路由器的ID
         request.set_OppositeRouterId(params['opposite_router_id'])
         # 对端的路由器的类型
         request.set_OppositeRouterType(params['opposite_router_type'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断Router Interface状态是否可用
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,
                                     self.describe_ri_status,
                                     'Idle', params['router_interface_id']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
示例#7
0
 def unassociate_eip_address(self, params):
     """
     unassociate_eip_address: 将EIP从绑定的云资源上解绑。
     官网API参考: https://help.aliyun.com/document_detail/36021.html
     """
     try:
         request = UnassociateEipAddressRequest.UnassociateEipAddressRequest(
         )
         # EIP的ID
         request.set_AllocationId(params['allocation_id'])
         # 要解绑的资源类型
         request.set_InstanceType(params['instance_type'])
         # 要解绑的云产品的实例ID
         request.set_InstanceId(params['instance_id'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,
                                     self.describe_eip_status, AVAILABLE,
                                     params['allocation_id']):
             return response_json
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
示例#8
0
 def create_tcp_listener(self, params):
     '''
     create_tcp_listener:创建tcp监听
     官网API参考链接: https://help.aliyun.com/document_detail/27594.html
     '''
     counter = 0
     while counter < TRY_TIME:
         try:
             request = CreateLoadBalancerTCPListenerRequest.CreateLoadBalancerTCPListenerRequest(
             )
             # 负载均衡实例的ID
             request.set_LoadBalancerId(params["load_balancer_id"])
             # 监听的带宽峰值
             request.set_Bandwidth(params["bandwidth"])
             # 负载均衡实例前端使用的端口
             request.set_ListenerPort(params["listener_port"])
             # 负载均衡实例后端使用的端口
             request.set_BackendServerPort(params["backend_server_port"])
             response = self.client.do_action_with_exception(request)
             response_json = json.loads(response)
             return response_json
         except ServerException as e:
             ExceptionHandler.server_exception(e)
         except ClientException as e:
             ExceptionHandler.client_exception(e)
         finally:
             counter += 1
def create_load_balancer_clone(params):
    '''
    create_load_balancer:创建slb实例
    官网API参考链接:https://help.aliyun.com/document_detail/27577.html
    '''
    counter = 0
    while counter < TRY_TIME:
        try:
            request = CreateLoadBalancerRequest.CreateLoadBalancerRequest()
            # 主可用区
            request.set_MasterZoneId(params["master_zone_id"])
            # 备可用区
            request.set_SlaveZoneId(params["slave_zone_id"])
            # 付费类型
            request.set_PayType(params["pay_balancer_type"])
            # 资源组id
            request.set_ResourceGroupId(params["resource_group_id"])
            # 负载均衡实例的ip版本
            request.set_AddressIPVersion(params["address_ip_version"])
            # 负载均衡实例的网络类型
            request.set_AddressType(params["address_type"])
            # 实例名称
            request.set_LoadBalancerName(params["load_balancer_name"])
            response = ACS_CLIENT.do_action_with_exception(request)
            response_json = json.loads(response)
            return response_json
        except ServerException as e:
            ExceptionHandler.server_exception(e)
        except ClientException as e:
            ExceptionHandler.client_exception(e)
        finally:
            counter += 1
示例#10
0
def upload_server_certificate(params):
    '''
    upload_server_certificate:上传服务器证书
    官网API参考链接: https://help.aliyun.com/document_detail/34181.html
    '''
    counter = 0
    while counter < TRY_TIME:
        try:
            request = UploadServerCertificateRequest.UploadServerCertificateRequest(
            )
            # 要上传的公钥证书
            request.set_ServerCertificate(params["server_certificate"])
            # 需要上传的私钥
            request.set_PrivateKey(params["private_key"])
            # 发送调用请求并接收返回数据
            response = ACS_CLIENT.do_action_with_exception(request)
            response_json = json.loads(response)
            # 返回结果
            return response_json
        except ServerException as e:
            ExceptionHandler.server_exception(e)
        except ClientException as e:
            ExceptionHandler.client_exception(e)
        finally:
            counter += 1
示例#11
0
 def create_route_table(self, params):
     """
     create_route_table: 创建一个自定义路由表
     官网API参考链接: https://help.aliyun.com/document_detail/87586.html
     """
     try:
         request = CreateRouteEntryRequest.CreateRouteEntryRequest()
         request.set_action_name("CreateRouteTable")
         # 自定义路由表所属的VPC ID
         request.add_query_param("VpcId", params['vpc_id'])
         # 路由表的名称
         request.add_query_param("RouteTableName",
                                 params['route_table_name'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         route_table_id = response_json['RouteTableId']
         # 判断route table状态是否可用
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME * 5,
                                     self.describe_route_table_status,
                                     route_table_id, route_table_id):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
示例#12
0
 def delete_load_balancer(self, params):
     try:
         request = DeleteLoadBalancerRequest.DeleteLoadBalancerRequest()
         request.set_LoadBalancerId(params["load_balancer_id"])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
示例#13
0
    def create_load_balancer_private(self, pay_type, name, vpc_id, vswitch_id):
        try:
            request = CreateLoadBalancerRequest.CreateLoadBalancerRequest()
            request.set_PayType(pay_type)
            request.set_LoadBalancerName(name)
            request.set_VpcId(vpc_id)
            request.set_VSwitchId(vswitch_id)
            response = self.client.do_action_with_exception(request)

            response_json = json.loads(response)
            return response_json
        except ServerException as e:
            ExceptionHandler.server_exception(e)
        except ClientException as e:
            ExceptionHandler.client_exception(e)
 def describe_nat_gateway(self, nat_gateway_id):
     """
     describe_nat_gateway: 查询指定地域已创建的nat gateway的信息
     官网API参考: https://help.aliyun.com/document_detail/36054.html
     """
     try:
         request = DescribeNatGatewaysRequest.DescribeNatGatewaysRequest()
         request.set_NatGatewayId(nat_gateway_id)
         response = client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
 def describe_route_entry(self, route_table_id):
     """
     describe_route_entry: 查询route_entry路由条目
     官网API参考链接: https://help.aliyun.com/document_detail/36014.html
     """
     try:
         request = DescribeRouteTablesRequest.DescribeRouteTablesRequest()
         request.set_RouteTableId(route_table_id)
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
 def describe_vpc_attribute(self, vpc_id):
     """
     describe_vpc_status: 查询指定地域已创建的vpc的状态
     官网API参考: https://help.aliyun.com/document_detail/94565.html
     """
     try:
         request = DescribeVpcAttributeRequest.DescribeVpcAttributeRequest()
         # 要查询的VPC ID
         request.set_VpcId(vpc_id)
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
 def delete_vpc(self, params):
     """
     delete_vpc:删除vpc
     官网API参考链接: https://help.aliyun.com/document_detail/35738.html
     """
     try:
         request = DeleteVpcRequest.DeleteVpcRequest()
         # 要删除的VPC的ID
         request.set_VpcId(params['vpc_id'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
示例#18
0
def remove_backend_servers(params):
    '''
    add_backend_servers:删除后端服务器
    官网API参考链接: https://help.aliyun.com/document_detail/27633.html
    '''
    counter = 0
    while counter < TRY_TIME:
        try:
            request = RemoveBackendServersRequest.RemoveBackendServersRequest()
            #负载均衡实例的ID
            request.set_LoadBalancerId(params["load_balancer_id"])
            #要删除的后端服务器列表
            request.set_BackendServers(params["backend_servers"])
            response = client.do_action_with_exception(request)

            response_json = json.loads(response)
            return response_json
        except ServerException as e:
            if ExceptionHandler.server_exception(e):
                return e
        except ClientException as e:
            if ExceptionHandler.client_exception(e):
                return e
        finally:
            counter += 1
 def describe_forward(self, forward_table_id):
     """
     describe_forward: 查询指定地域已创建的dnat的信息
     官网API参考: https://help.aliyun.com/document_detail/36053.html
     """
     try:
         request = DescribeForwardTableEntriesRequest.DescribeForwardTableEntriesRequest(
         )
         request.set_ForwardTableId(forward_table_id)
         response = client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
示例#20
0
 def describe_eip_address(self, allocation_id):
     """
     describe_eip_status: 查询指定地域已创建的EIP。
     官网API参考: https://help.aliyun.com/document_detail/36018.html
     """
     try:
         request = DescribeEipAddressesRequest.DescribeEipAddressesRequest()
         # EIP的ID
         request.set_AllocationId(allocation_id)
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
示例#21
0
 def release_eip_address(self, params):
     """
     release_eip_address: 释放指定的EIP。
     官网API参考: https://help.aliyun.com/document_detail/36020.html
     """
     try:
         request = ReleaseEipAddressRequest.ReleaseEipAddressRequest()
         # 要释放的弹性公网IP的ID
         request.set_AllocationId(params['allocation_id'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
 def describe_snat(self, snat_table_id):
     """
     describe_snat: 查询指定地域已创建的snat的信息
     官网API参考: https://help.aliyun.com/document_detail/42677.html
     """
     try:
         request = DescribeSnatTableEntriesRequest.DescribeSnatTableEntriesRequest(
         )
         request.set_SnatTableId(snat_table_id)
         response = client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
示例#23
0
 def describe_vswitch_attribute(self, vswitch_id):
     """
     describe_vswitch_attribute: 查询指定地域已创建的vswitch的状态
     官网API参考: https://help.aliyun.com/document_detail/36010.html
     """
     try:
         request = DescribeVSwitchAttributesRequest.DescribeVSwitchAttributesRequest(
         )
         request.set_VSwitchId(vswitch_id)
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
def create_tcp_listener(params):
    '''
    create_tcp_listener:创建tcp监听
    官网API参考链接: https://help.aliyun.com/document_detail/27594.html
    '''
    counter = 0
    while counter < TRY_TIME:
        try:
            # 设置创建TCP监听的调用参数
            request = CreateLoadBalancerTCPListenerRequest.CreateLoadBalancerTCPListenerRequest(
            )
            # 负载均衡实例的ID
            request.set_LoadBalancerId(params["load_balancer_id"])
            # 负载均衡实例前端使用的端口
            request.set_ListenerPort(params["listener_port"])
            # 负载均衡实例后端使用的端口
            request.set_BackendServerPort(params["backend_server_port"])
            # 监听的健康检查协议
            request.set_HealthCheckType(params["listener_health_check"])
            # 设置监听的带宽峰值
            request.set_Bandwidth(params["listener_bandwidth"])
            # 发送调用请求并接收返回数据
            response = ACS_CLIENT.do_action_with_exception(request)
            response_json = json.loads(response)
            # 返回结果
            return response_json
        except ServerException as e:
            if ExceptionHandler.server_exception(e):
                return e
        except ClientException as e:
            if ExceptionHandler.client_exception(e):
                return e
        finally:
            counter += 1
def delete_load_balancer(load_balancer_id):
    '''
    delete_load_balancer:删除slb实例
    官网API参考链接:https://help.aliyun.com/document_detail/27579.html
    '''
    try:
        request = DeleteLoadBalancerRequest.DeleteLoadBalancerRequest()
        # 负载均衡实例的ID
        request.set_LoadBalancerId(load_balancer_id)
        response = ACS_CLIENT.do_action_with_exception(request)
        response_json = json.loads(response)
        return response_json
    except ServerException as e:
        ExceptionHandler.server_exception(e)
    except ClientException as e:
        ExceptionHandler.client_exception(e)
示例#26
0
def add_backend_servers(params):
    '''
    add_backend_servers:添加后端服务器
    官网API参考链接: https://help.aliyun.com/document_detail/27632.html
    '''
    counter = 0
    while counter < TRY_TIME:
        try:
            # 设置添加默认服务器组的调用参数
            request = AddBackendServersRequest.AddBackendServersRequest()
            # 负载均衡实例的ID
            request.set_LoadBalancerId(params["load_balancer_id"])
            # 要添加的后端服务器列表
            request.set_BackendServers(params["backend_servers"])
            # 发送调用请求并接收返回数据
            response = ACS_CLIENT.do_action_with_exception(request)
            response_json = json.loads(response)
            # 返回结果
            return response_json
        except ServerException as e:
            if ExceptionHandler.server_exception(e):
                return e
        except ClientException as e:
            if ExceptionHandler.client_exception(e):
                return e
        finally:
            counter += 1
示例#27
0
 def allocate_eip_address(self, params):
     """
     allocate_eip_address: 申请弹性公网IP(EIP)
     官网API参考: https://help.aliyun.com/document_detail/36016.html
     """
     try:
         request = AllocateEipAddressRequest.AllocateEipAddressRequest()
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,
                                     self.describe_eip_status, AVAILABLE,
                                     response_json["AllocationId"]):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
 def create_vpc(self):
     """
     create_vpc:创建vpc
     官网API参考链接: https://help.aliyun.com/document_detail/35737.html
     """
     try:
         request = CreateVpcRequest.CreateVpcRequest()
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断Vpc状态是否可用
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,
                                     self.describe_vpc_status, AVAILABLE,
                                     response_json['VpcId']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
 def describe_route_entry_vrouter(self, params):
     """
     describe_route_entry_vrouter: 查询route_entry路由条目
     官网API参考链接: https://help.aliyun.com/document_detail/36014.html
     """
     try:
         request = DescribeRouteTablesRequest.DescribeRouteTablesRequest()
         # 路由表所属的VPC路由器或边界路由器的ID
         request.set_VRouterId(params['vrouter_id'])
         # 路由表的ID
         request.set_RouteTableId(params['route_table_id'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
 def describe_router_interface(self, instance_id):
     """
     describe_router_interface: 查询指定地域内的路由器接口
     官网API参考: https://help.aliyun.com/document_detail/36035.html
     """
     try:
         request = DescribeRouterInterfacesRequest.DescribeRouterInterfacesRequest()
         # 查询的过滤类型
         request.add_query_param('Filter.1.Key', "RouterInterfaceId")
         # 查询的实例ID
         request.add_query_param('Filter.1.Value.1', instance_id)
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)