def translate_vlan(primary_network, networks, nodes): def translate(node, vlan_id): splitted = node.split(".") splitted[0] = "%s-kavlan-%s" % (splitted[0], vlan_id) return ".".join(splitted) if utils.is_prod(primary_network, networks): return nodes net = utils.lookup_networks(primary_network, networks) vlan_id = net["_c_network"]["vlan_id"] return [translate(node, vlan_id) for node in nodes]
def _translate_vlan(primary_network, networks, nodes, reverse=False): def translate(node, vlan_id): if not reverse: splitted = node.split(".") splitted[0] = "%s-kavlan-%s" % (splitted[0], vlan_id) return ".".join(splitted) else: node = node.replace("-kavlan-%s" % vlan_id, "") return node if utils.is_prod(primary_network, networks): return nodes net = utils.lookup_networks(primary_network, networks) # There can be only one network in the vlan case... vlan_id = net["_c_network"][0].vlan_id return [translate(node, vlan_id) for node in nodes]
def deploy(self): def translate_vlan(primary_network, networks, nodes): def translate(node, vlan_id): splitted = node.split(".") splitted[0] = "%s-kavlan-%s" % (splitted[0], vlan_id) return ".".join(splitted) if utils.is_prod(primary_network, networks): return nodes net = utils.lookup_networks(primary_network, networks) vlan_id = net["_c_network"]["vlan_id"] return [translate(node, vlan_id) for node in nodes] env_name = self.configuration.get("env_name", DEFAULT_ENV_NAME) force_deploy = self.configuration.get("force_deploy", False) machines = self.c_resources["machines"] networks = self.c_resources["networks"] key = itemgetter("primary_network") s_machines = sorted(machines, key=key) for primary_network, i_descs in groupby(s_machines, key=key): descs = list(i_descs) nodes = [desc.get("_c_nodes", []) for desc in descs] # flatten nodes = sum(nodes, []) options = {"env_name": env_name} if not utils.is_prod(primary_network, networks): net = utils.lookup_networks(primary_network, networks) options.update({"vlan": net["_c_network"]["vlan_id"]}) # Yes, this is sequential deployed, undeployed = utils._deploy(nodes, force_deploy, options) for desc in descs: c_nodes = desc.get("_c_nodes", []) desc["_c_deployed"] = list(set(c_nodes) & set(deployed)) desc["_c_undeployed"] = list(set(c_nodes) & set(undeployed)) desc["_c_ssh_nodes"] = translate_vlan(primary_network, networks, desc["_c_deployed"])