summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Wong <stephen.kf.wong@gmail.com>2018-11-07 07:31:19 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-11-07 07:31:19 +0000
commitbecbc6627278efbe36f7c62d4ea6a0adf4731cac (patch)
treeb1596f96a2d0f453829ad7b01253b416f0f59d41
parent4635dc32b315f0d04ccee565192ad194b727b638 (diff)
parent265bdb46e6875cb5c75e6db8e98a38775da69391 (diff)
Merge "Add ability to read controller nodeport IP from file"
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/clear.go2
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/clear_visibility.go7
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/create.go4
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/create_docker_registry.go16
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/create_idsrules.go17
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/create_kubernetes.go18
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/create_testplan.go22
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/delete.go4
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/delete_docker_registry.go11
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/delete_kubernetes.go11
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/get.go4
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/get_docker_registry.go6
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/get_kubernetes.go6
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/get_services.go2
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/get_testresult.go47
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/get_visibility.go11
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/init.go2
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/init_visibility.go10
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/provider.go6
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/root.go58
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/set_nginx.go19
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/set_visibility.go16
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/start.go4
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/start_ids.go11
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/start_testplan.go23
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/start_visibility.go13
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/stop.go4
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/stop_ids.go9
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/stop_visibility.go7
29 files changed, 237 insertions, 133 deletions
diff --git a/clover/cloverctl/src/cloverctl/cmd/clear.go b/clover/cloverctl/src/cloverctl/cmd/clear.go
index 309df70..eab784a 100644
--- a/clover/cloverctl/src/cloverctl/cmd/clear.go
+++ b/clover/cloverctl/src/cloverctl/cmd/clear.go
@@ -17,7 +17,7 @@ var clearCmd = &cobra.Command{
Short: "Truncate visibility tables",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("clear called")
+ fmt.Println("Uncomplete command")
},
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/clear_visibility.go b/clover/cloverctl/src/cloverctl/cmd/clear_visibility.go
index 2ad43f1..2e66637 100644
--- a/clover/cloverctl/src/cloverctl/cmd/clear_visibility.go
+++ b/clover/cloverctl/src/cloverctl/cmd/clear_visibility.go
@@ -9,6 +9,7 @@ package cmd
import (
"fmt"
+ "os"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
)
@@ -16,7 +17,7 @@ import (
var visibilityclearCmd = &cobra.Command{
Use: "visibility",
- Short: "Clear visibility tables",
+ Short: "Clear visibility data",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
clearCollector()
@@ -28,12 +29,14 @@ func init() {
}
func clearCollector() {
+ checkControllerIP()
url := controllerIP + "/visibility/clear"
resp, err := resty.R().
Get(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/create.go b/clover/cloverctl/src/cloverctl/cmd/create.go
index 3a09fa4..a66acf9 100644
--- a/clover/cloverctl/src/cloverctl/cmd/create.go
+++ b/clover/cloverctl/src/cloverctl/cmd/create.go
@@ -14,10 +14,10 @@ import (
var createCmd = &cobra.Command{
Use: "create",
- Short: "Create resources including IDS rules, L7 testplans, etc.",
+ Short: "Create clover configurations and deployments",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("create called")
+ fmt.Println("Incomplete command")
},
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/create_docker_registry.go b/clover/cloverctl/src/cloverctl/cmd/create_docker_registry.go
index 77045f6..37e8aeb 100644
--- a/clover/cloverctl/src/cloverctl/cmd/create_docker_registry.go
+++ b/clover/cloverctl/src/cloverctl/cmd/create_docker_registry.go
@@ -10,7 +10,7 @@ package cmd
import (
"fmt"
"io/ioutil"
-
+ "os"
"gopkg.in/resty.v1"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
@@ -28,21 +28,24 @@ var dockerregistryCmd = &cobra.Command{
func init() {
providercreateCmd.AddCommand(dockerregistryCmd)
- dockerregistryCmd.Flags().StringVarP(&cloverFile, "file", "f", "", "Input yaml file to add kubernetes provider")
+ dockerregistryCmd.Flags().StringVarP(&cloverFile, "file", "f", "",
+ "Input yaml file to add docker registry")
dockerregistryCmd.MarkFlagRequired("file")
}
func createDockerRegistry() {
+ checkControllerIP()
url := controllerIP + "/halyard/addregistry"
in, err := ioutil.ReadFile(cloverFile)
if err != nil {
- fmt.Println("Please specify a valid rule definition yaml file")
- return
+ fmt.Println("Please specify a valid yaml file")
+ os.Exit(1)
}
out_json, err := yaml.YAMLToJSON(in)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Invalid yaml: %v\n", err)
+ os.Exit(1)
}
resp, err := resty.R().
@@ -50,7 +53,8 @@ func createDockerRegistry() {
SetBody(out_json).
Post(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
diff --git a/clover/cloverctl/src/cloverctl/cmd/create_idsrules.go b/clover/cloverctl/src/cloverctl/cmd/create_idsrules.go
index bc0d8d5..6e59297 100644
--- a/clover/cloverctl/src/cloverctl/cmd/create_idsrules.go
+++ b/clover/cloverctl/src/cloverctl/cmd/create_idsrules.go
@@ -9,6 +9,7 @@ package cmd
import (
"fmt"
+ "os"
"io/ioutil"
"gopkg.in/resty.v1"
"github.com/ghodss/yaml"
@@ -18,7 +19,7 @@ import (
var idsrulesCmd = &cobra.Command{
Use: "idsrules",
- Short: "Create one or many IDS rules from yaml file",
+ Short: "Create one or many snort IDS rules from yaml file",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
createIDSRules()
@@ -27,30 +28,32 @@ var idsrulesCmd = &cobra.Command{
func init() {
createCmd.AddCommand(idsrulesCmd)
- idsrulesCmd.Flags().StringVarP(&cloverFile, "file", "f", "", "Input yaml file to add IDS rules")
+ idsrulesCmd.Flags().StringVarP(&cloverFile, "file", "f", "",
+ "Input yaml file to add IDS rules")
idsrulesCmd.MarkFlagRequired("file")
}
func createIDSRules() {
+ checkControllerIP()
url := controllerIP + "/snort/addrule"
in, err := ioutil.ReadFile(cloverFile)
if err != nil {
fmt.Println("Please specify a valid rule definition yaml file")
- return
+ os.Exit(1)
}
out_json, err := yaml.YAMLToJSON(in)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Invalid yaml: %v\n", err)
+ os.Exit(1)
}
resp, err := resty.R().
SetHeader("Content-Type", "application/json").
SetBody(out_json).
Post(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
- //fmt.Println(string(out_json))
-
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/create_kubernetes.go b/clover/cloverctl/src/cloverctl/cmd/create_kubernetes.go
index 7311090..8ff4394 100644
--- a/clover/cloverctl/src/cloverctl/cmd/create_kubernetes.go
+++ b/clover/cloverctl/src/cloverctl/cmd/create_kubernetes.go
@@ -12,7 +12,7 @@ import (
"time"
"io/ioutil"
"strings"
-
+ "os"
"gopkg.in/resty.v1"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
@@ -33,7 +33,7 @@ type DockerRegistry struct {
var kubeproviderCmd = &cobra.Command{
Use: "kubernetes",
- Short: "Add one kubernete provider from yaml file to spinnaker",
+ Short: "Add one kubernetes provider from yaml file to spinnaker",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
createProvider()
@@ -42,17 +42,19 @@ var kubeproviderCmd = &cobra.Command{
func init() {
providercreateCmd.AddCommand(kubeproviderCmd)
- kubeproviderCmd.Flags().StringVarP(&cloverFile, "file", "f", "", "Input yaml file to add kubernetes provider")
+ kubeproviderCmd.Flags().StringVarP(&cloverFile, "file", "f", "",
+ "Input yaml file to add kubernetes provider")
kubeproviderCmd.MarkFlagRequired("file")
}
func createProvider() {
+ checkControllerIP()
url := controllerIP + "/halyard/addkube"
in, err := ioutil.ReadFile(cloverFile)
if err != nil {
- fmt.Println("Please specify a valid rule definition yaml file")
- return
+ fmt.Println("Please specify a valid yaml file")
+ os.Exit(1)
}
t := Kubernetes{}
@@ -73,14 +75,16 @@ func createProvider() {
newconfig, _ := yaml.Marshal(&t)
out_json, err := yaml.YAMLToJSON(newconfig)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Invalid yaml: %v\n", err)
+ os.Exit(1)
}
resp, err := resty.R().
SetHeader("Content-Type", "application/json").
SetBody(out_json).
Post(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
diff --git a/clover/cloverctl/src/cloverctl/cmd/create_testplan.go b/clover/cloverctl/src/cloverctl/cmd/create_testplan.go
index 686d5ba..1d9d8b2 100644
--- a/clover/cloverctl/src/cloverctl/cmd/create_testplan.go
+++ b/clover/cloverctl/src/cloverctl/cmd/create_testplan.go
@@ -9,49 +9,51 @@ package cmd
import (
"fmt"
+ "os"
"gopkg.in/resty.v1"
"io/ioutil"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
+
)
var testplanCmd = &cobra.Command{
Use: "testplan",
- Short: "Create L7 client emulation test plans from yaml file",
+ Short: "Create jmeter L7 client emulation test plan from yaml file",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
createTestPlan()
- //fmt.Printf("%v\n", cmd.Parent().CommandPath())
},
}
func init() {
createCmd.AddCommand(testplanCmd)
- testplanCmd.Flags().StringVarP(&cloverFile, "file", "f", "", "Input yaml file with test plan params")
+ testplanCmd.Flags().StringVarP(&cloverFile, "file", "f", "",
+ "Input test plan yaml file")
testplanCmd.MarkFlagRequired("file")
}
func createTestPlan() {
+ checkControllerIP()
url := controllerIP + "/jmeter/gen"
in, err := ioutil.ReadFile(cloverFile)
if err != nil {
- fmt.Println("Please specify a valid test plan yaml file")
- return
+ fmt.Println("Please specify a valid yaml file")
+ os.Exit(1)
}
out_json, err := yaml.YAMLToJSON(in)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Invalid yaml: %v\n", err)
+ os.Exit(1)
}
resp, err := resty.R().
SetHeader("Content-Type", "application/json").
SetBody(out_json).
Post(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
- //fmt.Println(string(out_json))
-
}
-
diff --git a/clover/cloverctl/src/cloverctl/cmd/delete.go b/clover/cloverctl/src/cloverctl/cmd/delete.go
index 742d769..34070e7 100644
--- a/clover/cloverctl/src/cloverctl/cmd/delete.go
+++ b/clover/cloverctl/src/cloverctl/cmd/delete.go
@@ -14,10 +14,10 @@ import (
var deleteCmd = &cobra.Command{
Use: "delete",
- Short: "Delete resources including clover-system services",
+ Short: "Delete configurations and clover services",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("delete called")
+ fmt.Println("Incomplete command")
},
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/delete_docker_registry.go b/clover/cloverctl/src/cloverctl/cmd/delete_docker_registry.go
index d4403a5..3bb411a 100644
--- a/clover/cloverctl/src/cloverctl/cmd/delete_docker_registry.go
+++ b/clover/cloverctl/src/cloverctl/cmd/delete_docker_registry.go
@@ -10,14 +10,14 @@ package cmd
import (
"fmt"
"encoding/json"
-
+ "os"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
)
var deldockerproviderCmd = &cobra.Command{
Use: "docker-registry",
- Short: "delete one docker registry provider by name from spinnaker",
+ Short: "Delete one docker registry provider by name from spinnaker",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
deldockerProvider()
@@ -26,12 +26,14 @@ var deldockerproviderCmd = &cobra.Command{
func init() {
providerdelCmd.AddCommand(deldockerproviderCmd)
- deldockerproviderCmd.Flags().StringVarP(&name, "name", "n", "", "Input docker-registry account name")
+ deldockerproviderCmd.Flags().StringVarP(&name, "name", "n", "",
+ "Input docker-registry account name")
deldockerproviderCmd.MarkFlagRequired("name")
}
func deldockerProvider() {
+ checkControllerIP()
url := controllerIP + "/halyard/delprovider"
var in = map[string]string{"name": name, "provider":"dockerRegistry"}
@@ -45,7 +47,8 @@ func deldockerProvider() {
SetBody(out_json).
Post(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
diff --git a/clover/cloverctl/src/cloverctl/cmd/delete_kubernetes.go b/clover/cloverctl/src/cloverctl/cmd/delete_kubernetes.go
index 77b466a..a6f29f9 100644
--- a/clover/cloverctl/src/cloverctl/cmd/delete_kubernetes.go
+++ b/clover/cloverctl/src/cloverctl/cmd/delete_kubernetes.go
@@ -10,7 +10,7 @@ package cmd
import (
"fmt"
"encoding/json"
-
+ "os"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
)
@@ -18,7 +18,7 @@ import (
var name string
var delkubeproviderCmd = &cobra.Command{
Use: "kubernetes",
- Short: "delete one kubernete provider by name from spinnaker",
+ Short: "Delete one kubernetes provider by name from spinnaker",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
delProvider()
@@ -27,12 +27,14 @@ var delkubeproviderCmd = &cobra.Command{
func init() {
providerdelCmd.AddCommand(delkubeproviderCmd)
- delkubeproviderCmd.Flags().StringVarP(&name, "name", "n", "", "Input kubernetes account name")
+ delkubeproviderCmd.Flags().StringVarP(&name, "name", "n", "",
+ "Input kubernetes account name")
delkubeproviderCmd.MarkFlagRequired("name")
}
func delProvider() {
+ checkControllerIP()
url := controllerIP + "/halyard/delprovider"
var in = map[string]string{"name": name, "provider":"kubernetes"}
@@ -46,7 +48,8 @@ func delProvider() {
SetBody(out_json).
Post(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
diff --git a/clover/cloverctl/src/cloverctl/cmd/get.go b/clover/cloverctl/src/cloverctl/cmd/get.go
index ae3d98e..c8493be 100644
--- a/clover/cloverctl/src/cloverctl/cmd/get.go
+++ b/clover/cloverctl/src/cloverctl/cmd/get.go
@@ -14,10 +14,10 @@ import (
var getCmd = &cobra.Command{
Use: "get",
- Short: "Get information about a resource",
+ Short: "Get information about a configuration or deployment",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("get called")
+ fmt.Println("Incomplete command")
},
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/get_docker_registry.go b/clover/cloverctl/src/cloverctl/cmd/get_docker_registry.go
index 93c1b3e..7ae94c9 100644
--- a/clover/cloverctl/src/cloverctl/cmd/get_docker_registry.go
+++ b/clover/cloverctl/src/cloverctl/cmd/get_docker_registry.go
@@ -11,7 +11,7 @@ import (
"fmt"
"strings"
"encoding/json"
-
+ "os"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
)
@@ -31,6 +31,7 @@ func init() {
}
func getdocker() {
+ checkControllerIP()
url := controllerIP + "/halyard/account"
var provider = map[string]string{"name": "dockerRegistry"}
@@ -44,7 +45,8 @@ func getdocker() {
SetBody(out_json).
Get(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
if resp.StatusCode() != 200 {
fmt.Printf("\n%v\n", resp)
diff --git a/clover/cloverctl/src/cloverctl/cmd/get_kubernetes.go b/clover/cloverctl/src/cloverctl/cmd/get_kubernetes.go
index 16dcca1..bd5875c 100644
--- a/clover/cloverctl/src/cloverctl/cmd/get_kubernetes.go
+++ b/clover/cloverctl/src/cloverctl/cmd/get_kubernetes.go
@@ -11,7 +11,7 @@ import (
"fmt"
"strings"
"encoding/json"
-
+ "os"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
)
@@ -31,6 +31,7 @@ func init() {
}
func getkube() {
+ checkControllerIP()
url := controllerIP + "/halyard/account"
var provider = map[string]string{"name": "kubernetes"}
@@ -44,7 +45,8 @@ func getkube() {
SetBody(out_json).
Get(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
if resp.StatusCode() != 200 {
fmt.Printf("\n%v\n", resp)
diff --git a/clover/cloverctl/src/cloverctl/cmd/get_services.go b/clover/cloverctl/src/cloverctl/cmd/get_services.go
index cfa56bd..bab13ce 100644
--- a/clover/cloverctl/src/cloverctl/cmd/get_services.go
+++ b/clover/cloverctl/src/cloverctl/cmd/get_services.go
@@ -14,7 +14,7 @@ import (
var servicesCmd = &cobra.Command{
Use: "services",
- Short: "Get info on Kubernetes services",
+ Short: "Get listing of Kubernetes services",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
cloverkube.GetServices()
diff --git a/clover/cloverctl/src/cloverctl/cmd/get_testresult.go b/clover/cloverctl/src/cloverctl/cmd/get_testresult.go
index 12d47c3..f9d8e6d 100644
--- a/clover/cloverctl/src/cloverctl/cmd/get_testresult.go
+++ b/clover/cloverctl/src/cloverctl/cmd/get_testresult.go
@@ -9,37 +9,54 @@ package cmd
import (
"fmt"
+ "os"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
)
-var JmeterResult string
-
var testresultCmd = &cobra.Command{
Use: "testresult",
- Short: "Get test results from L7 client emulation",
+ Short: "Get test results from jmeter L7 client emulation",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
- getResult()
+ getResult("log")
},
}
-func init() {
- getCmd.AddCommand(testresultCmd)
- testresultCmd.Flags().StringVarP(&JmeterResult, "r", "r", "", "Result to retrieve - use 'log' or 'results'")
- testresultCmd.MarkFlagRequired("r")
+var log_testresultCmd = &cobra.Command{
+ Use: "log",
+ Short: "Get jmeter summary log results",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ getResult("log")
+ },
+}
+var detail_testresultCmd = &cobra.Command{
+ Use: "detail",
+ Short: "Get jmeter detailed results",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ getResult("detail")
+ },
}
+func init() {
+ getCmd.AddCommand(testresultCmd)
+ testresultCmd.AddCommand(log_testresultCmd)
+ testresultCmd.AddCommand(detail_testresultCmd)
+}
-func getResult() {
- switch JmeterResult {
- case "results":
+func getResult(result_type string) {
+ checkControllerIP()
+ switch result_type {
+ case "detail":
url := controllerIP + "/jmeter/results/results"
resp, err := resty.R().
Get(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\nResponse Body: %v\n", resp)
case "log":
@@ -47,10 +64,12 @@ func getResult() {
resp, err := resty.R().
Get(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\nResponse Body: %v\n", resp)
default:
- fmt.Println("Unrecoginized jmeter result type - use 'log' or 'results'")
+ msg := "Unrecoginized jmeter result type"
+ fmt.Printf("%s - use 'log' or 'detail'", msg)
}
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/get_visibility.go b/clover/cloverctl/src/cloverctl/cmd/get_visibility.go
index 820b25a..a701164 100644
--- a/clover/cloverctl/src/cloverctl/cmd/get_visibility.go
+++ b/clover/cloverctl/src/cloverctl/cmd/get_visibility.go
@@ -9,6 +9,7 @@ package cmd
import (
"fmt"
+ "os"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
)
@@ -27,12 +28,15 @@ var visibilitygetCmd = &cobra.Command{
func init() {
getCmd.AddCommand(visibilitygetCmd)
- visibilitygetCmd.PersistentFlags().StringVarP(&VisibilityStat, "stat", "s", "", "Visibility stats type to get")
- visibilitygetCmd.PersistentFlags().StringVarP(&VisibilityConfig, "conf", "c", "", "Visibility config type to get")
+ visibilitygetCmd.PersistentFlags().StringVarP(&VisibilityStat, "stat", "s",
+ "", "Visibility stats type to get")
+ visibilitygetCmd.PersistentFlags().StringVarP(&VisibilityConfig, "conf",
+ "c", "", "Visibility config type to get")
}
func getVisibility() {
+ checkControllerIP()
url_prefix := "/visibility/get/"
get_data := "all"
response_prefix := "Config"
@@ -50,7 +54,8 @@ func getVisibility() {
SetHeader("Accept", "application/json").
Get(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%s %s: %v\n", response_prefix, get_data, resp)
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/init.go b/clover/cloverctl/src/cloverctl/cmd/init.go
index 613b263..102c5ba 100644
--- a/clover/cloverctl/src/cloverctl/cmd/init.go
+++ b/clover/cloverctl/src/cloverctl/cmd/init.go
@@ -17,7 +17,7 @@ var initCmd = &cobra.Command{
Short: "Initialize visibility schemas",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("init called")
+ fmt.Println("Incomplete command")
},
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/init_visibility.go b/clover/cloverctl/src/cloverctl/cmd/init_visibility.go
index ac9ec5c..004c300 100644
--- a/clover/cloverctl/src/cloverctl/cmd/init_visibility.go
+++ b/clover/cloverctl/src/cloverctl/cmd/init_visibility.go
@@ -9,6 +9,7 @@ package cmd
import (
"fmt"
+ "os"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
)
@@ -16,7 +17,7 @@ import (
var visibilityinitCmd = &cobra.Command{
Use: "visibility",
- Short: "Init visibility data schemas",
+ Short: "Initialize visibility data schemas in cassandra",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
initCollector()
@@ -28,14 +29,15 @@ func init() {
}
func initCollector() {
+
+ checkControllerIP()
url := controllerIP + "/collector/init"
resp, err := resty.R().
Get(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
}
-
-
diff --git a/clover/cloverctl/src/cloverctl/cmd/provider.go b/clover/cloverctl/src/cloverctl/cmd/provider.go
index fc8e888..e6f1cc8 100644
--- a/clover/cloverctl/src/cloverctl/cmd/provider.go
+++ b/clover/cloverctl/src/cloverctl/cmd/provider.go
@@ -17,7 +17,7 @@ var providercreateCmd = &cobra.Command{
Short: "Add spinnaker provider",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("provider called")
+ fmt.Println("Incomplete command")
},
}
@@ -26,7 +26,7 @@ var providerdelCmd = &cobra.Command{
Short: "Delete spinnaker provider",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("provider called")
+ fmt.Println("Incomplete command")
},
}
@@ -35,7 +35,7 @@ var providergetCmd = &cobra.Command{
Short: "Get spinnaker provider",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("provider called")
+ fmt.Println("Incomplete command")
},
}
func init() {
diff --git a/clover/cloverctl/src/cloverctl/cmd/root.go b/clover/cloverctl/src/cloverctl/cmd/root.go
index 6878077..d1d9405 100644
--- a/clover/cloverctl/src/cloverctl/cmd/root.go
+++ b/clover/cloverctl/src/cloverctl/cmd/root.go
@@ -10,6 +10,7 @@ package cmd
import (
"fmt"
"os"
+ "strings"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
@@ -18,7 +19,6 @@ import (
)
var cfgFile string
-
var controllerIP string
var cloverFile string
@@ -33,8 +33,9 @@ var rootCmd = &cobra.Command{
//},
}
-// Execute adds all child commands to the root command and sets flags appropriately.
-// This is called by main.main(). It only needs to happen once to the rootCmd.
+// Execute adds all child commands to the root command and sets flags
+// appropriately. This is called by main.main(). It only needs to happen
+// once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
@@ -48,19 +49,12 @@ func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
- rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cloverctl.yaml)")
+ rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "",
+ "config file (default is $HOME/.cloverctl.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
-
- cPort, cIP := cloverkube.GetServicesPortIP("clover-controller")
- if cIP == "" {
- controllerIP = "http://10.244.0.1:" + fmt.Sprint(cPort)
- } else {
- controllerIP = "http://" + cIP
- }
- fmt.Printf("\nclover-controller: %s %s\n", fmt.Sprint(cPort), cIP)
}
// initConfig reads in config file and ENV variables if set.
@@ -76,15 +70,51 @@ func initConfig() {
os.Exit(1)
}
- // Search config in home directory with name ".cloverctl" (without extension).
+ // Search config in home directory with name ".cloverctl"
viper.AddConfigPath(home)
viper.SetConfigName(".cloverctl")
}
viper.AutomaticEnv() // read in environment variables that match
- // If a config file is found, read it in.
+ cip_file := ""
+ // If a config file is found in home, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
+ cip_file = viper.GetString("ControllerIP")
+ } else {
+ // Check for file in path from cloverctl
+ ep, err := os.Executable()
+ if err == nil {
+ exe_path := strings.Replace(ep, "cloverctl", "", -1)
+ viper.AddConfigPath(exe_path)
+ if err := viper.ReadInConfig(); err == nil {
+ fmt.Println("Using config file:", viper.ConfigFileUsed())
+ cip_file = viper.GetString("ControllerIP")
+ }
+ }
+ }
+
+ cPort, cip_kube := cloverkube.GetServicesPortIP("clover-controller")
+ // If IP in file
+ if cip_file != "" {
+ // Nodeport
+ controllerIP = "http://" + cip_file + ":" + fmt.Sprint(cPort)
+ }
+ // Override IP, if LB IP found
+ if cip_kube != "" {
+ fmt.Printf("IP %v", cip_kube)
+ controllerIP = "http://" + cip_kube
+ }
+}
+
+func checkControllerIP() {
+ // controllerIP exists
+ service := "clover-controller"
+ if controllerIP == "" {
+ fmt.Printf("%s address unspecified or cannot be found\n", service)
+ os.Exit(1)
+ } else {
+ fmt.Printf("%s address: %s\n", service, controllerIP)
}
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/set_nginx.go b/clover/cloverctl/src/cloverctl/cmd/set_nginx.go
index e7e65c2..6b571bb 100644
--- a/clover/cloverctl/src/cloverctl/cmd/set_nginx.go
+++ b/clover/cloverctl/src/cloverctl/cmd/set_nginx.go
@@ -9,6 +9,7 @@ package cmd
import (
"fmt"
+ "os"
"io/ioutil"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
@@ -36,17 +37,19 @@ var setlbCmd = &cobra.Command{
func init() {
setCmd.AddCommand(setserverCmd)
- setserverCmd.Flags().StringVarP(&cloverFile, "file", "f", "", "Input yaml file for server config")
+ setserverCmd.Flags().StringVarP(&cloverFile, "file", "f", "",
+ "Input yaml file for server config")
setserverCmd.MarkFlagRequired("file")
setCmd.AddCommand(setlbCmd)
- setlbCmd.Flags().StringVarP(&cloverFile, "file", "f", "", "Input yaml file for lb config")
+ setlbCmd.Flags().StringVarP(&cloverFile, "file", "f", "",
+ "Input yaml file for lb config")
setlbCmd.MarkFlagRequired("file")
-
}
func setNginx(nginx_service string) {
+ checkControllerIP()
url := ""
if nginx_service == "server" {
url = controllerIP + "/nginx/server"
@@ -57,20 +60,20 @@ func setNginx(nginx_service string) {
in, err := ioutil.ReadFile(cloverFile)
if err != nil {
fmt.Println("Please specify a valid yaml file")
- return
+ os.Exit(1)
}
out_json, err := yaml.YAMLToJSON(in)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Invalid yaml: %v\n", err)
+ os.Exit(1)
}
resp, err := resty.R().
SetHeader("Content-Type", "application/json").
SetBody(out_json).
Post(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
-
-
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/set_visibility.go b/clover/cloverctl/src/cloverctl/cmd/set_visibility.go
index 685b250..ec28122 100644
--- a/clover/cloverctl/src/cloverctl/cmd/set_visibility.go
+++ b/clover/cloverctl/src/cloverctl/cmd/set_visibility.go
@@ -9,6 +9,7 @@ package cmd
import (
"fmt"
+ "os"
"io/ioutil"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
@@ -27,31 +28,32 @@ var setvisibilitystatsCmd = &cobra.Command{
func init() {
setCmd.AddCommand(setvisibilitystatsCmd)
- setvisibilitystatsCmd.Flags().StringVarP(&cloverFile, "file", "f", "", "Input yaml file to set visibility config")
+ setvisibilitystatsCmd.Flags().StringVarP(&cloverFile, "file", "f", "",
+ "Input yaml file to set visibility config")
setvisibilitystatsCmd.MarkFlagRequired("file")
-
}
func setCollector() {
+ checkControllerIP()
url := controllerIP + "/visibility/set"
in, err := ioutil.ReadFile(cloverFile)
if err != nil {
fmt.Println("Please specify a valid yaml file")
- return
+ os.Exit(1)
}
out_json, err := yaml.YAMLToJSON(in)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Invalid yaml: %v\n", err)
+ os.Exit(1)
}
resp, err := resty.R().
SetHeader("Content-Type", "application/json").
SetBody(out_json).
Post(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
-
-
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/start.go b/clover/cloverctl/src/cloverctl/cmd/start.go
index 741eacd..d2eb864 100644
--- a/clover/cloverctl/src/cloverctl/cmd/start.go
+++ b/clover/cloverctl/src/cloverctl/cmd/start.go
@@ -14,10 +14,10 @@ import (
var startCmd = &cobra.Command{
Use: "start",
- Short: "Start processes including tests, visibility and ingress services",
+ Short: "Start processes and tests",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("start called")
+ fmt.Println("Incomplete command")
},
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/start_ids.go b/clover/cloverctl/src/cloverctl/cmd/start_ids.go
index 0f495a7..be039fa 100644
--- a/clover/cloverctl/src/cloverctl/cmd/start_ids.go
+++ b/clover/cloverctl/src/cloverctl/cmd/start_ids.go
@@ -9,6 +9,7 @@ package cmd
import (
"fmt"
+ "os"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
)
@@ -16,8 +17,8 @@ import (
var startidsCmd = &cobra.Command{
Use: "ids",
- Short: "Start IDS process",
- Long: `Restart IDS process when adding custom rules`,
+ Short: "Start snort IDS process",
+ Long: `Restart snort IDS process when adding custom rules`,
Run: func(cmd *cobra.Command, args []string) {
startIDS()
},
@@ -29,14 +30,14 @@ func init() {
func startIDS() {
+ checkControllerIP()
url := controllerIP + "/snort/start"
resp, err := resty.R().
Get(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
}
-
-
diff --git a/clover/cloverctl/src/cloverctl/cmd/start_testplan.go b/clover/cloverctl/src/cloverctl/cmd/start_testplan.go
index b516ad6..9e664c0 100644
--- a/clover/cloverctl/src/cloverctl/cmd/start_testplan.go
+++ b/clover/cloverctl/src/cloverctl/cmd/start_testplan.go
@@ -9,6 +9,7 @@ package cmd
import (
"fmt"
+ "os"
"strings"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
@@ -18,20 +19,21 @@ import (
var testplanstartCmd = &cobra.Command{
Use: "testplan",
- Short: "Start a test for a given test plan",
+ Short: "Start test for configured test plan",
Long: `Specify number of slaves to use with '-s' flag. Default is 0 slaves,
-which runs tests only from jmeter-master.`,
+which runs tests from jmeter-master only.`,
Run: func(cmd *cobra.Command, args []string) {
startTest()
- //fmt.Printf("%v\n", cmd.Parent().CommandPath())
},
}
var num_slaves int
func init() {
startCmd.AddCommand(testplanstartCmd)
- testplanstartCmd.PersistentFlags().StringVarP(&cloverFile, "file", "f", "", "Currently unused")
- testplanstartCmd.PersistentFlags().IntVarP(&num_slaves, "slaves", "s", 0, "Number of slaves to use")
+ testplanstartCmd.PersistentFlags().StringVarP(&cloverFile, "file", "f", "",
+ "Currently unused")
+ testplanstartCmd.PersistentFlags().IntVarP(&num_slaves, "slaves", "s", 0,
+ "Number of slaves to use")
}
func startTest() {
@@ -39,21 +41,24 @@ func startTest() {
ips := cloverkube.GetPodsIP("clover-jmeter-slave", "default")
fmt.Printf("\njmeter-slaves found: %s\n", ips)
if num_slaves > len(ips) {
- fmt.Printf("Number of slaves specified must be less than found: %d\n", len(ips))
+ fmt.Printf("Number of slaves specified must be less than found: %d\n",
+ len(ips))
return
}
ip_list := strings.Join(ips[0:num_slaves], ",")
+ checkControllerIP()
url := controllerIP + "/jmeter/start"
resp, err := resty.R().
SetHeader("Content-Type", "application/json").
- SetBody(fmt.Sprintf(`{"num_slaves":"%d", "slave_list":"%s"}`, num_slaves, ip_list)).
+ SetBody(fmt.Sprintf(`{"num_slaves":"%d", "slave_list":"%s"}`, num_slaves,
+ ip_list)).
Post(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
-
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/start_visibility.go b/clover/cloverctl/src/cloverctl/cmd/start_visibility.go
index 18f8aac..bbc25d8 100644
--- a/clover/cloverctl/src/cloverctl/cmd/start_visibility.go
+++ b/clover/cloverctl/src/cloverctl/cmd/start_visibility.go
@@ -9,6 +9,7 @@ package cmd
import (
"fmt"
+ "os"
"io/ioutil"
"gopkg.in/resty.v1"
"github.com/ghodss/yaml"
@@ -18,7 +19,7 @@ import (
var visibilitystartCmd = &cobra.Command{
Use: "visibility",
- Short: "Start visibility data collection",
+ Short: "Start visibility collector process",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
startCollector()
@@ -36,23 +37,27 @@ func startCollector() {
if cloverFile != "" {
in, err := ioutil.ReadFile(cloverFile)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot read file: %v\n", err)
+ os.Exit(1)
}
out_json, err := yaml.YAMLToJSON(in)
message_body = string(out_json)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Invalid yaml: %v\n", err)
+ os.Exit(1)
}
} else {
message_body = `{"sample_interval":"10", "t_port":"80", "t_host":"jaeger-query.istio-system"}`
}
+ checkControllerIP()
url := controllerIP + "/collector/start"
resp, err := resty.R().
SetHeader("Content-Type", "application/json").
SetBody(message_body).
Post(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/stop.go b/clover/cloverctl/src/cloverctl/cmd/stop.go
index cfb7245..e77a36b 100644
--- a/clover/cloverctl/src/cloverctl/cmd/stop.go
+++ b/clover/cloverctl/src/cloverctl/cmd/stop.go
@@ -14,10 +14,10 @@ import (
var stopCmd = &cobra.Command{
Use: "stop",
- Short: "Stop processes including visibility and ingress services",
+ Short: "Stop processes including visibility and sample services",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("stop called")
+ fmt.Println("Incomplete command")
},
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/stop_ids.go b/clover/cloverctl/src/cloverctl/cmd/stop_ids.go
index b39b1e9..c810d9d 100644
--- a/clover/cloverctl/src/cloverctl/cmd/stop_ids.go
+++ b/clover/cloverctl/src/cloverctl/cmd/stop_ids.go
@@ -9,6 +9,7 @@ package cmd
import (
"fmt"
+ "os"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
)
@@ -16,8 +17,8 @@ import (
var stopidsCmd = &cobra.Command{
Use: "ids",
- Short: "Stop IDS process",
- Long: `Restart IDS process when adding custom rules`,
+ Short: "Stop snort IDS process",
+ Long: `Restart snort IDS process when adding custom rules`,
Run: func(cmd *cobra.Command, args []string) {
stopIDS()
},
@@ -29,12 +30,14 @@ func init() {
func stopIDS() {
+ checkControllerIP()
url := controllerIP + "/snort/stop"
resp, err := resty.R().
Get(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
}
diff --git a/clover/cloverctl/src/cloverctl/cmd/stop_visibility.go b/clover/cloverctl/src/cloverctl/cmd/stop_visibility.go
index 4233157..fda226e 100644
--- a/clover/cloverctl/src/cloverctl/cmd/stop_visibility.go
+++ b/clover/cloverctl/src/cloverctl/cmd/stop_visibility.go
@@ -9,6 +9,7 @@ package cmd
import (
"fmt"
+ "os"
"gopkg.in/resty.v1"
"github.com/spf13/cobra"
)
@@ -16,7 +17,7 @@ import (
var visibilitystopCmd = &cobra.Command{
Use: "visibility",
- Short: "Stop visibility data collection",
+ Short: "Stop visibility collector process",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
stopCollector()
@@ -29,12 +30,14 @@ func init() {
func stopCollector() {
+ checkControllerIP()
url := controllerIP + "/collector/stop"
resp, err := resty.R().
Get(url)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Cannot connect to controller: %v\n", err)
+ os.Exit(1)
}
fmt.Printf("\n%v\n", resp)
}