Ejemplo n.º 1
0
 def networks_data(self):
     nets = self.networks_data_from_cni_confs()
     sections = list(self.conf_sections("network"))
     if "network#default" not in sections:
         sections.append("network#default")
     for section in sections:
         _, name = section.split("#", 1)
         config = {}
         config["type"] = self.oget(section, "type")
         for key in self.section_kwargs(section, config["type"]):
             config[key] = self.oget(section, key, rtype=config["type"])
             if config["type"] == "routed_bridge":
                 config["subnets"] = self.oget_scopes(section,
                                                      "subnet",
                                                      rtype=config["type"])
         if not config:
             continue
         routes = self.routes(name, config)
         if config["type"] == "routed_bridge" and not any(
                 config["subnets"][n] for n in config["subnets"]):
             self.log.info(
                 "initial %s routed_bridge network subnets assignment:",
                 name)
             kws = []
             for route in routes:
                 kw = "network#%s.subnet@%s=%s" % (name, route["node"],
                                                   route["dst"])
                 kws.append(kw)
                 self.log.info(" %s", kw)
             from core.objects.ccfg import Ccfg
             svc = Ccfg()
             svc.set_multi(kws, validation=False)
             self.unset_lazy("cd")
             config["subnets"] = self.oget_scopes(section,
                                                  "subnet",
                                                  rtype="routed_bridge")
         if name not in nets:
             nets[name] = {}
         nets[name]["config"] = config
         nets[name]["routes"] = routes
         nets[name]["tables"] = self.tables(name)
     nets["lo"] = {
         "config": {
             "type": "loopback",
             "network": "127.0.0.1/32",
             "tables": ["main"],
         },
     }
     return nets
Ejemplo n.º 2
0
 def cluster_name(self):
     """
     Return the cluster name, read from cluster.name in the node
     configuration. If not set, return "default".
     """
     node = self.get_node()
     try:
         return node.oget("cluster", "name").lower()
     except Exception as exc:
         pass
     name = "default"
     from core.objects.ccfg import Ccfg
     svc = Ccfg()
     svc.set_multi(["cluster.name=" + name], validation=False)
     return name
Ejemplo n.º 3
0
 def cluster_id(self):
     """
     Return the cluster id read from cluster.id in the node configuration.
     If not already set generate and store a random one.
     """
     node = self.get_node()
     try:
         return node.conf_get("cluster", "id")
     except Exception as exc:
         pass
     import uuid
     from core.objects.ccfg import Ccfg
     cluster_id = str(uuid.uuid1())
     svc = Ccfg()
     svc.set_multi(["cluster.id="+cluster_id], validation=False)
     return cluster_id
Ejemplo n.º 4
0
 def cluster_key(self):
     """
     Return the key read from cluster.secret in the node configuration.
     If not already set generate and store a random one.
     """
     node = self.get_node()
     try:
         key = node.oget("cluster", "secret")
         return self.prepare_key(key)
     except Exception as exc:
         pass
     import uuid
     from core.objects.ccfg import Ccfg
     key = uuid.uuid1().hex
     svc = Ccfg()
     svc.set_multi(["cluster.secret="+key], validation=False)
     return self.prepare_key(key)
Ejemplo n.º 5
0
    def cluster_nodes(self):
        """
        Return the cluster nodes, read from cluster.nodes in the node
        configuration. If not set, return a list with the local node as the
        only element.
        """
        node = self.get_node()
        if want_context():
            return node._daemon_status()["cluster"]["nodes"]
        nodes = node.oget("cluster", "nodes")

        if nodes:
            if Env.nodename in nodes:
                return nodes
            else:
                nodes.append(Env.nodename)
        else:
            nodes = [Env.nodename]

        from core.objects.ccfg import Ccfg
        svc = Ccfg()
        svc.set_multi(["cluster.nodes=" + " ".join(nodes)], validation=False)
        node.unset_multi(["cluster.nodes"])
        return nodes