mirror of
https://github.com/kairos-io/provider-kairos.git
synced 2025-08-30 21:50:38 +00:00
47 lines
858 B
Go
47 lines
858 B
Go
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
|
|
}
|