/
agent.go
81 lines (65 loc) · 1.86 KB
/
agent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"github.com/fristonio/xene/pkg/apiserver/client/registry"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var agentCmd = &cobra.Command{
Use: "agent",
Short: "Subcommand for managing xene configured agents",
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
}
var agentGetCmd = &cobra.Command{
Use: "get",
Short: "Get the agent from the provided name.",
Run: func(cmd *cobra.Command, args []string) {
if agentName == "" {
log.Fatalf("agent name(--name) is a required parameter and must be a valid one")
}
client, auth := getClientAndAuth()
res, err := client.Registry.GetAPIV1RegistryAgentName(
registry.NewGetAPIV1RegistryAgentNameParams().WithName(agentName),
auth)
if err != nil {
log.Errorf("error while getting agent document: %s", err)
return
}
if res.Payload.Item.Value == "" {
log.Infof("the requested agent is not found")
return
}
prettyPrintJSON(res.Payload.Item.Value)
},
}
var agentDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete the agent with the provided name.",
Run: func(cmd *cobra.Command, args []string) {
if agentName == "" {
log.Fatalf("agent name(--name) is a required parameter and must be a valid one")
}
client, auth := getClientAndAuth()
res, err := client.Registry.DeleteAPIV1RegistryAgentName(
registry.NewDeleteAPIV1RegistryAgentNameParams().WithName(agentName),
auth)
if err != nil {
log.Errorf("error while deleting agent: %s", err)
return
}
fmt.Println(res.Payload.Message)
},
}
var (
agentName string
)
func init() {
agentGetCmd.Flags().StringVarP(&agentName, "name", "n",
"", "name of the agent definition to get.")
agentDeleteCmd.Flags().StringVarP(&agentName, "name", "n",
"", "name of the agent definition to delete.")
agentCmd.AddCommand(agentGetCmd)
agentCmd.AddCommand(agentDeleteCmd)
}