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 146 147 148 149 150 151 152 153 154 155 156 157
|
// Package incus implements a client for the Incus API
//
// # Overview
//
// This package lets you connect to Incus daemons or SimpleStream image
// servers over a Unix socket or HTTPs. You can then interact with those
// remote servers, creating instances, images, moving them around, ...
//
// The following examples make use of several imports:
//
// import (
// "github.com/lxc/incus/client"
// "github.com/lxc/incus/shared/api"
// "github.com/lxc/incus/shared/termios"
// )
//
// # Example - instance creation
//
// This creates a container on a local Incus daemon and then starts it.
//
// // Connect to Incus over the Unix socket
// c, err := incus.ConnectIncusUnix("", nil)
// if err != nil {
// return err
// }
//
// // Instance creation request
// name := "my-container"
// req := api.InstancesPost{
// Name: name,
// Source: api.InstanceSource{
// Type: "image",
// Alias: "my-image", # e.g. alpine/3.20
// Server: "https://images.linuxcontainers.org",
// Protocol: "simplestreams",
// },
// Type: "container"
// }
//
// // Get Incus to create the instance (background operation)
// op, err := c.CreateInstance(req)
// if err != nil {
// return err
// }
//
// // Wait for the operation to complete
// err = op.Wait()
// if err != nil {
// return err
// }
//
// // Get Incus to start the instance (background operation)
// reqState := api.InstanceStatePut{
// Action: "start",
// Timeout: -1,
// }
//
// op, err = c.UpdateInstanceState(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 Incus over the Unix socket
// c, err := incus.ConnectIncusUnix("", nil)
// if err != nil {
// return err
// }
//
// // Setup the exec request
// req := api.InstanceExecPost{
// Command: []string{"bash"},
// WaitForWS: true,
// Interactive: true,
// Width: 80,
// Height: 15,
// }
//
// // Setup the exec arguments (fds)
// args := incus.InstanceExecArgs{
// 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.ExecInstance(name, 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 Incus daemon
//
// // Connect to Incus over the Unix socket
// c, err := incus.ConnectIncusUnix("", nil)
// if err != nil {
// return err
// }
//
// // Connect to the remote SimpleStreams server
// d, err = incus.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 Incus 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 incus
|