2022-07-04 20:39:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2022-07-17 08:42:12 +00:00
|
|
|
agent "github.com/c3os-io/c3os/internal/agent"
|
2022-07-04 20:39:34 +00:00
|
|
|
"github.com/c3os-io/c3os/internal/bus"
|
2022-07-17 08:42:12 +00:00
|
|
|
|
2022-08-10 16:56:07 +00:00
|
|
|
machine "github.com/c3os-io/c3os/pkg/machine"
|
|
|
|
bundles "github.com/c3os-io/c3os/sdk/bundles"
|
2022-07-04 20:39:34 +00:00
|
|
|
|
|
|
|
"github.com/c3os-io/c3os/internal/github"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var cmds = []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "upgrade",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "force",
|
|
|
|
Usage: "Force an upgrade",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "image",
|
|
|
|
Usage: "Specify an full image reference, e.g.: quay.io/some/image:tag",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Description: `
|
|
|
|
Manually upgrade a c3os node.
|
|
|
|
|
|
|
|
By default takes no arguments, defaulting to latest available release, to specify a version, pass it as argument:
|
|
|
|
|
|
|
|
$ c3os upgrade v1.20....
|
|
|
|
|
|
|
|
To retrieve all the available versions, use "c3os upgrade list-releases"
|
|
|
|
|
|
|
|
$ c3os upgrade list-releases
|
|
|
|
|
|
|
|
See https://docs.c3os.io/after_install/upgrades/#manual for documentation.
|
|
|
|
|
|
|
|
`,
|
|
|
|
Subcommands: []cli.Command{
|
|
|
|
{
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "output",
|
|
|
|
Usage: "Output format (json|yaml|terminal)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Name: "list-releases",
|
|
|
|
Description: `List all available releases versions`,
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
rels, err := github.FindReleases(context.Background(), "", "c3os-io/c3os")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch strings.ToLower(c.String("output")) {
|
|
|
|
case "yaml":
|
|
|
|
d, _ := yaml.Marshal(rels)
|
|
|
|
fmt.Println(string(d))
|
|
|
|
case "json":
|
|
|
|
d, _ := json.Marshal(rels)
|
|
|
|
fmt.Println(string(d))
|
|
|
|
default:
|
|
|
|
for _, r := range rels {
|
|
|
|
fmt.Println(r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
args := c.Args()
|
|
|
|
var v string
|
|
|
|
if len(args) == 1 {
|
|
|
|
v = args[0]
|
|
|
|
}
|
|
|
|
|
2022-07-18 22:02:49 +00:00
|
|
|
return agent.Upgrade(v, c.String("image"), c.Bool("force"))
|
2022-07-04 20:39:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-08-09 06:01:54 +00:00
|
|
|
{
|
|
|
|
Name: "notify",
|
|
|
|
Usage: "notify <event> <config dir>...",
|
|
|
|
UsageText: "emits the given event with a generic event payload",
|
|
|
|
Description: `
|
|
|
|
Sends a generic event payload with the configuration found in the scanned directories.
|
|
|
|
`,
|
|
|
|
Aliases: []string{},
|
|
|
|
Flags: []cli.Flag{},
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
dirs := []string{"/oem", "/usr/local/cloud-config"}
|
|
|
|
args := c.Args()
|
|
|
|
if len(args) > 1 {
|
|
|
|
dirs = args[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
return agent.Notify(args[0], dirs)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-07-04 20:39:34 +00:00
|
|
|
{
|
|
|
|
Name: "start",
|
|
|
|
Usage: "Starts the c3os agent",
|
|
|
|
UsageText: "starts the agent",
|
|
|
|
Description: `
|
|
|
|
Starts the c3os agent which automatically bootstrap and advertize to the c3os network.
|
|
|
|
`,
|
|
|
|
Aliases: []string{"s"},
|
|
|
|
Flags: []cli.Flag{
|
2022-08-08 08:15:15 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "restart",
|
|
|
|
},
|
2022-07-04 20:39:34 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "force",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "api",
|
|
|
|
Value: "http://127.0.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
dirs := []string{"/oem", "/usr/local/cloud-config"}
|
|
|
|
args := c.Args()
|
|
|
|
if len(args) > 0 {
|
|
|
|
dirs = args
|
|
|
|
}
|
|
|
|
|
2022-08-08 08:15:15 +00:00
|
|
|
opts := []agent.Option{
|
|
|
|
agent.WithAPI(c.String("api")),
|
|
|
|
agent.WithDirectory(dirs...),
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Bool("force") {
|
|
|
|
opts = append(opts, agent.ForceAgent)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Bool("restart") {
|
|
|
|
opts = append(opts, agent.RestartAgent)
|
|
|
|
}
|
|
|
|
|
|
|
|
return agent.Run(opts...)
|
2022-07-04 20:39:34 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-13 22:23:47 +00:00
|
|
|
{
|
|
|
|
Name: "install-bundle",
|
|
|
|
Usage: "Installs a c3os bundle",
|
|
|
|
Description: `
|
|
|
|
|
|
|
|
Manually installs a c3os bundle.
|
|
|
|
|
|
|
|
E.g. c3os-agent install-bundle container:quay.io/c3os/c3os...
|
|
|
|
|
|
|
|
`,
|
|
|
|
Aliases: []string{"i"},
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "repository",
|
|
|
|
EnvVar: "REPOSITORY",
|
2022-07-16 14:28:55 +00:00
|
|
|
Value: "docker://quay.io/c3os/packages",
|
2022-07-13 22:23:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
UsageText: "Install a bundle manually in the node",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
args := c.Args()
|
|
|
|
if len(args) != 1 {
|
|
|
|
return fmt.Errorf("bundle name required")
|
|
|
|
}
|
|
|
|
|
2022-08-10 16:56:07 +00:00
|
|
|
return bundles.RunBundles([]bundles.BundleOption{bundles.WithRepository(c.String("repository")), bundles.WithTarget(args[0])})
|
2022-07-13 22:23:47 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-04 20:39:34 +00:00
|
|
|
{
|
|
|
|
Name: "uuid",
|
|
|
|
Usage: "Prints the local UUID",
|
|
|
|
Description: "Print node uuid",
|
|
|
|
Aliases: []string{"u"},
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
fmt.Print(machine.UUID())
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "interactive-install",
|
|
|
|
Description: `
|
|
|
|
Starts c3os in interactive mode.
|
|
|
|
|
|
|
|
It will ask prompt for several questions and perform an install
|
|
|
|
|
|
|
|
See also https://docs.c3os.io/installation/interactive_install/ for documentation.
|
|
|
|
|
|
|
|
This command is meant to be used from the boot GRUB menu, but can be started manually`,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "shell",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Usage: "Starts interactive installation",
|
|
|
|
Action: func(c *cli.Context) error {
|
2022-07-17 08:42:12 +00:00
|
|
|
return agent.InteractiveInstall(c.Bool("shell"))
|
2022-07-04 20:39:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "install",
|
|
|
|
Usage: "Starts the c3os pairing installation",
|
|
|
|
Description: `
|
|
|
|
Starts c3os in pairing mode.
|
|
|
|
|
|
|
|
It will print out a QR code which can be used with "c3os register" to send over a configuration and bootstraping a c3os node.
|
|
|
|
|
|
|
|
See also https://docs.c3os.io/installation/device_pairing/ for documentation.
|
|
|
|
|
|
|
|
This command is meant to be used from the boot GRUB menu, but can be started manually`,
|
|
|
|
Aliases: []string{"i"},
|
|
|
|
Action: func(c *cli.Context) error {
|
2022-07-17 08:42:12 +00:00
|
|
|
return agent.Install("/oem", "/usr/local/cloud-config", "/run/initramfs/live")
|
2022-07-04 20:39:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "recovery",
|
|
|
|
Aliases: []string{"r"},
|
2022-07-18 22:02:49 +00:00
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
return agent.Recovery()
|
|
|
|
},
|
|
|
|
Usage: "Starts c3os recovery mode",
|
2022-07-04 20:39:34 +00:00
|
|
|
Description: `
|
|
|
|
Starts c3os recovery mode.
|
|
|
|
|
2022-07-25 22:26:10 +00:00
|
|
|
In recovery mode a QR code will be printed out on the screen which should be used in conjunction with "c3os bridge". Pass by the QR code as snapshot
|
2022-07-04 20:39:34 +00:00
|
|
|
to the bridge to connect over the machine which runs the "c3os recovery" command.
|
|
|
|
|
|
|
|
See also https://docs.c3os.io/after_install/recovery_mode/ for documentation.
|
|
|
|
|
|
|
|
This command is meant to be used from the boot GRUB menu, but can likely be used standalone`,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2022-07-18 22:02:49 +00:00
|
|
|
Name: "reset",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
return agent.Reset()
|
|
|
|
},
|
|
|
|
Usage: "Starts c3os reset mode",
|
2022-07-04 20:39:34 +00:00
|
|
|
Description: `
|
|
|
|
Starts c3os reset mode, it will nuke completely the node data and restart fresh.
|
|
|
|
Attention ! this will delete any persistent data on the node. It is equivalent to re-init the node right after the installation.
|
|
|
|
|
|
|
|
In reset mode a the node will automatically reset
|
|
|
|
|
|
|
|
See also https://docs.c3os.io/after_install/reset_mode/ for documentation.
|
|
|
|
|
|
|
|
This command is meant to be used from the boot GRUB menu, but can likely be used standalone`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
bus.Manager.Initialize()
|
|
|
|
|
|
|
|
app := &cli.App{
|
|
|
|
Name: "c3os",
|
|
|
|
Version: "0.1",
|
|
|
|
Author: "Ettore Di Giacinto",
|
|
|
|
Usage: "c3os CLI to bootstrap, upgrade, connect and manage a c3os network",
|
|
|
|
Description: `
|
|
|
|
The c3os CLI can be used to manage a c3os box and perform all day-two tasks, like:
|
|
|
|
- register a node
|
|
|
|
- connect to a node in recovery mode
|
|
|
|
- to establish a VPN connection
|
|
|
|
- set, list roles
|
|
|
|
- interact with the network API
|
|
|
|
|
|
|
|
and much more.
|
|
|
|
|
|
|
|
For all the example cases, see: https://docs.c3os.io .
|
|
|
|
`,
|
|
|
|
UsageText: ``,
|
|
|
|
Copyright: "Ettore Di Giacinto",
|
|
|
|
|
2022-08-11 11:31:00 +00:00
|
|
|
Commands: cmds,
|
2022-07-04 20:39:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err := app.Run(os.Args)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|