Exemple #1
0
def list_securitygroups(call=None):
    """
    Return all Tencent Cloud security groups in current region

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_securitygroups my-tencentcloud-config
    """
    if call == "action":
        raise SaltCloudSystemExit(
            "The list_securitygroups function must be called with -f or --function."
        )

    client = get_provider_client("vpc_client")
    req = vpc_models.DescribeSecurityGroupsRequest()
    req.Offset = 0
    req.Limit = 100
    resp = client.DescribeSecurityGroups(req)

    ret = {}
    for sg in resp.SecurityGroupSet:
        ret[sg.SecurityGroupId] = {
            "SecurityGroupName": sg.SecurityGroupName,
            "SecurityGroupDesc": sg.SecurityGroupDesc,
            "ProjectId": sg.ProjectId,
            "IsDefault": sg.IsDefault,
            "CreatedTime": sg.CreatedTime,
        }

    return ret
Exemple #2
0
def show_sg_info(sg_name):
    try:
        sg_params = {
            "Filters": [{
                "Name": "security-group-name",
                "Values": sg_name
            }]
        }
        req = vpc_models.DescribeSecurityGroupsRequest()
        req.from_json_string(json.dumps(sg_params))

        resp = vpc_client.DescribeSecurityGroups(req)
        sg_info = json.loads(resp.to_json_string())["SecurityGroupSet"]
        return sg_info
    except TencentCloudSDKException as err:
        print(err)
Exemple #3
0
 def describe_security_groups(self, region):
     client = vpc_client.VpcClient(self.credential, region, self.profile(self.SERVICE_NAME))
     req = vpc_models.DescribeSecurityGroupsRequest()
     req.from_json_string('{}')
     return json.loads(client.DescribeSecurityGroups(req).to_json_string())['SecurityGroupSet']