4
echo "${0##*/} public_ip_address dns_ip [cloud-city] [maas-repo]
5
public_ip_address: Public IP of the host system.
6
dns_ip: DNS to which non-maas queries should be forwarded.
7
cloud-city: Path to cloud-city.
13
[[ $# < "2" ]] && help
17
[[ $# > "2" ]] && help
18
LOCAL_CLOUD_CITY="${1:-./cloud-city}"
19
MAAS_REPO="${2:-default}"
20
KEY="staging-juju-rsa"
21
PUB_KEY_VALUE=$(cat ${LOCAL_CLOUD_CITY}/${KEY}.pub)
22
WIN_CERT_KEY=$(cat ${LOCAL_CLOUD_CITY}/winrm_client_cert.pem)
23
MAAS_ADDRESS="http://${PUBLIC_ADDRESS}/MAAS"
24
MAAS_API_ADDRESS="${MAAS_ADDRESS}/api/1.0"
25
MAAS_HOME="/var/lib/maas"
27
# Install required packages
28
ssh -i $LOCAL_CLOUD_CITY/$KEY jenkins@$PUBLIC_ADDRESS <<EOT
29
[[ -d \$HOME/juju-ci-tools/maas ]] || { echo "\$HOME/juju-ci-tools/maas is required."; exit 1; }
32
sudo apt-get install -y libvirt-bin
33
sudo apt-get install -y cloud-utils
34
sudo apt-get install -y qemu-kvm
35
sudo apt-get install -y virt-manager
36
sudo usermod -G libvirtd jenkins
39
ssh -i $LOCAL_CLOUD_CITY/$KEY jenkins@$PUBLIC_ADDRESS <<EOT
40
[[ -d \$HOME/juju-ci-tools/maas ]] || { echo "\$HOME/juju-ci-tools/maas is required."; exit 1; }
41
# Setup libvirt network and pools
42
virsh net-define \$HOME/juju-ci-tools/maas/maasnet2.xml
43
virsh net-start maasnet2
44
virsh net-autostart maasnet2
46
virsh net-define \$HOME/juju-ci-tools/maas/maasprv1.xml
47
virsh net-start maasprv1
48
virsh net-autostart maasprv1
50
sudo mkdir -p /images/maaspool1
51
virsh pool-define \$HOME/juju-ci-tools/maas/maaspool1.xml
52
virsh pool-start maaspool1
53
virsh pool-autostart maaspool1
56
[[ $MAAS_REPO == "next" ]] && sudo add-apt-repository ppa:maas/next
58
sudo apt-get install -y maas
60
# Configure the maas user to access virsh for KVM machine power management
61
sudo chsh -s /bin/bash maas
62
sudo mkdir -p ${MAAS_HOME}/.ssh
63
sudo cp -L \${HOME}/.ssh/id_rsa* ${MAAS_HOME}/.ssh
64
sudo chmod 400 ${MAAS_HOME}/.ssh/rsa_id
65
sudo chown -R maas:maas ${MAAS_HOME}/.ssh
66
sudo chmod 700 ${MAAS_HOME}/.ssh
69
sudo maas-region-admin createsuperuser --noinput --username root --email ubuntu@localhost
70
APIKEY=\$(sudo maas-region-admin apikey --username=root)
71
maas login vmaas $MAAS_API_ADDRESS \$APIKEY
72
maas vmaas sshkeys new key="$PUB_KEY_VALUE"
73
maas vmaas sslkeys new key="$WIN_CERT_KEY"
76
# Select and import images
77
maas vmaas boot-source update 1 url="http://maas.ubuntu.com/images/ephemeral-v2/daily/"
79
# FIXME: Different version of MAAS behave differently when selecting images
80
# and setting network interfaces. Punt for now and print a message with
81
# the network values that should be manually set.
82
#maas vmaas boot-source-selections create 1 release="precise" arches="amd64" subarches="*" labels="*" os="ubuntu"
83
#maas vmaas boot-source-selections create 1 release="trusty" arches="amd64" subarches="*" labels="*" os="ubuntu"
84
#maas vmaas boot-source-selections create 1 release="wily" arches="amd64" subarches="*" labels="*" os="ubuntu"
85
#maas vmaas boot-source-selections create 1 release="xenial" arches="amd64" subarches="*" labels="*" os="ubuntu"
86
#maas vmaas boot-source-selections create 1 release="centos70" arches="amd64" subarches="*" labels="*" os="centos"
87
#maas vmaas boot-resources import
89
## Setup MAAS to manage nodes on the internal 10.0.200 network
90
maas vmaas maas set-config name=upstream_dns value=$DNS_ADDRESS
91
#NODE_GROUP_ID=\$(maas vmaas node-groups list | grep -e '"uuid":' | awk '{print \$2}' | tr -d \\")
92
#echo "NODE_GROUP_ID=\$NODE_GROUP_ID"
93
#cmd="maas vmaas node-group-interface update \"\$NODE_GROUP_ID\" maasnetbr2 ip_range_high=10.0.200.199 ip_range_low=10.0.200.150 static_ip_range_high=10.0.200.249 static_ip_range_low=10.0.200.200 broadcast_ip=10.0.200.255 router_ip=10.0.200.1 management=2 subnet_mask=255.255.255.0"
94
#cmd="maas vmaas node-group-interfaces new \$NODE_GROUP_ID name=maasnetbr2 interface=maasnetbr2 ip=10.0.200.1 ip_range_high=10.0.200.199 ip_range_low=10.0.200.150 static_ip_range_high=10.0.200.249 static_ip_range_low=10.0.200.200 broadcast_ip=10.0.200.255 router_ip=10.0.200.1 management=2 subnet_mask=255.255.255.0"
98
[[ -n \$(df -h | grep -e /images\$) ]] || echo 'WARNING: /images is not a mounted filesystem, virtual machine images could fill up the root filesystem.'
101
# Configure Jenkins with launch command
102
echo "Set the MAAS root password with \"sudo maas-region-admin changepassword root\" from the jenkins account on $PUBLIC_ADDRESS."
103
echo "Log into $MAAS_ADDRESS"
104
echo "Add and/or configure network settings for maasnetbr2 to:
106
Interface: maasnetbr2
107
Management: DHCP and DNS
109
Subnet Mask: 255.255.255.0
110
Broadcast IP: 10.0.200.255
111
Router IP: 10.0.200.1
112
DHCP dynamic IP range low value: 10.0.200.150
113
DHCP dynamic IP range high value: 10.0.200.199
114
Static IP range low value: 10.0.200.200
115
Static IP range high value: 10.0.200.249