ztcli_api.utils module

ZT platform and JSON/file handling utilities.

ztcli_api.utils.dump_json(endpoint, data, opener=None)[source]

Dump JSON endpoint data to a file using optional opener.

ztcli_api.utils.get_platform_path()[source]

Find platform path to ZT home directory (where the authtoken lives).

Returns

path to ZT home as Path obj

ztcli_api.utils.get_token(zt_home=None)[source]

Get ZeroTier authentication token (requires root or user acl).

Parameters

zt_home – non-std path to ZT home directory

Return zt_auth

contents of ZT authtoken file or None

ztcli_api.utils.json_dump_file(endpoint, data, dirname=None, is_posix=['linux'])[source]

Dump JSON endpoint data to a named file and, optionally, to a target directory.

Parameters
  • endpoint – ZT endpoint name => filename

  • data – endpoint data to dump

  • dirname – target directory name

  • is_posix – default is platform_check(), force True/False if needed

ztcli_api.utils.json_load_file(endpoint, dirname=None, is_posix=['linux'])[source]

Load JSON endpoint data from a named file and, optionally, a target directory.

Parameters
  • endpoint – ZT endpoint name => filename

  • dirname – target directory name

  • is_posix – default is platform_check(), force True/False

ztcli_api.utils.load_json(endpoint, opener=None)[source]

Load JSON endpoint data from a file using optional opener.

ztcli_api.utils.name_generator(size=10, chars='abcdefghijklmnopqrstuvwxyz0123456789', no_sep=False)[source]

Generate random ZeroTier network names or other ID strings. Default is 2 substrings of size with an underscore as separator, eg, if size is 10, the returned string is 21 characters.

Parameters
  • size – number of chars in each substring

  • chars – character types used

  • no_sep – if False, do not use separator, return size instead

Return str

ztcli_api.utils.platform_check()[source]

Check to see if we think we are POSIX.

Return valid_os

True if POSIX, else False

ztcli_api.utils.pprint(obj)[source]

Pretty printer for JSON.

Parameters

obj – JSON obj