~hp-moonshot/ubuntu/trusty/hp-moonshot/hp-proliant

« back to all changes in this revision

Viewing changes to usr/bin/hp-proliant-add-virtual-nodes

  • Committer: Narinder Gupta
  • Date: 2014-09-04 20:37:03 UTC
  • Revision ID: narinder.gupta@canonical.com-20140904203703-2sk67uwbzk9fc4tk
branch a new version for HP proliant systems where there is no power management required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
#    hp-proliant-add-virtual-nodes - create some virtual machines
 
4
#    Copyright (C) 2014 Canonical Ltd.
 
5
#
 
6
#    Authors: Ronald McCollam <ronald.mccollam@canonical.com>
 
7
#             Dustin Kirkland <kirkland@canonical.com>
 
8
#             Kent Baxley <kent.baxley@canonical.com>
 
9
#    This program is free software: you can redistribute it and/or modify
 
10
#    it under the terms of the GNU General Public License as published by
 
11
#    the Free Software Foundation, version 3 of the License.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 
 
21
 
 
22
if [ "$(id -u)" != "0" ]; then
 
23
  echo "Must be run with sudo or by root"
 
24
  exit 77
 
25
fi
 
26
 
 
27
set -e
 
28
set -x
 
29
 
 
30
if [ -f /etc/hp-proliant.conf ]; then
 
31
        PREFIX=$(awk -F '[:]' NR==1'{print $3"."$4}' /etc/hp-proliant.conf)
 
32
else
 
33
        PREFIX="10.14"
 
34
fi
 
35
 
 
36
virsh net-info default && virsh net-destroy default && virsh net-undefine default
 
37
 
 
38
[ -d /home/maas ] || install -d /home/maas --owner maas --group maas
 
39
chsh maas -s /bin/bash
 
40
[ -d /home/maas/.ssh ] || echo -e "\n\n\n" | sudo -u maas ssh-keygen -N "" -t rsa -f /home/maas/.ssh/id_rsa
 
41
grep 'maas@' /home/ubuntu/.ssh/authorized_keys || cat /home/maas/.ssh/id_rsa.pub | tee -a /home/ubuntu/.ssh/authorized_keys
 
42
printf "%s,%s %s %s\n" "moonshot-maas.maas" "${PREFIX}.4.1" $(awk '{print $1 " " $2}' /etc/ssh/ssh_host_ecdsa_key.pub) | tee -a /home/maas/.ssh/known_hosts
 
43
chown -R ubuntu:ubuntu /home/ubuntu
 
44
 
 
45
maas admin tags new name=virtual || true
 
46
maas admin tags new name=bootstrap || true
 
47
maas admin tags new name=neutron || true
 
48
maas admin tags new name='use-fastpath-installer' comment='fp' "definition=true()" || true
 
49
 
 
50
hostname="moonshotvm.maas"
 
51
virsh destroy $hostname || true
 
52
virsh undefine $hostname || true
 
53
 
 
54
echo "INFO: Installing virtual machine"
 
55
virt-install --name $hostname --ram 2048 --disk=path=/var/lib/hp-proliant/${hostname}.img,size=10 --vcpus=2 --os-type=linux --pxe --network=bridge=br0 --boot network || true
 
56
 
 
57
virsh console $hostname || true
 
58
virsh autostart $hostname
 
59
mac=$(virsh dumpxml $hostname | python -c 'import sys, lxml.etree; print list(lxml.etree.parse(sys.stdin).iter("mac"))[0].get("address")')
 
60
system_id=$(maas admin nodes list mac_address=$mac | grep system_id | cut -d'"' -f4)
 
61
 
 
62
if [ -n "$system_id" ]; then
 
63
 
 
64
    echo "DONE: VM creation done successfully"
 
65
else
 
66
    echo "ERROR: creating the VM lets try to start again"
 
67
    virsh start $hostname || true
 
68
    virsh console $hostname || true
 
69
    mac=$(virsh dumpxml $hostname | python -c 'import sys, lxml.etree; print list(lxml.etree.parse(sys.stdin).iter("mac"))[0].get("address")')
 
70
system_id=$(maas admin nodes list mac_address=$mac | grep system_id | cut -d'"' -f4)
 
71
 
 
72
fi
 
73
 
 
74
if [ -n "$system_id" ]; then
 
75
        maas admin node update $system_id hostname=$hostname power_type=virsh power_parameters_power_address=qemu+ssh://ubuntu@${PREFIX}.4.1/system power_parameters_power_id=$hostname
 
76
        maas admin tag update-nodes "virtual" add=$system_id
 
77
        maas admin tag update-nodes "bootstrap" add=$system_id
 
78
        maas admin tag update-nodes use-fastpath-installer add=$system_id
 
79
        maas admin node commission $system_id || true
 
80
        sleep 5
 
81
        virsh console $hostname || true
 
82
else
 
83
        echo "ERROR: Could not find virtual machine in MAAS" 1>&2
 
84
        exit 1
 
85
fi