From 39f93f4a609ec53be5b0fd034ae22200d5640778 Mon Sep 17 00:00:00 2001 From: Rui Loura Date: Thu, 7 Feb 2019 16:33:03 +0000 Subject: [PATCH] TRITON-849 imgapi setup scripts should be rack aware --- bin/imgapi-manta-setup | 26 ++++++++++++-------------- bin/imgapi-standalone-create | 19 +++---------------- package.json | 3 ++- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/bin/imgapi-manta-setup b/bin/imgapi-manta-setup index 0166483c..61c5658c 100755 --- a/bin/imgapi-manta-setup +++ b/bin/imgapi-manta-setup @@ -55,6 +55,7 @@ var async = require('async'); var sdcClients = require('sdc-clients'); var UFDS = require('ufds'); var bunyan = require('bunyan'); +var netconfig = require('triton-netconfig'); //---- globals @@ -163,24 +164,21 @@ function getMantaUrl(mantaUrl, sdcApp, callback) { state: 'running' }; vmapi.listVms(search, function (vErr, vms) { - if (vErr) - return callback(vErr); - if (vms.length === 0) { - return callback(new Error( - 'no manta "loadbalancer" VMs were found')); + if (vErr) { + callback(vErr); + return; } - var nics = vms[0].nics; - var ip; - for (var i = 0; i < nics.length; i++) { - if (nics[i].nic_tag === 'external') { - ip = nics[i].ip; - break; - } + if (vms.length === 0) { + callback(new Error('no manta "loadbalancer" VMs were found')); + return; } + + var ip = netconfig.externalIpFromVmMetadata(vms[0]); if (!ip) { - return callback(new Error( - 'no external IP on the first Manta LB')); + callback(new Error('no external IP on the first Manta LB')); + return; } + mantaUrl = 'https://' + ip; callback(null, mantaUrl); }); diff --git a/bin/imgapi-standalone-create b/bin/imgapi-standalone-create index 0021ef70..1ca9ded7 100755 --- a/bin/imgapi-standalone-create +++ b/bin/imgapi-standalone-create @@ -4,7 +4,7 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # -# Copyright 2017 Joyent, Inc. +# Copyright 2019 Joyent, Inc. # # @@ -161,19 +161,6 @@ else echo "Owner ($ownerUuid) is already on the image ACL" fi -# Network -echo "Find a suitable external network" -networkPoolJson=$(sdc-napi /network_pools?provisionable_by=$ownerUuid | json -Hc 'this.nic_tag==="external"' 0) -if [[ -z "$networkPoolJson" ]]; then - networkJson=$(sdc-napi /networks?provisionable_by=$ownerUuid\&fabric=false | json -Hc 'this.nic_tag==="external"' 0) - [[ -n "$networkJson" ]] || fatal "could not find a suitable network" - netJson="$networkJson" -else - netJson="$networkPoolJson" -fi -netUuid=$(echo "$netJson" | json uuid) -netName=$(echo "$netJson" | json name) - # Create the VM vmUuid=$(uuid) optMetadata=$(echo "$optMetadata" \ @@ -185,7 +172,7 @@ echo " alias: $ALIAS" echo " owner: $ownerUuid ($ownerLogin)" echo " image: $imageUuid ($imageName@$imageVersion)" echo " package: $packageUuid ($packageName)" -echo " network: $netUuid ($netName)" +echo " network: external" echo " tags: $(echo "$optTags" | json -o json-0)" echo " metadata:" echo "$optMetadata" | sed 's/^/ /' @@ -196,7 +183,7 @@ sdc-vmapi /vms -X POST -d@- <