add basic config struct to libkpod

Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
Ryan Cole 2017-07-25 15:16:43 -04:00
parent f8a822e900
commit 0c8f106ee8
8 changed files with 351 additions and 208 deletions

View file

@ -3,6 +3,7 @@ package main
import (
is "github.com/containers/image/storage"
"github.com/containers/storage"
"github.com/kubernetes-incubator/cri-o/libkpod"
"github.com/urfave/cli"
)
@ -31,3 +32,30 @@ func getStore(c *cli.Context) (storage.Store, error) {
is.Transport.SetStore(store)
return store, nil
}
func getConfig(c *cli.Context) (*libkpod.Config, error) {
config := libkpod.DefaultConfig()
if c.GlobalIsSet("config") {
err := config.FromFile(c.String("config"))
if err != nil {
return config, err
}
}
if c.GlobalIsSet("root") {
config.Root = c.GlobalString("root")
}
if c.GlobalIsSet("runroot") {
config.RunRoot = c.GlobalString("runroot")
}
if c.GlobalIsSet("storage-driver") {
config.Storage = c.GlobalString("storage-driver")
}
if c.GlobalIsSet("storage-opt") {
opts := c.GlobalStringSlice("storage-opt")
if len(opts) > 0 {
config.StorageOptions = opts
}
}
return config, nil
}

View file

@ -49,6 +49,10 @@ func main() {
Name: "storage-opt",
Usage: "used to pass an option to the storage driver",
},
cli.StringFlag{
Name: "config, c",
Usage: "path of a config file detailing container server configuration options",
},
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)