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