Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 1 | package com.mirantis.mk |
| 2 | |
| 3 | /** |
| 4 | * |
| 5 | * Openstack functions |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | /** |
Tomáš Kukrál | c3964e5 | 2017-02-22 14:07:37 +0100 | [diff] [blame] | 10 | * Convert maps |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | @NonCPS def entries(m) { |
| 15 | return m.collect {k, v -> [k, v]} |
| 16 | } |
| 17 | |
| 18 | /** |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 19 | * Install OpenStack service clients in isolated environment |
| 20 | * |
| 21 | * @param path Path where virtualenv is created |
| 22 | * @param version Version of the OpenStack clients |
| 23 | */ |
| 24 | |
Tomáš Kukrál | bee0b99 | 2017-08-10 16:50:40 +0200 | [diff] [blame] | 25 | def setupOpenstackVirtualenv(path, version = 'latest') { |
iberezovskiy | d4240b5 | 2017-02-20 17:18:28 +0400 | [diff] [blame] | 26 | def python = new com.mirantis.mk.Python() |
Vasyl Saienko | 030fc18 | 2017-07-12 14:54:42 +0300 | [diff] [blame] | 27 | python.setupDocutilsVirtualenv(path) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 28 | |
| 29 | def openstack_kilo_packages = [ |
| 30 | 'python-cinderclient>=1.3.1,<1.4.0', |
| 31 | 'python-glanceclient>=0.19.0,<0.20.0', |
| 32 | 'python-heatclient>=0.6.0,<0.7.0', |
| 33 | 'python-keystoneclient>=1.6.0,<1.7.0', |
| 34 | 'python-neutronclient>=2.2.6,<2.3.0', |
| 35 | 'python-novaclient>=2.19.0,<2.20.0', |
| 36 | 'python-swiftclient>=2.5.0,<2.6.0', |
Jakub Josef | bd92732 | 2017-05-30 13:20:27 +0000 | [diff] [blame] | 37 | 'python-openstackclient>=1.7.0,<1.8.0', |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 38 | 'oslo.config>=2.2.0,<2.3.0', |
| 39 | 'oslo.i18n>=2.3.0,<2.4.0', |
| 40 | 'oslo.serialization>=1.8.0,<1.9.0', |
| 41 | 'oslo.utils>=1.4.0,<1.5.0', |
Jakub Josef | 6028021 | 2017-08-10 19:01:19 +0200 | [diff] [blame^] | 42 | 'docutils' |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 43 | ] |
| 44 | |
Tomáš Kukrál | 381a8c9 | 2017-06-21 09:01:52 +0200 | [diff] [blame] | 45 | def openstack_latest_packages = [ |
| 46 | 'python-openstackclient', |
| 47 | 'python-heatclient', |
Jakub Josef | 6028021 | 2017-08-10 19:01:19 +0200 | [diff] [blame^] | 48 | 'docutils' |
Tomáš Kukrál | c6a94c6 | 2017-06-19 14:44:24 +0200 | [diff] [blame] | 49 | ] |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 50 | |
Tomáš Kukrál | c6a94c6 | 2017-06-19 14:44:24 +0200 | [diff] [blame] | 51 | if (version == 'kilo') { |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 52 | requirements = openstack_kilo_packages |
Tomáš Kukrál | c6a94c6 | 2017-06-19 14:44:24 +0200 | [diff] [blame] | 53 | } else if (version == 'liberty') { |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 54 | requirements = openstack_kilo_packages |
Tomáš Kukrál | c6a94c6 | 2017-06-19 14:44:24 +0200 | [diff] [blame] | 55 | } else if (version == 'mitaka') { |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 56 | requirements = openstack_kilo_packages |
Tomáš Kukrál | 381a8c9 | 2017-06-21 09:01:52 +0200 | [diff] [blame] | 57 | } else { |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 58 | requirements = openstack_latest_packages |
| 59 | } |
Tomáš Kukrál | bee0b99 | 2017-08-10 16:50:40 +0200 | [diff] [blame] | 60 | python.setupVirtualenv(path, 'python2', requirements, null, true) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /** |
| 64 | * create connection to OpenStack API endpoint |
| 65 | * |
| 66 | * @param url OpenStack API endpoint address |
| 67 | * @param credentialsId Credentials to the OpenStack API |
| 68 | * @param project OpenStack project to connect to |
| 69 | */ |
kairat_kushaev | 0a26bf7 | 2017-05-18 13:20:09 +0400 | [diff] [blame] | 70 | def createOpenstackEnv(url, credentialsId, project, project_domain="default", |
Tomáš Kukrál | 381a8c9 | 2017-06-21 09:01:52 +0200 | [diff] [blame] | 71 | project_id="", user_domain="default", api_ver="2", cacert="/etc/ssl/certs/ca-certificates.crt") { |
iberezovskiy | d4240b5 | 2017-02-20 17:18:28 +0400 | [diff] [blame] | 72 | def common = new com.mirantis.mk.Common() |
Ales Komarek | 0e558ee | 2016-12-23 13:02:55 +0100 | [diff] [blame] | 73 | rcFile = "${env.WORKSPACE}/keystonerc" |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 74 | creds = common.getPasswordCredentials(credentialsId) |
Alexander Tivelkov | f89a188 | 2017-01-11 13:29:35 +0300 | [diff] [blame] | 75 | rc = """set +x |
| 76 | export OS_USERNAME=${creds.username} |
Ales Komarek | 0e558ee | 2016-12-23 13:02:55 +0100 | [diff] [blame] | 77 | export OS_PASSWORD=${creds.password.toString()} |
| 78 | export OS_TENANT_NAME=${project} |
| 79 | export OS_AUTH_URL=${url} |
| 80 | export OS_AUTH_STRATEGY=keystone |
kairat_kushaev | 0a26bf7 | 2017-05-18 13:20:09 +0400 | [diff] [blame] | 81 | export OS_PROJECT_NAME=${project} |
Jakub Josef | bd92732 | 2017-05-30 13:20:27 +0000 | [diff] [blame] | 82 | export OS_PROJECT_ID=${project_id} |
kairat_kushaev | 0a26bf7 | 2017-05-18 13:20:09 +0400 | [diff] [blame] | 83 | export OS_PROJECT_DOMAIN_ID=${project_domain} |
Jakub Josef | bd92732 | 2017-05-30 13:20:27 +0000 | [diff] [blame] | 84 | export OS_USER_DOMAIN_NAME=${user_domain} |
Kirill Mashchenko | 234708f | 2017-07-20 17:00:01 +0300 | [diff] [blame] | 85 | export OS_IDENTITY_API_VERSION=${api_ver} |
Tomáš Kukrál | 381a8c9 | 2017-06-21 09:01:52 +0200 | [diff] [blame] | 86 | export OS_CACERT=${cacert} |
Alexander Tivelkov | f89a188 | 2017-01-11 13:29:35 +0300 | [diff] [blame] | 87 | set -x |
Ales Komarek | 0e558ee | 2016-12-23 13:02:55 +0100 | [diff] [blame] | 88 | """ |
| 89 | writeFile file: rcFile, text: rc |
| 90 | return rcFile |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Run command with OpenStack env params and optional python env |
| 95 | * |
| 96 | * @param cmd Command to be executed |
| 97 | * @param env Environmental parameters with endpoint credentials |
| 98 | * @param path Optional path to virtualenv with specific clients |
| 99 | */ |
| 100 | def runOpenstackCommand(cmd, venv, path = null) { |
iberezovskiy | d4240b5 | 2017-02-20 17:18:28 +0400 | [diff] [blame] | 101 | def python = new com.mirantis.mk.Python() |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 102 | openstackCmd = ". ${venv}; ${cmd}" |
| 103 | if (path) { |
| 104 | output = python.runVirtualenvCommand(path, openstackCmd) |
| 105 | } |
| 106 | else { |
| 107 | echo("[Command]: ${openstackCmd}") |
| 108 | output = sh ( |
| 109 | script: openstackCmd, |
| 110 | returnStdout: true |
| 111 | ).trim() |
| 112 | } |
| 113 | return output |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Get OpenStack Keystone token for current credentials |
| 118 | * |
| 119 | * @param env Connection parameters for OpenStack API endpoint |
| 120 | * @param path Optional path to the custom virtualenv |
| 121 | */ |
| 122 | def getKeystoneToken(client, path = null) { |
iberezovskiy | d4240b5 | 2017-02-20 17:18:28 +0400 | [diff] [blame] | 123 | def python = new com.mirantis.mk.Python() |
Jakub Josef | bd92732 | 2017-05-30 13:20:27 +0000 | [diff] [blame] | 124 | cmd = "openstack token issue" |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 125 | outputTable = runOpenstackCommand(cmd, client, path) |
Ales Komarek | e11e879 | 2016-12-28 09:42:25 +0100 | [diff] [blame] | 126 | output = python.parseTextTable(outputTable, 'item', 'prettytable', path) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 127 | return output |
| 128 | } |
| 129 | |
| 130 | /** |
Ales Komarek | 51b7b15 | 2017-06-27 11:14:50 +0200 | [diff] [blame] | 131 | * Create OpenStack environment file |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 132 | * |
| 133 | * @param env Connection parameters for OpenStack API endpoint |
| 134 | * @param path Optional path to the custom virtualenv |
| 135 | */ |
| 136 | def createHeatEnv(file, environment = [], original_file = null) { |
| 137 | if (original_file) { |
| 138 | envString = readFile file: original_file |
Tomáš Kukrál | 0302944 | 2017-02-21 17:14:29 +0100 | [diff] [blame] | 139 | } else { |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 140 | envString = "parameters:\n" |
| 141 | } |
Tomáš Kukrál | 0302944 | 2017-02-21 17:14:29 +0100 | [diff] [blame] | 142 | |
Tomáš Kukrál | c3964e5 | 2017-02-22 14:07:37 +0100 | [diff] [blame] | 143 | p = entries(environment) |
Tomáš Kukrál | b1fe964 | 2017-02-22 11:21:17 +0100 | [diff] [blame] | 144 | for (int i = 0; i < p.size(); i++) { |
| 145 | envString = "${envString} ${p.get(i)[0]}: ${p.get(i)[1]}\n" |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 146 | } |
Tomáš Kukrál | 0302944 | 2017-02-21 17:14:29 +0100 | [diff] [blame] | 147 | |
Tomáš Kukrál | e19ddea | 2017-02-21 11:09:40 +0100 | [diff] [blame] | 148 | echo("writing to env file:\n${envString}") |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 149 | writeFile file: file, text: envString |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Create new OpenStack Heat stack |
| 154 | * |
| 155 | * @param env Connection parameters for OpenStack API endpoint |
| 156 | * @param template HOT template for the new Heat stack |
| 157 | * @param environment Environmentale parameters of the new Heat stack |
| 158 | * @param name Name of the new Heat stack |
| 159 | * @param path Optional path to the custom virtualenv |
Ales Komarek | 51b7b15 | 2017-06-27 11:14:50 +0200 | [diff] [blame] | 160 | * @param legacy_env Use old path format [env_name/template_name] to |
| 161 | * target env file. |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 162 | */ |
Ales Komarek | 51b7b15 | 2017-06-27 11:14:50 +0200 | [diff] [blame] | 163 | def createHeatStack(client, name, template, params = [], environment = null, path = null, legacy_env = true) { |
iberezovskiy | d4240b5 | 2017-02-20 17:18:28 +0400 | [diff] [blame] | 164 | def python = new com.mirantis.mk.Python() |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 165 | templateFile = "${env.WORKSPACE}/template/template/${template}.hot" |
| 166 | if (environment) { |
Ales Komarek | 51b7b15 | 2017-06-27 11:14:50 +0200 | [diff] [blame] | 167 | if (legacy_env) { |
| 168 | envFile = "${env.WORKSPACE}/template/env/${template}/${name}.env" |
| 169 | envSource = "${env.WORKSPACE}/template/env/${template}/${environment}.env" |
| 170 | } |
| 171 | else { |
Ales Komarek | d6142a8 | 2017-06-28 15:22:04 +0200 | [diff] [blame] | 172 | envFile = "${env.WORKSPACE}/template/env/${name}.env" |
Ales Komarek | 51b7b15 | 2017-06-27 11:14:50 +0200 | [diff] [blame] | 173 | envSource = "${env.WORKSPACE}/template/env/${environment}.env" |
| 174 | } |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 175 | createHeatEnv(envFile, params, envSource) |
| 176 | } |
| 177 | else { |
| 178 | envFile = "${env.WORKSPACE}/template/${name}.env" |
| 179 | createHeatEnv(envFile, params) |
| 180 | } |
| 181 | cmd = "heat stack-create -f ${templateFile} -e ${envFile} ${name}" |
| 182 | dir("${env.WORKSPACE}/template/template") { |
| 183 | outputTable = runOpenstackCommand(cmd, client, path) |
| 184 | } |
Ales Komarek | e11e879 | 2016-12-28 09:42:25 +0100 | [diff] [blame] | 185 | output = python.parseTextTable(outputTable, 'item', 'prettytable', path) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 186 | |
| 187 | i = 1 |
Ales Komarek | dce8b47 | 2016-12-30 16:56:07 +0100 | [diff] [blame] | 188 | |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 189 | while (true) { |
| 190 | status = getHeatStackStatus(client, name, path) |
| 191 | echo("[Heat Stack] Status: ${status}, Check: ${i}") |
Ales Komarek | dce8b47 | 2016-12-30 16:56:07 +0100 | [diff] [blame] | 192 | |
| 193 | if (status.indexOf('CREATE_FAILED') != -1) { |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 194 | info = getHeatStackInfo(client, name, path) |
| 195 | throw new Exception(info.stack_status_reason) |
| 196 | } |
Ales Komarek | dce8b47 | 2016-12-30 16:56:07 +0100 | [diff] [blame] | 197 | else if (status.indexOf('CREATE_COMPLETE') != -1) { |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 198 | info = getHeatStackInfo(client, name, path) |
| 199 | echo(info.stack_status_reason) |
| 200 | break |
| 201 | } |
| 202 | sh('sleep 5s') |
| 203 | i++ |
| 204 | } |
| 205 | echo("[Heat Stack] Status: ${status}") |
| 206 | } |
| 207 | |
| 208 | /** |
Jakub Josef | db4baf2 | 2017-05-10 15:16:09 +0200 | [diff] [blame] | 209 | * Returns list of stacks for stack name filter |
| 210 | * |
| 211 | * @param client Connection parameters for OpenStack API endpoint |
| 212 | * @param filter Stack name filter |
| 213 | * @param path Optional path to the custom virtualenv |
| 214 | */ |
| 215 | def getStacksForNameContains(client, filter, path = null){ |
Jakub Josef | 6465fca | 2017-05-10 16:09:20 +0200 | [diff] [blame] | 216 | cmd = 'heat stack-list | awk \'NR>3 {print $4}\' | sed \'$ d\' | grep ' + filter + '|| true' |
Jakub Josef | db4baf2 | 2017-05-10 15:16:09 +0200 | [diff] [blame] | 217 | return runOpenstackCommand(cmd, client, path).trim().tokenize("\n") |
| 218 | } |
| 219 | |
| 220 | |
| 221 | /** |
Jakub Josef | 5e238a2 | 2017-04-19 16:35:15 +0200 | [diff] [blame] | 222 | * Get list of stack names with given stack status |
| 223 | * |
Jakub Josef | db4baf2 | 2017-05-10 15:16:09 +0200 | [diff] [blame] | 224 | * @param client Connection parameters for OpenStack API endpoint |
Jakub Josef | 5e238a2 | 2017-04-19 16:35:15 +0200 | [diff] [blame] | 225 | * @param status Stack status |
| 226 | * @param path Optional path to the custom virtualenv |
| 227 | */ |
| 228 | def getStacksWithStatus(client, status, path = null) { |
| 229 | cmd = 'heat stack-list -f stack_status='+status+' | awk \'NR>3 {print $4}\' | sed \'$ d\'' |
| 230 | return runOpenstackCommand(cmd, client, path).trim().tokenize("\n") |
| 231 | } |
| 232 | |
| 233 | /** |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 234 | * Get life cycle status for existing OpenStack Heat stack |
| 235 | * |
| 236 | * @param env Connection parameters for OpenStack API endpoint |
| 237 | * @param name Name of the managed Heat stack instance |
| 238 | * @param path Optional path to the custom virtualenv |
| 239 | */ |
| 240 | def getHeatStackStatus(client, name, path = null) { |
| 241 | cmd = 'heat stack-list | awk -v stack='+name+' \'{if ($4==stack) print $6}\'' |
| 242 | return runOpenstackCommand(cmd, client, path) |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Get info about existing OpenStack Heat stack |
| 247 | * |
| 248 | * @param env Connection parameters for OpenStack API endpoint |
| 249 | * @param name Name of the managed Heat stack instance |
| 250 | * @param path Optional path to the custom virtualenv |
| 251 | */ |
| 252 | def getHeatStackInfo(env, name, path = null) { |
iberezovskiy | d4240b5 | 2017-02-20 17:18:28 +0400 | [diff] [blame] | 253 | def python = new com.mirantis.mk.Python() |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 254 | cmd = "heat stack-show ${name}" |
| 255 | outputTable = runOpenstackCommand(cmd, env, path) |
Ales Komarek | e11e879 | 2016-12-28 09:42:25 +0100 | [diff] [blame] | 256 | output = python.parseTextTable(outputTable, 'item', 'prettytable', path) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 257 | return output |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Get existing OpenStack Heat stack output parameter |
| 262 | * |
| 263 | * @param env Connection parameters for OpenStack API endpoint |
| 264 | * @param name Name of the managed Heat stack |
| 265 | * @param parameter Name of the output parameter |
| 266 | * @param path Optional path to the custom virtualenv |
| 267 | */ |
| 268 | def getHeatStackOutputParam(env, name, outputParam, path = null) { |
Vasyl Saienko | ea4b281 | 2017-07-10 10:36:03 +0000 | [diff] [blame] | 269 | cmd = "heat output-show ${name} ${outputParam}" |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 270 | output = runOpenstackCommand(cmd, env, path) |
Ales Komarek | eedc222 | 2017-01-03 10:10:03 +0100 | [diff] [blame] | 271 | echo("${cmd}: ${output}") |
Vasyl Saienko | 2a1c2de | 2017-07-11 11:41:53 +0300 | [diff] [blame] | 272 | // NOTE(vsaienko) heatclient 1.5.1 returns output in "", while later |
| 273 | // versions returns string without "". |
| 274 | // TODO Use openstack 'stack output show' when all jobs using at least Mitaka heatclient |
| 275 | return "${output}".replaceAll('"', '') |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /** |
| 279 | * List all resources from existing OpenStack Heat stack |
| 280 | * |
| 281 | * @param env Connection parameters for OpenStack API endpoint |
| 282 | * @param name Name of the managed Heat stack instance |
| 283 | * @param path Optional path to the custom virtualenv |
| 284 | */ |
| 285 | def getHeatStackResources(env, name, path = null) { |
iberezovskiy | d4240b5 | 2017-02-20 17:18:28 +0400 | [diff] [blame] | 286 | def python = new com.mirantis.mk.Python() |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 287 | cmd = "heat resource-list ${name}" |
| 288 | outputTable = runOpenstackCommand(cmd, env, path) |
Ales Komarek | e11e879 | 2016-12-28 09:42:25 +0100 | [diff] [blame] | 289 | output = python.parseTextTable(outputTable, 'list', 'prettytable', path) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 290 | return output |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Get info about resource from existing OpenStack Heat stack |
| 295 | * |
| 296 | * @param env Connection parameters for OpenStack API endpoint |
| 297 | * @param name Name of the managed Heat stack instance |
| 298 | * @param path Optional path to the custom virtualenv |
| 299 | */ |
| 300 | def getHeatStackResourceInfo(env, name, resource, path = null) { |
iberezovskiy | d4240b5 | 2017-02-20 17:18:28 +0400 | [diff] [blame] | 301 | def python = new com.mirantis.mk.Python() |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 302 | cmd = "heat resource-show ${name} ${resource}" |
| 303 | outputTable = runOpenstackCommand(cmd, env, path) |
Ales Komarek | e11e879 | 2016-12-28 09:42:25 +0100 | [diff] [blame] | 304 | output = python.parseTextTable(outputTable, 'item', 'prettytable', path) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 305 | return output |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Update existing OpenStack Heat stack |
| 310 | * |
| 311 | * @param env Connection parameters for OpenStack API endpoint |
| 312 | * @param name Name of the managed Heat stack instance |
| 313 | * @param path Optional path to the custom virtualenv |
| 314 | */ |
| 315 | def updateHeatStack(env, name, path = null) { |
iberezovskiy | d4240b5 | 2017-02-20 17:18:28 +0400 | [diff] [blame] | 316 | def python = new com.mirantis.mk.Python() |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 317 | cmd = "heat stack-update ${name}" |
| 318 | outputTable = runOpenstackCommand(cmd, env, path) |
Ales Komarek | e11e879 | 2016-12-28 09:42:25 +0100 | [diff] [blame] | 319 | output = python.parseTextTable(outputTable, 'item', 'prettytable', path) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 320 | return output |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Delete existing OpenStack Heat stack |
| 325 | * |
| 326 | * @param env Connection parameters for OpenStack API endpoint |
| 327 | * @param name Name of the managed Heat stack instance |
| 328 | * @param path Optional path to the custom virtualenv |
| 329 | */ |
| 330 | def deleteHeatStack(env, name, path = null) { |
| 331 | cmd = "heat stack-delete ${name}" |
| 332 | outputTable = runOpenstackCommand(cmd, env, path) |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Return list of servers from OpenStack Heat stack |
| 337 | * |
| 338 | * @param env Connection parameters for OpenStack API endpoint |
| 339 | * @param name Name of the managed Heat stack instance |
| 340 | * @param path Optional path to the custom virtualenv |
| 341 | */ |
| 342 | def getHeatStackServers(env, name, path = null) { |
| 343 | resources = heatGetStackResources(env, name, path) |
| 344 | servers = [] |
| 345 | for (resource in resources) { |
| 346 | if (resource.resource_type == 'OS::Nova::Server') { |
| 347 | resourceName = resource.resource_name |
| 348 | server = heatGetStackResourceInfo(env, name, resourceName, path) |
| 349 | servers.add(server.attributes.name) |
| 350 | } |
| 351 | } |
| 352 | echo("[Stack ${name}] Servers: ${servers}") |
| 353 | return servers |
| 354 | } |