Client Interface¶
Creating a client¶
-
class
netlab.client.
Client
(system='default', config=None, config_path=None)¶ A client for communicating with a NETLAB+ server.
- Parameters
- Returns
A client instance with which you can use to interact with a remote NETLAB+ system.
-
call
(method, task_wait=True, task_poll=3, **kwargs)¶ Calls an API method.
Warning
This is a low-level API method and should not be used by most users.
Required:
- Parameters
method (str) – the method name
Optional:
- Parameters
Keyword Arguments:
All other named arguments are passed as parameters to the API backend and are specific to the method type. See the API documentation for method parameters.
Tasks:
Methods ending in “.task” are long running tasks. Tasks may be invoked syncronously or asyncronously by setting task_wait.
If task_wait == True, call() will continuously poll the task, wait for completion or error, and return task result on success. This is the default if task_wait is not specified.
If task_wait == False, call() will return the task_id of the created task but will not wait. This may be helpful if you want to do other work while waiting, or run tasks in parallel. Call task_check() to get the current task state, task progress, task result, or task error. Call task_wait() at a later time to wait on a task.
- Returns
A value or an object (check the API documentation).
- Raises
NetlabError – if the NETLAB+ server returns an error response.
Config JSON, dictionary, and environment variables¶
-
config
¶ The following parameters are used by config.json and the dictionary passed directly when instantiating the
netlab.client.Client
.- Parameters
host (str) – IP Address or hostname of remote NETLAB+ API. Defaults to
'localhost'
.user (str) – User account ID from NETLAB+ system.
token (str) – Token obtained from NETLAB+ system.
port (int) – Port of remote NETLAB+ API. Defaults to
9000
.timeout (int) – The amount of time in seconds of no response from the socket before it will close. Defaults to
10
.
Example:
config = { "host": "192.168.1.10", "user": "administrator", "token": "S25GWP5P2247CMRDNLTCNKATT49KSGEDDPXMTM6A", "port": 9000, "timeout": 10 }
-
config_env
¶ Each of the above configuration options can be specified as environment variables:
-
NETLAB_CONFIG_HOST
¶ IP Address or hostname of remote NETLAB+ API.
-
NETLAB_CONFIG_USER
¶ User account ID from NETLAB+ system.
-
NETLAB_CONFIG_TOKEN
¶ Token obtained from NETLAB+ system.
-
NETLAB_CONFIG_PORT
¶ Port of remote NETLAB+ API.
-
NETLAB_CONFIG_TIMEOUT
¶ The amount of time in seconds of no response from the socket before it will close.
-