def RequestIngress(cred): try: client = new_vpc_client(cred=cred, method="POST") req = vpc_models.ModifySecurityGroupPoliciesRequest() reqPolicyset = vpc_models.SecurityGroupPolicySet() # reqPolicyset.Version="2" reqPolicyset.Ingress = [vpc_models.SecurityGroupPolicy()] reqPolicyset.Egress = [vpc_models.SecurityGroupPolicy()] # reqPolicyset.Ingress.append() reqPolicyset.Ingress[0].CidrBlock = "117.172.9.99" # reqPolicyset.Ingress[0].Port=22 # reqPolicyset.Ingress[0].PolicyIndex="1" req.SecurityGroupPolicySet = reqPolicyset # print(reqPolicyset.to_json_string()) req.SecurityGroupId = "sg-hc7qsa1z" print(req.to_json_string()) # respFilter = vpc_models.Filter() # respFilter.Name = "zone" # respFilter.Values = ['ap-guangzhou-3','ap-guangzhou-2'] # resp = client.DescribeSecurityGroupPolicies(req) resp = client.ModifySecurityGroupPolicies(req) if os.getenv('API_JSON_INFO') == "1": resp = client.ModifySecurityGroupPolicies(req) apiinfo(resp.to_json_string()) except TencentCloudSDKException as err: print(err)
def describeIns(cred): try: # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey # cred = credential.Credential( # os.environ.get("TENCENTCLOUD_SECRET_ID"), # os.environ.get("TENCENTCLOUD_SECRET_KEY")) client = new_cvm_client(cred=cred, method="GET") req = cvm_models.DescribeInstancesRequest() respFilter = cvm_models.Filter() respFilter.Name = "zone" respFilter.Values = ['ap-guangzhou-3', 'ap-guangzhou-2'] resp = client.DescribeInstances(req) if os.getenv('API_JSON_INFO'): apiinfo("Json Response") print(resp.to_json_string()) # return(resp.to_json_string()) return (resp) except TencentCloudSDKException as err: # print(err) pass
def updateIngress(cred, host_ip): apidebug(host_ip.decode()) try: client = new_vpc_client(cred=cred, method="POST") httpProfile = HttpProfile() httpProfile.endpoint = "vpc.ap-guangzhou.tencentcloudapi.com" clientProfile = ClientProfile() clientProfile.httpProfile = httpProfile client = vpc_client.VpcClient(cred, "ap-guangzhou", clientProfile) req = vpc_models.ReplaceSecurityGroupPolicyRequest() req.from_json_string(params) req.SecurityGroupPolicySet.Ingress[0].CidrBlock = str(host_ip.decode()) req.SecurityGroupPolicySet.Version = '11' resp = client.ReplaceSecurityGroupPolicy(req) if os.getenv('API_JSON_INFO') == "1": # resp = client.ReplaceSecurityGroupPolicy(req) apiinfo(resp.to_json_string()) return resp except TencentCloudSDKException as err: print(err)
def modifySec(host_ip, *key): # apidebug(key) client = AcsClient(key[0], key[1], 'cn-beijing') request = CommonRequest() request.set_accept_format('json') request.set_domain('ecs.aliyuncs.com') request.set_method('POST') request.set_version('2014-05-26') request.set_action_name('AuthorizeSecurityGroup') request.add_query_param('RegionId', 'cn-beijing') request.add_query_param('SecurityGroupId', 'sg-2zeiafyiu5nh8zsuy1u6') request.add_query_param('IpProtocol', 'tcp') request.add_query_param('PortRange', '22/22') # request.add_query_param('SourceCidrIp', '223.87.240.203') # host_ip = key[2] apiinfo(host_ip) request.add_query_param('SourceCidrIp', host_ip) request.add_query_param('Policy', 'accept') request.add_query_param('Priority', '1') response = client.do_action_with_exception(request) apiinfo(response) # python2: print(response) # print(str(response, encoding = 'utf-8')) return response
def describeSec(*key): def deserialize(param): param = json.loads(param) top = objectview(param) permissions_param = top.Permissions Permissions = objectview(permissions_param.copy()) if permissions_param.get('Permission') is not None: Permissions.Permission = [] for item in permissions_param.get('Permission'): item = objectview(item) Permissions.Permission.append(item) # apidebug(Permissions.Permission[0]) top.Permissions = Permissions return top # def util(): # Permission=[] # Permission.append(objectview(param)) # apidebug(key) client = AcsClient(key[0], key[1], 'cn-beijing') request = CommonRequest() request.set_accept_format('json') request.set_domain('ecs.aliyuncs.com') request.set_method('POST') request.set_version('2014-05-26') request.set_action_name('DescribeSecurityGroupAttribute') request.add_query_param('RegionId', 'cn-beijing') request.add_query_param('SecurityGroupId', 'sg-2zeiafyiu5nh8zsuy1u6') resp_jsonByte = client.do_action_with_exception(request) if os.environ.get("API_JSON_INFO") == "1": apiinfo("Json Response") print(str(resp_jsonByte, encoding='utf-8')) # resp_param=json.loads(resp_jsonByte.decode()) resp_json = deserialize(resp_jsonByte.decode()) # apiinfo(resp_json.Permissions.Permission[0].SourceCidrIp) # apidebug(resp_json.) return resp_json
def describeIns(*key): def deserialize(param): param = json.loads(param) top = objectview(param) instances_param = top.Instances Instances = objectview(instances_param.copy()) if instances_param.get('Instance') is not None: Instances.Instance = [] for item in instances_param.get('Instance'): item = objectview(item) Instances.Instance.append(item) # apidebug(Permissions.Permission[0]) top.Instances = Instances return top apidebug(key) client = AcsClient(key[0], key[1], 'cn-beijing') request = CommonRequest() request.set_accept_format('json') request.set_domain('ecs.aliyuncs.com') request.set_method('POST') request.set_version('2014-05-26') request.set_action_name('DescribeInstances') resp_jsonByte = client.do_action_with_exception(request) if os.environ.get("API_JSON_INFO") == "1": apiinfo("Json Response") print(str(resp_jsonByte, encoding='utf-8')) resp_json = deserialize(resp_jsonByte.decode()) return resp_json