def security_group_exists(self, sg_id=None, name=None):
    """
    Checks if a security group already exists on this connection, by name or by ID.

    :param boto.ec2.EC2Connection self: Current connection.
    :param string sg_id: ID of the security group to check. Default : None.
    :param string name: Name of the security group to check. Default : None.

    :return: True if the security group is present, False otherwise
    :rtype: bool
    """
    if sg_id:
        return sg_id in [sg.id for sg in self.get_all_security_groups()]
    elif name:
        return name in [sg.name for sg in self.get_all_security_groups()]