3
# inc/common - helper bash functions, because Python is too good
4
# Copyright (C) 2014 Canonical Ltd.
6
# Authors: Marco Ceppi <marco.ceppi@canonical.com>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, version 3 of the License.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
_SETTINGS_FILE="${MICRO_CLUSTER_CFG:-~/.config/micro-cluster/settings.cfg}"
33
# $1 inet preface (eg: eth)
34
# $2 max range (eg: 5)
41
for i in `seq 0 $max`; do
42
if ifconfig ${tpl}${i} > /dev/null 2>&1; then
52
# $1 configuration key
53
if [ ! -f "$_SETTINGS_FILE" ]; then
57
if ! config_key_exists "$1"; then
61
local kv=$(egrep "^$1: .*" $_SETTINGS_FILE)
62
local v=$(echo "$kv" | sed -e 's/^.*: //')
67
# $1 configuration key
68
if [ ! -f "$_SETTINGS_FILE" ]; then
72
if ! egrep "^$1: .*$" $_SETTINGS_FILE > /dev/null; then
80
# $1 configuration key
82
if [ ! -f "$_SETTINGS_FILE" ]; then
83
mkdir -p $(dirname $_SETTINGS_FILE)
86
if config_key_exists "$1"; then
87
sed -i "s/^$1: .*$/$1: $2/" $_SETTINGS_FILE
89
echo "$1: $2" >> $_SETTINGS_FILE
94
if [ ! -f ~/.maascli.db ]; then
98
if [ "$(maas list)" == "" ]; then
104
echo "$(maas apikey --username=admin)"
108
if [ -f /etc/hp-proliant.conf ]; then
109
PREFIX=$(awk -F '[:]' NR==1'{print $3"."$4}' /etc/hp-proliant.conf)
114
if maas_logged_in; then
118
local user="${1:-admin}"
119
local auth=`oauth_key "$user"`
120
if [ "$auth" == "" ]; then
121
echo "Unable to find user creds, does user exist?"
125
maas $user login http://${PREFIX}.4.1/MAAS "$auth"
126
chown ubuntu: ~/.maascli.db
129
wake_me_up_before_you_go_go() {
130
for i in $(seq 1 30); do
131
if amttool $1 info 2>/dev/null | grep -qs "Powerstate:" 2>/dev/null; then