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