Exemplo n.º 1
0
def get_node_interfaces(host):
    dst = Discovery()
    interfaces = {}
    dst = Discovery()
    key = "PYRobot/Node_" + host + "/InterfacesOK"
    response = dst.Get(key)
    interfaces.update({
        k.split("/")[1].split("_")[1]: v
        for k, v in response.items() if k.find("/Node_Interface") != -1
    })
    return interfaces
Exemplo n.º 2
0
def get_all_nodes_interfaces():
    dst = Discovery()
    interfaces = {"localhost": hostname}
    dst = Discovery()
    key = "PYRobot/Node_*" + "/InterfacesOK"
    response = dst.Get(key)
    interfaces.update({
        k.split("/")[1].split("_")[1]: v
        for k, v in response.items() if k.find("/Node_Interface") != -1
    })
    return interfaces
Exemplo n.º 3
0
def Status_robot(search):
    dsc = Discovery()
    controls = {}
    for s in search:
        controls.update(dsc.Get(s + "/Control"))
    for uri in controls.values():
        if uri != "0.0.0.0:0":
            proxy = Proxy(uri)
            if proxy():
                info_comp = proxy.Get_INFO()
                show_PROC(info_comp)
    if len(controls) == 0:
        P_Log("[FY] Nothing to show")
Exemplo n.º 4
0
def get_all_hosts(eth=None):
    dst = Discovery()
    key = "iamrobot/*/HI"
    response = dst.Get(key)
    host_name = get_host_name()
    if host_name not in response:
        eths = get_ethernets()
        if eth in eths:
            ips = [eths[eth]]
        else:
            ips = [ip for dis, ip in eths.items()]
        response[host_name] = ips
    response["localhost"] = response[host_name]
    return response
Exemplo n.º 5
0
def Stop_robot(search):
    dsc = Discovery()
    controls = {}
    for s in search:
        controls.update(dsc.Get(s + "/Control"))
    for uri in controls.values():
        if uri != "0.0.0.0:0":
            proxy = Proxy(uri)
            if proxy():
                name = proxy.shutdown()
                P_Log("[FR][STOP][FY] Signal Stop in Component [FW]{}".format(
                    name))

    if len(controls) == 0:
        P_Log("[FY] Nothing to Stop")
Exemplo n.º 6
0
def Find_robot(search, show=True):
    dsc = Discovery()
    names = []
    if type(search) == str:
        search = [search]
    for s in search:
        name = dsc.Get(s + "/Name")
        names.extend(name)
    if len(names) == 0:
        if show:
            P_Log("[FY] Nothing to show")
        return []
    if show:
        P_Log("[FY] Find Components:")
        for n in names:
            P_Log("\tComponent: [FG]{}".format(n))
    return names
Exemplo n.º 7
0
def Start_robot(Filename=None, Init={}, Model={}):
    loader = Loader_PYRobot(Filename, Init, Model)
    robot_name = Init["NAME"]
    onlinecomps = Find_robot("{}/*".format(robot_name), show=False)
    loader.Check()
    components = loader.Get_Skel()
    dsc = Discovery()

    for c, comp in components.items():
        name = comp["_etc"]["name"]
        host = comp["_etc"]["host"]
        if name not in onlinecomps:
            comp = json.dumps(comp)
            if host == "localhost":
                utils.run_component("_comp", comp, run="start")
            else:
                uris = get_node_interfaces(host)
                if host in uris:
                    proxy = Proxy(uris[host])
                    if proxy():
                        proxy.Run_comp(comp)
                P_Log(
                    "[FY]component:[FW]{} [FY]starting in host:[FW]{}".format(
                        name, host))
        else:
            P_Log("[FY]component:[FW]{} [FY] is online on [FW]{}".format(
                name, host))

    trys = 6
    while trys > 0:
        controls = dsc.Get(robot_name + "/*/ControlOK")
        if len(controls) == len(components):
            trys = 0
        else:
            trys = trys - 1
            time.sleep(0.09)
    if len(controls) != len(components):
        P_Log("[FY][Warning][FW] some components are not running")
    P_Log("[FY] Waiting for connect loggins...")
    controls = dsc.Get(robot_name + "/*/ControlOK")
    for uri in controls.values():
        if uri != "0.0.0.0:0":
            proxy = Proxy(uri)
            if proxy():
                proxy.Set_Logging(0)