Commit 26b7ba4b by Czémán Arnold

Merge branch 'easy_setup' into 'master'

Easy setup

See merge request !10
parents 9865f826 0653b50a
#!/bin/sh
if [ $(id -u) -ne 0 ]; then
RED_UNDERLINED='\033[4;31m'
NC='\033[0m' # No Color
echo -e $RED_UNDERLINED"Please run as root or use sudo!"$NC
exit
fi
FULLPATH=$(readlink -m $0)
PREFIX=$(dirname $FULLPATH)
pip install -r $PREFIX/requirements.txt
$PREFIX/kvm-ok > /dev/null
retv=$?
EXTRAPARAMS=""
if [ $retv -eq 0 ]; then
EXTRAPARAMS="--kvm-present"
fi
python $PREFIX/install.py $EXTRAPARAMS
import salt.client
from salt import config
from salt.log.setup import setup_console_logger
from os.path import join, abspath, dirname
from netifaces import ifaddresses, gateways, AF_INET
from netaddr import IPNetwork
import socket
import yaml
import random
import os
import getpass
from halo import Halo
import argparse
PREFIX = dirname(__file__)
def get_timezone():
localtime = '/etc/localtime'
try:
zonefile = abspath(os.readlink(localtime))
zone_parts = zonefile.split('/')
return join(zone_parts[-2], zone_parts[-1])
except Exception:
return 'Europe/Budapest'
def get_gateway():
return gateways()['default'][AF_INET]
def get_default_gw():
return get_gateway()[0]
def get_interface():
return get_gateway()[1]
def get_ip_with_mask(intf):
ip = ifaddresses(intf)[AF_INET][0]
return str(IPNetwork(join(ip['addr'], ip['netmask'])))
def get_hostname():
return str(socket.gethostname().split('.')[0])
def print_warning(text):
RED_UNDERLINED = '\033[4;31m'
NC = '\033[0m' # No Color
print(RED_UNDERLINED + text + NC)
def input_password_with_retype():
pw = getpass.getpass("Enter admin password:")
if len(pw) == 0:
print_warning('Please enter a non-empty password!')
return ('', False)
pw2 = getpass.getpass("Retype password:")
status = pw == pw2
if not status:
print_warning('The passwords are different.')
return (pw, status)
def input_admin_password():
pw, status = input_password_with_retype()
while not status:
pw, status = input_password_with_retype()
return pw.encode('utf8')
def yaml_pretty_dump(data, file, **extra):
yaml.dump(data, file, encoding='utf-8', default_flow_style=False, **extra)
def dump_errors(result):
# Filter errors only
errors = {}
for key, data in result.iteritems():
if not data['result']:
errors[key] = data
with open(join(PREFIX, 'errors.yml'), 'w') as f:
yaml_pretty_dump(errors, f)
class KeyStore:
""" Loads, stores, generates, and saves secret keys """
def __init__(self, keyfile):
self.keyfile = keyfile
self.data = {}
try:
with open(keyfile) as f:
self.data = yaml.safe_load(f)
except Exception:
pass
def gen_key(self, length):
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
return "".join(random.sample(s, length))
def get_key(self, name):
key = self.data.get(name)
if key is None:
key = self.gen_key(16)
self.data[name] = key
return key
def save(self):
with open(self.keyfile, 'w') as f:
yaml.dump(self.data, f)
parser = argparse.ArgumentParser()
parser.add_argument('--kvm-present', action='store_true',
help='Installs with KVM hypervisor otherwise with QEMU.')
args = parser.parse_args()
KEYFILE = join(PREFIX, '.circlekeys')
ks = KeyStore(KEYFILE)
installer_sls = {
'user': 'cloud',
'proxy_secret': ks.get_key('proxy_secret'),
'secret_key': ks.get_key('secret_key'),
'timezone': get_timezone(),
'deployment_type': 'production',
'admin_user': 'admin',
'admin_pass': input_admin_password(),
'database': {
'name': 'circle',
'user': 'circle',
'password': ks.get_key('database_password'),
},
'amqp': {
'user': 'cloud',
'password': ks.get_key('amqp_password'),
'host': '127.0.0.1',
'port': 5672,
'vhost': 'circle',
},
'graphite': {
'user': 'monitor',
'password': ks.get_key('graphite_password'),
'host': '127.0.0.1',
'port': 5672,
'vhost': 'monitor',
'queue': 'monitor',
'secret_key': ks.get_key('graphite_secret_key'),
},
'cache': 'pylibmc://127.0.0.1:11211/',
'nfs': {
'enabled': True,
'server': '127.0.0.1',
'network': '127.0.0.0/8',
'directory': '/datastore',
},
'storagedriver': {
'queue_name': get_hostname(),
},
'fwdriver': {
'gateway': get_default_gw().encode('utf-8'),
'external_if': get_interface().encode('utf-8'),
'external_net': get_ip_with_mask(get_interface()).encode('utf-8'),
'queue_name': get_hostname(),
'management_if': 'ethy',
'trunk_if': 'linkb',
},
'vmdriver': {
'hypervisor_type': 'kvm' if args.kvm_present else 'qemu',
},
}
ks.save() # Save secret keys
# Make installer.sls
INSTALLERT_SLS = join(PREFIX, 'pillar/installer.sls')
with open(INSTALLERT_SLS, 'w') as f:
yaml_pretty_dump(installer_sls, f)
# NOTE: default logfile is '/var/log/salt/minion'
opts = config.minion_config('')
opts['file_client'] = 'local'
# NOTE: False will cause salt to only display output
# for states that failed or states that have changes
opts['state_verbose'] = False
opts['file_roots'] = {'base': [join(PREFIX, 'salt')]}
opts['pillar_roots'] = {'base': [join(PREFIX, 'pillar')]}
setup_console_logger(log_level='info')
caller = salt.client.Caller(mopts=opts)
# Run install with salt
with Halo(text='Installing', spinner='dots'):
result = caller.function('state.sls', 'allinone', with_grains=True)
# Count errors and print to console
error_num = 0
for key, data in result.iteritems():
if not data['result']:
print('Error in state: %s' % key)
error_num += 1
if error_num == 0:
print('Succesfully installed!')
else:
print_warning('%i error occured during install!' % error_num)
dump_errors(result)
#!/bin/sh
#
# kvm-ok - check whether the CPU we're running on supports KVM acceleration
# Copyright (C) 2008-2010 Canonical Ltd.
#
# Authors:
# Dustin Kirkland <kirkland@canonical.com>
# Kees Cook <kees.cook@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
assert_root() {
if [ "$(id -u)" != "0" ]; then
echo "INFO: For more detailed results, you should run this as root"
echo "HINT: sudo $0"
exit 1
fi
}
verdict() {
# Print verdict
if [ "$1" = "0" ]; then
echo "KVM acceleration can be used"
exit 0
else
echo "KVM acceleration can NOT be used"
exit 1
fi
}
# check cpu flags for capability
virt=$(egrep -m1 -w '^flags[[:blank:]]*:' /proc/cpuinfo | egrep -wo '(vmx|svm)') || true
[ "$virt" = "vmx" ] && brand="intel"
[ "$virt" = "svm" ] && brand="amd"
if [ -z "$virt" ]; then
echo "INFO: Your CPU does not support KVM extensions"
assert_root
verdict 1
fi
# Now, check that the device exists
if [ -e /dev/kvm ]; then
echo "INFO: /dev/kvm exists"
verdict 0
else
echo "INFO: /dev/kvm does not exist"
echo "HINT: sudo modprobe kvm_$brand"
fi
assert_root
# Prepare MSR access
msr="/dev/cpu/0/msr"
if [ ! -r "$msr" ]; then
modprobe msr
fi
if [ ! -r "$msr" ]; then
echo "You must be root to run this check." >&2
exit 2
fi
echo "INFO: Your CPU supports KVM extensions"
disabled=0
# check brand-specific registers
if [ "$virt" = "vmx" ]; then
BIT=$(rdmsr --bitfield 0:0 0x3a 2>/dev/null || true)
if [ "$BIT" = "1" ]; then
# and FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX clear (no tboot)
BIT=$(rdmsr --bitfield 2:2 0x3a 2>/dev/null || true)
if [ "$BIT" = "0" ]; then
disabled=1
fi
fi
elif [ "$virt" = "svm" ]; then
BIT=$(rdmsr --bitfield 4:4 0xc0010114 2>/dev/null || true)
if [ "$BIT" = "1" ]; then
disabled=1
fi
else
echo "FAIL: Unknown virtualization extension: $virt"
verdict 1
fi
if [ "$disabled" -eq 1 ]; then
echo "INFO: KVM ($virt) is disabled by your BIOS"
echo "HINT: Enter your BIOS setup and enable Virtualization Technology (VT),"
echo " and then hard poweroff/poweron your system"
verdict 1
fi
verdict 0
vmdriver:
repo_name: https://git.ik.bme.hu/circle/vmdriver.git
repo_revision: master
hypervisor_type: kvm
salt==2014.7.1
netaddr==0.7.14
netifaces==0.10.6
halo==0.0.7
......@@ -3,6 +3,14 @@
source /home/{{ pillar['user'] }}/.virtualenvs/circle/bin/activate
source /home/{{ pillar['user'] }}/.virtualenvs/circle/bin/postactivate
{% set fw = pillar['fwdriver'] %}
HOSTNAME=$(hostname -s)
EXTRAPARAMS=""
if [ "{{ pillar['vmdriver']['hypervisor_type'] }}" = "kvm" ]; then
EXTRAPARAMS="--kvm-present"
fi
exec python /home/{{ pillar['user'] }}/circle/circle/manage.py init \
--external-net={{ fw['external_net'] }} \
--management-net={{ fw['management_net'] }} \
......@@ -13,4 +21,9 @@ exec python /home/{{ pillar['user'] }}/circle/circle/manage.py init \
--firewall-queue={{ fw['queue_name'] }} \
--external-if={{ fw['external_if'] }} \
--management-if={{ fw['management_if'] }} \
--vm-if={{ fw['vm_if'] }}
--vm-if={{ fw['vm_if'] }} \
--node-hostname=$HOSTNAME \
--node-mac="99:AA:BB:CC:DD:EE" \
--node-ip="127.0.0.1" \
--node-name=$HOSTNAME \
$EXTRAPARAMS
export AMQP_URI=amqp://{{ pillar['amqp']['user'] }}:{{ pillar['amqp']['password'] }}@{{ pillar['amqp']['host'] }}:{{ pillar['amqp']['port'] }}/{{ pillar['amqp']['vhost'] }}
export CACHE_URI={{ pillar['cache'] }}
export LIBVIRT_URI=qemu:///system
export HYPERVISOR_TYPE=kvm
export HYPERVISOR_TYPE="{{ pillar['vmdriver']['hypervisor_type'] }}"
export NATIVE_OVS=True
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment