diff options
author | Marco Capitani <m.capitani@nextworks.it> | 2017-04-14 09:45:04 +0200 |
---|---|---|
committer | Marco Capitani <m.capitani@nextworks.it> | 2017-04-14 09:45:04 +0200 |
commit | 1ccea182dbde7cc2b875f8a5e5434b0f7ba822cd (patch) | |
tree | 58ef3799038e8dd5cf60ba0277bd2fcf3fd0f377 /rumba/prototypes/irati.py | |
parent | af692809383b55ec3b9d7cb96e50b553ffbcd496 (diff) | |
parent | a2b315d257e595af10cf55abdcf026c7c0954020 (diff) | |
download | rumba-1ccea182dbde7cc2b875f8a5e5434b0f7ba822cd.tar.gz rumba-1ccea182dbde7cc2b875f8a5e5434b0f7ba822cd.zip |
QEMU: ifname compilation and vm port activation
Diffstat (limited to 'rumba/prototypes/irati.py')
-rw-r--r-- | rumba/prototypes/irati.py | 105 |
1 files changed, 59 insertions, 46 deletions
diff --git a/rumba/prototypes/irati.py b/rumba/prototypes/irati.py index ba8a152..44eadb0 100644 --- a/rumba/prototypes/irati.py +++ b/rumba/prototypes/irati.py @@ -23,6 +23,8 @@ import json import subprocess +import os + import rumba.ssh_support as ssh import rumba.model as mod import rumba.prototypes.irati_templates as irati_templates @@ -53,19 +55,21 @@ class Experiment(mod.Experiment): def setup(self): """Installs IRATI on the vms.""" - cmds = list() - - cmds.append("sudo apt-get update") - cmds.append("sudo apt-get install g++ gcc " - "protobuf-compiler libprotobuf-dev git --yes") - cmds.append("sudo rm -rf ~/irati") - cmds.append("cd && git clone https://github.com/IRATI/stack irati") - cmds.append("cd ~/irati && sudo ./install-from-scratch") - cmds.append("sudo nohup ipcm &> ipcm.log &") - - for node in self.nodes: - ssh.execute_commands(self.testbed, node.ssh_config, - cmds, time_out=None) + setup_irati = False + if setup_irati: + cmds = list() + + cmds.append("sudo apt-get update") + cmds.append("sudo apt-get install g++ gcc " + "protobuf-compiler libprotobuf-dev git --yes") + cmds.append("sudo rm -rf ~/irati") + cmds.append("cd && git clone https://github.com/IRATI/stack irati") + cmds.append("cd ~/irati && sudo ./install-from-scratch") + cmds.append("sudo nohup ipcm &> ipcm.log &") + + for node in self.nodes: + ssh.execute_commands(self.testbed, node.ssh_config, + cmds, time_out=None) def bootstrap_network(self): """Creates the network by enrolling and configuring the nodes""" @@ -73,10 +77,16 @@ class Experiment(mod.Experiment): self.process_node(node) self.enroll_nodes() + def run_experiment(self): + input('Press ENTER to quit.') + def run_prototype(self): print("[IRATI experiment] start") print("Setting up IRATI on the nodes...") self.setup() + self.write_conf() + self.bootstrap_network() + self.run_experiment() print("[IRATI experiment] end") def process_node(self, node): @@ -89,17 +99,19 @@ class Experiment(mod.Experiment): name = node.name gen_files_conf = 'shimeth.%(name)s.*.dif da.map %(name)s.ipcm.conf' % { 'name': name} - if any(name in dif.members for dif in self.dif_ordering): + if any(node in dif.members for dif in self.dif_ordering): gen_files_conf = ' '.join( [gen_files_conf, 'normal.%(name)s.*.dif' % {'name': name}]) + dir_path = os.path.dirname(os.path.abspath(__file__)) gen_files_bin = 'enroll.py' + gen_files_bin_full = os.path.join(dir_path, 'enroll.py') ipcm_components = ['scripting', 'console'] if self.manager: ipcm_components.append('mad') ipcm_components = ', '.join(ipcm_components) - gen_files = ' '.join([gen_files_conf, gen_files_bin]) + gen_files = ' '.join([gen_files_conf, gen_files_bin_full]) sshopts = ('-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' ' -o IdentityFile=buildroot/irati_rsa') @@ -114,16 +126,20 @@ class Experiment(mod.Experiment): 'verb': 'DBG', 'ipcmcomps': ipcm_components} try: + print('DEBUG: executing >> ' + 'scp %(sshopts)s -r -P %(ssh)s ' + '%(genfiles)s %(username)s@localhost:' + % format_args) subprocess.check_call(('scp %(sshopts)s -r -P %(ssh)s ' '%(genfiles)s %(username)s@localhost:' - % format_args).split()) + % format_args), shell=True) except subprocess.CalledProcessError as e: raise Exception(str(e)) # TODO: review ssh opts through ssh support cmds = [self.sudo('hostname %(name)s' % format_args), - self.sudo('chmd a+rw /dev/irati'), + self.sudo('chmod a+rw /dev/irati'), self.sudo('mv %(genfilesconf)s /etc' % format_args), self.sudo('mv %(genfilesbin)s /usr/bin') % format_args] @@ -134,6 +150,10 @@ class Experiment(mod.Experiment): '-c /etc/%(name)s.ipcm.conf -l %(verb)s &> log &' % format_args)] + print('DEBUG: sending node setup via ssh.') + # print('Credentials:') + # print(node.ssh_config.hostname, node.ssh_config.port, + # self.testbed.username, self.testbed.password) ssh_support.execute_commands(self.testbed, node.ssh_config, cmds) def enroll_nodes(self): @@ -159,24 +179,18 @@ class Experiment(mod.Experiment): '--ipcm-conf /etc/%(name)s.ipcm.conf ' '--enrollee-name %(dif)s.%(name)s.IPCP ' '--enroller-name %(dif)s.%(o_name)s.IPCP' - % e_args) + % e_args) + print('DEBUG: sending enrollment operation via ssh.') + # print('Credentials:') + # print(e['enrollee'].ssh_config.hostname, + # e['enrollee'].ssh_config.port, + # self.testbed.username, self.testbed.password) ssh_support.execute_command(self.testbed, e['enrollee'].ssh_config, cmd) - -class ConfBuilder(object): - - def __init__(self, experiment, manager): - self.write_conf(experiment, manager) - - @staticmethod - def write_conf(experiment, manager): - """ - :type experiment: Experiment - :param experiment: the experiment to be configured - :param manager: boolean indicating if a manager is requested - """ + def write_conf(self): + """Write the configuration files""" # Constants and initializations ipcmconfs = dict() difconfs = dict() @@ -186,7 +200,7 @@ class ConfBuilder(object): # TODO: what format are the mappings registered in? Is this ok? app_mappings = [] - for node in experiment.nodes: + for node in self.nodes: app_mappings += [{'name': app, 'dif': dif.name} for app in node.registrations for dif in node.registrations[app]] @@ -195,10 +209,10 @@ class ConfBuilder(object): # Otherwise, assume the standard applications are to be mapped in # the DIF with the highest rank. if len(app_mappings) == 0: - if len(experiment.dif_ordering) > 0: + if len(self.dif_ordering) > 0: for adm in \ irati_templates.da_map_base["applicationToDIFMappings"]: - adm["difName"] = "%s" % (experiment.dif_ordering[-1],) + adm["difName"] = "%s" % (self.dif_ordering[-1],) else: irati_templates.da_map_base["applicationToDIFMappings"] = [] for apm in app_mappings: @@ -211,7 +225,7 @@ class ConfBuilder(object): # and in that case we should add it to the qemu plugin too... # Where should we take it in input? - if manager: + if self.manager: # Add MAD/Manager configuration irati_templates.ipcmconf_base["addons"] = { "mad": { @@ -225,15 +239,15 @@ class ConfBuilder(object): } node_number = 1 - for node in experiment.nodes: # type: mod.Node + for node in self.nodes: # type: mod.Node node2id_map[node.name] = node_number node_number += 1 ipcmconfs[node.name] = copy.deepcopy(irati_templates.ipcmconf_base) - if manager: + if self.manager: ipcmconfs[node.name]["addons"]["mad"]["managerAppName"] \ = "%s.mad-1--" % (node.name,) - for dif in experiment.dif_ordering: # type: mod.DIF + for dif in self.dif_ordering: # type: mod.DIF if isinstance(dif, mod.ShimEthDIF): ipcp2shim_map.update({ipcp.name: dif for ipcp in dif.ipcps}) elif isinstance(dif, mod.NormalDIF): @@ -243,21 +257,20 @@ class ConfBuilder(object): irati_templates.normal_dif_base ) - for node in experiment.nodes: # type: mod.Node + for node in self.nodes: # type: mod.Node ipcmconf = ipcmconfs[node.name] for ipcp in node.ipcps: # type: mod.ShimEthIPCP if isinstance(ipcp, mod.ShimEthIPCP): - node_name, port_id = ipcp.ifname.split('.') shim = ipcp2shim_map[ipcp.name] # type: mod.ShimEthDIF ipcmconf["ipcProcessesToCreate"].append({ - "apName": "eth.%d.IPCP" % int(port_id), + "apName": "eth.%s.IPCP" % ipcp.name, "apInstance": "1", "difName": shim.name }) template_file_name = 'shimeth.%s.%s.dif' \ - % (node_name, shim.name) + % (node.name, shim.name) ipcmconf["difConfigurations"].append({ "name": shim.name, "template": template_file_name @@ -267,7 +280,7 @@ class ConfBuilder(object): fout.write(json.dumps( {"difType": "shim-eth-vlan", "configParameters": { - "interface-name": "ifc%d" % (int(port_id),) + "interface-name": ipcp.ifname } }, indent=4, sort_keys=True)) @@ -280,7 +293,7 @@ class ConfBuilder(object): # This would happen because at the moment of registration, # it may be that the IPCP of the lower DIF has not been created yet. shims = ipcp2shim_map.values() - for dif in experiment.dif_ordering: # type: mod.NormalDIF + for dif in self.dif_ordering: # type: mod.NormalDIF if dif in shims: # Shims are managed separately, in the previous loop @@ -326,7 +339,7 @@ class ConfBuilder(object): indent=4, sort_keys=True) - for node in experiment.nodes: + for node in self.nodes: # Dump the IPCM configuration files with open('%s.ipcm.conf' % (node.name,), 'w') as node_file: json.dump(ipcmconfs[node.name], @@ -334,7 +347,7 @@ class ConfBuilder(object): indent=4, sort_keys=True) - for dif in experiment.dif_ordering: # type: mod.DIF + for dif in self.dif_ordering: # type: mod.DIF dif_conf = difconfs.get(dif.name, None) if dif_conf: # Dump the normal DIF configuration files |