| # Copyright 2014 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Umpire resource map web application. |
| |
| The class handles |
| 'http://umpire_address:umpire_port/webapps/resourcemap' HTTP GET. |
| """ |
| |
| import logging |
| |
| import factory_common # pylint: disable=unused-import |
| from cros.factory.umpire.server import bundle_selector |
| from cros.factory.umpire.server.web import wsgi |
| from cros.factory.umpire.server import webapp_utils |
| from cros.factory.utils import type_utils |
| |
| |
| PATH_INFO = '/webapps/resourcemap' |
| |
| |
| class ResourceMapApp(wsgi.WebApp): |
| """ResourceMap web application class. |
| |
| Args: |
| env: UmpireEnv object. |
| """ |
| |
| def __init__(self, env): |
| self._env = env |
| |
| def Handle(self, session): |
| """Gets resource map from DUT info and return text/plain result.""" |
| logging.debug('resourcemap app: %s', session) |
| if session.REQUEST_METHOD == 'GET': |
| dut_info = webapp_utils.ParseDUTHeader(session.HTTP_X_UMPIRE_DUT) |
| resource_map = bundle_selector.GetResourceMap(dut_info, self._env) |
| if resource_map is None: |
| return session.BadRequest400() |
| return session.Respond(type_utils.UnicodeToString(resource_map)) |
| return session.BadRequest400() |