Ken'ichi Ohmichi | 01151e8 | 2016-06-10 11:19:52 -0700 | [diff] [blame] | 1 | # Copyright 2016 NEC Corporation |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | |
| 17 | def get_image_meta_from_headers(resp): |
| 18 | meta = {'properties': {}} |
| 19 | for key in resp.response: |
| 20 | value = resp.response[key] |
| 21 | if key.startswith('x-image-meta-property-'): |
| 22 | _key = key[22:] |
| 23 | meta['properties'][_key] = value |
| 24 | elif key.startswith('x-image-meta-'): |
| 25 | _key = key[13:] |
| 26 | meta[_key] = value |
| 27 | |
| 28 | for key in ['is_public', 'protected', 'deleted']: |
| 29 | if key in meta: |
| 30 | meta[key] = meta[key].strip().lower() in ('t', 'true', 'yes', '1') |
| 31 | |
| 32 | for key in ['size', 'min_ram', 'min_disk']: |
| 33 | if key in meta: |
| 34 | try: |
| 35 | meta[key] = int(meta[key]) |
| 36 | except ValueError: |
| 37 | pass |
| 38 | return meta |