Skip to content

tttech-nerve/nerve-api-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nerve LIB

The nerve_lib provides an interface to the REST API of a Nerve Management System in python. It implements authentication, and management of nodes and workloads. The nerve_lib can be used to integrate Nerve related tasks into a build pipeline (e.g. automatically creating a workload and deploying it on a test node when a new version of an application image is built).

Table of Contents

Installation

To use the nerve_lib in a python project it has to be installed fist. The easiest way to do so is to add the dependency with poetry. If poetry is not used, the library can be added by copying the files and adding the dependencies.

Poetry

The nerve_lib is implemented as a poetry package. Poetry is a project and dependency management tool for python. Refer to the poetry documentation for more information on how to install poetry and how to use it to manage a python project.

To add the nerve_lib to your python project with poetry simply add the dependency with

poetry add git+https://github.com/tttech-nerve/nerve-api-python.git

and then install it into the environment with

poetry install

Manual

If the python project or script is not managed by poetry, the nerve_lib folder must be copied into the project tree. Furthermore the dependencies as listed in requirements.txt must be installed in the python environment of the project

pip install -r requirements.txt

Usage

The nerve_lib provides functions to manage the NERVE Management System and NERVE Nodes via API calls. It is split into different regions to define API interfaces into logical groups. Overview and Examples provide a very rough guideline on how to use the library. For details have a look at the code documentation. A more interactive version of the documentation is available by cloning the repository and opening docs/html/index.html in a browser.

Overview

Handle Description
setup_logging Defines a common logging schema. The function is automatically called when using MSHandle or NodeHandle.
CheckStatusCodeError When API functions are used, the returned status code is evaluated. An invalid code will raise this error type.
WorkloadDeployError Handles errors during workload deployment.
NodeHandle Provides functionality to manage local nodes.
MSHandle Manages the NERVE Management System.
MSWorkloads Manages workloads in the Management System.
LocalWorkloads Manages workloads on local nodes.
MSNode Represents a node in the Management System.
LocalNode Represents a local node.
MSUser Manages users in the Management System.
MSRole Manages roles in the Management System.
LocalUser Manages users on the local node.
LDAP Provides LDAP-related functionality.
MSDNA Manages DNA configurations in the Management System.
LocalDNA Manages DNA configurations on the local node.
MSLabel Manages labels in the Management System.
MSNotifications Handles notifications in the Management System.
MSOpenSearch Provides OpenSearch-related API interface.
InternalRegistry Manages the internal registry in the Management System.
DockerVolumes Manages Docker volumes in the Management System.

Examples

Provision a new workload

from nerve_lib import MSHandle
from nerve_lib import MSWorkloads

with MSHandle("testms.nerve.cloud", "ms-username", "ms-password") as ms_handle:
    wl = MSWorkloads(ms_handle)
    wl_config = wl.gen_workload_configuration(
        "docker",
        wrkld_name="docker",
        file_paths=["docker.tar"],
        restart_policy="always"
    )
    wl.provision_workload(wl_config, file_paths=["images/docker.tar"])

Get dict of all nodes containing "MFN" in the name

from nerve_lib import MSHandle
from nerve_lib import MSNode

with MSHandle("testms.nerve.cloud", "ms-username", "ms-password") as ms_handle:
    nodes = MSNode(ms_handle)
    nodes.get_nodes_by_name("MFN")

About

Python library that implements the Nerve API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages