mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Merge branch 'endpoint-groups'
This commit is contained in:
commit
aeba258ef8
@ -31,6 +31,9 @@ type PortainerClient interface {
|
||||
// Get endpoints
|
||||
GetEndpoints() ([]EndpointSubset, error)
|
||||
|
||||
// Get endpoint groups
|
||||
GetEndpointGroups() ([]EndpointGroup, error)
|
||||
|
||||
// Get stacks, optionally filtered by swarmId and endpointId
|
||||
GetStacks(swarmId string, endpointId uint32) ([]Stack, error)
|
||||
|
||||
@ -217,6 +220,11 @@ func (n *portainerClientImp) GetEndpoints() (endpoints []EndpointSubset, err err
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) GetEndpointGroups() (endpointGroups []EndpointGroup, err error) {
|
||||
err = n.doJSON("endpoint_groups", http.MethodGet, nil, &endpointGroups)
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) GetStacks(swarmId string, endpointId uint32) (stacks []Stack, err error) {
|
||||
filter := StackListFilter{
|
||||
SwarmId: swarmId,
|
||||
|
@ -37,6 +37,12 @@ type EndpointSubset struct {
|
||||
GroupID uint32
|
||||
}
|
||||
|
||||
type EndpointGroup struct {
|
||||
Id uint32
|
||||
Name string
|
||||
Description string
|
||||
}
|
||||
|
||||
type StackCreateRequest struct {
|
||||
Name string
|
||||
SwarmID string
|
||||
|
15
cmd/endpointGroup.go
Normal file
15
cmd/endpointGroup.go
Normal file
@ -0,0 +1,15 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// endpointGroupCmd represents the endpoint group command
|
||||
var endpointGroupCmd = &cobra.Command{
|
||||
Use: "group",
|
||||
Short: "Manage endpoint groups",
|
||||
}
|
||||
|
||||
func init() {
|
||||
endpointCmd.AddCommand(endpointGroupCmd)
|
||||
}
|
65
cmd/endpointGroupList.go
Normal file
65
cmd/endpointGroupList.go
Normal file
@ -0,0 +1,65 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/template"
|
||||
|
||||
"github.com/greenled/portainer-stack-utils/common"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// endpointGroupListCmd represents the endpoint group list command
|
||||
var endpointGroupListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List endpoint groups",
|
||||
Aliases: []string{"ls"},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
client, err := common.GetClient()
|
||||
common.CheckError(err)
|
||||
|
||||
logrus.Debug("Getting endpoint groups")
|
||||
endpointGroups, err := client.GetEndpointGroups()
|
||||
common.CheckError(err)
|
||||
|
||||
if viper.GetString("endpoint.group.list.format") != "" {
|
||||
// Print endpoint group fields formatted
|
||||
template, templateParsingErr := template.New("endpointGroupTpl").Parse(viper.GetString("endpoint.group.list.format"))
|
||||
common.CheckError(templateParsingErr)
|
||||
for _, g := range endpointGroups {
|
||||
templateExecutionErr := template.Execute(os.Stdout, g)
|
||||
common.CheckError(templateExecutionErr)
|
||||
fmt.Println()
|
||||
}
|
||||
} else {
|
||||
// Print all endpoint group fields as a table
|
||||
writer, err := common.NewTabWriter([]string{
|
||||
"ENDPOINT GROUP ID",
|
||||
"NAME",
|
||||
"DESCRIPTION",
|
||||
})
|
||||
common.CheckError(err)
|
||||
for _, g := range endpointGroups {
|
||||
_, err := fmt.Fprintln(writer, fmt.Sprintf(
|
||||
"%v\t%s\t%s",
|
||||
g.Id,
|
||||
g.Name,
|
||||
g.Description,
|
||||
))
|
||||
common.CheckError(err)
|
||||
}
|
||||
flushErr := writer.Flush()
|
||||
common.CheckError(flushErr)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
endpointGroupCmd.AddCommand(endpointGroupListCmd)
|
||||
|
||||
endpointGroupListCmd.Flags().String("format", "", "Format output using a Go template.")
|
||||
viper.BindPFlag("endpoint.group.list.format", endpointGroupListCmd.Flags().Lookup("format"))
|
||||
}
|
Loading…
Reference in New Issue
Block a user