Exemplo n.º 1
0
 def bootstrap_with_global_options(self, parser=None, context=None):
     parser = self.build_global_parser(parser, context)
     (options, args) = parser.parse_args()
     overrides = {}
     if options.env is not None:
         assert type(options.env) is list
         for item in options.env:
             try:
                 values = item.split('=', 1)
             except ValueError:
                 # FIXME: this should raise an IPA exception with an
                 # error code.
                 # --Jason, 2008-10-31
                 pass
             if len(values) == 2:
                 (key, value) = values
                 overrides[str(key.strip())] = value.strip()
             else:
                 raise errors.OptionError(
                     _('Unable to parse option {item}'.format(item=item)))
     for key in ('conf', 'debug', 'verbose', 'prompt_all', 'interactive',
                 'fallback', 'delegate'):
         value = getattr(options, key, None)
         if value is not None:
             overrides[key] = value
     if hasattr(options, 'prod'):
         overrides['webui_prod'] = options.prod
     if context is not None:
         overrides['context'] = context
     self.bootstrap(parser, **overrides)
     return (options, args)
Exemplo n.º 2
0
    def execute(self, *keys, **options):
        dn = self.obj.get_dn(*keys, **options)
        validate_domain_level(self.api)

        entry = self.obj.backend.get_entry(dn, [
            'nsds5beginreplicarefresh;left', 'nsds5beginreplicarefresh;right'
        ])

        left = options.get('left')
        right = options.get('right')
        stop = options.get('stop')

        if not left and not right:
            raise errors.OptionError(
                _('left or right node has to be specified'))

        if left and right:
            raise errors.OptionError(_('only one node can be specified'))

        action = u'start'
        msg = _('Replication refresh for segment: "%(pkey)s" requested.')
        if stop:
            action = u'stop'
            msg = _('Stopping of replication refresh for segment: "'
                    '%(pkey)s" requested.')

        # left and right are swapped because internally it's a push not
        # pull operation
        if right:
            entry['nsds5beginreplicarefresh;left'] = [action]
        if left:
            entry['nsds5beginreplicarefresh;right'] = [action]

        self.obj.backend.update_entry(entry)

        msg = msg % {'pkey': keys[-1]}
        return dict(
            result=True,
            value=msg,
        )
Exemplo n.º 3
0
def has_cli_options(cmd, options, no_option_msg, allow_empty_attrs=False):
    sufficient = ('setattr', 'addattr', 'delattr', 'rename')
    if any(k in options for k in sufficient):
        return

    has_options = False
    for attr in options.keys():
        obj_params = [n for n in cmd.params
                      if get_record_rrtype(n) or get_part_rrtype(n)]
        if attr in obj_params:
            if options[attr] or allow_empty_attrs:
                has_options = True
                break

    if not has_options:
        raise errors.OptionError(no_option_msg)
Exemplo n.º 4
0
class test_ping(Declarative):

    tests = [
        dict(
            desc='Ping the server',
            command=('ping', [], {}),
            expected=dict(
                summary=Fuzzy('IPA server version .*. API version .*')),
        ),
        dict(
            desc='Try to ping with an argument',
            command=('ping', ['bad_arg'], {}),
            expected=errors.ZeroArgumentError(name='ping'),
        ),
        dict(
            desc='Try to ping with an option',
            command=('ping', [], dict(bad_arg=True)),
            expected=errors.OptionError(_('Unknown option: %(option)s'),
                                        option='bad_arg'),
        ),
    ]
Exemplo n.º 5
0
 def test_ping_with_option(self):
     """Try to ping with an option."""
     with raises_exact(
             errors.OptionError(_('Unknown option: %(option)s'),
                                option='bad_arg')):
         self.tracker.run_command('ping', bad_arg=True)