valence/doc/source/developer-guide/db_development.rst
akhiljain23 cf99ff0165 Updating docs
>> Changed project name from plasma to valence in docs.
>> Fixed docstring indentation.
>> Added features docs.
>> Added driver docs.
>> Hidden licence headers from html files.

Depends-On: Ia02bc00ad168b3c3d01ef6ca9696d43996091070
Change-Id: I1fa382d566165f5e76c84ad864024c0f546ef74c
2018-04-24 19:18:35 +05:30

2.5 KiB

DB Development

Valence uses Etcd as the management DB for handling multiple pod managers, as well as underneath hardware resources info. There is one root Etcd directory for the pod managers, named "/pod_managers". Each key-value pair under directory "/pod_managers" indicates information about one pod manager.

Note

All db layer codes are located in valence/db.

Add a model for db

Models are defined in the valence/db/models.py file. A new model should be updated there.

To add an example model for Etcd db, we should create a class that inherits the ModelBase class in valence/db/models.py.

Note

If timestamp info is needed for this model, please inherit ModelBaseWithTimestamp class instead.

i.e.

# valence/db/models.py

class ExampleModel(ModelBase):

    # This is the Etcd dir the new model lives in
    path = "example_model"

    # The fields will be wrapped as a value for one object
    fields = {
        'uuid': {
            'validate': types.Text.validate
        },
        'name': {
            'validate': types.Text.validate
        },

    }

Add a driver for model

Etcd driver definition is in the file valence/db/etcd_driver.py.

Considering adding operations for one example model, we should create a class in valence/db/etcd_driver.py. i.e.

# valence/db/etcd_driver.py

@six.add_metaclass(singleton.Singleton)
class ExampleDriver(object):

    def __init__(self, host=config.etcd_host, port=config.etcd_port):
        self.client = etcd.Client(host=host, port=port)

    def get_example_object(self, object_id):
        pass

    def create_example_object(self, values):
        pass

There should be more guides to be continued later.