Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
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()
if home_folder:
print("home: {}".format(home_folder))
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: