def main(): load_balancer = LoadBalancer(client) tcp_listener = TcpListener(client) params = {} params["bandwidth"] = BANDWIDTH_NOT_LIMITED params["listener_port"] = 443 params["backend_server_port"] = 443 #创建slb实例 load_balancer_json = load_balancer.create_load_balancer() CommonUtil.log("create_load_balancer", load_balancer_json) params["load_balancer_id"] = load_balancer_json["LoadBalancerId"] params["LoadBalancerName"] = load_balancer_json["LoadBalancerName"] #添加tcp监听 result_json = tcp_listener.create_tcp_listener(params) CommonUtil.log("create_tcp_listener", result_json) #查询slb实例 result_json = describe_load_balancer_attribute(params) CommonUtil.log("describe_load_balancer_attribute", result_json) #创建slb实例 result_json = create_load_balancer(params) CommonUtil.log("create_load_balancer", result_json) #删除slb实例 result_json = load_balancer.delete_load_balancer(params) CommonUtil.log("delete_load_balancer", result_json)
def main(): load_balancer = LoadBalancer(client) params = {} params["backend_servers"] = [{ "ServerId": ECS_INSTANCE_ID, "Weight": "100" }] params["bandwidth"] = BANDWIDTH_NOT_LIMITED params["listener_port"] = 443 params["backend_server_port"] = 443 #创建slb实例 load_balancer_json = load_balancer.create_load_balancer() CommonUtil.log("create_load_balancer", load_balancer_json) #slb实例id params["load_balancer_id"] = load_balancer_json["LoadBalancerId"] #添加后端服务器 load_balancer_json = add_backend_servers(params) CommonUtil.log("add_backend_servers", load_balancer_json) #创建tcp监听 load_balancer_json = create_tcp_listener(params) CommonUtil.log("create_tcp_listener", load_balancer_json) #删除后端服务器 load_balancer_json = remove_backend_servers(params) CommonUtil.log("remove_backend_servers", load_balancer_json) #删除slb实例 load_balancer_json = load_balancer.delete_load_balancer(params) CommonUtil.log("delete_load_balancer", load_balancer_json)
def main(): # 设置创建SLB的实例参数值 params = {} # 设置新建SLB实例的主可用区为cn-zhangjiakou-a params["master_zone_id"] = "cn-zhangjiakou-a" # 设置新建SLB实例的主可用区为cn-zhangjiakou-b params["slave_zone_id"] = "cn-zhangjiakou-b" # 设置新建SLB实例的名称为SLB1 params["load_balancer_name"] = "SLB1" # 设置新建SLB实例的计费类型为按量计费 params["pay_balancer_type"] = "PayOnDemand" # 设置新建SLB实例的规格为slb.s1.small params["load_balancer_spec"] = "slb.s1.small" # 监听的带宽峰值为6Mbps params["balancer_listener_bandwith"] = "1" # 创建slb实例 # 获取create_load_balancer函数返回值,load_balancer_json为结果的json串 load_balancer_json = create_load_balancer(params) # 打印 load_balancer_json结果,其中"create_load_balancer"是对json串起的名字 CommonUtil.log("create_load_balancer", load_balancer_json) # 删除slb实例 # 删除返回的LoadBalancerId对应的SLB实例 load_balancer_json = delete_load_balancer( load_balancer_json["LoadBalancerId"]) # 打印 load_balancer_json结果 CommonUtil.log("delete_load_balancer", load_balancer_json)
def main(): params = {} # 设置创建SLB实例的参数 # 设置新建SLB实例的主可用区为cn-zhangjiakou-a params["master_zone_id"] = "cn-zhangjiakou-a" # 设置新建SLB实例的主可用区为cn-zhangjiakou-b params["slave_zone_id"] = "cn-zhangjiakou-b" # 设置新建SLB实例的名称为SLB1 params["load_balancer_name"] = "SLB1" # 设置新建SLB实例的计费类型为按量计费 params["pay_balancer_type"] = "PayOnDemand" # 设置新建SLB实例的规格为slb.s1.small params["load_balancer_spec"] = "slb.s1.small" # 设置添加到默认服务器组的ECS的实例ID和权重 params["backend_servers"] = [{ "ServerId": "i-8vbe8yi8krxxxxxxxxxxw", "Weight": "100" }, { "ServerId": "i-8vbe8yi8kccxxxxxxxxxv", "Weight": "100" }] # 设置添加TCP监听的参数 # 前端使用的端口为80 params["listener_port"] = 80 # 后端服务器开放用来接收请求的端口为80 params["backend_server_port"] = 80 # 健康检查协议为TCP params["listener_health_check"] = "tcp" # TCP监听的带宽峰值为-1,即不限制带宽峰值 params["listener_bandwidth"] = -1 # 创建slb实例 # 获取create_load_balancer函数返回值,load_balancer_json为结果的json串 load_balancer_json = create_load_balancer(params) # 打印 load_balancer_json结果,其中"create_load_balancer"是对json串起的名字 CommonUtil.log("create_load_balancer", load_balancer_json) # slb实例id params["load_balancer_id"] = load_balancer_json["LoadBalancerId"] # 添加后端服务器 load_balancer_json = add_backend_servers(params) CommonUtil.log("add_backend_servers", load_balancer_json) # 创建tcp监听 load_balancer_json = create_tcp_listener(params) CommonUtil.log("create_tcp_listener", load_balancer_json) # 删除后端服务器 load_balancer_json = remove_backend_servers(params) CommonUtil.log("remove_backend_servers", load_balancer_json) # 删除slb实例 # 删除返回的LoadBalancerId对应的SLB实例 load_balancer_json = delete_load_balancer( load_balancer_json["LoadBalancerId"]) # 打印 load_balancer_json结果 CommonUtil.log("delete_load_balancer", load_balancer_json)
def main(): router_interface = RouterInterface(client) route_entry = RouteEntry(client) params = {} params['spec'] = "Large.2" params['role'] = "InitiatingSide" params['router_id'] = ROUTER_ID params['router_type'] = "VRouter" params['opposite_region_id'] = "cn-hangzhou" params['opposite_router_type'] = "VRouter" # 创建发起端ri router_interface_json = router_interface.create_router_interface(params) CommonUtil.log("create_router_interface", router_interface_json) # 创建接收端ri params['spec'] = "Negative" params['role'] = "AcceptingSide" params['router_id'] = ROUTER_ID2 router_interface_json2 = router_interface.create_router_interface(params) CommonUtil.log("create_router_interface", router_interface_json2) # 修改发起端ri信息 params['router_interface_id'] = router_interface_json['RouterInterfaceId'] params['opposite_interface_id'] = router_interface_json2['RouterInterfaceId'] params['opposite_router_id'] = ROUTER_ID2 modify_ri_json = router_interface.modify_router_interface_attribute(params) CommonUtil.log("modify_router_interface_attribute", modify_ri_json) # 修改接收端ri信息 params['router_interface_id'] = router_interface_json2['RouterInterfaceId'] params['opposite_interface_id'] = router_interface_json['RouterInterfaceId'] params['opposite_router_id'] = ROUTER_ID modify_ri_json2 = router_interface.modify_router_interface_attribute(params) CommonUtil.log("modify_router_interface_attribute", modify_ri_json2) # 查询发起端ri信息 describe_ri_json = router_interface.describe_router_interface(router_interface_json['RouterInterfaceId']) CommonUtil.log("describe_router_interface", describe_ri_json) # 查询接收端ri信息 describe_ri_json2 = router_interface.describe_router_interface(router_interface_json2['RouterInterfaceId']) CommonUtil.log("describe_router_interface", describe_ri_json2) # 发起连接 params['router_interface_id'] = router_interface_json['RouterInterfaceId'] connect_ri_json = router_interface.connect_router_interface(params) CommonUtil.log("connect_router_interface", connect_ri_json) # 创建下一跳为发起端ri的路由条目 params['route_table_id'] = TABLE_ID params['destination_cidr_block'] = "0.0.0.0/0" params['nexthop_type'] = 'RouterInterface' params['nexthop_id'] = router_interface_json['RouterInterfaceId'] route_entry_json = route_entry.create_route_entry(params) CommonUtil.log("create_route_entry", route_entry_json) # 创建下一跳为接收端ri的路由条目 params['route_table_id'] = TABLE_ID2 params['destination_cidr_block'] = "0.0.0.0/0" params['nexthop_type'] = 'RouterInterface' params['nexthop_id'] = router_interface_json2['RouterInterfaceId'] route_entry_json2 = route_entry.create_route_entry(params) CommonUtil.log("create_route_entry", route_entry_json2) # 删除下一跳为接收端ri的路由条目 route_entry_json = route_entry.delete_route_entry(params) CommonUtil.log("delete_route_entry", route_entry_json) # 删除下一跳为发起端ri的路由条目 params['route_table_id'] = TABLE_ID params['nexthop_id'] = router_interface_json['RouterInterfaceId'] route_entry_json = route_entry.delete_route_entry(params) CommonUtil.log("delete_route_entry", route_entry_json) # 冻结发起端ri params['router_interface_id'] = router_interface_json['RouterInterfaceId'] deactivate_ri_json = router_interface.deactivate_router_interface(params) CommonUtil.log("deactivate_router_interface", deactivate_ri_json) # 冻结接收端ri params['router_interface_id'] = router_interface_json2['RouterInterfaceId'] deactivate_ri_json2 = router_interface.deactivate_router_interface(params) CommonUtil.log("deactivate_router_interface", deactivate_ri_json2) # 删除发起端ri params['instance_id'] = router_interface_json['RouterInterfaceId'] router_interface_json = router_interface.delete_router_interface(params) CommonUtil.log("delete_router_interface", router_interface_json) # 删除接收端ri params['instance_id'] = router_interface_json2['RouterInterfaceId'] router_interface_json2 = router_interface.delete_router_interface(params) CommonUtil.log("delete_router_interface", router_interface_json2)
def main(): params = {} # 设置创建SLB实例的参数 # 设置新建SLB实例的主可用区为cn-zhangjiakou-a params["master_zone_id"] = "cn-zhangjiakou-a" # 设置新建SLB实例的主可用区为cn-zhangjiakou-b params["slave_zone_id"] = "cn-zhangjiakou-b" # 设置新建SLB实例的名称为SLB1 params["load_balancer_name"] = "SLB1" # 设置新建SLB实例的计费类型为按量计费 params["pay_balancer_type"] = "PayOnDemand" # 设置添加到默认服务器组的ECS的实例ID和权重 params["backend_servers"] = [{ "ServerId": "i-8vbe8yixxxxxxxxxxxxxw", "Weight": "100" }, { "ServerId": "i-8vbe8yxxxxxxxxxxxxxj9v", "Weight": "100" }] # 设置上传服务器证书的参数 # 设置创建HTTPS监听的参数 # 关闭健康检查 params["health_check"] = "off" # 设置监听的带宽峰值 params["bandwidth"] = 6 # 负载均衡实例前端使用的端口 params["listener_port"] = 80 # 设置负载均衡实例后端使用的端口 params["backend_server_port"] = 443 # 关闭会话保持 params["sticky_session"] = "off" # 创建slb实例 # 获取create_load_balancer函数返回值,load_balancer_json为结果的json串 load_balancer_json = create_load_balancer(params) # 打印 load_balancer_json结果,其中"create_load_balancer"是对json串起的名字 CommonUtil.log("create_load_balancer", load_balancer_json) # 上传服务器证书 # 要上传的公钥证书 params[ "server_certificate"] = "-----BEGIN CERTIFICATE-----xxxxxxx-----END CERTIFICATE-----" params[ "private_key"] = "-----BEGIN RSA PRIVATE KEY-----xxxxxxxxxxx-----END RSA PRIVATE KEY-----" result_json = upload_server_certificate(params) CommonUtil.log("upload_server_certificate", result_json) params["server_certificate_id"] = result_json["ServerCertificateId"] # slb实例id params["load_balancer_id"] = load_balancer_json["LoadBalancerId"] # 创建https监听 result_json = create_https_listener(params) CommonUtil.log("create_https_listener", result_json) # 上传新的服务器证书 # 要上传的新公钥证书 params[ "server_certificate"] = "-----BEGIN CERTIFICATE-----xxxxxxx-----END CERTIFICATE-----" params[ "private_key"] = "-----BEGIN RSA PRIVATE KEY-----xxxxxxxxxxx-----END RSA PRIVATE KEY-----" result_json = upload_server_certificate(params) CommonUtil.log("upload_server_certificate", result_json) params["server_certificate_id"] = result_json["ServerCertificateId"] # 修改https监听配置 result_json = set_https_listener_attribute(params) CommonUtil.log("set_https_listener_attribute", result_json) # 删除slb实例 # 删除返回的LoadBalancerId对应的SLB实例 load_balancer_json = delete_load_balancer( load_balancer_json["LoadBalancerId"]) # 打印 load_balancer_json结果 CommonUtil.log("delete_load_balancer", load_balancer_json)
def main(): params = {} # 设置创建SLB实例的参数 # 设置新建SLB实例的主可用区为cn-zhangjiakou-a params["master_zone_id"] = "cn-zhangjiakou-a" # 设置新建SLB实例的主可用区为cn-zhangjiakou-b params["slave_zone_id"] = "cn-zhangjiakou-b" # 设置新建SLB实例的名称为SLB1 params["load_balancer_name"] = "SLB1" # 设置新建SLB实例的计费类型为按量计费 params["pay_balancer_type"] = "PayOnDemand" # 设置添加到默认服务器组的ECS的实例ID和权重 params["backend_servers"] = [{ "ServerId": "i-8vbe8xxxxxxxxxxxw", "Weight": "100" }, { "ServerId": "i-8vbe8yixxxxxxxxxxxxv", "Weight": "100" }] # 设置添加TCP监听的参数 # 前端使用的端口为80 params["listener_port"] = 80 # 后端服务器开放用来接收请求的端口为80 params["backend_server_port"] = 80 # 健康检查协议为TCP params["listener_health_check"] = "tcp" # TCP监听的带宽峰值为-1,即不限制带宽峰值 params["listener_bandwidth"] = -1 # 设置查询监控项的参数 # 设置监控数据所属产品 params["project"] = "acs_slb_dashboard" # 设置监控项名称 params["traffic_tx_new"] = "InstanceQpsUtilization" # 设置创建告警的参数 # 设置告警规则所属产品 params["name_space"] = "acs_slb_dashboard" # 设置告警规则名称 params["name"] = "slb_alarm" # 设置告警中SLB对应的监控项名称 params["metric_name"] = "InstanceQpsUtilization" # 设置统计方法 params["statistics"] = "Average" # 设置报警比较符 params["comparison_operator"] = ">=" # 设置报警阈值 params["threshold"] = 35 # 创建slb实例 # 获取create_load_balancer函数返回值,load_balancer_json为结果的json串 load_balancer_json = create_load_balancer(params) # 打印 load_balancer_json结果,其中"create_load_balancer"是对json串起的名字 CommonUtil.log("create_load_balancer", load_balancer_json) # slb实例id params["load_balancer_id"] = load_balancer_json["LoadBalancerId"] # 创建tcp监听 result_json = create_tcp_listener(params) CommonUtil.log("create_tcp_listener", result_json) # 创建后端服务器 result_json = add_backend_servers(params) CommonUtil.log("add_backend_servers", result_json) # 查询slb实例QPS使用率 params["dimensions"] = '[{"instanceId":"' + load_balancer_json[ "LoadBalancerId"] + '"}]' result_json = query_metric_last(params) CommonUtil.log("query_metric_last", result_json) # 创建告警规则 params["metric_name"] = "InstanceQpsUtilization" result_json = create_alarm(params) CommonUtil.log("create_alarm", result_json) # 删除slb实例 # 删除返回的LoadBalancerId对应的SLB实例 load_balancer_json = delete_load_balancer( load_balancer_json["LoadBalancerId"]) # 打印 load_balancer_json结果 CommonUtil.log("delete_load_balancer", load_balancer_json)
def main(): router_interface = RouterInterface(client) route_entry = RouteEntry(client) params = {} params['spec'] = "Large.2" params['role'] = "InitiatingSide" params['router_type'] = "VBR" params['opposite_region_id'] = "cn-hangzhou" params['opposite_router_type'] = "VRouter" params['access_point_id'] = "ap-cn-hangzhou-xs-B" # 创建边界路由器vbr params['physical_connection_id'] = PC_ID params['local_gateway_ip'] = "116.62.204.254" params['peer_gateway_ip'] = "116.62.204.254" params['peering_subnet_mask'] = "255.255.255.252" params['vlan_id'] = 30 vbr_json = router_interface.create_virtual_border_router(params) CommonUtil.log("create_virtual_border_router", vbr_json) # 创建发起端ri params['router_id'] = vbr_json['VbrId'] router_interface_json = router_interface.create_router_interface_vbr(params) CommonUtil.log("create_router_interface", router_interface_json) # 创建接收端ri params['router_type'] = "VRouter" params['spec'] = "Negative" params['role'] = "AcceptingSide" params['router_id'] = ROUTER_ID2 params['opposite_router_type'] = 'VBR' params['opposite_access_point_id'] = params['access_point_id'] router_interface_json2 = router_interface.create_router_interface(params) CommonUtil.log("create_router_interface", router_interface_json2) # 修改发起端ri信息 params['router_interface_id'] = router_interface_json['RouterInterfaceId'] params['opposite_interface_id'] = router_interface_json2['RouterInterfaceId'] params['opposite_router_id'] = ROUTER_ID2 params['opposite_router_type'] = "VRouter" modify_ri_json = router_interface.modify_router_interface_attribute(params) CommonUtil.log("modify_router_interface_attribute", modify_ri_json) # 修改接收端ri信息 params['router_interface_id'] = router_interface_json2['RouterInterfaceId'] params['opposite_interface_id'] = router_interface_json['RouterInterfaceId'] params['opposite_router_id'] = vbr_json['VbrId'] params['opposite_router_type'] = "VBR" modify_ri_json2 = router_interface.modify_router_interface_attribute(params) CommonUtil.log("modify_router_interface_attribute", modify_ri_json2) # 查询发起端ri信息 describe_ri_json = router_interface.describe_router_interface(router_interface_json['RouterInterfaceId']) CommonUtil.log("describe_router_interface", describe_ri_json) # 查询接收端ri信息 describe_ri_json2 = router_interface.describe_router_interface(router_interface_json2['RouterInterfaceId']) CommonUtil.log("describe_router_interface", describe_ri_json2) # 查询VBR的路由表ID params['router_id'] = vbr_json['VbrId'] params['router_type'] = 'VBR' route_table_json = router_interface.describe_route_table(params) CommonUtil.log("describe_route_table", route_table_json) # 发起连接 params['router_interface_id'] = router_interface_json['RouterInterfaceId'] connect_ri_json = router_interface.connect_router_interface(params) CommonUtil.log("connect_router_interface", connect_ri_json) # 创建下一跳为发起端ri的路由条目 params['route_table_id'] = route_table_json["RouteTables"]["RouteTable"][0]["RouteTableId"] params['destination_cidr_block'] = "0.0.0.0/0" params['nexthop_type'] = 'RouterInterface' params['nexthop_id'] = router_interface_json['RouterInterfaceId'] route_entry_json = route_entry.create_route_entry(params) CommonUtil.log("create_route_entry", route_entry_json) # 创建下一跳为接收端ri的路由条目 params['route_table_id'] = TABLE_ID2 params['destination_cidr_block'] = "0.0.0.0/0" params['nexthop_type'] = 'RouterInterface' params['nexthop_id'] = router_interface_json2['RouterInterfaceId'] route_entry_json2 = route_entry.create_route_entry(params) CommonUtil.log("create_route_entry", route_entry_json2) # 删除下一跳为接收端ri的路由条目 route_entry_json = route_entry.delete_route_entry(params) CommonUtil.log("delete_route_entry", route_entry_json) # 删除下一跳为发起端ri的路由条目 params['route_table_id'] = route_table_json["RouteTables"]["RouteTable"][0]["RouteTableId"] params['nexthop_id'] = router_interface_json['RouterInterfaceId'] route_entry_json = route_entry.delete_route_entry(params) CommonUtil.log("delete_route_entry", route_entry_json) # 冻结发起端ri params['router_interface_id'] = router_interface_json['RouterInterfaceId'] deactivate_ri_json = router_interface.deactivate_router_interface(params) CommonUtil.log("deactivate_router_interface", deactivate_ri_json) # 冻结接收端ri params['router_interface_id'] = router_interface_json2['RouterInterfaceId'] deactivate_ri_json2 = router_interface.deactivate_router_interface(params) CommonUtil.log("deactivate_router_interface", deactivate_ri_json2) # 删除发起端ri params['instance_id'] = router_interface_json['RouterInterfaceId'] router_interface_json = router_interface.delete_router_interface(params) CommonUtil.log("delete_router_interface", router_interface_json) # 删除接收端ri params['instance_id'] = router_interface_json2['RouterInterfaceId'] router_interface_json2 = router_interface.delete_router_interface(params) CommonUtil.log("delete_router_interface", router_interface_json2) # 删除边界路由器vbr params['vbr_id'] = vbr_json['VbrId'] vbr_json = router_interface.delete_virtual_border_router(params) CommonUtil.log("delete_virtual_border_router", vbr_json)
def main(): vpc = Vpc(client) vswitch = VSwitch(client) eip = Eip(client) cbwp = CommonBandwidthPackage(client) nat_gateway = NatGateway(client) params = {} # 创建vpc vpc_json = vpc.create_vpc() CommonUtil.log("create_vpc", vpc_json) # 创建vswitch params['vpc_id'] = vpc_json['VpcId'] params['zone_id'] = "cn-hangzhou-d" params['cidr_block'] = "172.16.1.0/24" vswitch_json = vswitch.create_vswitch(params) CommonUtil.log("create_vswitch", vswitch_json) params['vswitch_id'] = vswitch_json['VSwitchId'] # 创建natgw nat_gateway_json = nat_gateway.create_nat_gateway(params) CommonUtil.log("create_nat_gateway", nat_gateway_json) # 创建EIP eip_response_json = eip.allocate_eip_address(params) CommonUtil.log("allocate_eip_address", eip_response_json) params['allocation_id'] = eip_response_json["AllocationId"] params['snat_ip'] = eip_response_json['EipAddress'] # 绑定EIP到NAT网关 params['instance_id'] = nat_gateway_json['NatGatewayId'] params['allocation_id'] = eip_response_json["AllocationId"] params['instance_type'] = 'Nat' eip_response_json = eip.associate_eip_address(params) CommonUtil.log("associate_eip_address eip", eip_response_json) # 创建snat entry params['snat_table_id'] = nat_gateway_json['SnatTableIds']['SnatTableId'][ 0] snat_entry_json = nat_gateway.create_snat_entry(params) CommonUtil.log("create_snat_entry", snat_entry_json) # 查询EIP eip_response_json = eip.describe_eip_address(params['allocation_id']) CommonUtil.log("describe_eip_address", eip_response_json) # 查询natgw params['nat_gateway_id'] = nat_gateway_json['NatGatewayId'] nat_gateway_json = nat_gateway.describe_nat_gateway( params['nat_gateway_id']) CommonUtil.log("describe_nat_gateway", nat_gateway_json) # 删除snat entry params['snat_entry_id'] = snat_entry_json['SnatEntryId'] snat_entry_json = nat_gateway.delete_snat_entry(params) CommonUtil.log("delete_snat_entry", snat_entry_json) # 解绑EIP eip_response_json = eip.unassociate_eip_address(params) CommonUtil.log("unassociate_eip_address nat", eip_response_json) # 删除natgw nat_gateway_json = nat_gateway.delete_nat_gateway(params) CommonUtil.log("delete_nat_gateway", nat_gateway_json) # 释放EIP eip_response_json = eip.release_eip_address(params) CommonUtil.log("release_eip_address", eip_response_json) # 删除vswitch params['vswitch_id'] = vswitch_json['VSwitchId'] vswitch_json = vswitch.delete_vswitch(params) CommonUtil.log("delete_vswitch", vswitch_json) # 删除vpc vpc_json = vpc.delete_vpc(params) CommonUtil.log("delete_vpc", vpc_json)
def main(): params = {} params["backend_servers"] = [{"ServerId": ECS_INSTANCE_ID, "Weight": "100"}] params["bandwidth"] = BANDWIDTH_NOT_LIMITED params["listener_port"] = 443 params["backend_server_port"] = 443 params["project"] = "acs_slb_dashboard" params["traffic_tx_new"] = "TrafficTXNew" params["name_space"] = "acs_slb_dashboard" params["name"] = "slb_alarm" params["metric_name"] = "TrafficTXNew" params["statistics"] = "Average" params["comparison_operator"] = "<=" params["threshold"] = 35 load_balancer = LoadBalancer(client) tcp_listener = TcpListener(client) #创建slb实例 load_balancer_json = load_balancer.create_load_balancer() CommonUtil.log("create_load_balancer", load_balancer_json) #slb实例id params["load_balancer_id"] = load_balancer_json["LoadBalancerId"] #创建tcp监听 result_json = tcp_listener.create_tcp_listener(params) CommonUtil.log("create_tcp_listener", result_json) #创建后端服务器 result_json = add_backend_servers(params) CommonUtil.log("add_backend_servers", result_json) #查询slb实例端口当前并发连接数 params["metric_name"] = "MaxConnection" params["dimensions"] = '[{"instanceId":"' + load_balancer_json["LoadBalancerId"] + '"}]' result_json = query_metric_last(params) CommonUtil.log("query_metric_last", result_json) #创建告警规则 params["metric_name"] = "TrafficTXNew" result_json = create_alarm(params) CommonUtil.log("create_alarm", result_json) #删除slb实例 result_json = load_balancer.delete_load_balancer(params) CommonUtil.log("delete_load_balancer", result_json)
def main(): params = {} # 设置创建SLB实例的参数 # 设置新建SLB实例的主可用区为cn-zhangjiakou-a params["master_zone_id"] = "cn-zhangjiakou-a" # 设置新建SLB实例的主可用区为cn-zhangjiakou-b params["slave_zone_id"] = "cn-zhangjiakou-b" # 设置新建SLB实例的名称为SLB1 params["load_balancer_name"] = "SLB1" # 设置新建SLB实例的计费类型为按量计费 params["pay_balancer_type"] = "PayOnDemand" # 设置新建SLB实例的规格为slb.s1.small params["load_balancer_spec"] = "slb.s1.small" # 设置添加到默认服务器组的ECS的实例ID和权重 params["backend_servers"] = [{"ServerId": "i-8vxxxxx", "Weight": "100"}, {"ServerId": "i-8vbe8xxxxxxxv", "Weight": "100"}] # 设置添加TCP监听的参数 # 前端使用的端口为80 params["listener_port"] = 80 # 后端服务器开放用来接收请求的端口为80 params["backend_server_port"] = 80 # 健康检查协议为TCP params["listener_health_check"] = "tcp" # TCP监听的带宽峰值为-1,即不限制带宽峰值 params["listener_bandwidth"] = -1 # 创建slb实例 # 获取create_load_balancer函数返回值,load_balancer_json为结果的json串 result_json = create_load_balancer(params) # 打印 load_balancer_json结果,其中"create_load_balancer"是对json串起的名字 CommonUtil.log("create_load_balancer", result_json) # 读取新建SLB实例的ID和名称 load_balancer_id = result_json["LoadBalancerId"] params["load_balancer_id"] = load_balancer_id params["LoadBalancerName"] = result_json["LoadBalancerName"] # 创建tcp监听 result_json = create_tcp_listener(params) CommonUtil.log("create_tcp_listener", result_json) # 查询slb实例 result_json = describe_load_balancer_attribute(params) CommonUtil.log("describe_load_balancer_attribute", result_json) # 需要显示的查询新建SLB实例信息 params["master_zone_id"] = result_json["MasterZoneId"] params["slave_zone_id"] = result_json["SlaveZoneId"] params["pay_balancer_type"] = result_json["PayType"] params["resource_group_id"] = result_json["ResourceGroupId"] params["address_ip_version"] = result_json["AddressIPVersion"] params["address_type"] = result_json["AddressType"] params["load_balancer_name"] = result_json["LoadBalancerName"] # 根据SLB1的配置,克隆一个新的实例 result_json = create_load_balancer_clone(params) CommonUtil.log("create_load_balancer_clone", result_json) # 读取克隆实例ID clone_load_balancer_id = result_json["LoadBalancerId"] # 删除第一个实例 # 删除返回的LoadBalancerId对应的SLB实例 result_json = delete_load_balancer(load_balancer_id) # 打印 load_balancer_json结果 CommonUtil.log("delete_load_balancer", result_json) # 查询克隆出来的实例信息 params["load_balancer_id"] = clone_load_balancer_id result_json = describe_load_balancer_attribute(params) CommonUtil.log("describe_load_balancer_attribute", result_json) # 删除克隆出来的实例 # 删除返回的LoadBalancerId对应的SLB实例 result_json = delete_load_balancer(clone_load_balancer_id) # 打印 load_balancer_json结果 CommonUtil.log("delete_load_balancer", result_json)
def main(): client = ACS_CLIENT vpc = Vpc(client) vswitch = VSwitch(client) route_table = RouteTable(client) params = {} params['cidr_block'] = "172.16.1.0/24" params['zone_id'] = "cn-hangzhou-d" params['route_table_name'] = "sdk_route_table" #创建vpc vpc_json = vpc.create_vpc() CommonUtil.log("create_vpc", vpc_json) #创建vswitch params['vpc_id'] = vpc_json['VpcId'] vswitch_json = vswitch.create_vswitch(params) CommonUtil.log("create_vswitch", vswitch_json) #创建route table route_table_json = route_table.create_route_table(params) CommonUtil.log("create_route_table", route_table_json) #查询vswitch params['vswitch_id'] = vswitch_json['VSwitchId'] vswitch_json = vswitch.describe_vswitch_attribute(params['vswitch_id']) CommonUtil.log("describe_vswitch_attribute", vswitch_json) #route table绑定vswitch params['route_table_id'] = route_table_json['RouteTableId'] associate_json = route_table.associate_route_table(params) CommonUtil.log("associate_route_table", associate_json) #route table解绑vswitch unassociate_json = route_table.unassociate_route_table(params) CommonUtil.log("unassociate_route_table", unassociate_json) #删除route table delete_route_table_json = route_table.delete_route_table(params) CommonUtil.log("delete_route_table", delete_route_table_json) #删除vswitch delete_vswitch_json = vswitch.delete_vswitch(params) CommonUtil.log("delete_vswitch", delete_vswitch_json) #删除vpc delete_vpc_json = vpc.delete_vpc(params) CommonUtil.log("delete_vpc", delete_vpc_json)
def main(): client = ACS_CLIENT eip = Eip(client) params = {} # 创建EIP eip_response_json = eip.allocate_eip_address(params) CommonUtil.log("allocate_eip_address", eip_response_json) # 绑定EIP到ECS params['allocation_id'] = eip_response_json["AllocationId"] params['instance_id'] = ECS_INSTANCE_ID params['instance_type'] = 'EcsInstance' eip_response_json = eip.associate_eip_address(params) CommonUtil.log("associate_eip_address", eip_response_json) # 查询EIP eip_response_json = eip.describe_eip_address(params['allocation_id']) CommonUtil.log("describe_eip_address", eip_response_json) # 修改EIP配置和名字 params['bandwidth'] = BANDWIDTH_50 params['name'] = EIP_NEW_NAME eip_response_json = eip.modify_eip_address(params) CommonUtil.log("modify_eip_address", eip_response_json) # 查询EIP eip_response_json = eip.describe_eip_address(params['allocation_id']) CommonUtil.log("describe_eip_address", eip_response_json) # 解绑EIP eip_response_json = eip.unassociate_eip_address(params) CommonUtil.log("unassociate_eip_address", eip_response_json) # 释放EIP eip_response_json = eip.release_eip_address(params) CommonUtil.log("release_eip_address", eip_response_json)
def main(): client = ACS_CLIENT eip = Eip(client) params = {} # 创建EIP eip_response_json = eip.allocate_eip_address(params) CommonUtil.log("allocate_eip_address", eip_response_json) # 绑定EIP到ECS params['allocation_id'] = eip_response_json["AllocationId"] params['instance_id'] = ECS_INSTANCE_ID params['instance_type'] = 'EcsInstance' eip_response_json = eip.associate_eip_address(params) CommonUtil.log("associate_eip_address", eip_response_json) # 查询EIP eip_response_json = eip.describe_eip_address(params['allocation_id']) CommonUtil.log("describe_eip_address", eip_response_json) # 解绑EIP eip_response_json = eip.unassociate_eip_address(params) CommonUtil.log("unassociate_eip_address", eip_response_json) # 查询EIP eip_response_json = eip.describe_eip_address(params['allocation_id']) CommonUtil.log("describe_eip_address", eip_response_json) # 释放EIP eip_response_json = eip.release_eip_address(params) CommonUtil.log("release_eip_address", eip_response_json)
def main(): client = ACS_CLIENT eip = Eip(client) params = {} # 创建EIP eip_response_json = eip.allocate_eip_address(params) CommonUtil.log("allocate_eip_address", eip_response_json) params['allocation_id'] = eip_response_json["AllocationId"] #修改EIP带宽到50 params['name'] = EIP_NEW_NAME params['bandwidth'] = BANDWIDTH_50 eip_response_json = eip.modify_eip_address(params) CommonUtil.log("modify_eip_address", eip_response_json) # 查询EIP eip_response_json = eip.describe_eip_address(params['allocation_id']) CommonUtil.log("describe_eip_address", eip_response_json) # 修改EIP带宽到10 params['bandwidth'] = BANDWIDTH_10 eip_response_json = eip.modify_eip_address(params) CommonUtil.log("modify_eip_address", eip_response_json) # 查询EIP eip_response_json = eip.describe_eip_address(params['allocation_id']) CommonUtil.log("describe_eip_address", eip_response_json) # 释放EIP eip_response_json = eip.release_eip_address(params) CommonUtil.log("release_eip_address", eip_response_json)
def main(): client = ACS_CLIENT vswitch = VSwitch(client) route_table = RouteTable(client) route_entry = RouteEntry(client) params = {} params['route_table_name'] = "sdk_route_table" params['destination_cidr_block'] = "0.0.0.0/0" params['nexthop_id'] = "i-xxx" params['nexthop_type'] = "Instance" params['vpc_id'] = "vpc-xxx" params['vswitch_id'] = "vsw-xxx" #创建route table route_table_json = route_table.create_route_table(params) CommonUtil.log("create_route_table", route_table_json) #查询vswitch vswitch_json = vswitch.describe_vswitch_attribute(params) CommonUtil.log("describe_vswitch_attribute", vswitch_json) #route table绑定vswitch params['route_table_id'] = route_table_json['RouteTableId'] associate_json = route_table.associate_route_table(params) CommonUtil.log("associate_route_table", associate_json) #创建路由条目 create_route_entry_json = route_entry.create_route_entry(params) CommonUtil.log("create_route_entry", create_route_entry_json) #删除路由条目 delete_route_entry_json = route_entry.delete_route_entry(params) CommonUtil.log("delete_route_entry", delete_route_entry_json) #route table解绑vswitch unassociate_json = route_table.unassociate_route_table(params) CommonUtil.log("unassociate_route_table", unassociate_json) #删除route table delete_route_table_json = route_table.delete_route_table(params) CommonUtil.log("delete_route_table", delete_route_table_json)
def main(): vpc = Vpc(client) vswitch = VSwitch(client) eip = Eip(client) cbwp = CommonBandwidthPackage(client) nat_gateway = NatGateway(client) params = {} # 创建vpc vpc_json = vpc.create_vpc() CommonUtil.log("create_vpc", vpc_json) # 创建vswitch params['vpc_id'] = vpc_json['VpcId'] params['zone_id'] = "cn-hangzhou-d" params['cidr_block'] = "172.16.1.0/24" vswitch_json = vswitch.create_vswitch(params) CommonUtil.log("create_vswitch", vswitch_json) # 创建natgw nat_gateway_json = nat_gateway.create_nat_gateway(params) CommonUtil.log("create_nat_gateway", nat_gateway_json) # 创建EIP eip_response_json = eip.allocate_eip_address(params) CommonUtil.log("allocate_eip_address", eip_response_json) params['allocation_id'] = eip_response_json["AllocationId"] # 绑定EIP到NAT网关 params['instance_id'] = nat_gateway_json['NatGatewayId'] params['allocation_id'] = eip_response_json["AllocationId"] params['instance_type'] = 'Nat' eip_response_json = eip.associate_eip_address(params) CommonUtil.log("associate_eip_address eip", eip_response_json) # 查询EIP eip_response_json = eip.describe_eip_address(params['allocation_id']) CommonUtil.log("describe_eip_address", eip_response_json) # 创建带宽包 params['bandwidth'] = BANDWIDTH_10 cbwp_repsonse_json = cbwp.create_common_bandwidth_package(params) CommonUtil.log("create_common_bandwidth_package", cbwp_repsonse_json) # 添加EIP到共享带宽包中 params['ip_instance_id'] = params['allocation_id'] params['bandwidth_package_id'] = cbwp_repsonse_json['BandwidthPackageId'] cbwp_repsonse_json = cbwp.add_common_bandwidth_packageIp(params) CommonUtil.log("add_common_bandwidth_packageIp", cbwp_repsonse_json) # 查询natgw params['nat_gateway_id'] = nat_gateway_json['NatGatewayId'] nat_gateway_json = nat_gateway.describe_nat_gateway( params['nat_gateway_id']) CommonUtil.log("describe_nat_gateway", nat_gateway_json) # 解绑EIP eip_response_json = eip.unassociate_eip_address(params) CommonUtil.log("unassociate_eip_address nat", eip_response_json) # 移除共享带宽包中的EIP( cbwp_repsonse_json = cbwp.remove_common_bandwidth_packageIp(params) CommonUtil.log("remove_common_bandwidth_packageIp", cbwp_repsonse_json) # 删除共享带宽包 params['force'] = True cbwp_repsonse_json = cbwp.delete_common_bandwidth_package(params) CommonUtil.log("delete_common_bandwidth_package", cbwp_repsonse_json) # 删除natgw nat_gateway_json = nat_gateway.delete_nat_gateway(params) CommonUtil.log("delete_nat_gateway", nat_gateway_json) # 释放EIP eip_response_json = eip.release_eip_address(params) CommonUtil.log("release_eip_address", eip_response_json) # 删除vswitch params['vswitch_id'] = vswitch_json['VSwitchId'] vswitch_json = vswitch.delete_vswitch(params) CommonUtil.log("delete_vswitch", vswitch_json) # 删除vpc vpc_json = vpc.delete_vpc(params) CommonUtil.log("delete_vpc", vpc_json)
def main(): client = ACS_CLIENT eip = Eip(client) load_balancer = LoadBalancer(client) #创建VPC, 创建VSWITCH, 以及调用ECS API生成 ENI params = {} params['vpc_id'] = VPC_ID params['vswitch_id'] = VSWITCH_ID #创建负载均衡 load_balancer_repsonse_json = load_balancer.create_load_balancer_private( params) CommonUtil.log("create_load_balancer", load_balancer_repsonse_json) # 创建EIP params['load_balancer_id'] = load_balancer_repsonse_json['LoadBalancerId'] params['instance_id'] = load_balancer_repsonse_json['LoadBalancerId'] eip_response_json = eip.allocate_eip_address(params) CommonUtil.log("allocate_eip_address slb", eip_response_json) # 绑定EIP到SLB params['allocation_id'] = eip_response_json["AllocationId"] params['instance_type'] = 'SlbInstance' eip_response_json = eip.associate_eip_address(params) CommonUtil.log("associate_eip_address eip", eip_response_json) # 解绑EIP eip_response_json = eip.unassociate_eip_address(params) CommonUtil.log("unassociate_eip_address slb", eip_response_json) # 绑定EIP到ENI params['instance_id'] = ENI_ID params['instance_type'] = 'NetworkInterface' eip_response_json = eip.associate_eip_address(params) CommonUtil.log("associate_eip_address eni", eip_response_json) # 解绑EIP eip_response_json = eip.unassociate_eip_address(params) CommonUtil.log("unassociate_eip_address eni", eip_response_json) # 删除负载均衡实例 load_balancer_repsonse_json = load_balancer.delete_load_balancer(params) CommonUtil.log("delete_load_balancer", load_balancer_repsonse_json)
def main(): vpc = Vpc(client) vswitch = VSwitch(client) nat_gateway = NatGateway(client) params = {} # 创建vpc vpc_json = vpc.create_vpc() CommonUtil.log("create_vpc", vpc_json) # 创建vswitch params['vpc_id'] = vpc_json['VpcId'] params['zone_id'] = "cn-hangzhou-d" params['cidr_block'] = "172.16.1.0/24" vswitch_json = vswitch.create_vswitch(params) CommonUtil.log("create_vswitch", vswitch_json) # 创建natgw nat_gateway_json = nat_gateway.create_nat_gateway(params) CommonUtil.log("create_nat_gateway", nat_gateway_json) # 查询natgw params['nat_gateway_id'] = nat_gateway_json['NatGatewayId'] nat_gateway_json = nat_gateway.describe_nat_gateway( params['nat_gateway_id']) CommonUtil.log("describe_nat_gateway", nat_gateway_json) # 删除natgw nat_gateway_json = nat_gateway.delete_nat_gateway(params) CommonUtil.log("delete_nat_gateway", nat_gateway_json) # 删除vswitch params['vswitch_id'] = vswitch_json['VSwitchId'] vswitch_json = vswitch.delete_vswitch(params) CommonUtil.log("delete_vswitch", vswitch_json) # 删除vpc vpc_json = vpc.delete_vpc(params) CommonUtil.log("delete_vpc", vpc_json)