Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 1 | # Copyright 2016 Mirantis, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | import os |
| 16 | |
| 17 | from devops import error |
| 18 | from devops.helpers import helpers |
| 19 | from devops import models |
| 20 | from django import db |
| 21 | from oslo_config import cfg |
| 22 | |
| 23 | from tcp_tests import settings |
| 24 | from tcp_tests import settings_oslo |
| 25 | from tcp_tests.helpers import env_config |
| 26 | from tcp_tests.helpers import ext |
| 27 | from tcp_tests.helpers import exceptions |
| 28 | from tcp_tests import logger |
| 29 | |
| 30 | LOG = logger.logger |
| 31 | |
| 32 | |
| 33 | class EnvironmentManager(object): |
| 34 | """Class-helper for creating VMs via devops environments""" |
| 35 | |
Dmitry Tyzhnenko | 1fb041c | 2017-04-28 16:07:48 +0300 | [diff] [blame] | 36 | __config = None |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 37 | |
| 38 | def __init__(self, config=None): |
| 39 | """Initializing class instance and create the environment |
| 40 | |
| 41 | :param config: oslo.config object |
| 42 | :param config.hardware.conf_path: path to devops YAML template |
| 43 | :param config.hardware.current_snapshot: name of the snapshot that |
| 44 | descriebe environment status. |
| 45 | """ |
| 46 | self.__devops_config = env_config.EnvironmentConfig() |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 47 | self.__env = None |
Dmitry Tyzhnenko | 1fb041c | 2017-04-28 16:07:48 +0300 | [diff] [blame] | 48 | self.__config = config |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 49 | |
| 50 | if config.hardware.conf_path is not None: |
| 51 | self._devops_config.load_template(config.hardware.conf_path) |
| 52 | else: |
| 53 | raise Exception("Devops YAML template is not set in config object") |
| 54 | |
| 55 | try: |
| 56 | self._get_env_by_name(self._d_env_name) |
| 57 | if not self.has_snapshot(config.hardware.current_snapshot): |
| 58 | raise exceptions.EnvironmentSnapshotMissing( |
| 59 | self._d_env_name, config.hardware.current_snapshot) |
| 60 | except error.DevopsObjNotFound: |
| 61 | LOG.info("Environment doesn't exist, creating a new one") |
| 62 | self._create_environment() |
| 63 | self.set_dns_config() |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 64 | self.set_address_pools_config() |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 65 | |
| 66 | @property |
| 67 | def _devops_config(self): |
| 68 | return self.__devops_config |
| 69 | |
| 70 | @_devops_config.setter |
| 71 | def _devops_config(self, conf): |
| 72 | """Setter for self.__devops_config |
| 73 | |
| 74 | :param conf: tcp_tests.helpers.env_config.EnvironmentConfig |
| 75 | """ |
| 76 | if not isinstance(conf, env_config.EnvironmentConfig): |
| 77 | msg = ("Unexpected type of devops config. Got '{0}' " + |
| 78 | "instead of '{1}'") |
| 79 | raise TypeError( |
| 80 | msg.format( |
| 81 | type(conf).__name__, |
| 82 | env_config.EnvironmentConfig.__name__ |
| 83 | ) |
| 84 | ) |
| 85 | self.__devops_config = conf |
| 86 | |
| 87 | def lvm_storages(self): |
| 88 | """Returns a dict object of lvm storages in current environment |
| 89 | |
| 90 | returned data example: |
| 91 | { |
| 92 | "master": { |
| 93 | "id": "virtio-bff72959d1a54cb19d08" |
| 94 | }, |
| 95 | "slave-0": { |
| 96 | "id": "virtio-5e33affc8fe44503839f" |
| 97 | }, |
| 98 | "slave-1": { |
| 99 | "id": "virtio-10b6a262f1ec4341a1ba" |
| 100 | }, |
| 101 | } |
| 102 | |
| 103 | :rtype: dict |
| 104 | """ |
| 105 | result = {} |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 106 | for node in self.__env.get_nodes(role__in=ext.UNDERLAY_NODE_ROLES): |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 107 | lvm = filter(lambda x: x.volume.name == 'lvm', node.disk_devices) |
| 108 | if len(lvm) == 0: |
| 109 | continue |
| 110 | lvm = lvm[0] |
| 111 | result[node.name] = {} |
| 112 | result_node = result[node.name] |
| 113 | result_node['id'] = "{bus}-{serial}".format( |
| 114 | bus=lvm.bus, |
| 115 | serial=lvm.volume.serial[:20]) |
| 116 | LOG.info("Got disk-id '{}' for node '{}'".format( |
| 117 | result_node['id'], node.name)) |
| 118 | return result |
| 119 | |
| 120 | @property |
| 121 | def _d_env_name(self): |
| 122 | """Get environment name from fuel devops config |
| 123 | |
| 124 | :rtype: string |
| 125 | """ |
| 126 | return self._devops_config['env_name'] |
| 127 | |
| 128 | def _get_env_by_name(self, name): |
| 129 | """Set existing environment by name |
| 130 | |
| 131 | :param name: string |
| 132 | """ |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 133 | self.__env = models.Environment.get(name=name) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 134 | |
| 135 | def _get_default_node_group(self): |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 136 | return self.__env.get_group(name='default') |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 137 | |
| 138 | def _get_network_pool(self, net_pool_name): |
| 139 | default_node_group = self._get_default_node_group() |
| 140 | network_pool = default_node_group.get_network_pool(name=net_pool_name) |
| 141 | return network_pool |
| 142 | |
| 143 | def get_ssh_data(self, roles=None): |
| 144 | """Generate ssh config for Underlay |
| 145 | |
| 146 | :param roles: list of strings |
| 147 | """ |
| 148 | if roles is None: |
| 149 | raise Exception("No roles specified for the environment!") |
| 150 | |
| 151 | config_ssh = [] |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 152 | for d_node in self.__env.get_nodes(role__in=roles): |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 153 | ssh_data = { |
| 154 | 'node_name': d_node.name, |
Dennis Dmitriev | 474e3f7 | 2016-10-21 16:46:09 +0300 | [diff] [blame] | 155 | 'roles': [d_node.role], |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 156 | 'address_pool': self._get_network_pool( |
dis | c529838 | 2016-11-23 16:03:33 +0200 | [diff] [blame] | 157 | ext.NETWORK_TYPE.admin).address_pool.name, |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 158 | 'host': self.node_ip(d_node), |
| 159 | 'login': settings.SSH_NODE_CREDENTIALS['login'], |
| 160 | 'password': settings.SSH_NODE_CREDENTIALS['password'], |
| 161 | } |
| 162 | config_ssh.append(ssh_data) |
| 163 | return config_ssh |
| 164 | |
| 165 | def create_snapshot(self, name, description=None): |
| 166 | """Create named snapshot of current env. |
| 167 | |
| 168 | - Create a libvirt snapshots for all nodes in the environment |
| 169 | - Save 'config' object to a file 'config_<name>.ini' |
| 170 | |
| 171 | :name: string |
| 172 | """ |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 173 | msg = "[ Create snapshot '{0}' ] {1}".format(name, description or '') |
| 174 | LOG.info("\n\n{0}\n{1}".format(msg, '*' * len(msg))) |
| 175 | |
Dmitry Tyzhnenko | 1fb041c | 2017-04-28 16:07:48 +0300 | [diff] [blame] | 176 | self.__config.hardware.current_snapshot = name |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 177 | LOG.info("Set current snapshot in config to '{0}'".format( |
Dmitry Tyzhnenko | 1fb041c | 2017-04-28 16:07:48 +0300 | [diff] [blame] | 178 | self.__config.hardware.current_snapshot)) |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 179 | if self.__env is not None: |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 180 | LOG.info('trying to suspend ....') |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 181 | self.__env.suspend() |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 182 | LOG.info('trying to snapshot ....') |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 183 | self.__env.snapshot(name, description=description, force=True) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 184 | LOG.info('trying to resume ....') |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 185 | self.__env.resume() |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 186 | else: |
| 187 | raise exceptions.EnvironmentIsNotSet() |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 188 | settings_oslo.save_config(self.__config, name, self.__env.name) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 189 | |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 190 | if settings.VIRTUAL_ENV: |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 191 | venv_msg = "source {0}/bin/activate;\n".format( |
| 192 | settings.VIRTUAL_ENV) |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 193 | else: |
| 194 | venv_msg = "" |
| 195 | LOG.info("To revert the snapshot:\n\n" |
| 196 | "************************************\n" |
| 197 | "{venv_msg}" |
| 198 | "dos.py revert {env_name} {snapshot_name};\n" |
| 199 | "dos.py resume {env_name};\n" |
| 200 | "# dos.py time-sync {env_name}; # Optional\n" |
| 201 | "ssh {login}@{salt_master_host} # Password: {password}\n" |
| 202 | "************************************\n" |
| 203 | .format(venv_msg=venv_msg, |
| 204 | env_name=settings.ENV_NAME, |
| 205 | snapshot_name=name, |
| 206 | login=settings.SSH_NODE_CREDENTIALS['login'], |
| 207 | password=settings.SSH_NODE_CREDENTIALS['password'], |
Dmitry Tyzhnenko | 1fb041c | 2017-04-28 16:07:48 +0300 | [diff] [blame] | 208 | salt_master_host=self.__config.salt.salt_master_host)) |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 209 | |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 210 | def _get_snapshot_config_name(self, snapshot_name): |
| 211 | """Get config name for the environment""" |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 212 | env_name = self.__env.name |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 213 | if env_name is None: |
| 214 | env_name = 'config' |
| 215 | test_config_path = os.path.join( |
| 216 | settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name)) |
| 217 | return test_config_path |
| 218 | |
| 219 | def revert_snapshot(self, name): |
| 220 | """Revert snapshot by name |
| 221 | |
| 222 | - Revert a libvirt snapshots for all nodes in the environment |
| 223 | - Try to reload 'config' object from a file 'config_<name>.ini' |
| 224 | If the file not found, then pass with defaults. |
| 225 | - Set <name> as the current state of the environment after reload |
| 226 | |
| 227 | :param name: string |
| 228 | """ |
| 229 | LOG.info("Reverting from snapshot named '{0}'".format(name)) |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 230 | if self.__env is not None: |
| 231 | self.__env.revert(name=name) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 232 | LOG.info("Resuming environment after revert") |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 233 | self.__env.resume() |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 234 | else: |
| 235 | raise exceptions.EnvironmentIsNotSet() |
| 236 | |
| 237 | try: |
| 238 | test_config_path = self._get_snapshot_config_name(name) |
Dmitry Tyzhnenko | 1fb041c | 2017-04-28 16:07:48 +0300 | [diff] [blame] | 239 | settings_oslo.reload_snapshot_config(self.__config, |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 240 | test_config_path) |
| 241 | except cfg.ConfigFilesNotFoundError as conf_err: |
| 242 | LOG.error("Config file(s) {0} not found!".format( |
| 243 | conf_err.config_files)) |
| 244 | |
Dmitry Tyzhnenko | 1fb041c | 2017-04-28 16:07:48 +0300 | [diff] [blame] | 245 | self.__config.hardware.current_snapshot = name |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 246 | |
| 247 | def _create_environment(self): |
| 248 | """Create environment and start VMs. |
| 249 | |
| 250 | If config was provided earlier, we simply create and start VMs, |
| 251 | otherwise we tries to generate config from self.config_file, |
| 252 | """ |
| 253 | if self._devops_config.config is None: |
| 254 | raise exceptions.DevopsConfigPathIsNotSet() |
| 255 | settings = self._devops_config |
| 256 | env_name = settings['env_name'] |
| 257 | LOG.debug( |
| 258 | 'Preparing to create environment named "{0}"'.format(env_name) |
| 259 | ) |
| 260 | if env_name is None: |
| 261 | LOG.error('Environment name is not set!') |
| 262 | raise exceptions.EnvironmentNameIsNotSet() |
| 263 | try: |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 264 | self.__env = models.Environment.create_environment( |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 265 | settings.config |
| 266 | ) |
| 267 | except db.IntegrityError: |
| 268 | LOG.error( |
dis | 2b2d863 | 2016-12-08 17:56:57 +0200 | [diff] [blame] | 269 | 'Seems like environment {0} already exists or contain errors' |
| 270 | ' in template.'.format(env_name) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 271 | ) |
dis | 2b2d863 | 2016-12-08 17:56:57 +0200 | [diff] [blame] | 272 | raise |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 273 | self.__env.define() |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 274 | LOG.info( |
Dennis Dmitriev | 53d3b77 | 2016-10-18 14:31:58 +0300 | [diff] [blame] | 275 | 'Environment "{0}" created'.format(env_name) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 276 | ) |
| 277 | |
| 278 | def start(self): |
| 279 | """Method for start environment |
| 280 | |
| 281 | """ |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 282 | if self.__env is None: |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 283 | raise exceptions.EnvironmentIsNotSet() |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 284 | self.__env.start() |
| 285 | LOG.info('Environment "{0}" started'.format(self.__env.name)) |
| 286 | for node in self.__env.get_nodes(role__in=ext.UNDERLAY_NODE_ROLES): |
Dennis Dmitriev | 53d3b77 | 2016-10-18 14:31:58 +0300 | [diff] [blame] | 287 | LOG.info("Waiting for SSH on node '{}...'".format(node.name)) |
dis | c529838 | 2016-11-23 16:03:33 +0200 | [diff] [blame] | 288 | timeout = 480 |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 289 | helpers.wait( |
| 290 | lambda: helpers.tcp_ping(self.node_ip(node), 22), |
| 291 | timeout=timeout, |
| 292 | timeout_msg="Node '{}' didn't open SSH in {} sec".format( |
| 293 | node.name, timeout |
| 294 | ) |
| 295 | ) |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 296 | LOG.info('Environment "{0}" ready'.format(self.__env.name)) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 297 | |
| 298 | def resume(self): |
| 299 | """Resume environment""" |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 300 | if self.__env is None: |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 301 | raise exceptions.EnvironmentIsNotSet() |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 302 | self.__env.resume() |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 303 | |
| 304 | def suspend(self): |
| 305 | """Suspend environment""" |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 306 | if self.__env is None: |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 307 | raise exceptions.EnvironmentIsNotSet() |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 308 | self.__env.suspend() |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 309 | |
| 310 | def stop(self): |
| 311 | """Stop environment""" |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 312 | if self.__env is None: |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 313 | raise exceptions.EnvironmentIsNotSet() |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 314 | self.__env.destroy() |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 315 | |
| 316 | def has_snapshot(self, name): |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 317 | return self.__env.has_snapshot(name) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 318 | |
| 319 | def has_snapshot_config(self, name): |
| 320 | test_config_path = self._get_snapshot_config_name(name) |
| 321 | return os.path.isfile(test_config_path) |
| 322 | |
| 323 | def delete_environment(self): |
| 324 | """Delete environment |
| 325 | |
| 326 | """ |
| 327 | LOG.debug("Deleting environment") |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 328 | self.__env.erase() |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 329 | |
| 330 | def __get_nodes_by_role(self, node_role): |
| 331 | """Get node by given role name |
| 332 | |
| 333 | :param node_role: string |
| 334 | :rtype: devops.models.Node |
| 335 | """ |
| 336 | LOG.debug('Trying to get nodes by role {0}'.format(node_role)) |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 337 | return self.__env.get_nodes(role=node_role) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 338 | |
| 339 | @property |
| 340 | def master_nodes(self): |
| 341 | """Get all master nodes |
| 342 | |
| 343 | :rtype: list |
| 344 | """ |
| 345 | nodes = self.__get_nodes_by_role( |
Dennis Dmitriev | 53d3b77 | 2016-10-18 14:31:58 +0300 | [diff] [blame] | 346 | node_role=ext.UNDERLAY_NODE_ROLES.salt_master) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 347 | return nodes |
| 348 | |
| 349 | @property |
| 350 | def slave_nodes(self): |
| 351 | """Get all slave nodes |
| 352 | |
| 353 | :rtype: list |
| 354 | """ |
| 355 | nodes = self.__get_nodes_by_role( |
Dennis Dmitriev | 53d3b77 | 2016-10-18 14:31:58 +0300 | [diff] [blame] | 356 | node_role=ext.UNDERLAY_NODE_ROLES.salt_minion) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 357 | return nodes |
| 358 | |
Dennis Dmitriev | 53d3b77 | 2016-10-18 14:31:58 +0300 | [diff] [blame] | 359 | @staticmethod |
| 360 | def node_ip(node): |
| 361 | """Determine node's IP |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 362 | |
Dennis Dmitriev | 53d3b77 | 2016-10-18 14:31:58 +0300 | [diff] [blame] | 363 | :param node: devops.models.Node |
| 364 | :return: string |
| 365 | """ |
| 366 | LOG.debug('Trying to determine {0} ip.'.format(node.name)) |
| 367 | return node.get_ip_address_by_network_name( |
dis | c529838 | 2016-11-23 16:03:33 +0200 | [diff] [blame] | 368 | ext.NETWORK_TYPE.admin |
Dennis Dmitriev | 53d3b77 | 2016-10-18 14:31:58 +0300 | [diff] [blame] | 369 | ) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 370 | |
| 371 | @property |
| 372 | def nameserver(self): |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 373 | return self.__env.router(ext.NETWORK_TYPE.admin) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 374 | |
| 375 | def set_dns_config(self): |
| 376 | # Set local nameserver to use by default |
Dmitry Tyzhnenko | 1fb041c | 2017-04-28 16:07:48 +0300 | [diff] [blame] | 377 | if not self.__config.underlay.nameservers: |
| 378 | self.__config.underlay.nameservers = [self.nameserver] |
| 379 | if not self.__config.underlay.upstream_dns_servers: |
| 380 | self.__config.underlay.upstream_dns_servers = [self.nameserver] |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 381 | |
| 382 | def set_address_pools_config(self): |
| 383 | """Store address pools CIDRs in config object""" |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame^] | 384 | for ap in self.__env.get_address_pools(): |
Dmitry Tyzhnenko | 1fb041c | 2017-04-28 16:07:48 +0300 | [diff] [blame] | 385 | self.__config.underlay.address_pools[ap.name] = ap.net |