|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "github.com/kairos-io/AuroraBoot/internal" |
| 6 | + "github.com/kairos-io/AuroraBoot/pkg/ops" |
| 7 | + "github.com/kairos-io/AuroraBoot/pkg/schema" |
| 8 | + "github.com/kairos-io/kairos-sdk/types" |
| 9 | + "github.com/urfave/cli/v2" |
| 10 | +) |
| 11 | + |
| 12 | +var StartPixieCmd = cli.Command{ |
| 13 | + Name: "start-pixie", |
| 14 | + Aliases: []string{"sp"}, |
| 15 | + Usage: "Start the Pixiecore netboot server and serve custom PXE files (kernel, initrd, squashfs) with a cloud-config.", |
| 16 | + Description: `Start a Pixiecore-based PXE server to serve a kernel, initrd, and squashfs image for network booting. |
| 17 | +
|
| 18 | +Arguments: |
| 19 | + cloud-config-file Path to the cloud-init or cloud-config YAML file. |
| 20 | + squashfs-file Path to the root filesystem squashfs image. |
| 21 | + address IP address to bind the server (e.g., 0.0.0.0). |
| 22 | + port Port for the netboot server (e.g., 8080). |
| 23 | + initrd-file Path to the initrd image. |
| 24 | + kernel-file Path to the kernel image. |
| 25 | +
|
| 26 | +Options: |
| 27 | + --debug Enable debug logging for troubleshooting. |
| 28 | +
|
| 29 | +Example: |
| 30 | + start-pixie user-data.yaml rootfs.squashfs 0.0.0.0 8080 initrd.img vmlinuz --debug |
| 31 | +`, |
| 32 | + ArgsUsage: "<cloud-config-file> <squashfs-file> <address> <port> <initrd-file> <kernel-file>", |
| 33 | + Flags: []cli.Flag{ |
| 34 | + &cli.BoolFlag{ |
| 35 | + Name: "debug", |
| 36 | + Usage: "Enable debug logging", |
| 37 | + }, |
| 38 | + // Add more flags for optional NetBoot struct fields as needed |
| 39 | + }, |
| 40 | + Action: func(c *cli.Context) error { |
| 41 | + cloudConfigFile := c.Args().Get(0) |
| 42 | + squashFSfile := c.Args().Get(1) |
| 43 | + address := c.Args().Get(2) |
| 44 | + netbootPort := c.Args().Get(3) |
| 45 | + initrdFile := c.Args().Get(4) |
| 46 | + kernelFile := c.Args().Get(5) |
| 47 | + |
| 48 | + // Simple argument validation |
| 49 | + if cloudConfigFile == "" || squashFSfile == "" || address == "" || netbootPort == "" || initrdFile == "" || kernelFile == "" { |
| 50 | + cli.ShowCommandHelp(c, c.Command.Name) |
| 51 | + fmt.Println("") |
| 52 | + return fmt.Errorf("all arguments are required") |
| 53 | + } |
| 54 | + |
| 55 | + loglevel := "info" |
| 56 | + if c.Bool("debug") { |
| 57 | + loglevel = "debug" |
| 58 | + } |
| 59 | + internal.Log = types.NewKairosLogger("AuroraBoot", loglevel, false) |
| 60 | + |
| 61 | + // Optionally parse NetBoot from flags here if desired |
| 62 | + nb := schema.NetBoot{} // Use defaults, or parse from CLI flags |
| 63 | + |
| 64 | + f := ops.StartPixiecore( |
| 65 | + cloudConfigFile, |
| 66 | + address, |
| 67 | + netbootPort, |
| 68 | + func() string { return squashFSfile }, // Wrap squashFSfile in a function |
| 69 | + func() string { return initrdFile }, // Wrap initrdFile in a function |
| 70 | + func() string { return kernelFile }, // Wrap kernelFile in a function |
| 71 | + nb, |
| 72 | + ) |
| 73 | + |
| 74 | + return f(c.Context) |
| 75 | + }, |
| 76 | +} |
0 commit comments