From 2a17adb1277a0925351fc470f3cd78a624ddcd19 Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Thu, 14 Jan 2016 17:12:11 +0200 Subject: [PATCH 1/6] lxd: update config for latest version The LXD API has updated to allow config files to be loaded from arbitrary locations on disk without mucking around with the environment (sorry about that), which gets rid of some ugly code. Additionally, there are some minor symbol signature updates as well. Signed-off-by: Tycho Andersen --- dependencies.tsv | 2 +- provider/lxd/config_test.go | 5 ++-- provider/lxd/lxdclient/client.go | 6 +---- provider/lxd/lxdclient/client_raw.go | 4 ++-- provider/lxd/lxdclient/config.go | 35 +++++++++------------------- provider/lxd/lxdclient/config_test.go | 13 +++-------- provider/lxd/lxdclient/lxd_client.go | 44 +++++++++++++++++------------------ provider/lxd/testing_test.go | 3 --- 8 files changed, 42 insertions(+), 70 deletions(-) diff --git a/dependencies.tsv b/dependencies.tsv index 9001823884..25d7d12e84 100644 --- a/dependencies.tsv +++ b/dependencies.tsv @@ -36,7 +36,7 @@ github.com/juju/txn git 99ec629d0066a4d73c54d8e021a7fc1dc07df614 2015-06-09T16:5 github.com/juju/utils git 93acdddf8455dcb95aa63f2e2f707e5f8c199754 2016-01-20T00:56:23Z github.com/juju/xml git eb759a627588d35166bc505fceb51b88500e291e 2015-04-13T13:11:21Z github.com/julienschmidt/httprouter git 109e267447e95ad1bb48b758e40dd7453eb7b039 2015-09-05T17:25:33Z -github.com/lxc/lxd git 42b4c228e84cba622f221e04a1fa7164a416a440 2015-10-27T22:33:42Z +github.com/lxc/lxd git c2d6a334e768d82cc2551c557cf37b5f738e36da 2015-10-27T22:33:42Z github.com/mattn/go-colorable git 40e4aedc8fabf8c23e040057540867186712faa5 2015-06-25T15:46:42Z github.com/mattn/go-isatty git d6aaa2f596ae91a0a58d8e7f2c79670991468e4f 2015-11-07T15:36:48Z golang.org/x/crypto git aedad9a179ec1ea11b7064c57cbc6dc30d7724ec 2015-08-30T18:06:42Z diff --git a/provider/lxd/config_test.go b/provider/lxd/config_test.go index 8f66af797e..d17f9c3c97 100644 --- a/provider/lxd/config_test.go +++ b/provider/lxd/config_test.go @@ -9,7 +9,6 @@ import ( "fmt" jc "github.com/juju/testing/checkers" - lxdlib "github.com/lxc/lxd" gc "gopkg.in/check.v1" "github.com/juju/juju/environs" @@ -61,7 +60,7 @@ func (s *configSuite) TestClientConfigLocal(c *gc.C) { c.Check(clientCfg, jc.DeepEquals, lxdclient.Config{ Namespace: cfg.Name(), - Dirname: lxdlib.ConfigPath("juju-testenv"), + Dirname: lxdclient.ConfigPath("juju-testenv"), Remote: lxdclient.Remote{ Name: "juju-remote", Host: "", @@ -84,7 +83,7 @@ func (s *configSuite) TestClientConfigNonLocal(c *gc.C) { c.Check(clientCfg, jc.DeepEquals, lxdclient.Config{ Namespace: cfg.Name(), - Dirname: lxdlib.ConfigPath("juju-testenv"), + Dirname: lxdclient.ConfigPath("juju-testenv"), Remote: lxdclient.Remote{ Name: "juju-remote", Host: "10.0.0.1", diff --git a/provider/lxd/lxdclient/client.go b/provider/lxd/lxdclient/client.go index 069726ac90..45958dfbf1 100644 --- a/provider/lxd/lxdclient/client.go +++ b/provider/lxd/lxdclient/client.go @@ -52,11 +52,7 @@ var lxdLoadConfig = lxd.LoadConfig func newRawClient(remote, configDir string) (*lxd.Client, error) { logger.Debugf("loading LXD client config from %q", configDir) - // This will go away once LoadConfig takes a dirname argument. - origDirname := updateLXDVars(configDir) - defer updateLXDVars(origDirname) - - cfg, err := lxdLoadConfig() + cfg, err := lxdLoadConfig(configDir) if err != nil { return nil, errors.Trace(err) } diff --git a/provider/lxd/lxdclient/client_raw.go b/provider/lxd/lxdclient/client_raw.go index 7e8ae5a043..c5c880b820 100644 --- a/provider/lxd/lxdclient/client_raw.go +++ b/provider/lxd/lxdclient/client_raw.go @@ -63,7 +63,7 @@ type rawImageMethods interface { //PutImageProperties(name string, p shared.ImageProperties) error // image data (create, upload, download, destroy) - CopyImage(image string, dest *lxd.Client, copy_aliases bool, aliases []string, public bool) error + CopyImage(image string, dest *lxd.Client, copy_aliases bool, aliases []string, public bool, progressHandler func(string)) error ImageFromContainer(cname string, public bool, aliases []string, properties map[string]string) (string, error) PostImage(imageFile string, rootfsFile string, properties []string, public bool, aliases []string) (string, error) ExportImage(image string, target string) (*lxd.Response, string, error) @@ -90,7 +90,7 @@ type rawContainerMethods interface { // container data (create, actions, destroy) Init(name string, imgremote string, image string, profiles *[]string, config map[string]string, ephem bool) (*lxd.Response, error) LocalCopy(source string, name string, config map[string]string, profiles []string, ephemeral bool) (*lxd.Response, error) - MigrateFrom(name string, operation string, secrets map[string]string, config map[string]string, profiles []string, baseImage string, ephemeral bool) (*lxd.Response, error) + MigrateFrom(name string, operation string, secrets map[string]string, architecture int, config map[string]string, devices shared.Devices, profiles []string, baseImage string, ephemeral bool) (*lxd.Response, error) Action(name string, action shared.ContainerAction, timeout int, force bool) (*lxd.Response, error) Delete(name string) (*lxd.Response, error) diff --git a/provider/lxd/lxdclient/config.go b/provider/lxd/lxdclient/config.go index 266422c2e2..52972f3e3d 100644 --- a/provider/lxd/lxdclient/config.go +++ b/provider/lxd/lxdclient/config.go @@ -6,6 +6,7 @@ package lxdclient import ( + "fmt" "os" "path" "path/filepath" @@ -43,7 +44,9 @@ type Config struct { // ConfigPath returns the full path to Juju LXC config directory. // This is here so we do not have to import lxc/lxd into the provider. func ConfigPath(namespace string) string { - return lxd.ConfigPath(namespace) + // Here we use the same path as lxc for convention, but we could use + // any juju specific path. + return os.ExpandEnv(path.Join("$HOME/.config/lxc", namespace)) } // WithDefaults updates a copy of the config with default values @@ -53,9 +56,10 @@ func (cfg Config) WithDefaults() (Config, error) { // Also, note that cfg is a value receiver, so it is an implicit copy. if cfg.Dirname == "" { - // TODO(ericsnow) Switch to filepath as soon as LXD does. - dirname := path.Dir(lxd.ConfigPath("DUMMY")) + // TODO(ericsnow) Switch to filepath as soon as LXD does, + dirname := path.Dir(ConfigPath("DUMMY")) cfg.Dirname = path.Clean(dirname) + fmt.Println("cleaned config %s %s", dirname, cfg.Dirname) } var err error @@ -88,9 +92,6 @@ func (cfg Config) Write() error { return errors.Trace(err) } - origConfigDir := updateLXDVars(cfg.Dirname) - defer updateLXDVars(origConfigDir) - if err := cfg.write(); err != nil { return errors.Trace(err) } @@ -143,20 +144,6 @@ func prepareRemote(cfg Config, newCert Cert) error { return nil } -func updateLXDVars(dirname string) string { - // Change the hard-coded config dir that the raw client uses. - // TODO(ericsnow) This is exactly what happens in the lxc CLI for - // the LXD_CONF env var. Once the raw client accepts a path to the - // config dir we can drop this line. - // See: - // https://github.com/lxc/lxd/blob/master/lxc/main.go - // https://github.com/lxc/lxd/issues/1196 - origConfigDir := lxd.ConfigDir - lxd.ConfigDir = dirname - - return origConfigDir -} - //TODO(wwitzel3) make sure this is idempotent func initializeConfigDir(cfg Config) error { logger.Debugf("initializing config dir %q", cfg.Dirname) @@ -169,12 +156,12 @@ func initializeConfigDir(cfg Config) error { // default config from memory if there isn't a config file on disk. // So we load that and then explicitly save it to disk with a call // to SaveConfig(). - config, err := lxd.LoadConfig() + config, err := lxd.LoadConfig(cfg.resolve(configDefaultFile)) if err != nil { return errors.Trace(err) } - if err := lxd.SaveConfig(config); err != nil { + if err := lxd.SaveConfig(config, cfg.resolve(configDefaultFile)); err != nil { return errors.Trace(err) } @@ -205,7 +192,7 @@ func (cfg Config) writeConfigFile() error { logger.Debugf("writing config file %q", filename) // TODO(ericsnow) Cache the low-level config in Config? - rawCfg, err := lxd.LoadConfig() + rawCfg, err := lxd.LoadConfig(cfg.resolve(configDefaultFile)) if err != nil { return errors.Trace(err) } @@ -222,7 +209,7 @@ func (cfg Config) writeConfigFile() error { // Write out the updated config, if changed. // TODO(ericsnow) Check if changed. - if err := lxd.SaveConfig(rawCfg); err != nil { + if err := lxd.SaveConfig(rawCfg, cfg.resolve(configDefaultFile)); err != nil { return errors.Trace(err) } diff --git a/provider/lxd/lxdclient/config_test.go b/provider/lxd/lxdclient/config_test.go index 98ca910ae5..4d4c4b982b 100644 --- a/provider/lxd/lxdclient/config_test.go +++ b/provider/lxd/lxdclient/config_test.go @@ -7,6 +7,7 @@ package lxdclient_test import ( "io/ioutil" + "path" "path/filepath" "github.com/juju/errors" @@ -65,6 +66,8 @@ func (s *configSuite) TestWithDefaultsMissingDirname(c *gc.C) { updated, err := cfg.WithDefaults() c.Assert(err, jc.ErrorIsNil) + c.Logf("path.Clean of dirname is %s (dirname is %s)", path.Clean(updated.Dirname), updated.Dirname) + c.Check(updated, jc.DeepEquals, lxdclient.Config{ Namespace: "my-ns", // TODO(ericsnow) This will change on Windows once the LXD @@ -172,11 +175,6 @@ func (s *configFunctionalSuite) SetUpTest(c *gc.C) { s.client = newLocalClient(c) - origConfigDir := lxd.ConfigDir - s.AddCleanup(func(c *gc.C) { - lxd.ConfigDir = origConfigDir - }) - if s.client != nil { origCerts, err := s.client.ListCerts() c.Assert(err, jc.ErrorIsNil) @@ -236,11 +234,6 @@ func (s *configFunctionalSuite) TestUsingTCPRemote(c *gc.C) { } func newLocalClient(c *gc.C) *lxdclient.Client { - origConfigDir := lxd.ConfigDir - defer func() { - lxd.ConfigDir = origConfigDir - }() - client, err := lxdclient.Connect(lxdclient.Config{ Namespace: "my-ns", Dirname: c.MkDir(), diff --git a/provider/lxd/lxdclient/lxd_client.go b/provider/lxd/lxdclient/lxd_client.go index e5f4748b7e..b588f71269 100644 --- a/provider/lxd/lxdclient/lxd_client.go +++ b/provider/lxd/lxdclient/lxd_client.go @@ -20,29 +20,29 @@ const ( StatusStopping = "Stopping" StatusStopped = "Stopped" - StatusOK = "OK" - StatusPending = "Pending" - StatusAborting = "Aborting" - StatusCancelling = "Canceling" - StatusCancelled = "Canceled" - StatusSuccess = "Success" - StatusFailure = "Failure" + StatusOperationCreated = "Operation created" + StatusPending = "Pending" + StatusAborting = "Aborting" + StatusCancelling = "Canceling" + StatusCancelled = "Canceled" + StatusSuccess = "Success" + StatusFailure = "Failure" ) var allStatuses = map[string]shared.StatusCode{ - StatusStarting: shared.Starting, - StatusStarted: shared.Started, - StatusRunning: shared.Running, - StatusFreezing: shared.Freezing, - StatusFrozen: shared.Frozen, - StatusThawed: shared.Thawed, - StatusStopping: shared.Stopping, - StatusStopped: shared.Stopped, - StatusOK: shared.OK, - StatusPending: shared.Pending, - StatusAborting: shared.Aborting, - StatusCancelling: shared.Cancelling, - StatusCancelled: shared.Cancelled, - StatusSuccess: shared.Success, - StatusFailure: shared.Failure, + StatusStarting: shared.Starting, + StatusStarted: shared.Started, + StatusRunning: shared.Running, + StatusFreezing: shared.Freezing, + StatusFrozen: shared.Frozen, + StatusThawed: shared.Thawed, + StatusStopping: shared.Stopping, + StatusStopped: shared.Stopped, + StatusOperationCreated: shared.OperationCreated, + StatusPending: shared.Pending, + StatusAborting: shared.Aborting, + StatusCancelling: shared.Cancelling, + StatusCancelled: shared.Cancelled, + StatusSuccess: shared.Success, + StatusFailure: shared.Failure, } diff --git a/provider/lxd/testing_test.go b/provider/lxd/testing_test.go index b267c02808..d26f6a3676 100644 --- a/provider/lxd/testing_test.go +++ b/provider/lxd/testing_test.go @@ -14,7 +14,6 @@ import ( gitjujutesting "github.com/juju/testing" jc "github.com/juju/testing/checkers" "github.com/juju/utils/arch" - lxdlib "github.com/lxc/lxd" gc "gopkg.in/check.v1" "github.com/juju/juju/cloudconfig/instancecfg" @@ -125,8 +124,6 @@ func (s *BaseSuiteUnpatched) SetUpSuite(c *gc.C) { func (s *BaseSuiteUnpatched) SetUpTest(c *gc.C) { s.IsolationSuite.SetUpTest(c) - s.PatchValue(&lxdlib.ConfigDir, c.MkDir()) - s.initEnv(c) s.initInst(c) s.initNet(c) From 44ef5f43a8ab47a633427cfc3832b178e7c045f5 Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Sun, 17 Jan 2016 11:04:34 +0100 Subject: [PATCH 2/6] lxdclient: fix typo Signed-off-by: Tycho Andersen --- provider/lxd/lxdclient/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/lxd/lxdclient/config.go b/provider/lxd/lxdclient/config.go index 52972f3e3d..52151a9043 100644 --- a/provider/lxd/lxdclient/config.go +++ b/provider/lxd/lxdclient/config.go @@ -28,7 +28,7 @@ const ( // Config contains the config values used for a connection to the LXD API. type Config struct { // Namespace identifies the namespace to associate with containers - // and other resources with which the client interacts. If may be + // and other resources with which the client interacts. It may be // blank. Namespace string From 860ea776566cdce4f114c809d183289da282620b Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Sun, 17 Jan 2016 17:34:12 +0100 Subject: [PATCH 3/6] lxd provider: remove irrelevent documentation Since lxd-images is completely independent of images.linuxcontainers.org (and linuxcontainers.org don't have cloud-init anyway), let's not have people do this unnecessary step. Signed-off-by: Tycho Andersen --- provider/lxd/config.go | 1 - provider/lxd/provider_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/provider/lxd/config.go b/provider/lxd/config.go index 931f4791ca..d6fdace350 100644 --- a/provider/lxd/config.go +++ b/provider/lxd/config.go @@ -63,7 +63,6 @@ lxd: # # You will also need to prepare the "ubuntu" images that Juju uses: # - # lxc remote add images images.linuxcontainers.org # lxd-images import ubuntu --alias ubuntu-wily wily # # (Also consider the --stream and --sync options.) diff --git a/provider/lxd/provider_test.go b/provider/lxd/provider_test.go index 1cb5b760f3..68d37d0645 100644 --- a/provider/lxd/provider_test.go +++ b/provider/lxd/provider_test.go @@ -89,7 +89,6 @@ lxd: # # You will also need to prepare the "ubuntu" images that Juju uses: # - # lxc remote add images images.linuxcontainers.org # lxd-images import ubuntu --alias ubuntu-wily wily # # (Also consider the --stream and --sync options.) From 70c8b25b1c7326677346d5574ee26832db796607 Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Thu, 21 Jan 2016 07:20:29 -0700 Subject: [PATCH 4/6] lxd provider: use the right config path in all places Signed-off-by: Tycho Andersen --- provider/lxd/lxdclient/client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/provider/lxd/lxdclient/client.go b/provider/lxd/lxdclient/client.go index 45958dfbf1..152d9076e5 100644 --- a/provider/lxd/lxdclient/client.go +++ b/provider/lxd/lxdclient/client.go @@ -6,6 +6,8 @@ package lxdclient import ( + "path" + "github.com/juju/errors" "github.com/juju/loggo" "github.com/lxc/lxd" @@ -52,7 +54,7 @@ var lxdLoadConfig = lxd.LoadConfig func newRawClient(remote, configDir string) (*lxd.Client, error) { logger.Debugf("loading LXD client config from %q", configDir) - cfg, err := lxdLoadConfig(configDir) + cfg, err := lxdLoadConfig(path.Join(configDir, "config.yml")) if err != nil { return nil, errors.Trace(err) } From fd9f50ed798461c03ecbc92e210402dfab147d88 Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Thu, 21 Jan 2016 07:46:37 -0700 Subject: [PATCH 5/6] update lxd client version to 0.27 There is a breakage with version 0.27 such that older versions of the go client don't behave correctly when setting configuration. Let's use 0.27. Signed-off-by: Tycho Andersen --- dependencies.tsv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.tsv b/dependencies.tsv index 25d7d12e84..9e1e9a65d6 100644 --- a/dependencies.tsv +++ b/dependencies.tsv @@ -36,7 +36,7 @@ github.com/juju/txn git 99ec629d0066a4d73c54d8e021a7fc1dc07df614 2015-06-09T16:5 github.com/juju/utils git 93acdddf8455dcb95aa63f2e2f707e5f8c199754 2016-01-20T00:56:23Z github.com/juju/xml git eb759a627588d35166bc505fceb51b88500e291e 2015-04-13T13:11:21Z github.com/julienschmidt/httprouter git 109e267447e95ad1bb48b758e40dd7453eb7b039 2015-09-05T17:25:33Z -github.com/lxc/lxd git c2d6a334e768d82cc2551c557cf37b5f738e36da 2015-10-27T22:33:42Z +github.com/lxc/lxd git a65b71bfe278458fc5ded4bc92f7ccc082e335e4 2015-10-27T22:33:42Z github.com/mattn/go-colorable git 40e4aedc8fabf8c23e040057540867186712faa5 2015-06-25T15:46:42Z github.com/mattn/go-isatty git d6aaa2f596ae91a0a58d8e7f2c79670991468e4f 2015-11-07T15:36:48Z golang.org/x/crypto git aedad9a179ec1ea11b7064c57cbc6dc30d7724ec 2015-08-30T18:06:42Z From f8e3c5e401e64c80de5f03758d099d8daa6d498f Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Fri, 22 Jan 2016 08:44:15 -0700 Subject: [PATCH 6/6] lxdclient: get rid of spurious println I introduced this while debugging something, but didn't get rid of it. Happy to squash this commit into the previous ones if necessary. Signed-off-by: Tycho Andersen --- provider/lxd/lxdclient/config.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/provider/lxd/lxdclient/config.go b/provider/lxd/lxdclient/config.go index 52151a9043..c599675f19 100644 --- a/provider/lxd/lxdclient/config.go +++ b/provider/lxd/lxdclient/config.go @@ -6,7 +6,6 @@ package lxdclient import ( - "fmt" "os" "path" "path/filepath" @@ -59,7 +58,6 @@ func (cfg Config) WithDefaults() (Config, error) { // TODO(ericsnow) Switch to filepath as soon as LXD does, dirname := path.Dir(ConfigPath("DUMMY")) cfg.Dirname = path.Clean(dirname) - fmt.Println("cleaned config %s %s", dirname, cfg.Dirname) } var err error