From e7b4a2c499542e9f17e15e331802fd1c27bedd0f Mon Sep 17 00:00:00 2001 From: Anton Beloglazov Date: Thu, 8 Nov 2012 10:48:54 +1100 Subject: [PATCH] Added an ether_wake_interface config option, added it as an -i parameter to ether-wake --- neat.conf | 3 +++ neat/config.py | 1 + neat/globals/manager.py | 11 +++++++++-- tests/globals/test_manager.py | 17 +++++++++-------- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/neat.conf b/neat.conf index 63706fd..488f8dd 100644 --- a/neat.conf +++ b/neat.conf @@ -99,6 +99,9 @@ network_migration_bandwidth = 10 # compute_user must have permissions to execute this command sleep_command = pm-suspend +# The network interface to send a magic packet from using ether-wake +ether_wake_interface = eth0 + # The fully qualified name of a Python factory function that returns a # function implementing an underload detection algorithm #algorithm_underload_detection_factory = neat.locals.underload.trivial.threshold_factory diff --git a/neat/config.py b/neat/config.py index 334469f..72d0eb6 100644 --- a/neat/config.py +++ b/neat/config.py @@ -59,6 +59,7 @@ REQUIRED_FIELDS = [ 'compute_user', 'compute_password', 'sleep_command', + 'ether_wake_interface', 'network_migration_bandwidth', 'algorithm_underload_detection_factory', 'algorithm_underload_detection_parameters', diff --git a/neat/globals/manager.py b/neat/globals/manager.py index 3862d7a..ac2c075 100644 --- a/neat/globals/manager.py +++ b/neat/globals/manager.py @@ -164,6 +164,7 @@ def start(): state = init_state(config) switch_hosts_on(state['db'], + config['ether_wake_interface'], state['host_macs'], state['compute_hosts']) @@ -571,6 +572,7 @@ def execute_overload(config, state, host, vm_uuids): set(placement.values()))) if hosts_to_activate: switch_hosts_on(state['db'], + config['ether_wake_interface'], state['host_macs'], hosts_to_activate) log.info('Started overload VM migrations') @@ -789,12 +791,15 @@ def switch_hosts_off(db, sleep_command, hosts): @contract -def switch_hosts_on(db, host_macs, hosts): +def switch_hosts_on(db, ether_wake_interface, host_macs, hosts): """ Switch hosts to the active mode. :param db: The database object. :type db: Database + :param ether_wake_interface: An interface to send a magic packet. + :type ether_wake_interface: str + :param host_macs: A dict of host names to mac addresses. :type host_macs: dict(str: str) @@ -804,7 +809,9 @@ def switch_hosts_on(db, host_macs, hosts): for host in hosts: if host not in host_macs: host_macs[host] = host_mac(host) - command = 'ether-wake {0}'.format(host_macs[host]) + command = 'ether-wake -i {0} {1}'.format( + ether_wake_interface, + host_macs[host]) if log.isEnabledFor(logging.DEBUG): log.debug('Calling: %s', command) subprocess.call(command, shell=True) diff --git a/tests/globals/test_manager.py b/tests/globals/test_manager.py index 850554e..71fe825 100644 --- a/tests/globals/test_manager.py +++ b/tests/globals/test_manager.py @@ -168,7 +168,8 @@ class GlobalManager(TestCase): 'log_directory': 'dir', 'log_level': 2, 'global_manager_host': 'localhost', - 'global_manager_port': 8080} + 'global_manager_port': 8080, + 'ether_wake_interface': 'eth0'} paths = [manager.DEFAILT_CONFIG_PATH, manager.CONFIG_PATH] fields = manager.REQUIRED_FIELDS expect(manager).read_and_validate_config(paths, fields). \ @@ -176,7 +177,7 @@ class GlobalManager(TestCase): expect(common).init_logging('dir', 'global-manager.log', 2).once() expect(manager).init_state(config). \ and_return(state).once() - expect(manager).switch_hosts_on(db, {}, hosts).once() + expect(manager).switch_hosts_on(db, 'eth0', {}, hosts).once() expect(bottle).app().and_return(app).once() expect(bottle).run(host='localhost', port=8080).once() manager.start() @@ -380,20 +381,20 @@ class GlobalManager(TestCase): db = db_utils.init_db('sqlite:///:memory:') with MockTransaction: - expect(subprocess).call('ether-wake mac1', shell=True).once() - expect(subprocess).call('ether-wake mac2', shell=True).once() + expect(subprocess).call('ether-wake -i eth0 mac1', shell=True).once() + expect(subprocess).call('ether-wake -i eth0 mac2', shell=True).once() expect(manager).host_mac('h1').and_return('mac1').once() expect(db).insert_host_states({ 'h1': 1, 'h2': 1}).once() - manager.switch_hosts_on(db, {'h2': 'mac2'}, ['h1', 'h2']) + manager.switch_hosts_on(db, 'eth0', {'h2': 'mac2'}, ['h1', 'h2']) with MockTransaction: - expect(subprocess).call('ether-wake mac1', shell=True).once() - expect(subprocess).call('ether-wake mac2', shell=True).once() + expect(subprocess).call('ether-wake -i eth0 mac1', shell=True).once() + expect(subprocess).call('ether-wake -i eth0 mac2', shell=True).once() expect(manager).host_mac('h1').and_return('mac1').once() expect(manager).host_mac('h2').and_return('mac2').once() expect(db).insert_host_states({ 'h1': 1, 'h2': 1}).once() - manager.switch_hosts_on(db, {}, ['h1', 'h2']) + manager.switch_hosts_on(db, 'eth0', {}, ['h1', 'h2'])