Пример #1
0
def is_service(f, namespace=None, data=None, local=False, kinds=None):
    if f is None:
        return
    f = re.sub(r"\.conf$", '', f)
    f = f.replace(Env.paths.pathetcns + os.sep,
                  "").replace(Env.paths.pathetc + os.sep, "")
    try:
        name, _namespace, kind = split_path(f)
    except ValueError:
        return
    if kinds and kind not in kinds:
        return
    if not namespace:
        namespace = _namespace
    path = fmt_path(name, namespace, kind)
    if not local:
        try:
            data["services"][path]
            return path
        except Exception:
            if want_context():
                return
    cf = svc_pathcf(path)
    if not os.path.exists(cf):
        return
    return path
Пример #2
0
 def add_key(self, key, data, append=False):
     if append:
         data = self.decode_key(key) + data
     if want_context():
         self.remote_add_key(key, data)
     else:
         self._add_key(key, data)
Пример #3
0
 def daemon_request(self, *args, **kwargs):
     #print("req", args, kwargs)
     #import traceback
     #traceback.print_stack()
     sp = self.socket_parms(kwargs.get("server"))
     if sp.scheme == "raw" and not want_context():
         return self.raw_daemon_request(*args, sp=sp, **kwargs)
     else:
         return self.h2_daemon_request(*args, sp=sp, **kwargs)
Пример #4
0
 def cluster_drpnodes(self):
     """
     Return the cluster drp nodes, read from cluster.drpnodes in the node
     configuration. If not set, return an empty list.
     """
     node = self.get_node()
     if want_context():
         return node._daemon_status()["cluster"].get("drpnodes", [])
     nodes = node.oget("cluster", "drpnodes")
     return nodes
Пример #5
0
 def get_secret(self, sp, secret):
     if want_context():
         return
     if sp.context and not sp.context.get("secret"):
         return
     elif secret:
         return bdecode(secret)
     elif sp.server in self.cluster_drpnodes:
         node = self.get_node()
         return bdecode(self.prepare_key(node.oget("cluster", "secret", impersonate=sp.server)))
     else:
         return bdecode(self.cluster_key)
Пример #6
0
 def get_cluster_name(self, sp, cluster_name):
     if want_context():
         return
     if sp.context and not sp.context.get("clustername"):
         return
     elif cluster_name:
         return cluster_name
     elif sp.server in self.cluster_drpnodes:
         node = self.get_node()
         return node.oget("cluster", "name", impersonate=sp.server)
     else:
         return self.cluster_name
Пример #7
0
 def socket_parms(self, server=None):
     if os.environ.get("OSVC_ACTION_ORIGIN") != "daemon" and want_context():
         return self.socket_parms_from_context(server)
     if server is None or server == "":
         return self.socket_parms_ux(server)
     if server == Env.nodename and os.name != "nt":
         # Local comms
         return self.socket_parms_ux(server)
     if server.startswith("/"):
         return self.socket_parms_ux_h2(server)
     if ":" in server:
         # Explicit server uri (ex: --server https://1.2.3.4:1215)
         return self.socket_parms_parser(server)
     else:
         # relay, arbitrator, node-to-node
         return self.socket_parms_inet_raw(server)
Пример #8
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