Пример #1
0
class MyThingController(pecan.rest.RestController):

    _custom_actions = {
        'no_content': ['GET'],
        'response_content': ['GET'],
        'response_custom_status': ['GET'],
        'ouch': ['GET'],
    }

    @method.expose()
    @args.validate(name=args.string, flag=args.boolean)
    def get(self, name, flag):
        return {name: flag}

    @method.expose()
    def no_content(self):
        api.response.status_code = 204
        return 'nothing'

    @method.expose()
    def response_content(self):
        resp = v1.utils.PassthruResponse('nothing', status_code=200)
        api.response.status_code = resp.status_code
        return resp.obj

    @method.expose(status_code=202)
    def response_custom_status(self):
        return 'accepted'

    @method.expose()
    def ouch(self):
        raise Exception('ouch')

    @method.expose(status_code=201)
    @method.body('body')
    @args.validate(body=args.schema({
        'type': 'object',
        'properties': {
            'three': {
                'type': 'string'
            },
            'four': {
                'type': 'string',
                'maxLength': 4
            },
            'five': {
                'type': 'string'
            },
        },
        'additionalProperties': False,
        'required': ['three']
    }))
    def post(self, body):
        return body
Пример #2
0
class EventsController(pecan.rest.RestController):
    """REST controller for Events."""
    @pecan.expose()
    def _lookup(self):
        if not api_utils.allow_expose_events():
            pecan.abort(http_client.NOT_FOUND)

    @METRICS.timer('EventsController.post')
    @method.expose(status_code=http_client.NO_CONTENT)
    @method.body('evts')
    @args.validate(evts=args.and_valid(args.schema(EVENTS_SCHEMA),
                                       events_valid))
    def post(self, evts):
        if not api_utils.allow_expose_events():
            raise exception.NotFound()
        api_utils.check_policy('baremetal:events:post')
        for e in evts['events']:
            LOG.debug("Received external event: %s", e)
Пример #3
0
            'type': 'string'
        },
        'uuid': {
            'type': ['string', 'null']
        },
    },
    'required': ['boot_index', 'node_uuid', 'volume_id', 'volume_type'],
    'additionalProperties': False,
}

TARGET_VALIDATOR_EXTRA = args.dict_valid(
    node_uuid=args.uuid,
    uuid=args.uuid,
)

TARGET_VALIDATOR = args.and_valid(args.schema(TARGET_SCHEMA),
                                  TARGET_VALIDATOR_EXTRA)

PATCH_ALLOWED_FIELDS = [
    'boot_index', 'extra', 'node_uuid', 'properties', 'volume_id',
    'volume_type'
]


def convert_with_links(rpc_target, fields=None, sanitize=True):
    target = api_utils.object_to_dict(rpc_target,
                                      link_resource='volume/targets',
                                      fields=('boot_index', 'extra',
                                              'properties', 'volume_id',
                                              'volume_type'))
    api_utils.populate_node_uuid(rpc_target, target)
Пример #4
0
        'uuid': {
            'type': ['string', 'null']
        },
    },
    'required': ['node_uuid'],
    'additionalProperties': False,
}

PORTGROUP_PATCH_SCHEMA = PORTGROUP_SCHEMA

PORTGROUP_VALIDATOR_EXTRA = args.dict_valid(
    address=args.mac_address,
    node_uuid=args.uuid,
    standalone_ports_supported=args.boolean,
    uuid=args.uuid)
PORTGROUP_VALIDATOR = args.and_valid(args.schema(PORTGROUP_SCHEMA),
                                     PORTGROUP_VALIDATOR_EXTRA)

PORTGROUP_PATCH_VALIDATOR = args.and_valid(args.schema(PORTGROUP_PATCH_SCHEMA),
                                           PORTGROUP_VALIDATOR_EXTRA)

PATCH_ALLOWED_FIELDS = [
    'address', 'extra', 'mode', 'name', 'node_uuid', 'properties',
    'standalone_ports_supported'
]


def convert_with_links(rpc_portgroup, fields=None, sanitize=True):
    """Add links to the portgroup."""
    portgroup = api_utils.object_to_dict(
        rpc_portgroup,
Пример #5
0
    'portgroup_uuid',
    'pxe_enabled'
]

PORT_VALIDATOR_EXTRA = args.dict_valid(
    address=args.mac_address,
    node_uuid=args.uuid,
    is_smartnic=args.boolean,
    local_link_connection=api_utils.LOCAL_LINK_VALIDATOR,
    portgroup_uuid=args.uuid,
    pxe_enabled=args.boolean,
    uuid=args.uuid,
)

PORT_VALIDATOR = args.and_valid(
    args.schema(PORT_SCHEMA),
    PORT_VALIDATOR_EXTRA
)

PORT_PATCH_VALIDATOR = args.and_valid(
    args.schema(PORT_PATCH_SCHEMA),
    PORT_VALIDATOR_EXTRA
)


def hide_fields_in_newer_versions(port):
    # if requested version is < 1.18, hide internal_info field
    if not api_utils.allow_port_internal_info():
        port.pop('internal_info', None)
    # if requested version is < 1.19, hide local_link_connection and
    # pxe_enabled fields
Пример #6
0
        'resource_class': {
            'type': ['string', 'null'],
            'maxLength': 80
        },
        'traits': {
            'type': ['array', 'null'],
            'items': api_utils.TRAITS_SCHEMA
        },
        'uuid': {
            'type': ['string', 'null']
        },
    },
    'additionalProperties': False,
}

ALLOCATION_VALIDATOR = args.and_valid(args.schema(ALLOCATION_SCHEMA),
                                      args.dict_valid(uuid=args.uuid))

PATCH_ALLOWED_FIELDS = ['name', 'extra']


def hide_fields_in_newer_versions(allocation):
    # if requested version is < 1.60, hide owner field
    if not api_utils.allow_allocation_owner():
        allocation.pop('owner', None)


def convert_with_links(rpc_allocation, fields=None, sanitize=True):

    allocation = api_utils.object_to_dict(
        rpc_allocation,
Пример #7
0
PATCH_ALLOWED_FIELDS = [
    'address', 'extra', 'is_smartnic', 'local_link_connection', 'node_uuid',
    'physical_network', 'portgroup_uuid', 'pxe_enabled'
]

PORT_VALIDATOR_EXTRA = args.dict_valid(
    address=args.mac_address,
    node_uuid=args.uuid,
    is_smartnic=args.boolean,
    local_link_connection=api_utils.LOCAL_LINK_VALIDATOR,
    portgroup_uuid=args.uuid,
    pxe_enabled=args.boolean,
    uuid=args.uuid,
)

PORT_VALIDATOR = args.and_valid(args.schema(PORT_SCHEMA), PORT_VALIDATOR_EXTRA)

PORT_PATCH_VALIDATOR = args.and_valid(args.schema(PORT_PATCH_SCHEMA),
                                      PORT_VALIDATOR_EXTRA)


def hide_fields_in_newer_versions(port):
    # if requested version is < 1.18, hide internal_info field
    if not api_utils.allow_port_internal_info():
        port.pop('internal_info', None)
    # if requested version is < 1.19, hide local_link_connection and
    # pxe_enabled fields
    if not api_utils.allow_port_advanced_net_fields():
        port.pop('pxe_enabled', None)
        port.pop('local_link_connection', None)
    # if requested version is < 1.24, hide portgroup_uuid field
Пример #8
0
        'extra': {'type': ['object', 'null']},
        'node_uuid': {'type': 'string'},
        'type': {'type': 'string'},
        'uuid': {'type': ['string', 'null']},
    },
    'required': ['connector_id', 'node_uuid', 'type'],
    'additionalProperties': False,
}

CONNECTOR_VALIDATOR_EXTRA = args.dict_valid(
    node_uuid=args.uuid,
    uuid=args.uuid,
)

CONNECTOR_VALIDATOR = args.and_valid(
    args.schema(CONNECTOR_SCHEMA),
    CONNECTOR_VALIDATOR_EXTRA
)

PATCH_ALLOWED_FIELDS = [
    'connector_id',
    'extra',
    'node_uuid',
    'type'
]


def convert_with_links(rpc_connector, fields=None, sanitize=True):
    connector = api_utils.object_to_dict(
        rpc_connector,
        link_resource='volume/connectors',
Пример #9
0
 def setUp(self):
     super(TestEventValidator, self).setUp()
     self.v_event = event.NETWORK_EVENT_VALIDATOR
     self.v_events = args.schema(event.EVENTS_SCHEMA)
Пример #10
0
    counter = collections.Counter(
        (step['interface'], step['step']) for step in value['steps'])
    duplicates = {key for key, count in counter.items() if count > 1}
    if duplicates:
        duplicates = {
            "interface: %s, step: %s" % (interface, step)
            for interface, step in duplicates
        }
        err = _("Duplicate deploy steps. A deploy template cannot have "
                "multiple deploy steps with the same interface and step. "
                "Duplicates: %s") % "; ".join(duplicates)
        raise exception.InvalidDeployTemplate(err=err)
    return value


TEMPLATE_VALIDATOR = args.and_valid(args.schema(TEMPLATE_SCHEMA),
                                    duplicate_steps,
                                    args.dict_valid(uuid=args.uuid))


def convert_steps(rpc_steps):
    for step in rpc_steps:
        yield {
            'interface': step['interface'],
            'step': step['step'],
            'args': step['args'],
            'priority': step['priority'],
        }


def convert_with_links(rpc_template, fields=None, sanitize=True):
Пример #11
0
        'extra': {'type': ['object', 'null']},
        'name': {'type': ['string', 'null']},
        'node': {'type': ['string', 'null']},
        'owner': {'type': ['string', 'null']},
        'resource_class': {'type': ['string', 'null'], 'maxLength': 80},
        'traits': {
            'type': ['array', 'null'],
            'items': api_utils.TRAITS_SCHEMA
        },
        'uuid': {'type': ['string', 'null']},
    },
    'additionalProperties': False,
}

ALLOCATION_VALIDATOR = args.and_valid(
    args.schema(ALLOCATION_SCHEMA),
    args.dict_valid(uuid=args.uuid)
)


PATCH_ALLOWED_FIELDS = ['name', 'extra']


def hide_fields_in_newer_versions(allocation):
    # if requested version is < 1.60, hide owner field
    if not api_utils.allow_allocation_owner():
        allocation.pop('owner', None)


def convert_with_links(rpc_allocation, fields=None, sanitize=True):
Пример #12
0
        'properties': {'type': ['object', 'null']},
        'volume_id': {'type': 'string'},
        'volume_type': {'type': 'string'},
        'uuid': {'type': ['string', 'null']},
    },
    'required': ['boot_index', 'node_uuid', 'volume_id', 'volume_type'],
    'additionalProperties': False,
}

TARGET_VALIDATOR_EXTRA = args.dict_valid(
    node_uuid=args.uuid,
    uuid=args.uuid,
)

TARGET_VALIDATOR = args.and_valid(
    args.schema(TARGET_SCHEMA),
    TARGET_VALIDATOR_EXTRA
)

PATCH_ALLOWED_FIELDS = [
    'boot_index',
    'extra',
    'node_uuid',
    'properties',
    'volume_id',
    'volume_type'
]


def convert_with_links(rpc_target, fields=None, sanitize=True):
    target = api_utils.object_to_dict(
Пример #13
0
            'type': 'string'
        },
        'uuid': {
            'type': ['string', 'null']
        },
    },
    'required': ['connector_id', 'node_uuid', 'type'],
    'additionalProperties': False,
}

CONNECTOR_VALIDATOR_EXTRA = args.dict_valid(
    node_uuid=args.uuid,
    uuid=args.uuid,
)

CONNECTOR_VALIDATOR = args.and_valid(args.schema(CONNECTOR_SCHEMA),
                                     CONNECTOR_VALIDATOR_EXTRA)

PATCH_ALLOWED_FIELDS = ['connector_id', 'extra', 'node_uuid', 'type']


def convert_with_links(rpc_connector, fields=None, sanitize=True):
    connector = api_utils.object_to_dict(rpc_connector,
                                         link_resource='volume/connectors',
                                         fields=('connector_id', 'extra',
                                                 'type'))
    api_utils.populate_node_uuid(rpc_connector, connector)

    if fields is not None:
        api_utils.check_for_invalid_fields(fields, connector)
Пример #14
0
NETWORK_EVENT_VALIDATOR = args.and_valid(
    args.schema({
        'type': 'object',
        'properties': {
            'event': {
                'type': 'string'
            },
            'port_id': {
                'type': 'string'
            },
            'mac_address': {
                'type': 'string'
            },
            'status': {
                'type': 'string'
            },
            'device_id': {
                'type': ['string', 'null']
            },
            'binding:host_id': {
                'type': ['string', 'null']
            },
            'binding:vnic_type': {
                'type': ['string', 'null']
            },
        },
        'required': ['event', 'port_id', 'mac_address', 'status'],
        'additionalProperties': False,
    }),
    args.dict_valid(
        **{
Пример #15
0
    'properties': {
        'uuid': {
            'type': ['string', 'null']
        },
        'extra': {
            'type': ['object', 'null']
        },
        'description': {
            'type': ['string', 'null'],
            'maxLength': 255
        },
    },
    'additionalProperties': False,
}

CHASSIS_VALIDATOR = args.and_valid(args.schema(CHASSIS_SCHEMA),
                                   args.dict_valid(uuid=args.uuid))

DEFAULT_RETURN_FIELDS = ['uuid', 'description']


def convert_with_links(rpc_chassis, fields=None, sanitize=True):
    chassis = api_utils.object_to_dict(rpc_chassis,
                                       fields=('description', 'extra'),
                                       link_resource='chassis')

    url = api.request.public_url
    chassis['nodes'] = [
        link.make_link('self', url, 'chassis', rpc_chassis.uuid + "/nodes"),
        link.make_link('bookmark',
                       url,
Пример #16
0
class ArgsDecorated(object):

    @args.validate(one=args.string,
                   two=args.boolean,
                   three=args.uuid,
                   four=args.uuid_or_name)
    def method(self, one, two, three, four):
        return one, two, three, four

    @args.validate(one=args.string)
    def needs_string(self, one):
        return one

    @args.validate(one=args.boolean)
    def needs_boolean(self, one):
        return one

    @args.validate(one=args.uuid)
    def needs_uuid(self, one):
        return one

    @args.validate(one=args.name)
    def needs_name(self, one):
        return one

    @args.validate(one=args.uuid_or_name)
    def needs_uuid_or_name(self, one):
        return one

    @args.validate(one=args.string_list)
    def needs_string_list(self, one):
        return one

    @args.validate(one=args.integer)
    def needs_integer(self, one):
        return one

    @args.validate(one=args.mac_address)
    def needs_mac_address(self, one):
        return one

    @args.validate(one=args.schema({
        'type': 'array',
        'items': {
            'type': 'object',
            'properties': {
                'name': {'type': 'string'},
                'count': {'type': 'integer', 'minimum': 0},
            },
            'additionalProperties': False,
            'required': ['name'],
        }
    }))
    def needs_schema(self, one):
        return one

    @args.validate(one=args.string, two=args.string, the_rest=args.schema({
        'type': 'object',
        'properties': {
            'three': {'type': 'string'},
            'four': {'type': 'string', 'maxLength': 4},
            'five': {'type': 'string'},
        },
        'additionalProperties': False,
        'required': ['three']
    }))
    def needs_schema_kwargs(self, one, two, **the_rest):
        return one, two, the_rest

    @args.validate(one=args.string, two=args.string, the_rest=args.schema({
        'type': 'array',
        'items': {'type': 'string'}
    }))
    def needs_schema_args(self, one, two=None, *the_rest):
        return one, two, the_rest

    @args.validate(one=args.string, two=args.string, args=args.schema({
        'type': 'array',
        'items': {'type': 'string'}
    }), kwargs=args.schema({
        'type': 'object',
        'properties': {
            'four': {'type': 'string'},
        },
    }))
    def needs_schema_mixed(self, one, two=None, *args, **kwargs):
        return one, two, args, kwargs

    @args.validate(one=args.string)
    def needs_mixed_unvalidated(self, one, two=None, *args, **kwargs):
        return one, two, args, kwargs

    @args.validate(body=args.patch)
    def patch(self, body):
        return body