2017-06-27 13:45:25 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-08-15 20:53:17 +00:00
|
|
|
"strings"
|
|
|
|
|
2017-06-27 13:45:25 +00:00
|
|
|
is "github.com/containers/image/storage"
|
|
|
|
"github.com/containers/storage"
|
2017-08-15 20:53:17 +00:00
|
|
|
"github.com/fatih/camelcase"
|
2017-07-25 19:16:43 +00:00
|
|
|
"github.com/kubernetes-incubator/cri-o/libkpod"
|
2017-08-10 17:58:29 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-06-27 13:45:25 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2017-07-27 17:18:07 +00:00
|
|
|
func getStore(c *libkpod.Config) (storage.Store, error) {
|
2017-06-27 13:45:25 +00:00
|
|
|
options := storage.DefaultStoreOptions
|
2017-07-27 17:18:07 +00:00
|
|
|
options.GraphRoot = c.Root
|
|
|
|
options.RunRoot = c.RunRoot
|
|
|
|
options.GraphDriverName = c.Storage
|
|
|
|
options.GraphDriverOptions = c.StorageOptions
|
2017-06-30 19:10:57 +00:00
|
|
|
|
2017-06-27 13:45:25 +00:00
|
|
|
store, err := storage.GetStore(options)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
is.Transport.SetStore(store)
|
|
|
|
return store, nil
|
|
|
|
}
|
2017-07-25 19:16:43 +00:00
|
|
|
|
|
|
|
func getConfig(c *cli.Context) (*libkpod.Config, error) {
|
|
|
|
config := libkpod.DefaultConfig()
|
|
|
|
if c.GlobalIsSet("config") {
|
2017-07-27 17:18:07 +00:00
|
|
|
err := config.UpdateFromFile(c.String("config"))
|
2017-07-25 19:16:43 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2017-08-10 17:58:29 +00:00
|
|
|
if c.Bool("debug") {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
}
|
|
|
|
|
2017-07-25 19:16:43 +00:00
|
|
|
return config, nil
|
|
|
|
}
|
2017-08-15 20:53:17 +00:00
|
|
|
|
|
|
|
func splitCamelCase(src string) string {
|
|
|
|
entries := camelcase.Split(src)
|
|
|
|
return strings.Join(entries, " ")
|
|
|
|
}
|