Commit 09e9cce5 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis

hooks: Introduce snf-network-reconfigure

This hook should run on instance-modify-post phase and
will reconfigure the VM's taps based on certain tags.
Just like with firewalling we first check if the instance has
a tag with prefix synnefo:network:<some_nic_ident>:reconfigure.
If the identifier is missing then the reconfiguration will
apply to all NICs. This hook will run only in primary node
of the instance.

Since hooks and runtime environment may differ (due to modifications
without hotplug), we get all the info stored locally. That
is /var/lib/snf-network/<TAP>-env and
/var/run/ganeti/kvm-hypervisor/nics/<INSTANCE>/<NIC_UUID>.

Then we invoke /etc/ganeti/kvm-ifup-custom with the RECONFIGURE
environment variable set to true. If this is set it sources
the already existing env file (and overrides and other environment
variables).

This feature is useful when we want to apply changes that affect
only the hosts environment and not the VM, e.g. firewalls.
To this end we do:

 # gnt-instance add-tags instance synnefo:network:0:protected
 # gnt-instance add-tags instance synnefo:network:0:reconfigure
 # gnt-instance modify --net 0: instance
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
parent 628f4d68
......@@ -554,6 +554,7 @@ get_mode_info () {
# Note that INTERFACE is available only during ifup scripts
function get_info () {
test -n "$RECONFIGURE" && source $STATE_DIR/$INTERFACE-env
get_mode_info $MODE $LINK $INTERFACE
get_ebtables_chains $INTERFACE
get_rev4_info $IP
......
#!/bin/bash
#
# Copyright 2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
source /etc/default/snf-network
source /usr/lib/snf-network/common.sh
# Main starts here
INSTANCE=$GANETI_INSTANCE_NAME
hostname=$(hostname -f)
# Exit if we do not have instance name.
# It should be exported to hooks for instance related opcodes.
if [ -z "$INSTANCE" ]; then
exit 0
fi
# Run only in primary node of instance
if [ "$GANETI_INSTANCE_PRIMARY" != "$hostname" ]; then
exit 0
fi
# This runs only for instance modification
if [ "x$GANETI_OP_CODE" != "xOP_INSTANCE_SET_PARAMS" ]; then
exit 0
fi
log "Reconfiguring $INSTANCE"
KVM_NIC_DIR=/var/run/ganeti/kvm-hypervisor/nic/$INSTANCE
GANETI_TAP_FILES=$(ls $KVM_NIC_DIR/*-*)
for file in $GANETI_TAP_FILES; do
export INTERFACE=$(cat $file)
export INSTANCE=$INSTANCE
SNF_NETWORK_TAP_ENV=$STATE_DIR/$INTERFACE-env
test -e $SNF_NETWORK_TAP_ENV || continue
log "* Existing $SNF_NETWORK_TAP_ENV found.."
log "* Reconfiguring $INTERFACE of instance $INSTANCE.."
source $SNF_NETWORK_TAP_ENV
cat >> $SNF_NETWORK_TAP_ENV <<EOF
INTERFACE=$INTERFACE
TAGS="$GANETI_INSTANCE_TAGS"
EOF
ifprefixindex="synnefo:network:$INTERFACE_INDEX:"
ifprefixname="synnefo:network:$INTERFACE_NAME:"
ifprefixuuid="synnefo:network:$INTERFACE_UUID:"
ifprefix="synnefo:network:"
for tag in $GANETI_INSTANCE_TAGS; do
tag=${tag#$ifprefixindex}
tag=${tag#$ifprefixname}
tag=${tag#$ifprefixuuid}
tag=${tag#$ifprefix}
case $tag in
reconfigure)
RECONFIGURE=true /etc/ganeti/kvm-ifup-custom
break
;;
esac
done
done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment