"Fossies" - the Fresh Open Source Software Archive

Member "senlin-8.0.0/senlin/api/openstack/v1/services.py" (16 Oct 2019, 2045 Bytes) of package /linux/misc/openstack/senlin-8.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "services.py" see the Fossies "Dox" file reference documentation.

    1 #
    2 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    3 #    not use this file except in compliance with the License. You may obtain
    4 #    a copy of the License at
    5 #
    6 #         http://www.apache.org/licenses/LICENSE-2.0
    7 #
    8 #    Unless required by applicable law or agreed to in writing, software
    9 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   10 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   11 #    License for the specific language governing permissions and limitations
   12 #    under the License.
   13 
   14 from oslo_config import cfg
   15 from oslo_utils import timeutils
   16 from senlin.api.common import util
   17 from senlin.api.common import wsgi
   18 from senlin.common import exception
   19 from senlin.objects import service as service_obj
   20 
   21 CONF = cfg.CONF
   22 
   23 
   24 class ServiceController(wsgi.Controller):
   25     """WSGI controller for Services in Senlin v1 API."""
   26 
   27     REQUEST_SCOPE = 'services'
   28 
   29     @util.policy_enforce
   30     def index(self, req):
   31         if not req.context.is_admin:
   32             raise exception.Forbidden()
   33         now = timeutils.utcnow(with_timezone=True)
   34         _services = service_obj.Service.get_all(req.context)
   35         svcs = []
   36         for svc in _services:
   37             updated_at = svc.updated_at
   38             delta = now - (svc.updated_at or svc.created_at)
   39             delta_sec = delta.total_seconds()
   40             alive = abs(delta_sec) <= CONF.service_down_time
   41             art = (alive and "up") or "down"
   42             active = 'enabled'
   43             if svc.disabled:
   44                 active = 'disabled'
   45             if updated_at:
   46                 updated_at = timeutils.normalize_time(updated_at)
   47             ret_fields = {'id': svc.id, 'host': svc.host,
   48                           'binary': svc.binary, 'topic': svc.topic,
   49                           'disabled_reason': svc.disabled_reason,
   50                           'status': active, 'state': art,
   51                           'updated_at': updated_at}
   52             svcs.append(ret_fields)
   53         return {'services': svcs}