cord-776 create build / runtime containers for autmation uservices
Change-Id: I246973192adef56a250ffe93a5f65fff488840c1
diff --git a/config-generator/configGen.go b/config-generator/configGen.go
index c23ce53..063e46e 100644
--- a/config-generator/configGen.go
+++ b/config-generator/configGen.go
@@ -14,8 +14,10 @@
package main
import (
+ "flag"
"fmt"
"net/http"
+ "os"
"github.com/Sirupsen/logrus"
@@ -23,29 +25,43 @@
"github.com/kelseyhightower/envconfig"
)
+const appName = "CONFIGGEN"
+
type Config struct {
- Port int `default:"1337"`
- Listen string `default:"0.0.0.0"`
- Controller string `default:"http://%s:%s@127.0.0.1:8181"`
- Username string `default:"karaf"`
- Password string `default:"karaf"`
- LogLevel string `default:"warning" envconfig:"LOG_LEVEL"`
- LogFormat string `default:"text" envconfig:"LOG_FORMAT"`
+ Port int `default:"1337" desc:"port on which to listen for requests"`
+ Listen string `default:"0.0.0.0" desc:"IP address on which to listen for requests"`
+ Controller string `default:"http://%s:%s@127.0.0.1:8181" desc:"connection string with which to connect to ONOS"`
+ Username string `default:"karaf" desc:"username with which to connect to ONOS"`
+ Password string `default:"karaf" desc:"password with which to connect to ONOS"`
+ LogLevel string `default:"warning" envconfig:"LOG_LEVEL" desc:"detail level for logging"`
+ LogFormat string `default:"text" envconfig:"LOG_FORMAT" desc:"log output format, text or json"`
connect string
}
-var c Config
var log = logrus.New()
+var appFlags = flag.NewFlagSet("", flag.ContinueOnError)
func main() {
- err := envconfig.Process("CONFIGGEN", &c)
+ config := Config{}
+ appFlags.Usage = func() {
+ envconfig.Usage(appName, &config)
+ }
+ if err := appFlags.Parse(os.Args[1:]); err != nil {
+ if err != flag.ErrHelp {
+ os.Exit(1)
+ } else {
+ return
+ }
+ }
+
+ err := envconfig.Process("CONFIGGEN", &config)
if err != nil {
log.Fatalf("[ERROR] Unable to parse configuration options : %s", err)
}
- switch c.LogFormat {
+ switch config.LogFormat {
case "json":
log.Formatter = &logrus.JSONFormatter{}
default:
@@ -55,7 +71,7 @@
}
}
- level, err := logrus.ParseLevel(c.LogLevel)
+ level, err := logrus.ParseLevel(config.LogLevel)
if err != nil {
level = logrus.WarnLevel
}
@@ -69,15 +85,15 @@
PASSWORD: %s
LOG_LEVEL: %s
LOG_FORMAT: %s`,
- c.Listen, c.Port, c.Controller,
- c.Username, c.Password,
- c.LogLevel, c.LogFormat)
+ config.Listen, config.Port, config.Controller,
+ config.Username, config.Password,
+ config.LogLevel, config.LogFormat)
router := mux.NewRouter()
- router.HandleFunc("/config/", c.configGenHandler).Methods("POST")
+ router.HandleFunc("/config/", config.configGenHandler).Methods("POST")
http.Handle("/", router)
- c.connect = fmt.Sprintf(c.Controller, c.Username, c.Password)
+ config.connect = fmt.Sprintf(config.Controller, config.Username, config.Password)
- panic(http.ListenAndServe(fmt.Sprintf(":%d", c.Port), nil))
+ panic(http.ListenAndServe(fmt.Sprintf(":%d", config.Port), nil))
}