-
Notifications
You must be signed in to change notification settings - Fork 0
Zerotierlib DOCS v.1.4
- requests
- subprocess
- psutil
- pydbus
- pathlib
Flatpak imports requierements in a different way, so there's no need to create one, but, you could use in theory this library in other way.
Thanks to ZeroTierOne API v.0.1.0 we can manipulate the zerotier-one service, this in theory works for Linux, MacOS and Windows versions, but this library only works (meant to work) in Linux OS.
- COMMANDS : Tuple of commands to manage ZeroTier service.
- URL : Base URL for the ZeroTier API (You could try it on postman).
- FILE: Configuration file where X-ZT1-Auth is stored.
- SERVICE: Name of ZeroTier service.
They're a total of 16 methods,
-
__init__
: The class constructor. - ztStart: (Deprecated) Old way to start the application.
- ztStatus: Checks if the ZeroTier service is active.
- ztEnableStatus: Checks the enable status of the ZeroTier service.
- service: Changes the status of the ZeroTier service.
- _ztActivate: Activates the ZeroTier service based on the current status, NOT FOR ACUAL USE OUTSIDE OF THE LIBRARY.
- readToken: Reads the API token from the configuration file.
- checkToken: Checks if the provided API token is valid.
- saveToken: Saves the API token to the configuration file.
- getToken: Retrieves the API token from the ZeroTier service.
- getNetworks: Retrieves information about ZeroTier networks.
- joinNetworks: Joins a ZeroTier network.
- updateNetwork: (Not implemented) Updates a ZeroTier network.
- leaveNetworks: Leaves a ZeroTier network.
- getPeers: Retrieves information about peers in a ZeroTier network.
These methods provide functionality to interact with the ZeroTier API, perform operations on the ZeroTier service, and obtain information about networks and peers within those networks.
Initializes a new instance of the ZeroTierNetwork class.
Args:
- api_token (str, optional): The API token for ZeroTier authentication. Defaults to None.
Old way to start application, not sure if it works with flatpak, needs reimplementation.
Returns:
- str: Result of the operation
Return Ex: 'OK'
Checks if the ZeroTier service is active, it's like doing "sudo systemctl status"
Returns:
- bool: True if the service is active, False otherwise.
Checks the enable status of the Zerotier Service
Returns:
- bool: True if the service is enable, False otherwise.
Change the status of the ZeroTier service.
Args:
- setstatus (int): The desired status of the service Ex:
- start
- stop
- enable (won't work)
- disable (won't work)
Returns:
- bool: True if the operation was succesful, False otherwise.
Internal class that activates the current status, use service() instead.
Reads the API token from the configuration file.
Returns: int: Status code indicating the result of reading the token.
200 - OK 401 - Auth problems 404 - No response.
Check if the provided API token is valid.
Args:
- api_token (str): The API token to check.
Returns:
- bool: True if the token is valid, False otherwise.
Saves the API token to the configuration file internal use only.
Retrieves the API token "X-ZT1-Auth" from the ZeroTier service and use saveToken to save it.
Returns: str: The retrieved X-ZT1-Auth API token.
Token that is needed to make a petition to zerotier-one service.
Retrieves information about all networks or a specific network.
Args:
- network (str,optional): The network ID to retrieve information for. Defaults to none.
Returns:
- dict: The JSON response containing network information.
Example use:
Get all network information:
from zerotierlib import ZeroTierNetwork networks = ZeroTierNetwork('[X-ZT1-Auth]') print(networks.getNetworks())
Get a specific network information:
from zerotierlib import ZeroTierNetwork networks = ZeroTierNetwork('[X-ZT1-Auth]') print(networks.getNetworks('e8da8895f2fc2be'))
Joins a ZeroTier network
Args:
- network (str): The network Id to join
Returns:
- dict: The JSON response indicating the result of the operation.
Ex:
from zerotierlib import ZeroTierNetwork networks = ZeroTierNetwork('[X-ZT1-Auth]') print(networks.joinNetworks('e8da8895f2fc2be'))
Update a ZeroTier network, implementation is planned in version 2.0 Args: network (str): The network ID to update. config (dict): The configuration data to update the network with. Note: his method is planned for implementation in Version 2.0.
Leaves a ZeroTier network. Args:
- network (str): The network ID to leave. Returns:
- Response: The response object indicating the result of the operation
Retrieves information about peers in a ZeroTier network.
Args:
- network (str,optional): The network ID to retrieve peer information for. Defaults to None.
Returns:
- dict: The JSON response containing peer information.