diff --git a/scripts/cloudserver-aio.sh b/scripts/cloudserver-aio.sh index 6e1410013e..246c390a09 100755 --- a/scripts/cloudserver-aio.sh +++ b/scripts/cloudserver-aio.sh @@ -12,168 +12,457 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# -# (c) 2014, Kevin Carter - - -# Assumptions: -# This assumes that the lab environment will be setup using -# a rackspace cloud server build on the rackspace public cloud. -# The lab will attempt to create the required Volume Groups that -# the lab will want to use as it creates your containers, if -# /dev/xvde is not available all containers will be created using -# the local file system. If /dev/xvde is available it WILL BE -# NUKED and partitioned for the environment. Once the partitioning is -# done the lab will create all of the required containers as well as -# anything else that may be needed prior to running the installation. -# If using LVM you should have NO LESS than 100 GB of consumable space -# on your the /dev/xvde device. If you have less than 100G the installation -# will fail. - -# THIS IS NOT FOR PRODUCTION USE, NOR WILL IT EVER BE. This is a simple -# lab setup tool that will allow you to quickly build an ALL IN ONE -# environment for development purposes. - - set -e -u -v -x -LAB_NAME=${LAB_NAME:-ansible-lxc-rpc-inventory} -LAB_LV_DEVICE=${LAB_LV_DEVICE:-/dev/xvde} -LAB_BRIDGE_INTERFACE=${LAB_BRIDGE_INTERFACE:-br-mgmt} -LAB_MAIN_INTERFACE=${LAB_MAIN_INTERFACE:-eth0} +REPO_URL=${REPO_URL:-"https://github.com/rcbops/ansible-lxc-rpc.git"} +REPO_BRANCH=${REPO_BRANCH:-"master"} +FROZEN_REPO_URL=${FROZEN_REPO:-"http://rpc-slushee.rackspace.com"} +MAX_RETRIES=${MAX_RETRIES:-5} + +apt-get update +apt-get install -y python-dev \ + python2.7 \ + build-essential \ + curl \ + git-core \ + ipython \ + tmux \ + vim \ + vlan \ + bridge-utils \ + lvm2 \ + linux-image-extra-$(uname -r) function key_create(){ ssh-keygen -t rsa -f /root/.ssh/id_rsa -N '' } +# Used to retry process that may fail due to random issues. +function successerator() { + set +e + RETRY=0 + # Set the initial return value to failure + false + + while [ $? -ne 0 -a ${RETRY} -lt ${MAX_RETRIES} ];do + RETRY=$((${RETRY}+1)) + $@ + done + + if [ ${RETRY} -eq ${MAX_RETRIES} ];then + echo "Hit maximum number of retries, giving up..." + exit 1 + fi + set -e +} + +function install_bits() { + successerator ansible-playbook -e @/etc/rpc_deploy/user_variables.yml \ + playbooks/$@ +} + +if [ ! -d "/opt" ];then + mkdir /opt +fi + + +if [ ! "$(swapon -s | grep -v Filename)" ];then + cat > /opt/swap.sh < 100)") - if [ "$ENOUGH_SPACE" == True ];then - apt-get update && apt-get install -y lvm2 - if [ ! "$(echo C | parted ${LAB_LV_DEVICE} p | grep gpt)" ];then - parted -s ${LAB_LV_DEVICE} mktable gpt - parted -s ${LAB_LV_DEVICE} mkpart lvm 0% 90% - parted -s ${LAB_LV_DEVICE} mkpart lvm 90% 100% - fi - if [ ! "$(pvs | grep '/dev/xvde1')" ];then - pvcreate ${LAB_LV_DEVICE}1 - vgcreate lxc ${LAB_LV_DEVICE}1 - fi - if [ ! "$(pvs | grep '/dev/xvde2')" ];then - pvcreate ${LAB_LV_DEVICE}2 - vgcreate cinder-volumes ${LAB_LV_DEVICE}2 - fi - else - CINDER="/opt/cinder.img" - if [ ! "$(losetup -a | grep /opt/cinder.img)" ];then - LOOP=$(losetup -f) - dd if=/dev/zero of=${CINDER} bs=1 count=0 seek=1000G - losetup ${LOOP} ${CINDER} - pvcreate ${LOOP} - vgcreate cinder-volumes ${LOOP} - pvscan - fi +# Get the source +if [ -d "/opt/ansible-lxc-rpc" ];then + rm -rf "/opt/ansible-lxc-rpc" +fi +git clone "${REPO_URL}" "/opt/ansible-lxc-rpc" + +pushd /opt/ansible-lxc-rpc + git checkout "${REPO_BRANCH}" + # Copy the base etc files + if [ -d "/etc/rpc_deploy" ];then + rm -rf "/etc/rpc_deploy" fi -fi + cp -R /opt/ansible-lxc-rpc/etc/rpc_deploy /etc/ + # Install pip + curl ${FROZEN_REPO_URL}/downloads/get-pip.py | python + # Install requirements + pip install -r /opt/ansible-lxc-rpc/requirements.txt + # Generate the passwords + /opt/ansible-lxc-rpc/scripts/pw-token-gen.py --file /etc/rpc_deploy/user_variables.yml +popd -# Get modern pip -curl https://bootstrap.pypa.io/get-pip.py | python +cat > /etc/rpc_deploy/user_variables.yml < /etc/rpc_deploy/rpc_user_config.yml < /etc/network/interfaces.d/aio-bridges.cfg < /etc/update-motd.d/00-rpc-notice<< EOF +#!/usr/bin/env bash +echo "" +echo "############ RPC DEPLOYMENT #############" +echo "A new kernel was installed on this system. you will" +echo "need to re-bootstrap Galera to get the cluster operataional." +echo "from the /opt/ansible-lxc-rpc/rpc_deployment directory execute:" +echo "" +echo "ansible-playbook -e @/etc/rpc_deploy/user_variables.yml playbooks/infrastructure/galera-startup.yml" +EOF +chmod +x /etc/update-motd.d/00-rpc-notice +shutdown -r now +fi diff --git a/scripts/rpc9.0.0-aio-heat-template.yml b/scripts/rpc9.0.0-aio-heat-template.yml new file mode 100644 index 0000000000..5b35e51ac3 --- /dev/null +++ b/scripts/rpc9.0.0-aio-heat-template.yml @@ -0,0 +1,91 @@ +# Copyright 2014, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +heat_template_version: 2013-05-23 +description: Heat template to deploy Rackspace Private Cloud v9 +parameters: + ssh_key_name: + type: string + description: Name of a Key Pair to enable SSH access to the instance + image_name: + type: string + description: Name of image to use for server + flavor_name: + type: string + description: Name Flavor to use for server + server_name: + type: string + default: RPCv9.0.0-AIO + description: The Instance Name + install_script_url: + type: string + default: https://raw.githubusercontent.com/rcbops/ansible-lxc-rpc/master/scripts/cloudserver-aio.sh + description: The aio script installation URL + frozen_repo_url: + type: string + default: http://rpc-slushee.rackspace.com + description: URL to the frozen + repo_url: + type: string + default: https://github.com/rcbops/ansible-lxc-rpc.git + description: The repository URL + repo_branch: + type: string + default: master + description: The repository branch + net_id: + type: string + description: ID of Neutron network into which servers get deployed + sec_group: + type: string + description: Name of the security group +outputs: + RPCAIO_public_ip: + description: The public IP address of the newly configured Server. + value: { get_attr: [ RPCAIO, first_address ] } + RPCAIO_password: + description: The password for all the things. + value: secrete +resources: + RPCAIO_port: + type: OS::Neutron::Port + properties: + network_id: { get_param: net_id } + security_groups: [{ get_param: sec_group }] + RPCAIO: + type: OS::Nova::Server + properties: + flavor: { get_param: flavor_name } + image: { get_param: image_name } + name: { get_param: server_name } + key_name: { get_param: ssh_key_name } + networks: + - port: { get_resource: RPCAIO_port } + user_data: + str_replace: + params: + "%install_script_url%": { get_param: install_script_url } + "%repo_url%": { get_param: repo_url } + "%repo_branch%": { get_param: repo_branch } + "%frozen_repo_url%": { get_param: frozen_repo_url } + template: | + #!/usr/bin/env bash + export REPO_URL="%repo_url%" + export REPO_BRANCH="%repo_branch%" + export FROZEN_REPO_URL="%frozen_repo_url%" + apt-get update + apt-get -y install wget + pushd /opt + bash <(wget -O- "%install_script_url%") + popd diff --git a/scripts/rpc9.0.0-aio-rax-heat-template.yml b/scripts/rpc9.0.0-aio-rax-heat-template.yml new file mode 100644 index 0000000000..0f7323a386 --- /dev/null +++ b/scripts/rpc9.0.0-aio-rax-heat-template.yml @@ -0,0 +1,78 @@ +# Copyright 2014, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +heat_template_version: 2013-05-23 +description: Heat template to deploy Rackspace Private Cloud v9 +parameters: + ssh_key_name: + type: string + description: Name of a Key Pair to enable SSH access to the instance + image_name: + type: string + description: Name of image to use for server + flavor_name: + type: string + description: Name Flavor to use for server + server_name: + type: string + default: RPCv9.0.0-AIO + description: The Instance Name + install_script_url: + type: string + default: https://raw.githubusercontent.com/rcbops/ansible-lxc-rpc/master/scripts/cloudserver-aio.sh + description: The aio script installation URL + frozen_repo_url: + type: string + default: http://rpc-slushee.rackspace.com + description: URL to the frozen + repo_url: + type: string + default: https://github.com/rcbops/ansible-lxc-rpc.git + description: The repository URL + repo_branch: + type: string + default: master + description: The repository branch +outputs: + RPCAIO_public_ip: + description: The public IP address of the newly configured Server. + value: { get_attr: [ RPCAIO, first_address ] } + RPCAIO_password: + description: The password for all the things. + value: secrete +resources: + RPCAIO: + type: OS::Nova::Server + properties: + flavor: { get_param: flavor_name } + image: { get_param: image_name } + name: { get_param: server_name } + key_name: { get_param: ssh_key_name } + user_data: + str_replace: + params: + "%install_script_url%": { get_param: install_script_url } + "%repo_url%": { get_param: repo_url } + "%repo_branch%": { get_param: repo_branch } + "%frozen_repo_url%": { get_param: frozen_repo_url } + template: | + #!/usr/bin/env bash + export REPO_URL="%repo_url%" + export REPO_BRANCH="%repo_branch%" + export FROZEN_REPO_URL="%frozen_repo_url%" + apt-get update + apt-get -y install wget + pushd /opt + bash <(wget -O- "%install_script_url%") + popd