forked from canonical/lxd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.go
81 lines (65 loc) · 1.61 KB
/
launch.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"github.com/lxc/lxd/lxc/config"
"github.com/lxc/lxd/shared/api"
"github.com/lxc/lxd/shared/i18n"
)
type launchCmd struct {
init initCmd
}
func (c *launchCmd) showByDefault() bool {
return true
}
func (c *launchCmd) usage() string {
return i18n.G(
`Usage: lxc launch [<remote>:]<image> [<remote>:][<name>] [--ephemeral|-e] [--profile|-p <profile>...] [--config|-c <key=value>...] [--network|-n <network>] [--storage|-s <pool>] [--type|-t <instance type>]
Create and start containers from images.
Not specifying -p will result in the default profile.
Specifying "-p" with no argument will result in no profile.
Examples:
lxc launch ubuntu:16.04 u1`)
}
func (c *launchCmd) flags() {
c.init = initCmd{}
c.init.flags()
}
func (c *launchCmd) run(conf *config.Config, args []string) error {
// Call the matching code from init
d, name, err := c.init.create(conf, args)
if err != nil {
return err
}
// Get the remote
var remote string
if len(args) == 2 {
remote, _, err = conf.ParseRemote(args[1])
if err != nil {
return err
}
} else {
remote, _, err = conf.ParseRemote("")
if err != nil {
return err
}
}
// Start the container
fmt.Printf(i18n.G("Starting %s")+"\n", name)
req := api.ContainerStatePut{
Action: "start",
Timeout: -1,
}
op, err := d.UpdateContainerState(name, req, "")
if err != nil {
return err
}
err = op.Wait()
if err != nil {
prettyName := name
if remote != "" {
prettyName = fmt.Sprintf("%s:%s", remote, name)
}
return fmt.Errorf("%s\n"+i18n.G("Try `lxc info --show-log %s` for more info"), err, prettyName)
}
return nil
}