[eqv2] Check metro capacity again after its successfull selection
PRODX-24674
Change-Id: I2107aaf24b264c3476e5ce04765a4ebc1561d935
diff --git a/src/com/mirantis/mk/KaasUtils.groovy b/src/com/mirantis/mk/KaasUtils.groovy
index bc264d5..9079289 100644
--- a/src/com/mirantis/mk/KaasUtils.groovy
+++ b/src/com/mirantis/mk/KaasUtils.groovy
@@ -1110,29 +1110,36 @@
* @return ([]string) List of selected metros
*
**/
-def getEquinixMetrosWithCapacity(nodeCount = 10, nodeType = 'c3.small.x86', version = '0.9.0') {
+def getEquinixMetrosWithCapacity(nodeCount = 50, nodeType = 'c3.small.x86', version = '0.9.0') {
def common = new com.mirantis.mk.Common()
def metalUrl = "https://artifactory.mcp.mirantis.net:443/artifactory/binary-dev-kaas-local/core/bin/mirror/metal-${version}-linux"
def metros = []
def out = ''
- def retries = 10 // number of retries
+ def retries = 3 // number of retries
def i = 0
def delay = 60 // 1 minute sleep
+ def metal = './metal --config metal.yaml'
try {
sh "curl -o metal -# ${metalUrl} && chmod +x metal"
withCredentials([string(credentialsId: env.KAAS_EQUINIX_API_TOKEN, variable: 'KAAS_EQUINIX_API_TOKEN')]) {
sh 'echo "project-id: ${KAAS_EQUINIX_PROJECT_ID}\ntoken: ${KAAS_EQUINIX_API_TOKEN}" >metal.yaml'
}
- common.infoMsg("Selecting available Equinix metro with free ${nodeCount} ${nodeType} hosts")
while (metros.size() == 0 && i < retries) {
- common.infoMsg("Try ${i+1}/${retries} ...")
+ common.infoMsg("Selecting available Equinix metro with free ${nodeCount} ${nodeType} hosts, try ${i+1}/${retries} ...")
if (i > 0 ) { // skip sleep on first step
sleep(delay)
}
- out = sh(script: "./metal --config metal.yaml capacity get -m -P ${nodeType}|awk '/${nodeType}/ {print \$2}'|paste -s -d,|xargs ./metal --config metal.yaml capacity check -P ${nodeType} -q ${nodeCount} -m|grep true|awk '{print \$2}'|paste -s -d,", returnStdout: true).trim()
+ out = sh(script: "${metal} capacity get -m -P ${nodeType}|awk '/${nodeType}/ {print \$2}'|paste -s -d,|xargs ${metal} capacity check -P ${nodeType} -q ${nodeCount} -m|grep true|awk '{print \$2}'|paste -s -d,", returnStdout: true).trim()
metros = out.tokenize(',')
+ if (metros.size() == 0) {
+ nodeCount -= 10
+ }
i++
}
+ if (metros.size() > 0) {
+ m = metros.size() > 1 ? "${metros[0]},${metros[1]}" : "${metros[0]}"
+ sh "${metal} capacity check -P ${nodeType} -m ${m} -q ${nodeCount}"
+ }
} catch (Exception e) {
common.errorMsg "Exception: '${e}'"
return []