예제 #1
0
파일: __init__.py 프로젝트: xsc27/ironic
class Controller(rest.RestController):
    """Version 1 API controller root."""

    nodes = node.NodesController()
    ports = port.PortsController()
    chassis = chassis.ChassisController()
    drivers = driver.DriversController()
    lookup = ramdisk.LookupController()
    heartbeat = ramdisk.HeartbeatController()

    @expose.expose(V1)
    def get(self):
        # NOTE: The reason why convert() it's being called for every
        #       request is because we need to get the host url from
        #       the request object to make the links.
        return V1.convert()

    def _check_version(self, version, headers=None):
        if headers is None:
            headers = {}
        # ensure that major version in the URL matches the header
        if version.major != BASE_VERSION:
            raise exc.HTTPNotAcceptable(
                _("Mutually exclusive versions requested. Version %(ver)s "
                  "requested but not supported by this service. The supported "
                  "version range is: [%(min)s, %(max)s].") % {
                      'ver': version,
                      'min': versions.MIN_VERSION_STRING,
                      'max': versions.MAX_VERSION_STRING
                  },
                headers=headers)
        # ensure the minor version is within the supported range
        if version < MIN_VER or version > MAX_VER:
            raise exc.HTTPNotAcceptable(
                _("Version %(ver)s was requested but the minor version is not "
                  "supported by this service. The supported version range is: "
                  "[%(min)s, %(max)s].") % {
                      'ver': version,
                      'min': versions.MIN_VERSION_STRING,
                      'max': versions.MAX_VERSION_STRING
                  },
                headers=headers)

    @pecan.expose()
    def _route(self, args):
        v = base.Version(pecan.request.headers, versions.MIN_VERSION_STRING,
                         versions.MAX_VERSION_STRING)

        # Always set the min and max headers
        pecan.response.headers[base.Version.min_string] = (
            versions.MIN_VERSION_STRING)
        pecan.response.headers[base.Version.max_string] = (
            versions.MAX_VERSION_STRING)

        # assert that requested version is supported
        self._check_version(v, pecan.response.headers)
        pecan.response.headers[base.Version.string] = str(v)
        pecan.request.version = v

        return super(Controller, self)._route(args)
예제 #2
0
파일: __init__.py 프로젝트: mydaisy2/ironic
class Controller(rest.RestController):
    """Version 1 API controller root."""

    nodes = node.NodesController()
    ports = port.PortsController()
    chassis = chassis.ChassisController()

    @wsme_pecan.wsexpose(V1)
    def get(self):
        # NOTE: The reason why convert() it's being called for every
        #       request is because we need to get the host url from
        #       the request object to make the links.
        return V1.convert()
예제 #3
0
파일: __init__.py 프로젝트: luongduy/ironic
class Controller(rest.RestController):
    """Version 1 API controller root."""

    nodes = node.NodesController()
    ports = port.PortsController()
    chassis = chassis.ChassisController()
    drivers = driver.DriversController()

    @wsme_pecan.wsexpose(V1)
    def get(self):
        # NOTE: The reason why convert() it's being called for every
        #       request is because we need to get the host url from
        #       the request object to make the links.
        return V1.convert()

    def _check_version(self, version):
        # ensure that major version in the URL matches the header
        if version.major != 1:
            raise exc.HTTPNotAcceptable(
                _("Mutually exclusive versions requested. Version %(ver)s "
                  "requested but not supported by this service.") %
                {'ver': version})
        # ensure the minor version is within the supported range
        if version.minor < MIN_VER or version.minor > MAX_VER:
            raise exc.HTTPNotAcceptable(
                _("Unsupported minor version requested. This API service "
                  "supports the following version range: "
                  "[%(min)s, %(max)s].") % {
                      'min': MIN_VER,
                      'max': MAX_VER
                  })

        version.set_min_max(MIN_VER, MAX_VER)

    @pecan.expose()
    def _route(self, args):
        v = base.Version(pecan.request.headers)
        # Always set the min and max headers
        # FIXME: these are not being sent if _check_version raises an exception
        pecan.response.headers[base.Version.min_string] = str(MIN_VER)
        pecan.response.headers[base.Version.max_string] = str(MAX_VER)

        # assert that requested version is supported
        self._check_version(v)
        pecan.response.headers[base.Version.string] = str(v)
        pecan.request.version = v

        return super(Controller, self)._route(args)
예제 #4
0
class Controller(rest.RestController):
    """Version 1 API controller root."""

    nodes = node.NodesController()
    ports = port.PortsController()
    portgroups = portgroup.PortgroupsController()
    chassis = chassis.ChassisController()
    drivers = driver.DriversController()
    volume = volume.VolumeController()
    lookup = ramdisk.LookupController()
    heartbeat = ramdisk.HeartbeatController()
    conductors = conductor.ConductorsController()
    allocations = allocation.AllocationsController()
    events = event.EventsController()
    deploy_templates = deploy_template.DeployTemplatesController()

    @expose.expose(V1)
    def get(self):
        # NOTE: The reason why convert() it's being called for every
        #       request is because we need to get the host url from
        #       the request object to make the links.
        return V1.convert()

    def _check_version(self, version, headers=None):
        if headers is None:
            headers = {}
        # ensure that major version in the URL matches the header
        if version.major != BASE_VERSION:
            raise exc.HTTPNotAcceptable(
                _("Mutually exclusive versions requested. Version %(ver)s "
                  "requested but not supported by this service. The supported "
                  "version range is: [%(min)s, %(max)s].") % {
                      'ver': version,
                      'min': versions.min_version_string(),
                      'max': versions.max_version_string()
                  },
                headers=headers)
        # ensure the minor version is within the supported range
        if version < min_version() or version > max_version():
            raise exc.HTTPNotAcceptable(
                _("Version %(ver)s was requested but the minor version is not "
                  "supported by this service. The supported version range is: "
                  "[%(min)s, %(max)s].") % {
                      'ver': version,
                      'min': versions.min_version_string(),
                      'max': versions.max_version_string()
                  },
                headers=headers)

    @pecan.expose()
    def _route(self, args, request=None):
        v = base.Version(api.request.headers, versions.min_version_string(),
                         versions.max_version_string())

        # Always set the min and max headers
        api.response.headers[base.Version.min_string] = (
            versions.min_version_string())
        api.response.headers[base.Version.max_string] = (
            versions.max_version_string())

        # assert that requested version is supported
        self._check_version(v, api.response.headers)
        api.response.headers[base.Version.string] = str(v)
        api.request.version = v

        return super(Controller, self)._route(args, request)
예제 #5
0
class Controller(object):
    """Version 1 API controller root."""

    _subcontroller_map = {
        'nodes': node.NodesController(),
        'ports': port.PortsController(),
        'portgroups': portgroup.PortgroupsController(),
        'chassis': chassis.ChassisController(),
        'drivers': driver.DriversController(),
        'volume': volume.VolumeController(),
        'lookup': ramdisk.LookupController(),
        'heartbeat': ramdisk.HeartbeatController(),
        'conductors': conductor.ConductorsController(),
        'allocations': allocation.AllocationsController(),
        'events': event.EventsController(),
        'deploy_templates': deploy_template.DeployTemplatesController()
    }

    @method.expose()
    def index(self):
        # NOTE: The reason why v1() it's being called for every
        #       request is because we need to get the host url from
        #       the request object to make the links.
        self._add_version_attributes()
        if api.request.method != "GET":
            pecan.abort(http_client.METHOD_NOT_ALLOWED)

        return v1()

    def _check_version(self, version, headers=None):
        if headers is None:
            headers = {}
        # ensure that major version in the URL matches the header
        if version.major != BASE_VERSION:
            raise exc.HTTPNotAcceptable(
                _("Mutually exclusive versions requested. Version %(ver)s "
                  "requested but not supported by this service. The supported "
                  "version range is: [%(min)s, %(max)s].") % {
                      'ver': version,
                      'min': versions.min_version_string(),
                      'max': versions.max_version_string()
                  },
                headers=headers)
        # ensure the minor version is within the supported range
        if version < min_version() or version > max_version():
            raise exc.HTTPNotAcceptable(
                _("Version %(ver)s was requested but the minor version is not "
                  "supported by this service. The supported version range is: "
                  "[%(min)s, %(max)s].") % {
                      'ver': version,
                      'min': versions.min_version_string(),
                      'max': versions.max_version_string()
                  },
                headers=headers)

    def _add_version_attributes(self):
        v = base.Version(api.request.headers, versions.min_version_string(),
                         versions.max_version_string())

        # Always set the min and max headers
        api.response.headers[base.Version.min_string] = (
            versions.min_version_string())
        api.response.headers[base.Version.max_string] = (
            versions.max_version_string())

        # assert that requested version is supported
        self._check_version(v, api.response.headers)
        api.response.headers[base.Version.string] = str(v)
        api.request.version = v

    @pecan.expose()
    def _lookup(self, primary_key, *remainder):
        self._add_version_attributes()

        controller = self._subcontroller_map.get(primary_key)
        if not controller:
            pecan.abort(http_client.NOT_FOUND)

        return controller, remainder