下列脚本文件皆从ubuntu发布的关于openstack的镜像中提取,便于以后的查询和使用。
allinoneinstall-ubuntu.sh(shell部分在页面显示有问题,可以左上脚的view plain查看):
#!/bin/sh local_ip=`ifconfig eth0 | grep Bcast | awk {'print $2'} | awk -F ":" {'print $2'}` netmask=`ifconfig eth0 | grep Mask | awk -F "Mask:" {'print $2'}` gateway="" if [ -f /var/lib/dhcp/dhclient.eth0.leases ];then gateway=`cat /var/lib/dhcp/dhclient.eth0.leases | grep routers | awk '{print $3}' | awk -F ";" '{print $1}'` else gateway=`cat /etc/network/interfaces | grep gateway | awk {'print $2'}` fi gateway=`echo $gateway |awk -F " " '{print $NF}'` home_path=/opt/openstack os_VENDOR="" ##################### #######get OS######## ##################### function get_OS() { LOG "get OS" if [[ -x $(which lsb_release 2>/dev/null) ]]; then os_VENDOR=$(lsb_release -i -s) fi } ##################### #####add repo######## ##################### function add_repo() { LOG "add repo" mv /etc/apt/sources.list /etc/apt/sources.list.bak echo "deb file:/opt/openstack openstack/" >> /etc/apt/sources.list apt-get update #apt-get upgrade --force-yes -y } ###################### ## config network ## ###################### function init_network() { LOG "begin init network " /bin/bash $home_path/restore_networking.sh install_package openvswitch-common openvswitch-switch service openvswitch-switch restart sleep 2 ovs-vsctl add-br br-int ovs-vsctl add-br br-eth1 ovs-vsctl add-br br-ex ovs-vsctl add-port br-ex eth0 cat >/etc/network/interfaces <<EOF auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 0.0.0.0 auto br-ex iface br-ex inet static address $local_ip netmask $netmask gateway $gateway EOF #route add default gw $gateway dev br-ex #ifdown --all && ifup --all ifconfig eth0 0.0.0.0 service networking restart sed -i -r 's/^\s*#(net\.ipv4\.ip_forward=1.*)/\1/' /etc/sysctl.conf LOG "end init network " } ###################### ## install packages ## ###################### function install_package() { apt-get --force-yes -y install "$@" } ###################### ## install db ## ###################### function install_db() { LOG "begin install db" source /root/novarc mysql_packages="mariadb-server python-mysqldb" echo mysql-server-5.5 mysql-server/root_password password ${OPENSTACK_PASSWD} | debconf-set-selections echo mysql-server-5.5 mysql-server/root_password_again password ${OPENSTACK_PASSWD} | debconf-set-selections echo mysql-server-5.5 mysql-server/start_on_boot boolean true | debconf-set-selections install_package $mysql_packages sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf sed -i 's/\[mysqld\]/&\ninnodb_file_per_table/g' /etc/mysql/my.cnf sed -i 's/\[mysqld\]/&\ncharacter-set-server = utf8/g' /etc/mysql/my.cnf sed -i "s/\[mysqld\]/&\ninit-connect = 'SET NAMES utf8'/g" /etc/mysql/my.cnf sed -i "s/\[mysqld\]/&\ncollation-server = utf8_general_ci/g" /etc/mysql/my.cnf sed -i 's/\[mysqld\]/&\ndefault-storage-engine = innodb/g' /etc/mysql/my.cnf #mysql_install_db #mysql_secure_installation service mysql restart sleep 3 sh $home_path/etc/config-DB-mysql.sh sleep 3 ###################### } #function init_db() #{ # #} ###################### ###### init env ##### ###################### function init_env() { #packages="linux-image-generic-lts-saucy linux-headers-generic-lts-saucy" #install_packages $packages echo "export OS_TENANT_NAME=admin" > /root/novarc echo "export OS_USERNAME=admin" >> /root/novarc echo "export OS_PASSWORD=openstack" >> /root/novarc echo "export OPENSTACK_PASSWD=openstack" >> /root/novarc #echo "export SERVICE_PASSWORD=$password" >> /root/novarc #echo "export RABBIT_PASSWORD=$password" >> /root/novarc #echo "export OS_SERVICE_TOKEN=$OS_SERVICE_TOKEN" >> /root/novarc #echo "export OS_SERVICE_ENDPOINT=$OS_SERVICE_ENDPOINT" >> /root/novarc echo "export OS_AUTH_URL=http://$local_ip:5000/v2.0" >> /root/novarc echo "source /root/novarc" >> /root/.bashrc source /root/novarc } ###################### ## install rabbitmq ## ###################### function install_rabbitmq() { install_package rabbitmq-server service rabbitmq-server restart sleep 3 rabbitmqctl change_password guest $OPENSTACK_PASSWD sleep 3 } ####################### ######################### ##### modify config #### ###################### function update_config() { cd $home_path/etc for i in `find ./`;do sed -i "s/openstack-ip/$local_ip/g" $i;done for i in `find ./`;do sed -i "s/openstack-passwd/$OPENSTACK_PASSWD/g" $i;done } ####################### ## install keystone ### ####################### function install_keystone() { keystone_packages="keystone python-keystoneclient" install_package $keystone_packages cp -r $home_path/etc/keystone/* /etc/keystone/ service keystone restart rm /var/lib/keystone/keystone.db su -s /bin/sh -c "keystone-manage db_sync" keystone #keystone-manage pki_setup --keystone-user keystone --keystone-group keystone sleep 3 chmod +x $home_path/etc/keystone_basic.sh chmod +x $home_path/etc/keystone_endpoints_basic.sh sh $home_path/etc/keystone_basic.sh sh $home_path/etc/keystone_endpoints_basic.sh sleep 3 } ####################### ### config keystone ### ####################### function config_keystone() { cp -r etc/keystone/* /etc/keystone/ if [ "Ubuntu" = $os_VENDOR ]; then service keystone restart keystone-manage db_sync sleep 2 chmod +x etc/keystone_basic.sh chmod +x etc/keystone_endpoints_basic.sh sh etc/keystone_basic.sh sh etc/keystone_endpoints_basic.sh sleep 2 fi } ####################### #### install glance ### ####################### function install_glance() { keystone_packages="glance python-glanceclient" install_package $keystone_packages sleep 2 cp -r $home_path/etc/glance/* /etc/glance/ rm /var/lib/glance/glance.sqlite su -s /bin/sh -c "glance-manage db_sync" glance service glance-api restart service glance-registry restart ############################## } ####################### ##### install nova #### ####################### function install_nova() { nova_package="nova-api nova-scheduler nova-cert nova-conductor nova-consoleauth nova-novncproxy nova-compute python-novaclient" install_package $nova_package sleep 3 cp -r $home_path/etc/nova/* /etc/nova/ rm /var/lib/nova/nova.sqlite su -s /bin/sh -c "nova-manage db sync" nova #dpkg-statoverride --update --add root root 0644 /boot/vmlinuz-$(uname -r) num=`egrep -c '(vmx|svm)' /proc/cpuinfo` if [ $num -eq 0 ];then sed -i "s/virt_type=.*/virt_type=qemu/g" /etc/nova/nova-compute.conf fi #echo 'kvm_intel' >> /etc/modules for svc in api conductor cert consoleauth conductor scheduler novncproxy compute; do service nova-$svc restart; done; ############################## } ####################### ###### config ovs ##### ####################### function config_ovs() { service openvswitch-switch restart sleep 2 ovs-vsctl add-br br-int ovs-vsctl add-br br-eth1 ovs-vsctl add-br br-ex } ####################### ### install neutron ### ####################### function install_neutron() { LOG "begin install neutron" neutron_packages="neutron-server python-neutronclient neutron-plugin-ml2 neutron-plugin-openvswitch-agent neutron-l3-agent neutron-dhcp-agent ipset" install_package $neutron_packages novatenantid=`keystone tenant-list | awk '/ nova / { print $2 }'` sed -i "s/novatenantid/$novatenantid/g" $home_path/etc/neutron/neutron.conf cp -r $home_path/etc/neutron/* /etc/neutron rm /var/lib/neutron/neutron.sqlite su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron.conf \ --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade juno" neutron #mkdir -p /var/lock/neutron #chown neutron:neutron /var/lock/neutron #sed -i 's/NEUTRON_PLUGIN_CONF/#NEUTRON_PLUGIN_CONF/' /etc/sysconfig/neutron #echo NEUTRON_PLUGIN_CONF=\"/etc/neutron/plugins/ml2/ml2_conf.ini\" >> /etc/sysconfig/neutron sleep 3 LOG "service openstack-neutron restart" service nova-api restart service nova-scheduler restart service nova-conductor restart service neutron-server restart service neutron-plugin-openvswitch-agent restart service neutron-l3-agent restart service neutron-dhcp-agent restart service neutron-metadata-agent restart LOG "end install neutron" ########################## } ####################### #### install cinder ### ####################### function install_cinder() { cinder_packages="cinder-api cinder-scheduler python-cinderclient lvm2 cinder-volume" install_package $cinder_packages cp -r $home_path/etc/cinder/* /etc/cinder rm /var/lib/cinder/cinder.sqlite su -s /bin/sh -c "cinder-manage db sync" cinder vgremove cinder-volumes dd if=/dev/zero of=/var/cinder-volumes bs=1 count=0 seek=10G losetup /dev/loop2 /var/cinder-volumes pvcreate /dev/loop2 vgcreate cinder-volumes /dev/loop2 echo "losetup /dev/loop2 /var/cinder-volumes" >>/etc/init.d/rc.local echo "vgchange -a y cinder-volumes" >>/etc/init.d/rc.local echo "service cinder-volume restart" >>/etc/init.d/rc.local service cinder-scheduler restart service cinder-api restart service cinder-volume restart service tgt restart ############################ } ####################### #### install mongodb ## ####################### function install_mongodb() { mongodb_packages="mongodb-server" install_package $mongodb_packages sed -i "s/127.0.0.1/$local_ip/g" /etc/mongodb.conf chown -R mongodb:mongodb /var/lib/mongodb/ service mongodb restart sleep 3 chown -R mongodb:mongodb /var/lib/mongodb/ sleep 2 mongo --host $local_ip $home_path/etc/config_mongodb.js mongo --host $local_ip --eval ' db = db.getSiblingDB("ceilometer"); db.addUser({user: "ceilometer", pwd: "openstack", roles: [ "readWrite", "dbAdmin" ]})' mongo_ret=$? retry=0 while [ $mongo_ret -eq 1 -a $retry -le 5 ];do sleep 2 mongo --host $local_ip --eval ' db = db.getSiblingDB("ceilometer"); db.addUser({user: "ceilometer", pwd: "openstack", roles: [ "readWrite", "dbAdmin" ]})' mongo_ret=$? retry=`expr $retry + 1` done; #mongo --host $local_ip $home_path/etc/config_mongodb.js sleep 3 ######################## } ####################### ## install ceilometer # ####################### function install_ceilometer() { #TODO is this bug? patch_packages="python-bson python-pymongo" install_package $patch_packages ceilometer_packages="ceilometer-api ceilometer-collector ceilometer-agent-central ceilometer-agent-notification ceilometer-alarm-evaluator ceilometer-alarm-notifier python-ceilometerclient ceilometer-agent-compute" install_package $ceilometer_packages sleep 3 cp -r $home_path/etc/ceilometer/* /etc/ceilometer/ su -s /bin/sh -c "ceilometer-dbsync" ceilometer sleep 2 rm /var/lib/ceilometer/ceilometer.sqlite service ceilometer-agent-central restart service ceilometer-agent-notification restart service ceilometer-api restart service ceilometer-collector restart service ceilometer-alarm-evaluator restart service ceilometer-alarm-notifier restart service nova-compute restart service ceilometer-agent-compute restart ############################ } ####################### #### install heat ##### ####################### function install_heat() { heat_packages="heat-api heat-api-cfn heat-engine python-heatclient" install_package $heat_packages cp -r $home_path/etc/heat/* /etc/heat/ rm /var/lib/heat/heat.sqlite su -s /bin/sh -c "heat-manage db_sync" heat service heat-api restart service heat-api-cfn restart service heat-engine restart } ####################### ### install horizon ### ####################### function install_horizon() { horizon_packages="openstack-dashboard apache2 libapache2-mod-wsgi memcached python-memcache" install_package $horizon_packages apt-get remove --purge openstack-dashboard-ubuntu-theme -y cp $home_path/etc/local_settings.py /etc/openstack-dashboard/ #/usr/share/openstack-dashboard/manage.py syncdb #mkdir -p /var/lib/dash/.blackhole service apache2 restart service memcached restart } #TODO ####################### ### install trove ### ####################### function install_trove() { trove_packages="python-trove python-troveclient python-glanceclient trove-common trove-api trove-taskmanager" install_package $trove_packages cp -r $home_path/etc/trove/* /etc/trove/ su -s /bin/sh -c "trove-manage db_sync" trove su -s /bin/sh -c "trove-manage datastore_update mysql ''" trove service trove-api restart service trove-taskmanager restart service trove-conductor restart } ####################### #### install patch #### ####################### function install_patch() { neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head sed -i 's/\/etc\/cinder\/rootwrap.conf/\/etc\/cinder\/rootwrap.conf \*/' /etc/sudoers.d/cinder_sudoers sed -i 's/\[DEFAULT\]/&\napi_paste_config=\/etc\/ceilometer\/api_paste.ini/g' /etc/ceilometer/ceilometer.conf mongo --host $local_ip --eval ' db = db.getSiblingDB("ceilometer"); db.addUser({user: "ceilometer", pwd: "root", roles: [ "readWrite", "dbAdmin" ]})' } function restart_nova() { for svc in api conductor cert consoleauth conductor scheduler novncproxy compute; do service nova-$svc restart; done; } function restart_neutron() { service neutron-plugin-openvswitch-agent restart service neutron-server restart service neutron-plugin-openvswitch-agent restart service neutron-l3-agent restart service neutron-dhcp-agent restart service neutron-metadata-agent restart } function restart_cinder() { service tgt restart service cinder-api restart service cinder-scheduler restart service cinder-volume restart } function restart_glance() { service glance-api restart service glance-registry restart } function restart_ceilometer() { service ceilometer-agent-central restart service ceilometer-agent-notification restart service ceilometer-api restart service ceilometer-collector restart service ceilometer-alarm-evaluator restart service ceilometer-alarm-notifier restart service ceilometer-agent-compute restart } function restart_heat() { service heat-api restart service heat-api-cfn restart service heat-engine restart } function restart_service() { service keystone restart restart_nova restart_neutron restart_cinder restart_glance restart_ceilometer restart_heat sleep 3 } function check() { LOG "check begin" source /root/novarc check_nova check_cinder check_neutron check_glance check_keystone check_heat check_ceilometer LOG "check end,openstack is OK" } function service_check() { logfile="/opt/openstack/check.log" servicename=$1 servicenum=$2 if [ $servicename != "nova" -a $servicename != "cinder" ] ;then num=`ps -ef|grep $servicename- | grep -v grep | wc -l` if [ $num -ge $servicenum ]; then echo "$servicename service is OK" >> $logfile else echo "$servicename is NOK" >> $logfile exit 1 fi else num=`$servicename service-list | grep up | wc -l` if [ $num -eq $servicenum ]; then echo "$servicename service is OK" >> $logfile else name=`$servicename service-list | grep down | awk -F "|" {'print $2'}` echo "$name is NOK" >> $logfile exit 1 fi fi } function list() { logfile="/opt/openstack/check.log" name=$1 listnum=$2 if [ $name = "neutron" ];then num=`$name net-list | wc -l` if [ $num -eq $listnum ];then echo "$name net-list is OK" >> $logfile else echo "$name net-list is NOK" >> $logfile exit 1 fi elif [ $name = "glance" ];then num=`$name image-list | wc -l` if [ $num -eq $listnum ];then echo "$name image-list is OK" >> $logfile else echo "$name image-list is NOK" >> $logfile exit 1 fi elif [ $name = "ceilometer" ];then num=`$name alarm-list | wc -l` if [ $num -eq $listnum ];then echo "$name alarm-list is OK" >> $logfile else echo "$name alarm-list is NOK" >> $logfile exit 1 fi elif [ $name = "heat" ];then num=`$name stack-list | wc -l` if [ $num -eq $listnum ];then echo "$name stack-list is OK" >> $logfile else echo "$name stack-list is NOK" >> $logfile exit 1 fi elif [ $name = "keystone" ];then num=`$name user-list | wc -l` if [ $num -eq $listnum ];then echo "$name user-list is OK" >> $logfile else echo "$name user-list is NOK" >> $logfile exit 1 fi else num=`$name list | wc -l` if [ $num -eq $listnum ];then echo "$name list is OK" >> $logfile else echo "$name list is NOK" >> $logfile exit 1 fi fi } function check_nova() { logfile="/opt/openstack/check.log" LOG "check nova" echo "nova check begin" >> $logfile type=`cat /etc/nova/nova-compute.conf | grep virt_type | awk -F "=" {'print $2'}` cpu=`egrep -c '(vmx|svm)' /proc/cpuinfo` if [[ $type = "kvm" ]] && [[ $cpu -gt 0 ]];then echo "virt_tpyt is OK" >> $logfile elif [[ $type = "qemu" ]] && [[ $cpu -eq 0 ]];then echo "virt_tpyt is OK" >> $logfile else echo "virt_tpyt is NOK" >> $logfile exit 1 fi service_check nova 5 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi list nova 4 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi echo "nova is OK" >> /opt/openstack/check.log LOG "nova is OK" } function check_cinder() { logfile="/opt/openstack/check.log" LOG "check cinder" echo "cinder check begin" >> $logfile vg=`vgs | grep cinder-volumes | wc -l` if [ $vg -eq 1 ]; then echo "vg is OK" >> $logfile else echo "vg is NOK" >> $logfile exit 1 fi service_check cinder 2 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi list cinder 4 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi cinder create 1 sleep 1 num=`cinder list | grep available | wc -l` if [ $num -eq 1 ]; then echo "create volume is OK" >> $logfile fi echo "cinder is OK" >> $logfile LOG "cinder is OK" } function check_glance() { logfile="/opt/openstack/check.log" LOG "check glance" echo "glance check begin" >> $logfile service_check glance 7 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi list glance 4 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi } function check_neutron() { logfile="/opt/openstack/check.log" LOG "check neutron" echo "neutron check begin" >> $logfile #service_check neutron 11 #result=`echo $?` #if [ $result -ne 0 ]; then # exit $result #fi list neutron 1 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi } function check_keystone() { logfile="/opt/openstack/check.log" LOG "check keystone" echo "keystone check begin" >> $logfile service_check keystone 1 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi list keystone 12 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi } function check_ceilometer() { logfile="/opt/openstack/check.log" LOG "check ceilometer" echo "ceilometer check begin" >> $logfile service_check ceilometer 6 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi list ceilometer 4 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi } function check_heat() { logfile="/opt/openstack/check.log" LOG "check heat" echo "heat check begin" >> $logfile service_check heat 3 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi list heat 4 result=`echo $?` if [ $result -ne 0 ]; then exit $result fi } function LOG() { echo "`date -u +'%Y-%m-%d %T'`: $@" echo "`date -u +'%Y-%m-%d %T.%N'`: $@" >> /var/log/installallinone.log } function main() { add_repo init_env init_network update_config install_db install_rabbitmq install_keystone install_glance install_cinder install_neutron install_nova install_mongodb install_ceilometer install_heat install_horizon #install_patch restart_service check } main $@
config-DB-mysql.sh:
mysql -uroot -popenstack-passwd <<EOF grant all privileges on *.* to root@'%' identified by 'openstack-passwd'; flush privileges; CREATE DATABASE nova; GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'openstack-passwd'; CREATE DATABASE glance; GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'openstack-passwd'; CREATE DATABASE keystone; GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY 'openstack-passwd'; CREATE DATABASE cinder; GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'openstack-passwd'; CREATE DATABASE neutron; GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' IDENTIFIED BY 'openstack-passwd'; CREATE DATABASE heat; GRANT ALL PRIVILEGES ON heat.* TO 'heat'@'%' IDENTIFIED BY 'openstack-passwd'; CREATE DATABASE ceilometer; GRANT ALL PRIVILEGES ON ceilometer.* TO 'ceilometer'@'%' IDENTIFIED BY 'openstack-passwd'; CREATE DATABASE dash; GRANT ALL PRIVILEGES ON dash.* TO 'dash'@'%' IDENTIFIED BY 'openstack-passwd'; use mysql; delete from user where user=''; FLUSH PRIVILEGES; EOF
#!/bin/sh # # Keystone basic configuration # Mainly inspired by https://github.com/openstack/keystone/blob/master/tools/sample_data.sh # Modified by Bilel Msekni / Institut Telecom # # Support: [email protected] # License: Apache Software License (ASL) 2.0 # HOST_IP=openstack-ip ADMIN_PASSWORD=openstack-passwd SERVICE_PASSWORD=openstack-passwd export OS_SERVICE_TOKEN=2012 export OS_SERVICE_ENDPOINT="http://${HOST_IP}:35357/v2.0" # Tenants keystone tenant-create --name admin keystone tenant-create --name service # Users keystone user-create --name admin --pass "$ADMIN_PASSWORD" --email [email protected] # Roles keystone role-create --name admin keystone role-create --name _member_ keystone role-create --name KeystoneAdmin keystone role-create --name KeystoneServiceAdmin keystone role-create --name heat_stack_user keystone role-create --name heat_stack_owner # Add Roles to Users in Tenants keystone user-role-add --user admin --role admin --tenant admin keystone user-role-add --user admin --role _member_ --tenant admin keystone user-role-add --user admin --role KeystoneAdmin --tenant admin keystone user-role-add --user admin --role KeystoneServiceAdmin --tenant admin # The Member role is used by Horizon and Swift # Configure service users/roles keystone user-create --name nova --pass $SERVICE_PASSWORD --email [email protected] keystone user-role-add --tenant service --user nova --role admin keystone user-create --name glance --pass "$SERVICE_PASSWORD" --email [email protected] keystone user-role-add --tenant service --user glance --role admin keystone user-create --name neutron --pass "$SERVICE_PASSWORD" --email [email protected] keystone user-role-add --tenant service --user neutron --role admin keystone user-create --name cinder --pass "$SERVICE_PASSWORD" --email [email protected] keystone user-role-add --tenant service --user cinder --role admin keystone user-create --name ceilometer --pass "$SERVICE_PASSWORD" --email [email protected] keystone user-role-add --tenant service --user ceilometer --role admin keystone user-create --name heat --pass "$SERVICE_PASSWORD" --email [email protected] keystone user-role-add --tenant service --user heat --role admin keystone user-create --name swift --pass "$SERVICE_PASSWORD" --email [email protected] keystone user-role-add --tenant service --user swift --role adminkeystone_endpoints_basic.sh:
#!/bin/sh # # Keystone basic Endpoints # Mainly inspired by https://github.com/openstack/keystone/blob/master/tools/sample_data.sh # Modified by Bilel Msekni / Institut Telecom # # Support: [email protected] # License: Apache Software License (ASL) 2.0 # # Host address HOST_IP=openstack-ip EXT_HOST_IP=openstack-ip # Mysql definitions MYSQL_USER=keystone MYSQL_DATABASE=keystone MYSQL_HOST=openstack-ip MYSQL_PASSWORD=openstack-passwd # Keystone definitions KEYSTONE_REGION=RegionOne export SERVICE_TOKEN=2012 export SERVICE_ENDPOINT="http://openstack-ip:35357/v2.0" while getopts "u:D:p:m:K:R:E:T:vh" opt; do case $opt in u) MYSQL_USER=$OPTARG ;; D) MYSQL_DATABASE=$OPTARG ;; p) MYSQL_PASSWORD=$OPTARG ;; m) MYSQL_HOST=$OPTARG ;; K) MASTER=$OPTARG ;; R) KEYSTONE_REGION=$OPTARG ;; E) export SERVICE_ENDPOINT=$OPTARG ;; T) export SERVICE_TOKEN=$OPTARG ;; v) set -x ;; h) cat <<EOF Usage: $0 [-m mysql_hostname] [-u mysql_username] [-D mysql_database] [-p mysql_password] [-K keystone_master ] [ -R keystone_region ] [ -E keystone_endpoint_url ] [ -T keystone_token ] Add -v for verbose mode, -h to display this message. EOF exit 0 ;; \?) echo "Unknown option -$OPTARG" >&2 exit 1 ;; :) echo "Option -$OPTARG requires an argument" >&2 exit 1 ;; esac done if [ -z "$KEYSTONE_REGION" ]; then echo "Keystone region not set. Please set with -R option or set KEYSTONE_REGION variable." >&2 missing_args="true" fi if [ -z "$SERVICE_TOKEN" ]; then echo "Keystone service token not set. Please set with -T option or set SERVICE_TOKEN variable." >&2 missing_args="true" fi if [ -z "$SERVICE_ENDPOINT" ]; then echo "Keystone service endpoint not set. Please set with -E option or set SERVICE_ENDPOINT variable." >&2 missing_args="true" fi if [ -z "$MYSQL_PASSWORD" ]; then echo "MYSQL password not set. Please set with -p option or set MYSQL_PASSWORD variable." >&2 missing_args="true" fi if [ -n "$missing_args" ]; then exit 1 fi keystone service-create --name nova --type compute --description 'OpenStack Compute Service' keystone service-create --name cinder --type volume --description 'OpenStack Volume Service' keystone service-create --name cinder --type volumev2 --description 'OpenStack Volume Service V2' keystone service-create --name glance --type image --description 'OpenStack Image Service' keystone service-create --name keystone --type identity --description 'OpenStack Identity Service' keystone service-create --name ec2 --type ec2 --description 'OpenStack EC2 service' keystone service-create --name neutron --type network --description 'OpenStack Networking service' keystone service-create --name ceilometer --type metering --description 'OpenStack Metering service' keystone service-create --name heat-cfn --type cloudformation --description 'Heat CloudFormation API' keystone service-create --name heat --type orchestration --description 'Heat Orchestration API' keystone service-create --name swift --type object-store --description 'Swift Object-Store Service' create_endpoint () { case $1 in compute) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"openstack-ip"':8774/v2/$(tenant_id)s' --adminurl 'http://'"openstack-ip"':8774/v2/$(tenant_id)s' --internalurl 'http://'"openstack-ip"':8774/v2/$(tenant_id)s' ;; volume) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"openstack-ip"':8776/v1/$(tenant_id)s' --adminurl 'http://'"openstack-ip"':8776/v1/$(tenant_id)s' --internalurl 'http://'"openstack-ip"':8776/v1/$(tenant_id)s' ;; volumev2) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"openstack-ip"':8776/v2/$(tenant_id)s' --adminurl 'http://'"openstack-ip"':8776/v2/$(tenant_id)s' --internalurl 'http://'"openstack-ip"':8776/v2/$(tenant_id)s' ;; image) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"openstack-ip"':9292/' --adminurl 'http://'"openstack-ip"':9292/' --internalurl 'http://'"openstack-ip"':9292/' ;; identity) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"openstack-ip"':5000/v2.0' --adminurl 'http://'"openstack-ip"':35357/v2.0' --internalurl 'http://'"openstack-ip"':5000/v2.0' ;; ec2) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"openstack-ip"':8773/services/Cloud' --adminurl 'http://'"openstack-ip"':8773/services/Admin' --internalurl 'http://'"openstack-ip"':8773/services/Cloud' ;; network) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"openstack-ip"':9696/' --adminurl 'http://'"openstack-ip"':9696/' --internalurl 'http://'"openstack-ip"':9696/' ;; metering) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"openstack-ip"':8777/' --adminurl 'http://'"openstack-ip"':8777/' --internalurl 'http://'"openstack-ip"':8777/' ;; cloudformation) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"openstack-ip"':8000/v1' --adminurl 'http://'"openstack-ip"':8000/v1' --internalurl 'http://'"openstack-ip"':8000/v1' ;; orchestration) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"openstack-ip"':8004/v1/$(tenant_id)s' --adminurl 'http://'"openstack-ip"':8004/v1/$(tenant_id)s' --internalurl 'http://'"openstack-ip"':8004/v1/$(tenant_id)s' ;; object-store) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"openstack-ip"':8080/v1/AUTH_$(tenant_id)s' --adminurl 'http://'"openstack-ip"':8080' --internalurl 'http://'"openstack-ip"':8080/v1/AUTH_$(tenant_id)s' ;; esac } for i in compute volume volumev2 image identity ec2 network metering cloudformation orchestration object-store; do id=`mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" -ss -e "SELECT id FROM service WHERE type='"$i"';"` || exit 1 create_endpoint $i $id done
#!/bin/sh floatingcidr=$1 netname=testnet source ~/novarc #glance glance image-create --name=cirros --public --container-format=bare --disk-format=qcow2 < ./cirros-0.3.1-x86_64-disk.img sleep 2 status=`glance image-list | grep cirros | awk -F "|" {'print $7'} | awk {'print $1'}` while [ $status != "active" ]; do sleep 1 status=`glance image-list | grep cirros | awk -F "|" {'print $7'} | awk {'print $1'}` done imageid=`glance image-list | grep cirros | awk -F "|" {'print $2'} | awk {'print $1'}` #echo "image $status" #flavor flavor=`nova flavor-list | grep tiny | awk -F "|" {'print $2'} | awk {'print $1'}` #echo "flavor $flavor" #neutron neutron net-create $netname neutron subnet-create --name fixedsubnet $netname 10.10.0.0/24 sleep 2 netid=`neutron net-list | grep $netname | awk -F "|" {'print $2'} | awk {'print $1'}` #echo "$netid" fixsubnetid=`neutron subnet-list | grep fixedsubnet | awk -F "|" {'print $2'} | awk {'print $1'}` #create router neutron router-create testrouter routeid=`neutron router-list | grep testroute | awk -F "|" {'print $2'} | awk {'print $1'}` neutron router-interface-add $routeid $fixsubnetid neutron net-create floatingnet --router:external=true #neutron net-create floatingnet --router:external=true --provider:network_type=vlan --provider:physical_network=physnet --provider:segmentation_id=200 neutron subnet-create --name floatingsubnet floatingnet $floatingcidr/24 floatingnetid=`neutron net-list | grep floatingnet | awk -F "|" {'print $2'} | awk {'print $1'}` neutron router-gateway-set $routeid $floatingnetid #neutron security-group-rule-create --direction ingress --protocol icmp $floatingnetid --remote-ip-prefix 0.0.0.0/0 #neutron security-group-rule-create --direction ingress --protocol tcp $floatingnetid --remote-ip-prefix 0.0.0.0/0 #create vm nova boot --flavor $flavor --image cirros --nic net-id=$netid testvm #sleep 3 #status=`nova list | grep testvm | awk -F "|" {'print $4'} | awk {'print $1'}` #echo "$status" #while [ $status != "ACTIVE" ]; do # if [ $status = "ERROR" ]; then # echo "vm is $status,please check it." # else # sleep 1 # status=`nova list | grep name | awk -F "|" {'print $4'}` # fi #done #modify tempest.conf #sed -i "s/cirrosimageid/$imageid/g" tempest.conf #sed -i "s/fixednetname/$netname/g" tempest.conf #sed -i "s/floatingnetid/$floatingnetid/g" tempest.conf #sed -i "s/floatingcidr/$floatingcidr/g" tempest.conf #sed -i "s/routeid/$routeid/g" tempest.conf