Skip to content

Files

Latest commit

50fa7eb · Mar 25, 2019

History

History

osdconfig

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Feb 15, 2018
Mar 24, 2018
Mar 14, 2018
Mar 19, 2018
Feb 15, 2018
Feb 15, 2018
Mar 14, 2018
Aug 30, 2018
Nov 26, 2018
Mar 25, 2019
Mar 14, 2018

osdconfig

osdconfig is a library to work with distributed configuration parameters. It defines an interface and provides an implementation against KVDB backend.

General purpose of this package is as follows:

  • Allow users to register their callback functions on updates to backend
  • Allow users to set/get config parameters

installation

osdconfig is written in go (golang). It can be installed using go get

$ go get github.com/libopenstorage/openstorage/osdconfig/...

example

Create an instance of kvdb

kv, err := kvdb.New(mem.Name, "", []string{}, nil, nil)
if err != nil {
    logrus.Fatal(err)
}

Create an instance of osdconfig manager

manager, err := osdconfig.NewManager(kv)
if err != nil {
	// do something
}
defer manager.Close()

Define a function literal that can be registered to watch for changes

f := func(config *osdconfig.Config) error {
	// do something with config (say print)
	fmt.Println(config)
	return nil
}

Register this function literal to watch on kvdb changes

if err := manager.WatchCluster("watcher", f); err != nil {
	// do something
}

Update cluster config on kvdb

conf := new(osdconfig.ClusterConfig)
conf.ClusterID = "myID"
if err := manager.SetClusterConf(conf); err != nil {
	// do something
	return
}

once updates are pushed to backend (kvdb in this implementation), callback function is called