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.