Esempio n. 1
0
def profile_remove(profile_name, nocheck):
    """
    Remove a profile as long as it does not contain any endpoints.
    Allow user to explicitly remove the profile if desired.
    :param profile_name: The name of the profile to remove.
    :param nocheck: Flag saying to remove profile regardless of endpoints.
    :return: None.
    """
    # Check if the profile exists.
    if client.profile_exists(profile_name):
        rm_profile = False
        # Check that the nocheck flag was used
        if nocheck:
            rm_profile = True
        else:
            # Check if the the profile has endpoints associated with it
            members = client.get_profile_members(profile_name)
            if not members:
                rm_profile = True
        # Remove the profile if criteria was met
        if rm_profile:
            client.remove_profile(profile_name)
            print "Deleted profile %s" % profile_name
        else:
            # Members must exist if this branch is reached
            print "Cannot remove profile - profile in use by endpoint(s).\n" + \
                  "Use the '--no-check' flag to remove the profile anyway."
    else:
        print "Profile %s not found." % profile_name
Esempio n. 2
0
def profile_remove(profile_name, nocheck):
    """
    Remove a profile as long as it does not contain any endpoints.
    Allow user to explicitly remove the profile if desired.
    :param profile_name: The name of the profile to remove.
    :param nocheck: Flag saying to remove profile regardless of endpoints.
    :return: None.
    """
    # Check if the profile exists.
    if client.profile_exists(profile_name):
        rm_profile = False
        # Check that the nocheck flag was used
        if nocheck:
            rm_profile = True
        else:
            # Check if the the profile has endpoints associated with it
            members = client.get_profile_members(profile_name)
            if not members:
                rm_profile = True
        # Remove the profile if criteria was met
        if rm_profile:
            client.remove_profile(profile_name)
            print "Deleted profile %s" % profile_name
        else:
            # Members must exist if this branch is reached
            print "Cannot remove profile - profile in use by endpoint(s).\n" + \
                  "Use the '--no-check' flag to remove the profile anyway."
    else:
        print "Profile %s not found." % profile_name
Esempio n. 3
0
def profile_add(profile_name):
    """
    Create a policy profile with the given name.
    :param profile_name: The name for the profile.
    :return: None.
    """
    # Check if the profile exists.
    if client.profile_exists(profile_name):
        print "Profile %s already exists." % profile_name
    else:
        # Create the profile.
        client.create_profile(profile_name)
        print "Created profile %s" % profile_name
Esempio n. 4
0
def profile_add(profile_name):
    """
    Create a policy profile with the given name.
    :param profile_name: The name for the profile.
    :return: None.
    """
    # Check if the profile exists.
    if client.profile_exists(profile_name):
        print "Profile %s already exists." % profile_name
    else:
        # Create the profile.
        client.create_profile(profile_name)
        print "Created profile %s" % profile_name
Esempio n. 5
0
def validate_profile_list(profile_names):
    """
    Validate a list of profiles.  This checks that each profile name is
    valid and specified only once in the list.

    This method traces and exits upon failure.

    :param profile_names: The list of profiles to check.
    :return: None
    """
    compiled = set()
    for profile_name in profile_names:
        if not client.profile_exists(profile_name):
            print "Profile with name %s was not found." % profile_name
            sys.exit(1)
        if profile_name in compiled:
            print "Profile with name %s was specified more than " \
                  "once." % profile_name
            sys.exit(1)
        compiled.add(profile_name)
Esempio n. 6
0
def validate_profile_list(profile_names):
    """
    Validate a list of profiles.  This checks that each profile name is
    valid and specified only once in the list.

    This method traces and exits upon failure.

    :param profile_names: The list of profiles to check.
    :return: None
    """
    compiled = set()
    for profile_name in profile_names:
        if not client.profile_exists(profile_name):
            print "Profile with name %s was not found." % profile_name
            sys.exit(1)
        if profile_name in compiled:
            print "Profile with name %s was specified more than " \
                  "once." % profile_name
            sys.exit(1)
        compiled.add(profile_name)