"Fossies" - the Fresh Open Source Software Archive

Member "glance-24.1.0/glance/api/v2/model/metadef_namespace.py" (8 Jun 2022, 3021 Bytes) of package /linux/misc/openstack/glance-24.1.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 "metadef_namespace.py" see the Fossies "Dox" file reference documentation.

    1 # Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License");
    4 # you may not use this file except in compliance with the License.
    5 # You may obtain a copy of the License at
    6 #
    7 #    http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS,
   11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
   12 # implied.
   13 # See the License for the specific language governing permissions and
   14 # limitations under the License.
   15 
   16 import wsme
   17 from wsme.rest import json
   18 from wsme import types
   19 
   20 from glance.api.v2.model.metadef_object import MetadefObject
   21 from glance.api.v2.model.metadef_property_type import PropertyType
   22 from glance.api.v2.model.metadef_resource_type import ResourceTypeAssociation
   23 from glance.api.v2.model.metadef_tag import MetadefTag
   24 from glance.common.wsme_utils import WSMEModelTransformer
   25 
   26 
   27 class Namespace(types.Base, WSMEModelTransformer):
   28 
   29     # Base fields
   30     namespace = wsme.wsattr(types.text, mandatory=True)
   31     display_name = wsme.wsattr(types.text, mandatory=False)
   32     description = wsme.wsattr(types.text, mandatory=False)
   33     visibility = wsme.wsattr(types.text, mandatory=False)
   34     protected = wsme.wsattr(bool, mandatory=False)
   35     owner = wsme.wsattr(types.text, mandatory=False)
   36 
   37     # Not using datetime since time format has to be
   38     # in oslo_utils.timeutils.isotime() format
   39     created_at = wsme.wsattr(types.text, mandatory=False)
   40     updated_at = wsme.wsattr(types.text, mandatory=False)
   41 
   42     # Contained fields
   43     resource_type_associations = wsme.wsattr([ResourceTypeAssociation],
   44                                              mandatory=False)
   45     properties = wsme.wsattr({types.text: PropertyType}, mandatory=False)
   46     objects = wsme.wsattr([MetadefObject], mandatory=False)
   47     tags = wsme.wsattr([MetadefTag], mandatory=False)
   48 
   49     # Generated fields
   50     self = wsme.wsattr(types.text, mandatory=False)
   51     schema = wsme.wsattr(types.text, mandatory=False)
   52 
   53     def __init__(cls, **kwargs):
   54         super(Namespace, cls).__init__(**kwargs)
   55 
   56     @staticmethod
   57     def to_model_properties(db_property_types):
   58         property_types = {}
   59         for db_property_type in db_property_types:
   60             # Convert the persisted json schema to a dict of PropertyTypes
   61             property_type = json.fromjson(
   62                 PropertyType, db_property_type.schema)
   63             property_type_name = db_property_type.name
   64             property_types[property_type_name] = property_type
   65 
   66         return property_types
   67 
   68 
   69 class Namespaces(types.Base, WSMEModelTransformer):
   70 
   71     namespaces = wsme.wsattr([Namespace], mandatory=False)
   72 
   73     # Pagination
   74     next = wsme.wsattr(types.text, mandatory=False)
   75     schema = wsme.wsattr(types.text, mandatory=True)
   76     first = wsme.wsattr(types.text, mandatory=True)
   77 
   78     def __init__(self, **kwargs):
   79         super(Namespaces, self).__init__(**kwargs)