bug fixes, preparing for unittesting
This commit is contained in:
parent
3061b54059
commit
2f5b5fcf6b
@ -1,2 +1,2 @@
|
|||||||
__version__ = "2.1.3"
|
__version__ = "2.1.4"
|
||||||
|
|
||||||
|
@ -69,14 +69,18 @@ class configfile:
|
|||||||
self.profiles = config["profiles"]
|
self.profiles = config["profiles"]
|
||||||
if not os.path.exists(self.key):
|
if not os.path.exists(self.key):
|
||||||
self._createkey(self.key)
|
self._createkey(self.key)
|
||||||
self.privatekey = RSA.import_key(open(self.key).read())
|
with open(self.key) as f:
|
||||||
|
self.privatekey = RSA.import_key(f.read())
|
||||||
|
f.close()
|
||||||
self.publickey = self.privatekey.publickey()
|
self.publickey = self.privatekey.publickey()
|
||||||
|
|
||||||
|
|
||||||
def _loadconfig(self, conf):
|
def _loadconfig(self, conf):
|
||||||
#Loads config file
|
#Loads config file
|
||||||
jsonconf = open(conf)
|
jsonconf = open(conf)
|
||||||
return json.load(jsonconf)
|
jsondata = json.load(jsonconf)
|
||||||
|
jsonconf.close()
|
||||||
|
return jsondata
|
||||||
|
|
||||||
def _createconfig(self, conf):
|
def _createconfig(self, conf):
|
||||||
#Create config file
|
#Create config file
|
||||||
@ -87,7 +91,9 @@ class configfile:
|
|||||||
f.close()
|
f.close()
|
||||||
os.chmod(conf, 0o600)
|
os.chmod(conf, 0o600)
|
||||||
jsonconf = open(conf)
|
jsonconf = open(conf)
|
||||||
return json.load(jsonconf)
|
jsondata = json.load(jsonconf)
|
||||||
|
jsonconf.close()
|
||||||
|
return jsondata
|
||||||
|
|
||||||
def _saveconfig(self, conf):
|
def _saveconfig(self, conf):
|
||||||
#Save config file
|
#Save config file
|
||||||
@ -106,6 +112,7 @@ class configfile:
|
|||||||
f.write(key.export_key('PEM'))
|
f.write(key.export_key('PEM'))
|
||||||
f.close()
|
f.close()
|
||||||
os.chmod(keyfile, 0o600)
|
os.chmod(keyfile, 0o600)
|
||||||
|
return key
|
||||||
|
|
||||||
def _explode_unique(self, unique):
|
def _explode_unique(self, unique):
|
||||||
#Divide unique name into folder, subfolder and id
|
#Divide unique name into folder, subfolder and id
|
||||||
|
@ -129,448 +129,458 @@ class connapp:
|
|||||||
#Function called when connecting or managing nodes.
|
#Function called when connecting or managing nodes.
|
||||||
if not self.case and args.data != None:
|
if not self.case and args.data != None:
|
||||||
args.data = args.data.lower()
|
args.data = args.data.lower()
|
||||||
if args.action == "version":
|
actions = {"version": self._version, "connect": self._connect, "debug": self._connect, "add": self._add, "del": self._del, "mod": self._mod, "show": self._show}
|
||||||
print(__version__)
|
return actions.get(args.action)(args)
|
||||||
if args.action == "connect" or args.action == "debug":
|
|
||||||
if args.data == None:
|
def _version(self, args):
|
||||||
matches = self.nodes
|
print(__version__)
|
||||||
if len(matches) == 0:
|
|
||||||
print("There are no nodes created")
|
def _connect(self, args):
|
||||||
print("try: conn --help")
|
if args.data == None:
|
||||||
exit(9)
|
matches = self.nodes
|
||||||
else:
|
|
||||||
if args.data.startswith("@"):
|
|
||||||
matches = list(filter(lambda k: args.data in k, self.nodes))
|
|
||||||
else:
|
|
||||||
matches = list(filter(lambda k: k.startswith(args.data), self.nodes))
|
|
||||||
if len(matches) == 0:
|
if len(matches) == 0:
|
||||||
print("{} not found".format(args.data))
|
print("There are no nodes created")
|
||||||
exit(2)
|
print("try: conn --help")
|
||||||
elif len(matches) > 1:
|
exit(9)
|
||||||
matches[0] = self._choose(matches,"node", "connect")
|
else:
|
||||||
if matches[0] == None:
|
if args.data.startswith("@"):
|
||||||
exit(7)
|
matches = list(filter(lambda k: args.data in k, self.nodes))
|
||||||
node = self.config.getitem(matches[0])
|
|
||||||
node = self.node(matches[0],**node, config = self.config)
|
|
||||||
if args.action == "debug":
|
|
||||||
node.interact(debug = True)
|
|
||||||
else:
|
else:
|
||||||
node.interact()
|
matches = list(filter(lambda k: k.startswith(args.data), self.nodes))
|
||||||
elif args.action == "del":
|
if len(matches) == 0:
|
||||||
if args.data == None:
|
print("{} not found".format(args.data))
|
||||||
print("Missing argument node")
|
exit(2)
|
||||||
exit(3)
|
elif len(matches) > 1:
|
||||||
elif args.data.startswith("@"):
|
matches[0] = self._choose(matches,"node", "connect")
|
||||||
matches = list(filter(lambda k: k == args.data, self.folders))
|
if matches[0] == None:
|
||||||
|
exit(7)
|
||||||
|
node = self.config.getitem(matches[0])
|
||||||
|
node = self.node(matches[0],**node, config = self.config)
|
||||||
|
if args.action == "debug":
|
||||||
|
node.interact(debug = True)
|
||||||
|
else:
|
||||||
|
node.interact()
|
||||||
|
|
||||||
|
def _del(self, args):
|
||||||
|
if args.data == None:
|
||||||
|
print("Missing argument node")
|
||||||
|
exit(3)
|
||||||
|
elif args.data.startswith("@"):
|
||||||
|
matches = list(filter(lambda k: k == args.data, self.folders))
|
||||||
|
else:
|
||||||
|
matches = list(filter(lambda k: k == args.data, self.nodes))
|
||||||
|
if len(matches) == 0:
|
||||||
|
print("{} not found".format(args.data))
|
||||||
|
exit(2)
|
||||||
|
question = [inquirer.Confirm("delete", message="Are you sure you want to delete {}?".format(matches[0]))]
|
||||||
|
confirm = inquirer.prompt(question)
|
||||||
|
if confirm == None:
|
||||||
|
exit(7)
|
||||||
|
if confirm["delete"]:
|
||||||
|
uniques = self.config._explode_unique(matches[0])
|
||||||
|
if args.data.startswith("@"):
|
||||||
|
self.config._folder_del(**uniques)
|
||||||
else:
|
else:
|
||||||
matches = list(filter(lambda k: k == args.data, self.nodes))
|
self.config._connections_del(**uniques)
|
||||||
if len(matches) == 0:
|
self.config._saveconfig(self.config.file)
|
||||||
print("{} not found".format(args.data))
|
print("{} deleted succesfully".format(matches[0]))
|
||||||
exit(2)
|
|
||||||
question = [inquirer.Confirm("delete", message="Are you sure you want to delete {}?".format(matches[0]))]
|
def _add(self, args):
|
||||||
confirm = inquirer.prompt(question)
|
if args.data == None:
|
||||||
if confirm["delete"]:
|
print("Missing argument node")
|
||||||
uniques = self.config._explode_unique(matches[0])
|
exit(3)
|
||||||
if args.data.startswith("@"):
|
elif args.data.startswith("@"):
|
||||||
self.config._folder_del(**uniques)
|
type = "folder"
|
||||||
else:
|
matches = list(filter(lambda k: k == args.data, self.folders))
|
||||||
self.config._connections_del(**uniques)
|
reversematches = list(filter(lambda k: "@" + k == args.data, self.nodes))
|
||||||
self.config._saveconfig(self.config.file)
|
else:
|
||||||
print("{} deleted succesfully".format(matches[0]))
|
type = "node"
|
||||||
elif args.action == "add":
|
matches = list(filter(lambda k: k == args.data, self.nodes))
|
||||||
if args.data == None:
|
reversematches = list(filter(lambda k: k == "@" + args.data, self.folders))
|
||||||
print("Missing argument node")
|
if len(matches) > 0:
|
||||||
exit(3)
|
print("{} already exist".format(matches[0]))
|
||||||
elif args.data.startswith("@"):
|
exit(4)
|
||||||
type = "folder"
|
if len(reversematches) > 0:
|
||||||
matches = list(filter(lambda k: k == args.data, self.folders))
|
print("{} already exist".format(reversematches[0]))
|
||||||
reversematches = list(filter(lambda k: "@" + k == args.data, self.nodes))
|
exit(4)
|
||||||
else:
|
else:
|
||||||
type = "node"
|
if type == "folder":
|
||||||
matches = list(filter(lambda k: k == args.data, self.nodes))
|
uniques = self.config._explode_unique(args.data)
|
||||||
reversematches = list(filter(lambda k: k == "@" + args.data, self.folders))
|
if uniques == False:
|
||||||
if len(matches) > 0:
|
print("Invalid folder {}".format(args.data))
|
||||||
print("{} already exist".format(matches[0]))
|
exit(5)
|
||||||
exit(4)
|
if "subfolder" in uniques.keys():
|
||||||
if len(reversematches) > 0:
|
parent = "@" + uniques["folder"]
|
||||||
print("{} already exist".format(reversematches[0]))
|
if parent not in self.folders:
|
||||||
exit(4)
|
print("Folder {} not found".format(uniques["folder"]))
|
||||||
else:
|
|
||||||
if type == "folder":
|
|
||||||
uniques = self.config._explode_unique(args.data)
|
|
||||||
if uniques == False:
|
|
||||||
print("Invalid folder {}".format(args.data))
|
|
||||||
exit(5)
|
|
||||||
if "subfolder" in uniques.keys():
|
|
||||||
parent = "@" + uniques["folder"]
|
|
||||||
if parent not in self.folders:
|
|
||||||
print("Folder {} not found".format(uniques["folder"]))
|
|
||||||
exit(2)
|
|
||||||
self.config._folder_add(**uniques)
|
|
||||||
self.config._saveconfig(self.config.file)
|
|
||||||
print("{} added succesfully".format(args.data))
|
|
||||||
|
|
||||||
if type == "node":
|
|
||||||
nodefolder = args.data.partition("@")
|
|
||||||
nodefolder = "@" + nodefolder[2]
|
|
||||||
if nodefolder not in self.folders and nodefolder != "@":
|
|
||||||
print(nodefolder + " not found")
|
|
||||||
exit(2)
|
exit(2)
|
||||||
uniques = self.config._explode_unique(args.data)
|
self.config._folder_add(**uniques)
|
||||||
if uniques == False:
|
|
||||||
print("Invalid node {}".format(args.data))
|
|
||||||
exit(5)
|
|
||||||
print("You can use the configured setting in a profile using @profilename.")
|
|
||||||
print("You can also leave empty any value except hostname/IP.")
|
|
||||||
print("You can pass 1 or more passwords using comma separated @profiles")
|
|
||||||
print("You can use this variables on logging file name: ${id} ${unique} ${host} ${port} ${user} ${protocol}")
|
|
||||||
newnode = self._questions_nodes(args.data, uniques)
|
|
||||||
if newnode == False:
|
|
||||||
exit(7)
|
|
||||||
self.config._connections_add(**newnode)
|
|
||||||
self.config._saveconfig(self.config.file)
|
|
||||||
print("{} added succesfully".format(args.data))
|
|
||||||
elif args.action == "show":
|
|
||||||
if args.data == None:
|
|
||||||
print("Missing argument node")
|
|
||||||
exit(3)
|
|
||||||
matches = list(filter(lambda k: k == args.data, self.nodes))
|
|
||||||
if len(matches) == 0:
|
|
||||||
print("{} not found".format(args.data))
|
|
||||||
exit(2)
|
|
||||||
node = self.config.getitem(matches[0])
|
|
||||||
for k, v in node.items():
|
|
||||||
if isinstance(v, str):
|
|
||||||
print(k + ": " + v)
|
|
||||||
else:
|
|
||||||
print(k + ":")
|
|
||||||
for i in v:
|
|
||||||
print(" - " + i)
|
|
||||||
elif args.action == "mod":
|
|
||||||
if args.data == None:
|
|
||||||
print("Missing argument node")
|
|
||||||
exit(3)
|
|
||||||
matches = list(filter(lambda k: k == args.data, self.nodes))
|
|
||||||
if len(matches) == 0:
|
|
||||||
print("{} not found".format(args.data))
|
|
||||||
exit(2)
|
|
||||||
node = self.config.getitem(matches[0])
|
|
||||||
edits = self._questions_edit()
|
|
||||||
if edits == None:
|
|
||||||
exit(7)
|
|
||||||
uniques = self.config._explode_unique(args.data)
|
|
||||||
updatenode = self._questions_nodes(args.data, uniques, edit=edits)
|
|
||||||
if not updatenode:
|
|
||||||
exit(7)
|
|
||||||
uniques.update(node)
|
|
||||||
uniques["type"] = "connection"
|
|
||||||
if sorted(updatenode.items()) == sorted(uniques.items()):
|
|
||||||
print("Nothing to do here")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
self.config._connections_add(**updatenode)
|
|
||||||
self.config._saveconfig(self.config.file)
|
self.config._saveconfig(self.config.file)
|
||||||
print("{} edited succesfully".format(args.data))
|
print("{} added succesfully".format(args.data))
|
||||||
|
if type == "node":
|
||||||
|
nodefolder = args.data.partition("@")
|
||||||
|
nodefolder = "@" + nodefolder[2]
|
||||||
|
if nodefolder not in self.folders and nodefolder != "@":
|
||||||
|
print(nodefolder + " not found")
|
||||||
|
exit(2)
|
||||||
|
uniques = self.config._explode_unique(args.data)
|
||||||
|
if uniques == False:
|
||||||
|
print("Invalid node {}".format(args.data))
|
||||||
|
exit(5)
|
||||||
|
print("You can use the configured setting in a profile using @profilename.")
|
||||||
|
print("You can also leave empty any value except hostname/IP.")
|
||||||
|
print("You can pass 1 or more passwords using comma separated @profiles")
|
||||||
|
print("You can use this variables on logging file name: ${id} ${unique} ${host} ${port} ${user} ${protocol}")
|
||||||
|
newnode = self._questions_nodes(args.data, uniques)
|
||||||
|
if newnode == False:
|
||||||
|
exit(7)
|
||||||
|
self.config._connections_add(**newnode)
|
||||||
|
self.config._saveconfig(self.config.file)
|
||||||
|
print("{} added succesfully".format(args.data))
|
||||||
|
|
||||||
|
def _show(self, args):
|
||||||
|
if args.data == None:
|
||||||
|
print("Missing argument node")
|
||||||
|
exit(3)
|
||||||
|
matches = list(filter(lambda k: k == args.data, self.nodes))
|
||||||
|
if len(matches) == 0:
|
||||||
|
print("{} not found".format(args.data))
|
||||||
|
exit(2)
|
||||||
|
node = self.config.getitem(matches[0])
|
||||||
|
for k, v in node.items():
|
||||||
|
if isinstance(v, str):
|
||||||
|
print(k + ": " + v)
|
||||||
|
else:
|
||||||
|
print(k + ":")
|
||||||
|
for i in v:
|
||||||
|
print(" - " + i)
|
||||||
|
|
||||||
|
def _mod(self, args):
|
||||||
|
if args.data == None:
|
||||||
|
print("Missing argument node")
|
||||||
|
exit(3)
|
||||||
|
matches = list(filter(lambda k: k == args.data, self.nodes))
|
||||||
|
if len(matches) == 0:
|
||||||
|
print("{} not found".format(args.data))
|
||||||
|
exit(2)
|
||||||
|
node = self.config.getitem(matches[0])
|
||||||
|
edits = self._questions_edit()
|
||||||
|
if edits == None:
|
||||||
|
exit(7)
|
||||||
|
uniques = self.config._explode_unique(args.data)
|
||||||
|
updatenode = self._questions_nodes(args.data, uniques, edit=edits)
|
||||||
|
if not updatenode:
|
||||||
|
exit(7)
|
||||||
|
uniques.update(node)
|
||||||
|
uniques["type"] = "connection"
|
||||||
|
if sorted(updatenode.items()) == sorted(uniques.items()):
|
||||||
|
print("Nothing to do here")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.config._connections_add(**updatenode)
|
||||||
|
self.config._saveconfig(self.config.file)
|
||||||
|
print("{} edited succesfully".format(args.data))
|
||||||
|
|
||||||
|
|
||||||
def _func_profile(self, args):
|
def _func_profile(self, args):
|
||||||
#Function called when managing profiles
|
#Function called when managing profiles
|
||||||
if not self.case:
|
if not self.case:
|
||||||
args.data[0] = args.data[0].lower()
|
args.data[0] = args.data[0].lower()
|
||||||
if args.action == "del":
|
actions = {"add": self._profile_add, "del": self._profile_del, "mod": self._profile_mod, "show": self._profile_show}
|
||||||
matches = list(filter(lambda k: k == args.data[0], self.profiles))
|
return actions.get(args.action)(args)
|
||||||
if len(matches) == 0:
|
|
||||||
print("{} not found".format(args.data[0]))
|
def _profile_del(self, args):
|
||||||
exit(2)
|
matches = list(filter(lambda k: k == args.data[0], self.profiles))
|
||||||
if matches[0] == "default":
|
if len(matches) == 0:
|
||||||
print("Can't delete default profile")
|
print("{} not found".format(args.data[0]))
|
||||||
exit(6)
|
exit(2)
|
||||||
usedprofile = self._profileused(matches[0])
|
if matches[0] == "default":
|
||||||
if len(usedprofile) > 0:
|
print("Can't delete default profile")
|
||||||
print("Profile {} used in the following nodes:".format(matches[0]))
|
exit(6)
|
||||||
print(", ".join(usedprofile))
|
usedprofile = self._profileused(matches[0])
|
||||||
exit(8)
|
if len(usedprofile) > 0:
|
||||||
question = [inquirer.Confirm("delete", message="Are you sure you want to delete {}?".format(matches[0]))]
|
print("Profile {} used in the following nodes:".format(matches[0]))
|
||||||
confirm = inquirer.prompt(question)
|
print(", ".join(usedprofile))
|
||||||
if confirm["delete"]:
|
exit(8)
|
||||||
self.config._profiles_del(id = matches[0])
|
question = [inquirer.Confirm("delete", message="Are you sure you want to delete {}?".format(matches[0]))]
|
||||||
self.config._saveconfig(self.config.file)
|
confirm = inquirer.prompt(question)
|
||||||
print("{} deleted succesfully".format(matches[0]))
|
if confirm["delete"]:
|
||||||
elif args.action == "show":
|
self.config._profiles_del(id = matches[0])
|
||||||
matches = list(filter(lambda k: k == args.data[0], self.profiles))
|
|
||||||
if len(matches) == 0:
|
|
||||||
print("{} not found".format(args.data[0]))
|
|
||||||
exit(2)
|
|
||||||
profile = self.config.profiles[matches[0]]
|
|
||||||
for k, v in profile.items():
|
|
||||||
if isinstance(v, str):
|
|
||||||
print(k + ": " + v)
|
|
||||||
else:
|
|
||||||
print(k + ":")
|
|
||||||
for i in v:
|
|
||||||
print(" - " + i)
|
|
||||||
elif args.action == "add":
|
|
||||||
matches = list(filter(lambda k: k == args.data[0], self.profiles))
|
|
||||||
if len(matches) > 0:
|
|
||||||
print("Profile {} Already exist".format(matches[0]))
|
|
||||||
exit(4)
|
|
||||||
newprofile = self._questions_profiles(args.data[0])
|
|
||||||
if newprofile == False:
|
|
||||||
exit(7)
|
|
||||||
self.config._profiles_add(**newprofile)
|
|
||||||
self.config._saveconfig(self.config.file)
|
self.config._saveconfig(self.config.file)
|
||||||
print("{} added succesfully".format(args.data[0]))
|
print("{} deleted succesfully".format(matches[0]))
|
||||||
elif args.action == "mod":
|
|
||||||
matches = list(filter(lambda k: k == args.data[0], self.profiles))
|
def _profile_show(self, args):
|
||||||
if len(matches) == 0:
|
matches = list(filter(lambda k: k == args.data[0], self.profiles))
|
||||||
print("{} not found".format(args.data[0]))
|
if len(matches) == 0:
|
||||||
exit(2)
|
print("{} not found".format(args.data[0]))
|
||||||
profile = self.config.profiles[matches[0]]
|
exit(2)
|
||||||
oldprofile = {"id": matches[0]}
|
profile = self.config.profiles[matches[0]]
|
||||||
oldprofile.update(profile)
|
for k, v in profile.items():
|
||||||
edits = self._questions_edit()
|
if isinstance(v, str):
|
||||||
if edits == None:
|
print(k + ": " + v)
|
||||||
exit(7)
|
|
||||||
updateprofile = self._questions_profiles(matches[0], edit=edits)
|
|
||||||
if not updateprofile:
|
|
||||||
exit(7)
|
|
||||||
if sorted(updateprofile.items()) == sorted(oldprofile.items()):
|
|
||||||
print("Nothing to do here")
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
self.config._profiles_add(**updateprofile)
|
print(k + ":")
|
||||||
self.config._saveconfig(self.config.file)
|
for i in v:
|
||||||
print("{} edited succesfully".format(args.data[0]))
|
print(" - " + i)
|
||||||
|
|
||||||
|
def _profile_add(self, args):
|
||||||
|
matches = list(filter(lambda k: k == args.data[0], self.profiles))
|
||||||
|
if len(matches) > 0:
|
||||||
|
print("Profile {} Already exist".format(matches[0]))
|
||||||
|
exit(4)
|
||||||
|
newprofile = self._questions_profiles(args.data[0])
|
||||||
|
if newprofile == False:
|
||||||
|
exit(7)
|
||||||
|
self.config._profiles_add(**newprofile)
|
||||||
|
self.config._saveconfig(self.config.file)
|
||||||
|
print("{} added succesfully".format(args.data[0]))
|
||||||
|
|
||||||
|
def _profile_mod(self, args):
|
||||||
|
matches = list(filter(lambda k: k == args.data[0], self.profiles))
|
||||||
|
if len(matches) == 0:
|
||||||
|
print("{} not found".format(args.data[0]))
|
||||||
|
exit(2)
|
||||||
|
profile = self.config.profiles[matches[0]]
|
||||||
|
oldprofile = {"id": matches[0]}
|
||||||
|
oldprofile.update(profile)
|
||||||
|
edits = self._questions_edit()
|
||||||
|
if edits == None:
|
||||||
|
exit(7)
|
||||||
|
updateprofile = self._questions_profiles(matches[0], edit=edits)
|
||||||
|
if not updateprofile:
|
||||||
|
exit(7)
|
||||||
|
if sorted(updateprofile.items()) == sorted(oldprofile.items()):
|
||||||
|
print("Nothing to do here")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.config._profiles_add(**updateprofile)
|
||||||
|
self.config._saveconfig(self.config.file)
|
||||||
|
print("{} edited succesfully".format(args.data[0]))
|
||||||
|
|
||||||
def _func_others(self, args):
|
def _func_others(self, args):
|
||||||
#Function called when using other commands
|
#Function called when using other commands
|
||||||
if args.command == "ls":
|
actions = {"ls": self._ls, "move": self._mvcp, "cp": self._mvcp, "bulk": self._bulk, "completion": self._completion, "case": self._case, "fzf": self._fzf, "idletime": self._idletime}
|
||||||
print(*getattr(self, args.data), sep="\n")
|
return actions.get(args.command)(args)
|
||||||
elif args.command == "move" or args.command == "cp":
|
|
||||||
if not self.case:
|
def _ls(self, args):
|
||||||
args.data[0] = args.data[0].lower()
|
print(*getattr(self, args.data), sep="\n")
|
||||||
args.data[1] = args.data[1].lower()
|
|
||||||
source = list(filter(lambda k: k == args.data[0], self.nodes))
|
def _mvcp(self, args):
|
||||||
dest = list(filter(lambda k: k == args.data[1], self.nodes))
|
if not self.case:
|
||||||
if len(source) != 1:
|
args.data[0] = args.data[0].lower()
|
||||||
print("{} not found".format(args.data[0]))
|
args.data[1] = args.data[1].lower()
|
||||||
exit(2)
|
source = list(filter(lambda k: k == args.data[0], self.nodes))
|
||||||
if len(dest) > 0:
|
dest = list(filter(lambda k: k == args.data[1], self.nodes))
|
||||||
print("Node {} Already exist".format(args.data[1]))
|
if len(source) != 1:
|
||||||
exit(4)
|
print("{} not found".format(args.data[0]))
|
||||||
nodefolder = args.data[1].partition("@")
|
exit(2)
|
||||||
nodefolder = "@" + nodefolder[2]
|
if len(dest) > 0:
|
||||||
if nodefolder not in self.folders and nodefolder != "@":
|
print("Node {} Already exist".format(args.data[1]))
|
||||||
print("{} not found".format(nodefolder))
|
exit(4)
|
||||||
exit(2)
|
nodefolder = args.data[1].partition("@")
|
||||||
olduniques = self.config._explode_unique(args.data[0])
|
nodefolder = "@" + nodefolder[2]
|
||||||
newuniques = self.config._explode_unique(args.data[1])
|
if nodefolder not in self.folders and nodefolder != "@":
|
||||||
if newuniques == False:
|
print("{} not found".format(nodefolder))
|
||||||
print("Invalid node {}".format(args.data[1]))
|
exit(2)
|
||||||
exit(5)
|
olduniques = self.config._explode_unique(args.data[0])
|
||||||
node = self.config.getitem(source[0])
|
newuniques = self.config._explode_unique(args.data[1])
|
||||||
newnode = {**newuniques, **node}
|
if newuniques == False:
|
||||||
|
print("Invalid node {}".format(args.data[1]))
|
||||||
|
exit(5)
|
||||||
|
node = self.config.getitem(source[0])
|
||||||
|
newnode = {**newuniques, **node}
|
||||||
|
self.config._connections_add(**newnode)
|
||||||
|
if args.command == "move":
|
||||||
|
self.config._connections_del(**olduniques)
|
||||||
|
self.config._saveconfig(self.config.file)
|
||||||
|
action = "moved" if args.command == "move" else "copied"
|
||||||
|
print("{} {} succesfully to {}".format(args.data[0],action, args.data[1]))
|
||||||
|
|
||||||
|
def _bulk(self, args):
|
||||||
|
newnodes = self._questions_bulk()
|
||||||
|
if newnodes == False:
|
||||||
|
exit(7)
|
||||||
|
if not self.case:
|
||||||
|
newnodes["location"] = newnodes["location"].lower()
|
||||||
|
newnodes["ids"] = newnodes["ids"].lower()
|
||||||
|
ids = newnodes["ids"].split(",")
|
||||||
|
hosts = newnodes["host"].split(",")
|
||||||
|
count = 0
|
||||||
|
for n in ids:
|
||||||
|
unique = n + newnodes["location"]
|
||||||
|
matches = list(filter(lambda k: k == unique, self.nodes))
|
||||||
|
reversematches = list(filter(lambda k: k == "@" + unique, self.folders))
|
||||||
|
if len(matches) > 0:
|
||||||
|
print("Node {} already exist, ignoring it".format(unique))
|
||||||
|
continue
|
||||||
|
if len(reversematches) > 0:
|
||||||
|
print("Folder with name {} already exist, ignoring it".format(unique))
|
||||||
|
continue
|
||||||
|
newnode = {"id": n}
|
||||||
|
if newnodes["location"] != "":
|
||||||
|
location = self.config._explode_unique(newnodes["location"])
|
||||||
|
newnode.update(location)
|
||||||
|
if len(hosts) > 1:
|
||||||
|
index = ids.index(n)
|
||||||
|
newnode["host"] = hosts[index]
|
||||||
|
else:
|
||||||
|
newnode["host"] = hosts[0]
|
||||||
|
newnode["protocol"] = newnodes["protocol"]
|
||||||
|
newnode["port"] = newnodes["port"]
|
||||||
|
newnode["options"] = newnodes["options"]
|
||||||
|
newnode["logs"] = newnodes["logs"]
|
||||||
|
newnode["user"] = newnodes["user"]
|
||||||
|
newnode["password"] = newnodes["password"]
|
||||||
|
count +=1
|
||||||
self.config._connections_add(**newnode)
|
self.config._connections_add(**newnode)
|
||||||
if args.command == "move":
|
self.nodes = self._getallnodes()
|
||||||
self.config._connections_del(**olduniques)
|
if count > 0:
|
||||||
self.config._saveconfig(self.config.file)
|
self.config._saveconfig(self.config.file)
|
||||||
if args.command == "move":
|
print("Succesfully added {} nodes".format(count))
|
||||||
print("{} moved succesfully to {}".format(args.data[0],args.data[1]))
|
|
||||||
if args.command == "cp":
|
|
||||||
print("{} copied succesfully to {}".format(args.data[0],args.data[1]))
|
|
||||||
elif args.command == "bulk":
|
|
||||||
newnodes = self._questions_bulk()
|
|
||||||
if newnodes == False:
|
|
||||||
exit(7)
|
|
||||||
if not self.case:
|
|
||||||
newnodes["location"] = newnodes["location"].lower()
|
|
||||||
newnodes["ids"] = newnodes["ids"].lower()
|
|
||||||
ids = newnodes["ids"].split(",")
|
|
||||||
hosts = newnodes["host"].split(",")
|
|
||||||
count = 0
|
|
||||||
for n in ids:
|
|
||||||
unique = n + newnodes["location"]
|
|
||||||
matches = list(filter(lambda k: k == unique, self.nodes))
|
|
||||||
reversematches = list(filter(lambda k: k == "@" + unique, self.folders))
|
|
||||||
if len(matches) > 0:
|
|
||||||
print("Node {} already exist, ignoring it".format(unique))
|
|
||||||
continue
|
|
||||||
if len(reversematches) > 0:
|
|
||||||
print("Folder with name {} already exist, ignoring it".format(unique))
|
|
||||||
continue
|
|
||||||
newnode = {"id": n}
|
|
||||||
if newnodes["location"] != "":
|
|
||||||
location = self.config._explode_unique(newnodes["location"])
|
|
||||||
newnode.update(location)
|
|
||||||
if len(hosts) > 1:
|
|
||||||
index = ids.index(n)
|
|
||||||
newnode["host"] = hosts[index]
|
|
||||||
else:
|
|
||||||
newnode["host"] = hosts[0]
|
|
||||||
newnode["protocol"] = newnodes["protocol"]
|
|
||||||
newnode["port"] = newnodes["port"]
|
|
||||||
newnode["options"] = newnodes["options"]
|
|
||||||
newnode["logs"] = newnodes["logs"]
|
|
||||||
newnode["user"] = newnodes["user"]
|
|
||||||
newnode["password"] = newnodes["password"]
|
|
||||||
count +=1
|
|
||||||
self.config._connections_add(**newnode)
|
|
||||||
self.nodes = self._getallnodes()
|
|
||||||
if count > 0:
|
|
||||||
self.config._saveconfig(self.config.file)
|
|
||||||
print("Succesfully added {} nodes".format(count))
|
|
||||||
else:
|
|
||||||
print("0 nodes added")
|
|
||||||
else:
|
else:
|
||||||
if args.command == "completion":
|
print("0 nodes added")
|
||||||
if args.data[0] == "bash":
|
|
||||||
print(self._help("bashcompletion"))
|
def _completion(self, args):
|
||||||
elif args.data[0] == "zsh":
|
if args.data[0] == "bash":
|
||||||
print(self._help("zshcompletion"))
|
print(self._help("bashcompletion"))
|
||||||
else:
|
elif args.data[0] == "zsh":
|
||||||
if args.command == "case":
|
print(self._help("zshcompletion"))
|
||||||
if args.data[0] == "true":
|
|
||||||
args.data[0] = True
|
def _case(self, args):
|
||||||
elif args.data[0] == "false":
|
if args.data[0] == "true":
|
||||||
args.data[0] = False
|
args.data[0] = True
|
||||||
if args.command == "fzf":
|
elif args.data[0] == "false":
|
||||||
if args.data[0] == "true":
|
args.data[0] = False
|
||||||
args.data[0] = True
|
self._change_settings(args.command, args.data[0])
|
||||||
elif args.data[0] == "false":
|
|
||||||
args.data[0] = False
|
def _fzf(self, args):
|
||||||
if args.command == "idletime":
|
if args.data[0] == "true":
|
||||||
if args.data[0] < 0:
|
args.data[0] = True
|
||||||
args.data[0] = 0
|
elif args.data[0] == "false":
|
||||||
self.config.config[args.command] = args.data[0]
|
args.data[0] = False
|
||||||
self.config._saveconfig(self.config.file)
|
self._change_settings(args.command, args.data[0])
|
||||||
print("Config saved")
|
|
||||||
|
def _idletime(self, args):
|
||||||
|
if args.data[0] < 0:
|
||||||
|
args.data[0] = 0
|
||||||
|
self._change_settings(args.command, args.data[0])
|
||||||
|
|
||||||
|
def _change_settings(self, name, value):
|
||||||
|
self.config.config[name] = value
|
||||||
|
self.config._saveconfig(self.config.file)
|
||||||
|
print("Config saved")
|
||||||
|
|
||||||
def _func_run(self, args):
|
def _func_run(self, args):
|
||||||
if len(args.data) > 1:
|
if len(args.data) > 1:
|
||||||
command = " ".join(args.data[1:])
|
args.action = "noderun"
|
||||||
command = command.split("-")
|
actions = {"noderun": self._node_run, "generate": self._yaml_generate, "run": self._yaml_run}
|
||||||
matches = list(filter(lambda k: k == args.data[0], self.nodes))
|
return actions.get(args.action)(args)
|
||||||
if len(matches) == 0:
|
|
||||||
print("{} not found".format(args.data[0]))
|
def _node_run(self, args):
|
||||||
exit(2)
|
command = " ".join(args.data[1:])
|
||||||
node = self.config.getitem(matches[0])
|
command = command.split("-")
|
||||||
node = self.node(matches[0],**node, config = self.config)
|
matches = list(filter(lambda k: k == args.data[0], self.nodes))
|
||||||
node.run(command)
|
if len(matches) == 0:
|
||||||
print(node.output)
|
print("{} not found".format(args.data[0]))
|
||||||
|
exit(2)
|
||||||
|
node = self.config.getitem(matches[0])
|
||||||
|
node = self.node(matches[0],**node, config = self.config)
|
||||||
|
node.run(command)
|
||||||
|
print(node.output)
|
||||||
|
|
||||||
|
def _yaml_generate(self, args):
|
||||||
|
if os.path.exists(args.data[0]):
|
||||||
|
print("File {} already exists".format(args.data[0]))
|
||||||
|
exit(14)
|
||||||
else:
|
else:
|
||||||
if args.action == "generate":
|
with open(args.data[0], "w") as file:
|
||||||
if os.path.exists(args.data[0]):
|
file.write(self._help("generate"))
|
||||||
print("File {} already exists".format(args.data[0]))
|
file.close()
|
||||||
exit(14)
|
print("File {} generated succesfully".format(args.data[0]))
|
||||||
else:
|
exit()
|
||||||
with open(args.data[0], "w") as file:
|
|
||||||
file.write(self._help("generate"))
|
def _yaml_run(self, args):
|
||||||
file.close()
|
try:
|
||||||
print("File {} generated succesfully".format(args.data[0]))
|
with open(args.data[0]) as file:
|
||||||
exit()
|
scripts = yaml.load(file, Loader=yaml.FullLoader)
|
||||||
|
except:
|
||||||
|
print("failed reading file {}".format(args.data[0]))
|
||||||
|
exit(10)
|
||||||
|
for script in scripts["tasks"]:
|
||||||
|
nodes = {}
|
||||||
|
args = {}
|
||||||
try:
|
try:
|
||||||
with open(args.data[0]) as file:
|
action = script["action"]
|
||||||
scripts = yaml.load(file, Loader=yaml.FullLoader)
|
nodelist = script["nodes"]
|
||||||
except:
|
args["commands"] = script["commands"]
|
||||||
print("failed reading file {}".format(args.data[0]))
|
output = script["output"]
|
||||||
exit(10)
|
|
||||||
for script in scripts["tasks"]:
|
|
||||||
nodes = {}
|
|
||||||
args = {}
|
|
||||||
try:
|
|
||||||
action = script["action"]
|
|
||||||
except:
|
|
||||||
print("Action is mandatory")
|
|
||||||
exit(11)
|
|
||||||
try:
|
|
||||||
nodelist = script["nodes"]
|
|
||||||
except:
|
|
||||||
print("Nodes list is mandatory")
|
|
||||||
exit(11)
|
|
||||||
# try:
|
|
||||||
for i in nodelist:
|
|
||||||
if isinstance(i, dict):
|
|
||||||
name = list(i.keys())[0]
|
|
||||||
this = self.config.getitem(name, i[name])
|
|
||||||
nodes.update(this)
|
|
||||||
elif i.startswith("@"):
|
|
||||||
this = self.config.getitem(i)
|
|
||||||
nodes.update(this)
|
|
||||||
else:
|
|
||||||
this = self.config.getitem(i)
|
|
||||||
nodes[i] = this
|
|
||||||
nodes = self.connnodes(nodes, config = self.config)
|
|
||||||
# except:
|
|
||||||
# print("Failed getting nodes")
|
|
||||||
# exit(12)
|
|
||||||
try:
|
|
||||||
args["commands"] = script["commands"]
|
|
||||||
except:
|
|
||||||
print("Commands list is mandatory")
|
|
||||||
exit(11)
|
|
||||||
if action == "test":
|
if action == "test":
|
||||||
try:
|
args["expected"] = script["expected"]
|
||||||
args["expected"] = script["expected"]
|
except KeyError as e:
|
||||||
except:
|
print("'{}' is mandatory".format(e.args[0]))
|
||||||
print("Expected is mandatory with action 'test'")
|
exit(11)
|
||||||
exit(11)
|
for i in nodelist:
|
||||||
try:
|
if isinstance(i, dict):
|
||||||
args["vars"] = script["variables"]
|
name = list(i.keys())[0]
|
||||||
except:
|
this = self.config.getitem(name, i[name])
|
||||||
pass
|
nodes.update(this)
|
||||||
try:
|
elif i.startswith("@"):
|
||||||
output = script["output"]
|
this = self.config.getitem(i)
|
||||||
except:
|
nodes.update(this)
|
||||||
print("output is mandatory")
|
|
||||||
exit(11)
|
|
||||||
stdout = False
|
|
||||||
if output is None:
|
|
||||||
pass
|
|
||||||
elif output == "stdout":
|
|
||||||
stdout = True
|
|
||||||
elif isinstance(output, str) and action == "run":
|
|
||||||
args["folder"] = output
|
|
||||||
try:
|
|
||||||
options = script["options"]
|
|
||||||
except:
|
|
||||||
options = None
|
|
||||||
if options is not None:
|
|
||||||
thisoptions = {k: v for k, v in options.items() if k in ["prompt", "parallel", "timeout"]}
|
|
||||||
print(thisoptions)
|
|
||||||
args.update(thisoptions)
|
|
||||||
size = str(os.get_terminal_size())
|
|
||||||
p = re.search(r'.*columns=([0-9]+)', size)
|
|
||||||
columns = int(p.group(1))
|
|
||||||
if action == "run":
|
|
||||||
nodes.run(**args)
|
|
||||||
print(script["name"].upper() + "-" * (columns - len(script["name"])))
|
|
||||||
for i in nodes.status.keys():
|
|
||||||
print(" " + i + " " + "-" * (columns - len(i) - 13) + (" PASS(0)" if nodes.status[i] == 0 else " FAIL({})".format(nodes.status[i])))
|
|
||||||
if stdout:
|
|
||||||
for line in nodes.output[i].splitlines():
|
|
||||||
print(" " + line)
|
|
||||||
elif action == "test":
|
|
||||||
nodes.test(**args)
|
|
||||||
print(script["name"].upper() + "-" * (columns - len(script["name"])))
|
|
||||||
for i in nodes.status.keys():
|
|
||||||
print(" " + i + " " + "-" * (columns - len(i) - 13) + (" PASS(0)" if nodes.status[i] == 0 else " FAIL({})".format(nodes.status[i])))
|
|
||||||
if nodes.status[i] == 0:
|
|
||||||
try:
|
|
||||||
myexpected = args["expected"].format(**args["vars"][i])
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
myexpected = args["expected"].format(**args["vars"]["__global__"])
|
|
||||||
except:
|
|
||||||
myexpected = args["expected"]
|
|
||||||
print(" TEST for '{}' --> ".format(myexpected) + str(nodes.result[i]).upper())
|
|
||||||
if stdout:
|
|
||||||
if nodes.status[i] == 0:
|
|
||||||
print(" " + "-" * (len(myexpected) + 16 + len(str(nodes.result[i]))))
|
|
||||||
for line in nodes.output[i].splitlines():
|
|
||||||
print(" " + line)
|
|
||||||
else:
|
else:
|
||||||
print("Wrong action '{}'".format(action))
|
this = self.config.getitem(i)
|
||||||
exit(13)
|
nodes[i] = this
|
||||||
|
nodes = self.connnodes(nodes, config = self.config)
|
||||||
|
stdout = False
|
||||||
|
if output is None:
|
||||||
|
pass
|
||||||
|
elif output == "stdout":
|
||||||
|
stdout = True
|
||||||
|
elif isinstance(output, str) and action == "run":
|
||||||
|
args["folder"] = output
|
||||||
|
try:
|
||||||
|
args["vars"] = script["variables"]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
options = script["options"]
|
||||||
|
thisoptions = {k: v for k, v in options.items() if k in ["prompt", "parallel", "timeout"]}
|
||||||
|
args.update(thisoptions)
|
||||||
|
except:
|
||||||
|
options = None
|
||||||
|
size = str(os.get_terminal_size())
|
||||||
|
p = re.search(r'.*columns=([0-9]+)', size)
|
||||||
|
columns = int(p.group(1))
|
||||||
|
if action == "run":
|
||||||
|
nodes.run(**args)
|
||||||
|
print(script["name"].upper() + "-" * (columns - len(script["name"])))
|
||||||
|
for i in nodes.status.keys():
|
||||||
|
print(" " + i + " " + "-" * (columns - len(i) - 13) + (" PASS(0)" if nodes.status[i] == 0 else " FAIL({})".format(nodes.status[i])))
|
||||||
|
if stdout:
|
||||||
|
for line in nodes.output[i].splitlines():
|
||||||
|
print(" " + line)
|
||||||
|
elif action == "test":
|
||||||
|
nodes.test(**args)
|
||||||
|
print(script["name"].upper() + "-" * (columns - len(script["name"])))
|
||||||
|
for i in nodes.status.keys():
|
||||||
|
print(" " + i + " " + "-" * (columns - len(i) - 13) + (" PASS(0)" if nodes.status[i] == 0 else " FAIL({})".format(nodes.status[i])))
|
||||||
|
if nodes.status[i] == 0:
|
||||||
|
try:
|
||||||
|
myexpected = args["expected"].format(**args["vars"][i])
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
myexpected = args["expected"].format(**args["vars"]["__global__"])
|
||||||
|
except:
|
||||||
|
myexpected = args["expected"]
|
||||||
|
print(" TEST for '{}' --> ".format(myexpected) + str(nodes.result[i]).upper())
|
||||||
|
if stdout:
|
||||||
|
if nodes.status[i] == 0:
|
||||||
|
print(" " + "-" * (len(myexpected) + 16 + len(str(nodes.result[i]))))
|
||||||
|
for line in nodes.output[i].splitlines():
|
||||||
|
print(" " + line)
|
||||||
|
else:
|
||||||
|
print("Wrong action '{}'".format(action))
|
||||||
|
exit(13)
|
||||||
|
|
||||||
def _choose(self, list, name, action):
|
def _choose(self, list, name, action):
|
||||||
#Generates an inquirer list to pick
|
#Generates an inquirer list to pick
|
||||||
@ -1014,7 +1024,9 @@ tasks:
|
|||||||
'''
|
'''
|
||||||
if keyfile is None:
|
if keyfile is None:
|
||||||
keyfile = self.config.key
|
keyfile = self.config.key
|
||||||
key = RSA.import_key(open(keyfile).read())
|
with open(keyfile) as f:
|
||||||
|
key = RSA.import_key(f.read())
|
||||||
|
f.close()
|
||||||
publickey = key.publickey()
|
publickey = key.publickey()
|
||||||
encryptor = PKCS1_OAEP.new(publickey)
|
encryptor = PKCS1_OAEP.new(publickey)
|
||||||
password = encryptor.encrypt(password.encode("utf-8"))
|
password = encryptor.encrypt(password.encode("utf-8"))
|
||||||
|
@ -92,13 +92,14 @@ class node:
|
|||||||
else:
|
else:
|
||||||
self.password = [password]
|
self.password = [password]
|
||||||
|
|
||||||
def __passtx(self, passwords, *, keyfile=None):
|
def _passtx(self, passwords, *, keyfile=None):
|
||||||
# decrypts passwords, used by other methdos.
|
# decrypts passwords, used by other methdos.
|
||||||
dpass = []
|
dpass = []
|
||||||
if keyfile is None:
|
if keyfile is None:
|
||||||
keyfile = self.key
|
keyfile = self.key
|
||||||
if keyfile is not None:
|
if keyfile is not None:
|
||||||
key = RSA.import_key(open(keyfile).read())
|
with open(keyfile) as f:
|
||||||
|
key = RSA.import_key(f.read())
|
||||||
decryptor = PKCS1_OAEP.new(key)
|
decryptor = PKCS1_OAEP.new(key)
|
||||||
for passwd in passwords:
|
for passwd in passwords:
|
||||||
if not re.match('^b[\"\'].+[\"\']$', passwd):
|
if not re.match('^b[\"\'].+[\"\']$', passwd):
|
||||||
@ -147,6 +148,8 @@ class node:
|
|||||||
t = ansi_escape.sub('', t)
|
t = ansi_escape.sub('', t)
|
||||||
t = t.lstrip(" \n\r")
|
t = t.lstrip(" \n\r")
|
||||||
t = t.replace("\r","")
|
t = t.replace("\r","")
|
||||||
|
t = t.replace("\x0E","")
|
||||||
|
t = t.replace("\x0F","")
|
||||||
if var == False:
|
if var == False:
|
||||||
d = open(logfile, "w")
|
d = open(logfile, "w")
|
||||||
d.write(t)
|
d.write(t)
|
||||||
@ -163,7 +166,7 @@ class node:
|
|||||||
def _keepalive(self):
|
def _keepalive(self):
|
||||||
#Send keepalive ctrl+e when idletime passed without new inputs on interact
|
#Send keepalive ctrl+e when idletime passed without new inputs on interact
|
||||||
self.lastinput = time()
|
self.lastinput = time()
|
||||||
t = threading.currentThread()
|
t = threading.current_thread()
|
||||||
while True:
|
while True:
|
||||||
if time() - self.lastinput >= self.idletime:
|
if time() - self.lastinput >= self.idletime:
|
||||||
self.child.sendcontrol("e")
|
self.child.sendcontrol("e")
|
||||||
@ -208,7 +211,7 @@ class node:
|
|||||||
print(connect)
|
print(connect)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
def run(self, commands, vars = None,*, folder = '', prompt = r'>$|#$|\$$|>.$|#.$|\$.$', stdout = False, timeout = 10):
|
def run(self, commands, vars = None,*, folder = '', prompt = r'>$|#$|\$$|>.$|#.$|\$.$', stdout = False, timeout = 20):
|
||||||
'''
|
'''
|
||||||
Run a command or list of commands on the node and return the output.
|
Run a command or list of commands on the node and return the output.
|
||||||
|
|
||||||
@ -241,7 +244,7 @@ class node:
|
|||||||
default False.
|
default False.
|
||||||
|
|
||||||
- timeout (int):Time in seconds for expect to wait for prompt/EOF.
|
- timeout (int):Time in seconds for expect to wait for prompt/EOF.
|
||||||
default 10.
|
default 20.
|
||||||
|
|
||||||
### Returns:
|
### Returns:
|
||||||
|
|
||||||
@ -292,7 +295,7 @@ class node:
|
|||||||
f.close()
|
f.close()
|
||||||
return connect
|
return connect
|
||||||
|
|
||||||
def test(self, commands, expected, vars = None,*, prompt = r'>$|#$|\$$|>.$|#.$|\$.$', timeout = 10):
|
def test(self, commands, expected, vars = None,*, prompt = r'>$|#$|\$$|>.$|#.$|\$.$', timeout = 20):
|
||||||
'''
|
'''
|
||||||
Run a command or list of commands on the node, then check if expected value appears on the output after the last command.
|
Run a command or list of commands on the node, then check if expected value appears on the output after the last command.
|
||||||
|
|
||||||
@ -324,7 +327,7 @@ class node:
|
|||||||
need some special symbol.
|
need some special symbol.
|
||||||
|
|
||||||
- timeout (int):Time in seconds for expect to wait for prompt/EOF.
|
- timeout (int):Time in seconds for expect to wait for prompt/EOF.
|
||||||
default 10.
|
default 20.
|
||||||
|
|
||||||
### Returns:
|
### Returns:
|
||||||
bool: true if expected value is found after running the commands
|
bool: true if expected value is found after running the commands
|
||||||
@ -390,7 +393,7 @@ class node:
|
|||||||
if self.logs != '':
|
if self.logs != '':
|
||||||
self.logfile = self._logfile()
|
self.logfile = self._logfile()
|
||||||
if self.password[0] != '':
|
if self.password[0] != '':
|
||||||
passwords = self.__passtx(self.password)
|
passwords = self._passtx(self.password)
|
||||||
else:
|
else:
|
||||||
passwords = []
|
passwords = []
|
||||||
expects = ['yes/no', 'refused', 'supported', 'cipher', 'sage', 'timeout', 'unavailable', 'closed', '[p|P]assword:|[u|U]sername:', r'>$|#$|\$$|>.$|#.$|\$.$', 'suspend', pexpect.EOF, pexpect.TIMEOUT, "No route to host", "resolve hostname", "no matching host key"]
|
expects = ['yes/no', 'refused', 'supported', 'cipher', 'sage', 'timeout', 'unavailable', 'closed', '[p|P]assword:|[u|U]sername:', r'>$|#$|\$$|>.$|#.$|\$.$', 'suspend', pexpect.EOF, pexpect.TIMEOUT, "No route to host", "resolve hostname", "no matching host key"]
|
||||||
@ -403,7 +406,7 @@ class node:
|
|||||||
if self.logs != '':
|
if self.logs != '':
|
||||||
self.logfile = self._logfile()
|
self.logfile = self._logfile()
|
||||||
if self.password[0] != '':
|
if self.password[0] != '':
|
||||||
passwords = self.__passtx(self.password)
|
passwords = self._passtx(self.password)
|
||||||
else:
|
else:
|
||||||
passwords = []
|
passwords = []
|
||||||
expects = ['[u|U]sername:', 'refused', 'supported', 'cipher', 'sage', 'timeout', 'unavailable', 'closed', '[p|P]assword:', r'>$|#$|\$$|>.$|#.$|\$.$', 'suspend', pexpect.EOF, pexpect.TIMEOUT, "No route to host", "resolve hostname", "no matching host key"]
|
expects = ['[u|U]sername:', 'refused', 'supported', 'cipher', 'sage', 'timeout', 'unavailable', 'closed', '[p|P]assword:', r'>$|#$|\$$|>.$|#.$|\$.$', 'suspend', pexpect.EOF, pexpect.TIMEOUT, "No route to host", "resolve hostname", "no matching host key"]
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user