From ff3e73681b4e1cb725d1d97582318ac6ebf4bc4e Mon Sep 17 00:00:00 2001 From: Alessandro Pilotti Date: Thu, 5 Dec 2013 12:20:55 +0100 Subject: [PATCH] First commit --- configure-devstack.sh | 138 ++++++++++++++ configure-rdo-multi-node.sh | 301 ++++++++++++++++++++++++++++++ configure-ssh-public-key-auth.sh | 28 +++ create-hyperv-external-vswitch.sh | 17 ++ deploy-hyperv-compute.sh | 110 +++++++++++ rename-windows-host.sh | 23 +++ scppass.sh | 19 ++ sshpass.sh | 19 ++ utils.sh | 208 +++++++++++++++++++++ wsmancmd.py | 95 ++++++++++ 10 files changed, 958 insertions(+) create mode 100755 configure-devstack.sh create mode 100755 configure-rdo-multi-node.sh create mode 100755 configure-ssh-public-key-auth.sh create mode 100755 create-hyperv-external-vswitch.sh create mode 100755 deploy-hyperv-compute.sh create mode 100755 rename-windows-host.sh create mode 100755 scppass.sh create mode 100755 sshpass.sh create mode 100755 utils.sh create mode 100755 wsmancmd.py diff --git a/configure-devstack.sh b/configure-devstack.sh new file mode 100755 index 0000000..f8041c3 --- /dev/null +++ b/configure-devstack.sh @@ -0,0 +1,138 @@ +#!/bin/bash +set -e + +if [ $# -ne 5 ]; then + echo "Usage: $0 " + exit 1 +fi + +SSH_KEY_FILE=$1 + +CONTROLLER_VM_NAME=$2 +CONTROLLER_VM_IP=$3 +HYPERV_COMPUTE_VM_NAME=$4 +HYPERV_COMPUTE_VM_IP=$5 + +ADMIN_USER=ubuntu +ADMIN_PASSWORD=Passw0rd + +HYPERV_ADMIN=Administrator +HYPERV_PASSWORD=$ADMIN_PASSWORD + +NOVA_CONF_FILE=/etc/nova/nova.conf +CEILOMETER_CONF_FILE=/etc/ceilometer/ceilometer.conf + +BASEDIR=$(dirname $0) + +. $BASEDIR/utils.sh + +if [ ! -f "$SSH_KEY_FILE" ]; then + ssh-keygen -q -t rsa -f $SSH_KEY_FILE -N "" -b 4096 +fi +SSH_KEY_FILE_PUB=$SSH_KEY_FILE.pub + +echo "Configuring SSH public key authentication" +configure_ssh_pubkey_auth $ADMIN_USER $CONTROLLER_VM_IP $SSH_KEY_FILE_PUB $ADMIN_PASSWORD + +echo "Disabling sudo password prompt" +disable_sudo_password_prompt $ADMIN_USER@$CONTROLLER_VM_IP $SSH_KEY_FILE $ADMIN_PASSWORD + +echo "Setting controller host name" +set_hostname_ubuntu $ADMIN_USER@$CONTROLLER_VM_IP $CONTROLLER_VM_NAME + +echo "Renaming and rebooting Hyper-V host $HYPERV_COMPUTE_VM_IP" +exec_with_retry "$BASEDIR/rename-windows-host.sh $HYPERV_COMPUTE_VM_IP $HYPERV_ADMIN $HYPERV_PASSWORD $HYPERV_COMPUTE_VM_NAME" 30 30 + +echo "Configure networking" +config_openstack_network_adapter_ubuntu $ADMIN_USER@$CONTROLLER_VM_IP eth1 +config_openstack_network_adapter_ubuntu $ADMIN_USER@$CONTROLLER_VM_IP eth2 + +echo "Sync hosts date and time" +update_host_date $ADMIN_USER@$CONTROLLER_VM_IP +# TODO: Sync Windows date and time + +echo "Installing git" +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "sudo apt-get install -y git" + +echo "Unstack if DevStack is already running" +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "[ ! -d devstack ] || (cd devstack && ./unstack.sh)" + +echo "Downloading DevStack" +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "sudo rm -rf devstack" +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "git clone https://github.com/openstack-dev/devstack.git" + +echo "Downloading DevStack localrc" +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "wget https://raw.github.com/cloudbase/devstack-localrc/master/all-in-one-localrc -O devstack/localrc" +run_ssh_cmd_with_retry $SSHUSER_HOST "sudo sed -i 's/^HOST_IP\s*=.\+$/HOST_IP='"$CONTROLLER_VM_IP"'/g' devstack/localrc" + +echo "Running DevStack" +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "cd devstack && ./unstack.sh && ./stack.sh" + +echo "Configuring OpenVSwitch" +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "sudo ovs-vsctl show | grep 'Bridge \"br-eth1\"' > /dev/null || sudo ovs-vsctl add-br br-eth1" +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "sudo ovs-vsctl show | grep 'Port \"eth1\"' > /dev/null || sudo ovs-vsctl add-port br-eth1 eth1" +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "sudo ovs-vsctl show | grep 'Port \"eth2\"' > /dev/null || sudo ovs-vsctl add-port br-ex eth2" + +echo "Adding OpenStack vars to .bashrc" +add_openstack_vars_to_bashrc $ADMIN_USER@$CONTROLLER_VM_IP $CONTROLLER_VM_IP + +echo "Install crudini on controller" + +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "git clone https://github.com/pixelb/crudini.git" +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "sudo apt-get install -y python-iniparse" +run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "sudo cp crudini/crudini /usr/local/bin" + +echo "Getting Nova config options for Hyper-V" + +RPC_BACKEND_HOST=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT rabbit_host $NOVA_CONF_FILE` + +if [ "$RPC_BACKEND_HOST" == "localhost" ]; then + RPC_BACKEND_HOST=$CONTROLLER_VM_IP +fi + +RPC_BACKEND_PASSWORD=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT rabbit_password $NOVA_CONF_FILE` + +NEUTRON_URL=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT neutron_url $NOVA_CONF_FILE` +NEUTRON_ADMIN_AUTH_URL=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT neutron_admin_auth_url $NOVA_CONF_FILE` +NEUTRON_ADMIN_TENANT_NAME=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT neutron_admin_tenant_name $NOVA_CONF_FILE` +NEUTRON_ADMIN_USERNAME=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT neutron_admin_username $NOVA_CONF_FILE` +NEUTRON_ADMIN_PASSWORD=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT neutron_admin_password $NOVA_CONF_FILE` + +CEILOMETER=`run_ssh_cmd_with_retry $ADMIN_USER@$CONTROLLER_VM_IP "if [ -f \"$CEILOMETER_CONF_FILE\" ]; then echo 1; fi"` + +if [ -n "$CEILOMETER" ]; then + echo "Getting Ceilometer config options for Hyper-V" + + CEILOMETER_ADMIN_AUTH_URL=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT os_auth_url $CEILOMETER_CONF_FILE` + CEILOMETER_ADMIN_TENANT_NAME=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT os_tenant_name $CEILOMETER_CONF_FILE` + CEILOMETER_ADMIN_USERNAME=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT os_username $CEILOMETER_CONF_FILE` + CEILOMETER_ADMIN_PASSWORD=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT os_password $CEILOMETER_CONF_FILE` + CEILOMETER_METERING_SECRET=`get_openstack_option_value $ADMIN_USER@$CONTROLLER_VM_IP DEFAULT metering_secret $CEILOMETER_CONF_FILE` + + if [ -z "$CEILOMETER_ADMIN_AUTH_URL" ]; then + CEILOMETER_ADMIN_AUTH_URL=$NEUTRON_ADMIN_AUTH_URL + fi +fi + +# TODO: read Glance host/port from nova.conf +GLANCE_HOST=$CONTROLLER_VM_IP +GLANCE_PORT=9292 +RPC_BACKEND_USERNAME=guest +RPC_BACKEND_PORT=5672 +HYPERV_VSWITCH_NAME=external +RPC_BACKEND=RabbitMQ +OPENSTACK_RELEASE=master + +echo "Waiting for WinRM HTTPS port to be available on $HYPERV_COMPUTE_VM_IP" +wait_for_listening_port $HYPERV_COMPUTE_VM_IP 5986 $MAX_WAIT_SECONDS + +$BASEDIR/deploy-hyperv-compute.sh "$HYPERV_COMPUTE_VM_IP" "$HYPERV_ADMIN" "$HYPERV_PASSWORD" \ +"$OPENSTACK_RELEASE" "$HYPERV_VSWITCH_NAME" "$GLANCE_HOST" "$RPC_BACKEND" "$RPC_BACKEND_HOST" \ +"$RPC_BACKEND_USERNAME" "$RPC_BACKEND_PASSWORD" "$NEUTRON_URL" "$NEUTRON_ADMIN_AUTH_URL" \ +"$NEUTRON_ADMIN_TENANT_NAME" "$NEUTRON_ADMIN_USERNAME" "$NEUTRON_ADMIN_PASSWORD" \ +"$CEILOMETER_ADMIN_AUTH_URL" "$CEILOMETER_ADMIN_TENANT_NAME" "$CEILOMETER_ADMIN_USERNAME" \ +"$CEILOMETER_ADMIN_PASSWORD" "$CEILOMETER_METERING_SECRET" + +echo "DevStack configured!" +echo "SSH access:" +echo "ssh -i $SSH_KEY_FILE $ADMIN_USER@$CONTROLLER_VM_IP" diff --git a/configure-rdo-multi-node.sh b/configure-rdo-multi-node.sh new file mode 100755 index 0000000..8badacb --- /dev/null +++ b/configure-rdo-multi-node.sh @@ -0,0 +1,301 @@ +#!/bin/bash +set -e + +if [ $# -lt 8 ]; then + echo "Usage: $0 " + exit 1 +fi + +OPENSTACK_RELEASE=$1 + +SSH_KEY_FILE=$2 + +CONTROLLER_VM_NAME=$3 +CONTROLLER_VM_IP=$4 +NETWORK_VM_NAME=$5 +NETWORK_VM_IP=$6 +QEMU_COMPUTE_VM_NAME=$7 +QEMU_COMPUTE_VM_IP=$8 +HYPERV_COMPUTE_VM_NAME=$9 +HYPERV_COMPUTE_VM_IP=${10} + +#QEMU_COMPUTE_VM_NAMES=(${7//,/ }) +#QEMU_COMPUTE_VM_IPS=(${8//,/ }) +#HYPERV_COMPUTE_VM_NAMES=(${9//,/ }) +#HYPERV_COMPUTE_VM_IPS=(${10//,/ }) + +RDO_ADMIN=root +RDO_ADMIN_PASSWORD=Passw0rd + +HYPERV_ADMIN=Administrator +HYPERV_PASSWORD=$RDO_ADMIN_PASSWORD + +ANSWERS_FILE=packstack_answers.conf +NOVA_CONF_FILE=/etc/nova/nova.conf +CEILOMETER_CONF_FILE=/etc/ceilometer/ceilometer.conf + +DOMAIN=localdomain + +MAX_WAIT_SECONDS=600 + +BASEDIR=$(dirname $0) + +. $BASEDIR/utils.sh + +if [ ! -f "$SSH_KEY_FILE" ]; then + ssh-keygen -q -t rsa -f $SSH_KEY_FILE -N "" -b 4096 +fi +SSH_KEY_FILE_PUB=$SSH_KEY_FILE.pub + +echo "Configuring SSH public key authentication on the RDO hosts" + +configure_ssh_pubkey_auth $RDO_ADMIN $CONTROLLER_VM_IP $SSH_KEY_FILE_PUB $RDO_ADMIN_PASSWORD +configure_ssh_pubkey_auth $RDO_ADMIN $NETWORK_VM_IP $SSH_KEY_FILE_PUB $RDO_ADMIN_PASSWORD +configure_ssh_pubkey_auth $RDO_ADMIN $QEMU_COMPUTE_VM_IP $SSH_KEY_FILE_PUB $RDO_ADMIN_PASSWORD + +echo "Sync hosts date and time" +update_host_date $RDO_ADMIN@$CONTROLLER_VM_IP +update_host_date $RDO_ADMIN@$NETWORK_VM_IP +update_host_date $RDO_ADMIN@$QEMU_COMPUTE_VM_IP +#TODO: sync time on Hyper-V + +if [ -n "$HYPERV_COMPUTE_VM_IP" ]; then + echo "Waiting for WinRM HTTPS port to be available on $HYPERV_COMPUTE_VM_IP" + wait_for_listening_port $HYPERV_COMPUTE_VM_IP 5986 $MAX_WAIT_SECONDS + + echo "Renaming and rebooting Hyper-V host $HYPERV_COMPUTE_VM_IP" + exec_with_retry "$BASEDIR/rename-windows-host.sh $HYPERV_COMPUTE_VM_IP $HYPERV_ADMIN $HYPERV_PASSWORD $HYPERV_COMPUTE_VM_NAME" 30 30 +fi + +config_openstack_network_adapter () { + SSHUSER_HOST=$1 + ADAPTER=$2 + + run_ssh_cmd_with_retry $SSHUSER_HOST "cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$ADAPTER +DEVICE="$ADAPTER" +BOOTPROTO="none" +MTU="1500" +ONBOOT="yes" +EOF" + + run_ssh_cmd_with_retry $SSHUSER_HOST "ifup $ADAPTER" +} + +echo "Configuring networking" + +set_hostname $RDO_ADMIN@$CONTROLLER_VM_IP $CONTROLLER_VM_NAME.$DOMAIN $CONTROLLER_VM_IP + +config_openstack_network_adapter $RDO_ADMIN@$NETWORK_VM_IP eth1 +config_openstack_network_adapter $RDO_ADMIN@$NETWORK_VM_IP eth2 +set_hostname $RDO_ADMIN@$NETWORK_VM_IP $NETWORK_VM_NAME.$DOMAIN $NETWORK_VM_IP + +config_openstack_network_adapter $RDO_ADMIN@$QEMU_COMPUTE_VM_IP eth1 +set_hostname $RDO_ADMIN@$QEMU_COMPUTE_VM_IP $QEMU_COMPUTE_VM_NAME.$DOMAIN $QEMU_COMPUTE_VM_IP + +echo "Validating network configuration" + +set_test_network_config () { + SSHUSER_HOST=$1 + IFADDR=$2 + ACTION=$3 + + if check_interface_exists $SSHUSER_HOST br-eth1; then + IFACE=br-eth1 + else + IFACE=eth1 + fi + + set_interface_ip $SSHUSER_HOST $IFACE $IFADDR $ACTION +} + +TEST_IP_BASE=10.13.8 +NETWORK_VM_TEST_IP=$TEST_IP_BASE.1 +QEMU_COMPUTE_VM_TEST_IP=$TEST_IP_BASE.2 + +set_test_network_config $RDO_ADMIN@$NETWORK_VM_IP $NETWORK_VM_TEST_IP/24 add +set_test_network_config $RDO_ADMIN@$QEMU_COMPUTE_VM_IP $QEMU_COMPUTE_VM_TEST_IP/24 add + +ping_ip $RDO_ADMIN@$NETWORK_VM_IP $QEMU_COMPUTE_VM_TEST_IP +ping_ip $RDO_ADMIN@$QEMU_COMPUTE_VM_IP $NETWORK_VM_TEST_IP + +set_test_network_config $RDO_ADMIN@$NETWORK_VM_IP $NETWORK_VM_TEST_IP/24 del +set_test_network_config $RDO_ADMIN@$QEMU_COMPUTE_VM_IP $QEMU_COMPUTE_VM_TEST_IP/24 del + +# TODO: Check networking between Hyper-V and network +# TODO: Check external network + +echo "Installing RDO RPMs on controller" + +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "yum install -y http://rdo.fedorapeople.org/openstack/openstack-$OPENSTACK_RELEASE/rdo-release-$OPENSTACK_RELEASE.rpm || true" +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "yum install -y openstack-packstack" + +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm || true" +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "yum install -y crudini" + +echo "Generating Packstack answer file" + +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "packstack --gen-answer-file=$ANSWERS_FILE" + +echo "Configuring Packstack answer file" + +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "\ +crudini --set $ANSWERS_FILE general CONFIG_SSH_KEY /root/.ssh/id_rsa.pub && \ +crudini --set $ANSWERS_FILE general CONFIG_NTP_SERVERS 0.pool.ntp.org,1.pool.ntp.org,2.pool.ntp.org,3.pool.ntp.org && \ +crudini --set $ANSWERS_FILE general CONFIG_CINDER_VOLUMES_SIZE 20G && \ +crudini --set $ANSWERS_FILE general CONFIG_NOVA_COMPUTE_HOSTS $QEMU_COMPUTE_VM_IP && \ +crudini --del $ANSWERS_FILE general CONFIG_NOVA_NETWORK_HOST" + +if [ "$OPENSTACK_RELEASE" == "grizzly" ]; then + run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "\ + crudini --set $ANSWERS_FILE general CONFIG_QUANTUM_L3_HOSTS $NETWORK_VM_IP && \ + crudini --set $ANSWERS_FILE general CONFIG_QUANTUM_DHCP_HOSTS $NETWORK_VM_IP && \ + crudini --set $ANSWERS_FILE general CONFIG_QUANTUM_METADATA_HOSTS $NETWORK_VM_IP && \ + crudini --set $ANSWERS_FILE general CONFIG_QUANTUM_OVS_TENANT_NETWORK_TYPE vlan && \ + crudini --set $ANSWERS_FILE general CONFIG_QUANTUM_OVS_VLAN_RANGES physnet1:1000:2000 && \ + crudini --set $ANSWERS_FILE general CONFIG_QUANTUM_OVS_BRIDGE_MAPPINGS physnet1:br-eth1 && \ + crudini --set $ANSWERS_FILE general CONFIG_QUANTUM_OVS_BRIDGE_IFACES br-eth1:eth1" +else + run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "\ + crudini --set $ANSWERS_FILE general CONFIG_NEUTRON_L3_HOSTS $NETWORK_VM_IP && \ + crudini --set $ANSWERS_FILE general CONFIG_NEUTRON_DHCP_HOSTS $NETWORK_VM_IP && \ + crudini --set $ANSWERS_FILE general CONFIG_NEUTRON_METADATA_HOSTS $NETWORK_VM_IP && \ + crudini --set $ANSWERS_FILE general CONFIG_NEUTRON_OVS_TENANT_NETWORK_TYPE vlan && \ + crudini --set $ANSWERS_FILE general CONFIG_NEUTRON_OVS_VLAN_RANGES physnet1:1000:2000 && \ + crudini --set $ANSWERS_FILE general CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS physnet1:br-eth1 && \ + crudini --set $ANSWERS_FILE general CONFIG_NEUTRON_OVS_BRIDGE_IFACES br-eth1:eth1" +fi + +echo "Deploying SSH private key on $CONTROLLER_VM_IP" + +scp -i $SSH_KEY_FILE -o 'PasswordAuthentication no' $SSH_KEY_FILE $RDO_ADMIN@$CONTROLLER_VM_IP:.ssh/id_rsa +scp -i $SSH_KEY_FILE -o 'PasswordAuthentication no' $SSH_KEY_FILE_PUB $RDO_ADMIN@$CONTROLLER_VM_IP:.ssh/id_rsa.pub + +echo "Running Packstack" + +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "packstack --answer-file=$ANSWERS_FILE" + +echo "Additional firewall rules" + +# See https://github.com/stackforge/packstack/commit/ca46227119fd6a6e5b0f1ef19e8967d92a3b1f6c +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "iptables -I INPUT -s $QEMU_COMPUTE_VM_IP/32 -p tcp --dport 9696 -j ACCEPT" +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "iptables -I INPUT -s $NETWORK_VM_IP/32 -p tcp --dport 9696 -j ACCEPT" +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "iptables -I INPUT -s $NETWORK_VM_IP/32 -p tcp --dport 35357 -j ACCEPT" + +if [ -n "$HYPERV_COMPUTE_VM_IP" ]; then + run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "iptables -I INPUT -s $HYPERV_COMPUTE_VM_IP/32 -p tcp --dport 9696 -j ACCEPT" + run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "iptables -I INPUT -s $HYPERV_COMPUTE_VM_IP/32 -p tcp --dport 9292 -j ACCEPT" +fi + +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "service iptables save" + +echo "Disabling Nova API rate limits" +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "crudini --set $NOVA_CONF_FILE DEFAULT api_rate_limit False" + +if [ "$OPENSTACK_RELEASE" == "grizzly" ]; then + echo "Enabling Quantum firewall driver on controller" + run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "sed -i 's/^#\ firewall_driver/firewall_driver/g' /etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini && service quantum-server restart" +else + echo "Enabling Neutron firewall driver on controller" + run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "sed -i 's/^#\ firewall_driver/firewall_driver/g' /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini && service neutron-server restart" +fi + +echo "Set libvirt_type on QEMU/KVM compute node" +run_ssh_cmd_with_retry $RDO_ADMIN@$QEMU_COMPUTE_VM_IP "grep vmx /proc/cpuinfo > /dev/null && crudini --set $NOVA_CONF_FILE DEFAULT libvirt_type kvm || true" + +echo "Applying additional OVS configuration on $NETWORK_VM_IP" + +run_ssh_cmd_with_retry $RDO_ADMIN@$NETWORK_VM_IP "ovs-vsctl list-ports br-ex | grep eth2 || ovs-vsctl add-port br-ex eth2" + +install_3x_kernel () { + SSHUSER_HOST=$1 + run_ssh_cmd_with_retry $SSHUSER_HOST "yum install -y centos-release-xen && yum update -y --disablerepo=* --enablerepo=Xen4CentOS kernel" +} + +#echo "Installing 3.x kernel on network and compute nodes" + +#install_3x_kernel $RDO_ADMIN@$NETWORK_VM_IP +#install_3x_kernel $RDO_ADMIN@$QEMU_COMPUTE_VM_IP + +if [ -n "$HYPERV_COMPUTE_VM_IP" ]; then + GLANCE_HOST=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP general CONFIG_GLANCE_HOST $ANSWERS_FILE` + QPID_HOST=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP general CONFIG_QPID_HOST $ANSWERS_FILE` + QPID_USERNAME=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT qpid_username $NOVA_CONF_FILE` + QPID_PASSWORD=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT qpid_password $NOVA_CONF_FILE` + + if [ "$OPENSTACK_RELEASE" == "grizzly" ]; then + NEUTRON_URL=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT quantum_url $NOVA_CONF_FILE` + NEUTRON_ADMIN_AUTH_URL=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT quantum_admin_auth_url $NOVA_CONF_FILE` + NEUTRON_ADMIN_TENANT_NAME=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT quantum_admin_tenant_name $NOVA_CONF_FILE` + NEUTRON_ADMIN_PASSWORD=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP general CONFIG_QUANTUM_KS_PW $ANSWERS_FILE` + + NEUTRON_ADMIN_USERNAME=quantum + else + NEUTRON_URL=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT neutron_url $NOVA_CONF_FILE` + NEUTRON_ADMIN_AUTH_URL=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT neutron_admin_auth_url $NOVA_CONF_FILE` + NEUTRON_ADMIN_TENANT_NAME=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT neutron_admin_tenant_name $NOVA_CONF_FILE` + NEUTRON_ADMIN_PASSWORD=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP general CONFIG_NEUTRON_KS_PW $ANSWERS_FILE` + + CEILOMETER_ADMIN_AUTH_URL=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT os_auth_url $CEILOMETER_CONF_FILE` + CEILOMETER_ADMIN_TENANT_NAME=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT os_tenant_name $CEILOMETER_CONF_FILE` + CEILOMETER_ADMIN_USERNAME=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT os_username $CEILOMETER_CONF_FILE` + CEILOMETER_ADMIN_PASSWORD=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT os_password $CEILOMETER_CONF_FILE` + CEILOMETER_METERING_SECRET=`get_openstack_option_value $RDO_ADMIN@$CONTROLLER_VM_IP DEFAULT metering_secret $CEILOMETER_CONF_FILE` + + NEUTRON_ADMIN_USERNAME=neutron + fi + + GLANCE_PORT=9292 + QPID_PORT=5672 +fi + +echo "Rebooting Linux nodes to load the new kernel" + +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP reboot +run_ssh_cmd_with_retry $RDO_ADMIN@$NETWORK_VM_IP reboot +run_ssh_cmd_with_retry $RDO_ADMIN@$QEMU_COMPUTE_VM_IP reboot + +if [ -n "$HYPERV_COMPUTE_VM_IP" ]; then + echo "Waiting for WinRM HTTPS port to be available on $HYPERV_COMPUTE_VM_IP" + wait_for_listening_port $HYPERV_COMPUTE_VM_IP 5986 $MAX_WAIT_SECONDS + + HYPERV_VSWITCH_NAME=external + RPC_BACKEND=ApacheQpid + + $BASEDIR/deploy-hyperv-compute.sh $HYPERV_COMPUTE_VM_IP $HYPERV_ADMIN $HYPERV_PASSWORD $OPENSTACK_RELEASE \ + $HYPERV_VSWITCH_NAME $GLANCE_HOST $RPC_BACKEND $QPID_HOST $QPID_USERNAME $QPID_PASSWORD $NEUTRON_URL \ + $NEUTRON_ADMIN_AUTH_URL $NEUTRON_ADMIN_TENANT_NAME $NEUTRON_ADMIN_USERNAME $NEUTRON_ADMIN_PASSWORD \ + $CEILOMETER_ADMIN_AUTH_URL $CEILOMETER_ADMIN_TENANT_NAME $CEILOMETER_ADMIN_USERNAME $CEILOMETER_ADMIN_PASSWORD \ + $CEILOMETER_METERING_SECRET +fi + +echo "Wait for reboot" +sleep 120 + +echo "Waiting for SSH to be available on $CONTROLLER_VM_IP" +wait_for_listening_port $CONTROLLER_VM_IP 22 $MAX_WAIT_SECONDS + +#echo "Restarting Nova services on controller" +#run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "for SVC in \`chkconfig --list | grep openstack-nova | grep ":on" | awk '{ print \$1 }'\`; do service \$SVC restart; done" + +#echo "Restarting Nova services on QEMU/KVM compute node" +#run_ssh_cmd_with_retry $RDO_ADMIN@$QEMU_COMPUTE_VM_IP "for SVC in \`chkconfig --list | grep openstack-nova | grep ":on" | awk '{ print \$1 }'\`; do service \$SVC restart; done" + +#sleep 5 + +#run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "echo 120 > /proc/sys/kernel/softlockup_thresh" + +echo "Validating Nova configuration" +run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "source ./keystonerc_admin && nova service-list | sed -e '$d' | awk '(NR > 3) {print $10}' | sed -rn '/down/q1'" 10 + +if [ "$OPENSTACK_RELEASE" == "grizzly" ]; then + echo "Validating Quantum configuration" + run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "source ./keystonerc_admin && quantum agent-list -f csv | sed -e '1d' | sed -rn 's/\".*\",\".*\",\".*\",\"(.*)\",.*/\1/p' | sed -rn '/xxx/q1'" 10 +else + echo "Validating Neutron configuration" + run_ssh_cmd_with_retry $RDO_ADMIN@$CONTROLLER_VM_IP "source ./keystonerc_admin && neutron agent-list -f csv | sed -e '1d' | sed -rn 's/\".*\",\".*\",\".*\",\"(.*)\",.*/\1/p' | sed -rn '/xxx/q1'" 10 +fi + +echo "RDO installed!" +echo "SSH access:" +echo "ssh -i $SSH_KEY_FILE $RDO_ADMIN@$CONTROLLER_VM_IP" + diff --git a/configure-ssh-public-key-auth.sh b/configure-ssh-public-key-auth.sh new file mode 100755 index 0000000..b6e3faf --- /dev/null +++ b/configure-ssh-public-key-auth.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -e + +if [ $# -ne 4 ]; then + echo "Usage: $0 " + exit 1 +fi + +USERNAME=$1 +HOST=$2 +SSH_KEY_FILE_PUB=$3 +PASSWORD=$4 + +MAX_WAIT_SECONDS=300 + +BASEDIR=$(dirname $0) + +. $BASEDIR/utils.sh + +ssh-keygen -R $HOST + +PUBKEYFILE=`mktemp -u /tmp/ssh_key_pub.XXXXXX` + +wait_for_listening_port $HOST 22 $MAX_WAIT_SECONDS +$BASEDIR/scppass.sh $SSH_KEY_FILE_PUB $USERNAME@$HOST:$PUBKEYFILE "$PASSWORD" +$BASEDIR/sshpass.sh $USERNAME@$HOST "$PASSWORD" "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat $PUBKEYFILE >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && (\[ ! -x /sbin/restorecon \] || restorecon -R -v ~/.ssh)" + + diff --git a/create-hyperv-external-vswitch.sh b/create-hyperv-external-vswitch.sh new file mode 100755 index 0000000..e7ca290 --- /dev/null +++ b/create-hyperv-external-vswitch.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +if [ $# -ne 4 ]; then + echo "Usage: $0 " + exit 1 +fi + +# This is the IP of the interface that will NOT be configured +MGMT_IP=$1 +HYPERV_USER=$2 +HYPERV_PASSWORD=$3 +SWITCH_NAME=$4 + +BASEDIR=$(dirname $0) + +$BASEDIR/wsmancmd.py -U https://$MGMT_IP:5986/wsman -u "$HYPERV_USER" -p "$HYPERV_PASSWORD" powershell -NonInteractive -Command '"if (!(Get-VMSwitch | where {$_.Name -eq \"'$SWITCH_NAME'\"})) {New-VMSwitch -Name \"'$SWITCH_NAME'\" -AllowManagementOS $false -InterfaceAlias (Get-NetAdapter | where {$_.IfIndex -ne ((Get-NetIPAddress -IPAddress \"'$MGMT_IP'\").InterfaceIndex)}).Name}"' + diff --git a/deploy-hyperv-compute.sh b/deploy-hyperv-compute.sh new file mode 100755 index 0000000..6276178 --- /dev/null +++ b/deploy-hyperv-compute.sh @@ -0,0 +1,110 @@ +#!/bin/bash +set -e + +if [ $# -ne 20 ]; then + echo "Usage: $0 \ + \ + \ + \ +" + exit 1 +fi + +HYPERV_COMPUTE_VM_IP=$1 +HYPERV_ADMIN=$2 +HYPERV_PASSWORD=$3 +OPENSTACK_RELEASE=$4 +HYPERV_VSWITCH=$5 +GLANCE_HOST=$6 +RPC_BACKEND=$7 +RPC_BACKEND_HOST=$8 +RPC_BACKEND_USERNAME=$9 +RPC_BACKEND_PASSWORD=${10} +NEUTRON_URL=${11} +NEUTRON_ADMIN_AUTH_URL=${12} +NEUTRON_ADMIN_TENANT_NAME=${13} +NEUTRON_ADMIN_USERNAME=${14} +NEUTRON_ADMIN_PASSWORD=${15} +CEILOMETER_ADMIN_AUTH_URL=${16} +CEILOMETER_ADMIN_TENANT_NAME=${17} +CEILOMETER_ADMIN_USERNAME=${18} +CEILOMETER_ADMIN_PASSWORD=${19} +CEILOMETER_METERING_SECRET=${20} + +GLANCE_PORT=9292 +RPC_BACKEND_PORT=5672 + +BASEDIR=$(dirname $0) + +. $BASEDIR/utils.sh + +echo "Checking prerequisites" + +NOTFOUND=0 +pip freeze | grep pywinrm > /dev/null || NOTFOUND=1 + +if [ "$NOTFOUND" -eq 1 ]; then + echoerr "pywinrm not found. Install with: sudo pip install --pre pywinrm" + exit 1 +fi + +if [ "$RPC_BACKEND" != "RabbitMQ" ] && [ "$RPC_BACKEND" != "ApacheQpid" ]; then + echoerr "Unsupported RPC backend: $RPC_BACKEND" + exit 1 +fi + +if [ "$OPENSTACK_RELEASE" == "grizzly" ]; then + MSI_FILE=HyperVNovaCompute_Grizzly.msi +elif [ "$OPENSTACK_RELEASE" == "havana" ]; then + MSI_FILE=HyperVNovaCompute_Havana.msi +elif [ "$OPENSTACK_RELEASE" == "master" ]; then + MSI_FILE=HyperVNovaCompute_Beta.msi +else + echoerr "Unsupported OpenStack release: $OPENSTACK_RELEASE" + exit 1 +fi + +echo "OpenStack release: $OPENSTACK_RELEASE" + +echo "Configuring external virtual switch on Hyper-V" + +exec_with_retry "$BASEDIR/create-hyperv-external-vswitch.sh $HYPERV_COMPUTE_VM_IP $HYPERV_ADMIN $HYPERV_PASSWORD $HYPERV_VSWITCH" + +echo "Downloading Hyper-V OpenStack Compute installer on $HYPERV_COMPUTE_VM_IP" + +run_wsmancmd_with_retry $HYPERV_COMPUTE_VM_IP $HYPERV_ADMIN $HYPERV_PASSWORD "powershell -NonInteractive Invoke-WebRequest -Uri http://www.cloudbase.it/downloads/$MSI_FILE -OutFile \$ENV:TEMP\\$MSI_FILE" + +echo "Installing Hyper-V OpenStack Compute on $HYPERV_COMPUTE_VM_IP" + +HYPERV_FEATURES="HyperVNovaCompute,iSCSISWInitiator,FreeRDP" + +if [ "$OPENSTACK_RELEASE" == "grizzly" ]; then + if [ -n "$NEUTRON_ADMIN_AUTH_URL" ]; then + HYPERV_FEATURES+=",QuantumHyperVAgent" + fi + + run_wsmancmd_with_retry $HYPERV_COMPUTE_VM_IP $HYPERV_ADMIN $HYPERV_PASSWORD "msiexec /i %TEMP%\\$MSI_FILE /qn /l*v %TEMP%\\HyperVNovaCompute_setup_log.txt \ + ADDLOCAL=$HYPERV_FEATURES GLANCEHOST=$GLANCE_HOST GLANCEPORT=$GLANCE_PORT RPCBACKEND=$RPC_BACKEND \ + RPCBACKENDHOST=$RPC_BACKEND_HOST RPCBACKENDPORT=$RPC_BACKEND_PORT RPCBACKENDUSER=$RPC_BACKEND_USERNAME RPCBACKENDPASSWORD=$RPC_BACKEND_PASSWORD \ + INSTANCESPATH=C:\\OpenStack\\Instances ADDVSWITCH=0 VSWITCHNAME=$HYPERV_VSWITCH USECOWIMAGES=1 LOGDIR=C:\\OpenStack\\Log ENABLELOGGING=1 \ + VERBOSELOGGING=1 QUANTUMURL=$NEUTRON_URL QUANTUMADMINTENANTNAME=$NEUTRON_ADMIN_TENANT_NAME QUANTUMADMINUSERNAME=$NEUTRON_ADMIN_USERNAME \ + QUANTUMADMINPASSWORD=$NEUTRON_ADMIN_PASSWORD QUANTUMADMINAUTHURL=$NEUTRON_ADMIN_AUTH_URL" +else + if [ -n "$NEUTRON_ADMIN_AUTH_URL" ]; then + HYPERV_FEATURES+=",NeutronHyperVAgent" + fi + + if [ -n "$CEILOMETER_ADMIN_AUTH_URL" ]; then + HYPERV_FEATURES+=",CeilometerComputeAgent" + fi + + run_wsmancmd_with_retry $HYPERV_COMPUTE_VM_IP $HYPERV_ADMIN $HYPERV_PASSWORD "msiexec /i %TEMP%\\$MSI_FILE /qn /l*v %TEMP%\\HyperVNovaCompute_setup_log.txt \ + ADDLOCAL=$HYPERV_FEATURES GLANCEHOST=$GLANCE_HOST GLANCEPORT=$GLANCE_PORT RPCBACKEND=$RPC_BACKEND \ + RPCBACKENDHOST=$RPC_BACKEND_HOST RPCBACKENDPORT=$RPC_BACKEND_PORT RPCBACKENDUSER=$RPC_BACKEND_USERNAME RPCBACKENDPASSWORD=$RPC_BACKEND_PASSWORD \ + INSTANCESPATH=C:\\OpenStack\\Instances ADDVSWITCH=0 VSWITCHNAME=$HYPERV_VSWITCH USECOWIMAGES=1 LOGDIR=C:\\OpenStack\\Log ENABLELOGGING=1 \ + VERBOSELOGGING=1 NEUTRONURL=$NEUTRON_URL NEUTRONADMINTENANTNAME=$NEUTRON_ADMIN_TENANT_NAME NEUTRONADMINUSERNAME=$NEUTRON_ADMIN_USERNAME \ + NEUTRONADMINPASSWORD=$NEUTRON_ADMIN_PASSWORD NEUTRONADMINAUTHURL=$NEUTRON_ADMIN_AUTH_URL \ + CEILOMETERADMINTENANTNAME=$CEILOMETER_ADMIN_TENANT_NAME CEILOMETERADMINUSERNAME=$CEILOMETER_ADMIN_USERNAME \ + CEILOMETERADMINPASSWORD=$CEILOMETER_ADMIN_PASSWORD CEILOMETERADMINAUTHURL=$CEILOMETER_ADMIN_AUTH_URL \ + CEILOMETERMETERINGSECRET=$CEILOMETER_METERING_SECRET" +fi diff --git a/rename-windows-host.sh b/rename-windows-host.sh new file mode 100755 index 0000000..832e0fc --- /dev/null +++ b/rename-windows-host.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +if [ $# -ne 4 ]; then + echo "Usage: $0 " + exit 1 +fi + +HOST=$1 +USERNAME=$2 +PASSWORD=$3 +NEW_HOST_NAME=$4 + +BASEDIR=$(dirname $0) + +NOTFOUND=0 +pip freeze | grep pywinrm > /dev/null || NOTFOUND=1 +if [ "$NOTFOUND" -eq 1 ]; then + echoerr "pywinrm not found. Install with: sudo pip install --pre pywinrm" + exit 1 +fi + +$BASEDIR/wsmancmd.py -U https://$HOST:5986/wsman -u $USERNAME -p $PASSWORD 'powershell -NonInteractive -Command "if ([System.Net.Dns]::GetHostName() -ne \"'$NEW_HOST_NAME'\") { Rename-Computer \"'$NEW_HOST_NAME'\" -Restart -Force }"' + diff --git a/scppass.sh b/scppass.sh new file mode 100755 index 0000000..21121d3 --- /dev/null +++ b/scppass.sh @@ -0,0 +1,19 @@ +#!/bin/sh +set -e + +if [ $# -ne 3 ]; then + echo "Usage: $0 " + exit 1 +fi + +SRC=$1 +DEST=$2 +PWD=$3 + +/usr/bin/expect <@ []" + exit 1 +fi + +SSHUSER_HOST=$1 +PWD=$2 +ARGS="${@:3}" + +/usr/bin/expect <&2; } + +exec_with_retry2 () { + MAX_RETRIES=$1 + INTERVAL=$2 + + COUNTER=0 + while [ $COUNTER -lt $MAX_RETRIES ]; do + EXIT=0 + eval '${@:3}' || EXIT=$? + if [ $EXIT -eq 0 ]; then + return 0 + fi + let COUNTER=COUNTER+1 + + if [ -n "$INTERVAL" ]; then + sleep $INTERVAL + fi + done + return $EXIT +} + +exec_with_retry () { + CMD=$1 + MAX_RETRIES=${2-10} + INTERVAL=${3-0} + + exec_with_retry2 $MAX_RETRIES $INTERVAL $CMD +} + +run_wsmancmd_with_retry () { + HOST=$1 + USERNAME=$2 + PASSWORD=$3 + CMD=$4 + + exec_with_retry "$BASEDIR/wsmancmd.py -U https://$HOST:5986/wsman -u $USERNAME -p $PASSWORD $CMD" +} + +wait_for_listening_port () { + HOST=$1 + PORT=$2 + TIMEOUT=$3 + exec_with_retry "nc -z -w$TIMEOUT $HOST $PORT" 10 5 +} + +run_ssh_cmd () { + SSHUSER_HOST=$1 + CMD=$2 + ssh -t -i $SSH_KEY_FILE $SSHUSER_HOST -o 'PasswordAuthentication no' "$CMD" +} + +run_ssh_cmd_with_retry () { + SSHUSER_HOST=$1 + CMD=$2 + INTERVAL=$3 + MAX_RETRIES=10 + + COUNTER=0 + while [ $COUNTER -lt $MAX_RETRIES ]; do + EXIT=0 + run_ssh_cmd $SSHUSER_HOST "$CMD" || EXIT=$? + if [ $EXIT -eq 0 ]; then + return 0 + fi + let COUNTER=COUNTER+1 + + if [ -n "$INTERVAL" ]; then + sleep $INTERVAL + fi + done + return $EXIT +} + +update_host_date () { + SSHUSER_HOST=$1 + run_ssh_cmd_with_retry $SSHUSER_HOST "sudo ntpdate pool.ntp.org" +} + +# TODO: rename to set_hostname_centos +set_hostname () { + SSHUSER_HOST=$1 + FQDN=$2 + IP=$3 + HOSTNAME=${FQDN%%.*} + + run_ssh_cmd_with_retry $SSHUSER_HOST "sed -i 's/^HOSTNAME=.\+$/HOSTNAME=$FQDN/g' /etc/sysconfig/network" + run_ssh_cmd_with_retry $SSHUSER_HOST "sed -r '/$FQDN/d' -i /etc/hosts && echo '$IP $HOSTNAME $FQDN' >> /etc/hosts" + run_ssh_cmd_with_retry $SSHUSER_HOST "hostname $FQDN" + run_ssh_cmd_with_retry $SSHUSER_HOST "service network restart" +} + +set_hostname_ubuntu () { + SSHUSER_HOST=$1 + FQDN=$2 + HOSTNAME=${FQDN%%.*} + + run_ssh_cmd_with_retry $SSHUSER_HOST "sudo sed -i 's/^127.0.1.1\s*.\+$/127.0.1.1\t'"$FQDN"' '"$HOSTNAME"'/g' /etc/hosts" + run_ssh_cmd_with_retry $SSHUSER_HOST "sudo hostname $FQDN" + run_ssh_cmd_with_retry $SSHUSER_HOST "sudo sh -c \"echo $FQDN > /etc/hostname\"" +} + +check_interface_exists () { + SSHUSER_HOST=$1 + IFACE=$2 + + IFACE_EXISTS=0 + run_ssh_cmd_with_retry $SSHUSER_HOST "ifconfig $IFACE 2> /dev/null" || IFACE_EXISTS=1 + return $IFACE_EXISTS +} + +set_interface_ip () { + SSHUSER_HOST=$1 + IFACE=$2 + IFADDR=$3 + ACTION=$4 + + run_ssh_cmd_with_retry $SSHUSER_HOST "ip addr $ACTION $IFADDR dev $IFACE" +} + +ping_ip () { + SSHUSER_HOST=$1 + IP=$2 + + run_ssh_cmd_with_retry $SSHUSER_HOST "ping -c1 $IP" +} + +get_openstack_option_value () { + + SSHUSER_HOST=$1 + SECTION_NAME=$2 + OPTION_NAME=$3 + CONFIG_FILE_PATH=$4 + + # Return an empty result if the value is not found + # TODO: improve the hack that removes the trailing '\r\n' + run_ssh_cmd_with_retry $SSHUSER_HOST "crudini --get $CONFIG_FILE_PATH $SECTION_NAME $OPTION_NAME 2> /dev/null || if [ \"\$?\" == \"1\" ]; then true; else false; fi" | tr -d '\r' +} + +configure_ssh_pubkey_auth () { + USERNAME=$1 + HOST=$2 + SSH_KEY_FILE_PUB=$3 + PASSWORD=$4 + + MAX_WAIT_SECONDS=300 + + PUBKEYFILE=`mktemp -u /tmp/ssh_key_pub.XXXXXX` + + ssh-keygen -R $HOST + + wait_for_listening_port $HOST 22 $MAX_WAIT_SECONDS + exec_with_retry2 10 0 $BASEDIR/scppass.sh $SSH_KEY_FILE_PUB $USERNAME@$HOST:$PUBKEYFILE "$PASSWORD" + exec_with_retry2 10 0 $BASEDIR/sshpass.sh $USERNAME@$HOST "$PASSWORD" "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat $PUBKEYFILE >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && (\[ ! -x /sbin/restorecon \] || restorecon -R -v ~/.ssh)" +} + +disable_sudo_password_prompt () { + SSHUSER_HOST=$1 + SSH_KEY_FILE=$2 + PWD=$3 + + exec_with_retry2 10 0 /usr/bin/expect <> /etc/sudoers'" +expect "password" +send "$PWD\n" +expect eof +EOD +} + +config_openstack_network_adapter_ubuntu () { + SSHUSER_HOST=$1 + ADAPTER=$2 + + run_ssh_cmd_with_retry $SSHUSER_HOST "grep \"iface $ADAPTER\" /etc/network/interfaces || sudo sh -c \"cat << EOF >> /etc/network/interfaces + +auto $ADAPTER +iface $ADAPTER inet manual +up ip link set $ADAPTER up +down ip link set $ADAPTER down +EOF\"" + + run_ssh_cmd_with_retry $SSHUSER_HOST "sudo ifup $ADAPTER" +} + +add_openstack_vars_to_bashrc () { + SSHUSER_HOST=$1 + CONTROLLER_VM_IP=$2 + run_ssh_cmd_with_retry $SSHUSER_HOST "cat << EOF >> ~/.bashrc + +export OS_USERNAME=admin +export OS_TENANT_NAME=admin +export OS_PASSWORD=Passw0rd +export OS_AUTH_URL=http://$CONTROLLER_VM_IP:35357/v2.0/ +EOF" +} + +array_contains () { + local E + for E in "${@:2}"; do [[ "$E" == "$1" ]] && return 0; done + return 1 +} + +array_remove_dups () { + local E + local DEST=($1) + for E in "${@:2}"; do ! array_contains "$E" "${DEST[@]}" && DEST+=("$E"); done + echo "${DEST[@]}" +} diff --git a/wsmancmd.py b/wsmancmd.py new file mode 100755 index 0000000..b6d07a3 --- /dev/null +++ b/wsmancmd.py @@ -0,0 +1,95 @@ +#!/usr/bin/python + +# Copyright 2013 Cloudbase Solutions Srl +# All Rights Reserved. +# +# 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. + +import getopt +import sys + +from winrm import protocol + + +def print_usage(): + print ("%s -U -u -p [cmd_args]" % + sys.argv[0]) + + +def parse_args(): + + username = None + password = None + url = None + cmd = None + + try: + show_usage = False + opts, args = getopt.getopt(sys.argv[1:], "hU:u:p:c:") + for opt, arg in opts: + if opt == "-h": + show_usage = True + if opt == "-U": + url = arg + elif opt == "-u": + username = arg + elif opt == "-p": + password = arg + + cmd = args + + if show_usage or not (url and username and password and cmd): + print_usage() + + except getopt.GetoptError: + print_usage() + + return (url, username, password, cmd) + + +def run_wsman_cmd(url, username, password, cmd): + protocol.Protocol.DEFAULT_TIMEOUT = "PT3600S" + + p = protocol.Protocol(endpoint=url, + transport='plaintext', + username=username, + password=password) + + shell_id = p.open_shell() + + command_id = p.run_command(shell_id, cmd[0], cmd[1:]) + std_out, std_err, status_code = p.get_command_output(shell_id, command_id) + + p.cleanup_command(shell_id, command_id) + p.close_shell(shell_id) + + return (std_out, std_err, status_code) + + +def main(): + exit_code = 0 + + url, username, password, cmd = parse_args() + if not (url and username and password and cmd): + exit_code = 1 + else: + std_out, std_err, exit_code = run_wsman_cmd(url, username, password, + cmd) + sys.stderr.write(std_out) + sys.stderr.write(std_err) + + sys.exit(exit_code) + + +if __name__ == "__main__": + main()