[lxc-devel] [lxd/master] Moving some bits around

stgraber on Github lxc-bot at linuxcontainers.org
Tue Dec 20 19:50:41 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161220/7a30f8bd/attachment.bin>
-------------- next part --------------
From e102bd2d087a4ba34ac2034853c80883c9503c67 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 19 Dec 2016 20:59:03 -0500
Subject: [PATCH 1/2] shared: Move WebsocketUpgrader to network.go
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 shared/network.go   | 5 +++++
 shared/operation.go | 7 -------
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/shared/network.go b/shared/network.go
index d04ff96..c60ba74 100644
--- a/shared/network.go
+++ b/shared/network.go
@@ -8,6 +8,7 @@ import (
 	"io"
 	"io/ioutil"
 	"net"
+	"net/http"
 	"time"
 
 	"github.com/gorilla/websocket"
@@ -325,3 +326,7 @@ func WebsocketMirror(conn *websocket.Conn, w io.WriteCloser, r io.ReadCloser, Re
 
 	return readDone, writeDone
 }
+
+var WebsocketUpgrader = websocket.Upgrader{
+	CheckOrigin: func(r *http.Request) bool { return true },
+}
diff --git a/shared/operation.go b/shared/operation.go
index fa955e8..121be2e 100644
--- a/shared/operation.go
+++ b/shared/operation.go
@@ -1,16 +1,9 @@
 package shared
 
 import (
-	"net/http"
 	"time"
-
-	"github.com/gorilla/websocket"
 )
 
-var WebsocketUpgrader = websocket.Upgrader{
-	CheckOrigin: func(r *http.Request) bool { return true },
-}
-
 type Operation struct {
 	Id         string              `json:"id"`
 	Class      string              `json:"class"`

From 997900dd7412452d387e198817a5be4a6dc516c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 19 Dec 2016 21:14:57 -0500
Subject: [PATCH 2/2] Move FromLXCState out of shared
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/container_lxc.go | 18 ++++++++++++++++--
 shared/status.go     | 19 -------------------
 2 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 95232bc..3d84d7d 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -163,6 +163,20 @@ func lxcValidConfig(rawLxc string) error {
 	return nil
 }
 
+func lxcStatusCode(state lxc.State) shared.StatusCode {
+	return map[int]shared.StatusCode{
+		1: shared.Stopped,
+		2: shared.Starting,
+		3: shared.Running,
+		4: shared.Stopping,
+		5: shared.Aborting,
+		6: shared.Freezing,
+		7: shared.Frozen,
+		8: shared.Thawed,
+		9: shared.Error,
+	}[int(state)]
+}
+
 // Loader functions
 func containerLXCCreate(d *Daemon, args containerArgs) (container, error) {
 	// Create the container struct
@@ -2406,7 +2420,7 @@ func (c *containerLXC) Render() (interface{}, interface{}, error) {
 		if err != nil {
 			return nil, nil, err
 		}
-		statusCode := shared.FromLXCState(int(cState))
+		statusCode := lxcStatusCode(cState)
 
 		return &shared.ContainerInfo{
 			Architecture:    architectureName,
@@ -2437,7 +2451,7 @@ func (c *containerLXC) RenderState() (*shared.ContainerState, error) {
 	if err != nil {
 		return nil, err
 	}
-	statusCode := shared.FromLXCState(int(cState))
+	statusCode := lxcStatusCode(cState)
 	status := shared.ContainerState{
 		Status:     statusCode.String(),
 		StatusCode: statusCode,
diff --git a/shared/status.go b/shared/status.go
index 96010c4..7651f5c 100644
--- a/shared/status.go
+++ b/shared/status.go
@@ -47,22 +47,3 @@ func (o StatusCode) String() string {
 func (o StatusCode) IsFinal() bool {
 	return int(o) >= 200
 }
-
-/*
- * Create a StatusCode from an lxc.State code. N.B.: we accept an int instead
- * of a lxc.State so that the shared code doesn't depend on lxc, which depends
- * on liblxc, etc.
- */
-func FromLXCState(state int) StatusCode {
-	return map[int]StatusCode{
-		1: Stopped,
-		2: Starting,
-		3: Running,
-		4: Stopping,
-		5: Aborting,
-		6: Freezing,
-		7: Frozen,
-		8: Thawed,
-		9: Error,
-	}[state]
-}


More information about the lxc-devel mailing list