Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | ''' |
| 3 | Module for handling maas calls. |
| 4 | |
| 5 | :optdepends: pyapi-maas Python adapter |
| 6 | :configuration: This module is not usable until the following are specified |
| 7 | either in a pillar or in the minion's config file:: |
| 8 | |
| 9 | maas.url: 'https://maas.domain.com/' |
| 10 | maas.token: fdsfdsdsdsfa:fsdfae3fassd:fdsfdsfsafasdfsa |
| 11 | |
| 12 | ''' |
| 13 | |
| 14 | from __future__ import absolute_import |
| 15 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 16 | import io |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 17 | import logging |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 18 | import collections |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 19 | import os.path |
| 20 | import subprocess |
| 21 | import urllib2 |
| 22 | import hashlib |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 23 | |
smolaon | 27359ae | 2016-03-11 17:15:34 +0100 | [diff] [blame] | 24 | import json |
| 25 | |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 26 | LOG = logging.getLogger(__name__) |
| 27 | |
| 28 | # Import third party libs |
| 29 | HAS_MASS = False |
| 30 | try: |
Damian Szeluga | d0ac0ac | 2017-03-29 15:15:33 +0200 | [diff] [blame] | 31 | from maas_client import MAASClient, MAASDispatcher, MAASOAuth |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 32 | HAS_MASS = True |
| 33 | except ImportError: |
Damian Szeluga | a400421 | 2017-05-17 15:43:14 +0200 | [diff] [blame] | 34 | LOG.debug('Missing python-oauth module. Skipping') |
| 35 | pass |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 36 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 37 | |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 38 | def __virtual__(): |
| 39 | ''' |
| 40 | Only load this module if maas-client |
| 41 | is installed on this minion. |
| 42 | ''' |
| 43 | if HAS_MASS: |
| 44 | return 'maas' |
| 45 | return False |
| 46 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 47 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 48 | APIKEY_FILE = '/var/lib/maas/.maas_credentials' |
| 49 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 50 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 51 | def _format_data(data): |
| 52 | class Lazy: |
| 53 | def __str__(self): |
| 54 | return ' '.join(['{0}={1}'.format(k, v) |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 55 | for k, v in data.iteritems()]) |
Krzysztof Szukiełojć | 52cc6b0 | 2017-04-06 09:53:43 +0200 | [diff] [blame] | 56 | return Lazy() |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 57 | |
| 58 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 59 | def _create_maas_client(): |
| 60 | global APIKEY_FILE |
| 61 | try: |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 62 | api_token = file(APIKEY_FILE).read().splitlines()[-1].strip()\ |
| 63 | .split(':') |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 64 | except: |
| 65 | LOG.exception('token') |
| 66 | auth = MAASOAuth(*api_token) |
| 67 | api_url = 'http://localhost:5240/MAAS' |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 68 | dispatcher = MAASDispatcher() |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 69 | return MAASClient(auth, dispatcher, api_url) |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 70 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 71 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 72 | class MaasObject(object): |
| 73 | def __init__(self): |
| 74 | self._maas = _create_maas_client() |
| 75 | self._extra_data_urls = {} |
| 76 | self._extra_data = {} |
| 77 | self._update = False |
| 78 | self._element_key = 'name' |
| 79 | self._update_key = 'id' |
| 80 | |
| 81 | def send(self, data): |
| 82 | LOG.info('%s %s', self.__class__.__name__.lower(), _format_data(data)) |
| 83 | if self._update: |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 84 | return self._maas.put( |
| 85 | self._update_url.format(data[self._update_key]), **data).read() |
Krzysztof Szukiełojć | 43bc7e0 | 2017-03-17 10:32:07 +0100 | [diff] [blame] | 86 | if isinstance(self._create_url, tuple): |
Krzysztof Szukiełojć | d57a32d | 2017-04-04 11:25:02 +0200 | [diff] [blame] | 87 | return self._maas.post(self._create_url[0].format(**data), |
| 88 | *self._create_url[1:], **data).read() |
Krzysztof Szukiełojć | 76d9a5c | 2017-04-14 12:00:42 +0200 | [diff] [blame] | 89 | return self._maas.post(self._create_url.format(**data), |
| 90 | None, **data).read() |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 91 | |
Krzysztof Szukiełojć | f506220 | 2017-04-11 12:33:36 +0200 | [diff] [blame] | 92 | def process(self, objects_name=None): |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 93 | ret = { |
| 94 | 'success': [], |
| 95 | 'errors': {}, |
| 96 | 'updated': [], |
| 97 | } |
Krzysztof Szukiełojć | d57a32d | 2017-04-04 11:25:02 +0200 | [diff] [blame] | 98 | try: |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 99 | config = __salt__['config.get']('maas') |
| 100 | for part in self._config_path.split('.'): |
| 101 | config = config.get(part, {}) |
| 102 | extra = {} |
| 103 | for name, url_call in self._extra_data_urls.iteritems(): |
| 104 | key = 'id' |
| 105 | key_name = 'name' |
| 106 | if isinstance(url_call, tuple): |
| 107 | if len(url_call) == 2: |
| 108 | url_call, key = url_call[:] |
| 109 | else: |
| 110 | url_call, key, key_name = url_call[:] |
| 111 | json_res = json.loads(self._maas.get(url_call).read()) |
| 112 | if key: |
| 113 | extra[name] = {v[key_name]: v[key] for v in json_res} |
| 114 | else: |
Krzysztof Szukiełojć | 52cc6b0 | 2017-04-06 09:53:43 +0200 | [diff] [blame] | 115 | extra[name] = {v[key_name]: v for v in json_res} |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 116 | if self._all_elements_url: |
| 117 | all_elements = {} |
| 118 | elements = self._maas.get(self._all_elements_url).read() |
| 119 | res_json = json.loads(elements) |
| 120 | for element in res_json: |
| 121 | if isinstance(element, (str, unicode)): |
| 122 | all_elements[element] = {} |
| 123 | else: |
| 124 | all_elements[element[self._element_key]] = element |
| 125 | else: |
| 126 | all_elements = {} |
Krzysztof Szukiełojć | 222a3eb | 2017-04-11 09:39:07 +0200 | [diff] [blame] | 127 | |
| 128 | def process_single(name, config_data): |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 129 | self._update = False |
| 130 | try: |
| 131 | data = self.fill_data(name, config_data, **extra) |
| 132 | if data is None: |
| 133 | ret['updated'].append(name) |
Krzysztof Szukiełojć | 222a3eb | 2017-04-11 09:39:07 +0200 | [diff] [blame] | 134 | return |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 135 | if name in all_elements: |
| 136 | self._update = True |
| 137 | data = self.update(data, all_elements[name]) |
| 138 | self.send(data) |
| 139 | ret['updated'].append(name) |
| 140 | else: |
| 141 | self.send(data) |
| 142 | ret['success'].append(name) |
| 143 | except urllib2.HTTPError as e: |
| 144 | etxt = e.read() |
Krzysztof Szukiełojć | 199d5af | 2017-04-12 13:23:10 +0200 | [diff] [blame] | 145 | LOG.error('Failed for object %s reason %s', name, etxt) |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 146 | ret['errors'][name] = str(etxt) |
| 147 | except Exception as e: |
Krzysztof Szukiełojć | 199d5af | 2017-04-12 13:23:10 +0200 | [diff] [blame] | 148 | LOG.error('Failed for object %s reason %s', name, e) |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 149 | ret['errors'][name] = str(e) |
Krzysztof Szukiełojć | f506220 | 2017-04-11 12:33:36 +0200 | [diff] [blame] | 150 | if objects_name is not None: |
| 151 | if ',' in objects_name: |
| 152 | objects_name = objects_name.split(',') |
| 153 | else: |
| 154 | objects_name = [objects_name] |
| 155 | for object_name in objects_name: |
| 156 | process_single(object_name, config[object_name]) |
Krzysztof Szukiełojć | 222a3eb | 2017-04-11 09:39:07 +0200 | [diff] [blame] | 157 | else: |
| 158 | for name, config_data in config.iteritems(): |
| 159 | process_single(name, config_data) |
Krzysztof Szukiełojć | 04e1833 | 2017-04-04 11:51:44 +0200 | [diff] [blame] | 160 | except Exception as e: |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 161 | LOG.exception('Error Global') |
| 162 | raise |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 163 | if ret['errors']: |
| 164 | raise Exception(ret) |
| 165 | return ret |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 166 | |
| 167 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 168 | class Fabric(MaasObject): |
| 169 | def __init__(self): |
| 170 | super(Fabric, self).__init__() |
| 171 | self._all_elements_url = u'api/2.0/fabrics/' |
| 172 | self._create_url = u'api/2.0/fabrics/' |
| 173 | self._update_url = u'api/2.0/fabrics/{0}/' |
| 174 | self._config_path = 'region.fabrics' |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 175 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 176 | def fill_data(self, name, fabric): |
| 177 | data = { |
| 178 | 'name': name, |
| 179 | 'description': fabric.get('description', ''), |
| 180 | } |
| 181 | if 'class_type' in fabric: |
| 182 | data['class_type'] = fabric.get('class_type'), |
| 183 | return data |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 184 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 185 | def update(self, new, old): |
| 186 | new['id'] = str(old['id']) |
| 187 | return new |
Ales Komarek | 663b85c | 2016-03-11 14:26:42 +0100 | [diff] [blame] | 188 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 189 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 190 | class Subnet(MaasObject): |
| 191 | def __init__(self): |
| 192 | super(Subnet, self).__init__() |
| 193 | self._all_elements_url = u'api/2.0/subnets/' |
| 194 | self._create_url = u'api/2.0/subnets/' |
| 195 | self._update_url = u'api/2.0/subnets/{0}/' |
| 196 | self._config_path = 'region.subnets' |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 197 | self._extra_data_urls = {'fabrics': u'api/2.0/fabrics/'} |
Ales Komarek | 0fafa57 | 2016-03-11 14:56:44 +0100 | [diff] [blame] | 198 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 199 | def fill_data(self, name, subnet, fabrics): |
| 200 | data = { |
| 201 | 'name': name, |
| 202 | 'fabric': str(fabrics[subnet.get('fabric', '')]), |
| 203 | 'cidr': subnet.get('cidr'), |
| 204 | 'gateway_ip': subnet['gateway_ip'], |
| 205 | } |
| 206 | self._iprange = subnet['iprange'] |
| 207 | return data |
Krzysztof Szukiełojć | 15b62b7 | 2017-02-15 08:58:18 +0100 | [diff] [blame] | 208 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 209 | def update(self, new, old): |
| 210 | new['id'] = str(old['id']) |
| 211 | return new |
Ales Komarek | 0fafa57 | 2016-03-11 14:56:44 +0100 | [diff] [blame] | 212 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 213 | def send(self, data): |
| 214 | response = super(Subnet, self).send(data) |
| 215 | res_json = json.loads(response) |
| 216 | self._process_iprange(res_json['id']) |
| 217 | return response |
Krzysztof Szukiełojć | 15b62b7 | 2017-02-15 08:58:18 +0100 | [diff] [blame] | 218 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 219 | def _process_iprange(self, subnet_id): |
| 220 | ipranges = json.loads(self._maas.get(u'api/2.0/ipranges/').read()) |
| 221 | LOG.warn('all %s ipranges %s', subnet_id, ipranges) |
| 222 | update = False |
| 223 | old_data = None |
| 224 | for iprange in ipranges: |
| 225 | if iprange['subnet']['id'] == subnet_id: |
| 226 | update = True |
| 227 | old_data = iprange |
| 228 | break |
| 229 | data = { |
| 230 | 'start_ip': self._iprange.get('start'), |
| 231 | 'end_ip': self._iprange.get('end'), |
| 232 | 'subnet': str(subnet_id), |
| 233 | 'type': self._iprange.get('type', 'dynamic') |
| 234 | } |
| 235 | LOG.warn('INFO: %s\n OLD: %s', data, old_data) |
| 236 | LOG.info('iprange %s', _format_data(data)) |
| 237 | if update: |
| 238 | LOG.warn('UPDATING %s %s', data, old_data) |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 239 | self._maas.put(u'api/2.0/ipranges/{0}/'.format(old_data['id']), |
| 240 | **data) |
smolaon | c3385f8 | 2016-03-11 19:01:24 +0100 | [diff] [blame] | 241 | else: |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 242 | self._maas.post(u'api/2.0/ipranges/', None, **data) |
smolaon | c3385f8 | 2016-03-11 19:01:24 +0100 | [diff] [blame] | 243 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 244 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 245 | class DHCPSnippet(MaasObject): |
| 246 | def __init__(self): |
| 247 | super(DHCPSnippet, self).__init__() |
| 248 | self._all_elements_url = u'api/2.0/dhcp-snippets/' |
| 249 | self._create_url = u'api/2.0/dhcp-snippets/' |
| 250 | self._update_url = u'api/2.0/dhcp-snippets/{0}/' |
| 251 | self._config_path = 'region.dhcp_snippets' |
| 252 | self._extra_data_urls = {'subnets': u'api/2.0/subnets/'} |
Krzysztof Szukiełojć | 15b62b7 | 2017-02-15 08:58:18 +0100 | [diff] [blame] | 253 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 254 | def fill_data(self, name, snippet, subnets): |
| 255 | data = { |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 256 | 'name': name, |
| 257 | 'value': snippet['value'], |
| 258 | 'description': snippet['description'], |
| 259 | 'enabled': str(snippet['enabled'] and 1 or 0), |
| 260 | 'subnet': str(subnets[snippet['subnet']]), |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 261 | } |
| 262 | return data |
smolaon | c3385f8 | 2016-03-11 19:01:24 +0100 | [diff] [blame] | 263 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 264 | def update(self, new, old): |
| 265 | new['id'] = str(old['id']) |
| 266 | return new |
Krzysztof Szukiełojć | 15b62b7 | 2017-02-15 08:58:18 +0100 | [diff] [blame] | 267 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 268 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 269 | class PacketRepository(MaasObject): |
| 270 | def __init__(self): |
| 271 | super(PacketRepository, self).__init__() |
| 272 | self._all_elements_url = u'api/2.0/package-repositories/' |
| 273 | self._create_url = u'api/2.0/package-repositories/' |
| 274 | self._update_url = u'api/2.0/package-repositories/{0}/' |
| 275 | self._config_path = 'region.package_repositories' |
Krzysztof Szukiełojć | 15b62b7 | 2017-02-15 08:58:18 +0100 | [diff] [blame] | 276 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 277 | def fill_data(self, name, package_repository): |
| 278 | data = { |
| 279 | 'name': name, |
| 280 | 'url': package_repository['url'], |
| 281 | 'distributions': package_repository['distributions'], |
| 282 | 'components': package_repository['components'], |
| 283 | 'arches': package_repository['arches'], |
| 284 | 'key': package_repository['key'], |
| 285 | 'enabled': str(package_repository['enabled'] and 1 or 0), |
| 286 | } |
| 287 | if 'disabled_pockets' in package_repository: |
| 288 | data['disabled_pockets'] = package_repository['disable_pockets'], |
| 289 | return data |
Krzysztof Szukiełojć | 15b62b7 | 2017-02-15 08:58:18 +0100 | [diff] [blame] | 290 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 291 | def update(self, new, old): |
| 292 | new['id'] = str(old['id']) |
| 293 | return new |
Krzysztof Szukiełojć | 15b62b7 | 2017-02-15 08:58:18 +0100 | [diff] [blame] | 294 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 295 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 296 | class Device(MaasObject): |
| 297 | def __init__(self): |
| 298 | super(Device, self).__init__() |
| 299 | self._all_elements_url = u'api/2.0/devices/' |
| 300 | self._create_url = u'api/2.0/devices/' |
| 301 | self._update_url = u'api/2.0/devices/{0}/' |
| 302 | self._config_path = 'region.devices' |
| 303 | self._element_key = 'hostname' |
| 304 | self._update_key = 'system_id' |
smolaon | c3385f8 | 2016-03-11 19:01:24 +0100 | [diff] [blame] | 305 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 306 | def fill_data(self, name, device_data): |
| 307 | data = { |
| 308 | 'mac_addresses': device_data['mac'], |
| 309 | 'hostname': name, |
| 310 | } |
| 311 | self._interface = device_data['interface'] |
| 312 | return data |
| 313 | |
| 314 | def update(self, new, old): |
Krzysztof Szukiełojć | a6352a4 | 2017-03-17 14:21:57 +0100 | [diff] [blame] | 315 | old_macs = set(v['mac_address'].lower() for v in old['interface_set']) |
| 316 | if new['mac_addresses'].lower() not in old_macs: |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 317 | self._update = False |
Krzysztof Szukiełojć | a6352a4 | 2017-03-17 14:21:57 +0100 | [diff] [blame] | 318 | LOG.info('Mac changed deleting old device %s', old['system_id']) |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 319 | self._maas.delete(u'api/2.0/devices/{0}/'.format(old['system_id'])) |
| 320 | else: |
| 321 | new[self._update_key] = str(old[self._update_key]) |
| 322 | return new |
| 323 | |
| 324 | def send(self, data): |
| 325 | response = super(Device, self).send(data) |
| 326 | resp_json = json.loads(response) |
| 327 | system_id = resp_json['system_id'] |
| 328 | iface_id = resp_json['interface_set'][0]['id'] |
Krzysztof Szukiełojć | a6352a4 | 2017-03-17 14:21:57 +0100 | [diff] [blame] | 329 | self._link_interface(system_id, iface_id) |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 330 | return response |
| 331 | |
| 332 | def _link_interface(self, system_id, interface_id): |
| 333 | data = { |
| 334 | 'mode': self._interface.get('mode', 'STATIC'), |
Krzysztof Szukiełojć | a6352a4 | 2017-03-17 14:21:57 +0100 | [diff] [blame] | 335 | 'subnet': self._interface['subnet'], |
| 336 | 'ip_address': self._interface['ip_address'], |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 337 | } |
| 338 | if 'default_gateway' in self._interface: |
| 339 | data['default_gateway'] = self._interface.get('default_gateway') |
| 340 | if self._update: |
| 341 | data['force'] = '1' |
| 342 | LOG.info('interfaces link_subnet %s %s %s', system_id, interface_id, |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 343 | _format_data(data)) |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 344 | self._maas.post(u'/api/2.0/nodes/{0}/interfaces/{1}/' |
| 345 | .format(system_id, interface_id), 'link_subnet', |
| 346 | **data) |
| 347 | |
| 348 | |
| 349 | class Machine(MaasObject): |
| 350 | def __init__(self): |
| 351 | super(Machine, self).__init__() |
| 352 | self._all_elements_url = u'api/2.0/machines/' |
| 353 | self._create_url = u'api/2.0/machines/' |
| 354 | self._update_url = u'api/2.0/machines/{0}/' |
| 355 | self._config_path = 'region.machines' |
| 356 | self._element_key = 'hostname' |
| 357 | self._update_key = 'system_id' |
| 358 | |
| 359 | def fill_data(self, name, machine_data): |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 360 | power_data = machine_data['power_parameters'] |
| 361 | data = { |
| 362 | 'hostname': name, |
| 363 | 'architecture': machine_data.get('architecture', 'amd64/generic'), |
Krzysztof Szukiełojć | d57a32d | 2017-04-04 11:25:02 +0200 | [diff] [blame] | 364 | 'mac_addresses': machine_data['interface']['mac'], |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 365 | 'power_type': machine_data.get('power_type', 'ipmi'), |
| 366 | 'power_parameters_power_address': power_data['power_address'], |
| 367 | } |
Ondrej Smola | 455003c | 2017-06-01 22:53:39 +0200 | [diff] [blame^] | 368 | if 'power_driver' in power_data: |
| 369 | data['power_parameters_power_driver'] = power_data['power_driver'] |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 370 | if 'power_user' in power_data: |
| 371 | data['power_parameters_power_user'] = power_data['power_user'] |
| 372 | if 'power_password' in power_data: |
| 373 | data['power_parameters_power_pass'] = \ |
| 374 | power_data['power_password'] |
| 375 | return data |
| 376 | |
| 377 | def update(self, new, old): |
Krzysztof Szukiełojć | a6352a4 | 2017-03-17 14:21:57 +0100 | [diff] [blame] | 378 | old_macs = set(v['mac_address'].lower() for v in old['interface_set']) |
| 379 | if new['mac_addresses'].lower() not in old_macs: |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 380 | self._update = False |
Krzysztof Szukiełojć | a6352a4 | 2017-03-17 14:21:57 +0100 | [diff] [blame] | 381 | LOG.info('Mac changed deleting old machine %s', old['system_id']) |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 382 | self._maas.delete(u'api/2.0/machines/{0}/' |
| 383 | .format(old['system_id'])) |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 384 | else: |
| 385 | new[self._update_key] = str(old[self._update_key]) |
| 386 | return new |
| 387 | |
Krzysztof Szukiełojć | d57a32d | 2017-04-04 11:25:02 +0200 | [diff] [blame] | 388 | |
| 389 | class AssignMachinesIP(MaasObject): |
Krzysztof Szukiełojć | d6ee1a0 | 2017-04-07 14:01:30 +0200 | [diff] [blame] | 390 | READY = 4 |
| 391 | |
Krzysztof Szukiełojć | d57a32d | 2017-04-04 11:25:02 +0200 | [diff] [blame] | 392 | def __init__(self): |
| 393 | super(AssignMachinesIP, self).__init__() |
| 394 | self._all_elements_url = None |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 395 | self._create_url = \ |
| 396 | (u'/api/2.0/nodes/{system_id}/interfaces/{interface_id}/', |
| 397 | 'link_subnet') |
Krzysztof Szukiełojć | d57a32d | 2017-04-04 11:25:02 +0200 | [diff] [blame] | 398 | self._config_path = 'region.machines' |
| 399 | self._element_key = 'hostname' |
| 400 | self._update_key = 'system_id' |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 401 | self._extra_data_urls = {'machines': (u'api/2.0/machines/', |
| 402 | None, 'hostname')} |
Krzysztof Szukiełojć | d57a32d | 2017-04-04 11:25:02 +0200 | [diff] [blame] | 403 | |
| 404 | def fill_data(self, name, data, machines): |
| 405 | interface = data['interface'] |
| 406 | machine = machines[name] |
Krzysztof Szukiełojć | d6ee1a0 | 2017-04-07 14:01:30 +0200 | [diff] [blame] | 407 | if machine['status'] != self.READY: |
| 408 | raise Exception('Not in ready state') |
Krzysztof Szukiełojć | d57a32d | 2017-04-04 11:25:02 +0200 | [diff] [blame] | 409 | if 'ip' not in interface: |
Krzysztof Szukiełojć | a6352a4 | 2017-03-17 14:21:57 +0100 | [diff] [blame] | 410 | return |
| 411 | data = { |
| 412 | 'mode': 'STATIC', |
Krzysztof Szukiełojć | d57a32d | 2017-04-04 11:25:02 +0200 | [diff] [blame] | 413 | 'subnet': str(interface.get('subnet')), |
| 414 | 'ip_address': str(interface.get('ip')), |
Krzysztof Szukiełojć | a6352a4 | 2017-03-17 14:21:57 +0100 | [diff] [blame] | 415 | } |
Krzysztof Szukiełojć | d57a32d | 2017-04-04 11:25:02 +0200 | [diff] [blame] | 416 | if 'default_gateway' in interface: |
| 417 | data['default_gateway'] = interface.get('gateway') |
Krzysztof Szukiełojć | 9449af1 | 2017-04-11 14:01:30 +0200 | [diff] [blame] | 418 | data['force'] = '1' |
Krzysztof Szukiełojć | d57a32d | 2017-04-04 11:25:02 +0200 | [diff] [blame] | 419 | data['system_id'] = str(machine['system_id']) |
| 420 | data['interface_id'] = str(machine['interface_set'][0]['id']) |
| 421 | return data |
Krzysztof Szukiełojć | a6352a4 | 2017-03-17 14:21:57 +0100 | [diff] [blame] | 422 | |
| 423 | |
Krzysztof Szukiełojć | 7c16e05 | 2017-04-05 10:04:45 +0200 | [diff] [blame] | 424 | class DeployMachines(MaasObject): |
Krzysztof Szukiełojć | 008d7d4 | 2017-04-05 15:26:01 +0200 | [diff] [blame] | 425 | READY = 4 |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 426 | |
Krzysztof Szukiełojć | 7c16e05 | 2017-04-05 10:04:45 +0200 | [diff] [blame] | 427 | def __init__(self): |
| 428 | super(DeployMachines, self).__init__() |
| 429 | self._all_elements_url = None |
| 430 | self._create_url = (u'api/2.0/machines/{system_id}/', 'deploy') |
| 431 | self._config_path = 'region.machines' |
| 432 | self._element_key = 'hostname' |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 433 | self._extra_data_urls = {'machines': (u'api/2.0/machines/', |
| 434 | None, 'hostname')} |
Krzysztof Szukiełojć | 7c16e05 | 2017-04-05 10:04:45 +0200 | [diff] [blame] | 435 | |
| 436 | def fill_data(self, name, machine_data, machines): |
Krzysztof Szukiełojć | 008d7d4 | 2017-04-05 15:26:01 +0200 | [diff] [blame] | 437 | machine = machines[name] |
| 438 | if machine['status'] != self.READY: |
| 439 | raise Exception('Not in ready state') |
Krzysztof Szukiełojć | 7c16e05 | 2017-04-05 10:04:45 +0200 | [diff] [blame] | 440 | data = { |
Krzysztof Szukiełojć | 008d7d4 | 2017-04-05 15:26:01 +0200 | [diff] [blame] | 441 | 'system_id': machine['system_id'], |
Krzysztof Szukiełojć | 7c16e05 | 2017-04-05 10:04:45 +0200 | [diff] [blame] | 442 | } |
Krzysztof Szukiełojć | 32677bf | 2017-04-13 11:04:25 +0200 | [diff] [blame] | 443 | if 'distro_series' in machine_data: |
Krzysztof Szukiełojć | 008d7d4 | 2017-04-05 15:26:01 +0200 | [diff] [blame] | 444 | data['distro_series'] = machine_data['distro_series'] |
Krzysztof Szukiełojć | 7c16e05 | 2017-04-05 10:04:45 +0200 | [diff] [blame] | 445 | if 'hwe_kernel' in machine_data: |
Krzysztof Szukiełojć | 008d7d4 | 2017-04-05 15:26:01 +0200 | [diff] [blame] | 446 | data['hwe_kernel'] = machine_data['hwe_kernel'] |
Krzysztof Szukiełojć | 7c16e05 | 2017-04-05 10:04:45 +0200 | [diff] [blame] | 447 | return data |
| 448 | |
Krzysztof Szukiełojć | 33f9b59 | 2017-04-12 11:43:50 +0200 | [diff] [blame] | 449 | def send(self, data): |
| 450 | LOG.info('%s %s', self.__class__.__name__.lower(), _format_data(data)) |
Krzysztof Szukiełojć | 3b7516d | 2017-04-12 11:52:55 +0200 | [diff] [blame] | 451 | self._maas.post(u'api/2.0/machines/', 'allocate', system_id=data['system_id']).read() |
Krzysztof Szukiełojć | 33f9b59 | 2017-04-12 11:43:50 +0200 | [diff] [blame] | 452 | return self._maas.post(self._create_url[0].format(**data), |
| 453 | *self._create_url[1:], **data).read() |
Krzysztof Szukiełojć | 7c16e05 | 2017-04-05 10:04:45 +0200 | [diff] [blame] | 454 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 455 | class BootResource(MaasObject): |
| 456 | def __init__(self): |
| 457 | super(BootResource, self).__init__() |
| 458 | self._all_elements_url = u'api/2.0/boot-resources/' |
| 459 | self._create_url = u'api/2.0/boot-resources/' |
| 460 | self._update_url = u'api/2.0/boot-resources/{0}/' |
| 461 | self._config_path = 'region.boot_resources' |
| 462 | |
| 463 | def fill_data(self, name, boot_data): |
| 464 | sha256 = hashlib.sha256() |
| 465 | sha256.update(file(boot_data['content']).read()) |
| 466 | data = { |
| 467 | 'name': name, |
| 468 | 'title': boot_data['title'], |
| 469 | 'architecture': boot_data['architecture'], |
| 470 | 'filetype': boot_data['filetype'], |
| 471 | 'size': str(os.path.getsize(boot_data['content'])), |
| 472 | 'sha256': sha256.hexdigest(), |
| 473 | 'content': io.open(boot_data['content']), |
| 474 | } |
| 475 | return data |
| 476 | |
| 477 | def update(self, new, old): |
| 478 | self._update = False |
| 479 | return new |
| 480 | |
Krzysztof Szukiełojć | 7c16e05 | 2017-04-05 10:04:45 +0200 | [diff] [blame] | 481 | |
Krzysztof Szukiełojć | 43bc7e0 | 2017-03-17 10:32:07 +0100 | [diff] [blame] | 482 | class CommissioningScripts(MaasObject): |
| 483 | def __init__(self): |
| 484 | super(CommissioningScripts, self).__init__() |
| 485 | self._all_elements_url = u'api/2.0/commissioning-scripts/' |
| 486 | self._create_url = u'api/2.0/commissioning-scripts/' |
Krzysztof Szukiełojć | 43bc7e0 | 2017-03-17 10:32:07 +0100 | [diff] [blame] | 487 | self._config_path = 'region.commissioning_scripts' |
Krzysztof Szukiełojć | a6352a4 | 2017-03-17 14:21:57 +0100 | [diff] [blame] | 488 | self._update_url = u'api/2.0/commissioning-scripts/{0}' |
Krzysztof Szukiełojć | 43bc7e0 | 2017-03-17 10:32:07 +0100 | [diff] [blame] | 489 | self._update_key = 'name' |
| 490 | |
| 491 | def fill_data(self, name, file_path): |
| 492 | data = { |
| 493 | 'name': name, |
| 494 | 'content': io.open(file_path), |
| 495 | } |
| 496 | return data |
| 497 | |
| 498 | def update(self, new, old): |
| 499 | return new |
| 500 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 501 | |
Krzysztof Szukiełojć | 43bc7e0 | 2017-03-17 10:32:07 +0100 | [diff] [blame] | 502 | class MaasConfig(MaasObject): |
| 503 | def __init__(self): |
| 504 | super(MaasConfig, self).__init__() |
| 505 | self._all_elements_url = None |
| 506 | self._create_url = (u'api/2.0/maas/', u'set_config') |
| 507 | self._config_path = 'region.maas_config' |
| 508 | |
| 509 | def fill_data(self, name, value): |
| 510 | data = { |
| 511 | 'name': name, |
Krzysztof Szukiełojć | a6352a4 | 2017-03-17 14:21:57 +0100 | [diff] [blame] | 512 | 'value': str(value), |
Krzysztof Szukiełojć | 43bc7e0 | 2017-03-17 10:32:07 +0100 | [diff] [blame] | 513 | } |
| 514 | return data |
| 515 | |
| 516 | def update(self, new, old): |
| 517 | self._update = False |
| 518 | return new |
| 519 | |
| 520 | |
Krzysztof Szukiełojć | a1bd77e | 2017-03-30 08:34:22 +0200 | [diff] [blame] | 521 | class SSHPrefs(MaasObject): |
| 522 | def __init__(self): |
| 523 | super(SSHPrefs, self).__init__() |
| 524 | self._all_elements_url = None |
| 525 | self._create_url = u'api/2.0/account/prefs/sshkeys/' |
| 526 | self._config_path = 'region.sshprefs' |
| 527 | self._element_key = 'hostname' |
| 528 | self._update_key = 'system_id' |
| 529 | |
| 530 | def fill_data(self, value): |
| 531 | data = { |
| 532 | 'key': value, |
| 533 | } |
| 534 | return data |
| 535 | |
| 536 | def process(self): |
| 537 | config = __salt__['config.get']('maas') |
| 538 | for part in self._config_path.split('.'): |
| 539 | config = config.get(part, {}) |
| 540 | extra = {} |
| 541 | for name, url_call in self._extra_data_urls.iteritems(): |
| 542 | key = 'id' |
| 543 | if isinstance(url_call, tuple): |
| 544 | url_call, key = url_call[:] |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 545 | json_res = json.loads(self._maas.get(url_call).read()) |
| 546 | extra[name] = {v['name']: v[key] for v in json_res} |
Krzysztof Szukiełojć | a1bd77e | 2017-03-30 08:34:22 +0200 | [diff] [blame] | 547 | if self._all_elements_url: |
| 548 | all_elements = {} |
| 549 | elements = self._maas.get(self._all_elements_url).read() |
| 550 | res_json = json.loads(elements) |
| 551 | for element in res_json: |
| 552 | if isinstance(element, (str, unicode)): |
| 553 | all_elements[element] = {} |
| 554 | else: |
| 555 | all_elements[element[self._element_key]] = element |
| 556 | else: |
| 557 | all_elements = {} |
| 558 | ret = { |
| 559 | 'success': [], |
| 560 | 'errors': {}, |
| 561 | 'updated': [], |
| 562 | } |
| 563 | for config_data in config: |
| 564 | name = config_data[:10] |
| 565 | try: |
| 566 | data = self.fill_data(config_data, **extra) |
| 567 | self.send(data) |
| 568 | ret['success'].append(name) |
| 569 | except urllib2.HTTPError as e: |
| 570 | etxt = e.read() |
| 571 | LOG.exception('Failed for object %s reason %s', name, etxt) |
| 572 | ret['errors'][name] = str(etxt) |
| 573 | except Exception as e: |
| 574 | LOG.exception('Failed for object %s reason %s', name, e) |
| 575 | ret['errors'][name] = str(e) |
| 576 | if ret['errors']: |
| 577 | raise Exception(ret) |
| 578 | return ret |
Krzysztof Szukiełojć | 8cc32b4 | 2017-03-29 15:22:57 +0200 | [diff] [blame] | 579 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 580 | |
Krzysztof Szukiełojć | 8cc32b4 | 2017-03-29 15:22:57 +0200 | [diff] [blame] | 581 | class Domain(MaasObject): |
| 582 | def __init__(self): |
| 583 | super(Domain, self).__init__() |
| 584 | self._all_elements_url = u'/api/2.0/domains/' |
| 585 | self._create_url = u'/api/2.0/domains/' |
| 586 | self._config_path = 'region.domain' |
| 587 | self._update_url = u'/api/2.0/domains/{0}/' |
| 588 | |
| 589 | def fill_data(self, value): |
| 590 | data = { |
| 591 | 'name': value, |
| 592 | } |
| 593 | self._update = True |
| 594 | return data |
| 595 | |
| 596 | def update(self, new, old): |
| 597 | new['id'] = str(old['id']) |
| 598 | new['authoritative'] = str(old['authoritative']) |
| 599 | return new |
| 600 | |
| 601 | def process(self): |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 602 | ret = { |
| 603 | 'success': [], |
| 604 | 'errors': {}, |
| 605 | 'updated': [], |
| 606 | } |
Krzysztof Szukiełojć | 8cc32b4 | 2017-03-29 15:22:57 +0200 | [diff] [blame] | 607 | config = __salt__['config.get']('maas') |
| 608 | for part in self._config_path.split('.'): |
| 609 | config = config.get(part, {}) |
| 610 | extra = {} |
| 611 | for name, url_call in self._extra_data_urls.iteritems(): |
| 612 | key = 'id' |
| 613 | if isinstance(url_call, tuple): |
| 614 | url_call, key = url_call[:] |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 615 | json_res = json.loads(self._maas.get(url_call).read()) |
| 616 | extra[name] = {v['name']: v[key] for v in json_res} |
Krzysztof Szukiełojć | 8cc32b4 | 2017-03-29 15:22:57 +0200 | [diff] [blame] | 617 | if self._all_elements_url: |
| 618 | all_elements = {} |
| 619 | elements = self._maas.get(self._all_elements_url).read() |
| 620 | res_json = json.loads(elements) |
| 621 | for element in res_json: |
| 622 | if isinstance(element, (str, unicode)): |
| 623 | all_elements[element] = {} |
| 624 | else: |
| 625 | all_elements[element[self._element_key]] = element |
| 626 | else: |
| 627 | all_elements = {} |
Krzysztof Szukiełojć | 8cc32b4 | 2017-03-29 15:22:57 +0200 | [diff] [blame] | 628 | try: |
| 629 | data = self.fill_data(config, **extra) |
| 630 | data = self.update(data, all_elements.values()[0]) |
| 631 | self.send(data) |
| 632 | ret['success'].append('domain') |
| 633 | except urllib2.HTTPError as e: |
| 634 | etxt = e.read() |
| 635 | LOG.exception('Failed for object %s reason %s', 'domain', etxt) |
| 636 | ret['errors']['domain'] = str(etxt) |
| 637 | except Exception as e: |
| 638 | LOG.exception('Failed for object %s reason %s', 'domain', e) |
| 639 | ret['errors']['domain'] = str(e) |
| 640 | if ret['errors']: |
| 641 | raise Exception(ret) |
| 642 | return ret |
| 643 | |
| 644 | |
Krzysztof Szukiełojć | 04e1833 | 2017-04-04 11:51:44 +0200 | [diff] [blame] | 645 | class MachinesStatus(MaasObject): |
| 646 | @classmethod |
Krzysztof Szukiełojć | f506220 | 2017-04-11 12:33:36 +0200 | [diff] [blame] | 647 | def execute(cls, objects_name=None): |
Krzysztof Szukiełojć | 0be1a16 | 2017-04-04 11:59:09 +0200 | [diff] [blame] | 648 | cls._maas = _create_maas_client() |
| 649 | result = cls._maas.get(u'api/2.0/machines/') |
Krzysztof Szukiełojć | 04e1833 | 2017-04-04 11:51:44 +0200 | [diff] [blame] | 650 | json_result = json.loads(result.read()) |
| 651 | res = [] |
Krzysztof Szukiełojć | 0be1a16 | 2017-04-04 11:59:09 +0200 | [diff] [blame] | 652 | status_name_dict = dict([ |
| 653 | (0, 'New'), (1, 'Commissioning'), (2, 'Failed commissioning'), |
| 654 | (3, 'Missing'), (4, 'Ready'), (5, 'Reserved'), (10, 'Allocated'), |
| 655 | (9, 'Deploying'), (6, 'Deployed'), (7, 'Retired'), (8, 'Broken'), |
| 656 | (11, 'Failed deployment'), (12, 'Releasing'), |
| 657 | (13, 'Releasing failed'), (14, 'Disk erasing'), |
| 658 | (15, 'Failed disk erasing')]) |
| 659 | summary = collections.Counter() |
Krzysztof Szukiełojć | f506220 | 2017-04-11 12:33:36 +0200 | [diff] [blame] | 660 | if objects_name: |
| 661 | if ',' in objects_name: |
| 662 | objects_name = set(objects_name.split(',')) |
| 663 | else: |
| 664 | objects_name = set([objects_name]) |
Krzysztof Szukiełojć | 04e1833 | 2017-04-04 11:51:44 +0200 | [diff] [blame] | 665 | for machine in json_result: |
Krzysztof Szukiełojć | f506220 | 2017-04-11 12:33:36 +0200 | [diff] [blame] | 666 | if objects_name and machine['hostname'] not in objects_name: |
Krzysztof Szukiełojć | 2497cdb | 2017-04-11 09:50:28 +0200 | [diff] [blame] | 667 | continue |
Krzysztof Szukiełojć | 0be1a16 | 2017-04-04 11:59:09 +0200 | [diff] [blame] | 668 | status = status_name_dict[machine['status']] |
| 669 | summary[status] += 1 |
Krzysztof Szukiełojć | 02e10d3 | 2017-04-12 12:23:51 +0200 | [diff] [blame] | 670 | res.append('hostname:{},system_id:{},status:{}' |
| 671 | .format(machine['hostname'], machine['system_id'], |
| 672 | status)) |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 673 | return {'machines': res, 'summary': summary} |
Krzysztof Szukiełojć | 04e1833 | 2017-04-04 11:51:44 +0200 | [diff] [blame] | 674 | |
| 675 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 676 | def process_fabrics(): |
| 677 | return Fabric().process() |
| 678 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 679 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 680 | def process_subnets(): |
| 681 | return Subnet().process() |
| 682 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 683 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 684 | def process_dhcp_snippets(): |
| 685 | return DHCPSnippet().process() |
| 686 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 687 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 688 | def process_package_repositories(): |
| 689 | return PacketRepository().process() |
| 690 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 691 | |
Krzysztof Szukiełojć | 889eee9 | 2017-04-14 11:45:35 +0200 | [diff] [blame] | 692 | def process_devices(*args): |
| 693 | return Device().process(*args) |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 694 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 695 | |
Krzysztof Szukiełojć | 222a3eb | 2017-04-11 09:39:07 +0200 | [diff] [blame] | 696 | def process_machines(*args): |
| 697 | return Machine().process(*args) |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 698 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 699 | |
Krzysztof Szukiełojć | 222a3eb | 2017-04-11 09:39:07 +0200 | [diff] [blame] | 700 | def process_assign_machines_ip(*args): |
| 701 | return AssignMachinesIP().process(*args) |
Krzysztof Szukiełojć | 04e1833 | 2017-04-04 11:51:44 +0200 | [diff] [blame] | 702 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 703 | |
Krzysztof Szukiełojć | 222a3eb | 2017-04-11 09:39:07 +0200 | [diff] [blame] | 704 | def machines_status(*args): |
| 705 | return MachinesStatus.execute(*args) |
Krzysztof Szukiełojć | 04e1833 | 2017-04-04 11:51:44 +0200 | [diff] [blame] | 706 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 707 | |
Krzysztof Szukiełojć | 222a3eb | 2017-04-11 09:39:07 +0200 | [diff] [blame] | 708 | def deploy_machines(*args): |
| 709 | return DeployMachines().process(*args) |
Krzysztof Szukiełojć | 7c16e05 | 2017-04-05 10:04:45 +0200 | [diff] [blame] | 710 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 711 | |
Krzysztof Szukiełojć | c4b3309 | 2017-02-15 13:25:38 +0100 | [diff] [blame] | 712 | def process_boot_resources(): |
| 713 | return BootResource().process() |
Krzysztof Szukiełojć | 43bc7e0 | 2017-03-17 10:32:07 +0100 | [diff] [blame] | 714 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 715 | |
Krzysztof Szukiełojć | 43bc7e0 | 2017-03-17 10:32:07 +0100 | [diff] [blame] | 716 | def process_maas_config(): |
| 717 | return MaasConfig().process() |
| 718 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 719 | |
Krzysztof Szukiełojć | 43bc7e0 | 2017-03-17 10:32:07 +0100 | [diff] [blame] | 720 | def process_commissioning_scripts(): |
| 721 | return CommissioningScripts().process() |
Krzysztof Szukiełojć | 8cc32b4 | 2017-03-29 15:22:57 +0200 | [diff] [blame] | 722 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 723 | |
Krzysztof Szukiełojć | 8cc32b4 | 2017-03-29 15:22:57 +0200 | [diff] [blame] | 724 | def process_domain(): |
| 725 | return Domain().process() |
Krzysztof Szukiełojć | a1bd77e | 2017-03-30 08:34:22 +0200 | [diff] [blame] | 726 | |
Krzysztof Szukiełojć | b321675 | 2017-04-05 15:50:41 +0200 | [diff] [blame] | 727 | |
Krzysztof Szukiełojć | a1bd77e | 2017-03-30 08:34:22 +0200 | [diff] [blame] | 728 | def process_sshprefs(): |
| 729 | return SSHPrefs().process() |