Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/import.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ An import can be started through the subcommand ``import``::
-p, --password ask for credentials for connections to the devices
-P PASSWORD, --Password PASSWORD
credentials for connections to the devices
-s, --secret ask for secret credentials to enter enable mode
-S SECRET, --Secret SECRET
secret credentials to enter enable mode
-t THREADS, --threads THREADS
number of threads to run
-v LEVEL, --verbose LEVEL
Expand All @@ -59,6 +62,11 @@ password/authentication by key. To change this behavior, the ``-u/--user`` and
``-p/--password|-P/--Password`` options can be used to specify the user to use, and tells the
importer to ask|set for the password to use.

The importer will collect the data of the devices with the permissions of the
user logged in by the napalm driver. If enable mode is required to collect the
data, the ``-s/--secret|-S/--Secret`` options tells the importer to ask|set for
the secret to enter enable mode.

The import is multithreaded, and split by device. The default number of threads
is 10, but can be changed with the ``-t/--threads`` option.

Expand Down Expand Up @@ -102,6 +110,10 @@ To use a different user, for example `bar` do::

$ netbox-netprod-importer import -u bar -p -f ~/importer/devices.yml

If enable mode is required to collect the data of these devices, do::

$ netbox-netprod-importer import -u bar -p -s -f ~/importer/devices.yml

And to use more threads and enable the overwrite mode to get a clean clone of a
device state::

Expand Down
12 changes: 12 additions & 0 deletions docs/interconnect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ The interconnections feature can be started through the subcommand
-p, --password ask for credentials for connections to the devices
-P PASSWORD, --Password PASSWORD
credentials for connections to the devices
-s, --secret ask for secret credentials to enter enable mode
-S SECRET, --Secret SECRET
secret credentials to enter enable mode
-t THREADS, --threads THREADS
number of threads to run
--overwrite overwrite data already pushed
Expand All @@ -51,6 +54,11 @@ password/authentication by key. To change this behavior, the ``-u/--user`` and
``-p/--password`` options can be used to specify the user to use, and tells
netbox-netprod-importer to ask for the password to use.

The importer will collect the data of the devices with the permissions of the
user logged in by the napalm driver. If enable mode is required to collect the
data, the ``-s/--secret|-S/--Secret`` options tells the importer to ask|set for
the secret to enter enable mode.

The process is multithreaded, and split by device. The default number of
threads is 10, but can be changed with the ``-t/--threads`` option.

Expand Down Expand Up @@ -100,6 +108,10 @@ To use a different user, for example `bar` do::

$ netbox-netprod-importer interco -u bar -p -f ~/importer/devices.yml

If enable mode is required to collect the data of these devices, do::

$ netbox-netprod-importer interco -u bar -p -s -f ~/importer/devices.yml

And to use more threads::

$ netbox-netprod-importer interco -u bar -p -t 30 -f ~/importer/devices.yml
Expand Down
17 changes: 17 additions & 0 deletions netbox_netprod_importer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ def parse_args():
help="credentials for connections to the devices",
dest="password", type=str
)
sp.add_argument(
"-s", "--secret",
help="ask for secret credentials to enter enable mode",
dest="ask_secret", action="store_true"
)
sp.add_argument(
"-S", "--Secret", metavar="SECRET",
help="secret credentials to enter enable mode",
dest="secret", type=str
)
sp.add_argument(
"-t", "--threads", metavar="THREADS",
help="number of threads to run",
Expand Down Expand Up @@ -144,6 +154,13 @@ def _get_creds(parsed_args):
elif parsed_args.password:
creds = (parsed_args.user or getpass.getuser(), parsed_args.password)

if parsed_args.ask_secret:
creds = creds + tuple([getpass.getpass(prompt="Secret pasword: ")])
elif parsed_args.secret:
creds = creds + tuple([parsed_args.secret])
else:
creds = creds + tuple([None])

return creds


Expand Down
8 changes: 7 additions & 1 deletion netbox_netprod_importer/devices_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ def parse_devices_yaml_def(devices_yaml, creds=None):
with open(devices_yaml) as devices_yaml_str:
for hostname, props in tqdm(yaml.safe_load(devices_yaml_str).items()):
try:
optional_args = props.get("optional_args")
if creds[2] is not None:
if optional_args is None:
optional_args = {"secret": creds[2]}
else:
optional_args["secret"] = creds[2]
devices[hostname] = DeviceImporter(
props.get("target") or hostname,
napalm_driver_name=props["driver"],
napalm_optional_args=props.get("optional_args"),
napalm_optional_args=optional_args,
creds=creds,
discovery_protocol=props.get("discovery_protocol")
)
Expand Down