"Fossies" - the Fresh Open Source Software Archive

Member "cinder-13.0.7/cinder/api/v3/views/attachments.py" (4 Oct 2019, 2051 Bytes) of package /linux/misc/openstack/cinder-13.0.7.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 "attachments.py" see the Fossies "Dox" file reference documentation.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 
   13 from oslo_utils import timeutils
   14 
   15 
   16 class ViewBuilder(object):
   17     """Model an attachment API response as a python dictionary."""
   18 
   19     _collection_name = "attachments"
   20 
   21     @staticmethod
   22     def _normalize(date):
   23         if date:
   24             return timeutils.normalize_time(date)
   25         return ''
   26 
   27     @classmethod
   28     def detail(cls, attachment, flat=False):
   29         """Detailed view of an attachment."""
   30         result = cls.summary(attachment, flat=True)
   31         result.update(
   32             attached_at=cls._normalize(attachment.attach_time),
   33             detached_at=cls._normalize(attachment.detach_time),
   34             attach_mode=attachment.attach_mode,
   35             connection_info=attachment.connection_info)
   36         if flat:
   37             return result
   38         return {'attachment': result}
   39 
   40     @staticmethod
   41     def summary(attachment, flat=False):
   42         """Non detailed view of an attachment."""
   43         result = {
   44             'id': attachment.id,
   45             'status': attachment.attach_status,
   46             'instance': attachment.instance_uuid,
   47             'volume_id': attachment.volume_id, }
   48         if flat:
   49             return result
   50         return {'attachment': result}
   51 
   52     @classmethod
   53     def list(cls, attachments, detail=False):
   54         """Build a view of a list of attachments."""
   55         func = cls.detail if detail else cls.summary
   56         return {'attachments': [func(attachment, flat=True) for attachment in
   57                                 attachments]}