forked from canonical/lxd
/
doc.go
145 lines (145 loc) · 3.21 KB
/
doc.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Package lxd implements a client for the LXD API
//
// Overview
//
// This package lets you connect to LXD daemons or SimpleStream image
// servers over a Unix socket or HTTPs. You can then interact with those
// remote servers, creating containers, images, moving them around, ...
//
// Example - container creation
//
// This creates a container on a local LXD daemon and then starts it.
//
// // Connect to LXD over the Unix socket
// c, err := lxd.ConnectLXDUnix("", nil)
// if err != nil {
// return err
// }
//
// // Container creation request
// req := api.ContainersPost{
// Name: "my-container",
// Source: api.ContainerSource{
// Type: "image",
// Alias: "my-image",
// },
// }
//
// // Get LXD to create the container (background operation)
// op, err := c.CreateContainer(req)
// if err != nil {
// return err
// }
//
// // Wait for the operation to complete
// err = op.Wait()
// if err != nil {
// return err
// }
//
// // Get LXD to start the container (background operation)
// reqState := api.ContainerStatePut{
// Action: "start",
// Timeout: -1,
// }
//
// op, err = c.UpdateContainerState(name, reqState, "")
// if err != nil {
// return err
// }
//
// // Wait for the operation to complete
// err = op.Wait()
// if err != nil {
// return err
// }
//
// Example - command execution
//
// This executes an interactive bash terminal
//
// // Connect to LXD over the Unix socket
// c, err := lxd.ConnectLXDUnix("", nil)
// if err != nil {
// return err
// }
//
// // Setup the exec request
// req := api.ContainerExecPost{
// Command: []string{"bash"},
// WaitForWS: true,
// Interactive: true,
// Width: 80,
// Height: 15,
// }
//
// // Setup the exec arguments (fds)
// args := lxd.ContainerExecArgs{
// Stdin: os.Stdin,
// Stdout: os.Stdout,
// Stderr: os.Stderr,
// }
//
// // Setup the terminal (set to raw mode)
// if req.Interactive {
// cfd := int(syscall.Stdin)
// oldttystate, err := termios.MakeRaw(cfd)
// if err != nil {
// return err
// }
//
// defer termios.Restore(cfd, oldttystate)
// }
//
// // Get the current state
// op, err := c.ExecContainer("c1", req, &args)
// if err != nil {
// return err
// }
//
// // Wait for it to complete
// err = op.Wait()
// if err != nil {
// return err
// }
//
// Example - image copy
//
// This copies an image from a simplestreams server to a local LXD daemon
//
// // Connect to LXD over the Unix socket
// c, err := lxd.ConnectLXDUnix("", nil)
// if err != nil {
// return err
// }
//
// // Connect to the remote SimpleStreams server
// d, err = lxd.ConnectSimpleStreams("https://images.linuxcontainers.org", nil)
// if err != nil {
// return err
// }
//
// // Resolve the alias
// alias, _, err := d.GetImageAlias("centos/7")
// if err != nil {
// return err
// }
//
// // Get the image information
// image, _, err := d.GetImage(alias.Target)
// if err != nil {
// return err
// }
//
// // Ask LXD to copy the image from the remote server
// op, err := d.CopyImage(*image, c, nil)
// if err != nil {
// return err
// }
//
// // And wait for it to finish
// err = op.Wait()
// if err != nil {
// return err
// }
package lxd