aboutsummaryrefslogtreecommitdiff
path: root/rumba/model.py
diff options
context:
space:
mode:
Diffstat (limited to 'rumba/model.py')
-rw-r--r--rumba/model.py130
1 files changed, 56 insertions, 74 deletions
diff --git a/rumba/model.py b/rumba/model.py
index 39528be..20f8215 100644
--- a/rumba/model.py
+++ b/rumba/model.py
@@ -31,7 +31,6 @@ import time
import shutil
import rumba.log as log
-from rumba import ssh_support
logger = log.get_logger(__name__)
@@ -88,7 +87,8 @@ class Testbed(object):
@abc.abstractmethod
def swap_in(self, experiment):
- raise Exception('swap_in() not implemented')
+ for node in experiment.nodes:
+ node.executor = self.executor
@abc.abstractmethod
def swap_out(self, experiment):
@@ -245,6 +245,9 @@ class Node(object):
if hasattr(dif, 'policy'): # check if the dif supports policies
self.policies[dif] = policies.get(dif, Policy(dif, self))
+ self.executor = None # will be set by testbed on swap_in
+ self.startup_command = None # will be set by prototype
+
self._validate()
def get_ipcp_by_dif(self, dif):
@@ -328,88 +331,34 @@ class Node(object):
def get_policy(self, dif):
return self.policies[dif]
- def execute_commands(self, commands, time_out=3, use_proxy=False):
- # Ssh_config is used twice since it doubles as testbed info
- # (it holds fields username and password)
- if use_proxy:
- return ssh_support.execute_proxy_commands(
- self.ssh_config,
- self.ssh_config,
- commands,
- time_out
- )
- # else:
- return ssh_support.execute_commands(
- self.ssh_config,
- self.ssh_config,
- commands,
- time_out
- )
-
- def execute_command(self, command, time_out=3,
- use_proxy=False, as_root=False):
- # Ssh_config is used twice since it doubles as testbed info
- # (it holds fields username and password)
- if as_root:
- if self.ssh_config.username != 'root':
- command = "sudo %s" % command
-
- if use_proxy:
- return ssh_support.execute_proxy_command(
- self.ssh_config,
- self.ssh_config,
- command,
- time_out
- )
- # else:
- return ssh_support.execute_command(
- self.ssh_config,
- self.ssh_config,
- command,
- time_out
- )
+ def execute_commands(self, commands, as_root=False, time_out=3,
+ use_proxy=False):
+ return self.executor.execute_commands(self, commands, as_root, time_out)
+
+ def execute_command(self, command, as_root=False, time_out=3,
+ use_proxy=False):
+ return self.executor.execute_command(self, command, as_root, time_out)
def write_text_to_file(self, text, file_name):
- ssh_support.write_text_to_file(
- self.ssh_config,
- self.ssh_config,
- text,
- file_name
- )
+ # ssh_support.write_text_to_file(
+ # self.ssh_config,
+ # self.ssh_config,
+ # text,
+ # file_name
+ # )
+ return
def copy_file(self, path, destination):
- ssh_support.copy_file_to_testbed(
- self.ssh_config,
- self.ssh_config,
- path,
- destination
- )
+ self.executor.copy_file(self, path, destination)
def copy_files(self, paths, destination):
- ssh_support.copy_files_to_testbed(
- self.ssh_config,
- self.ssh_config,
- paths,
- destination
- )
+ self.executor.copy_files(self, paths, destination)
def fetch_files(self, paths, destination, sudo=False):
- ssh_support.copy_files_from_testbed(
- self.ssh_config,
- self.ssh_config,
- paths,
- destination,
- sudo=sudo
- )
+ self.executor.fetch_files(self, paths, destination, sudo)
def fetch_file(self, path, destination, sudo=False):
- ssh_support.copy_file_from_testbed(
- self.ssh_config,
- self.ssh_config,
- path,
- destination,
- sudo=sudo
- )
+ self.executor.fetch_files(self, path, destination, sudo)
def set_link_state(self, ipcp, state):
self.execute_command('ip link set dev ' + ipcp.ifname + ' ' + state,
@@ -869,6 +818,10 @@ class Experiment(object):
end = time.time()
logger.info("Install took %.2f seconds", end - start)
+ def set_startup_command(self, command):
+ for node in self.nodes:
+ node.startup_command = command
+
def bootstrap_prototype(self):
start = time.time()
self._bootstrap_prototype()
@@ -912,3 +865,32 @@ class Experiment(object):
self.testbed.swap_out(self)
end = time.time()
logger.info("Swap-out took %.2f seconds", end - start)
+
+
+class Executor:
+ __metaclass__ = abc.ABCMeta
+
+ @abc.abstractmethod
+ def execute_command(self, node, command, as_root=False, time_out=3):
+ # Execute command on a node
+ return
+
+ def execute_commands(self, node, commands, as_root=False, time_out=3):
+ for command in commands:
+ self.execute_command(node, command, as_root, time_out)
+
+ @abc.abstractmethod
+ def copy_file(self, node, path, destination):
+ return
+
+ def copy_files(self, node, paths, destination):
+ for path in paths:
+ self.copy_file(node, path, destination)
+
+ @abc.abstractmethod
+ def fetch_file(self, node, path, destination, sudo=False):
+ return
+
+ def fetch_files(self, node, paths, destination, sudo=False):
+ for path in paths:
+ self.fetch_file(node, path, destination, sudo) \ No newline at end of file