minor bug fixes, add new tags, add bulk using file

This commit is contained in:
2025-05-09 17:44:29 -03:00
parent 582459d6d3
commit e2e4c9bfe7
4 changed files with 36 additions and 7 deletions

View File

@ -1,2 +1,2 @@
__version__ = "4.1.2"
__version__ = "4.1.3"

View File

@ -110,6 +110,7 @@ class connapp:
#BULKPARSER
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("-f", "--file", nargs=1, help="Import nodes from a file. First line nodes, second line hosts")
bulkparser.set_defaults(func=self._func_others)
# EXPORTPARSER
exportparser = subparsers.add_parser("export", description="Export connection folder to Yaml file")
@ -340,7 +341,7 @@ class connapp:
elif isinstance(v, dict):
print(k + ":")
for i,d in v.items():
print(" - " + i + ": " + d)
print(" - " + i + ": " + str(d))
def _mod(self, args):
if args.data == None:
@ -439,7 +440,7 @@ class connapp:
elif isinstance(v, dict):
print(k + ":")
for i,d in v.items():
print(" - " + i + ": " + d)
print(" - " + i + ": " + str(d))
def _profile_add(self, args):
matches = list(filter(lambda k: k == args.data[0], self.profiles))
@ -542,7 +543,19 @@ class connapp:
print("{} {} succesfully to {}".format(args.data[0],action, args.data[1]))
def _bulk(self, args):
newnodes = self._questions_bulk()
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()
if newnodes == False:
exit(7)
if not self.case:
@ -1361,12 +1374,12 @@ class connapp:
result["id"] = unique
return result
def _questions_bulk(self):
def _questions_bulk(self, nodes="", hosts=""):
#Questions when using bulk command
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("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("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))

View File

@ -582,6 +582,8 @@ class node:
attempts = 1
while attempts <= max_attempts:
child = pexpect.spawn(cmd)
if isinstance(self.tags, dict) and self.tags.get("console"):
child.sendline()
if debug:
print(cmd)
self.mylog = io.BytesIO()
@ -635,6 +637,12 @@ class node:
else:
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)
self.child = child
return True

View File

@ -2646,6 +2646,8 @@ class node:
attempts = 1
while attempts &lt;= max_attempts:
child = pexpect.spawn(cmd)
if isinstance(self.tags, dict) and self.tags.get(&#34;console&#34;):
child.sendline()
if debug:
print(cmd)
self.mylog = io.BytesIO()
@ -2699,6 +2701,12 @@ class node:
else:
break
if isinstance(self.tags, dict) and self.tags.get(&#34;post_connect_commands&#34;):
cmds = self.tags.get(&#34;post_connect_commands&#34;)
commands = [cmds] if isinstance(cmds, str) else cmds
for command in commands:
child.sendline(command)
sleep(1)
child.readline(0)
self.child = child
return True</code></pre>