provider-kairos/internal/cli/register.go

47 lines
858 B
Go
Raw Normal View History

2022-08-11 11:30:51 +00:00
package cli
import (
"context"
"fmt"
"io/ioutil"
nodepair "github.com/mudler/go-nodepair"
qr "github.com/mudler/go-nodepair/qrcode"
)
func register(loglevel, arg, configFile, device string, reboot, poweroff bool) error {
b, _ := ioutil.ReadFile(configFile)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// dmesg -D to suppress tty ev
fmt.Println("Sending registration payload, please wait")
config := map[string]string{
"device": device,
"cc": string(b),
}
if reboot {
config["reboot"] = ""
}
if poweroff {
config["poweroff"] = ""
}
err := nodepair.Send(
ctx,
config,
nodepair.WithReader(qr.Reader),
nodepair.WithToken(arg),
nodepair.WithLogLevel(loglevel),
)
if err != nil {
return err
}
fmt.Println("Payload sent, installation will start on the machine briefly")
return nil
}