The real run-thru version

This commit is contained in:
John Hua 2015-08-11 18:12:52 +08:00
parent 07e8c68e69
commit 99947819ed
5 changed files with 63 additions and 26 deletions

View File

@ -58,7 +58,7 @@ do
sshpass -p $XEN_PASSWORD ssh $XEN_ROOT@$HOST \
'
guest_name="'$NODE'"
vm_uuid=$(xe vm-list name-label="$guest_name" --minimal)
vm_uuid=$(xe vm-list name-label="$guest_name" power-state="halted" --minimal)
xe vm-start vm=$vm_uuid
echo "'$NODE' booted"
'

25
test_cluster_himn.sh Executable file
View File

@ -0,0 +1,25 @@
source localrc
for HOST_NODE in ${COMPUTE_NODES//,/ }
do
IFS=/ read -a _HOST_NODE <<< $HOST_NODE
HOST=${_HOST_NODE[0]}
NODE=${_HOST_NODE[1]}
eth2=$(sshpass -p $XEN_PASSWORD ssh $XEN_ROOT@$HOST \
'xe vm-list name-label="'$NODE'" params=networks --minimal | grep -o -P "(?<=0\/ip\:\s)(\d+\.\d+\.\d+\.\d+)"')
echo $HOST $NODE $eth2
sshpass -p $XEN_PASSWORD ssh $XEN_ROOT@$HOST \
'
set +x
route -n | grep -F 169.254.0
'
sshpass -p $FUELMASTER_PASSWORD ssh $FUELMASTER_ROOT@$FUELMASTER \
'
set +x
ssh '$eth2' iptables -S | grep eth2
'
done

View File

@ -20,14 +20,19 @@ XENAPI_URL = \
basicConfig(filename=LOG_FILE, level=DEBUG)
def execute(*cmd):
def execute(*cmd, **kwargs):
cmd = map(str, cmd)
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
out = proc.stdout.readlines()
err = proc.stderr.readlines()
(out, err, cmd) = map(' '.join, [out, err, cmd])
if 'prompt' in kwargs:
prompt = kwargs.get('prompt')
proc.stdout.flush()
(out, err) = proc.communicate(prompt)
cmd = ' '.join(cmd)
else:
out = proc.stdout.readlines()
err = proc.stderr.readlines()
(out, err, cmd) = map(' '.join, [out, err, cmd])
info(cmd)
if out:
@ -35,19 +40,21 @@ def execute(*cmd):
if err:
warning(err)
return (out, err, cmd)
return (out, err, cmd, proc)
def ssh(host, username, password, *cmd):
def ssh(host, username, password, *cmd, **kwargs):
cmd = map(str, cmd)
return execute('sshpass', '-p', password, 'ssh', '-o',
'StrictHostKeyChecking=no',
'%s@%s' % (username, host), *cmd)
return execute('sshpass', '-p', password, 'ssh',
'-o', 'StrictHostKeyChecking=no',
'%s@%s' % (username, host), *cmd,
prompt=kwargs.get('prompt'))
def scp(host, username, password, target_path, filename):
return execute('sshpass', '-p', '"%s"' % password, 'scp', filename,
return execute('sshpass', '-p', password, 'scp',
'-o', 'StrictHostKeyChecking=no', filename,
'%s@%s:%s' % (username, host, target_path))
@ -153,7 +160,7 @@ def restart_nova_services():
def route_to_compute(endpoints, himn_xs, himn_local, username, password):
(out, err, cmd) = ssh(himn_xs, username, password, 'route -n')
(out, err, cmd, proc) = ssh(himn_xs, username, password, 'route -n')
_net = lambda ip: '.'.join(ip.split('.')[:-1] + ['0'])
_mask = lambda cidr: inet_ntoa(pack(
'>I', 0xffffffff ^ (1 << 32 - int(cidr)) - 1))
@ -182,21 +189,26 @@ def route_to_compute(endpoints, himn_xs, himn_local, username, password):
def install_suppack(himn, username, password):
# TODO: check exists
scp(himn, username, password, '/tmp/', 'novaplugins.iso')
ssh(himn, username, password,
'xe-install-supplemental-pack', '/tmp/novaplugins.iso')
(out, err, cmd, proc) = ssh(
himn, username, password,
'xe-install-supplemental-pack', '/tmp/novaplugins.iso', prompt='Y\n')
ssh(himn, username, password, 'rm', '/tmp/novaplugins.iso')
def forward_from_himn(eth):
(out, err, cmd) = execute('iptables', '-S')
if not ('-A FORWARD -i %s -j ACCEPT') % eth in out:
execute('iptables', '-A', 'FORWARD', '-i', eth, '-j', 'ACCEPT')
execute('sed', '-i', 's/#net.ipv4.ip_forward/net.ipv4.ip_forward/g',
'/etc/sysctl.conf')
execute('sysctl', '-p', '/etc/sysctl.conf')
execute('iptables', '-t', 'nat', '-A', 'POSTROUTING', '-o', eth,
'-j', 'MASQUERADE')
(out, err, cmd, proc) = execute('iptables', '-S')
#if not ('-A FORWARD -i %s -j ACCEPT') % eth in out:
execute('iptables', '-A', 'FORWARD', '-i', eth, '-j', 'ACCEPT')
execute('sed', '-i', 's/#net.ipv4.ip_forward/net.ipv4.ip_forward/g',
'/etc/sysctl.conf')
execute('sysctl', '-p', '/etc/sysctl.conf')
execute('iptables', '-t', 'nat', '-A', 'POSTROUTING', '-o', 'br-mgmt', '-j', 'MASQUERADE')
execute('iptables', '-A', 'FORWARD', '-i', 'br-mgmt', '-o', eth, '-m', 'state', '--state', 'RELATED,ESTABLISHED', '-j', 'ACCEPT')
execute('iptables', '-A', 'FORWARD', '-i', eth, '-o', 'br-mgmt', '-j', 'ACCEPT')
execute('iptables', '-t', 'nat', '-A', 'POSTROUTING', '-o', 'br-storage', '-j', 'MASQUERADE')
execute('iptables', '-A', 'FORWARD', '-i', 'br-storage', '-o', eth, '-m', 'state', '--state', 'RELATED,ESTABLISHED', '-j', 'ACCEPT')
execute('iptables', '-A', 'FORWARD', '-i', eth, '-o', 'br-storage', '-j', 'ACCEPT')
if __name__ == '__main__':
eth = 'eth2'

View File

@ -22,7 +22,7 @@ function create_image {
local image_file
image_file=$(mktemp)
wget -qO "$image_file" "$image_URL"
wget -q -O "$image_file" "$image_url"
glance image-create \
--name "$image_name" \
--container-format ovf \

View File

@ -10,4 +10,4 @@ attributes:
label: 'Password'
description: ''
weight: 25
type: "text"
type: "password"