summaryrefslogtreecommitdiffstats
path: root/clover/cloverctl/src/cloverctl
diff options
context:
space:
mode:
Diffstat (limited to 'clover/cloverctl/src/cloverctl')
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/create_docker_registry.go57
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/create_kubernetes.go87
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/delete_docker_registry.go52
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/delete_kubernetes.go53
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/get_docker_registry.go59
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/get_kubernetes.go59
-rw-r--r--clover/cloverctl/src/cloverctl/cmd/provider.go45
7 files changed, 412 insertions, 0 deletions
diff --git a/clover/cloverctl/src/cloverctl/cmd/create_docker_registry.go b/clover/cloverctl/src/cloverctl/cmd/create_docker_registry.go
new file mode 100644
index 0000000..77045f6
--- /dev/null
+++ b/clover/cloverctl/src/cloverctl/cmd/create_docker_registry.go
@@ -0,0 +1,57 @@
+// Copyright (c) Authors of Clover
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Apache License, Version 2.0
+// which accompanies this distribution, and is available at
+// http://www.apache.org/licenses/LICENSE-2.0
+
+package cmd
+
+import (
+ "fmt"
+ "io/ioutil"
+
+ "gopkg.in/resty.v1"
+ "github.com/ghodss/yaml"
+ "github.com/spf13/cobra"
+)
+
+
+var dockerregistryCmd = &cobra.Command{
+ Use: "docker-registry",
+ Short: "Add one docker registry from yaml file to spinnaker",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ createDockerRegistry()
+ },
+}
+
+func init() {
+ providercreateCmd.AddCommand(dockerregistryCmd)
+ dockerregistryCmd.Flags().StringVarP(&cloverFile, "file", "f", "", "Input yaml file to add kubernetes provider")
+ dockerregistryCmd.MarkFlagRequired("file")
+
+}
+
+func createDockerRegistry() {
+ url := controllerIP + "/halyard/addregistry"
+ in, err := ioutil.ReadFile(cloverFile)
+ if err != nil {
+ fmt.Println("Please specify a valid rule definition yaml file")
+ return
+ }
+ out_json, err := yaml.YAMLToJSON(in)
+ if err != nil {
+ panic(err.Error())
+ }
+
+ resp, err := resty.R().
+ SetHeader("Content-Type", "application/json").
+ SetBody(out_json).
+ Post(url)
+ if err != nil {
+ panic(err.Error())
+ }
+ fmt.Printf("\n%v\n", resp)
+
+}
diff --git a/clover/cloverctl/src/cloverctl/cmd/create_kubernetes.go b/clover/cloverctl/src/cloverctl/cmd/create_kubernetes.go
new file mode 100644
index 0000000..7311090
--- /dev/null
+++ b/clover/cloverctl/src/cloverctl/cmd/create_kubernetes.go
@@ -0,0 +1,87 @@
+// Copyright (c) Authors of Clover
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Apache License, Version 2.0
+// which accompanies this distribution, and is available at
+// http://www.apache.org/licenses/LICENSE-2.0
+
+package cmd
+
+import (
+ "fmt"
+ "time"
+ "io/ioutil"
+ "strings"
+
+ "gopkg.in/resty.v1"
+ "github.com/ghodss/yaml"
+ "github.com/spf13/cobra"
+ "cloverkube"
+)
+
+type Kubernetes struct {
+ Name string
+ ProviderVersion string
+ KubeconfigFile string
+ DockerRegistries []DockerRegistry
+}
+
+type DockerRegistry struct {
+ AccountName string
+}
+
+
+var kubeproviderCmd = &cobra.Command{
+ Use: "kubernetes",
+ Short: "Add one kubernete provider from yaml file to spinnaker",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ createProvider()
+ },
+}
+
+func init() {
+ providercreateCmd.AddCommand(kubeproviderCmd)
+ kubeproviderCmd.Flags().StringVarP(&cloverFile, "file", "f", "", "Input yaml file to add kubernetes provider")
+ kubeproviderCmd.MarkFlagRequired("file")
+
+}
+
+func createProvider() {
+ url := controllerIP + "/halyard/addkube"
+ in, err := ioutil.ReadFile(cloverFile)
+ if err != nil {
+ fmt.Println("Please specify a valid rule definition yaml file")
+ return
+ }
+
+ t := Kubernetes{}
+ yaml.Unmarshal(in, &t)
+ if(t.KubeconfigFile==""){
+ fmt.Println("error")
+ return;
+ }
+ filename := t.KubeconfigFile
+ hal_path := "/home/spinnaker/config"
+ timestamp := time.Now().Unix()
+ tm := time.Unix(timestamp, 0)
+ t.KubeconfigFile = hal_path + tm.Format("2006-01-02-15-04-05")
+ dest_container := "spinnaker/spin-halyard/halyard-daemon"
+ destPath := t.KubeconfigFile
+ dest := strings.Join([]string{dest_container, destPath}, ":")
+ cloverkube.CopyFileToPod(filename, dest)
+ newconfig, _ := yaml.Marshal(&t)
+ out_json, err := yaml.YAMLToJSON(newconfig)
+ if err != nil {
+ panic(err.Error())
+ }
+ resp, err := resty.R().
+ SetHeader("Content-Type", "application/json").
+ SetBody(out_json).
+ Post(url)
+ if err != nil {
+ panic(err.Error())
+ }
+ fmt.Printf("\n%v\n", resp)
+
+}
diff --git a/clover/cloverctl/src/cloverctl/cmd/delete_docker_registry.go b/clover/cloverctl/src/cloverctl/cmd/delete_docker_registry.go
new file mode 100644
index 0000000..d4403a5
--- /dev/null
+++ b/clover/cloverctl/src/cloverctl/cmd/delete_docker_registry.go
@@ -0,0 +1,52 @@
+// Copyright (c) Authors of Clover
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Apache License, Version 2.0
+// which accompanies this distribution, and is available at
+// http://www.apache.org/licenses/LICENSE-2.0
+
+package cmd
+
+import (
+ "fmt"
+ "encoding/json"
+
+ "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",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ deldockerProvider()
+ },
+}
+
+func init() {
+ providerdelCmd.AddCommand(deldockerproviderCmd)
+ deldockerproviderCmd.Flags().StringVarP(&name, "name", "n", "", "Input docker-registry account name")
+ deldockerproviderCmd.MarkFlagRequired("name")
+
+}
+
+func deldockerProvider() {
+ url := controllerIP + "/halyard/delprovider"
+
+ var in = map[string]string{"name": name, "provider":"dockerRegistry"}
+ out_json, err := json.Marshal(in)
+ if err != nil {
+ fmt.Println("json.Marshal failed:", err)
+ return
+ }
+ resp, err := resty.R().
+ SetHeader("Content-Type", "application/json").
+ SetBody(out_json).
+ Post(url)
+ if err != nil {
+ panic(err.Error())
+ }
+ 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
new file mode 100644
index 0000000..77b466a
--- /dev/null
+++ b/clover/cloverctl/src/cloverctl/cmd/delete_kubernetes.go
@@ -0,0 +1,53 @@
+// Copyright (c) Authors of Clover
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Apache License, Version 2.0
+// which accompanies this distribution, and is available at
+// http://www.apache.org/licenses/LICENSE-2.0
+
+package cmd
+
+import (
+ "fmt"
+ "encoding/json"
+
+ "gopkg.in/resty.v1"
+ "github.com/spf13/cobra"
+)
+
+var name string
+var delkubeproviderCmd = &cobra.Command{
+ Use: "kubernetes",
+ Short: "delete one kubernete provider by name from spinnaker",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ delProvider()
+ },
+}
+
+func init() {
+ providerdelCmd.AddCommand(delkubeproviderCmd)
+ delkubeproviderCmd.Flags().StringVarP(&name, "name", "n", "", "Input kubernetes account name")
+ delkubeproviderCmd.MarkFlagRequired("name")
+
+}
+
+func delProvider() {
+ url := controllerIP + "/halyard/delprovider"
+
+ var in = map[string]string{"name": name, "provider":"kubernetes"}
+ out_json, err := json.Marshal(in)
+ if err != nil {
+ fmt.Println("json.Marshal failed:", err)
+ return
+ }
+ resp, err := resty.R().
+ SetHeader("Content-Type", "application/json").
+ SetBody(out_json).
+ Post(url)
+ if err != nil {
+ panic(err.Error())
+ }
+ fmt.Printf("\n%v\n", resp)
+
+}
diff --git a/clover/cloverctl/src/cloverctl/cmd/get_docker_registry.go b/clover/cloverctl/src/cloverctl/cmd/get_docker_registry.go
new file mode 100644
index 0000000..93c1b3e
--- /dev/null
+++ b/clover/cloverctl/src/cloverctl/cmd/get_docker_registry.go
@@ -0,0 +1,59 @@
+// Copyright (c) Authors of Clover
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Apache License, Version 2.0
+// which accompanies this distribution, and is available at
+// http://www.apache.org/licenses/LICENSE-2.0
+
+package cmd
+
+import (
+ "fmt"
+ "strings"
+ "encoding/json"
+
+ "gopkg.in/resty.v1"
+ "github.com/spf13/cobra"
+)
+
+
+var getdockerregistry = &cobra.Command{
+ Use: "docker-registry",
+ Short: "Get docker registry from spinnaker",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ getdocker()
+ },
+}
+
+func init() {
+ providergetCmd.AddCommand(getdockerregistry)
+}
+
+func getdocker() {
+ url := controllerIP + "/halyard/account"
+
+ var provider = map[string]string{"name": "dockerRegistry"}
+ out_json, err := json.Marshal(provider)
+ if err != nil {
+ fmt.Println("json.Marshal failed:", err)
+ return
+ }
+ resp, err := resty.SetAllowGetMethodPayload(true).R().
+ SetHeader("Content-Type", "application/json").
+ SetBody(out_json).
+ Get(url)
+ if err != nil {
+ panic(err.Error())
+ }
+ if resp.StatusCode() != 200 {
+ fmt.Printf("\n%v\n", resp)
+ return
+ }
+
+ accounts := strings.Split(resp.String(), ":")
+ fmt.Printf("\n")
+ for index, account := range accounts{
+ fmt.Printf("%d. %v\n",index + 1, account)
+ }
+}
diff --git a/clover/cloverctl/src/cloverctl/cmd/get_kubernetes.go b/clover/cloverctl/src/cloverctl/cmd/get_kubernetes.go
new file mode 100644
index 0000000..16dcca1
--- /dev/null
+++ b/clover/cloverctl/src/cloverctl/cmd/get_kubernetes.go
@@ -0,0 +1,59 @@
+// Copyright (c) Authors of Clover
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Apache License, Version 2.0
+// which accompanies this distribution, and is available at
+// http://www.apache.org/licenses/LICENSE-2.0
+
+package cmd
+
+import (
+ "fmt"
+ "strings"
+ "encoding/json"
+
+ "gopkg.in/resty.v1"
+ "github.com/spf13/cobra"
+)
+
+
+var getkubeprovider = &cobra.Command{
+ Use: "kubernetes",
+ Short: "Get kubernetes provider from spinnaker",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ getkube()
+ },
+}
+
+func init() {
+ providergetCmd.AddCommand(getkubeprovider)
+}
+
+func getkube() {
+ url := controllerIP + "/halyard/account"
+
+ var provider = map[string]string{"name": "kubernetes"}
+ out_json, err := json.Marshal(provider)
+ if err != nil {
+ fmt.Println("json.Marshal failed:", err)
+ return
+ }
+ resp, err := resty.SetAllowGetMethodPayload(true).R().
+ SetHeader("Content-Type", "application/json").
+ SetBody(out_json).
+ Get(url)
+ if err != nil {
+ panic(err.Error())
+ }
+ if resp.StatusCode() != 200 {
+ fmt.Printf("\n%v\n", resp)
+ return
+ }
+
+ accounts := strings.Split(resp.String(), ":")
+ fmt.Printf("\n")
+ for index, account := range accounts{
+ fmt.Printf("%d. %v\n",index + 1, account)
+ }
+}
diff --git a/clover/cloverctl/src/cloverctl/cmd/provider.go b/clover/cloverctl/src/cloverctl/cmd/provider.go
new file mode 100644
index 0000000..fc8e888
--- /dev/null
+++ b/clover/cloverctl/src/cloverctl/cmd/provider.go
@@ -0,0 +1,45 @@
+// Copyright (c) Authors of Clover
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Apache License, Version 2.0
+// which accompanies this distribution, and is available at
+// http://www.apache.org/licenses/LICENSE-2.0
+
+package cmd
+
+import (
+ "fmt"
+ "github.com/spf13/cobra"
+)
+
+var providercreateCmd = &cobra.Command{
+ Use: "provider",
+ Short: "Add spinnaker provider",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("provider called")
+ },
+}
+
+var providerdelCmd = &cobra.Command{
+ Use: "provider",
+ Short: "Delete spinnaker provider",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("provider called")
+ },
+}
+
+var providergetCmd = &cobra.Command{
+ Use: "provider",
+ Short: "Get spinnaker provider",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("provider called")
+ },
+}
+func init() {
+ createCmd.AddCommand(providercreateCmd)
+ deleteCmd.AddCommand(providerdelCmd)
+ getCmd.AddCommand(providergetCmd)
+}