Example #1
0
 def remove_member(group_name, users):
     _validate_blacklist_groups(group_name, users)
     user_options = ['--users={}'.format(user) for user in users]
     ipa_command = 'group-remove-member'
     args = [group_name] + user_options
     try:
         ipa_utils.ipa_run(ipa_command, args, error_in_stdout=True)
         utils.display_success()
         utils.run_post_command_script('POST_MEMBER_REMOVE_SCRIPT', builtins.list(users))
     except IpaRunError:
         _diagnose_member_command_error(group_name, users, add_command=False)
Example #2
0
 def add_member(hostgroup_name, hosts):
     _validate_blacklist_hostgroups(hostgroup_name, hosts)
     host_options = ['--hosts={}'.format(host) for host in hosts]
     ipa_command = 'hostgroup-add-member'
     args = [hostgroup_name] + host_options
     try:
         ipa_utils.ipa_run(ipa_command, args, error_in_stdout=True)
         utils.display_success()
     except IpaRunError:
         _diagnose_member_command_error(hostgroup_name,
                                        hosts,
                                        add_command=True)
Example #3
0
        def remove_member():
            click.echo('Please enter the name of the group you wish to remove from:')
            group = click.prompt('  Group name')
            _validate_blacklist_groups(group)

            click.echo(
                'Please enter the user(s) you wish to remove from %s, separated'
                ' by spaces:' % group
            )
            users = click.prompt('  User(s)').split()
            user_options = ['--users={}'.format(user) for user in users]

            args = [group] + user_options
            try:
                ipa_utils.ipa_run('group-remove-member', args, error_in_stdout=True)
                utils.display_success()
                utils.run_post_command_script('POST_MEMBER_REMOVE_SCRIPT', users)
            except IpaRunError:
                _diagnose_member_command_error(group, users, add_command=False)
    def ipa_wrapper(**validated_params):
        # This method is called by both Click as a callback and manually for the simple commands.
        # Using a defaultdict allows for handling these params in the same way regardless of
        # how this method is called.
        validated_params = defaultdict(lambda: None, validated_params)

        # Get argument if present; the other params are options.
        argument = validated_params.pop(argument_name)

        # At somepoint during processing of the options, seemingly in click.Option, the '-' in ip-address
        #   is being replaced with an underscore
        # I couldn't work out why so this is a messy fix for the time being
        if 'ip_address' in validated_params:
            validated_params['ip-address'] = validated_params['ip_address']
            del validated_params['ip_address']

        options = validated_params

        args = _build_ipa_args(
            argument,
            options=options,
            transform_options_callback=transform_options_callback)

        # if the command is modify host & there's only one item in the args list it's neccesary not to call
        #   the ipa command as a) the option to modify it wouldn't do anything anyway and b) it would result
        #   in a spurious error message if the --ip-address option has been removed in transform_options_callback
        if not (ipa_command == "host-mod" and len(args) == 1):
            # want to check if attempting user-add with creation script but that script isn't usable
            #   before completing the user-add
            if (ipa_command == "user-add" and utils.get_user_config('POST_CREATE_SCRIPT') \
                and (not utils.detect_user_config \
                or not os.access(utils.get_user_config('POST_CREATE_SCRIPT'), os.X_OK))\
            ):
                raise click.ClickException(
                    "User create script unavailable - you need permissions to execute '{}' or alter your user config."
                    .format(utils.get_user_config('POST_CREATE_SCRIPT')))
            result = ipa_utils.ipa_run(ipa_command, args)
            utils.display_success()
            handle_result_callback(argument, options, result)