|
| 1 | +package microvm |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/moby/moby/pkg/namesgenerator" |
| 5 | + "github.com/spf13/cobra" |
| 6 | + "go.uber.org/zap" |
| 7 | + |
| 8 | + "github.com/weaveworks-experiments/fl/pkg/app" |
| 9 | + "github.com/weaveworks-experiments/fl/pkg/flags" |
| 10 | +) |
| 11 | + |
| 12 | +const ( |
| 13 | + defaultNamespace = "default" |
| 14 | + defaultVCPU = 2 |
| 15 | + defaultMemoryMb = 2048 |
| 16 | + defaultKernelImage = "ghcr.io/weaveworks/flintlock-kernel:5.10.77" |
| 17 | + defaultKernelFile = "boot/vmlinux" |
| 18 | + defaultRootImage = "ghcr.io/weaveworks/capmvm-kubernetes:1.21.8" |
| 19 | +) |
| 20 | + |
| 21 | +func newCreateCommand() *cobra.Command { |
| 22 | + createInput := &app.CreateInput{} |
| 23 | + |
| 24 | + cmd := &cobra.Command{ |
| 25 | + Use: "create", |
| 26 | + Short: "create a new microvm", |
| 27 | + PreRun: func(cmd *cobra.Command, args []string) { |
| 28 | + flags.BindFlags(cmd) |
| 29 | + }, |
| 30 | + Run: func(c *cobra.Command, _ []string) { |
| 31 | + a := app.New(zap.S().With("action", "create")) |
| 32 | + if err := a.Create(c.Context(), createInput); err != nil { |
| 33 | + zap.S().Errorw("failed creating microvm", "error", err) |
| 34 | + } |
| 35 | + }, |
| 36 | + } |
| 37 | + |
| 38 | + cmd.Flags().StringVar(&createInput.Host, "host", "", "the flintlock host to create the microvm on") |
| 39 | + cmd.MarkFlagRequired("host") |
| 40 | + |
| 41 | + defaultName := namesgenerator.GetRandomName(10) |
| 42 | + cmd.Flags().StringVar(&createInput.Name, "name", defaultName, "the name of the microvm, auto-generated if not supplied") |
| 43 | + cmd.Flags().StringVar(&createInput.Namespace, "namespace", defaultNamespace, "the namespace for the microvm") |
| 44 | + cmd.Flags().IntVar(&createInput.VCPU, "vcpu", defaultVCPU, "the number of vcpus") |
| 45 | + cmd.Flags().IntVar(&createInput.MemoryInMb, "memory", defaultMemoryMb, "the memory in mb") |
| 46 | + cmd.Flags().StringVar(&createInput.KernelImage, "kernel-image", defaultKernelImage, "the image to use for the kernel") |
| 47 | + cmd.Flags().BoolVar(&createInput.KernelAddNetConf, "add-netconf", true, "automatically add network configuration to the kernel cmd line") |
| 48 | + cmd.Flags().StringVar(&createInput.KernelFileName, "kernel-filename", defaultKernelFile, "name of the kernel file in the image") |
| 49 | + cmd.Flags().StringVar(&createInput.RootImage, "root-image", defaultRootImage, "the image to use for the root volume") |
| 50 | + cmd.Flags().StringVar(&createInput.InitrdImage, "initrd-image", "", "the image to use for the initial ramdisk") |
| 51 | + cmd.Flags().StringVar(&createInput.InitrdFilename, "initrd-filename", "", "name of the file in the image to use for the initial ramdisk") |
| 52 | + cmd.Flags().StringSliceVar(&createInput.NetworkInterfaces, "network-interface", nil, "specify the network interfaces to attach. In the following format: name:type:[macaddress]:[ipaddress]") |
| 53 | + cmd.Flags().StringSliceVar(&createInput.MetadataFromFile, "metadata-from-file", nil, "specify metadata to be available to your microvm. In the following format key=pathtofile") |
| 54 | + cmd.Flags().StringVar(&createInput.Hostname, "hostname", "", "the hostname of the the microvm") |
| 55 | + cmd.Flags().StringVar(&createInput.SSHKeyFile, "ssh-key-file", "", "an ssh key to use") |
| 56 | + //TODO: additional command line args for kernel |
| 57 | + //TODO: add additional volumes |
| 58 | + |
| 59 | + return cmd |
| 60 | +} |
0 commit comments