def getServerInfo(cfg): """ get server state and print """ username = cfg["hs_username"] password = cfg["hs_password"] endpoint = cfg["hs_endpoint"] try: info = h5pyd.getServerInfo(username=username, password=password, endpoint=endpoint) print("server name: {}".format(info["name"])) if "state" in info: print("server state: {}".format(info['state'])) print("endpoint: {}".format(endpoint)) print("username: {}".format(info["username"])) print("password: {}".format(info["password"])) if info['state'] == "READY": home_folder = getHomeFolder(username) if home_folder: print("home: {}".format(home_folder)) if "hsds_version" in info: print("server version: {}".format(info["hsds_version"])) elif "h5serv_version" in info: print("server version: {}".format(info["h5serv_version"])) if "start_time" in info: uptime = getUpTime(info["start_time"]) print("up: {}".format(uptime)) print("h5pyd version: {}".format(h5pyd.version.version)) except IOError as ioe: if ioe.errno == 401: print("username/password not valid for username: {}".format( username)) else: print("Error: {}".format(ioe))
def pingServer(username, password, endpoint, api_key): if not endpoint.startswith("http"): print("endpoint must start with 'http...'") return False try: info = h5pyd.getServerInfo(username=username, password=password, endpoint=endpoint, api_key=api_key) if 'state' not in info: print("unexpected response from server") return False state = info["state"] if state != "READY": print("Server is not ready, please try later") return False except IOError as ioe: if ioe.errno == 401: print("Unauthorized (username/password or api key not valid)") return False elif ioe.errno == 403: print("forbidden (account not setup?)") return False elif ioe.errno: print("Unexpected error: {}".format(ioe.errno)) return False else: print("Couldn't connect to server") return False except json.decoder.JSONDecodeError: print("Unexpected response from server") return False return True
def info() -> Dict[str, Any]: try: return {"version": __version__, **getServerInfo(**get_credentials())} except Exception as e: print(e) config = Config() return { "version": __version__, "endpoint": config["hs_endpoint"], "state": "ERROR", "node_count": 0, "hsds_version": "<unknown>", "username": session["hsds_user"], }
def getServerInfo(cfg): """ get server state and print """ username = cfg["hs_username"] password = cfg["hs_password"] endpoint = cfg["hs_endpoint"] try: info = h5pyd.getServerInfo(username=username, password=password, endpoint=endpoint) print("server name: {}".format(info["name"])) if "state" in info: print("server state: {}".format(info['state'])) print("endpoint: {}".format(endpoint)) if "isadmin" in info and info["isadmin"]: admin_tag = "(admin)" else: admin_tag = "" print("username: {} {}".format(info["username"], admin_tag)) print("password: {}".format(info["password"])) if info['state'] == "READY": try: home_folder = getHomeFolder() if home_folder: print("home: {}".format(home_folder)) except IOError: print("home: NO ACCESS", ) if "hsds_version" in info: print("server version: {}".format(info["hsds_version"])) if "node_count" in info: print("node count: {}".format(info["node_count"])) elif "h5serv_version" in info: print("server version: {}".format(info["h5serv_version"])) if "start_time" in info: uptime = getUpTime(info["start_time"]) print("up: {}".format(uptime)) print("h5pyd version: {}".format(h5pyd.version.version)) except IOError as ioe: if ioe.errno == 401: if username and password: print("username/password not valid for username: {}".format( username)) else: # authentication error with openid or app token print("authentication failure") else: print("Error: {}".format(ioe))
def main(): argn = 1 depth = 2 cfg["loglevel"] = logging.ERROR cfg["logfname"] = None while argn < len(sys.argv): arg = sys.argv[argn] val = None if len(sys.argv) > argn + 1: val = sys.argv[argn + 1] if arg == "--loglevel": val = val.upper() if val == "DEBUG": cfg["loglevel"] = logging.DEBUG elif val == "INFO": cfg["loglevel"] = logging.INFO elif val in ("WARN", "WARNING"): cfg["loglevel"] = logging.WARNING elif val == "ERROR": cfg["loglevel"] = logging.ERROR else: printUsage() argn += 2 elif arg == '--logfile': cfg["logfname"] = val argn += 2 elif arg in ("-h", "--help"): printUsage() elif arg in ("-e", "--endpoint"): cfg["hs_endpoint"] = val argn += 2 elif arg in ("-u", "--username"): cfg["hs_username"] = val argn += 2 elif arg in ("-p", "--password"): cfg["hs_password"] = val argn += 2 else: printUsage() # setup logging logging.basicConfig(filename=cfg["logfname"], format='%(asctime)s %(message)s', level=cfg["loglevel"]) logging.debug("set log_level to {}".format(cfg["loglevel"])) username = cfg["hs_username"] password = cfg["hs_password"] endpoint = cfg["hs_endpoint"] print("endpoint:", endpoint) try: info = h5pyd.getServerInfo(username=username, password=password, endpoint=endpoint) print("server name:", info["name"]) if "state" in info: print("server state:", info['state']) print("username:"******"username"]) print("password:"******"password"]) if "hsds_version" in info: print("server version:", info["hsds_version"]) elif "h5serv_version" in info: print("server version", info["h5serv_version"]) if "start_time" in info: uptime = getUpTime(info["start_time"]) print("up: {}".format(uptime)) print("h5pyd version:", h5pyd.version.version) except IOError as ioe: if ioe.errno == 401: print("username/password not valid for username:"******"Error:", ioe)
### main loglevel = config.get("log_level") logging.basicConfig(format='%(asctime)s %(message)s', level=loglevel) # make sure the global (and local if set) hsds is up (if being used) for endpoint in (hsds_global, hsds_local): if not endpoint: print("local endpoint not set?") continue state = None while state != "READY": print(f"waiting on endpoint: {endpoint} to be in READY state") time.sleep(1) info = h5pyd.getServerInfo(endpoint=endpoint) if info and 'state' in info: state = info['state'] print(f"endpoint: {endpoint} is in READY state") f = h5pyd.File(inventory_domain, "r+", use_cache=False, endpoint=hsds_global, username=username, password=password) table = f["inventory"] print("table.nrows:", table.nrows) print("table.dtype:", table.dtype)
return result ### main loglevel = config.get("log_level") logging.basicConfig(format='%(asctime)s %(message)s', level=loglevel) # make sure the local hsds is up (if being used) if hsds_local: state = None while state != "READY": print("waiting on local hsds READY") time.sleep(1) info = h5pyd.getServerInfo(endpoint=hsds_local) if info and 'state' in info: state = info['state'] print("local hsds in in READY state") f = h5pyd.File(inventory_domain, "r+", use_cache=False, endpoint=hsds_global, username=username, password=password) table = f["inventory"] print("table.nrows:", table.nrows) condition = "(loaddone > 0) & (loadstatus == 0) & (diffstart == 0)" # query for files that haven't been proccessed
def main(): argn = 1 cfg["cmd"] = sys.argv[0].split('/')[-1] if cfg["cmd"].endswith(".py"): cfg["cmd"] = "python " + cfg["cmd"] cfg["loglevel"] = logging.ERROR cfg["logfname"] = None while argn < len(sys.argv): arg = sys.argv[argn] val = None if len(sys.argv) > argn + 1: val = sys.argv[argn+1] if arg == "--loglevel": val = val.upper() if val == "DEBUG": cfg["loglevel"] = logging.DEBUG elif val == "INFO": cfg["loglevel"] = logging.INFO elif val in ("WARN", "WARNING"): cfg["loglevel"] = logging.WARNING elif val == "ERROR": cfg["loglevel"] = logging.ERROR else: printUsage() argn += 2 elif arg == '--logfile': cfg["logfname"] = val argn += 2 elif arg in ("-h", "--help"): printUsage() elif arg in ("-e", "--endpoint"): cfg["hs_endpoint"] = val argn += 2 elif arg in ("-u", "--username"): cfg["hs_username"] = val argn += 2 elif arg in ("-p", "--password"): cfg["hs_password"] = val argn += 2 else: printUsage() # setup logging logging.basicConfig(filename=cfg["logfname"], format='%(asctime)s %(message)s', level=cfg["loglevel"]) logging.debug("set log_level to {}".format(cfg["loglevel"])) username = cfg["hs_username"] password = cfg["hs_password"] endpoint = cfg["hs_endpoint"] print("endpoint: {}".format(endpoint)) if not endpoint or endpoint[-1] == '/' or endpoint[:4] != "http": print("WARNING: endpoint: {} doesn't appear to be valid".format(endpoint)) try: info = h5pyd.getServerInfo(username=username, password=password, endpoint=endpoint) print("server name: {}".format(info["name"])) if "state" in info: print("server state: {}".format(info['state'])) print("username: {}".format(info["username"])) print("password: {}".format(info["password"])) if info['state'] == "READY": home_folder = getHomeFolder(username) if home_folder: print("home: {}".format(home_folder)) if "hsds_version" in info: print("server version: {}".format(info["hsds_version"])) elif "h5serv_version" in info: print("server version: {}".format(info["h5serv_version"])) if "start_time" in info: uptime = getUpTime(info["start_time"]) print("up: {}".format(uptime)) print("h5pyd version: {}".format(h5pyd.version.version)) except IOError as ioe: if ioe.errno == 401: print("username/password not valid for username: {}".format(username)) else: print("Error: {}".format(ioe))