Пример #1
0
    def convert_with_links(cls, rpc_allocation, fields=None, sanitize=True):
        """Add links to the allocation."""
        allocation = Allocation(**rpc_allocation.as_dict())

        if rpc_allocation.node_id:
            try:
                allocation.node_uuid = objects.Node.get_by_id(
                    api.request.context, rpc_allocation.node_id).uuid
            except exception.NodeNotFound:
                allocation.node_uuid = None
        else:
            allocation.node_uuid = None

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, allocation.fields)

        # Make the default values consistent between POST and GET API
        if allocation.candidate_nodes is None:
            allocation.candidate_nodes = []
        if allocation.traits is None:
            allocation.traits = []

        allocation = cls._convert_with_links(allocation, api.request.host_url)

        if not sanitize:
            return allocation

        allocation.sanitize(fields)

        return allocation
Пример #2
0
    def convert_with_links(cls, rpc_allocation, fields=None, sanitize=True):
        """Add links to the allocation."""
        allocation = Allocation(**rpc_allocation.as_dict())

        if rpc_allocation.node_id:
            try:
                allocation.node_uuid = objects.Node.get_by_id(
                    pecan.request.context,
                    rpc_allocation.node_id).uuid
            except exception.NodeNotFound:
                allocation.node_uuid = None
        else:
            allocation.node_uuid = None

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, allocation.fields)

        # Make the default values consistent between POST and GET API
        if allocation.candidate_nodes is None:
            allocation.candidate_nodes = []
        if allocation.traits is None:
            allocation.traits = []

        allocation = cls._convert_with_links(allocation,
                                             pecan.request.host_url)

        if not sanitize:
            return allocation

        allocation.sanitize(fields)

        return allocation
Пример #3
0
def convert_with_links(rpc_portgroup, fields=None, sanitize=True):
    """Add links to the portgroup."""
    portgroup = api_utils.object_to_dict(
        rpc_portgroup,
        link_resource='portgroups',
        fields=('address', 'extra', 'internal_info', 'mode', 'name',
                'properties', 'standalone_ports_supported'))
    api_utils.populate_node_uuid(rpc_portgroup, portgroup)
    url = api.request.public_url
    portgroup['ports'] = [
        link.make_link('self', url, 'portgroups',
                       rpc_portgroup.uuid + "/ports"),
        link.make_link('bookmark',
                       url,
                       'portgroups',
                       rpc_portgroup.uuid + "/ports",
                       bookmark=True)
    ]

    if fields is not None:
        api_utils.check_for_invalid_fields(fields, portgroup)

    if not sanitize:
        return portgroup

    api_utils.sanitize_dict(portgroup, fields)

    return portgroup
Пример #4
0
def convert_with_links(rpc_allocation, fields=None, sanitize=True):

    allocation = api_utils.object_to_dict(
        rpc_allocation,
        link_resource='allocations',
        fields=(
            'candidate_nodes',
            'extra',
            'last_error',
            'name',
            'owner',
            'resource_class',
            'state',
            'traits'
        )
    )
    try:
        api_utils.populate_node_uuid(rpc_allocation, allocation)
    except exception.NodeNotFound:
        allocation['node_uuid'] = None

    if fields is not None:
        api_utils.check_for_invalid_fields(fields, set(allocation))

    if sanitize:
        allocation_sanitize(allocation, fields)
    return allocation
Пример #5
0
    def convert_with_links(cls, rpc_port, fields=None):
        port = Port(**rpc_port.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, port.as_dict())

        return cls._convert_with_links(port, pecan.request.host_url, fields=fields)
Пример #6
0
    def convert_with_links(cls, rpc_chassis, fields=None):
        chassis = Chassis(**rpc_chassis.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, chassis.as_dict())

        return cls._convert_with_links(chassis, pecan.request.host_url, fields)
    def convert_with_links(cls, rpc_port, fields=None):
        port = Port(**rpc_port.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, port.as_dict())

        return cls._convert_with_links(port, pecan.request.public_url,
                                       fields=fields)
Пример #8
0
    def convert_with_links(cls, rpc_target, fields=None):
        target = VolumeTarget(**rpc_target.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, target.as_dict())

        return cls._convert_with_links(target, pecan.request.public_url,
                                       fields=fields)
Пример #9
0
    def convert_with_links(cls, rpc_connector, fields=None):
        connector = VolumeConnector(**rpc_connector.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, connector.as_dict())

        return cls._convert_with_links(connector, pecan.request.public_url,
                                       fields=fields)
Пример #10
0
    def convert_with_links(cls, rpc_chassis, fields=None):
        chassis = Chassis(**rpc_chassis.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, chassis.as_dict())

        return cls._convert_with_links(chassis, pecan.request.public_url,
                                       fields)
Пример #11
0
    def convert_with_links(cls, rpc_connector, fields=None):
        connector = VolumeConnector(**rpc_connector.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, connector.as_dict())

        return cls._convert_with_links(connector,
                                       pecan.request.public_url,
                                       fields=fields)
Пример #12
0
    def convert_with_links(cls, rpc_portgroup, fields=None):
        """Add links to the portgroup."""
        portgroup = Portgroup(**rpc_portgroup.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, portgroup.as_dict())

        return cls._convert_with_links(portgroup, pecan.request.host_url,
                                       fields=fields)
Пример #13
0
    def convert_with_links(cls, rpc_node, fields=None):
        node = Node(**rpc_node.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, node.as_dict())

        assert_juno_provision_state_name(node)
        hide_fields_in_newer_versions(node)
        show_password = pecan.request.context.show_password
        return cls._convert_with_links(node, pecan.request.host_url, fields=fields, show_password=show_password)
Пример #14
0
    def convert_with_links(cls, rpc_port, fields=None):
        port = Port(**rpc_port.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, port.as_dict())

        hide_fields_in_newer_versions(port)

        return cls._convert_with_links(port, pecan.request.public_url,
                                       fields=fields)
Пример #15
0
    def convert_with_links(cls, rpc_node, fields=None):
        node = Node(**rpc_node.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, node.as_dict())

        assert_juno_provision_state_name(node)
        hide_fields_in_newer_versions(node)
        show_password = pecan.request.context.show_password
        return cls._convert_with_links(node, pecan.request.host_url,
                                       fields=fields,
                                       show_password=show_password)
Пример #16
0
    def convert_with_links(cls, rpc_conductor, fields=None):
        conductor = Conductor(**rpc_conductor.as_dict())
        conductor.alive = not timeutils.is_older_than(
            conductor.updated_at, CONF.conductor.heartbeat_timeout)

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, conductor.as_dict())

        conductor = cls._convert_with_links(conductor,
                                            api.request.public_url,
                                            fields=fields)
        conductor.sanitize(fields)
        return conductor
Пример #17
0
    def convert_with_links(cls, rpc_template, fields=None, sanitize=True):
        """Add links to the deploy template."""
        template = DeployTemplate(**rpc_template.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, template.as_dict())

        template = cls._convert_with_links(template,
                                           api.request.public_url,
                                           fields=fields)
        if sanitize:
            template.sanitize(fields)

        return template
Пример #18
0
    def convert_with_links(cls, rpc_target, fields=None, sanitize=True):
        target = VolumeTarget(**rpc_target.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, target.as_dict())

        target = cls._convert_with_links(target, pecan.request.public_url)

        if not sanitize:
            return target

        target.sanitize(fields)

        return target
Пример #19
0
    def convert_with_links(cls, rpc_connector, fields=None, sanitize=True):
        connector = VolumeConnector(**rpc_connector.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, connector.as_dict())

        connector = cls._convert_with_links(connector, api.request.public_url)

        if not sanitize:
            return connector

        connector.sanitize(fields)

        return connector
Пример #20
0
    def convert_with_links(cls, rpc_chassis, fields=None, sanitize=True):
        chassis = Chassis(**rpc_chassis.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, chassis.as_dict())

        chassis = cls._convert_with_links(chassis, api.request.public_url,
                                          fields)

        if not sanitize:
            return chassis

        chassis.sanitize(fields)
        return chassis
Пример #21
0
    def convert_with_links(cls, rpc_target, fields=None, sanitize=True):
        target = VolumeTarget(**rpc_target.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, target.as_dict())

        target = cls._convert_with_links(target, pecan.request.public_url)

        if not sanitize:
            return target

        target.sanitize(fields)

        return target
Пример #22
0
    def convert_with_links(cls, rpc_connector, fields=None, sanitize=True):
        connector = VolumeConnector(**rpc_connector.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, connector.as_dict())

        connector = cls._convert_with_links(connector,
                                            pecan.request.public_url)

        if not sanitize:
            return connector

        connector.sanitize(fields)

        return connector
Пример #23
0
def convert_with_links(rpc_conductor, fields=None, sanitize=True):
    conductor = api_utils.object_to_dict(
        rpc_conductor,
        include_uuid=False,
        fields=('hostname', 'conductor_group', 'drivers'),
        link_resource='conductors',
        link_resource_args=rpc_conductor.hostname)
    conductor['alive'] = not timeutils.is_older_than(
        rpc_conductor.updated_at, CONF.conductor.heartbeat_timeout)
    if fields is not None:
        api_utils.check_for_invalid_fields(fields, conductor)

    if sanitize:
        api_utils.sanitize_dict(conductor, fields)
    return conductor
Пример #24
0
def convert_with_links(rpc_template, fields=None, sanitize=True):
    """Add links to the deploy template."""
    template = api_utils.object_to_dict(
        rpc_template,
        fields=('name', 'extra'),
        link_resource='deploy_templates',
    )
    template['steps'] = list(convert_steps(rpc_template.steps))

    if fields is not None:
        api_utils.check_for_invalid_fields(fields, template)

    if sanitize:
        template_sanitize(template, fields)

    return template
Пример #25
0
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)

    if not sanitize:
        return connector

    api_utils.sanitize_dict(connector, fields)

    return connector
Пример #26
0
    def convert_with_links(cls, rpc_portgroup, fields=None, sanitize=True):
        """Add links to the portgroup."""
        portgroup = Portgroup(**rpc_portgroup.as_dict())

        if fields is not None:
            api_utils.check_for_invalid_fields(fields, portgroup.as_dict())

        portgroup = cls._convert_with_links(portgroup, api.request.host_url,
                                            fields=fields)

        if not sanitize:
            return portgroup

        portgroup.sanitize(fields)

        return portgroup
Пример #27
0
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)

    if fields is not None:
        api_utils.check_for_invalid_fields(fields, target)

    if not sanitize:
        return target

    api_utils.sanitize_dict(target, fields)

    return target
Пример #28
0
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,
                       'chassis',
                       rpc_chassis.uuid + "/nodes",
                       bookmark=True)
    ],

    if fields is not None:
        api_utils.check_for_invalid_fields(fields, chassis)

    if sanitize:
        api_utils.sanitize_dict(chassis, fields)
    return chassis
Пример #29
0
 def test_check_for_invalid_fields(self):
     requested = ['field_1', 'field_3']
     supported = ['field_1', 'field_2', 'field_3']
     utils.check_for_invalid_fields(requested, supported)
Пример #30
0
 def _validate_fields(self, fields=None):
     if fields is not None:
         api_utils.check_for_invalid_fields(fields, self.as_dict())
Пример #31
0
def _validate_fields(port, fields=None):
    if fields is not None:
        api_utils.check_for_invalid_fields(fields, port)
Пример #32
0
 def test_check_for_invalid_fields(self):
     requested = ["field_1", "field_3"]
     supported = ["field_1", "field_2", "field_3"]
     utils.check_for_invalid_fields(requested, supported)
Пример #33
0
 def _validate_fields(self, fields=None):
     if fields is not None:
         api_utils.check_for_invalid_fields(fields, self.as_dict())