Merge "add kolla backend"

This commit is contained in:
Jenkins 2016-07-20 08:44:34 +00:00 committed by Gerrit Code Review
commit a1b3dd6a05
10 changed files with 375 additions and 21 deletions

View File

@ -1 +0,0 @@
this empty is to replace the backend code lose in 'make allrpm' stage

215
backend/kolla/getnodeinfo.sh Executable file
View File

@ -0,0 +1,215 @@
#!/bin/bash
dhcp_ip="192.0.1.152"
listen_port="5050"
DISCOVERD_URL="http://$dhcp_ip:$listen_port/v1/continue"
function update() {
jq "$1" data.json > temp.json || echo "Error: update $1 to json failed"
mv temp.json data.json
}
function get_system_info(){
PRODUCT=$(dmidecode -s system-product-name)
FAMILY=$(dmidecode -t system|grep "Family"|cut -d ":" -f2)
VERSION=$(dmidecode -s system-version)
SERIAL=$(dmidecode -s system-serial-number)
MANUFACTURER=$(dmidecode -s system-manufacturer)
UUID=$(dmidecode -s system-uuid)
FQDN=$(hostname -f)
echo '{"system":{}}' > data.json
update ".system[\"product\"] = \"$PRODUCT\""
update ".system[\"family\"] = \"$FAMILY\""
update ".system[\"fqdn\"] = \"$FQDN\""
update ".system[\"version\"] = \"$VERSION\""
update ".system[\"serial\"] = \"$SERIAL\""
update ".system[\"manufacturer\"] = \"$MANUFACTURER\""
update ".system[\"uuid\"] = \"$UUID\""
}
function get_cpu_info(){
REAL=$(cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l)
TOTAL=$(cat /proc/cpuinfo |grep "processor"|wc -l)
update ".cpu[\"real\"] = $REAL"
update ".cpu[\"total\"] = $TOTAL"
for i in $(seq $TOTAL)
do
if [ ! -z "$i" ]; then
SPEC_MODEL=$(cat /proc/cpuinfo | grep name | cut -f2 -d:|sed -n $i"p")
SPEC_FRE=$(cat /proc/cpuinfo | grep MHz | cut -f2 -d:|sed -n $i"p")
update ".cpu[\"spec_$i\"] = {model:\"$SPEC_MODEL\", frequency:$SPEC_FRE}"
fi
done
for node in $(lscpu | grep "node[0-9]" | awk -F ":" '{print $1}' | awk '{print $2}')
do
numanodes=$(lscpu | grep $node | awk -F ":" '{print $2}' | awk 'gsub(/^ *| *$/,"")')
update ".cpu[\"numa_$node\"] = \"$numanodes\""
done
}
function get_memory_info(){
PHY_NUM=$(dmidecode -t memory|grep "Physical Memory Array"|wc -l)
TOTAL_MEM=$(cat /proc/meminfo |grep MemTotal |cut -d ":" -f2)
update ".memory[\"total\"] = \"$TOTAL_MEM\""
for num in $(seq $PHY_NUM)
do
SLOTS=$(dmidecode -t memory |grep "Number Of Devices" |cut -d ":" -f2|sed -n $num"p")
MAX_CAP=$(dmidecode -t memory |grep "Maximum Capacity" |cut -d ":" -f2|sed -n $num"p")
update ".memory[\"phy_memory_$num\"] = {slots:\"$SLOTS\", maximum_capacity:\"$MAX_CAP\"}"
for i in $(seq $SLOTS)
do
if [ ! -z "$i" ]; then
DEVICE_FRE=$(dmidecode -t memory |grep "Speed" |cut -d ":" -f2|sed -n $i"p")
DEVICE_TYPE=$(dmidecode -t memory |grep 'Type:' |grep -v "Error Correction Type"|cut -d ":" -f2|sed -n $i"p")
DEVICE_SIZE=$(dmidecode -t memory |grep Size |cut -d ":" -f2|sed -n $i"p")
update ".memory[\"phy_memory_$num\"][\"devices_$i\"] = {frequency:\"$DEVICE_FRE\", type:\"$DEVICE_TYPE\", size:\"$DEVICE_SIZE\"}"
fi
done
done
}
function get_net_info(){
physical_networks=`ls -l /sys/class/net/ | grep -v lo |grep "pci"|awk -F 'net/' '{print $2}'`
if [ -f "/sys/class/net/bonding_masters" ]; then
bond_network=$(cat /sys/class/net/bonding_masters)
if [ ! -z "$bond_network" ];then
physical_networks+=" $bond_network"
fi
fi
for nic in $physical_networks
do
vlan_nic=`cat /proc/net/vlan/config | grep $nic |awk -F ' ' {'print $1'}`
if [ ! -z "$vlan_nic" ];then
all_vlan_nic+=" $vlan_nic "
fi
done
all_nic=$all_vlan_nic$physical_networks
for iface in $all_nic
do
NAME=$iface
MAC=$(ip link show $iface | awk '/ether/ {print $2}')
IP=$(ip addr show $iface | awk '/inet / { sub(/\/.*/, "", $2); print $2 }'| awk 'NR==1{print}')
NETMASK=$(ifconfig $iface | grep netmask | awk '{print $4}')
STATE=$(ip link show $iface | awk '/mtu/ {print $3}')
PCI=$(ethtool -i $iface|grep "bus-info"|cut -d " " -f2)
CURRENT_SPEED=$(ethtool $iface |grep Speed |awk -F " " '{print $2}')
LINE=$(ethtool $iface|grep -n "Supported pause frame use"|awk -F ":" '{print $1}')
LINE=$[ LINE - 1 ]
LINE_SPEED=$(ethtool $iface|grep -n "Supported link modes"|awk -F ":" '{print $1}')
BOND=$(ifconfig $iface | grep MASTER)
if [ $LINE -eq $LINE_SPEED ]; then
MAX_SPEED=$(ethtool $iface|grep "Supported link modes"|cut -d ":" -f2)
else
MAX_SPEED=$(ethtool $iface |sed -n $LINE"p"|awk -F " " '{print $1}')
fi
UP="UP"
if [[ "$STATE" =~ "$UP" ]]; then
STATE="up"
else
STATE="down"
fi
if [ -z "$BOND" ]; then
vlan_nic=`cat /proc/net/vlan/config |awk -F ' ' {'print $1'} |grep -w "${iface}$"`
if [ -z "$vlan_nic" ];then
TYPE="ether"
else
TYPE="vlan"
fi
else
TYPE="bond"
SLAVES=$(find /etc/sysconfig/network-scripts/ -name "ifcfg-*" |xargs grep "$iface" | grep "MASTER" |awk -F 'ifcfg-' '{print $2}'|awk -F ':' '{print $1}')
fi
if [ ! -z "$MAC" ]; then
update ".interfaces[\"$iface\"] = {mac: \"$MAC\", ip: \"$IP\", netmask: \"$NETMASK\", name: \"$iface\", max_speed: \"$MAX_SPEED\", state: \"$STATE\", pci: \"$PCI\", current_speed: \"$CURRENT_SPEED\", type: \"$TYPE\", slaves:\"$SLAVES\"}"
fi
done
}
function get_disk_info(){
for disk in $(fdisk -l|grep Disk|grep "/dev" |awk -F ": " '{print $1}'|awk -F "/" '{print $NF}')
do
DISK_NAME=$disk
DISK_SIZE=$(fdisk -l|grep Disk|grep "/dev" |grep -w $disk|cut -d "," -f2)
DISK_DISK=$(ls -l /dev/disk/by-path/|grep $disk"$"|awk '{print $9}')
DISK_EXTRA_1=$(ls -l /dev/disk/by-id/|grep $disk"$"|awk '{print $9}'|sed -n 1p)
DISK_EXTRA_2=$(ls -l /dev/disk/by-id/|grep $disk"$"|awk '{print $9}'|sed -n 2p)
MODEL=$(hdparm -I /dev/sda |grep Model | cut -d ":" -f2)
REMOVABLE=$(hdparm -I /dev/sda |grep removable|awk '{print $4}')
update ".disk[\"$disk\"] = {name: \"$DISK_NAME\", size: \"$DISK_SIZE\", disk: \"$DISK_DISK\", model: \"$MODEL\", removable: \"$REMOVABLE\",extra: [\"$DISK_EXTRA_1\", \"$DISK_EXTRA_2\"]}"
done
}
function get_hostname_info(){
HOST_NAME=$(hostname)
update ".hostname = \"$HOST_NAME\""
}
function get_devices_numa_info(){
for device in $(ls /sys/bus/pci/devices)
do
numa=$(cat /sys/bus/pci/devices/$device/numa_node)
update ".devices[\"$device\"] = {\"$device\": \"$numa\"}"
done
}
function get_pci_info(){
for key in $(lspci | awk '{print $1}')
do
info=$(lspci | grep "$key")
update ".pci[\"$key\"] = \"$info\""
done
}
function get_fc_port(){
for host in $(ls /sys/class/fc_host/)
do
path="/sys/class/fc_host/"${host}"/port_name"
port_name=$(cat $path)
update ".fc_port[\"$host\"] = \"$port_name\""
done
}
function main(){
get_system_info
get_cpu_info
get_memory_info
get_net_info
get_disk_info
get_hostname_info
get_devices_numa_info
get_pci_info
get_fc_port
}
main
BMC_ADDRESS=$(ipmitool lan print | grep -e "IP Address [^S]" | awk '{ print $4 }')
if [ -z "$BMC_ADDRESS" ]; then
BMC_ADDRESS=$(ipmitool lan print 3| grep -e "IP Address [^S]" | awk '{ print $4 }')
fi
update ".ipmi_address = \"$BMC_ADDRESS\""
update ".data_name = \"baremetal_source\""
update ".os_status = \"active\""
echo Collected:
cat data.json
RESULT=$(eval curl -i -X POST \
"-H 'Accept: application/json'" \
"-H 'Content-Type: application/json'" \
"-d @data.json" \
"$DISCOVERD_URL")
if echo $RESULT | grep "HTTP/1.0 4"; then
echo "Ironic API returned error: $RESULT"
fi
echo "Node is now discovered! Halting..."
sleep 5

16
backend/kolla/prepare.sh Executable file
View File

@ -0,0 +1,16 @@
#! /bin/bash
yum -y install epel-release
curl -sSL https://get.docker.io | bash
mkdir -p /etc/systemd/system/docker.service.d
config_path=/etc/systemd/system/docker.service.d/kolla.conf
echo -e "[Service]\nMountFlags=shared" > $config_path
systemctl daemon-reload
systemctl restart docker
yum install -y python-docker-py
yum -y install ntp
systemctl enable ntpd.service
systemctl stop libvirtd.service
systemctl disable libvirtd.service
systemctl start ntpd.service
yum -y install ansible1.9

88
backend/kolla/trustme.sh Normal file
View File

@ -0,0 +1,88 @@
#!/bin/sh
#to be trusted by other host£¬and no password needed when use ssh command
#check parameters legality
logfile=/var/log/trustme.log
function print_log
{
local promt="$1"
echo -e "$promt"
echo -e "`date -d today +"%Y-%m-%d %H:%M:%S"` $promt" >> $logfile
}
ip=$1
passwd=$2
if [ -z $passwd ]; then
print_log "Usage: `basename $0` ipaddr passwd"
exit 1
fi
rpm -qi sshpass >/dev/null
if [ $? != 0 ]; then
print_log "Please install sshpass first"
exit 1
fi
#ping other host
unreachable=`ping $ip -c 1 -W 3 | grep -c "100% packet loss"`
if [ $unreachable -eq 1 ]; then
print_log "host $ip is unreachable"
exit 1
fi
#generate ssh pubkey
if [ ! -e ~/.ssh/id_dsa.pub ]; then
print_log "generating ssh public key ..."
ssh-keygen -t dsa -f /root/.ssh/id_dsa -N "" <<EOF
n
EOF
if [ $? != 0 ]; then
print_log "ssh-keygen failed"
exit 1
fi
fi
#clear old public key
user=`whoami`
host=`hostname`
keyend="$user@$host"
print_log "my keyend = $keyend"
cmd="sed '/$keyend$/d' -i ~/.ssh/authorized_keys"
print_log "clear my old pub key on $local_host ..."
ssh-keygen -f "/root/.ssh/known_hosts" -R $ip
if [ $? != 0 ]; then
print_log "delete pub key of $ip from known_hosts failed"
exit 1
fi
sshpass -p $passwd ssh -o StrictHostKeyChecking=no $ip "touch ~/.ssh/authorized_keys"
if [ $? != 0 ]; then
print_log "ssh $ip to create file authorized_keys failed"
exit 1
fi
sshpass -p $passwd ssh -o StrictHostKeyChecking=no $ip "$cmd"
if [ $? != 0 ]; then
print_log "ssh $ip to edit authorized_keys failed"
exit 1
fi
#copy new public key
print_log "copy my public key to $ip ..."
tmpfile=/tmp/`hostname`.key.pub
sshpass -p $passwd scp -o StrictHostKeyChecking=no ~/.ssh/id_dsa.pub $ip:$tmpfile
if [ $? != 0 ]; then
print_log "scp file to $ip failed"
exit 1
fi
#copy public key to authorized_keys
print_log "on $ip, append my public key to ~/.ssh/authorized_keys ..."
sshpass -p $passwd ssh -o StrictHostKeyChecking=no $ip "cat $tmpfile >> ~/.ssh/authorized_keys"
if [ $? != 0 ]; then
print_log "ssh $ip to add public key for authorized_keys failed"
exit 1
fi
print_log "rm tmp file $ip:$tmpfile"
sshpass -p $passwd ssh -o StrictHostKeyChecking=no $ip "rm $tmpfile"
if [ $? != 0 ]; then
print_log "ssh $ip to delete tmp file failed"
exit 1
fi
print_log "trustme ok!"

View File

@ -36,6 +36,7 @@ daisy_path = '/var/lib/daisy/'
tecs_backend_name = "tecs"
zenic_backend_name = "zenic"
proton_backend_name = "proton"
kolla_backend_name = "kolla"
os_install_start_time = 0.0

View File

@ -1834,7 +1834,7 @@ class Controller(controller.BaseController):
with open(var_log_path, "w+") as fp:
try:
trustme_result = subprocess.check_output(
'/var/lib/daisy/tecs/trustme.sh %s %s' %
'/var/lib/daisy/kolla/trustme.sh %s %s' %
(discover_host_meta['ip'], discover_host_meta['passwd']),
shell=True, stderr=subprocess.STDOUT)
if 'Permission denied' in trustme_result:
@ -1910,40 +1910,54 @@ class Controller(controller.BaseController):
try:
subprocess.check_output(
'clush -S -w %s -c /var/lib/daisy/tecs/getnodeinfo.sh'
' /var/lib/daisy/tecs/jq-1.3-2.el7.x86_64.rpm '
'clush -S -w %s -c /var/lib/daisy/kolla/getnodeinfo.sh '
'--dest=/home/daisy/discover_host' %
(discover_host_meta['ip'],),
shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
update_info = {}
update_info['status'] = 'DISCOVERY_FAILED'
update_info['message'] = "scp getnodeinfo.sh and " \
"jq-1.3-2.el7.x86_64.rpm for %s" \
update_info['message'] = "scp getnodeinfo.sh" \
" failed!" % discover_host_meta['ip']
self.update_progress_to_db(req, update_info,
discover_host_meta)
LOG.error(_("scp getnodeinfo.sh and"
" jq-1.3-2.el7.x86_64.rpm for %s failed!"
LOG.error(_("scp getnodeinfo.sh for %s failed!"
% discover_host_meta['ip']))
fp.write(e.output.strip())
return
try:
subprocess.check_output(
'clush -S -w %s rpm -ivh --force '
'/home/daisy/discover_host/jq-1.3-2.el7.x86_64.rpm'
'clush -S -w %s yum install epel-release'
% (discover_host_meta['ip'],),
shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
update_info = {}
update_info['status'] = 'DISCOVERY_FAILED'
update_info['message'] = \
"install jq-1.3-2.el7.x86_64.rpm for %s failed!"\
"creat repo epel for %s failed!"\
% discover_host_meta['ip']
self.update_progress_to_db(req, update_info,
discover_host_meta)
LOG.error(_("install jq-1.3-2.el7.x86_64.rpm for %s failed!"
LOG.error(_("creat repo epel for %s failed!"
% discover_host_meta['ip']))
fp.write(e.output.strip())
return
try:
subprocess.check_output(
'clush -S -w %s yum install jq'
% (discover_host_meta['ip'],),
shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
update_info = {}
update_info['status'] = 'DISCOVERY_FAILED'
update_info['message'] = \
"install jq rpm for %s failed!"\
% discover_host_meta['ip']
self.update_progress_to_db(req, update_info,
discover_host_meta)
LOG.error(_("install jq rpm for %s failed!"
% discover_host_meta['ip']))
fp.write(e.output.strip())
return
@ -2088,9 +2102,10 @@ class Controller(controller.BaseController):
daisy_management_ip = config.get("DEFAULT", "daisy_management_ip")
if daisy_management_ip:
cmd = 'dhcp_linenumber=`grep -n "dhcp_ip="' \
' /var/lib/daisy/tecs/getnodeinfo.sh|cut -d ":" -f 1` && ' \
' /var/lib/daisy/kolla/getnodeinfo.sh|cut -d ":" -f 1` && ' \
'sed -i "${dhcp_linenumber}c dhcp_ip=\'%s\'" ' \
'/var/lib/daisy/tecs/getnodeinfo.sh' % (daisy_management_ip,)
'/var/lib/daisy/kolla/getnodeinfo.sh' \
% (daisy_management_ip,)
daisy_cmn.subprocess_call(cmd)
config_discoverd = ConfigParser.ConfigParser(
@ -2099,9 +2114,9 @@ class Controller(controller.BaseController):
listen_port = config_discoverd.get("discoverd", "listen_port")
if listen_port:
cmd = 'port_linenumber=`grep -n "listen_port="' \
' /var/lib/daisy/tecs/getnodeinfo.sh|cut -d ":" -f 1` && ' \
' /var/lib/daisy/kolla/getnodeinfo.sh|cut -d ":" -f 1` && ' \
'sed -i "${port_linenumber}c listen_port=\'%s\'" ' \
'/var/lib/daisy/tecs/getnodeinfo.sh' % (listen_port,)
'/var/lib/daisy/kolla/getnodeinfo.sh' % (listen_port,)
daisy_cmn.subprocess_call(cmd)
discovery_host_thread = threading.Thread(

View File

@ -55,8 +55,8 @@ ACTIVE_IMMUTABLE = daisy.api.v1.ACTIVE_IMMUTABLE
# if some backends have order constraint, please add here
# if backend not in the next three order list, we will be
# think it does't have order constraint.
BACKENDS_INSTALL_ORDER = ['proton', 'zenic', 'tecs']
BACKENDS_UPGRADE_ORDER = ['proton', 'zenic', 'tecs']
BACKENDS_INSTALL_ORDER = ['proton', 'zenic', 'tecs', 'kolla']
BACKENDS_UPGRADE_ORDER = ['proton', 'zenic', 'tecs', 'kolla']
BACKENDS_UNINSTALL_ORDER = []

View File

@ -45,7 +45,7 @@ _LW = i18n._LW
SUPPORTED_PARAMS = daisy.api.v1.SUPPORTED_PARAMS
SUPPORTED_FILTERS = daisy.api.v1.SUPPORTED_FILTERS
ACTIVE_IMMUTABLE = daisy.api.v1.ACTIVE_IMMUTABLE
SUPPORTED_DEPLOYMENT_BACKENDS = ('tecs', 'zenic', 'proton')
SUPPORTED_DEPLOYMENT_BACKENDS = ('tecs', 'zenic', 'proton', 'kolla')
SUPPORTED_ROLE = (
'CONTROLLER_LB',
'CONTROLLER_HA',

View File

@ -225,6 +225,7 @@ install -d -m 755 %{buildroot}%{_localstatedir}/log/daisy
mkdir -p %{buildroot}/var/lib/daisy
cp -Rf ../kolla %{buildroot}/var/lib/daisy
%pre
id daisy
@ -263,6 +264,9 @@ if [ $1 -eq 0 ] ; then
fi
%files
/var/lib/daisy/kolla/trustme.sh
/var/lib/daisy/kolla/prepare.sh
/var/lib/daisy/kolla/getnodeinfo.sh
/etc/daisy/daisy-api-paste.ini
/etc/daisy/daisy-registry-paste.ini
%doc README.rst
@ -309,6 +313,8 @@ fi
%dir %attr(0750, daisy, daisy) %{_localstatedir}/log/daisy
%dir %attr(0755, daisy, daisy) %{_localstatedir}/run/daisy
%dir %attr(0755, daisy, daisy) /var/lib/daisy/*
%dir %attr(0777, all, all) /var/lib/daisy/kolla/
%attr(0755, daisy, daisy) /var/lib/daisy/kolla/*
%files -n python-daisy
%doc README.rst

View File

@ -476,6 +476,16 @@ function create_daisy_role_with_proton
[ "$?" -ne 0 ] && { write_install_log "create the role of proton failed"; exit 1; }
}
function create_daisy_role_with_kolla
{
write_install_log "Daisy init and create the role with kolla"
daisy --os-endpoint="http://${public_ip}:$bind_port" role-add "CONTROLLER_LB" "Controller Role for kolla." --type template --deployment-backend kolla --role-type CONTROLLER_LB >> $install_logfile 2>&1
[ "$?" -ne 0 ] && { write_install_log "create the controller role of KOLLA failed"; exit 1; }
daisy --os-endpoint="http://${public_ip}:$bind_port" role-add "COMPUTER" "Computer Role for kolla." --type template --deployment-backend kolla --role-type COMPUTER >> $install_logfile 2>&1
[ "$?" -ne 0 ] && { write_install_log "create the computer role of KOLLA failed"; exit 1; }
}
function create_daisy_service_role_with_cell
{
write_install_log "Daisy init and create component and role with cell"
@ -539,6 +549,10 @@ function daisy_init_func
if [ $proton -ne 0 ];then
create_daisy_role_with_proton
fi
kolla=`echo $default_backend_types_params|grep 'kolla'|wc -l`
if [ $kolla -ne 0 ];then
create_daisy_role_with_kolla
fi
}
function modify_sudoers
@ -765,7 +779,7 @@ function config_keystone_local_setting
function config_get_node_info
{
local get_node_info_file="/var/lib/daisy/tecs/getnodeinfo.sh"
local get_node_info_file="/var/lib/daisy/kolla/getnodeinfo.sh"
if [ ! -e $get_node_info_file ];then
write_install_log "Error:the file $get_node_info_file is not exist"
exit 1
@ -776,7 +790,7 @@ function config_get_node_info
exit 1
fi
sed -i "s/127.0.0.1/$public_ip/g" $get_node_info_file
[ "$?" -ne 0 ] && { write_install_log "Error:config /var/lib/daisy/tecs/getnodeinfo.sh failed"; exit 1;}
[ "$?" -ne 0 ] && { write_install_log "Error:config /var/lib/daisy/kolla/getnodeinfo.sh failed"; exit 1;}
}
_INSTALL_FUNC_FILE="install_func.sh"