Exemple #1
0
func newLocalClient(c *gc.C) *lxdclient.Client {
	client, err := lxdclient.Connect(lxdclient.Config{
		Namespace: "my-ns",
		Remote:    lxdclient.Local,
	})
	if err != nil {
		c.Log(err)
		return nil
	}
	return client
}
Exemple #2
0
// This is a quick hack to make wily pass with it's default, but unsupported,
// version of LXD. Wily is supported until 2016-7-??. AFAIU LXD will not be
// backported to wily... so we have this:|
// TODO(redir): Remove after wiley or in yakkety.
func skipIfWily(c *gc.C) {
	if series.HostSeries() == "wily" {
		cfg, _ := lxdclient.Config{}.WithDefaults()
		_, err := lxdclient.Connect(cfg)
		// We try to create a client here. On wily this should fail, because
		// the default 0.20 lxd version should make juju/tools/lxdclient return
		// an error.
		if err != nil {
			c.Skip(fmt.Sprintf("Skipping LXD tests because %s", err))
		}
	}
}
Exemple #3
0
func newClient(ecfg *environConfig) (*lxdclient.Client, error) {
	clientCfg, err := ecfg.clientConfig()
	if err != nil {
		return nil, errors.Trace(err)
	}

	client, err := lxdclient.Connect(clientCfg)
	if err != nil {
		return nil, errors.Trace(err)
	}

	return client, nil
}
Exemple #4
0
Fichier : lxd.go Projet : bac/juju
func ConnectLocal() (*lxdclient.Client, error) {
	cfg := lxdclient.Config{
		Remote: lxdclient.Local,
	}

	cfg, err := cfg.WithDefaults()
	if err != nil {
		return nil, errors.Trace(err)
	}

	client, err := lxdclient.Connect(cfg, false)
	if err != nil {
		return nil, errors.Trace(err)
	}

	return client, nil
}
Exemple #5
0
func ConnectLocal(namespace string) (*lxdclient.Client, error) {
	cfg := lxdclient.Config{
		Namespace: namespace,
		Remote:    lxdclient.Local,
	}

	cfg, err := cfg.WithDefaults()
	if err != nil {
		return nil, errors.Trace(err)
	}

	client, err := lxdclient.Connect(cfg)
	if err != nil {
		return nil, errors.Trace(err)
	}

	return client, nil
}
Exemple #6
0
func newClient(
	spec environs.CloudSpec,
	readFile readFileFunc,
	runCommand runCommandFunc,
) (*lxdclient.Client, error) {
	if spec.Endpoint != "" {
		// We don't handle connecting to non-local lxd at present.
		return nil, errors.NotValidf("endpoint %q", spec.Endpoint)
	}

	config, err := getRemoteConfig(readFile, runCommand)
	if errors.IsNotFound(err) {
		config = &lxdclient.Config{Remote: lxdclient.Local}
	} else if err != nil {
		return nil, errors.Trace(err)
	}

	client, err := lxdclient.Connect(*config, true)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return client, nil
}