Beispiel #1
0
    def deploy(self):
        def _key(desc):
            """Get the site and the primary network of a description.

            Prerequesite: the desc must have some concrete nodes attached.
            """
            site = desc["_c_nodes"][0].split(".")[1]
            net = desc["primary_network"]
            return site, net

        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"]
        # Get rid of empty groups if any
        # There's nothing to deploy for such description
        s_machines = [m for m in machines if m.get("_c_nodes", [])]
        s_machines = sorted(s_machines, key=_key)
        for (site, 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}

            net = utils.lookup_networks(primary_network, networks)
            if net["type"] != PROD:
                options.update({"vlan": net["_c_network"][0].vlan_id})

            # Yes, this is sequential
            deployed, undeployed = [], nodes
            if not force_deploy:
                deployed, undeployed = _check_deployed_nodes(
                    _translate_vlan(primary_network, networks, nodes))
                deployed = _translate_vlan(primary_network,
                                           networks,
                                           deployed,
                                           reverse=True)
                undeployed = _translate_vlan(primary_network,
                                             networks,
                                             undeployed,
                                             reverse=True)

            if force_deploy or not deployed:
                deployed, undeployed = self.driver.deploy(site, nodes, 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"])
Beispiel #2
0
        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]
Beispiel #3
0
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]
Beispiel #4
0
    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"])