From 12aa04b46dc5c42f1fda0a204d955e53d9f89bc2 Mon Sep 17 00:00:00 2001 From: Changbin Liu Date: Wed, 22 May 2013 22:48:39 -0400 Subject: [PATCH] Consolidate code of two functions Move same code of _deploy_network_vxlan and _deploy_dnsmasq into a new function: _add_recipe Change-Id: Ied2f27f42772acd4485c43cf44b8cd12a150be93 --- inception/orchestrator.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/inception/orchestrator.py b/inception/orchestrator.py index a18bcea..c3ae300 100644 --- a/inception/orchestrator.py +++ b/inception/orchestrator.py @@ -302,14 +302,7 @@ class Orchestrator(object): i.e., build VXLAN tunnels with gateway as layer-2 hub and other VMs as spokes, and assign ip address and netmask """ - hostnames = ([self._chefserver_name, self._gateway_name, - self._controller_name] + self._worker_names) - for hostname in hostnames: - cmd.ssh(self.user + '@' + self._chefserver_ip, - "/usr/bin/knife node run_list add %s %s" % ( - hostname, 'recipe[openvswitch::network-vxlan]'), - screen_output=True, - agent_forwarding=True) + self._add_recipe('recipe[openvswitch::network-vxlan]') self._run_chef_client() def _deploy_dnsmasq(self): @@ -318,19 +311,28 @@ class Orchestrator(object): i.e., install and config on dnsmasq on gateway node, and point all VMs to gateway as nameserver """ + self._add_recipe('recipe[openvswitch::dnsmasq]') + self._run_chef_client() + + def _add_recipe(self, recipe): + """ + for each server, add a recipe its run_list + + @param recipe: name of the recipe + """ hostnames = ([self._chefserver_name, self._gateway_name, self._controller_name] + self._worker_names) for hostname in hostnames: cmd.ssh(self.user + '@' + self._chefserver_ip, "/usr/bin/knife node run_list add %s %s" % ( - hostname, 'recipe[openvswitch::dnsmasq]'), + hostname, recipe), screen_output=True, agent_forwarding=True) - self._run_chef_client() def _run_chef_client(self): """ - run the chef-client for all specified cookbooks in the run_list + for each server, run the chef-client for all specified cookbooks in its + run_list """ ipaddrs = ([self._chefserver_ip, self._gateway_ip, self._controller_ip] + self._worker_ips)