aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2017-02-03 16:54:48 +0100
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-02-03 16:54:48 +0100
commit47d65005256166cdeb795debbce327fcbf155c48 (patch)
treecda3f13a3d98a057a319dde3e2fc8afbde7d1a14
parenta79578988cb2bc7e08a516aca93a3816d996072d (diff)
downloadrumba-47d65005256166cdeb795debbce327fcbf155c48.tar.gz
rumba-47d65005256166cdeb795debbce327fcbf155c48.zip
rhumba: Add Ouroboros commands and SSH helpers
This adds initial support for Ouroboros. It installs and sets up the stack, and binds ap names to names. It also moves the SSH helper functions to common ground, so that every file can use them.
-rw-r--r--emulab_support.py109
-rw-r--r--ouroboros_support.py42
-rwxr-xr-xrhumba.py8
-rw-r--r--ssh_support.py156
4 files changed, 206 insertions, 109 deletions
diff --git a/emulab_support.py b/emulab_support.py
index db779a9..99a903c 100644
--- a/emulab_support.py
+++ b/emulab_support.py
@@ -19,24 +19,15 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
-import socket
-import paramiko
-import time
import os
+import time
import re
from ast import literal_eval
-import configparser
+from ssh_support import *
import warnings
warnings.filterwarnings("ignore")
-def get_ssh_client():
- ssh_client = paramiko.SSHClient()
- ssh_client.load_system_host_keys()
- ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
-
- return ssh_client
-
def ops_server(testbed):
'''
Return server name of the ops-server (is testbed specific)
@@ -59,73 +50,6 @@ def full_name(testbed, node_name):
return node_name + '.' + testbed.exp_name + '.' + \
testbed.proj_name + '.' + testbed.url
-def execute_command(testbed, hostname, command, time_out = 3):
- '''
- Remote execution of a list of shell command on hostname. By
- default this function will exit (timeout) after 3 seconds.
-
- @param testbed: testbed info
- @param hostname: host name or ip address of the node
- @param command: *nix shell command
- @param time_out: time_out value in seconds, error will be generated if
- no result received in given number of seconds, the value None can
- be used when no timeout is needed
-
- @return: stdout resulting from the command
- '''
- ssh_client = get_ssh_client()
-
- try:
- ssh_client.connect(hostname, 22,
- testbed.username, testbed.password,
- look_for_keys = True, timeout = time_out)
- stdin, stdout, stderr = ssh_client.exec_command(command)
- err = str(stderr.read()).strip('b\'\"\\n')
- if err != "":
- print(err)
- output = str(stdout.read()).strip('b\'\"\\n')
- ssh_client.close()
-
- return output
-
- except Exception as e:
- print(str(e))
- return
-
-def copy_file_to_testbed(testbed, hostname, text, file_name):
- '''
- Write a string to a given remote file.
- Overwrite the complete file if it already exists!
-
- @param testbed: testbed info
- @param hostname: host name or ip address of the node
- @param text: string to be written in file
- @param file_name: file name (including full path) on the host
- '''
- ssh_client = get_ssh_client()
-
- try:
- ssh_client.connect(hostname, 22,
- testbed.username,
- testbed.password,
- look_for_keys=True)
-
- cmd = "touch " + file_name + \
- "; chmod a+rwx " + file_name
-
- stdin, stdout, stderr = ssh_client.exec_command(cmd)
- err = str(stderr.read()).strip('b\'\"\\n')
- if err != "":
- print(err)
-
- sftp_client = ssh_client.open_sftp()
- remote_file = sftp_client.open(file_name, 'w')
-
- remote_file.write(text)
- remote_file.close()
-
- except Exception as e:
- print(str(e))
def get_experiment_list(testbed, project_name = None):
'''
@@ -298,32 +222,3 @@ def complete_experiment_graph(testbed, nodes, p2plinks):
link.int_b.ip == item[1]:
link.int_b.name = item[0]
node.full_name = full_name(testbed, node.name)
-
-def setup_vlan(testbed, node_name, vlan_id, int_name):
- '''
- Gets the interface (ethx) to link mapping
-
- @param testbed: testbed info
- @param node_name: the node to create the VLAN on
- @param vlan_id: the VLAN id
- @param int_name: the name of the interface
- '''
- print("Setting up VLAN on node " + node_name)
-
- node_full_name = full_name(node_name, testbed)
- cmd = "sudo ip link add link " + \
- str(int_name) + \
- " name " + str(int_name) + \
- "." + str(vlan_id) + \
- " type vlan id " + str(vlan_id)
- execute_command(testbed, node_full_name, cmd)
- cmd = "sudo ifconfig " + \
- str(int_name) + "." + \
- str(vlan_id) + " up"
- execute_command(node_full_name, cmd, testbed)
- cmd = "sudo ethtool -K " + \
- str(int_name) + " rxvlan off"
- execute_command(node_full_name, cmd, testbed)
- cmd = "sudo ethtool -K " + \
- str(int_name) + " txvlan off"
- execute_command(node_full_name, cmd, testbed)
diff --git a/ouroboros_support.py b/ouroboros_support.py
new file mode 100644
index 0000000..061c097
--- /dev/null
+++ b/ouroboros_support.py
@@ -0,0 +1,42 @@
+#
+# Commands to instruct Ouroboros
+#
+# Sander Vrijders <sander.vrijders@intec.ugent.be>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301 USA
+
+import ssh_support as ssh
+
+def setup_ouroboros(testbed, nodes):
+ cmds = list()
+
+ cmds.append("sudo apt-get update")
+ cmds.append("sudo apt-get install cmake protobuf-c-compiler git --yes")
+ cmds.append("sudo rm -r ~/ouroboros/build")
+ cmds.append("cd ~/ouroboros; sudo ./install_release.sh")
+ cmds.append("sudo nohup irmd > /dev/null &")
+
+ for node in nodes:
+ ssh.execute_commands(testbed, node.full_name, cmds, time_out = None)
+ return
+
+def bind_names(testbed, nodes):
+ for node in nodes:
+ cmds = list()
+ for name, ap in node.bindings.items():
+ cmds.append("irm b ap " + ap + " n " + name)
+
+ ssh.execute_commands(testbed, node.full_name, cmds, time_out = None)
diff --git a/rhumba.py b/rhumba.py
index 843b319..fbcfc8f 100755
--- a/rhumba.py
+++ b/rhumba.py
@@ -23,6 +23,7 @@ import emulab_support as es
import jfed_support as js
import abc
import getpass
+import ouroboros_support as our
# Represents generic testbed info
#
@@ -312,7 +313,10 @@ class OuroborosExperiment(Experiment):
def run(self):
print("[Ouroboros experiment] start")
+ print("Creating resources...")
Experiment.run(self)
- for node in self.nodes:
- print(node.full_name)
+ print("Setting up Ouroboros...")
+ our.setup_ouroboros(self.testbed, self.nodes)
+ print("Binding names...")
+ our.bind_names(self.testbed, self.nodes)
print("[Ouroboros experiment] end")
diff --git a/ssh_support.py b/ssh_support.py
new file mode 100644
index 0000000..6bc892f
--- /dev/null
+++ b/ssh_support.py
@@ -0,0 +1,156 @@
+#
+# SSH support for Rhumba
+#
+# Sander Vrijders <sander.vrijders@intec.ugent.be>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301 USA
+
+import paramiko
+
+def get_ssh_client():
+ ssh_client = paramiko.SSHClient()
+ ssh_client.load_system_host_keys()
+ ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+
+ return ssh_client
+
+def execute_commands(testbed, hostname, commands, time_out = 3):
+ '''
+ Remote execution of a list of shell command on hostname. By
+ default this function will exit (timeout) after 3 seconds.
+
+ @param testbed: testbed info
+ @param hostname: host name or ip address of the node
+ @param command: *nix shell command
+ @param time_out: time_out value in seconds, error will be generated if
+ no result received in given number of seconds, the value None can
+ be used when no timeout is needed
+ '''
+ ssh_client = get_ssh_client()
+
+ try:
+ ssh_client.connect(hostname, 22,
+ testbed.username, testbed.password,
+ look_for_keys = True, timeout = time_out)
+ for command in commands:
+ stdin, stdout, stderr = ssh_client.exec_command(command)
+ err = str(stderr.read()).strip('b\'\"\\n')
+ if err != "":
+ err_array = err.split('\\n')
+ for erra in err_array:
+ print(erra)
+ ssh_client.close()
+
+ except Exception as e:
+ print(str(e))
+ return
+
+def execute_command(testbed, hostname, command, time_out = 3):
+ '''
+ Remote execution of a list of shell command on hostname. By
+ default this function will exit (timeout) after 3 seconds.
+
+ @param testbed: testbed info
+ @param hostname: host name or ip address of the node
+ @param command: *nix shell command
+ @param time_out: time_out value in seconds, error will be generated if
+ no result received in given number of seconds, the value None can
+ be used when no timeout is needed
+
+ @return: stdout resulting from the command
+ '''
+ ssh_client = get_ssh_client()
+
+ try:
+ ssh_client.connect(hostname, 22,
+ testbed.username, testbed.password,
+ look_for_keys = True, timeout = time_out)
+ stdin, stdout, stderr = ssh_client.exec_command(command)
+ err = str(stderr.read()).strip('b\'\"\\n')
+ if err != "":
+ print(err)
+ output = str(stdout.read()).strip('b\'\"\\n')
+ ssh_client.close()
+
+ return output
+
+ except Exception as e:
+ print(str(e))
+ return
+
+def copy_file_to_testbed(testbed, hostname, text, file_name):
+ '''
+ Write a string to a given remote file.
+ Overwrite the complete file if it already exists!
+
+ @param testbed: testbed info
+ @param hostname: host name or ip address of the node
+ @param text: string to be written in file
+ @param file_name: file name (including full path) on the host
+ '''
+ ssh_client = get_ssh_client()
+
+ try:
+ ssh_client.connect(hostname, 22,
+ testbed.username,
+ testbed.password,
+ look_for_keys=True)
+
+ cmd = "touch " + file_name + \
+ "; chmod a+rwx " + file_name
+
+ stdin, stdout, stderr = ssh_client.exec_command(cmd)
+ err = str(stderr.read()).strip('b\'\"\\n')
+ if err != "":
+ print(err)
+
+ sftp_client = ssh_client.open_sftp()
+ remote_file = sftp_client.open(file_name, 'w')
+
+ remote_file.write(text)
+ remote_file.close()
+
+ except Exception as e:
+ print(str(e))
+
+def setup_vlan(testbed, node_name, vlan_id, int_name):
+ '''
+ Gets the interface (ethx) to link mapping
+
+ @param testbed: testbed info
+ @param node_name: the node to create the VLAN on
+ @param vlan_id: the VLAN id
+ @param int_name: the name of the interface
+ '''
+ print("Setting up VLAN on node " + node_name)
+
+ node_full_name = full_name(node_name, testbed)
+ cmd = "sudo ip link add link " + \
+ str(int_name) + \
+ " name " + str(int_name) + \
+ "." + str(vlan_id) + \
+ " type vlan id " + str(vlan_id)
+ execute_command(testbed, node_full_name, cmd)
+ cmd = "sudo ifconfig " + \
+ str(int_name) + "." + \
+ str(vlan_id) + " up"
+ execute_command(node_full_name, cmd, testbed)
+ cmd = "sudo ethtool -K " + \
+ str(int_name) + " rxvlan off"
+ execute_command(node_full_name, cmd, testbed)
+ cmd = "sudo ethtool -K " + \
+ str(int_name) + " txvlan off"
+ execute_command(node_full_name, cmd, testbed)