Fix aarch64 image naming in parser
[parser.git] / tosca2heat / heat-translator / translator / common / images.py
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 logging
15
16 try:
17     import glanceclient.client
18     client_available = True
19 except ImportError:
20     client_available = False
21     pass
22
23 log = logging.getLogger('heat-translator')
24
25
26 PREDEF_IMAGES = {
27     'ubuntu-software-config-os-init': {'architecture': 'x86_64',
28                                        'os_type': 'linux',
29                                        'os_distro': 'ubuntu',
30                                        'os_version': '14.04'
31                                        },
32
33     'ubuntu-12.04-software-config-os-init': {'architecture': 'x86_64',
34                                              'os_type': 'linux',
35                                              'os_distro': 'ubuntu',
36                                              'os_version': '12.04'
37                                              },
38     'fedora-amd64-heat-config': {'architecture': 'x86_64',
39                                  'os_type': 'linux',
40                                  'os_distro': 'fedora',
41                                  'os_version': '18.0'
42                                  },
43     'F18-x86_64-cfntools': {'architecture': 'x86_64',
44                             'os_type': 'linux',
45                             'os_distro': 'fedora',
46                             'os_version': '19'
47                             },
48     'Fedora-x86_64-20-20131211.1-sda': {'architecture': 'x86_64',
49                                         'os_type': 'linux',
50                                         'os_distro': 'fedora',
51                                         'os_version': '20'
52                                         },
53     'cirros-0.3.1-x86_64-uec': {'architecture': 'x86_64',
54                                 'os_type': 'linux',
55                                 'os_distro': 'cirros',
56                                 'os_version': '0.3.1'
57                                 },
58     'cirros-0.3.2-x86_64-uec': {'architecture': 'x86_64',
59                                 'os_type': 'linux',
60                                 'os_distro': 'cirros',
61                                 'os_version': '0.3.2'
62                                 },
63     'rhel-6.5-test-image': {'architecture': 'x86_64',
64                             'os_type': 'linux',
65                             'os_distro': 'rhel',
66                             'os_version': '6.5'
67                             },
68     'cirros-0.4.0-aarch64-disk': {'architecture': 'aarch64',
69                                   'os_type': 'linux',
70                                   'os_distro': 'cirros',
71                                   'os_version': '0.4.0'
72                                   }
73 }
74
75 SESSION = None
76
77 IMAGES = {}
78
79
80 def get_images():
81     global IMAGES
82
83     if IMAGES:
84         return IMAGES
85
86     if SESSION is not None and client_available:
87         try:
88             client = glanceclient.client.Client("2", session=SESSION)
89         except Exception as e:
90             # Handles any exception coming from openstack
91             log.warn(_('Choosing predefined images since received '
92                        'Openstack Exception: %s') % str(e))
93         else:
94             for image in client.images.list():
95                 image_name = image.name.encode('ascii', 'ignore')
96                 metadata = ["architecture", "type", "distribution", "version",
97                             "os_distro", "os_type", "os_version"]
98                 if any(key in image.keys() for key in metadata):
99                     IMAGES[image_name] = {}
100                     for key in metadata:
101                         if key in image.keys():
102                             IMAGES[image_name][key] = image[key]
103
104     if not IMAGES:
105         IMAGES = PREDEF_IMAGES
106
107     return IMAGES