This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 223
/
run.go
58 lines (50 loc) · 1.41 KB
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package vmcmd
import (
"io"
"github.com/lithammer/dedent"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/weaveworks/ignite/cmd/ignite/cmd/cmdutil"
"github.com/weaveworks/ignite/cmd/ignite/run"
)
// NewCmdRun creates, starts (and attaches to) a VM
func NewCmdRun(out io.Writer) *cobra.Command {
rf := &run.RunFlags{
CreateFlags: run.NewCreateFlags(),
StartFlags: &run.StartFlags{},
}
cmd := &cobra.Command{
Use: "run <OCI image>",
Short: "Create a new VM and start it",
Long: dedent.Dedent(`
Create and start a new VM immediately. The image (and kernel) is matched by
prefix based on its ID and name. This command accepts all flags used to
create and start a VM. The interactive flag (-i, --interactive) can be
specified to immediately attach to the started VM after creation.
Example usage:
$ ignite run weaveworks/ignite-ubuntu \
--interactive \
--name my-vm \
--cpus 2 \
--ssh \
--memory 2GB \
--size 10G
`),
Args: cobra.RangeArgs(0, 1),
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(func() error {
ro, err := rf.NewRunOptions(args, cmd.Flags())
if err != nil {
return err
}
return run.Run(ro, cmd.Flags())
}())
},
}
addRunFlags(cmd.Flags(), rf)
return cmd
}
func addRunFlags(fs *pflag.FlagSet, rf *run.RunFlags) {
addCreateFlags(fs, rf.CreateFlags)
addStartFlags(fs, rf.StartFlags)
}