Synergy doesn't need extra tools to create VMs into the private or shared quota but they are created in the standard OpenStack way (i.e. shell and dashboard). For example:
# openstack server create <options>
By default, the VMs are instantiated into the private quota. To select the shared quota, is needed to place special keys in the local user data file and pass it through the--user-data <user-data-file> parameter at instance creation:
A virtual machine instantiated into the shared quota is deleted by Synergy when its time to live (TTL) is expired. A mechanism, based on TTL expiration, that allows you to execute automated tasks (i.e. exporting data, turning off services) in your instance before Synergy deletes it is provided through the following example.
This mechanism can be used with version greater or equal of:
Synergy version: service 1.5.3, scheduler 2.6.0
Operating Systems: CentOS 7, Ubuntu 14.04
OpenStack versions: Ocata, Newton
Example
Before you begin make sure you could access to the Internet from your virtual machine.
Creating personal script
Define in an executable bash script any actions you want to perform before your VM is deleted from the shared quota. Of course, script commands must be executable by the O.S. that will be installed on the virtual machine.
In this example my_script.sh simply mounts a volume and creates the synergy_test_result.txt file where it will be printed execution date and time of my_script.sh file.
Creating the wrapper script
This bash script creates the user data that will be used during VM contextualization phase (contextualisation phase configure a VM after it has been installed).
Create an executable bash script that contains the same content of generate_userdata.sh script.
Generating user data file
To generate user data file run the following command:
Specify how many minutes before TTL expiration your script will run (my_script.sh). The default value is 5 minutes.
Enter user data file name.
If everything is fine a .txt file (my_userdata.txt) in the current directory is created.
Creating a volume
To create the volume that will be mounted by the script my_script.sh run the following commands:
Creating Virtual Machine
To create a VM into the shared quota follow the paragraph "How to use Synergy".
Attaching a volume
Verify operation
Access to your virtual machine and check the log.txt file in the new directory /root/synergy_scripts. It should has a content like this:
In the example the user script (my_script.sh) was executed 5 minutes before the TTL expired and into the file /mnt/volume/synergy_test_result.txt was printed:
# cat generate_userdata.sh
#!/bin/bash
script=$(cat $1)
ex_1="false"
while [ $ex_1 != "true" ] ; do
echo -n "Do you want to run your script 5 minutes before Synergy deletes your VM from the shared quota (y/n)? "
read answer
if [[ "$answer" = "y" || "$answer" = "n" ]] ; then
ex_1="true"
fi
done
if echo "$answer" | grep -iq "^n" ;then
ex_2="false"
while [ $ex_2 != "true" ] ; do
echo "Please enter your value in minutes, it must be less or equal to TTL"
read input_time
if ! [[ "$input_time" =~ ^[0-9]+$ ]] ; then
echo "The value entered must be a number!"
else
ex_2="true"
fi
done
syn_clock=$input_time
else
syn_clock=5
fi
ex_3="false"
while [ $ex_3 != "true" ] ; do
echo "Please enter user data name:"
read answer
if [[ "$answer" != "" ]] ; then
ex_3="true"
fi
done
userdata_name="$answer.txt"
encoded_user_script=$(echo -n "$script" | base64)
encoded_script_github=$(curl -sL https://raw.githubusercontent.com/indigo-dc/synergy-doc/master/doc/create_scripts.sh | base64)
work_dir=/root/synergy_scripts
cat <<EOF>> $userdata_name
#!/bin/bash
quota=shared
syn_clock=$syn_clock
# Create work dir
mkdir -p $work_dir
# Dencoding user script
echo -n "$encoded_user_script" | base64 -d > $work_dir/$1
chmod 755 $work_dir/$1
user_script_path=$work_dir/$1
# Dencoding github script
echo -n "$encoded_script_github" | base64 -d > $work_dir/create_scripts.sh
chmod 755 $work_dir/create_scripts.sh
$work_dir/create_scripts.sh
rm -rf $work_dir/create_scripts.sh
EOF
# ./generate_userdata.sh my_script.sh
Do you want to run your script 5 minutes before Synergy deletes your VM from the shared quota (y/n)? y
Please enter user data name:
my_userdata
# ls
generate_userdata.sh my_script.sh my_userdata.txt