provider-kairos/internal/cli/role.go
Mauro Morales d88983a906
Extract some commands into kairosctl (#310)
This PR extracts the registration command into a `kairos-register`
binary of its own. The old sub command is kept so users can see a
deprecation notice and adapt for a future release when it's removed. The
version number is shared between binaries.

⚠️ I'm not entirely sure about the gorelease, and would benefit
from a couple of extra 👀 on this, thanks!

relates to kairos-io/kairos#1211

---------

Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
Signed-off-by: Mauro Morales <contact@mauromorales.com>
Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
Signed-off-by: GitHub <noreply@github.com>
Co-authored-by: Dimitris Karakasilis <dimitris@karakasilis.me>
Co-authored-by: Itxaka <itxaka.garcia@spectrocloud.com>
Co-authored-by: ci-robbot [bot] <105103991+ci-robbot@users.noreply.github.com>
Co-authored-by: mudler <mudler@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-04-21 11:04:15 +02:00

56 lines
1.4 KiB
Go

package cli
import (
"fmt"
edgeVPNClient "github.com/mudler/edgevpn/api/client"
"github.com/mudler/edgevpn/api/client/service"
"github.com/urfave/cli/v2"
)
var RoleCMD = cli.Command{
Name: "role",
Usage: "Set or list node roles",
Subcommands: []*cli.Command{
{
Flags: networkAPI,
Name: "set",
Usage: "Set a node role",
UsageText: "kairos role set <UUID> master",
Description: `
Sets a node role propagating the setting to the network.
A role must be set prior to the node joining a network. You can retrieve a node UUID by running "kairos uuid".
Example:
$ (node A) kairos uuid
$ (node B) kairos role set <UUID of node A> master
`,
Action: func(c *cli.Context) error {
cc := service.NewClient(
c.String("network-id"),
edgeVPNClient.NewClient(edgeVPNClient.WithHost(c.String("api"))))
return cc.Set("role", c.Args().Get(0), c.Args().Get(1))
},
},
{
Flags: networkAPI,
Name: "list",
Description: "List node roles",
Action: func(c *cli.Context) error {
cc := service.NewClient(
c.String("network-id"),
edgeVPNClient.NewClient(edgeVPNClient.WithHost(c.String("api"))))
advertizing, _ := cc.AdvertizingNodes()
fmt.Println("Node\tRole")
for _, a := range advertizing {
role, _ := cc.Get("role", a)
fmt.Printf("%s\t%s\n", a, role)
}
return nil
},
},
},
}