semvec/pypi-packages huggingface dataset:
p2.Loader 0.2.10
P2 Loader module to load resources.
License: BSD
Keywords: p2.loader

=========
p2.loader
=========


.. image:: https://img.shields.io/pypi/v/p2.loader.svg
        :target: https://pypi.python.org/pypi/p2.loader


Resource loader for the P2 platform. This base class implements common logic used by all p2.loader drivers.

License
-------

* Free software: BSD license


Usage
-----

.. code-block::

    from p2.driver import get_driver

    """ get a p2.loader driver instance object.
        You can pass a first set of resources.
        These will be stored at construction time
        if not already present in p2.store"""
    params = {
            'layer': <driver>,
            'tag': <any tag...>
    }

    driver = get_driver(
        module='p2.loader',
        driver=<driver>,
        class_name='Loader',
        **params)

    """ this is implemented by each driver and valorises the
        self.root attribute """
    driver.get_resources()

    """ Synchronize resources starting from root, implemented by this base class """
    driver.sync_resources()


Description
-----------

This class handles generic infrastructure resources. A resource identifies a possible target for a chaos experiment.
All resources are stored in the ``p2.store.resources`` table.

Resources are hierarchically organized.
The Loader class exports methods to keep the ``p2.store`` in sync with the infrastructure.

Resources are grouped by "layers" and "tags".
The layer generally identifies the driver used, aka 'k8' for Kubernetes resources.
The tag groups together resources handled by a driver. In case of Kubernetes the tag can be the Kubernetes context.
So the same p2.loader.k8 driver runs on different context and the couple (layer, tag) uniquely identifies all resources handled by a specific instance of the driver.


Classes exported
################

Resource
********

Attributes:

* layer: str    identifies the driver
* kind:str
* name:str
* tag:str       used to group resources
* profile:dict
* children:list


Loader (base class)
*******************

Attributes:

* resources:list

Methods:

* get_resources()   : abstract class to be implemented by specific drivers
* sync_resources()  : synchronise resources in ``p2.store`` (deletes old resources in ``p2.store`` with same tag not present any more in the infrastructure)

The ``p2.store.resources`` table schema
***************************************

*  id:serial primary key
*  parent_id: int
*  layer: str
*  kind: str
*  name: str
*  tag: str
*  profile: JSONB
*  status:str

UNIQUE constraint on (kind, name, tag)