minor bug fixes, add new tags, add bulk using file
This commit is contained in:
@ -1,2 +1,2 @@
|
|||||||
__version__ = "4.1.2"
|
__version__ = "4.1.3"
|
||||||
|
|
||||||
|
@ -110,6 +110,7 @@ class connapp:
|
|||||||
#BULKPARSER
|
#BULKPARSER
|
||||||
bulkparser = subparsers.add_parser("bulk", description="Add nodes in bulk")
|
bulkparser = subparsers.add_parser("bulk", description="Add nodes in bulk")
|
||||||
bulkparser.add_argument("bulk", const="bulk", nargs=0, action=self._store_type, help="Add nodes in bulk")
|
bulkparser.add_argument("bulk", const="bulk", nargs=0, action=self._store_type, help="Add nodes in bulk")
|
||||||
|
bulkparser.add_argument("-f", "--file", nargs=1, help="Import nodes from a file. First line nodes, second line hosts")
|
||||||
bulkparser.set_defaults(func=self._func_others)
|
bulkparser.set_defaults(func=self._func_others)
|
||||||
# EXPORTPARSER
|
# EXPORTPARSER
|
||||||
exportparser = subparsers.add_parser("export", description="Export connection folder to Yaml file")
|
exportparser = subparsers.add_parser("export", description="Export connection folder to Yaml file")
|
||||||
@ -340,7 +341,7 @@ class connapp:
|
|||||||
elif isinstance(v, dict):
|
elif isinstance(v, dict):
|
||||||
print(k + ":")
|
print(k + ":")
|
||||||
for i,d in v.items():
|
for i,d in v.items():
|
||||||
print(" - " + i + ": " + d)
|
print(" - " + i + ": " + str(d))
|
||||||
|
|
||||||
def _mod(self, args):
|
def _mod(self, args):
|
||||||
if args.data == None:
|
if args.data == None:
|
||||||
@ -439,7 +440,7 @@ class connapp:
|
|||||||
elif isinstance(v, dict):
|
elif isinstance(v, dict):
|
||||||
print(k + ":")
|
print(k + ":")
|
||||||
for i,d in v.items():
|
for i,d in v.items():
|
||||||
print(" - " + i + ": " + d)
|
print(" - " + i + ": " + str(d))
|
||||||
|
|
||||||
def _profile_add(self, args):
|
def _profile_add(self, args):
|
||||||
matches = list(filter(lambda k: k == args.data[0], self.profiles))
|
matches = list(filter(lambda k: k == args.data[0], self.profiles))
|
||||||
@ -542,6 +543,18 @@ class connapp:
|
|||||||
print("{} {} succesfully to {}".format(args.data[0],action, args.data[1]))
|
print("{} {} succesfully to {}".format(args.data[0],action, args.data[1]))
|
||||||
|
|
||||||
def _bulk(self, args):
|
def _bulk(self, args):
|
||||||
|
if args.file and os.path.isfile(args.file[0]):
|
||||||
|
with open(args.file[0], 'r') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
# Expecting exactly 2 lines
|
||||||
|
if len(lines) < 2:
|
||||||
|
raise ValueError("The file must contain at least two lines: one for nodes, one for hosts.")
|
||||||
|
|
||||||
|
nodes = lines[0].strip()
|
||||||
|
hosts = lines[1].strip()
|
||||||
|
newnodes = self._questions_bulk(nodes, hosts)
|
||||||
|
else:
|
||||||
newnodes = self._questions_bulk()
|
newnodes = self._questions_bulk()
|
||||||
if newnodes == False:
|
if newnodes == False:
|
||||||
exit(7)
|
exit(7)
|
||||||
@ -1361,12 +1374,12 @@ class connapp:
|
|||||||
result["id"] = unique
|
result["id"] = unique
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _questions_bulk(self):
|
def _questions_bulk(self, nodes="", hosts=""):
|
||||||
#Questions when using bulk command
|
#Questions when using bulk command
|
||||||
questions = []
|
questions = []
|
||||||
questions.append(inquirer.Text("ids", message="add a comma separated list of nodes to add", validate=self._bulk_node_validation))
|
questions.append(inquirer.Text("ids", message="add a comma separated list of nodes to add", default=nodes, validate=self._bulk_node_validation))
|
||||||
questions.append(inquirer.Text("location", message="Add a @folder, @subfolder@folder or leave empty", validate=self._bulk_folder_validation))
|
questions.append(inquirer.Text("location", message="Add a @folder, @subfolder@folder or leave empty", validate=self._bulk_folder_validation))
|
||||||
questions.append(inquirer.Text("host", message="Add comma separated list of Hostnames or IPs", validate=self._bulk_host_validation))
|
questions.append(inquirer.Text("host", message="Add comma separated list of Hostnames or IPs", default=hosts, validate=self._bulk_host_validation))
|
||||||
questions.append(inquirer.Text("protocol", message="Select Protocol/app", validate=self._protocol_validation))
|
questions.append(inquirer.Text("protocol", message="Select Protocol/app", validate=self._protocol_validation))
|
||||||
questions.append(inquirer.Text("port", message="Select Port Number", validate=self._port_validation))
|
questions.append(inquirer.Text("port", message="Select Port Number", validate=self._port_validation))
|
||||||
questions.append(inquirer.Text("options", message="Pass extra options to protocol/app", validate=self._default_validation))
|
questions.append(inquirer.Text("options", message="Pass extra options to protocol/app", validate=self._default_validation))
|
||||||
|
@ -582,6 +582,8 @@ class node:
|
|||||||
attempts = 1
|
attempts = 1
|
||||||
while attempts <= max_attempts:
|
while attempts <= max_attempts:
|
||||||
child = pexpect.spawn(cmd)
|
child = pexpect.spawn(cmd)
|
||||||
|
if isinstance(self.tags, dict) and self.tags.get("console"):
|
||||||
|
child.sendline()
|
||||||
if debug:
|
if debug:
|
||||||
print(cmd)
|
print(cmd)
|
||||||
self.mylog = io.BytesIO()
|
self.mylog = io.BytesIO()
|
||||||
@ -635,6 +637,12 @@ class node:
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if isinstance(self.tags, dict) and self.tags.get("post_connect_commands"):
|
||||||
|
cmds = self.tags.get("post_connect_commands")
|
||||||
|
commands = [cmds] if isinstance(cmds, str) else cmds
|
||||||
|
for command in commands:
|
||||||
|
child.sendline(command)
|
||||||
|
sleep(1)
|
||||||
child.readline(0)
|
child.readline(0)
|
||||||
self.child = child
|
self.child = child
|
||||||
return True
|
return True
|
||||||
|
@ -2646,6 +2646,8 @@ class node:
|
|||||||
attempts = 1
|
attempts = 1
|
||||||
while attempts <= max_attempts:
|
while attempts <= max_attempts:
|
||||||
child = pexpect.spawn(cmd)
|
child = pexpect.spawn(cmd)
|
||||||
|
if isinstance(self.tags, dict) and self.tags.get("console"):
|
||||||
|
child.sendline()
|
||||||
if debug:
|
if debug:
|
||||||
print(cmd)
|
print(cmd)
|
||||||
self.mylog = io.BytesIO()
|
self.mylog = io.BytesIO()
|
||||||
@ -2699,6 +2701,12 @@ class node:
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if isinstance(self.tags, dict) and self.tags.get("post_connect_commands"):
|
||||||
|
cmds = self.tags.get("post_connect_commands")
|
||||||
|
commands = [cmds] if isinstance(cmds, str) else cmds
|
||||||
|
for command in commands:
|
||||||
|
child.sendline(command)
|
||||||
|
sleep(1)
|
||||||
child.readline(0)
|
child.readline(0)
|
||||||
self.child = child
|
self.child = child
|
||||||
return True</code></pre>
|
return True</code></pre>
|
||||||
|
Reference in New Issue
Block a user