예제 #1
0
 def __request_security_group(self, security_group_id):
     # if SecurityGroupId not found, server will return 404 and sdk
     # will raise A aliyunsdkcore.acs_exception.exceptions.ServerException
     # this behaviour is not same as DescribeVSwitchAttributesRequest
     # which just return a empty response, so we don't need raise
     # any exceptions here.
     req = DescribeSecurityGroupAttributeRequest.DescribeSecurityGroupAttributeRequest(
     )
     req.set_SecurityGroupId(security_group_id)
     body = self.client.do_action_with_exception(req)
     return json.loads(body.decode("utf-8"))
예제 #2
0
 def describeSecurityGroupAttributeRequest(
         self,
         SecurityGroupId,
         NicType='intranet',
         Direction='ingress'):  # 需要改NicType
     '''查询安全组'''
     request = DescribeSecurityGroupAttributeRequest.DescribeSecurityGroupAttributeRequest(
     )
     request.set_SecurityGroupId(SecurityGroupId)
     request.set_accept_format('json')
     request.set_NicType(NicType)
     request.set_Direction(Direction)
     return request
예제 #3
0
def describe_sg_policy(sg_id, accesskey_id, accesskey_secret, region_id):
    print("Now, the region is " + region_id)
    clt = client.AcsClient(accesskey_id, accesskey_secret, region_id)
    request = DescribeSecurityGroupAttributeRequest.DescribeSecurityGroupAttributeRequest(
    )
    request.set_accept_format('json')
    request.set_SecurityGroupId(sg_id)
    result = clt.do_action_with_exception(request)
    js_str = json.loads(result)
    print "SourceCidrIp    " + "DestCidrIp    " + "Direction    " + "PortRange    " + "IpProtocol    " + "Policy"
    for i in js_str["Permissions"]["Permission"]:
        print i["SourceCidrIp"], "\t", i["DestCidrIp"], "\t", i[
            "Direction"], "\t", i["PortRange"], "\t", i["IpProtocol"], "\t", i[
                "Policy"]
    return
예제 #4
0
def descSecurityGroup(groupId):
    request = DescribeSecurityGroupAttributeRequest.DescribeSecurityGroupAttributeRequest(
    )
    request.set_SecurityGroupId(groupId)
    response = client.do_action_with_exception(request)
    return json.loads(response)
예제 #5
0
body = client.do_action_with_exception(req)
pp.pprint(json.loads(body.decode("utf-8")))

# zone
req = DescribeZonesRequest.DescribeZonesRequest()
body = client.do_action_with_exception(req)
pp.pprint(json.loads(body.decode("utf-8")))

# SecurityGroup
req = DescribeSecurityGroupsRequest.DescribeSecurityGroupsRequest()
req.set_query_params({'PageSize': 50})
body = client.do_action_with_exception(req)
pp.pprint(json.loads(body.decode("utf-8")))

# SecurityGroup id
req = DescribeSecurityGroupAttributeRequest.DescribeSecurityGroupAttributeRequest(
)
req.set_SecurityGroupId("")
body = client.do_action_with_exception(req)
pp.pprint(json.loads(body.decode("utf-8")))

# InstanceType
req = DescribeInstanceTypesRequest.DescribeInstanceTypesRequest()
req.set_query_params({'PageSize': 50})
body = client.do_action_with_exception(req)
pp.pprint(json.loads(body.decode("utf-8")))

# ImageId
req = DescribeImagesRequest.DescribeImagesRequest()
req.set_query_params({'PageSize': 10})
req.set_query_params({'ImageId': ""})
body = client.do_action_with_exception(req)