[lxc-devel] [lxd/master] client: Init() supports passing in devices
tych0 on Github
lxc-bot at linuxcontainers.org
Thu May 5 18:56:47 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 483 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160505/92cbca29/attachment.bin>
-------------- next part --------------
From e3a1cb6b0ac5e1cd5daffa801d377fccc673e94b Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Thu, 5 May 2016 13:50:13 -0500
Subject: [PATCH] client: Init() supports passing in devices
containers_post.go has an implementation which respects the devices
parameter. Let's document it and also pass it in.
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
client.go | 6 +++++-
doc/rest-api.md | 42 ++++++++++++++++++++++++++++++++++++++++++
lxc/init.go | 4 ++--
lxc/launch.go | 4 ++--
test/lxd-benchmark/main.go | 2 +-
5 files changed, 52 insertions(+), 6 deletions(-)
diff --git a/client.go b/client.go
index 0254b5b..6338017 100644
--- a/client.go
+++ b/client.go
@@ -1197,7 +1197,7 @@ func (c *Client) GetAlias(alias string) string {
// Init creates a container from either a fingerprint or an alias; you must
// provide at least one.
-func (c *Client) Init(name string, imgremote string, image string, profiles *[]string, config map[string]string, ephem bool) (*Response, error) {
+func (c *Client) Init(name string, imgremote string, image string, profiles *[]string, config map[string]string, devices shared.Devices, ephem bool) (*Response, error) {
if c.Remote.Public {
return nil, fmt.Errorf("This function isn't supported by public remotes.")
}
@@ -1299,6 +1299,10 @@ func (c *Client) Init(name string, imgremote string, image string, profiles *[]s
body["config"] = config
}
+ if devices != nil {
+ body["devices"] = devices
+ }
+
if ephem {
body["ephemeral"] = ephem
}
diff --git a/doc/rest-api.md b/doc/rest-api.md
index 7a5f859..b510b9e 100644
--- a/doc/rest-api.md
+++ b/doc/rest-api.md
@@ -356,6 +356,12 @@ Input (container based on a local image with the "ubuntu/devel" alias):
"profiles": ["default"], # List of profiles
"ephemeral": true, # Whether to destroy the container on shutdown
"config": {"limits.cpu": "2"}, # Config override.
+ "devices": { # any devices the container should have
+ "rootfs": {
+ "path": "/",
+ "type": "disk"
+ },
+ },
"source": {"type": "image", # Can be: "image", "migration", "copy" or "none"
"alias": "ubuntu/devel"}, # Name of the alias
}
@@ -368,6 +374,12 @@ Input (container based on a local image identified by its fingerprint):
"profiles": ["default"], # List of profiles
"ephemeral": true, # Whether to destroy the container on shutdown
"config": {"limits.cpu": "2"}, # Config override.
+ "devices": { # any devices the container should have
+ "rootfs": {
+ "path": "/",
+ "type": "disk"
+ },
+ },
"source": {"type": "image", # Can be: "image", "migration", "copy" or "none"
"fingerprint": "SHA-256"}, # Fingerprint
}
@@ -380,6 +392,12 @@ Input (container based on most recent match based on image properties):
"profiles": ["default"], # List of profiles
"ephemeral": true, # Whether to destroy the container on shutdown
"config": {"limits.cpu": "2"}, # Config override.
+ "devices": { # any devices the container should have
+ "rootfs": {
+ "path": "/",
+ "type": "disk"
+ },
+ },
"source": {"type": "image", # Can be: "image", "migration", "copy" or "none"
"properties": { # Properties
"os": "ubuntu",
@@ -396,6 +414,12 @@ Input (container without a pre-populated rootfs, useful when attaching to an exi
"profiles": ["default"], # List of profiles
"ephemeral": true, # Whether to destroy the container on shutdown
"config": {"limits.cpu": "2"}, # Config override.
+ "devices": { # any devices the container should have
+ "rootfs": {
+ "path": "/",
+ "type": "disk"
+ },
+ },
"source": {"type": "none"}, # Can be: "image", "migration", "copy" or "none"
}
@@ -407,6 +431,12 @@ Input (using a public remote image):
"profiles": ["default"], # List of profiles
"ephemeral": true, # Whether to destroy the container on shutdown
"config": {"limits.cpu": "2"}, # Config override.
+ "devices": { # any devices the container should have
+ "rootfs": {
+ "path": "/",
+ "type": "disk"
+ },
+ },
"source": {"type": "image", # Can be: "image", "migration", "copy" or "none"
"mode": "pull", # One of "local" (default) or "pull"
"server": "https://10.0.2.3:8443", # Remote server (pull mode only)
@@ -424,6 +454,12 @@ Input (using a private remote image after having obtained a secret for that imag
"profiles": ["default"], # List of profiles
"ephemeral": true, # Whether to destroy the container on shutdown
"config": {"limits.cpu": "2"}, # Config override.
+ "devices": { # any devices the container should have
+ "rootfs": {
+ "path": "/",
+ "type": "disk"
+ },
+ },
"source": {"type": "image", # Can be: "image", "migration", "copy" or "none"
"mode": "pull", # One of "local" (default) or "pull"
"server": "https://10.0.2.3:8443", # Remote server (pull mode only)
@@ -440,6 +476,12 @@ Input (using a remote container, sent over the migration websocket):
"profiles": ["default"], # List of profiles
"ephemeral": true, # Whether to destroy the container on shutdown
"config": {"limits.cpu": "2"}, # Config override.
+ "devices": { # any devices the container should have
+ "rootfs": {
+ "path": "/",
+ "type": "disk"
+ },
+ },
"source": {"type": "migration", # Can be: "image", "migration", "copy" or "none"
"mode": "pull", # Only "pull" is supported for now
"operation": "https://10.0.2.3:8443/1.0/operations/<UUID>", # Full URL to the remote operation (pull mode only)
diff --git a/lxc/init.go b/lxc/init.go
index 9cad5f8..2c1ce41 100644
--- a/lxc/init.go
+++ b/lxc/init.go
@@ -180,9 +180,9 @@ func (c *initCmd) run(config *lxd.Config, args []string) error {
iremote, image = c.guessImage(config, d, remote, iremote, image)
if !initRequestedEmptyProfiles && len(profiles) == 0 {
- resp, err = d.Init(name, iremote, image, nil, configMap, c.ephem)
+ resp, err = d.Init(name, iremote, image, nil, configMap, nil, c.ephem)
} else {
- resp, err = d.Init(name, iremote, image, &profiles, configMap, c.ephem)
+ resp, err = d.Init(name, iremote, image, &profiles, configMap, nil, c.ephem)
}
if err != nil {
return err
diff --git a/lxc/launch.go b/lxc/launch.go
index eea4929..c180704 100644
--- a/lxc/launch.go
+++ b/lxc/launch.go
@@ -78,9 +78,9 @@ func (c *launchCmd) run(config *lxd.Config, args []string) error {
iremote, image = c.init.guessImage(config, d, remote, iremote, image)
if !initRequestedEmptyProfiles && len(profiles) == 0 {
- resp, err = d.Init(name, iremote, image, nil, configMap, c.init.ephem)
+ resp, err = d.Init(name, iremote, image, nil, configMap, nil, c.init.ephem)
} else {
- resp, err = d.Init(name, iremote, image, &profiles, configMap, c.init.ephem)
+ resp, err = d.Init(name, iremote, image, &profiles, configMap, nil, c.init.ephem)
}
if err != nil {
diff --git a/test/lxd-benchmark/main.go b/test/lxd-benchmark/main.go
index b35ded5..dc06f60 100644
--- a/test/lxd-benchmark/main.go
+++ b/test/lxd-benchmark/main.go
@@ -165,7 +165,7 @@ func spawnContainers(c *lxd.Client, count int, image string, privileged bool) er
config["user.lxd-benchmark"] = "true"
// Create
- resp, err := c.Init(name, "local", fingerprint, nil, config, false)
+ resp, err := c.Init(name, "local", fingerprint, nil, config, nil, false)
if err != nil {
logf(fmt.Sprintf("Failed to spawn container '%s': %s", name, err))
return
More information about the lxc-devel
mailing list