"Fossies" - the Fresh Open Source Software Archive

Member "zun-4.0.0/zun/api/controllers/v1/views/hosts_view.py" (16 Oct 2019, 1511 Bytes) of package /linux/misc/openstack/zun-4.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 "hosts_view.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.1.0_vs_3.0.0.

    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 import itertools
   15 
   16 from zun.api.controllers import link
   17 
   18 
   19 _basic_keys = (
   20     'uuid',
   21     'hostname',
   22     'mem_total',
   23     'cpus',
   24     'total_containers',
   25     'architecture',
   26     'os_type',
   27     'os',
   28     'kernel_version',
   29     'labels',
   30     'mem_used',
   31     'cpu_used',
   32     'disk_used',
   33     'disk_total',
   34     'disk_quota_supported',
   35     'runtimes',
   36     'enable_cpu_pinning',
   37 )
   38 
   39 
   40 def format_host(url, host):
   41     def transform(key, value):
   42         if key not in _basic_keys:
   43             return
   44         if key == 'uuid':
   45             yield ('uuid', value)
   46             yield ('links', [link.make_link(
   47                 'self', url, 'hosts', value),
   48                 link.make_link(
   49                     'bookmark', url,
   50                     'hosts', value,
   51                     bookmark=True)])
   52         else:
   53             yield (key, value)
   54 
   55     return dict(itertools.chain.from_iterable(
   56         transform(k, v) for k, v in host.as_dict().items()))