Esempio n. 1
0
def backend_modify(cc, args):
    db_backends = cc.storage_backend.list()
    backend_entry = next(
        (b for b in db_backends if ((b.name == args.backend_name_or_uuid) or (
            b.uuid == args.backend_name_or_uuid))), None)
    if not backend_entry:
        raise exc.CommandError("Backend %s is not found." %
                               args.backend_name_or_uuid)

    # filter out arg noise: Only relevant fields
    allowed_fields = ['services', 'ceph_conf']

    # filter the args.passed to backend creation
    fields = dict((k, v) for (k, v) in vars(args).items()
                  if k in allowed_fields and not (v is None))

    # Load command line attributes to pass to backend modify
    # REST API will ignore the cruft
    attr_dict = dict(
        s.split('=') for s in vars(args).get('attributes', []) if '=' in s)

    # non-capability, backend specific attributes
    backend = backend_entry.backend

    if backend in constants.SB_SUPPORTED:
        backend_attrs = getattr(eval('storage_' + backend.replace("-", "_")),
                                'PATCH_ATTRIBUTES')
        allowed_fields += backend_attrs
        for k, v in attr_dict.items():
            if k in backend_attrs:
                fields[k] = v

    # Move tha rest of the attributes to the capabilities, used for hiera data
    # overrides
    capabilities = {}
    for k, v in attr_dict.items():
        if k not in allowed_fields:
            capabilities[k] = v

    patch = []
    patch = utils.dict_to_patch(fields)
    patch.append({
        'path': '/capabilities',
        'value': jsonutils.dumps(capabilities),
        'op': 'replace'
    })

    try:
        backend_client = getattr(cc, 'storage_' + backend.replace("-", "_"))
        backend_entry = backend_client.update(backend_entry.uuid, patch)

    except exc.HTTPNotFound:
        raise exc.CommandError('Storage %s not found: %s' %
                               (backend, backend_entry.uuid))

    backend_show(cc, backend_entry.uuid)
def do_service_disable(cc, args):
    """Disable optional service"""
    values = {'enabled': False}
    patch = utils.dict_to_patch(values)
    try:
        response = cc.sm_service.update(args.service, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('service not recognized: %s' % args.service)
    except exc.Forbidden:
        raise exc.CommandError("Not authorized. The requested action "
                               "requires 'admin' level")