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