-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy
executable file
·112 lines (92 loc) · 4.29 KB
/
deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash -e
TMPDIR="$(mktemp -d /tmp/aoi-maas.XXXXXXXXXX)"
VERBOSE=0
if [ "$1" == "--verbose" -o "$1" == "-v" ]; then
let VERBOSE=$VERBOSE+1
echo "Log directory: $TMPDIR"
shift
fi
function cleanup {
if [ $VERBOSE -eq 0 ]; then
rm -rf "$TMPDIR"
else
echo ""
echo "Logging is available in: $TMPDIR"
fi
}
trap cleanup EXIT
SCRIPT_NUM=0
function run {
LOG_FILE=$(printf "$TMPDIR/%03d-deploy.log")
local pretty_log="$(echo "[$(date '+%H:%M:%S')] $1...")"
shift
echo "$pretty_log"
echo "$pretty_log" >> $LOG_FILE
echo "$pretty_log" >> $LOG_FILE.err
echo "$@" >> $LOG_FILE
echo "$@" >> $LOG_FILE.err
"$@" >> $LOG_FILE 2>> $LOG_FILE.err || \
(echo ""; cat $LOG_FILE ; cat $LOG_FILE.err ; printf "\nCommand failed: \n $@\n" && exit 1)
let SCRIPT_NUM=$SCRIPT_NUM+1
}
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
aoi config delete maas_api_key || true
source $SCRIPT_DIR/config.sh
export VIRT_CPUS=$MAAS_SERVER_CPUS
export VIRT_RAM=$MAAS_SERVER_RAM
run "Creating virtual machine" aoi launch "$DISTRO" "$INSTANCE"
unset VIRT_CPUS
unset VIRT_RAM
if [ "$MAAS_REPO" != "" ]; then
run "Adding MAAS repo: $MAAS_REPO" aoi-ssh $INSTANCE "echo \"deb $MAAS_REPO $DISTRO main\" | sudo tee -a /etc/apt/sources.list"
run "Adding MAAS repo key: $MAAS_REPO_KEY" aoi-ssh $INSTANCE "curl $MAAS_REPO_KEY | sudo apt-key add -"
elif [ "$PPA" != "" ]; then
run "Adding MAAS PPA: $PPA" aoi-ssh $INSTANCE sudo apt-add-repository -y $PPA
fi
run "Updating apt sources" aoi-ssh $INSTANCE sudo apt-get update
echo "MAAS version:"
aoi-ssh $INSTANCE apt-cache policy maas
run "Upgrading packages" aoi-ssh $INSTANCE sudo apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuy dist-upgrade
run "Installing bridge-utils" aoi-ssh $INSTANCE sudo apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuy install bridge-utils
# Enable SSH access for the root account.
# This allows us to easily redeploy MAAS components using a shortcut script.
run "Enabling root SSH access" aoi-ssh $INSTANCE sudo cp -r --no-preserve=ownership /home/ubuntu/.ssh /root
# Configure the test network with a static IP address.
TESTNET=$(aoi-ssh $INSTANCE ifconfig -a | grep $(aoi-get-mac testnet-$INSTANCE) | awk '{ print $1 }')
run "Adding private bridge interface" \
aoi-ssh root@$INSTANCE "cat >> /etc/network/interfaces.d/51-testnet.cfg <<EOF
auto $TESTNET
iface $TESTNET inet manual
auto br0
iface br0 inet static
bridge_ports $TESTNET
bridge_stp off
bridge_waitport 0
bridge_fd 0
address $TESTNET_IP
netmask $TESTNET_NETMASK
EOF"
run "Bringing up bridge interface" aoi-ssh root@$INSTANCE "ifup $TESTNET ; ifup br0"
# We'll need MAAS (obviously), and also jq to help parse MAAS API output.
# Also, libvirt-bin so that we can add the hypervisor as a chassis.
run "Installing MAAS" aoi-ssh $INSTANCE "sudo apt-get --force-yes -o Dpkg::Options::=\"--force-confold\" --force-yes -o Dpkg::Options::=\"--force-confdef\" -fuy install maas jq libvirt-bin"
# Update the maas_url in the rack config, because the nodes won't be able
# to contact MAAS on the management interface on virbr0; they can only
# access the test network.
run "Configuring MAAS region URL" aoi-ssh $INSTANCE sudo maas-rack config --region-url http://$TESTNET_IP:5240/MAAS
# run "Restarting MAAS rack service" aoi-ssh $INSTANCE sudo service maas-rackd restart
run "Restarting MAAS" $SCRIPT_DIR/restart-maas
run "Waiting for MAAS API to become available" $SCRIPT_DIR/wait-for-api
run "Configuring authentication" $SCRIPT_DIR/configure-auth
run "Configuring region" $SCRIPT_DIR/configure-region
# We sadly "reboot" the MAAS service here to work around the fact that MAAS
# may be automatically importing images from the default URL right now.
run "Restarting MAAS" $SCRIPT_DIR/restart-maas
run "Importing boot resources" $SCRIPT_DIR/import-boot-resources
run "Importing SSH keys" $SCRIPT_DIR/import-ssh-keys
run "Configuring MAAS networks for DHCP" $SCRIPT_DIR/configure-networking
echo "MAAS is available at: http://$(aoi-get-ip-via-arp maas)/MAAS/"
echo " Username: $MAAS_USER"
echo " Password: $MAAS_PASSWORD"
echo ""
echo "If you want to create some test hosts, try the 'init-chassis' script."