コード例 #1
0
 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)
コード例 #2
0
    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)
コード例 #3
0
 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)
コード例 #4
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)
コード例 #5
0
    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)
コード例 #6
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)
コード例 #7
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)
コード例 #8
0
 def delete_virtual_border_router(self, params):
     """
     delete_virtual_border_router: 删除边界路由器
     官网API参考: https://help.aliyun.com/document_detail/40542.html
     """
     try:
         request = DeleteVirtualBorderRouterRequest.DeleteVirtualBorderRouterRequest()
         request.set_VbrId(params['vbr_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_vbr_status,
                                     '', params['vbr_id']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
コード例 #9
0
 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)
コード例 #10
0
 def delete_nat_gateway(self, params):
     """
     delete_nat_gateway: 删除nat gateway
     官网API参考: https://help.aliyun.com/document_detail/36051.html
     """
     try:
         request = DeleteNatGatewayRequest.DeleteNatGatewayRequest()
         request.set_NatGatewayId(params['nat_gateway_id'])
         response = client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断Nat Gateway状态是否可用
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME * 5,
                                     self.describe_nat_gateway_status, '',
                                     params['nat_gateway_id']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
コード例 #11
0
 def connect_router_interface(self, params):
     """
     connect_router_interface: 由发起端路由器接口向接收端发起连接
     官网API参考: https://help.aliyun.com/document_detail/36031.html
     """
     try:
         request = ConnectRouterInterfaceRequest.ConnectRouterInterfaceRequest()
         # 发起端路由器接口的ID
         request.set_RouterInterfaceId(params['router_interface_id'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         if CheckStatus.check_status(TIME_DEFAULT_OUT * 5, DEFAULT_TIME * 5,
                                     self.describe_ri_status,
                                     'Active', params['router_interface_id']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
コード例 #12
0
 def delete_snat_entry(self, params):
     """
     delete_snat_entry: 删除snat entry
     官网API参考: https://help.aliyun.com/document_detail/42678.html
     """
     try:
         request = DeleteSnatEntryRequest.DeleteSnatEntryRequest()
         request.set_SnatTableId(params['snat_table_id'])
         request.set_SnatEntryId(params['snat_entry_id'])
         response = client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断Snat Entry状态是否可用
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME * 5,
                                     self.describe_snat_status, '',
                                     params['snat_table_id']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
コード例 #13
0
 def delete_vswitch(self, params):
     """
     delete_vswitch: 删除vswitch实例
     官网API参考: https://help.aliyun.com/document_detail/35746.html
     """
     try:
         request = DeleteVSwitchRequest.DeleteVSwitchRequest()
         # 要删除的交换机的ID
         request.set_VSwitchId(params['vswitch_id'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断VSwitch是否被删除成功
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME * 5,
                                     self.describe_vswitch_status, '',
                                     params['vswitch_id']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
コード例 #14
0
 def deactivate_router_interface(self, params):
     """
     deactivate_router_interface: 冻结路由器接口
     官网API参考: https://help.aliyun.com/document_detail/36033.html
     """
     try:
         request = DeactivateRouterInterfaceRequest.DeactivateRouterInterfaceRequest()
         # 路由器接口的ID
         request.set_RouterInterfaceId(params['router_interface_id'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断Router Interface状态是否可用
         if CheckStatus.check_status(TIME_DEFAULT_OUT * 5, DEFAULT_TIME * 5,
                                     self.describe_ri_status,
                                     'Inactive', params['router_interface_id']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
コード例 #15
0
 def create_nat_gateway(self, params):
     """
     create_nat_gateway: 创建nat gateway
     官网API参考: https://help.aliyun.com/document_detail/36048.html
     """
     try:
         request = CreateNatGatewayRequest.CreateNatGatewayRequest()
         request.set_VpcId(params['vpc_id'])
         response = client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断Nat Gateway状态是否可用
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,
                                     self.describe_nat_gateway_status,
                                     AVAILABLE,
                                     response_json['NatGatewayId']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
コード例 #16
0
 def create_snat_entry(self, params):
     """
     describe_snat: 创建snat entry
     官网API参考: https://help.aliyun.com/document_detail/42672.html
     """
     try:
         request = CreateSnatEntryRequest.CreateSnatEntryRequest()
         request.set_SnatTableId(params['snat_table_id'])
         request.set_SourceVSwitchId(params['vswitch_id'])
         request.set_SnatIp(params['snat_ip'])
         response = client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断Snat Entry状态是否可用
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,
                                     self.describe_snat_status, AVAILABLE,
                                     params['snat_table_id']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
コード例 #17
0
 def delete_route_table(self, params):
     """
     delete_route_table: 删除自定义路由表
     官网API参考链接: https://help.aliyun.com/document_detail/87601.html
     """
     try:
         request = DeleteRouteEntryRequest.DeleteRouteEntryRequest()
         request.set_action_name("DeleteRouteTable")
         # 路由表ID
         request.add_query_param("RouteTableId", params['route_table_id'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断route table是否被删除成功
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME * 5,
                                     self.describe_route_table_status,
                                     '', params['route_table_id']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
コード例 #18
0
 def create_forward_entry(self, params):
     """
     create_forward_entry: 创建forward entry
     官网API参考: https://help.aliyun.com/document_detail/36058.html
     """
     try:
         request = CreateForwardEntryRequest.CreateForwardEntryRequest()
         request.set_ForwardTableId(params['forward_table_id'])
         request.set_ExternalIp(params['external_ip'])
         request.set_IpProtocol(params['ip_protocol'])
         request.set_ExternalPort(params['external_port'])
         request.set_InternalIp(params['internal_ip'])
         request.set_InternalPort(params['internal_port'])
         response = client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断Forward Entry状态是否可用
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,
                                     self.describe_forward_status,
                                     AVAILABLE, params['forward_table_id']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)
コード例 #19
0
 def create_vswitch(self, params):
     """
     create_vswitch: 创建vpc实例
     官网API参考: https://help.aliyun.com/document_detail/35745.html
     """
     try:
         request = CreateVSwitchRequest.CreateVSwitchRequest()
         # 交换机所属区的ID,您可以通过调用DescribeZones接口获取地域ID
         request.set_ZoneId(params['zone_id'])
         # 交换机所属的VPC ID
         request.set_VpcId(params['vpc_id'])
         # 交换机的网段
         request.set_CidrBlock(params['cidr_block'])
         response = self.client.do_action_with_exception(request)
         response_json = json.loads(response)
         # 判断VSwitch状态是否可用
         if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,
                                     self.describe_vswitch_status,
                                     AVAILABLE, response_json['VSwitchId']):
             return response_json
     except ServerException as e:
         ExceptionHandler.server_exception(e)
     except ClientException as e:
         ExceptionHandler.client_exception(e)