Merge lp:~cpe-sa/obinstall/profile into lp:obinstall/next

Proposed by Matt Jarvis
Status: Needs review
Proposed branch: lp:~cpe-sa/obinstall/profile
Merge into: lp:obinstall/next
Diff against target: 3422 lines (+1946/-1267) (has conflicts)
37 files modified
00-network.sh (+0/-187)
01-packages.sh (+0/-165)
02-apache_setup.sh (+0/-45)
03-maas_setup_environment.sh (+0/-100)
04-add_virtual_nodes.sh (+0/-135)
04a-mod_virtual_nodes.sh (+0/-57)
05-add_physical_nodes.sh (+0/-88)
05a-mod_physical_nodes.sh (+0/-74)
06-juju_environment.sh (+0/-130)
LP_USERS.list (+7/-9)
PACKAGES.list (+2/-1)
VARS (+0/-1)
amt_vnc_config.sh (+0/-109)
archive.conf (+0/-13)
bin/change-juju-password.exp (+0/-28)
bin/verify.sh (+0/-78)
fabric.sh (+0/-16)
import_SA_keys.sh (+0/-19)
scripts/04a-mod_virtual_nodes.sh (+57/-0)
scripts/05a-mod_physical_nodes.sh (+74/-0)
scripts/add_physical_nodes.sh (+147/-0)
scripts/add_virtual_nodes.sh (+212/-0)
scripts/amt_vnc_config.sh (+109/-0)
scripts/change-juju-password.exp (+28/-0)
scripts/fabric.sh (+16/-0)
scripts/install_base_system.sh (+167/-0)
scripts/ob_profile.sh (+80/-0)
scripts/obinstaller.sh (+67/-0)
scripts/setup_apache.sh (+52/-0)
scripts/setup_base_system.sh (+181/-0)
scripts/setup_juju_environment.sh (+179/-0)
scripts/setup_maas_environment.sh (+226/-0)
scripts/setup_network.sh (+239/-0)
scripts/verify.sh (+78/-0)
template/archive.conf (+13/-0)
template/ubuntu-cloud.conf (+12/-0)
ubuntu-cloud.conf (+0/-12)
Text conflict in LP_USERS.list
To merge this branch: bzr merge lp:~cpe-sa/obinstall/profile
Reviewer Review Type Date Requested Status
Michael Iatrou Approve
Josh McJilton Pending
Review via email: mp+323171@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Nobuto Murata (nobuto) :
Revision history for this message
Michael Iatrou (michael.iatrou) wrote :

Tested during ODS.

review: Approve

Unmerged revisions

20. By Matt Jarvis <email address hidden>

Refactor - add profile, functions, update LP_USERS, add installer script

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file '00-network.sh'
2--- 00-network.sh 2016-09-20 09:23:07 +0000
3+++ 00-network.sh 1970-01-01 00:00:00 +0000
4@@ -1,187 +0,0 @@
5-#!/bin/bash
6-#
7-# Setup of OrangeBox network
8-# Copyright (C) 2014 Canonical Ltd.
9-#
10-# Authors: Dustin Kirkland <kirkland@canonical.com>
11-# Scott Croft <scott@canonical.com>
12-#
13-# This program is free software: you can redistribute it and/or modify
14-# it under the terms of the GNU General Public License as published by
15-# the Free Software Foundation, version 3 of the License.
16-#
17-# This program is distributed in the hope that it will be useful,
18-# but WITHOUT ANY WARRANTY; without even the implied warranty of
19-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20-# GNU General Public License for more details.
21-#
22-# You should have received a copy of the GNU General Public License
23-# along with this program. If not, see <http://www.gnu.org/licenses/>.
24-#
25-#
26-set -e
27-set -x
28-
29-# If user is not root then exit
30-#
31-if [ "$(id -u)" != "0" ]; then
32- echo "Must be run with sudo or by root"
33- exit 77
34-fi
35-
36-#Get Orangebox number from the hostname and place into the configuration file
37-obnum=`hostname | cut -c 10- -`
38-echo "orangebox_number=${obnum}" > /etc/orange-box.conf
39-
40-# Install bridge-utils first
41-apt-get update
42-apt-get install -y bridge-utils
43-
44-# Get interface names of the 3 interfaces on node0 since in Xenial they aren't ethX anymore
45-# An array is declared and the interface names are placed into the array to be used later on
46-#
47-declare interface=()
48-
49-for inter_face in $(ip a | awk '{print $2}'|egrep 'enp|enx'|sed 's/://')
50-do
51- echo "Interface read $inter_face"
52- interface=("${interface[@]}" "$inter_face")
53-done
54-echo "Interfaces assigned "${interface[@]}""
55-
56-# Check to make sure the OrangeBox is divisable by 4 to ensure the network is setup correctly
57-#
58-check_orangebox_number() {
59- local num=$1
60- if [[ $((num/4)) -lt 1 ]]; then
61- echo "Your hostname should in the format of OrangeBox??: ex OrangeBox56"
62- exit 1;
63- fi
64-}
65-
66-#Add kernel parameters for networking with MAAS to function correctly
67-#
68-echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
69-echo "net.ipv4.conf.all.accept_redirects = 1" >> /etc/sysctl.conf
70-
71-# Assign variables with the values for the network setup and execute the check_orangebox_number
72-#
73-. /etc/orange-box.conf
74-
75-check_orangebox_number ${obnum}
76-internal1_ip="172.27.$((orangebox_number)).1"
77-gateway1_ip=172.27.$((orangebox_number+1)).254
78-internal2_ip=172.27.$((orangebox_number+2)).1
79-gateway2_ip=172.27.$((orangebox_number+3)).254
80-gateway_ip=$gateway1_ip
81-
82-# Set up the nic variables
83-internal0_if="${interface[0]}"
84-internal1_if="${interface[1]}"
85-internal2_if="${interface[2]}"
86-
87-# check with i/f is on which bridge-vlan
88-ifconfig ${internal1_if} ${internal1_ip}/23
89-ping -c 1 ${gateway1_ip}
90-if [[ $(echo $?) -eq 0 ]]
91-then
92- ip addr flush dev ${internal1_if}
93- internal1_if="${interface[1]}"
94- internal2_if="${interface[2]}"
95-else
96- ip addr flush dev ${internal1_if}
97- internal1_if="${interface[2]}"
98- internal2_if="${interface[1]}"
99-fi
100-
101-# Setup the network interfaces for Node0 and populate the /etc/network/networking file with the correct
102-# information
103-#
104-setup_networking() {
105- # Disable NetworkManager
106- systemctl stop NetworkManager
107- systemctl disable NetworkManager
108-
109- # gen network configuration /etc/network/interfaces
110- cat >/etc/network/interfaces <<-EOF
111- #These are generated by orange-box build scripts
112- auto lo
113- iface lo inet loopback
114-
115- auto $internal0_if
116- iface $internal0_if inet manual
117-
118- auto $internal1_if
119- iface $internal1_if inet manual
120-
121- auto $internal2_if
122- iface $internal2_if inet manual
123-
124- auto br0
125- iface br0 inet static
126- address ${internal1_ip}
127- netmask 255.255.254.0
128- gateway ${gateway_ip}
129- dns-nameservers ${internal1_ip} ${gateway_ip}
130- bridge_ports $internal1_if
131- bridge_stp off
132- bridge_fd 0
133- bridge_maxwait 0
134-
135- auto br1
136- iface br1 inet static
137- address ${internal2_ip}
138- netmask 255.255.254.0
139- bridge_ports $internal2_if
140- bridge_stp off
141- bridge_fd 0
142- bridge_maxwait 0
143-EOF
144-
145- # Take down all of the interfaces
146- ifdown --force $internal0_if || true
147- ifdown --force $internal1_if || true
148- ifdown --force $internal2_if || true
149-
150- # Take down br interfaces
151- ifdown --force br0 || true
152- ifdown --force br1 || true
153-
154- # Bring up br0, br1
155- ifup $internal1_if --force
156- ifup $internal2_if --force
157- ifup br0 --force
158- ifup br1 --force
159-
160- # Wait a moment for the network to normalize
161- echo "INFO: Ensure networking has settled"
162- if ping -c 3 8.8.8.8
163- then
164- echo ""
165- echo "Networking is fine"
166- echo ""
167- else
168- echo ""
169- echo "You're having network issues, fix them"
170- echo ""
171- exit 1
172- fi
173-
174- # Confirm DNS working
175- echo "INFO: Ensure DNS working"
176- if ping -c 3 google.com
177- then
178- echo ""
179- echo "DNS is fine"
180- echo ""
181- else
182- echo ""
183- echo "DNS is having issues, check /etc/resolv.conf and ifdown/ifup br0/br1 interfaces if need be"
184- echo ""
185- exit 2
186- fi
187-}
188-
189-setup_networking
190-
191-exit 0
192
193=== removed file '01-packages.sh'
194--- 01-packages.sh 2016-06-13 13:52:57 +0000
195+++ 01-packages.sh 1970-01-01 00:00:00 +0000
196@@ -1,165 +0,0 @@
197-#!/bin/bash
198-#
199-# Installation of all the required packages to configure the OrangeBox
200-# Copyright (C) 2016 Canonical Ltd.
201-#
202-# Authors: Scott Croft <scott@canonical.com>
203-#
204-# This program is free software: you can redistribute it and/or modify
205-# it under the terms of the GNU General Public License as published by
206-# the Free Software Foundation, version 3 of the License.
207-#
208-# This program is distributed in the hope that it will be useful,
209-# but WITHOUT ANY WARRANTY; without even the implied warranty of
210-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
211-# GNU General Public License for more details.
212-#
213-# You should have received a copy of the GNU General Public License
214-# along with this program. If not, see <http://www.gnu.org/licenses/>.
215-#
216-#
217-set -e
218-set -x
219-
220-
221-# If user is not root then exit
222-if [ "$(id -u)" != "0" ]; then
223- echo "Must be run with sudo or by root"
224- exit 77
225-fi
226-
227-# Check to ensure that the user on the system is ubuntu and assigned the uid of 1000
228-#
229-if [ "$(id -u ubuntu)" != "1000" ]; then
230- echo "ERROR: Read the docs; a proper OrangeBox setup requires the default user to be [ubuntu]" 1>&2
231- exit 1
232-fi
233-
234-# The usage script will deliver a message on what should be executed to install the correct software
235-#
236-
237-usage()
238-{
239-cat << EOF
240-usage: $0 options
241-
242-This script to select desired repository and install packages
243-
244-OPTIONS:
245- -h Show this message
246- -p Manually enter in ppa's name (as in ppa:/juju/stable)
247-EOF
248-}
249-
250-get_orangebox_number() {
251-obnum=`hostname | cut -c 10- -`
252-echo $obnum
253-echo "orangebox_number=$obnum" > /etc/orange-box.conf
254-}
255-
256-# Setup the ssh keys for the Ubuntu user on the OrangeBox
257-#
258-setup_ssh_keys() {
259- # Disable remote password authentication, since our username/password
260- # combo is very well known
261- if ! grep -qs "^PasswordAuthentication no" /etc/ssh/sshd_config 2>/dev/null; then
262- echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
263- invoke-rc.d ssh stop || true
264- invoke-rc.d ssh start
265- fi
266- if [ ! -e /home/ubuntu/.ssh/id_rsa ]; then
267- su -l ubuntu -c "ssh-keygen -N '' -f /home/ubuntu/.ssh/id_rsa"
268- fi
269-
270- install -o ubuntu -g ubuntu -m 0600 template/ssh_config ~ubuntu/.ssh/config
271-}
272-
273-# Install the extra packages needed for the desktop and configuration of the OrangeBox
274-#
275-install_packages (){
276- packages=
277- while read package; do
278- package=${package%%#*}
279- packages="$packages $package"
280- done < PACKAGES.list
281- apt install -y $packages
282-}
283-
284-# Setup the ppa's for what respositories will be used to install the correct packages with respect to MAAS and Juju
285-#
286-set_up_ppas(){
287-if [ "$1" = "default" ];then
288- printf "Adding Stable ppa's"
289- printf "\n"
290- add-apt-repository -y ppa:juju/stable
291- add-apt-repository -y ppa:maas/stable
292-fi
293-if [ "$1" = "jujuexp" ];then
294- printf "Adding juju experimental ppa"
295- printf "\n"
296- add-apt-repository -y ppa:juju/proposed
297-fi
298-if [ "$1" = "maasexp" ];then
299- printf "Adding maas experimental ppa"
300- printf "\n"
301- add-apt-repository -y ppa:maas/proposed
302-fi
303-if [ "$1" = "ppaset" ];then
304- printf "Build system with custom PPAS"
305- printf "\n"
306- printf "Enter ppa for juju (i.e. ppa:juju/stable):"
307- read JUJUPPA
308- printf "Enter ppa for maas (i.e. ppa:maas-maintainers/stable):"
309- read MAASPPA
310- add-apt-repository -y $JUJUPPA
311- add-apt-repository -y $MAASPPA
312-fi
313-
314-# Replace whatever locale was used with nothing so the system just goes to
315-# archive.ubuntu.com
316-#
317-
318-sed -i.orig 's|http://.*archive|http://archive|g' /etc/apt/sources.list
319-
320-# Update the system sources and packages, then install new packages required for
321-# the OrangeBox
322-#
323-
324-apt-get update -y
325-apt-get dist-upgrade -y
326-apt-get install run-one -y
327-install_packages
328-setup_ssh_keys
329-sleep 5
330-reboot
331-}
332-
333-if (($# == 0)); then
334- set_up_ppas default
335-fi
336-
337-# Section to decide which options to use
338-#
339-while getopts “hp” OPTION
340-do
341- case $OPTION in
342- h)
343- usage
344- exit 1
345- ;;
346- p)
347- set_up_ppas ppaset
348- ;;
349- v)
350- VERBOSE=1
351- ;;
352- ?)
353- usage
354- exit
355- ;;
356- \?)
357- echo "Invalid option: -$OPTARG" >&2
358- ;;
359- esac
360-done
361-
362
363=== removed file '02-apache_setup.sh'
364--- 02-apache_setup.sh 2016-06-02 16:26:55 +0000
365+++ 02-apache_setup.sh 1970-01-01 00:00:00 +0000
366@@ -1,45 +0,0 @@
367-#/bin/bash
368-#
369-# Setup of OrangeBox network
370-# Copyright (C) 2014 Canonical Ltd.
371-#
372-# Authors: Scott Croft <scott@canonical.com>
373-#
374-# This program is free software: you can redistribute it and/or modify
375-# it under the terms of the GNU General Public License as published by
376-# the Free Software Foundation, version 3 of the License.
377-#
378-# This program is distributed in the hope that it will be useful,
379-# but WITHOUT ANY WARRANTY; without even the implied warranty of
380-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
381-# GNU General Public License for more details.
382-#
383-# You should have received a copy of the GNU General Public License
384-# along with this program. If not, see <http://www.gnu.org/licenses/>.
385-#
386-#
387-
388-# script to configure apache
389-#
390-set -e
391-set -x
392-
393-
394-# If user is not root then exit
395-#
396-if [ "$(id -u)" != "0" ]; then
397- echo "Must be run with sudo or by root"
398- exit 77
399-fi
400-
401-# This sets up Apache so that when going to the OB IP address of Node0, the user is automatically put
402-# into the MAAS login/interface and they don't have to place /MAAS at the end of the system-name or IP address
403-#
404-setup_apache() {
405- mkdir -p /srv/mirrors/archive.ubuntu.com
406- echo '<meta http-equiv="refresh" content="0; url=MAAS/">' > /srv/mirrors/archive.ubuntu.com/index.html
407- invoke-rc.d apache2 stop || true
408- invoke-rc.d apache2 start
409-}
410-
411-setup_apache
412
413=== removed file '03-maas_setup_environment.sh'
414--- 03-maas_setup_environment.sh 2016-09-20 09:23:07 +0000
415+++ 03-maas_setup_environment.sh 1970-01-01 00:00:00 +0000
416@@ -1,100 +0,0 @@
417-#!/bin/bash
418-#
419-# Setup of OrangeBox MAAS environment
420-# Copyright (C) 2016 Canonical Ltd.
421-#
422-# Authors: Scott Croft <scott@canonical.com>
423-#
424-# This program is free software: you can redistribute it and/or modify
425-# it under the terms of the GNU General Public License as published by
426-# the Free Software Foundation, version 3 of the License.
427-#
428-# This program is distributed in the hope that it will be useful,
429-# but WITHOUT ANY WARRANTY; without even the implied warranty of
430-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
431-# GNU General Public License for more details.
432-#
433-# You should have received a copy of the GNU General Public License
434-# along with this program. If not, see <http://www.gnu.org/licenses/>.
435-#
436-#
437-
438-set -ax
439-# If user is not root then exit
440-if [ "$(id -u)" != "0" ]; then
441- echo "Must be run with sudo or by root"
442- exit 77
443-fi
444-
445-#Get ob number
446-ob_number=`hostname | cut -c 10- -`
447-
448-# Set the MAAS URL and CLUSTER_UUID for the admin login setup
449-MAAS_URL=http://172.27.${ob_number}.1/MAAS
450-CLUSTER_UUID=`grep cluster_uuid /etc/maas/rackd.conf |awk '{print $2}'`
451-
452-#AMT Password set
453-AMT_PASSWORD=Password1+
454-
455-#Set ip's for MAAS configuration
456-router_ip=172.27.`expr ${ob_number} + 1`.254
457-dhcp_low=172.27.`expr ${ob_number} + 1`.1
458-dhcp_high=172.27.`expr ${ob_number} + 1`.20
459-dns_ip=172.27.`expr ${ob_number} + 1`.254
460-sub_net="172.27.${ob_number}.0/23"
461-gateway_ip="172.27.${ob_number}.1"
462-dns_servers="172.27.${ob_number}.1"
463-
464-#Create the MAAS credentials
465-if [[ $(maas-region apikey --username admin 1>/dev/null 2>&1;echo $?) -eq 1 ]]
466-then
467- maas-region createadmin --username admin --email maas-admin@example.com --password="admin" || true
468-fi
469-
470-#get apikey variable
471-apikey=`maas-region apikey --username admin | tail -n1`
472-
473-#login to MAAS
474-maas login admin $MAAS_URL $apikey
475-
476-#Add ssh key to MAAS
477-maas admin sshkeys create key="$(cat /home/ubuntu/.ssh/id_rsa.pub)" || true
478-
479-#update VLAN info to switch on DHCP
480-maas admin ipranges create type=dynamic start_ip=${dhcp_low} end_ip=${dhcp_high}
481-maas admin subnets read|grep "\"id\""|awk '{print $2}'|sed 's/,//'|egrep -x '.{1,2}'|while read subnet_id
482-do
483- maas admin subnet read $subnet_id|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null
484- if [[ $? -eq 0 ]]
485- then
486- maas_fabric=$(maas admin subnet read ${subnet_id}|grep fabric|awk '{print $2}'|sed 's/,//'|sed 's/\"//g')
487- maas admin vlan update ${maas_fabric} untagged dhcp_on=True primary_rack="OrangeBox${ob_number}"
488- fi
489-done
490-maas admin subnet update ${sub_net} gateway_ip=${gateway_ip} dns_servers=${dns_servers}
491-
492-#update http conf
493-cat >/var/www/html/index.html <<EOF
494-<meta http-equiv="refresh" content="0; url=/MAAS">
495-EOF
496-
497-#update DNS info
498-maas admin maas set-config name=upstream_dns value=$dns_ip
499-maas admin maas set-config name=dnssec_validation value=no
500-maas admin maas set-config name=kernel_opts value="net.ifnames=0"
501-sed -e 's/dnssec-validation auto;/dnssec-enable no;dnssec-validation no;/g' -i /etc/bind/named.conf.options
502-pkill -HUP named
503-
504-#Import boot images
505-maas admin boot-source-selections create 1 os="ubuntu" release="xenial" arches="amd64" subarches="*" labels="*" || true
506-maas admin boot-source-selections create 1 os="ubuntu" release="trusty" arches="amd64" subarches="*" labels="*" || true
507-maas admin boot-resources import
508-while [ $(maas admin boot-resources read name=$CLUSTER_UUID | wc -l) -lt 10 ]; do
509-echo " Waiting for images to download"
510- sleep 10
511-done
512-sleep 5
513-
514-#Add zones to MAAS for NUC's
515-maas admin zone read zone1 || maas admin zones create name=zone1 description="Physical machines 1-5"
516-maas admin zone read zone2 || maas admin zones create name=zone2 description="Physical machines 6-10"
517
518=== removed file '04-add_virtual_nodes.sh'
519--- 04-add_virtual_nodes.sh 2016-09-20 09:23:07 +0000
520+++ 04-add_virtual_nodes.sh 1970-01-01 00:00:00 +0000
521@@ -1,135 +0,0 @@
522-#!/bin/bash
523-#
524-# orange-box-setup-kvms - create some virtual machines
525-# Copyright (C) 2014 Canonical Ltd.
526-#
527-# Authors: Ronald McCollam <ronald.mccollam@canonical.com>
528-# Dustin Kirkland <kirkland@canonical.com>
529-# Modified: Scott Croft <scott@canonical.com> 2016
530-#
531-# This program is free software: you can redistribute it and/or modify
532-# it under the terms of the GNU General Public License as published by
533-# the Free Software Foundation, version 3 of the License.
534-#
535-# This program is distributed in the hope that it will be useful,
536-# but WITHOUT ANY WARRANTY; without even the implied warranty of
537-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
538-# GNU General Public License for more details.
539-#
540-# You should have received a copy of the GNU General Public License
541-# along with this program. If not, see <http://www.gnu.org/licenses/>.
542-
543-trap 'echo Error at about $LINENO' ERR
544-
545-# Source file to get OB number variable
546-. /etc/orange-box.conf
547-
548-# Set network variables
549-external_ip="172.27.252.${orangebox_number}"
550-internal_ip="172.27.${orangebox_number}.1"
551-internal_network="172.27.${orangebox_number}.0"
552-
553-# If user is not root then exit
554-if [ "$(id -u)" != "0" ]; then
555- echo "Must be run with sudo or by root"
556- exit 77
557-fi
558-
559-set -e
560-set -aux
561-
562-virsh net-info default && virsh net-destroy default && virsh net-undefine default
563-
564-# If directory exist then change ownership
565-[ -d /var/lib/maas ] || install -d /var/lib/maas --owner maas --group maas
566-
567-# Create the /srv/obvms directory for storing the virtual machines files
568-[ -d /srv/obvms ] || mkdir /srv/obvms
569-chown libvirt-qemu:kvm /srv/obvms
570-touch /srv/obvms/junk.img
571-rm /srv/obvms/*.img
572-
573-# Change login shell to Bash for MAAS user
574-chsh maas -s /bin/bash
575-
576-# If directory exist then make directory and change ownership
577-[ -d /var/lib/maas/.ssh ] || mkdir /var/lib/maas/.ssh && chown maas:maas /var/lib/maas/.ssh
578-
579-# If file exist then echo 3 returns but do not output trailing newlines. Create SSH key for MAAS user with no passphrase of type RSA v2 at the specified location
580-[ -f /var/lib/maas/.ssh/id_rsa ] || echo -e "\n\n\n" | sudo -u maas ssh-keygen -N "" -t rsa -f /var/lib/maas/.ssh/id_rsa
581-
582-# If file exist then gather known host keys of MAAS user for OB and append to the end of specified file while discarding output
583-[ -f /var/lib/maas/.ssh/known_hosts ] || sudo -u maas ssh-keyscan 172.27.${orangebox_number}.1 |sudo -u maas tee -a /var/lib/maas/.ssh/known_hosts > /dev/null
584-
585-# Always add host keys .. not an issue if files grows
586-sudo -u maas ssh-keyscan 172.27.${orangebox_number}.1 |sudo -u maas tee -a /var/lib/maas/.ssh/known_hosts > /dev/null
587-
588-# if very first install ubuntu user might not have authorized keys set.
589-if [ ! -f /home/ubuntu/.ssh/authorized_keys ]; then
590- mkdir -p /home/ubuntu/.ssh/
591- cat /var/lib/maas/.ssh/id_rsa.pub | tee -a /home/ubuntu/.ssh/authorized_keys
592- chown -R ubuntu /home/ubuntu/.ssh/
593- chmod 700 /home/ubuntu/.ssh/
594-fi
595-
596-sudo -u maas virsh -c qemu+ssh://ubuntu@172.27.${orangebox_number}.1/system list > /dev/null || sed -i '/ maas@/d' /home/ubuntu/.ssh/authorized_keys
597-
598-# If there is no key /new install or just removed add it"
599-# echo -e "\n\n\n" | sudo -u maas ssh-keygen -N "" -t rsa -f /var/lib/maas/.ssh/id_rsa
600-grep 'maas@' /home/ubuntu/.ssh/authorized_keys || cat /var/lib/maas/.ssh/id_rsa.pub | tee -a /home/ubuntu/.ssh/authorized_keys
601-printf "%s,%s %s %s\n" "node0.maas" "$internal_ip" $(awk '{print $1 " " $2}' /etc/ssh/ssh_host_ecdsa_key.pub) | tee -a /var/lib/maas/.ssh/known_hosts
602-
603-#Change ownership of specified directory
604-chown -R ubuntu:ubuntu /home/ubuntu
605-
606-# Add virtual node tags in MAAS
607-maas admin tags create name=virtual || true
608-maas admin tags create name=bootstrap || true
609-maas admin tags create name=neutron || true
610-
611-# Mark all nodes to be fast path installed
612-# Support MAAS 1.5, and 1.6
613-maas_ver=$(dpkg -l maas | tail -n1 | awk '{print $3}')
614-if dpkg --compare-versions $maas_ver lt 1.6; then
615- maas admin tags create name='use-fastpath-installer' comment='fp' "definition=true()" || true
616-else
617- maas admin tags create name='use-fastpath-installer' comment='fp' || true
618-fi
619-
620-#Create zone0 for virtual nodes
621-maas admin zone read zone0 || maas admin zones create name=zone0 description="Virtual machines on node0"
622-
623-for i in {0..2}; do
624- hostname="node00vm${i}ob${orangebox_number}.maas"
625- virsh destroy $hostname || true
626- virsh undefine $hostname || true
627- echo "INFO: Installing virtual machine"
628- if [ $i = 0 ]; then
629- virt-install --debug --name $hostname --ram 6144 --disk=path=/srv/obvms/${hostname}-1.img,size=20 --disk=path=/srv/obvms/${hostname}-2.img,size=2 --vcpus=2 --os-type=linux --pxe --network=bridge=br0 --network=bridge=br0 --boot network --video=cirrus --graphics vnc|| true
630- else
631- virt-install --debug --name $hostname --ram 4096 --disk=path=/srv/obvms/${hostname}-1.img,size=20 --disk=path=/srv/obvms/${hostname}-2.img,size=2 --vcpus=2 --os-type=linux --pxe --network=bridge=br0 --network=bridge=br0 --boot network --video=cirrus --graphics vnc|| true
632- fi
633- virsh console $hostname || true
634- virsh autostart $hostname
635- mac=$(virsh dumpxml $hostname | python -c 'import sys, lxml.etree; print list(lxml.etree.parse(sys.stdin).iter("mac"))[0].get("address")')
636- system_id=$(maas admin nodes read mac_address=$mac | grep system_id | cut -d'"' -f4)
637-
638- if [ -n "$system_id" ]; then
639- maas admin machine update $system_id hostname=$hostname power_type=virsh power_parameters_power_address=qemu+ssh://ubuntu@${internal_ip}/system power_parameters_power_id=$hostname
640- maas admin tag update-nodes "virtual" add=$system_id
641- case $i in
642- 0)
643- maas admin tag update-nodes "bootstrap" add=$system_id
644- ;;
645- 1)
646- maas admin tag update-nodes "neutron" add=$system_id
647- ;;
648- esac
649- maas admin tag update-nodes use-fastpath-installer add=$system_id
650- maas admin machine commission $system_id || true
651- maas admin nodes set-zone zone=zone0 nodes=$system_id
652- else
653- echo "ERROR: Could not find virtual machine in MAAS" 1>&2
654- exit 1
655- fi
656-done
657
658=== removed file '04a-mod_virtual_nodes.sh'
659--- 04a-mod_virtual_nodes.sh 2016-09-20 09:23:07 +0000
660+++ 04a-mod_virtual_nodes.sh 1970-01-01 00:00:00 +0000
661@@ -1,57 +0,0 @@
662-#!/bin/bash
663-#
664-# Script to modify virtual OrangeBox nodes in MAAS
665-# Copyright (C) 2016 Canonical Ltd.
666-#
667-# Authors: Scott Croft <scott@canonical.com>
668-#
669-# This program is free software: you can redistribute it and/or modify
670-# it under the terms of the GNU General Public License as published by
671-# the Free Software Foundation, version 3 of the License.
672-#
673-# This program is distributed in the hope that it will be useful,
674-# but WITHOUT ANY WARRANTY; without even the implied warranty of
675-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
676-# GNU General Public License for more details.
677-#
678-# You should have received a copy of the GNU General Public License
679-# along with this program. If not, see <http://www.gnu.org/licenses/>.
680-#
681-
682-set -aux
683-
684-# Source file to get OB number variable
685-. /etc/orange-box.conf
686-
687-# If user is not root then exit
688-if [ "$(id -u)" != "0" ]; then
689- echo "Must be run with sudo or by root"
690- exit 77
691-fi
692-
693-# Ensure the MAAS URL is set correctly
694-MAAS_URL=http://172.27.${orangebox_number}.1/MAAS
695-
696-# set apikey variable
697-apikey=`maas-region apikey --username admin | tail -n1`
698-
699-# login to MAAS
700-maas login admin $MAAS_URL $apikey
701-
702-for i in {0..2}; do
703- hostname="node00vm${i}ob${orangebox_number}"
704- system_id=$(maas admin nodes read hostname=${hostname} |grep system_id | cut -d'"' -f4)
705- sub_net="172.27.$(expr ${orangebox_number} + 2).0/23"
706- eth1_set=$(maas admin interface read $system_id eth1|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null 2>&1; echo $?) #0=already set, 1=needs setting
707- maas admin subnets read|grep "\"id\""|awk '{print $2}'|sed 's/,//'|egrep -x '.{1,2}'|while read subnet_id
708- do
709- maas admin subnet read $subnet_id|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null
710- if [[ $? -eq 0 && ${eth1_set} -eq 1 ]]
711- then
712- maas_fabric=$(maas admin subnet read ${subnet_id}|grep fabric|awk '{print $2}'|sed 's/,//'|sed 's/\"//g')
713- vlanid=$(maas admin vlans read ${maas_fabric} |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}')
714- maas admin interface update $system_id eth1 vlan=$vlanid
715- maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net"
716- fi
717- done
718-done
719
720=== removed file '05-add_physical_nodes.sh'
721--- 05-add_physical_nodes.sh 2016-12-07 17:37:21 +0000
722+++ 05-add_physical_nodes.sh 1970-01-01 00:00:00 +0000
723@@ -1,88 +0,0 @@
724-#!/bin/bash
725-#
726-# Script to add physical OrangeBox nodes to MAAS
727-# Copyright (C) 2016 Canonical Ltd.
728-#
729-# Authors: Scott Croft <scott@canonical.com>
730-#
731-# This program is free software: you can redistribute it and/or modify
732-# it under the terms of the GNU General Public License as published by
733-# the Free Software Foundation, version 3 of the License.
734-#
735-# This program is distributed in the hope that it will be useful,
736-# but WITHOUT ANY WARRANTY; without even the implied warranty of
737-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
738-# GNU General Public License for more details.
739-#
740-# You should have received a copy of the GNU General Public License
741-# along with this program. If not, see <http://www.gnu.org/licenses/>.
742-#
743-
744-set -aux
745-
746-# If user is not root then exit
747-if [ "$(id -u)" != "0" ]; then
748- echo "Must be run with sudo or by root"
749- exit 77
750-fi
751-
752-# Get ob number
753-#
754-ob_number=`hostname | cut -c 10- -`
755-
756-# Ensure the MAAS URL and CLUSTER UUID are set correctly
757-MAAS_URL=http://172.27.${ob_number}.1/MAAS
758-CLUSTER_UUID=`grep cluster_uuid /etc/maas/rackd.conf |awk '{print $2}'`
759-
760-# AMT Password set
761-AMT_PASSWORD=Password1+
762-
763-# set apikey variable
764-apikey=`maas-region apikey --username admin | tail -n1`
765-
766-# login to MAAS
767-maas login admin $MAAS_URL $apikey
768-
769-# Add nodes to MAAS by accessing their amt interfaces
770-for amtnum in {11..20}
771-do
772-ping -c 2 172.27.${ob_number}.${amtnum}
773-
774-# Get mac address for the corresponding amt ip address
775-mac=`arp -n | grep 172.27.${ob_number}.$amtnum |awk '{print $3}'`
776-echo "$mac belongs to node${amtnum}ob${ob_number} with ip 172.27.${ob_number}.${amtnum}"
777-
778-# Get the node number for the name out of the amt ip address
779-nodenum=`expr ${amtnum} - 10`
780-if [ ${nodenum} -lt 10 ]; then
781- nodenum="0${nodenum}"
782-fi
783-echo "The name of the node is node${nodenum}ob${ob_number}"
784-
785-# Add each node to MAAS and commission it
786-maas admin machines create architecture=amd64 power_type=amt power_parameters_power_address=172.27.${ob_number}.${amtnum} power_parameters_power_pass=Password1+ mac_addresses=${mac} hostname=node${nodenum}ob${ob_number}
787-
788-#Add tags to MAAS if not already there
789-maas admin tags create name=physical || true
790-maas admin tags create name=use-fastpath-installer || true
791-
792-#Get the system id of each node
793-system_id=$(maas admin nodes read mac_address=$mac | grep system_id | cut -d'"' -f4)
794-echo $system_id
795-
796-#Assign tags to each node
797-maas admin tag update-nodes "physical" add=$system_id
798-maas admin tag update-nodes "use-fastpath-installer" add=$system_id
799-
800-#Determine which zone a node will be in
801-if [ ${nodenum} -lt 6 ]; then
802- zone="zone1"
803- else
804- zone="zone2"
805-fi
806-echo "Node node${nodenum}ob${ob_number} is in $zone"
807-
808-#Add the nodes to their respective zone
809-maas admin nodes set-zone zone=$zone nodes=$system_id
810-
811-done
812
813=== removed file '05a-mod_physical_nodes.sh'
814--- 05a-mod_physical_nodes.sh 2016-09-20 09:23:07 +0000
815+++ 05a-mod_physical_nodes.sh 1970-01-01 00:00:00 +0000
816@@ -1,74 +0,0 @@
817-#!/bin/bash
818-#
819-# Script to add physical OrangeBox nodes to MAAS
820-# Copyright (C) 2016 Canonical Ltd.
821-#
822-# Authors: Scott Croft <scott@canonical.com>
823-#
824-# This program is free software: you can redistribute it and/or modify
825-# it under the terms of the GNU General Public License as published by
826-# the Free Software Foundation, version 3 of the License.
827-#
828-# This program is distributed in the hope that it will be useful,
829-# but WITHOUT ANY WARRANTY; without even the implied warranty of
830-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
831-# GNU General Public License for more details.
832-#
833-# You should have received a copy of the GNU General Public License
834-# along with this program. If not, see <http://www.gnu.org/licenses/>.
835-#
836-
837-set -aux
838-
839-# If user is not root then exit
840-if [ "$(id -u)" != "0" ]; then
841- echo "Must be run with sudo or by root"
842- exit 77
843-fi
844-
845-# Get ob number
846-#
847-ob_number=`hostname | cut -c 10- -`
848-
849-# Ensure the MAAS URL is set correctly
850-#
851-MAAS_URL=http://172.27.${ob_number}.1/MAAS
852-
853-# set apikey variable
854-#
855-apikey=`maas-region apikey --username admin | tail -n1`
856-
857-# login to MAAS
858-#
859-maas login admin $MAAS_URL $apikey
860-
861-# Configure second usb interface for second fabric and proper subnet
862-#
863-sub_net="172.27.$(expr ${ob_number} + 2).0/23"
864-for nodenum in {01..10}
865-do
866- interface=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep enx | cut -d '"' -f4)
867- system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep system_id | cut -d'"' -f4)
868- maas admin subnets read|grep "\"id\""|awk '{print $2}'|sed 's/,//'|egrep -x '.{1,2}'|while read subnet_id
869- do
870- maas admin subnet read $subnet_id|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null
871- if [[ $? -eq 0 ]]
872- then
873- maas_fabric=$(maas admin subnet read ${subnet_id}|grep fabric|awk '{print $2}'|sed 's/,//'|sed 's/\"//g')
874- vlanid=$(maas admin vlans read ${maas_fabric} |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}')
875- if [[ -n ${interface} ]]
876- then
877- maas admin interface update $system_id $interface name=eth1
878- maas admin interface update $system_id eth1 vlan=$vlanid
879- maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net"
880- else
881- eth1_set=$(maas admin interface read $system_id eth1|grep cidr 1>/dev/null 2>&1; echo $?) #0=already set, 1=needs setting
882- if [[ ${eth1_set} -eq 1 ]]
883- then
884- maas admin interface update $system_id eth1 vlan=$vlanid
885- maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net"
886- fi
887- fi
888- fi
889- done
890-done
891
892=== removed file '06-juju_environment.sh'
893--- 06-juju_environment.sh 2016-09-20 09:23:07 +0000
894+++ 06-juju_environment.sh 1970-01-01 00:00:00 +0000
895@@ -1,130 +0,0 @@
896-#!/bin/bash
897-
898-set -e
899-set -x
900-
901-#Get ob number
902-ob_number=`hostname | cut -c 10- -`
903-
904-router_ip=172.27.${ob_number}.1
905-#set apikey variable
906-apikey=`sudo maas-region apikey --username admin | tail -n1`
907-
908-setup_juju() {
909- mkdir -p /home/ubuntu/.juju
910- cat >/home/ubuntu/.juju/environments.yaml <<EOF
911-default: maas
912-environments:
913- maas:
914- type: maas
915- maas-server: 'http://${router_ip}/MAAS/'
916- maas-oauth: '$apikey'
917- default-series: trusty
918- #enable-os-upgrade: false
919- authorized-keys-path: /home/ubuntu/.ssh/id_rsa.pub
920- admin-secret: 'admin'
921- logging-config: '<root>=DEBUG'
922- lxc-clone: true
923-EOF
924- rm -rf /home/ubuntu/.juju-plugins
925- git clone https://github.com/juju/plugins /home/ubuntu/.juju-plugins
926-
927- # Change ownership recusrively of specified directory
928-# sudo chown -R ubuntu:ubuntu /home/ubuntu/
929-
930- echo "PATH=\$PATH:/home/ubuntu/.juju-plugins:/home/ubuntu/Examples/bin" >> /home/ubuntu/.bashrc
931- echo "export JUJU_DEV_FEATURE_FLAGS=maas2" >> /home/ubuntu/.bashrc
932-}
933-
934-setup_landscape() {
935- # The master node will be managed by Landscape
936- if which landscape-config; then
937- case "$(hostname)" in
938- OrangeBox*|orangebox*)
939- sudo landscape-config -a cpe-sa -t "$(hostname)__$(dmidecode -s baseboard-serial-number)" --script-users=ALL --silent --include-manager-plugins=ScriptExecution || true
940- ;;
941- esac
942- fi
943-}
944-
945-setup_desktop() {
946- # connect running session bus if any
947- dbus_session_bus_address=$(pgrep -u "$USER" -af 'dbus-daemon --fork --session' | grep -o 'unix:.*' || true)
948- if [ -n "$dbus_session_bus_address" ]; then
949- env DBUS_SESSION_BUS_ADDRESS="$dbus_session_bus_address" \
950- dconf load / < template/dconf.txt
951- else
952- dbus-launch dconf load / < template/dconf.txt
953- fi
954-
955- # Disable Ubuntu crash reporter
956- echo "enabled=0" |sudo tee /etc/default/apport
957-
958- # Stop Ubuntu crash reporter
959- sudo invoke-rc.d apport stop || true
960-}
961-
962-setup_remmina() {
963- if [[ -d /home/ubuntu/.remmina ]]
964- then
965- echo "Remmina already setup"
966- else
967- echo "Setting up Remmina..."
968- mkdir /home/ubuntu/.remmina
969- for nodenum in {1..10}
970- do
971- cat >/home/ubuntu/.remmina/node${nodenum}.remmina <<EOF
972-[remmina]
973-keymap=
974-ssh_auth=0
975-quality=0
976-disableencryption=0
977-ssh_charset=
978-ssh_privatekey=
979-server=172.27.${ob_number}.`expr ${nodenum} + 10`
980-hscale=0
981-group=
982-password=Ubuntu1+
983-name=node${nodenum}
984-ssh_loopback=0
985-viewonly=0
986-ssh_username=
987-ssh_server=
988-window_maximize=0
989-aspectscale=0
990-protocol=VNC
991-window_height=825
992-window_width=963
993-vscale=0
994-ssh_enabled=0
995-username=admin
996-showcursor=0
997-disableserverinput=0
998-colordepth=8
999-disableclipboard=0
1000-viewmode=1
1001-EOF
1002- done
1003- chown -R ubuntu:ubuntu /home/ubuntu/.remmina
1004- fi
1005-}
1006-
1007-setup_juju
1008-setup_landscape
1009-setup_desktop
1010-setup_remmina
1011-/srv/obinstall/import_SA_keys.sh
1012-if [[ -d /srv/sademos-15.10 ]]
1013-then
1014- cd /srv/sademos-15.10; bzr pull
1015-else
1016- bzr branch lp:sademos /srv/sademos-15.10
1017-fi
1018-if [[ -d /srv/sademos-16.04 ]]
1019-then
1020- cd /srv/sademos-16.04; bzr pull
1021-else
1022- bzr branch lp:sademos/16.04 /srv/sademos-16.04
1023-fi
1024-ln -s /srv/sademos-16.04 /home/ubuntu/sademos-juju2
1025-ln -s /srv/sademos-15.10 /home/ubuntu/sademos-juju1.25
1026
1027=== modified file 'LP_USERS.list'
1028--- LP_USERS.list 2017-01-24 22:18:42 +0000
1029+++ LP_USERS.list 2017-04-25 19:02:06 +0000
1030@@ -4,26 +4,24 @@
1031 sabdfl
1032
1033 # Americas
1034-mahmoh
1035-secroft
1036 elchito
1037 michael.iatrou
1038-achandrashekar
1039-jfrancisco-poo
1040-fenar-e
1041 craig-bender
1042-twitch0815
1043 mcjilton
1044+<<<<<<< TREE
1045 boulderrickv
1046+=======
1047+kiko
1048+>>>>>>> MERGE-SOURCE
1049
1050 # EMEA
1051-markashtonb
1052 5ello
1053-irdezfer
1054 molinari-dario
1055 idobos
1056+ivoks
1057+mmenkhof
1058+matt-jarvis
1059
1060 # APAC
1061 zhanglei-mao
1062 nobuto
1063-takaakisuzuki
1064
1065=== modified file 'PACKAGES.list'
1066--- PACKAGES.list 2016-05-19 22:40:57 +0000
1067+++ PACKAGES.list 2017-04-25 19:02:06 +0000
1068@@ -39,7 +39,8 @@
1069 nload
1070 traceroute
1071 python-openstackclient
1072-
1073+# Moved from main script body
1074+run-one
1075 # automate USB-serial operations
1076 expect
1077 picocom
1078
1079=== removed file 'VARS'
1080--- VARS 2016-05-19 22:40:57 +0000
1081+++ VARS 1970-01-01 00:00:00 +0000
1082@@ -1,1 +0,0 @@
1083-TESTED_BIOS_REVISION=0027
1084
1085=== removed file 'amt_vnc_config.sh'
1086--- amt_vnc_config.sh 2016-12-07 17:37:21 +0000
1087+++ amt_vnc_config.sh 1970-01-01 00:00:00 +0000
1088@@ -1,109 +0,0 @@
1089-#!/bin/bash
1090-#
1091-# Script to modify physical OrangeBox nodes, setting the amt settings correctly
1092-# Copyright (C) 2016 Canonical Ltd.
1093-#
1094-# Authors: Scott Croft <scott@canonical.com>
1095-#
1096-# This program is free software: you can redistribute it and/or modify
1097-# it under the terms of the GNU General Public License as published by
1098-# the Free Software Foundation, version 3 of the License.
1099-#
1100-# This program is distributed in the hope that it will be useful,
1101-# but WITHOUT ANY WARRANTY; without even the implied warranty of
1102-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1103-# GNU General Public License for more details.
1104-#
1105-# You should have received a copy of the GNU General Public License
1106-# along with this program. If not, see <http://www.gnu.org/licenses/>.
1107-#
1108-
1109-#set -aux
1110-
1111-usage()
1112-{
1113-cat << EOF
1114-usage: $0 options
1115-
1116-This script to setup amt on the node(s)
1117-
1118-OPTIONS:
1119- -h Show this message
1120- -a Sets the amt port configuration for all nodes
1121- -s <node #> Sets the amt configuration for a single node numbering between 11 and 20 where
1122- node1 is equal to 11, node2 - 12, etc.
1123-EOF
1124-}
1125-
1126-if [ "$(id -u)" != "0" ]; then
1127- echo "Must be run with sudo or by root"
1128- exit 77
1129-fi
1130-
1131-# Get ob number
1132-#
1133-ob_number=`hostname | cut -c 10- -`
1134-
1135-AMT_PASSWORD=Password1+
1136-
1137-all_nodes(){
1138- for amtnum in {11..20}
1139- do
1140- # Set AMT to work with VNC and Remmina
1141- wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${amtnum} -P 16992 -u admin -p ${AMT_PASSWORD} -k RFBPassword=Ubuntu1+ > /dev/null 2>&1
1142- # enable KVM redirection to port 5900
1143- wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${amtnum} -P 16992 -u admin -p ${AMT_PASSWORD} -k Is5900PortEnabled=true > /dev/null 2>&1
1144- # disable opt-in policy
1145- wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${amtnum} -P 16992 -u admin -p ${AMT_PASSWORD} -k OptInPolicy=false > /dev/null 2>&1
1146- # disable session timeout
1147- wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${amtnum} -P 16992 -u admin -p ${AMT_PASSWORD} -k SessionTimeout=0 > /dev/null 2>&1
1148- # enable KVM
1149- wsman invoke -a RequestStateChange http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_KVMRedirectionSAP -h 172.27.${ob_number}.${amtnum} -P 16992 -u admin -p ${AMT_PASSWORD} -k RequestedState=2 > /dev/null 2>&1
1150- done
1151-}
1152-
1153-single_node(){
1154- if [ ${node} -lt 11 ] || [ ${node} -gt 20 ];then
1155- echo "The node numbers range from 11-20"
1156- exit 1
1157- fi
1158- wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${node} -P 16992 -u admin -p ${AMT_PASSWORD} -k RFBPassword=Ubuntu1+ > /dev/null 2>&1
1159- wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${node} -P 16992 -u admin -p ${AMT_PASSWORD} -k Is5900PortEnabled=true > /dev/null 2>&1
1160- wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${node} -P 16992 -u admin -p ${AMT_PASSWORD} -k OptInPolicy=false > /dev/null 2>&1
1161- wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${node} -P 16992 -u admin -p ${AMT_PASSWORD} -k SessionTimeout=0 > /dev/null 2>&1
1162- wsman invoke -a RequestStateChange http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_KVMRedirectionSAP -h 172.27.${ob_number}.${node} -P 16992 -u admin -p ${AMT_PASSWORD} -k RequestedState=2 > /dev/null 2>&1
1163-}
1164-
1165-if (($# == 0)); then
1166- usage
1167-fi
1168-
1169-while getopts "ahs:" OPTION
1170-do
1171- case $OPTION in
1172- a)
1173- echo "Working"
1174- all_nodes
1175- echo "Done"
1176- ;;
1177- h)
1178- usage
1179- exit 1
1180- ;;
1181- s)
1182- node=$2
1183- echo "Working"
1184- single_node
1185- echo "Done"
1186- ;;
1187- ?)
1188- usage
1189- exit
1190- ;;
1191- \?)
1192- echo "Invalid option: -$OPTARG" >&2
1193- usage
1194- exit
1195- ;;
1196- esac
1197-done
1198
1199=== removed file 'archive.conf'
1200--- archive.conf 2016-05-19 22:40:57 +0000
1201+++ archive.conf 1970-01-01 00:00:00 +0000
1202@@ -1,13 +0,0 @@
1203-<VirtualHost *:80>
1204- ServerName archive.ubuntu.com
1205- ServerAdmin webmaster@localhost
1206- DocumentRoot /srv/mirrors/archive.ubuntu.com/
1207- ErrorLog ${APACHE_LOG_DIR}/error.log
1208- CustomLog ${APACHE_LOG_DIR}/access.log combined
1209- <Directory /srv/mirrors/archive.ubuntu.com/>
1210- Options Indexes FollowSymLinks Multiviews
1211- Require all granted
1212- </Directory>
1213-</VirtualHost>
1214-
1215-# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
1216
1217=== removed directory 'bin'
1218=== removed file 'bin/change-juju-password.exp'
1219--- bin/change-juju-password.exp 2016-06-16 18:42:07 +0000
1220+++ bin/change-juju-password.exp 1970-01-01 00:00:00 +0000
1221@@ -1,28 +0,0 @@
1222-#!/usr/bin/expect -f
1223-if {$argc!=3} {
1224- send_user "usage: $argv0 controller username password \n"
1225- send_user "ex: $argv0 maas-controller admin canonical\n\n"
1226- exit
1227-}
1228-log_user 0
1229-set timeout -1
1230-match_max 100000
1231-# juju controller
1232-set JUJU_CONTROLLER [lindex $argv 0]
1233-# set username
1234-set JUJU_USER [lindex $argv 1]
1235-# store password
1236-set JUJU_PASS [lindex $argv 2]
1237-# spawn a shell
1238-spawn $env(SHELL)
1239-# send juju change password command
1240-# Add logic to do current user controller/user
1241-send -- "juju change-user-password -c $JUJU_CONTROLLER $JUJU_USER\r"
1242-expect "*assword:"
1243-send "$JUJU_PASS\r"
1244-expect "*again:"
1245-send "$JUJU_PASS\r"
1246-expect "*pdated."
1247-send "\r"
1248-send_user "$argv0 completed successfully.\n"
1249-
1250
1251=== removed file 'bin/verify.sh'
1252--- bin/verify.sh 2016-05-19 22:40:57 +0000
1253+++ bin/verify.sh 1970-01-01 00:00:00 +0000
1254@@ -1,78 +0,0 @@
1255-#!/bin/bash
1256-
1257-set -e
1258-set -u
1259-
1260-BIOS_PREFIX=MYBDWi5v.86A.
1261-USERNAME=ubuntu
1262-HOSTNAME_REGEX='OrangeBox[0-9][0-9]'
1263-
1264-. VARS
1265-
1266-ERROR=
1267-log() {
1268- type=$1
1269- format=$2
1270- shift 2
1271- case $type in
1272- error)
1273- printf '\e[1;31mERROR:\e[0m '
1274- # shellcheck disable=SC2059
1275- printf "${format}\n" "$@"
1276- ERROR=1
1277- ;;
1278- warn)
1279- printf '\e[1;33mWARNING:\e[0m '
1280- # shellcheck disable=SC2059
1281- printf "${format}\n" "$@"
1282- ;;
1283- info)
1284- printf '\e[0;32mINFO:\e[0m '
1285- # shellcheck disable=SC2059
1286- printf "${format}\n" "$@"
1287- ;;
1288- *)
1289- echo 'log: unknown type specified.'
1290- exit 1
1291- ;;
1292- esac
1293-}
1294-
1295-check_bios_revision() {
1296- bios_version=$(sudo dmidecode -s bios-version | cut -d' ' -f2)
1297- bios_revision=${bios_version#$BIOS_PREFIX}
1298- bios_revision=${bios_revision%%.*}
1299-
1300- if [ "$bios_revision" = "$TESTED_BIOS_REVISION" ]; then
1301- log info 'You have the tested BIOS revision - %s' "$TESTED_BIOS_REVISION"
1302- else
1303- log warn 'The current tested BIOS revision is %s, but you have revision %s' "$TESTED_BIOS_REVISION" "$bios_revision"
1304- fi
1305-}
1306-
1307-check_hostname() {
1308- if echo "$HOSTNAME" | egrep -q "^${HOSTNAME_REGEX}$"; then
1309- log info 'hostname is OK - %s' "$HOSTNAME"
1310- else
1311- log error 'hostname must meet the regex "%s"' "$HOSTNAME_REGEX"
1312- fi
1313-}
1314-
1315-check_username() {
1316- if [ "$USER" = "$USERNAME" ]; then
1317- log info 'username is OK - %s' "$USERNAME"
1318- else
1319- log error 'username must be "%s"' "$USERNAME"
1320- fi
1321-}
1322-
1323-# get sudo permission
1324-sudo true
1325-
1326-check_bios_revision
1327-check_hostname
1328-check_username
1329-
1330-if [ "$ERROR" = 1 ]; then
1331- exit 1
1332-fi
1333
1334=== removed file 'fabric.sh'
1335--- fabric.sh 2016-05-19 22:40:57 +0000
1336+++ fabric.sh 1970-01-01 00:00:00 +0000
1337@@ -1,16 +0,0 @@
1338-#!/bin/bash
1339-
1340-ob_number=`hostname | cut -c 10- -`
1341-
1342-vlanid=$(maas admin vlans read 2 |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}')
1343-sub_net="172.27.`expr ${ob_number} + 2`.0/23"
1344-#configure eth1 for fabric-1 and proper subnet
1345-for nodenum in {01..10}
1346-do
1347- system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep system_id | cut -d'"' -f4)
1348- echo $system_id
1349- interface=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep enx |cut -d'"' -f4)
1350- echo $interface
1351- maas admin interface update $system_id $interface vlan=$vlanid
1352- maas admin interface link-subnet $system_id $interface mode=auto subnet="$sub_net"
1353-done
1354
1355=== removed file 'import_SA_keys.sh'
1356--- import_SA_keys.sh 2016-05-19 22:40:57 +0000
1357+++ import_SA_keys.sh 1970-01-01 00:00:00 +0000
1358@@ -1,19 +0,0 @@
1359-#!/bin/bash
1360-
1361-set -e
1362-set -u
1363-
1364-authorized_keys=~/.ssh/authorized_keys
1365-if [ -e $authorized_keys ]; then
1366- mv $authorized_keys $authorized_keys.old
1367-fi
1368-
1369-if [ -e ~maas/.ssh/id_rsa.pub ]; then
1370- #copy maas user's ssh key
1371- sudo cat ~maas/.ssh/id_rsa.pub > $authorized_keys
1372-fi
1373-
1374-while read user; do
1375- user=${user%%#*}
1376- [ -n "$user" ] && ssh-import-id "$user"
1377-done < LP_USERS.list
1378
1379=== added directory 'scripts'
1380=== added file 'scripts/04a-mod_virtual_nodes.sh'
1381--- scripts/04a-mod_virtual_nodes.sh 1970-01-01 00:00:00 +0000
1382+++ scripts/04a-mod_virtual_nodes.sh 2017-04-25 19:02:06 +0000
1383@@ -0,0 +1,57 @@
1384+#!/bin/bash
1385+#
1386+# Script to modify virtual OrangeBox nodes in MAAS
1387+# Copyright (C) 2016 Canonical Ltd.
1388+#
1389+# Authors: Scott Croft <scott@canonical.com>
1390+#
1391+# This program is free software: you can redistribute it and/or modify
1392+# it under the terms of the GNU General Public License as published by
1393+# the Free Software Foundation, version 3 of the License.
1394+#
1395+# This program is distributed in the hope that it will be useful,
1396+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1397+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1398+# GNU General Public License for more details.
1399+#
1400+# You should have received a copy of the GNU General Public License
1401+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1402+#
1403+
1404+set -aux
1405+
1406+# Source file to get OB number variable
1407+. /etc/orange-box.conf
1408+
1409+# If user is not root then exit
1410+if [ "$(id -u)" != "0" ]; then
1411+ echo "Must be run with sudo or by root"
1412+ exit 77
1413+fi
1414+
1415+# Ensure the MAAS URL is set correctly
1416+MAAS_URL=http://172.27.${orangebox_number}.1/MAAS
1417+
1418+# set apikey variable
1419+apikey=`maas-region apikey --username admin | tail -n1`
1420+
1421+# login to MAAS
1422+maas login admin $MAAS_URL $apikey
1423+
1424+for i in {0..2}; do
1425+ hostname="node00vm${i}ob${orangebox_number}"
1426+ system_id=$(maas admin nodes read hostname=${hostname} |grep system_id | cut -d'"' -f4)
1427+ sub_net="172.27.$(expr ${orangebox_number} + 2).0/23"
1428+ eth1_set=$(maas admin interface read $system_id eth1|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null 2>&1; echo $?) #0=already set, 1=needs setting
1429+ maas admin subnets read|grep "\"id\""|awk '{print $2}'|sed 's/,//'|egrep -x '.{1,2}'|while read subnet_id
1430+ do
1431+ maas admin subnet read $subnet_id|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null
1432+ if [[ $? -eq 0 && ${eth1_set} -eq 1 ]]
1433+ then
1434+ maas_fabric=$(maas admin subnet read ${subnet_id}|grep fabric|awk '{print $2}'|sed 's/,//'|sed 's/\"//g')
1435+ vlanid=$(maas admin vlans read ${maas_fabric} |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}')
1436+ maas admin interface update $system_id eth1 vlan=$vlanid
1437+ maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net"
1438+ fi
1439+ done
1440+done
1441
1442=== added file 'scripts/05a-mod_physical_nodes.sh'
1443--- scripts/05a-mod_physical_nodes.sh 1970-01-01 00:00:00 +0000
1444+++ scripts/05a-mod_physical_nodes.sh 2017-04-25 19:02:06 +0000
1445@@ -0,0 +1,74 @@
1446+#!/bin/bash
1447+#
1448+# Script to add physical OrangeBox nodes to MAAS
1449+# Copyright (C) 2016 Canonical Ltd.
1450+#
1451+# Authors: Scott Croft <scott@canonical.com>
1452+#
1453+# This program is free software: you can redistribute it and/or modify
1454+# it under the terms of the GNU General Public License as published by
1455+# the Free Software Foundation, version 3 of the License.
1456+#
1457+# This program is distributed in the hope that it will be useful,
1458+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1459+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1460+# GNU General Public License for more details.
1461+#
1462+# You should have received a copy of the GNU General Public License
1463+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1464+#
1465+
1466+set -aux
1467+
1468+# If user is not root then exit
1469+if [ "$(id -u)" != "0" ]; then
1470+ echo "Must be run with sudo or by root"
1471+ exit 77
1472+fi
1473+
1474+# Get ob number
1475+#
1476+ob_number=`hostname | cut -c 10- -`
1477+
1478+# Ensure the MAAS URL is set correctly
1479+#
1480+MAAS_URL=http://172.27.${ob_number}.1/MAAS
1481+
1482+# set apikey variable
1483+#
1484+apikey=`maas-region apikey --username admin | tail -n1`
1485+
1486+# login to MAAS
1487+#
1488+maas login admin $MAAS_URL $apikey
1489+
1490+# Configure second usb interface for second fabric and proper subnet
1491+#
1492+sub_net="172.27.$(expr ${ob_number} + 2).0/23"
1493+for nodenum in {01..10}
1494+do
1495+ interface=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep enx | cut -d '"' -f4)
1496+ system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep system_id | cut -d'"' -f4)
1497+ maas admin subnets read|grep "\"id\""|awk '{print $2}'|sed 's/,//'|egrep -x '.{1,2}'|while read subnet_id
1498+ do
1499+ maas admin subnet read $subnet_id|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null
1500+ if [[ $? -eq 0 ]]
1501+ then
1502+ maas_fabric=$(maas admin subnet read ${subnet_id}|grep fabric|awk '{print $2}'|sed 's/,//'|sed 's/\"//g')
1503+ vlanid=$(maas admin vlans read ${maas_fabric} |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}')
1504+ if [[ -n ${interface} ]]
1505+ then
1506+ maas admin interface update $system_id $interface name=eth1
1507+ maas admin interface update $system_id eth1 vlan=$vlanid
1508+ maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net"
1509+ else
1510+ eth1_set=$(maas admin interface read $system_id eth1|grep cidr 1>/dev/null 2>&1; echo $?) #0=already set, 1=needs setting
1511+ if [[ ${eth1_set} -eq 1 ]]
1512+ then
1513+ maas admin interface update $system_id eth1 vlan=$vlanid
1514+ maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net"
1515+ fi
1516+ fi
1517+ fi
1518+ done
1519+done
1520
1521=== added file 'scripts/add_physical_nodes.sh'
1522--- scripts/add_physical_nodes.sh 1970-01-01 00:00:00 +0000
1523+++ scripts/add_physical_nodes.sh 2017-04-25 19:02:06 +0000
1524@@ -0,0 +1,147 @@
1525+#!/bin/bash
1526+#
1527+# Script to add physical OrangeBox nodes to MAAS
1528+# Copyright (C) 2016 Canonical Ltd.
1529+#
1530+# Authors: Scott Croft <scott@canonical.com>
1531+#
1532+# This program is free software: you can redistribute it and/or modify
1533+# it under the terms of the GNU General Public License as published by
1534+# the Free Software Foundation, version 3 of the License.
1535+#
1536+# This program is distributed in the hope that it will be useful,
1537+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1538+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1539+# GNU General Public License for more details.
1540+#
1541+# You should have received a copy of the GNU General Public License
1542+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1543+#
1544+
1545+# set -aux
1546+
1547+source ob_profile.sh
1548+
1549+# Get the real node number
1550+get_real_node_number(){
1551+
1552+ local node_num=$(($1 - 10))
1553+ if [ $node_num -lt 10 ]; then
1554+ real_node_num="0${node_num}"
1555+ else
1556+ real_node_num=$node_num
1557+ fi
1558+ echo $real_node_num
1559+
1560+}
1561+
1562+# Get the MAC of the AMT via the ARP table
1563+# $1 - AMT IP address
1564+get_amt_mac(){
1565+
1566+ local amt_ipaddress=$1
1567+ ping -c 2 "$amt_ipaddress" >/dev/null
1568+ mac=$( arp -n | grep "$amt_ipaddress" | awk '{print $3}' )
1569+ echo "$mac"
1570+
1571+}
1572+
1573+# Add a node to MAAS
1574+# $1 - AMT IP address
1575+# $2 - Hostname
1576+# $3 - AMT MAC address
1577+add_node_to_maas(){
1578+
1579+ local amt_ipaddress=$1; shift
1580+ local hostname=$1; shift
1581+ local mac_address=$1; shift
1582+ if maas admin machines create \
1583+ architecture=amd64 \
1584+ power_type=amt \
1585+ power_parameters_power_address="$amt_ipaddress" \
1586+ power_parameters_power_pass="$AMT_PASSWORD" \
1587+ mac_addresses="$mac_address" \
1588+ hostname="$hostname"; then
1589+ system_id=$(maas admin nodes read mac_address="$mac_address" | grep -m 1 system_id | cut -d'"' -f4)
1590+ local -i retval=0
1591+ else
1592+ local -i retval=1
1593+ echo "Unable to create machine $hostname"
1594+ exit $retval
1595+ fi
1596+ return $retval
1597+
1598+}
1599+
1600+# Assign tags to each node
1601+# $1 - MAAS system ID
1602+assign_maas_tags(){
1603+
1604+ local system_id=$1
1605+ local -i retval=0
1606+ echo "Assigning MAAS tags for $system_id"
1607+ for tag in physical use-fastpath-installer; do
1608+ maas admin tag update-nodes "$tag" add="$system_id" || local -i retval=1
1609+ done
1610+ return $retval
1611+
1612+}
1613+
1614+# Determine which zone nodes should be added to
1615+# $1 - node number
1616+# $2 - MAAS system ID
1617+set_zone(){
1618+
1619+ local -i retval=0;
1620+ local node_num=$1; shift
1621+ local system_id=$1; shift
1622+ if [ "$node_num" -lt 6 ]; then
1623+ zone="zone1"
1624+ else
1625+ zone="zone2"
1626+ fi
1627+ echo "Node $node_num should be in $zone - assigning"
1628+ maas admin nodes set-zone zone="$zone" nodes="$system_id" || local -i retval=1
1629+ return $retval
1630+
1631+}
1632+
1633+main(){
1634+
1635+ if ! check_for_root; then
1636+ echo "ERROR: This script needs to be run as root"
1637+ exit 1
1638+ fi
1639+
1640+ login_to_maas
1641+
1642+ for amt_num in {11..20}; do
1643+
1644+ amt_ipaddress=${IP_ROOT}.${OB_NUM}.${amt_num}
1645+ mac_address=$(get_amt_mac "$amt_ipaddress")
1646+ echo "Found MAC $mac_address for AMT IP $amt_ipaddress"
1647+ echo "Configuring AMT $amt_ipaddress"
1648+
1649+ node_num=$(get_real_node_number $amt_num)
1650+ hostname=node${node_num}ob${OB_NUM}
1651+ echo "This node has hostname $hostname"
1652+
1653+ echo "Adding ${hostname} to MAAS"
1654+ if ! add_node_to_maas "$amt_ipaddress" "$hostname" "$mac_address"; then
1655+ echo "ERROR: Could not add node ${hostname}"
1656+ exit 1
1657+ fi
1658+
1659+ # Assume these are non-critical so warn but don't exit
1660+ echo "Assigning MAAS tags for ${hostname}"
1661+ system_id=$(maas admin nodes read mac_address="$mac_address" | grep -m 1 system_id | cut -d'"' -f4)
1662+ if ! assign_maas_tags "$system_id"; then
1663+ echo "Could not set tags correctly for $hostname"
1664+ fi
1665+
1666+ echo "Configuring zones in MAAS"
1667+ set_zone "$node_num" "$system_id"
1668+ done
1669+}
1670+
1671+main "$@"
1672
1673=== added file 'scripts/add_virtual_nodes.sh'
1674--- scripts/add_virtual_nodes.sh 1970-01-01 00:00:00 +0000
1675+++ scripts/add_virtual_nodes.sh 2017-04-25 19:02:06 +0000
1676@@ -0,0 +1,212 @@
1677+#!/bin/bash
1678+#
1679+# orange-box-setup-kvms - create some virtual machines
1680+# Copyright (C) 2014 Canonical Ltd.
1681+#
1682+# Authors: Ronald McCollam <ronald.mccollam@canonical.com>
1683+# Dustin Kirkland <kirkland@canonical.com>
1684+# Modified: Scott Croft <scott@canonical.com> 2016
1685+# Modified: Matt Jarvis <matt.jarvis@canonical.com> 2017
1686+#
1687+# This program is free software: you can redistribute it and/or modify
1688+# it under the terms of the GNU General Public License as published by
1689+# the Free Software Foundation, version 3 of the License.
1690+#
1691+# This program is distributed in the hope that it will be useful,
1692+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1693+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1694+# GNU General Public License for more details.
1695+#
1696+# You should have received a copy of the GNU General Public License
1697+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1698+
1699+source ob_profile.sh
1700+
1701+# Remove default domain
1702+remove_default_domain(){
1703+
1704+ if virsh net-info default &>/dev/null; then
1705+ virsh net-undefine default
1706+ virsh net-destroy default
1707+ fi
1708+
1709+}
1710+
1711+# Check the directories we need exist
1712+check_maas_dirs(){
1713+
1714+ if [ ! -d /var/lib/maas/.ssh ]; then
1715+ mkdir /var/lib/maas/.ssh
1716+ chown maas:maas /var/lib/maas/.ssh
1717+ fi
1718+
1719+}
1720+
1721+# Create the /srv/obvms directory for storing the virtual machines files
1722+create_vm_storage(){
1723+
1724+ if ! [ -d /srv/obvms ]; then
1725+ mkdir /srv/obvms
1726+ fi
1727+ chown -R libvirt-qemu:kvm /srv/obvms
1728+
1729+}
1730+
1731+# Check the MAAS user has an ssh key
1732+check_maas_sshkeys(){
1733+
1734+ if [ ! -f /var/lib/maas/.ssh/id_rsa ]; then
1735+ chsh maas -s /bin/bash
1736+ sudo -u maas ssh-keygen -N "" -t rsa -f /var/lib/maas/.ssh/id_rsa >/dev/null
1737+ fi
1738+
1739+}
1740+
1741+# Check the ubuntu user has the MAAS SSH key in authorized keys
1742+check_ubuntu_authkeys(){
1743+
1744+ if [ ! -f /home/ubuntu/.ssh/authorized_keys ]; then
1745+ mkdir /home/ubuntu/.ssh/
1746+ touch /home/ubuntu/.ssh/authorized_keys
1747+ chown -R ubuntu /home/ubuntu/.ssh/
1748+ chmod 700 /home/ubuntu/.ssh/
1749+ chmod 644 /home/ubuntu/.ssh/authorized_keys
1750+ fi
1751+ cat /var/lib/maas/.ssh/id_rsa.pub >> /home/ubuntu/.ssh/authorized_keys
1752+
1753+}
1754+
1755+# Create zone0 for virtual nodes
1756+create_zone0(){
1757+
1758+ if ! maas admin zone read zone0 >/dev/null 2>&1; then
1759+ maas admin zones create name=zone0 description="Virtual machines on node0"
1760+ fi
1761+
1762+}
1763+
1764+# Add host key signature
1765+add_host_key_sig(){
1766+ # shellcheck disable=SC2024
1767+ sudo -u maas ssh-keyscan "$INTERNAL1_IP" >> /var/lib/maas/.ssh/known_hosts 2>/dev/null
1768+}
1769+
1770+add_node0_key(){
1771+ # shellcheck disable=SC2183
1772+ printf "%s,%s %s %s\n" "node0.maas" "$INTERNAL1_IP" "$(awk '{print $1 " " $2}' /etc/ssh/ssh_host_ecdsa_key.pub)" | tee -a /var/lib/maas/.ssh/known_hosts
1773+}
1774+
1775+cleanup_keys(){
1776+ sudo -u maas virsh -c qemu+ssh://ubuntu@"${INTERNAL1_IP}"/system list > /dev/null || sed -i '/ maas@/d' /home/ubuntu/.ssh/authorized_keys
1777+}
1778+
1779+# Install a virtual machine
1780+# $1 - hostname
1781+install_vm(){
1782+
1783+ virsh destroy "$1" || true
1784+ virsh undefine "$1" || true
1785+ echo "INFO: Installing virtual machine $1"
1786+ if [ "$1" = "node00vm0ob${OB_NUM}.maas" ]; then
1787+ ram=6144
1788+ else
1789+ ram=4096
1790+ fi
1791+ virt-install --name "$1" \
1792+ --ram $ram \
1793+ --disk=path=/srv/obvms/"$1"-1.img,size=20 \
1794+ --disk=path=/srv/obvms/"$1"-2.img,size=2 \
1795+ --vcpus=2 \
1796+ --os-type=linux \
1797+ --pxe \
1798+ --network=bridge=br0 \
1799+ --network=bridge=br0 \
1800+ --boot network \
1801+ --video=cirrus \
1802+ --graphics vnc
1803+ virsh console "$1" || true
1804+ virsh autostart "$1"
1805+
1806+}
1807+
1808+# Update MAAS for a given hostname
1809+# $1 - hostname
1810+update_maas(){
1811+
1812+ local -i retval=0
1813+ mac=$(virsh dumpxml "$1" | python -c 'import sys, lxml.etree; print list(lxml.etree.parse(sys.stdin).iter("mac"))[0].get("address")')
1814+ system_id=$(maas admin nodes read mac_address="$mac" | grep -m 1 system_id | cut -d'"' -f4)
1815+
1816+ if [ -n "$system_id" ]; then
1817+ maas admin machine update "$system_id" \
1818+ hostname="$hostname" \
1819+ power_type=virsh \
1820+ power_parameters_power_address=qemu+ssh://ubuntu@"${INTERNAL1_IP}"/system \
1821+ power_parameters_power_id="$hostname"
1822+ maas admin tag update-nodes "virtual" add="$system_id"
1823+ case $i in
1824+ 0)
1825+ maas admin tag update-nodes "bootstrap" add="$system_id"
1826+ ;;
1827+ 1)
1828+ maas admin tag update-nodes "neutron" add="$system_id"
1829+ ;;
1830+ esac
1831+ maas admin tag update-nodes use-fastpath-installer add="$system_id"
1832+ maas admin machine commission "$system_id" || true
1833+ maas admin nodes set-zone zone=zone0 nodes="$system_id"
1834+ else
1835+ echo "Could not find node $hostname in MAAS"
1836+ local -i retval=1
1837+ fi
1838+ return $retval
1839+
1840+}
1841+
1842+main(){
1843+
1844+ echo "Creating virtual nodes"
1845+
1846+ if ! check_for_root; then
1847+ echo "ERROR: This script must be run as root"
1848+ exit 1
1849+ fi
1850+
1851+ echo "Login to MAAS"
1852+ login_to_maas
1853+
1854+ echo "Checking MAAS configuration"
1855+ check_maas_dirs
1856+
1857+ echo "Configuring keys"
1858+ check_maas_sshkeys
1859+
1860+ add_host_key_sig
1861+
1862+ check_ubuntu_authkeys
1863+
1864+ echo "Creating zone0 in MAAS"
1865+ create_zone0
1866+ echo -e "\n"
1867+
1868+ add_node0_key
1869+
1870+ echo "Creating virtual machine storage"
1871+ create_vm_storage
1872+
1873+ echo "Removing default domain"
1874+ remove_default_domain
1875+
1876+ for i in {0..2}; do
1877+ hostname="node00vm${i}ob${OB_NUM}.maas"
1878+ echo "Installing ${hostname}"
1879+ install_vm "$hostname"
1880+ echo -e "\n"
1881+ echo "Configuring MAAS for ${hostname}"
1882+ update_maas "$hostname"
1883+ echo -e "\n"
1884+ done
1885+
1886+}
1887+
1888+main "$@"
1889
1890=== added file 'scripts/amt_vnc_config.sh'
1891--- scripts/amt_vnc_config.sh 1970-01-01 00:00:00 +0000
1892+++ scripts/amt_vnc_config.sh 2017-04-25 19:02:06 +0000
1893@@ -0,0 +1,109 @@
1894+#!/bin/bash
1895+#
1896+# Script to modify physical OrangeBox nodes, setting the amt settings correctly
1897+# Copyright (C) 2016 Canonical Ltd.
1898+#
1899+# Authors: Scott Croft <scott@canonical.com>
1900+#
1901+# This program is free software: you can redistribute it and/or modify
1902+# it under the terms of the GNU General Public License as published by
1903+# the Free Software Foundation, version 3 of the License.
1904+#
1905+# This program is distributed in the hope that it will be useful,
1906+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1907+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1908+# GNU General Public License for more details.
1909+#
1910+# You should have received a copy of the GNU General Public License
1911+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1912+#
1913+
1914+#set -aux
1915+
1916+usage()
1917+{
1918+cat << EOF
1919+usage: $0 options
1920+
1921+This script to setup amt on the node(s)
1922+
1923+OPTIONS:
1924+ -h Show this message
1925+ -a Sets the amt port configuration for all nodes
1926+ -s <node #> Sets the amt configuration for a single node numbering between 11 and 20 where
1927+ node1 is equal to 11, node2 - 12, etc.
1928+EOF
1929+}
1930+
1931+if [ "$(id -u)" != "0" ]; then
1932+ echo "Must be run with sudo or by root"
1933+ exit 77
1934+fi
1935+
1936+# Get ob number
1937+#
1938+ob_number=`hostname | cut -c 10- -`
1939+
1940+AMT_PASSWORD=Password1+
1941+
1942+all_nodes(){
1943+ for amtnum in {11..20}
1944+ do
1945+ # Set AMT to work with VNC and Remmina
1946+ wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${amtnum} -P 16992 -u admin -p ${AMT_PASSWORD} -k RFBPassword=Ubuntu1+ > /dev/null 2>&1
1947+ # enable KVM redirection to port 5900
1948+ wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${amtnum} -P 16992 -u admin -p ${AMT_PASSWORD} -k Is5900PortEnabled=true > /dev/null 2>&1
1949+ # disable opt-in policy
1950+ wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${amtnum} -P 16992 -u admin -p ${AMT_PASSWORD} -k OptInPolicy=false > /dev/null 2>&1
1951+ # disable session timeout
1952+ wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${amtnum} -P 16992 -u admin -p ${AMT_PASSWORD} -k SessionTimeout=0 > /dev/null 2>&1
1953+ # enable KVM
1954+ wsman invoke -a RequestStateChange http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_KVMRedirectionSAP -h 172.27.${ob_number}.${amtnum} -P 16992 -u admin -p ${AMT_PASSWORD} -k RequestedState=2 > /dev/null 2>&1
1955+ done
1956+}
1957+
1958+single_node(){
1959+ if [ ${node} -lt 11 ] || [ ${node} -gt 20 ];then
1960+ echo "The node numbers range from 11-20"
1961+ exit 1
1962+ fi
1963+ wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${node} -P 16992 -u admin -p ${AMT_PASSWORD} -k RFBPassword=Ubuntu1+ > /dev/null 2>&1
1964+ wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${node} -P 16992 -u admin -p ${AMT_PASSWORD} -k Is5900PortEnabled=true > /dev/null 2>&1
1965+ wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${node} -P 16992 -u admin -p ${AMT_PASSWORD} -k OptInPolicy=false > /dev/null 2>&1
1966+ wsman put http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData -h 172.27.${ob_number}.${node} -P 16992 -u admin -p ${AMT_PASSWORD} -k SessionTimeout=0 > /dev/null 2>&1
1967+ wsman invoke -a RequestStateChange http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_KVMRedirectionSAP -h 172.27.${ob_number}.${node} -P 16992 -u admin -p ${AMT_PASSWORD} -k RequestedState=2 > /dev/null 2>&1
1968+}
1969+
1970+if (($# == 0)); then
1971+ usage
1972+fi
1973+
1974+while getopts "ahs:" OPTION
1975+do
1976+ case $OPTION in
1977+ a)
1978+ echo "Working"
1979+ all_nodes
1980+ echo "Done"
1981+ ;;
1982+ h)
1983+ usage
1984+ exit 1
1985+ ;;
1986+ s)
1987+ node=$2
1988+ echo "Working"
1989+ single_node
1990+ echo "Done"
1991+ ;;
1992+ ?)
1993+ usage
1994+ exit
1995+ ;;
1996+ \?)
1997+ echo "Invalid option: -$OPTARG" >&2
1998+ usage
1999+ exit
2000+ ;;
2001+ esac
2002+done
2003
2004=== added file 'scripts/change-juju-password.exp'
2005--- scripts/change-juju-password.exp 1970-01-01 00:00:00 +0000
2006+++ scripts/change-juju-password.exp 2017-04-25 19:02:06 +0000
2007@@ -0,0 +1,28 @@
2008+#!/usr/bin/expect -f
2009+if {$argc!=3} {
2010+ send_user "usage: $argv0 controller username password \n"
2011+ send_user "ex: $argv0 maas-controller admin canonical\n\n"
2012+ exit
2013+}
2014+log_user 0
2015+set timeout -1
2016+match_max 100000
2017+# juju controller
2018+set JUJU_CONTROLLER [lindex $argv 0]
2019+# set username
2020+set JUJU_USER [lindex $argv 1]
2021+# store password
2022+set JUJU_PASS [lindex $argv 2]
2023+# spawn a shell
2024+spawn $env(SHELL)
2025+# send juju change password command
2026+# Add logic to do current user controller/user
2027+send -- "juju change-user-password -c $JUJU_CONTROLLER $JUJU_USER\r"
2028+expect "*assword:"
2029+send "$JUJU_PASS\r"
2030+expect "*again:"
2031+send "$JUJU_PASS\r"
2032+expect "*pdated."
2033+send "\r"
2034+send_user "$argv0 completed successfully.\n"
2035+
2036
2037=== added file 'scripts/fabric.sh'
2038--- scripts/fabric.sh 1970-01-01 00:00:00 +0000
2039+++ scripts/fabric.sh 2017-04-25 19:02:06 +0000
2040@@ -0,0 +1,16 @@
2041+#!/bin/bash
2042+
2043+ob_number=`hostname | cut -c 10- -`
2044+
2045+vlanid=$(maas admin vlans read 2 |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}')
2046+sub_net="172.27.`expr ${ob_number} + 2`.0/23"
2047+#configure eth1 for fabric-1 and proper subnet
2048+for nodenum in {01..10}
2049+do
2050+ system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep system_id | cut -d'"' -f4)
2051+ echo $system_id
2052+ interface=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep enx |cut -d'"' -f4)
2053+ echo $interface
2054+ maas admin interface update $system_id $interface vlan=$vlanid
2055+ maas admin interface link-subnet $system_id $interface mode=auto subnet="$sub_net"
2056+done
2057
2058=== added file 'scripts/install_base_system.sh'
2059--- scripts/install_base_system.sh 1970-01-01 00:00:00 +0000
2060+++ scripts/install_base_system.sh 2017-04-25 19:02:06 +0000
2061@@ -0,0 +1,167 @@
2062+#!/bin/bash
2063+#
2064+# Base system installation for the OrangeBox
2065+# Copyright (C) 2016 Canonical Ltd.
2066+#
2067+# Authors: Scott Croft <scott@canonical.com>
2068+# Matt Jarvis <matt.jarvis@canonical.com>
2069+#
2070+# This program is free software: you can redistribute it and/or modify
2071+# it under the terms of the GNU General Public License as published by
2072+# the Free Software Foundation, version 3 of the License.
2073+#
2074+# This program is distributed in the hope that it will be useful,
2075+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2076+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2077+# GNU General Public License for more details.
2078+#
2079+# You should have received a copy of the GNU General Public License
2080+# along with this program. If not, see <http://www.gnu.org/licenses/>.
2081+#
2082+#
2083+# set -e
2084+# set -x
2085+
2086+source ob_profile.sh
2087+
2088+PACKAGE_LIST=../PACKAGES.list
2089+
2090+usage()
2091+{
2092+cat << EOF
2093+usage: $0 options
2094+
2095+This script installs the base system
2096+Allows selection of additional PPA's to use
2097+
2098+OPTIONS:
2099+ -h Show this message
2100+ -p Manually enter PPA URL's ( eg. ppa:/juju/stable)
2101+EOF
2102+}
2103+
2104+# Check to ensure that the user on the system is ubuntu and assigned the uid of 1000
2105+check_ubuntu_user(){
2106+
2107+ if [ "$(id -u ubuntu)" != "1000" ]; then
2108+ return 1
2109+ fi
2110+
2111+}
2112+
2113+# Check if a package is installed
2114+# $1 - package name
2115+check_package(){
2116+
2117+ local -i retval=0
2118+ if ! dpkg -l | grep -q "$package"; then
2119+ local -i retval=1
2120+ fi
2121+ return $retval
2122+
2123+}
2124+
2125+# Install the required packages for OrangeBox operation
2126+install_packages (){
2127+
2128+ local -i errors=0
2129+ local -i retval=0
2130+ # Ignore blank lines and bash style comments
2131+ egrep -v '^$|^#' $PACKAGE_LIST | while read -r package; do
2132+ if ! check_package "$package"; then
2133+ # shellcheck disable=SC2030
2134+ apt-get install -qq -y "$package" || ((errors++))
2135+ fi
2136+ done
2137+ # shellcheck disable=SC2031
2138+ if [ $errors -ne 0 ]; then
2139+ local -i retval=1
2140+ fi
2141+ return $retval
2142+
2143+}
2144+
2145+# Setup PPA's for MAAS and Juju
2146+set_up_ppas(){
2147+
2148+ local jujuppa=$1; shift
2149+ local maasppa=$1; shift
2150+ local -i retval=0
2151+ local -i errors=0
2152+ for ppa in $jujuppa $maasppa; do
2153+ echo "Adding PPA ${ppa}"
2154+ add-apt-repository -y "$ppa" || ((errors++))
2155+ done
2156+ if [ $errors -ne 0 ]; then
2157+ local -i retval=1
2158+ fi
2159+ return $retval
2160+
2161+}
2162+
2163+# Configure apt to use archive.ubuntu.com
2164+configure_apt_geos(){
2165+
2166+ sed -i.orig 's|http://.*archive|http://archive|g' /etc/apt/sources.list
2167+
2168+}
2169+
2170+main(){
2171+
2172+ if ! check_for_root; then
2173+ echo "ERROR: this script must be run as root"
2174+ fi
2175+
2176+ if ! check_ubuntu_user; then
2177+ echo "ERROR: OrangeBox setup requires the default user to be [ubuntu]"
2178+ exit 1
2179+ fi
2180+
2181+ # No arguments given - use default PPA's
2182+ if (($# == 0)); then
2183+ jujuppa="ppa:juju/stable"
2184+ maasppa="ppa:maas/stable"
2185+ fi
2186+
2187+ while getopts "hp" OPTION
2188+ do
2189+ case $OPTION in
2190+ h)
2191+ usage
2192+ exit 0
2193+ ;;
2194+ p)
2195+ echo "Build system with custom PPA's"
2196+ printf "Enter PPA URL for juju (eg. ppa:juju/stable):"
2197+ read -r jujuppa
2198+ printf "Enter PPA URL for maas (eg. ppa:maas-maintainers/stable):"
2199+ read -r maasppa
2200+ ;;
2201+ \?)
2202+ usage
2203+ exit 1
2204+ ;;
2205+ esac
2206+ done
2207+
2208+ echo "Configuring PPA's"
2209+ if ! set_up_ppas "$jujuppa" "$maasppa"; then
2210+ echo "Unable to configure PPA's"
2211+ exit 1
2212+ fi
2213+
2214+ echo "Configuring apt"
2215+ configure_apt_geos
2216+
2217+ echo "Updating system"
2218+ apt-get update -y
2219+ apt-get dist-upgrade -qq -y
2220+
2221+ if ! install_packages; then
2222+ echo "Some required packages could not be installed"
2223+ exit 1
2224+ fi
2225+
2226+}
2227+
2228+main "$@"
2229
2230=== added file 'scripts/ob_profile.sh'
2231--- scripts/ob_profile.sh 1970-01-01 00:00:00 +0000
2232+++ scripts/ob_profile.sh 2017-04-25 19:02:06 +0000
2233@@ -0,0 +1,80 @@
2234+#
2235+# Global variables and functions for OrangeBox install scripts
2236+# Copyright (C) 2017 Canonical Ltd.
2237+#
2238+# Authors: Matt Jarvis <matt.jarvis@canonical.com>
2239+#
2240+# This program is free software: you can redistribute it and/or modify
2241+# it under the terms of the GNU General Public License as published by
2242+# the Free Software Foundation, version 3 of the License.
2243+#
2244+# This program is distributed in the hope that it will be useful,
2245+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2246+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2247+# GNU General Public License for more details.
2248+#
2249+# You should have received a copy of the GNU General Public License
2250+# along with this program. If not, see <http://www.gnu.org/licenses/>.
2251+#
2252+
2253+# Required BIOS revision
2254+TESTED_BIOS_REVISION=0027
2255+
2256+# Installer log file
2257+LOG_FILE=installer.log
2258+
2259+# Launchpad ID
2260+LAUNCHPAD_ID=matt-jarvis
2261+
2262+# Get OB number
2263+OB_NUM=`hostname | cut -c 10- -`
2264+
2265+# AMT Password
2266+AMT_PASSWORD=Password1+
2267+
2268+# Remmina password
2269+REMMINA_PASSWORD=Ubuntu1+
2270+
2271+# Main internal interface IP
2272+IP_ROOT=172.27
2273+INTERNAL1_IP=$IP_ROOT.${OB_NUM}.1
2274+
2275+# Set MAAS URL
2276+MAAS_URL=http://$INTERNAL1_IP/MAAS
2277+
2278+# Check how we were called
2279+check_for_root(){
2280+ local -i retval=0
2281+ if [ "$(id -u)" != "0" ]; then
2282+ local -i retval=1
2283+ fi
2284+ return $retval
2285+}
2286+
2287+# MAAS specific config
2288+# We only call these if MAAS is installed and configured
2289+if dpkg -l | grep maas >/dev/null; then
2290+ # Get MAAS cluster uuid
2291+ if check_for_root; then
2292+ CLUSTER_UUID=`grep cluster_uuid /etc/maas/rackd.conf |awk '{print $2}'`
2293+ fi
2294+ # Get MAAS API key - export it as we need it outside this shell
2295+ # FIXME this is fairly horrible, we need it in the juju setup script
2296+ if sudo maas-region apikey --username admin 1>/dev/null 2>&1; then
2297+ export API_KEY=`sudo maas-region apikey --username admin | tail -n1`
2298+ fi
2299+fi
2300+# Login to MAAS
2301+login_to_maas(){
2302+ echo "Attempting to login to MAAS"
2303+ if maas login admin $MAAS_URL $API_KEY; then
2304+ local -i retval=0
2305+ echo "Login successful"
2306+ return $retval
2307+ else
2308+ local -i $retval=1
2309+ echo "Could not login to MAAS"
2310+ # No point in going on so bail out
2311+ exit $retval
2312+ fi
2313+}
2314
2315=== added file 'scripts/obinstaller.sh'
2316--- scripts/obinstaller.sh 1970-01-01 00:00:00 +0000
2317+++ scripts/obinstaller.sh 2017-04-25 19:02:06 +0000
2318@@ -0,0 +1,67 @@
2319+#!/bin/bash
2320+
2321+source ob_profile.sh
2322+
2323+if ! check_for_root; then
2324+ echo "ERROR: This script must be run as root"
2325+ exit 1
2326+fi
2327+
2328+if [ -f $LOG_FILE ]; then
2329+ rm $LOG_FILE
2330+ touch $LOG_FILE
2331+ chmod a+rw $LOG_FILE
2332+fi
2333+
2334+log_output(){
2335+ echo $1 | tee -a $LOG_FILE
2336+}
2337+
2338+log_output "Starting OrangeBox install for $(hostname) on $(date)"
2339+
2340+log_output "Configuring networks"
2341+if ./setup_network.sh | tee -a $LOG_FILE; then
2342+ echo "Network configuration completed"
2343+fi
2344+
2345+log_output "Installing base system"
2346+if ./install_base_system.sh | tee -a $LOG_FILE; then
2347+ log_output "Base system installation completed"
2348+fi
2349+
2350+log_output "Configuring base system"
2351+if ./setup_base_system.sh | tee -a $LOG_FILE; then
2352+ log_output "Base system configuration completed"
2353+fi
2354+
2355+log_output "Configuring Apache"
2356+if ./setup_apache.sh | tee -a $LOG_FILE; then
2357+ log_output "Apache configuration completed"
2358+fi
2359+
2360+log_output "Configuring MAAS"
2361+if ./setup_maas_environment.sh | tee -a $LOG_FILE; then
2362+ log_output "MAAS configuration completed"
2363+fi
2364+
2365+log_output "Configuring physical hosts"
2366+if ./add_physical_nodes.sh | tee -a $LOG_FILE; then
2367+ log_output "Physical host configuration completed"
2368+else
2369+ echo "ERROR: Unable to configure physical hosts"
2370+ exit 1
2371+fi
2372+
2373+
2374+log_output "Configuring virtual hosts"
2375+if ./add_virtual_nodes.sh | tee -a $LOG_FILE; then
2376+ log_output "Virtual host configuration completed"
2377+else
2378+ echo "ERROR: Unable to configure virtual hosts"
2379+ exit 1
2380+fi
2381+
2382+log_output "Configuring Juju"
2383+if sudo -Eu ubuntu ./setup_juju_environment.sh | tee -a $LOG_FILE; then
2384+ log_output "Juju configuration completed"
2385+fi
2386
2387=== added file 'scripts/setup_apache.sh'
2388--- scripts/setup_apache.sh 1970-01-01 00:00:00 +0000
2389+++ scripts/setup_apache.sh 2017-04-25 19:02:06 +0000
2390@@ -0,0 +1,52 @@
2391+#!/bin/bash
2392+#
2393+# Setup of OrangeBox network
2394+# Copyright (C) 2014 Canonical Ltd.
2395+#
2396+# Authors: Scott Croft <scott@canonical.com>
2397+#
2398+# This program is free software: you can redistribute it and/or modify
2399+# it under the terms of the GNU General Public License as published by
2400+# the Free Software Foundation, version 3 of the License.
2401+#
2402+# This program is distributed in the hope that it will be useful,
2403+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2404+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2405+# GNU General Public License for more details.
2406+#
2407+# You should have received a copy of the GNU General Public License
2408+# along with this program. If not, see <http://www.gnu.org/licenses/>.
2409+#
2410+#
2411+
2412+# script to configure apache
2413+#
2414+# set -e
2415+# set -x
2416+
2417+source ob_profile.sh
2418+
2419+# Configure apache so that the base URL reaches MAAS
2420+setup_apache() {
2421+
2422+ mkdir -p /srv/mirrors/archive.ubuntu.com
2423+ echo '<meta http-equiv="refresh" content="0; url=MAAS/">' > /srv/mirrors/archive.ubuntu.com/index.html
2424+ invoke-rc.d apache2 stop || true
2425+ invoke-rc.d apache2 start
2426+
2427+}
2428+
2429+main(){
2430+
2431+ echo "Configuring Apache for MAAS"
2432+
2433+ if ! check_for_root; then
2434+ echo "ERROR: This script needs to be run as root"
2435+ exit 1
2436+ fi
2437+
2438+ setup_apache
2439+
2440+}
2441+
2442+main "$@"
2443
2444=== added file 'scripts/setup_base_system.sh'
2445--- scripts/setup_base_system.sh 1970-01-01 00:00:00 +0000
2446+++ scripts/setup_base_system.sh 2017-04-25 19:02:06 +0000
2447@@ -0,0 +1,181 @@
2448+#!/bin/bash
2449+#
2450+# Base system configuration for the OrangeBox
2451+# Copyright (C) 2016 Canonical Ltd.
2452+#
2453+# Authors: Scott Croft <scott@canonical.com>
2454+# Matt Jarvis <matt.jarvis@canonical.com>
2455+#
2456+# This program is free software: you can redistribute it and/or modify
2457+# it under the terms of the GNU General Public License as published by
2458+# the Free Software Foundation, version 3 of the License.
2459+#
2460+# This program is distributed in the hope that it will be useful,
2461+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2462+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2463+# GNU General Public License for more details.
2464+#
2465+# You should have received a copy of the GNU General Public License
2466+# along with this program. If not, see <http://www.gnu.org/licenses/>.
2467+#
2468+#
2469+# set -e
2470+# set -x
2471+
2472+# FIXME this could be split out into package related and other config
2473+
2474+source ob_profile.sh
2475+
2476+KEYS_LIST=../LP_USERS.list
2477+
2478+usage()
2479+{
2480+cat << EOF
2481+usage: $0 options
2482+
2483+This script configures the base system
2484+Can also be used to update the authorized keys if the list has changed
2485+
2486+OPTIONS:
2487+ -h Show this message
2488+ -k Update authorized keys only
2489+EOF
2490+}
2491+
2492+# Check to ensure that the user on the system is ubuntu and assigned the uid of 1000
2493+check_ubuntu_user(){
2494+
2495+ if [ "$(id -u ubuntu)" != "1000" ]; then
2496+ return 1
2497+ fi
2498+
2499+}
2500+
2501+# Configure the SSH service
2502+configure_ssh(){
2503+
2504+ # Disable remote password authentication for security purposes
2505+ if ! grep -qs "^PasswordAuthentication no" /etc/ssh/sshd_config; then
2506+ echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
2507+ invoke-rc.d ssh stop || true
2508+ invoke-rc.d ssh start
2509+ fi
2510+
2511+}
2512+
2513+# Setup SSH for the ubuntu user
2514+setup_ubuntu_ssh(){
2515+
2516+ # Ensure the ubuntu user has an SSH key
2517+ if [ ! -e /home/ubuntu/.ssh/id_rsa ]; then
2518+ su -l ubuntu -c "ssh-keygen -N '' -f /home/ubuntu/.ssh/id_rsa"
2519+ fi
2520+ # Install SSH client config
2521+ install -o ubuntu -g ubuntu -m 0600 template/ssh_config ~ubuntu/.ssh/config
2522+
2523+}
2524+
2525+install_keys(){
2526+
2527+ local -i retval=0
2528+ local -i errors=0
2529+ authorized_keys=/home/ubuntu/.ssh/authorized_keys
2530+ if [ -e $authorized_keys ]; then
2531+ mv $authorized_keys $authorized_keys.old
2532+ fi
2533+
2534+ # Ignore blank lines and bash style comments
2535+ egrep -v '^$|^#' $KEYS_LIST | while read -r user; do
2536+ # shellcheck disable=SC2030
2537+ su -l ubuntu -c "ssh-import-id ${user}" || ((errors++))
2538+ done
2539+
2540+ # Install the user listed in the profile configuration
2541+ # shellcheck disable=SC2031
2542+ su -l ubuntu -c "ssh-import-id ${LAUNCHPAD_ID}" || ((errors++))
2543+
2544+ if [ $errors -ne 0 ]; then
2545+ local -i retval=1
2546+ fi
2547+ return $retval
2548+
2549+}
2550+
2551+setup_landscape() {
2552+
2553+ # The master node will be managed by Landscape
2554+ # FIXME - this appears to fail with invalid account name or registration key - expected behaviour ?
2555+ if which landscape-config; then
2556+ case "$(hostname)" in
2557+ OrangeBox*|orangebox*)
2558+ landscape-config -a cpe-sa -t "$(hostname)__$(dmidecode -s baseboard-serial-number)" --script-users=ALL --silent --include-manager-plugins=ScriptExecution || true
2559+ ;;
2560+ esac
2561+ fi
2562+
2563+}
2564+
2565+disable_crash_reporter(){
2566+
2567+ # Disable Ubuntu crash reporter
2568+ echo "enabled=0" | sudo tee /etc/default/apport
2569+
2570+ # Stop Ubuntu crash reporter
2571+ sudo invoke-rc.d apport stop || true
2572+
2573+}
2574+
2575+
2576+main(){
2577+
2578+ if ! check_for_root; then
2579+ echo "ERROR: this script must be run as root"
2580+ fi
2581+
2582+ if ! check_ubuntu_user; then
2583+ echo "ERROR: OrangeBox setup requires the default user to be [ubuntu]"
2584+ exit 1
2585+ fi
2586+
2587+ # No arguments given - use default PPA's
2588+ if (($# != 0)); then
2589+ while getopts "hk" OPTION
2590+ do
2591+ case $OPTION in
2592+ h)
2593+ usage
2594+ exit 0
2595+ ;;
2596+ k)
2597+ echo "Updating authorized keys"
2598+ install_keys
2599+ exit 0
2600+ ;;
2601+ \?)
2602+ usage
2603+ exit 1
2604+ ;;
2605+ esac
2606+ done
2607+ fi
2608+
2609+ echo "Configuring SSH daemon"
2610+ configure_ssh
2611+
2612+ echo "Configuring SSH for the ubuntu user"
2613+ setup_ubuntu_ssh
2614+
2615+ echo "Configuring Landscape"
2616+ setup_landscape
2617+
2618+ echo "Disabling crash reporter"
2619+ disable_crash_reporter
2620+
2621+ echo "Installing additional authorized keys"
2622+ if ! install_keys; then
2623+ echo "Some keys could not be installed"
2624+ fi
2625+
2626+}
2627+
2628+main "$@"
2629
2630=== added file 'scripts/setup_juju_environment.sh'
2631--- scripts/setup_juju_environment.sh 1970-01-01 00:00:00 +0000
2632+++ scripts/setup_juju_environment.sh 2017-04-25 19:02:06 +0000
2633@@ -0,0 +1,179 @@
2634+#!/bin/bash
2635+
2636+#set -e
2637+#set -x
2638+
2639+source ob_profile.sh
2640+
2641+MAAS_JUJU_NAME=maas-controller
2642+
2643+setup_juju_1(){
2644+
2645+ mkdir -p /home/ubuntu/.juju
2646+ cat >/home/ubuntu/.juju/environments.yaml <<EOF
2647+default: maas
2648+environments:
2649+ maas:
2650+ type: maas
2651+ maas-server: '${MAAS_URL}'
2652+ maas-oauth: '${API_KEY}'
2653+ default-series: trusty
2654+ #enable-os-upgrade: false
2655+ authorized-keys-path: /home/ubuntu/.ssh/id_rsa.pub
2656+ admin-secret: 'admin'
2657+ logging-config: '<root>=DEBUG'
2658+ lxc-clone: true
2659+EOF
2660+ echo "export JUJU_DEV_FEATURE_FLAGS=maas2" >> /home/ubuntu/.bashrc
2661+
2662+}
2663+
2664+setup_juju_2(){
2665+
2666+ maas_yaml=/home/ubuntu/.juju/juju_maas.yaml
2667+ cat >$maas_yaml<<EOF
2668+clouds:
2669+ $MAAS_JUJU_NAME:
2670+ type: maas
2671+ auth-types: [oauth1]
2672+ endpoint: $MAAS_URL
2673+credentials:
2674+ $MAAS_JUJU_NAME:
2675+ admin:
2676+ auth-type: oauth1
2677+ maas-oauth: $API_KEY
2678+EOF
2679+ if ! juju list-clouds | grep -q maas; then
2680+ juju add-cloud $MAAS_JUJU_NAME $maas_yaml
2681+ juju add-credential $MAAS_JUJU_NAME -f $maas_yaml
2682+ fi
2683+
2684+}
2685+
2686+bootstrap_juju_2(){
2687+ juju update-clouds
2688+ if juju bootstrap --to node00vm0ob"${OB_NUM}".maas --show-log $MAAS_JUJU_NAME maas/"${INTERNAL1_IP}"
2689+ then
2690+ juju show-controller --show-password maas/"${INTERNAL1_IP}" | egrep "user|password"
2691+ URL=$(juju gui --no-browser)
2692+ # Start Chromium with flags to ignore certificate errors and avoid pop up complaining about ignoring them
2693+ chromium-browser --ignore-certificate-errors --test-type "$URL"
2694+ fi
2695+}
2696+
2697+install_juju_plugins(){
2698+
2699+ plugin_path=/home/ubuntu/.juju-plugins
2700+ rm -rf $plugin_path
2701+ git clone https://github.com/juju/plugins $plugin_path
2702+ echo "PATH=\$PATH:${plugin_path}:/home/ubuntu/Examples/bin" >> /home/ubuntu/.bashrc
2703+
2704+}
2705+
2706+setup_desktop() {
2707+
2708+ # connect running session bus if any
2709+ dbus_session_bus_address=$(pgrep -u "$USER" -af 'dbus-daemon --fork --session' | grep -o 'unix:.*' || true)
2710+ if [ -n "$dbus_session_bus_address" ]; then
2711+ env DBUS_SESSION_BUS_ADDRESS="$dbus_session_bus_address" \
2712+ dconf load / < ../template/dconf.txt
2713+ else
2714+ dbus-launch dconf load / < ../template/dconf.txt
2715+ fi
2716+
2717+}
2718+
2719+install_demos(){
2720+
2721+ if [[ -d /srv/sademos-15.10 ]]; then
2722+ cd /srv/sademos-15.10 || exit 1
2723+ bzr pull
2724+ else
2725+ bzr branch lp:sademos /srv/sademos-15.10
2726+ fi
2727+ if [[ -d /srv/sademos-16.04 ]]; then
2728+ cd /srv/sademos-16.04 || exit 1
2729+ bzr pull
2730+ else
2731+ bzr branch lp:sademos/16.04 /srv/sademos-16.04
2732+ fi
2733+
2734+ ln -s /srv/sademos-16.04 /home/ubuntu/sademos-juju2 >/dev/null 2>&1
2735+ ln -s /srv/sademos-15.10 /home/ubuntu/sademos-juju1.25 >/dev/null 2>&1
2736+
2737+}
2738+
2739+setup_remmina() {
2740+
2741+ if [[ -d /home/ubuntu/.remmina ]]; then
2742+ echo "Remmina already setup"
2743+ else
2744+ echo "Setting up Remmina..."
2745+ mkdir /home/ubuntu/.remmina
2746+ for node_num in {1..10}
2747+ do
2748+ cat >/home/ubuntu/.remmina/node${node_num}.remmina <<EOF
2749+[remmina]
2750+keymap=
2751+ssh_auth=0
2752+quality=0
2753+disableencryption=0
2754+ssh_charset=
2755+ssh_privatekey=
2756+server=${IP_ROOT}.${OB_NUM}.$((node_num + 10))
2757+hscale=0
2758+group=
2759+password=${REMMINA_PASSWORD}
2760+name=node${node_num}
2761+ssh_loopback=0
2762+viewonly=0
2763+ssh_username=
2764+ssh_server=
2765+window_maximize=0
2766+aspectscale=0
2767+protocol=VNC
2768+window_height=825
2769+window_width=963
2770+vscale=0
2771+ssh_enabled=0
2772+username=admin
2773+showcursor=0
2774+disableserverinput=0
2775+colordepth=8
2776+disableclipboard=0
2777+viewmode=1
2778+EOF
2779+ done
2780+ chown -R ubuntu:ubuntu /home/ubuntu/.remmina
2781+ fi
2782+
2783+}
2784+
2785+main(){
2786+
2787+ if check_for_root; then
2788+ echo "ERROR: This script needs to be run as the ubuntu user"
2789+ exit 1
2790+ fi
2791+
2792+ echo "Adding configuration for Juju 1.x"
2793+ setup_juju_1
2794+
2795+ echo "Adding configuration for Juju 2.x"
2796+ setup_juju_2
2797+
2798+ echo "Configuring desktop"
2799+ setup_desktop
2800+
2801+ echo "Configuring Remmina"
2802+ setup_remmina
2803+
2804+ echo "Installing demos"
2805+ install_demos
2806+
2807+ echo "Bootstrapping Juju 2"
2808+ bootstrap_juju_2
2809+
2810+}
2811+
2812+main "$@"
2813
2814=== added file 'scripts/setup_maas_environment.sh'
2815--- scripts/setup_maas_environment.sh 1970-01-01 00:00:00 +0000
2816+++ scripts/setup_maas_environment.sh 2017-04-25 19:02:06 +0000
2817@@ -0,0 +1,226 @@
2818+#!/bin/bash
2819+#
2820+# Setup of OrangeBox MAAS environment
2821+# Copyright (C) 2017 Canonical Ltd.
2822+#
2823+# Authors: Scott Croft <scott@canonical.com>
2824+# Matt Jarvis <matt.jarvis@canonical.com>
2825+#
2826+# This program is free software: you can redistribute it and/or modify
2827+# it under the terms of the GNU General Public License as published by
2828+# the Free Software Foundation, version 3 of the License.
2829+#
2830+# This program is distributed in the hope that it will be useful,
2831+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2832+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2833+# GNU General Public License for more details.
2834+#
2835+# You should have received a copy of the GNU General Public License
2836+# along with this program. If not, see <http://www.gnu.org/licenses/>.
2837+#
2838+#
2839+# set -ax
2840+
2841+source ob_profile.sh
2842+
2843+# Set ip's for MAAS configuration
2844+DHCP_OCTETS=$IP_ROOT.$((OB_NUM + 1))
2845+NETWORK_OCTETS=$IP_ROOT.$OB_NUM
2846+DHCP_SUBNET=$IP_ROOT.${OB_NUM}.0/23
2847+
2848+# Create MAAS dynamic range
2849+create_dynamic_range(){
2850+ local dhcp_low=$DHCP_OCTETS.1
2851+ local dhcp_high=$DHCP_OCTETS.20
2852+ local -i retval=0
2853+ if ! maas admin ipranges create type=dynamic start_ip="$dhcp_low" end_ip="$dhcp_high"; then
2854+ local -i retval=1
2855+ fi
2856+ return $retval
2857+}
2858+
2859+# Create MAAS admin credentials
2860+create_maas_credentials(){
2861+ if ! maas-region apikey --username admin 1>/dev/null 2>&1;then
2862+ if maas-region createadmin --username admin --email maas-admin@example.com --password="admin";then
2863+ local -i retval=0
2864+ else
2865+ local -i retval=1
2866+ fi
2867+ fi
2868+ return $retval
2869+}
2870+
2871+# Add SSH key to MAAS
2872+add_maas_ssh_key(){
2873+ maas admin sshkeys create key="$(cat /home/ubuntu/.ssh/id_rsa.pub)" || true
2874+}
2875+
2876+# Update http config
2877+# FIXME this seems to be doing the same as the 02-apache setup script for a different root, are both needed ?
2878+update_http_conf(){
2879+ cat >/var/www/html/index.html <<EOF
2880+ <meta http-equiv="refresh" content="0; url=/MAAS">
2881+EOF
2882+}
2883+
2884+# Update subnet settings
2885+update_subnet(){
2886+ local -i retval=0
2887+ local gateway_ip=$NETWORK_OCTETS.1
2888+ local dns_servers=$NETWORK_OCTETS.1
2889+ local subnet=$NETWORK_OCTETS.0/23
2890+ maas admin subnet update "$subnet" gateway_ip="$gateway_ip" dns_servers="$dns_servers" || local -i retval=1
2891+ return $retval
2892+}
2893+
2894+# Update DNS settings
2895+update_dns(){
2896+ local dns_ip=$DHCP_OCTETS.254
2897+ local -i retval=0
2898+ declare -Ag maas_dns_config=( ["upstream_dns"]="${dns_ip}" ["dnssec_validation"]="no" ["kernel_opts"]="net.ifnames=0" )
2899+ for config in "${!maas_dns_config[@]}"; do
2900+ echo "Setting ${config}"
2901+ maas admin maas set-config name="$config" value="${maas_dns_config[$config]}" || local -i retval=1
2902+ echo -e "\n"
2903+ done
2904+ sed -e 's/dnssec-validation auto;/dnssec-enable no;dnssec-validation no;/g' -i /etc/bind/named.conf.options
2905+ pkill -HUP named
2906+ return $retval
2907+}
2908+
2909+# Create required tags
2910+create_maas_tags(){
2911+ local -i retval=0
2912+ local -i errors=0
2913+ for tag in physical virtual neutron use-fastpath-installer; do
2914+ echo "Creating tag ${tag}"
2915+ maas admin tags create name=$tag || ((errors++))
2916+ echo -e "\n"
2917+ done
2918+ if [ $errors -ne 0 ]; then
2919+ local -i retval=1
2920+ fi
2921+ return $retval
2922+}
2923+
2924+# Configure DHCP
2925+configure_dhcp(){
2926+ maas admin subnets read | grep "\"id\"" | awk '{print $2}' | sed 's/,//' | egrep -x '.{1,2}' | while read -r subnet_id
2927+ do
2928+ if maas admin subnet read "$subnet_id" | grep "\"cidr\": \"${DHCP_SUBNET}\"" 1>/dev/null
2929+ then
2930+ maas_fabric=$(maas admin subnet read "$subnet_id" | grep -w fabric | awk '{print $2}' | sed 's/,//' | sed 's/\"//g')
2931+ maas admin vlan update "$maas_fabric" untagged dhcp_on=True primary_rack="OrangeBox${OB_NUM}"
2932+ fi
2933+ done
2934+}
2935+
2936+# Import boot images
2937+import_boot_images(){
2938+ local -i retval=0
2939+ local -i errors=0
2940+ for release in xenial trusty; do
2941+ if ! maas admin boot-source-selections read 1 | grep -q $release; then
2942+ maas admin boot-source-selections create 1 \
2943+ os="ubuntu" \
2944+ release="$release" \
2945+ arches="amd64" \
2946+ subarches="*" \
2947+ labels="*" || ((errors++))
2948+ fi
2949+ done
2950+ echo -e "\n"
2951+ if [ $errors -ne 0 ]; then
2952+ local -i retval=1
2953+ fi
2954+ maas admin boot-resources import
2955+ while [ "$(maas admin boot-resources read name="$CLUSTER_UUID" | wc -l)" -lt 10 ]; do
2956+ echo " Waiting for images to download"
2957+ sleep 10
2958+ done
2959+ return $retval
2960+}
2961+
2962+# Add zones to MAAS for NUC's
2963+add_zones(){
2964+ local -i retval=0
2965+ declare -A zone_config=( ["zone1"]="Physical machines 1-5" ["zone2"]="Physical machines 6-10" )
2966+ for zone in "${!zone_config[@]}"; do
2967+ if ! maas admin zone read "$zone" >/dev/null; then
2968+ maas admin zones create name="$zone" description="${zone_config[$zone]}" || local -i retval=1
2969+ fi
2970+ done
2971+ return $retval
2972+}
2973+
2974+add_maas_key_to_authkeys(){
2975+ authorized_keys=/home/ubuntu/.ssh/authorized_keys
2976+ if [ -e ~maas/.ssh/id_rsa.pub ]; then
2977+ cat ~maas/.ssh/id_rsa.pub >> $authorized_keys
2978+ fi
2979+}
2980+
2981+main(){
2982+
2983+ if ! check_for_root; then
2984+ echo "ERROR: This script must be run as root"
2985+ exit 1
2986+ fi
2987+
2988+ if ! create_maas_credentials; then
2989+ echo "ERROR Could not create MAAS credentials"
2990+ exit 1
2991+ else
2992+ # Source the profile again now the admin user exists
2993+ source ob_profile.sh
2994+ fi
2995+
2996+ login_to_maas
2997+ # Echo newlines after MAAS commands since the MAAS output doesn't properly newline
2998+ # purely for display purposes in the log file and terminal output
2999+ echo -e "\n"
3000+
3001+ echo "Configuring MAAS SSH keys"
3002+ add_maas_ssh_key
3003+ echo -e "\n"
3004+
3005+ echo "Creating dynamic range"
3006+ create_dynamic_range
3007+ echo -e "\n"
3008+
3009+ echo "Configuring DHCP"
3010+ configure_dhcp
3011+ echo -e "\n"
3012+
3013+ echo "Updating subnet"
3014+ update_subnet
3015+ echo -e "\n"
3016+
3017+ update_http_conf
3018+
3019+ echo "Updating DNS"
3020+ update_dns
3021+ echo -e "\n"
3022+
3023+ echo "Importing boot images"
3024+ if ! import_boot_images; then
3025+ echo "Could not import all required boot images"
3026+ fi
3027+ echo -e "\n"
3028+
3029+ echo "Adding zones"
3030+ add_zones
3031+ echo -e "\n"\
3032+
3033+ echo "Adding tags"
3034+ if ! create_maas_tags; then
3035+ echo "Could not create all required tags"
3036+ fi
3037+ echo -e "\n"
3038+
3039+ add_maas_key_to_authkeys
3040+
3041+}
3042+
3043+main "$@"
3044
3045=== added file 'scripts/setup_network.sh'
3046--- scripts/setup_network.sh 1970-01-01 00:00:00 +0000
3047+++ scripts/setup_network.sh 2017-04-25 19:02:06 +0000
3048@@ -0,0 +1,239 @@
3049+#!/bin/bash
3050+#
3051+# Setup of OrangeBox network
3052+# Copyright (C) 2014 Canonical Ltd.
3053+#
3054+# Authors: Dustin Kirkland <kirkland@canonical.com>
3055+# Scott Croft <scott@canonical.com>
3056+# Matt Jarvis <matt.jarvis@canonical.com>
3057+#
3058+# This program is free software: you can redistribute it and/or modify
3059+# it under the terms of the GNU General Public License as published by
3060+# the Free Software Foundation, version 3 of the License.
3061+#
3062+# This program is distributed in the hope that it will be useful,
3063+# but WITHOUT ANY WARRANTY; without even the implied warranty of
3064+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3065+# GNU General Public License for more details.
3066+#
3067+# You should have received a copy of the GNU General Public License
3068+# along with this program. If not, see <http://www.gnu.org/licenses/>.
3069+#
3070+#
3071+# set -e
3072+# set -x
3073+
3074+source ob_profile.sh
3075+
3076+GATEWAY1_IP=$IP_ROOT.$((OB_NUM+1)).254
3077+INTERNAL2_IP=$IP_ROOT.$((OB_NUM+2)).1
3078+
3079+# Populate the OrangeBox config file
3080+set_orange_box_config(){
3081+ echo "orangebox_number=${OB_NUM}" > /etc/orange-box.conf
3082+}
3083+
3084+# Install bridge-utils packages
3085+install_bridge_packages(){
3086+ local -i retval=0
3087+ if ! dpkg -l | grep -q bridge-utils; then
3088+ if apt-get update; then
3089+ if ! apt-get install -y bridge-utils; then
3090+ local -i retval=1
3091+ fi
3092+ else
3093+ local -i retval=1
3094+ fi
3095+ fi
3096+ return $retval
3097+}
3098+
3099+# Get interface names of the 3 interfaces on node0 since in Xenial they aren't ethX anymore
3100+# See https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
3101+# An array is declared and the interface names are placed into the array to be used later on
3102+create_interface_array(){
3103+ echo "Detecting network interfaces"
3104+ # Arrays in functions need to be declared explicitly as a global
3105+ declare -g INTERFACE=()
3106+ for iface in $(ip a | awk '{print $2}' | egrep 'enp|enx' | sed 's/://'); do
3107+ echo "Found interface $iface"
3108+ INTERFACE=("${INTERFACE[@]}" "$iface")
3109+ done
3110+ echo "Interface detection complete ${INTERFACE[*]}"
3111+}
3112+
3113+# Check to make sure the OrangeBox number is divisable by 4 to ensure the network is setup correctly
3114+check_orangebox_number() {
3115+ local num=$1
3116+ local -i retval=0
3117+ if [[ $((num/4)) -lt 1 ]]; then
3118+ local -i retval=1
3119+ fi
3120+ return $retval
3121+}
3122+
3123+# Set required kernel parameters for MAAS
3124+set_sysctls(){
3125+ for sysctl in "net.ipv4.ip_forward=1" "net.ipv4.conf.all.accept_redirects=1"; do
3126+ if ! grep -qx $sysctl /etc/sysctl.conf; then
3127+ echo $sysctl >> /etc/sysctl.conf
3128+ fi
3129+ done
3130+}
3131+
3132+# Check which interface is on which bridge-vlan
3133+check_interface_vlan(){
3134+ local -i retval=0
3135+ if ifconfig "${INTERFACE[1]}" "$INTERNAL1_IP"/23; then
3136+ if ping -c 1 $GATEWAY1_IP >/dev/null
3137+ then
3138+ INTERNAL1_IF=${INTERFACE[1]}
3139+ INTERNAL2_IF=${INTERFACE[2]}
3140+ else
3141+ INTERNAL1_IF=${INTERFACE[2]}
3142+ INTERNAL2_IF=${INTERFACE[1]}
3143+ fi
3144+ else
3145+ echo "Unable to configure ${INTERFACE[1]}"
3146+ local -i retval=1
3147+ fi
3148+ ip addr flush dev "$INTERNAL1_IF"
3149+ return $retval
3150+}
3151+
3152+# Check external network connectivity
3153+check_networking(){
3154+ if ping -c 3 8.8.8.8 >/dev/null; then
3155+ echo "Networking appears to be working correctly"
3156+ local -i retval=0
3157+ else
3158+ echo "ERROR: Networking is not working correctly"
3159+ local -i retval=1
3160+ fi
3161+ return $retval
3162+}
3163+
3164+# Check DNS resolution
3165+check_dns(){
3166+ if ping -c 3 google.com >/dev/null; then
3167+ echo "DNS appears to be working correctly"
3168+ local -i retval=0
3169+ else
3170+ echo "ERROR: DNS is not working correctly"
3171+ echo "Check /etc/resolv.conf and try ifdown/ifup br0/br1 interfaces"
3172+ local -i retval=1
3173+ fi
3174+ return $retval
3175+}
3176+
3177+generate_network_interfaces(){
3178+ cat >/etc/network/interfaces <<-EOF
3179+#These are generated by orange-box build scripts
3180+auto lo
3181+iface lo inet loopback
3182+
3183+auto ${INTERFACE[0]}
3184+iface ${INTERFACE[0]} inet manual
3185+
3186+auto $INTERNAL1_IF
3187+iface $INTERNAL1_IF inet manual
3188+
3189+auto $INTERNAL2_IF
3190+iface $INTERNAL2_IF inet manual
3191+
3192+auto br0
3193+iface br0 inet static
3194+ address $INTERNAL1_IP
3195+ netmask 255.255.254.0
3196+ gateway $GATEWAY1_IP
3197+ dns-nameservers $INTERNAL1_IP $GATEWAY1_IP
3198+ bridge_ports $INTERNAL1_IF
3199+ bridge_stp off
3200+ bridge_fd 0
3201+ bridge_maxwait 0
3202+
3203+auto br1
3204+iface br1 inet static
3205+ address $INTERNAL2_IP
3206+ netmask 255.255.254.0
3207+ bridge_ports $INTERNAL2_IF
3208+ bridge_stp off
3209+ bridge_fd 0
3210+ bridge_maxwait 0
3211+EOF
3212+}
3213+
3214+# Disable NetworkManager
3215+disable_network_manager(){
3216+ systemctl stop NetworkManager >/dev/null 2>&1
3217+ systemctl disable NetworkManager >/dev/null 2>&1
3218+}
3219+
3220+# Restart all network interfaces
3221+restart_interfaces(){
3222+ for iface in ${INTERFACE[0]} $INTERNAL1_IF $INTERNAL2_IF; do
3223+ ifdown --force "$iface"
3224+ done
3225+
3226+ for iface in $INTERNAL1_IF $INTERNAL2_IF br0 br1; do
3227+ ifup --force "$iface"
3228+ done
3229+}
3230+
3231+main(){
3232+
3233+ if ! check_for_root; then
3234+ echo "ERROR: This script must be run as root"
3235+ exit 1
3236+ fi
3237+
3238+ echo "Creating OrangeBox configuration file"
3239+ set_orange_box_config
3240+
3241+ echo "Checking required packages"
3242+ if ! install_bridge_packages; then
3243+ echo "Could not install bridge-utils packages"
3244+ exit 1
3245+ fi
3246+
3247+ create_interface_array
3248+
3249+ echo "Setting kernel parameters"
3250+ set_sysctls
3251+
3252+ # Sanity check that the OrangeBox number is correct before configuring networks
3253+ if ! check_orangebox_number "$OB_NUM"; then
3254+ echo "ERROR Your hostname should in the format of OrangeBox??: ex OrangeBox56"
3255+ exit 1
3256+ fi
3257+
3258+ echo "Checking VLAN configuration"
3259+ if ! check_interface_vlan; then
3260+ echo "ERROR Could not configure interfaces for initial tests"
3261+ exit 1
3262+ fi
3263+
3264+ echo "Disabling NetworkManager"
3265+ disable_network_manager
3266+
3267+ echo "Generating network interfaces file"
3268+ generate_network_interfaces
3269+
3270+ echo "Restarting networking"
3271+ restart_interfaces
3272+
3273+ echo "Checking network function"
3274+ if ! check_networking; then
3275+ exit 1
3276+ fi
3277+
3278+ echo "Checking DNS resolution"
3279+ if ! check_dns; then
3280+ exit 1
3281+ fi
3282+
3283+ exit 0
3284+
3285+}
3286+
3287+main "$@"
3288
3289=== added file 'scripts/verify.sh'
3290--- scripts/verify.sh 1970-01-01 00:00:00 +0000
3291+++ scripts/verify.sh 2017-04-25 19:02:06 +0000
3292@@ -0,0 +1,78 @@
3293+#!/bin/bash
3294+
3295+set -e
3296+set -u
3297+
3298+BIOS_PREFIX=MYBDWi5v.86A.
3299+USERNAME=ubuntu
3300+HOSTNAME_REGEX='OrangeBox[0-9][0-9]'
3301+
3302+source ob_profile.sh
3303+
3304+ERROR=
3305+log() {
3306+ type=$1
3307+ format=$2
3308+ shift 2
3309+ case $type in
3310+ error)
3311+ printf '\e[1;31mERROR:\e[0m '
3312+ # shellcheck disable=SC2059
3313+ printf "${format}\n" "$@"
3314+ ERROR=1
3315+ ;;
3316+ warn)
3317+ printf '\e[1;33mWARNING:\e[0m '
3318+ # shellcheck disable=SC2059
3319+ printf "${format}\n" "$@"
3320+ ;;
3321+ info)
3322+ printf '\e[0;32mINFO:\e[0m '
3323+ # shellcheck disable=SC2059
3324+ printf "${format}\n" "$@"
3325+ ;;
3326+ *)
3327+ echo 'log: unknown type specified.'
3328+ exit 1
3329+ ;;
3330+ esac
3331+}
3332+
3333+check_bios_revision() {
3334+ bios_version=$(sudo dmidecode -s bios-version | cut -d' ' -f2)
3335+ bios_revision=${bios_version#$BIOS_PREFIX}
3336+ bios_revision=${bios_revision%%.*}
3337+
3338+ if [ "$bios_revision" = "$TESTED_BIOS_REVISION" ]; then
3339+ log info 'You have the tested BIOS revision - %s' "$TESTED_BIOS_REVISION"
3340+ else
3341+ log warn 'The current tested BIOS revision is %s, but you have revision %s' "$TESTED_BIOS_REVISION" "$bios_revision"
3342+ fi
3343+}
3344+
3345+check_hostname() {
3346+ if echo "$HOSTNAME" | egrep -q "^${HOSTNAME_REGEX}$"; then
3347+ log info 'hostname is OK - %s' "$HOSTNAME"
3348+ else
3349+ log error 'hostname must meet the regex "%s"' "$HOSTNAME_REGEX"
3350+ fi
3351+}
3352+
3353+check_username() {
3354+ if [ "$USER" = "$USERNAME" ]; then
3355+ log info 'username is OK - %s' "$USERNAME"
3356+ else
3357+ log error 'username must be "%s"' "$USERNAME"
3358+ fi
3359+}
3360+
3361+# get sudo permission
3362+sudo true
3363+
3364+check_bios_revision
3365+check_hostname
3366+check_username
3367+
3368+if [ "$ERROR" = 1 ]; then
3369+ exit 1
3370+fi
3371
3372=== added file 'template/archive.conf'
3373--- template/archive.conf 1970-01-01 00:00:00 +0000
3374+++ template/archive.conf 2017-04-25 19:02:06 +0000
3375@@ -0,0 +1,13 @@
3376+<VirtualHost *:80>
3377+ ServerName archive.ubuntu.com
3378+ ServerAdmin webmaster@localhost
3379+ DocumentRoot /srv/mirrors/archive.ubuntu.com/
3380+ ErrorLog ${APACHE_LOG_DIR}/error.log
3381+ CustomLog ${APACHE_LOG_DIR}/access.log combined
3382+ <Directory /srv/mirrors/archive.ubuntu.com/>
3383+ Options Indexes FollowSymLinks Multiviews
3384+ Require all granted
3385+ </Directory>
3386+</VirtualHost>
3387+
3388+# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
3389
3390=== added file 'template/ubuntu-cloud.conf'
3391--- template/ubuntu-cloud.conf 1970-01-01 00:00:00 +0000
3392+++ template/ubuntu-cloud.conf 2017-04-25 19:02:06 +0000
3393@@ -0,0 +1,12 @@
3394+<VirtualHost *:80>
3395+ ServerName ubuntu-cloud.archive.canonical.com
3396+ ServerAdmin webmaster@localhost
3397+ DocumentRoot /srv/mirrors/ubuntu-cloud.archive.canonical.com/
3398+ ErrorLog ${APACHE_LOG_DIR}/error.log
3399+ CustomLog ${APACHE_LOG_DIR}/access.log combined
3400+ <Directory /srv/mirrors/ubuntu-cloud.archive.canonical.com/>
3401+ Options Indexes FollowSymLinks Multiviews
3402+ Require all granted
3403+ </Directory>
3404+</VirtualHost>
3405+# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
3406
3407=== removed file 'ubuntu-cloud.conf'
3408--- ubuntu-cloud.conf 2016-05-19 22:40:57 +0000
3409+++ ubuntu-cloud.conf 1970-01-01 00:00:00 +0000
3410@@ -1,12 +0,0 @@
3411-<VirtualHost *:80>
3412- ServerName ubuntu-cloud.archive.canonical.com
3413- ServerAdmin webmaster@localhost
3414- DocumentRoot /srv/mirrors/ubuntu-cloud.archive.canonical.com/
3415- ErrorLog ${APACHE_LOG_DIR}/error.log
3416- CustomLog ${APACHE_LOG_DIR}/access.log combined
3417- <Directory /srv/mirrors/ubuntu-cloud.archive.canonical.com/>
3418- Options Indexes FollowSymLinks Multiviews
3419- Require all granted
3420- </Directory>
3421-</VirtualHost>
3422-# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Subscribers

People subscribed via source and target branches

to all changes: