[lxc-devel] [lxd/master] API endpoints cleanup

2019-04-23 Thread stgraber on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/5694

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
This is a preparation branch for the RBAC branch, makes things a bit more consistent internally and also puts a restriction in place on the internal API so that it may only be called over the UNIX socket or by another cluster member, but not by a random API client.
From 76a004266a4b3d962ae37245f48747edd4f1a978 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= 
Date: Tue, 23 Apr 2019 22:43:40 -0400
Subject: [PATCH 1/5] lxd/api: Rename serverResources to api10Resources
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Making things consistent with existing commands.

Signed-off-by: Stéphane Graber 
---
 lxd/api_1.0.go   | 3 +--
 lxd/resources.go | 6 +++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/lxd/api_1.0.go b/lxd/api_1.0.go
index 6f194d76f1..d3ea20ecb8 100644
--- a/lxd/api_1.0.go
+++ b/lxd/api_1.0.go
@@ -33,6 +33,7 @@ var api10 = []Command{
aliasCmd,
aliasesCmd,
api10Cmd,
+   api10ResourcesCmd,
certificateFingerprintCmd,
certificatesCmd,
clusterCmd,
@@ -71,8 +72,6 @@ var api10 = []Command{
profilesCmd,
projectCmd,
projectsCmd,
-   serverResourceCmd,
-   serverResourceCmd,
storagePoolCmd,
storagePoolResourcesCmd,
storagePoolsCmd,
diff --git a/lxd/resources.go b/lxd/resources.go
index 5d9916d162..161dbcc91a 100644
--- a/lxd/resources.go
+++ b/lxd/resources.go
@@ -10,9 +10,9 @@ import (
"github.com/lxc/lxd/shared/api"
 )
 
-var serverResourceCmd = Command{
+var api10ResourcesCmd = Command{
name: "resources",
-   get:  serverResourcesGet,
+   get:  api10ResourcesGet,
 }
 
 var storagePoolResourcesCmd = Command{
@@ -22,7 +22,7 @@ var storagePoolResourcesCmd = Command{
 
 // /1.0/resources
 // Get system resources
-func serverResourcesGet(d *Daemon, r *http.Request) Response {
+func api10ResourcesGet(d *Daemon, r *http.Request) Response {
// If a target was specified, forward the request to the relevant node.
response := ForwardedResponseIfTargetIsRemote(d, r)
if response != nil {

From 0f8bb153682bf63b70a2cf5c63167eaf4e2ba813 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= 
Date: Tue, 23 Apr 2019 22:44:14 -0400
Subject: [PATCH 2/5] lxd/api: Sort API commands list
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber 
---
 lxd/api_1.0.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxd/api_1.0.go b/lxd/api_1.0.go
index d3ea20ecb8..0e34ebbb8e 100644
--- a/lxd/api_1.0.go
+++ b/lxd/api_1.0.go
@@ -76,12 +76,12 @@ var api10 = []Command{
storagePoolResourcesCmd,
storagePoolsCmd,
storagePoolVolumesCmd,
+   storagePoolVolumeSnapshotsTypeCmd,
+   storagePoolVolumeSnapshotTypeCmd,
storagePoolVolumesTypeCmd,
storagePoolVolumeTypeContainerCmd,
storagePoolVolumeTypeCustomCmd,
storagePoolVolumeTypeImageCmd,
-   storagePoolVolumeSnapshotsTypeCmd,
-   storagePoolVolumeSnapshotTypeCmd,
 }
 
 func api10Get(d *Daemon, r *http.Request) Response {

From ca022cbf401dd46fcec9320a99b89ef31fc71b0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= 
Date: Tue, 23 Apr 2019 22:45:59 -0400
Subject: [PATCH 3/5] lxd/api: Rename snapshotHandler to
 containerSnapshotHandler
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber 
---
 lxd/container_snapshot.go | 2 +-
 lxd/containers.go | 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lxd/container_snapshot.go b/lxd/container_snapshot.go
index 0d3fde4f76..bcc77a984b 100644
--- a/lxd/container_snapshot.go
+++ b/lxd/container_snapshot.go
@@ -170,7 +170,7 @@ func containerSnapshotsPost(d *Daemon, r *http.Request) 
Response {
return OperationResponse(op)
 }
 
-func snapshotHandler(d *Daemon, r *http.Request) Response {
+func containerSnapshotHandler(d *Daemon, r *http.Request) Response {
project := projectParam(r)
containerName := mux.Vars(r)["name"]
snapshotName := mux.Vars(r)["snapshotName"]
diff --git a/lxd/containers.go b/lxd/containers.go
index 271be1afb7..30aa2b6c63 100644
--- a/lxd/containers.go
+++ b/lxd/containers.go
@@ -52,10 +52,10 @@ var containerSnapshotsCmd = Command{
 
 var containerSnapshotCmd = Command{
name:   "containers/{name}/snapshots/{snapshotName}",
-   get:snapshotHandler,
-   post:   snapshotHandler,
-   delete: snapshotHandler,
-   put:snapshotHandler,
+   get:

[lxc-devel] [libresource/master] making memory related information cgroup aware.

2019-04-23 Thread rahuyada on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/libresource/pull/5

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
This PR makes memory related information provided by libresource cgroup aware.
If process is part of a cgroup then libresource figures out corresponding cgroup for memory controller and reads/interprets the information based on cgroup files.
From 0600cd30ccf1ccedf58ac9be62a9f2162780c8e6 Mon Sep 17 00:00:00 2001
From: Rahul Yadav 
Date: Tue, 23 Apr 2019 12:18:46 -0700
Subject: [PATCH 1/2] Made code changes to make memory information cgroup
 aware.

---
 resmem.c| 444 
 resmem.h|   2 +
 resnet.c|   4 +-
 resource.c  |   4 +-
 resource_impl.h |  86 +-
 5 files changed, 495 insertions(+), 45 deletions(-)

diff --git a/resmem.c b/resmem.c
index d0820e0..97a0eb4 100644
--- a/resmem.c
+++ b/resmem.c
@@ -19,7 +19,6 @@
 #ifndef _RESOURCE_H
 #include "resource.h"
 #endif
-#include 
 #include 
 #include 
 #include 
@@ -27,6 +26,9 @@
 #include "resmem.h"
 #include "resource_impl.h"
 #include 
+#include 
+
+#define startswith(str, buf) strncmp(str, buf, sizeof(str) - 1)
 
 /* read a specific information from file on the basis of a string.
  * String should tell what information is being read.
@@ -36,7 +38,7 @@ static inline int get_info_infile(char *fname, char *res, 
void *out)
const char *loc;
char buf[MEMBUF_2048];
 
-   if (file_to_buf(fname, buf) == -1)
+   if (file_to_buf(fname, buf, MEMBUF_2048) == -1)
return -1;
 
loc = strstr(buf, res);
@@ -50,37 +52,295 @@ static inline int get_info_infile(char *fname, char *res, 
void *out)
return 0;
 }
 
+/* read information from a cgroup file.
+ */
+static inline size_t cgmemread(char *cg, char *file)
+{
+   char buf[MEMBUF_128];
+   char fn[FNAMELEN];
+
+   snprintf(fn, FNAMELEN, "%s/%s%s/%s", DEFAULTCGFS,
+   MEMCGNAME, cg, file);
+
+   if (file_to_buf(fn, buf, MEMBUF_128) == -1)
+   return 0;
+
+   return (strtoul(buf, NULL, 10) / 1024);
+}
+
+/* read memory limit from cgorup file
+ */
+static size_t cgmemlimit(char *cg, char *f)
+{
+   char *copy;
+   char *dir;
+   size_t mem = 0, retmem = 0;
+
+   /* read memory limit for cgroup */
+   if ((retmem = cgmemread(cg, f)) == -1) {
+   return 0;
+   }
+
+   copy = strdup(cg);
+   dir = dirname(copy);
+
+   /*read memory limit for parant cg */
+   if (strcmp(dir, "/") != 0) {
+   if((mem = cgmemread(dir, f)) == 0) {
+   free(copy);
+   return 0;
+   }
+   if (mem < retmem) {
+   retmem = mem;
+   }
+   }
+
+   free(copy);
+   return retmem;
+}
+
+/* get memory stat from memory.stat file */
+static inline size_t cgmemstat(char *cg, char *stat)
+{
+   char fn[FNAMELEN];
+   size_t ret;
+
+   snprintf(fn, FNAMELEN, "%s/%s%s/%s", DEFAULTCGFS,
+   MEMCGNAME, cg, "memory.stat");
+
+   if (get_info_infile(fn, stat, ) == -1)
+   return 0;
+
+   return (ret / 1024);
+}
+
+/* Get all memory info for a cgroup */
+static int getmeminfoall(char *cg, void *out)
+{
+   size_t memtotal, mmusage, mmtot, cache, active_anon, inactive_anon,
+   active_file, inactive_file, swaptotal, swapfree, swusage,
+   swtot;
+   char fn[FNAMELEN];
+   FILE *fp;
+   int err;
+   char buf[MEMBUF_128];
+
+   snprintf(fn, FNAMELEN, "%s/%s%s/%s", DEFAULTCGFS,
+   MEMCGNAME, cg, "memory.stat");
+
+   fp = fopen(fn, "r");
+
+   if (fp == NULL) {
+   err = errno;
+   eprintf("while opening File %s with errno: %d", fn, errno);
+   errno = err;
+   return -1;
+   }
+
+   while(fgets(buf, sizeof(buf), fp) != NULL) {
+   if (startswith("cache", buf) == 0) {
+   sscanf(buf, "%*s%zu", );
+   cache /= 1024;
+   } else if (startswith("active_anon", buf) == 0) {
+   sscanf(buf, "%*s%zu", _anon);
+   active_anon /= 1024;
+   } else if (startswith("inactive_anon", buf) == 0) {
+   sscanf(buf, "%*s%zu", _anon);
+   inactive_anon /= 1024;
+   } else if (startswith("active_file", buf) == 0) {
+   sscanf(buf, "%*s%zu", _file);
+   active_file /= 1024;
+   } else if (startswith("inactive_file", buf) == 0) {
+   sscanf(buf, "%*s%zu", _file);
+   inactive_file /= 1024;
+   }
+   }
+   

[lxc-devel] [lxd/master] lxd/candid: Cleanup config handling

2019-04-23 Thread stgraber on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/5693

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Stéphane Graber 
From c19848cef9f259bc46cad39b9705fdf200bdf7a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= 
Date: Thu, 18 Apr 2019 15:47:14 +0100
Subject: [PATCH] lxd/candid: Cleanup config handling
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber 
---
 lxd/api_1.0.go| 13 ++---
 lxd/api_cluster.go|  8 ++--
 lxd/cluster/config.go | 22 +++---
 lxd/daemon.go | 14 ++
 4 files changed, 17 insertions(+), 40 deletions(-)

diff --git a/lxd/api_1.0.go b/lxd/api_1.0.go
index 9f87b89c90..6f194d76f1 100644
--- a/lxd/api_1.0.go
+++ b/lxd/api_1.0.go
@@ -92,9 +92,12 @@ func api10Get(d *Daemon, r *http.Request) Response {
if err != nil {
return err
}
-   if config.CandidEndpoint() != "" {
+
+   candidURL, _, _, _ := config.CandidServer()
+   if candidURL != "" {
authMethods = append(authMethods, "candid")
}
+
return nil
})
if err != nil {
@@ -491,12 +494,8 @@ func doApi10UpdateTriggers(d *Daemon, nodeChanged, 
clusterChanged map[string]str
}
 
if candidChanged {
-   endpoint := clusterConfig.CandidEndpoint()
-   endpointKey := clusterConfig.CandidEndpointKey()
-   expiry := clusterConfig.CandidExpiry()
-   domains := clusterConfig.CandidDomains()
-
-   err := d.setupExternalAuthentication(endpoint, endpointKey, 
expiry, domains)
+   apiURL, apiKey, expiry, domains := clusterConfig.CandidServer()
+   err := d.setupExternalAuthentication(apiURL, apiKey, expiry, 
domains)
if err != nil {
return err
}
diff --git a/lxd/api_cluster.go b/lxd/api_cluster.go
index 3a5c5dfeea..b930c8a18c 100644
--- a/lxd/api_cluster.go
+++ b/lxd/api_cluster.go
@@ -523,12 +523,8 @@ func clusterPutJoin(d *Daemon, req api.ClusterPut) 
Response {
}
 
// Connect to Candid
-   endpoint := clusterConfig.CandidEndpoint()
-   endpointKey := clusterConfig.CandidEndpointKey()
-   expiry := clusterConfig.CandidExpiry()
-   domains := clusterConfig.CandidDomains()
-
-   err = d.setupExternalAuthentication(endpoint, endpointKey, 
expiry, domains)
+   candidAPIURL, candidAPIKey, candidExpiry, candidDomains := 
clusterConfig.CandidServer()
+   err = d.setupExternalAuthentication(candidAPIURL, candidAPIKey, 
candidExpiry, candidDomains)
if err != nil {
return err
}
diff --git a/lxd/cluster/config.go b/lxd/cluster/config.go
index 3b32f89d00..aa521424fa 100644
--- a/lxd/cluster/config.go
+++ b/lxd/cluster/config.go
@@ -64,25 +64,9 @@ func (c *Config) TrustPassword() string {
return c.m.GetString("core.trust_password")
 }
 
-// CandidEndpoint returns the address of the Candid endpoint to use for
-// authentication, if any.
-func (c *Config) CandidEndpoint() string {
-   return c.m.GetString("candid.api.url")
-}
-
-// CandidEndpointKey returns the public key for the API endpoint
-func (c *Config) CandidEndpointKey() string {
-   return c.m.GetString("candid.api.key")
-}
-
-// CandidExpiry returns the cookie expiry of the macaroon.
-func (c *Config) CandidExpiry() int64 {
-   return c.m.GetInt64("candid.expiry")
-}
-
-// CandidDomains returns the valid domains.
-func (c *Config) CandidDomains() string {
-   return c.m.GetString("candid.domains")
+// CandidServer returns all the Candid settings needed to connect to a server.
+func (c *Config) CandidServer() (string, string, int64, string) {
+   return c.m.GetString("candid.api.url"), 
c.m.GetString("candid.api.key"), c.m.GetInt64("candid.expiry"), 
c.m.GetString("candid.domains")
 }
 
 // AutoUpdateInterval returns the configured images auto update interval.
diff --git a/lxd/daemon.go b/lxd/daemon.go
index 23a8fd8fb4..96a373869d 100644
--- a/lxd/daemon.go
+++ b/lxd/daemon.go
@@ -719,10 +719,11 @@ func (d *Daemon) init() error {
pruneLeftoverImages(d)
 
/* Setup the proxy handler, external authentication and MAAS */
-   var candidExpiry int64
+   candidAPIURL := ""
+   candidAPIKey := ""
candidDomains := ""
-   candidEndpoint := ""
-   candidEndpointKey := ""
+   candidExpiry := int64(0)
+
maasAPIURL := ""
maasAPIKey := ""
maasMachine := ""
@@ -750,10 +751,7 @@ func (d *Daemon) 

[lxc-devel] [lxc/lxc] bd65f5: lxc-start: remove bad doc

2019-04-23 Thread Christian Brauner
  Branch: refs/heads/master
  Home:   https://github.com/lxc/lxc
  Commit: bd65f5ce50d40f3cfece6ed3eaf2c471448281ae
  https://github.com/lxc/lxc/commit/bd65f5ce50d40f3cfece6ed3eaf2c471448281ae
  Author: Tycho Andersen 
  Date:   2019-04-23 (Tue, 23 Apr 2019)

  Changed paths:
M src/lxc/tools/lxc_start.c

  Log Message:
  ---
  lxc-start: remove bad doc

We don't in fact exit(1) if this is not specified, and it wouldn't make
sense to, since most people probably don't specify this.

Signed-off-by: Tycho Andersen 


  Commit: a24d015dafa7121b5089d264b79cf82406702924
  https://github.com/lxc/lxc/commit/a24d015dafa7121b5089d264b79cf82406702924
  Author: Christian Brauner 
  Date:   2019-04-23 (Tue, 23 Apr 2019)

  Changed paths:
M src/lxc/tools/lxc_start.c

  Log Message:
  ---
  Merge pull request #2946 from tych0/remove-bad-doc

lxc-start: remove bad doc


Compare: https://github.com/lxc/lxc/compare/60c20c6e0e85...a24d015dafa7
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


[lxc-devel] [lxc/master] lxc-start: remove bad doc

2019-04-23 Thread tych0 on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/2946

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
We don't in fact exit(1) if this is not specified, and it wouldn't make
sense to, since most people probably don't specify this.

Signed-off-by: Tycho Andersen 
From bd65f5ce50d40f3cfece6ed3eaf2c471448281ae Mon Sep 17 00:00:00 2001
From: Tycho Andersen 
Date: Tue, 23 Apr 2019 08:48:29 -0600
Subject: [PATCH] lxc-start: remove bad doc

We don't in fact exit(1) if this is not specified, and it wouldn't make
sense to, since most people probably don't specify this.

Signed-off-by: Tycho Andersen 
---
 src/lxc/tools/lxc_start.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/lxc/tools/lxc_start.c b/src/lxc/tools/lxc_start.c
index 4553cb5ca3..ee716f1f3f 100644
--- a/src/lxc/tools/lxc_start.c
+++ b/src/lxc/tools/lxc_start.c
@@ -88,7 +88,6 @@ Options :\n\
   -c, --console=FILE Use specified FILE for the container console\n\
   -L, --console-log=FILE Log container console output to FILE\n\
   -C, --close-all-fdsIf any fds are inherited, close them\n\
- If not specified, exit with failure instead\n\
  Note: --daemon implies --close-all-fds\n\
   -s, --define KEY=VAL   Assign VAL to configuration variable KEY\n\
   --share-[net|ipc|uts|pid]=NAME Share a namespace with another container 
or pid\n\
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


[lxc-devel] [distrobuilder/master] chroot: Fix error during chroot setup

2019-04-23 Thread monstermunchkin on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/170

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
This fixes #167 

Signed-off-by: Thomas Hipp 
From 67be9d8d77f719ebdfcd64cf70cc69d8178a7a62 Mon Sep 17 00:00:00 2001
From: Thomas Hipp 
Date: Tue, 23 Apr 2019 12:17:15 +0200
Subject: [PATCH] chroot: Fix error during chroot setup

Signed-off-by: Thomas Hipp 
---
 shared/chroot.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/shared/chroot.go b/shared/chroot.go
index 8f18fb7..2b6aa9d 100644
--- a/shared/chroot.go
+++ b/shared/chroot.go
@@ -34,7 +34,7 @@ func setupMounts(rootfs string, mounts []chrootMount) error {
 
// Create the target mountpoint
if mount.isDir {
-   err := os.Mkdir(tmpTarget, 0755)
+   err := os.MkdirAll(tmpTarget, 0755)
if err != nil {
return err
}
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel