lxc/config/remote.go
func (c *Config) GetContainerServer(name string) (lxd.ContainerServer, error) {
	// Get the remote
	remote, ok := c.Remotes[name]
	if !ok {
		return nil, fmt.Errorf("The remote \"%s\" doesn't exist", name)
	}

	// Sanity checks
	if remote.Public || remote.Protocol == "simplestreams" {
		return nil, fmt.Errorf("The remote isn't a private LXD server")
	}

	// Get connection arguments
	args, err := c.getConnectionArgs(name)
	if err != nil {
		return nil, err
	}

	// Unix socket
	if strings.HasPrefix(remote.Addr, "unix:") {
		d, err := lxd.ConnectLXDUnix(strings.TrimPrefix(strings.TrimPrefix(remote.Addr, "unix:"), "//"), args)
		if err != nil {
			return nil, err
		}

		if remote.Project != "" && remote.Project != "default" {
			d = d.UseProject(remote.Project)
		}

		if c.ProjectOverride != "" {
			d = d.UseProject(c.ProjectOverride)
		}

		return d, nil
	}

	// HTTPs
	if remote.AuthType != "candid" && (args.TLSClientCert == "" || args.TLSClientKey == "") {
		return nil, fmt.Errorf("Missing TLS client certificate and key")
	}

	d, err := lxd.ConnectLXD(remote.Addr, args)
	if err != nil {
		return nil, err
	}

	if remote.Project != "" && remote.Project != "default" {
		d = d.UseProject(remote.Project)
	}

	if c.ProjectOverride != "" {
		d = d.UseProject(c.ProjectOverride)
	}

	return d, nil
}
func (c *Config) GetContainerServer(name string) (lxd.ContainerServer, error) {
	// Get the remote
	remote, ok := c.Remotes[name]
	if !ok {
		return nil, fmt.Errorf("The remote \"%s\" doesn't exist", name)
	}

	// Sanity checks
	if remote.Public || remote.Protocol == "simplestreams" {
		return nil, fmt.Errorf("The remote isn't a private LXD server")
	}

	// Get connection arguments
	args, err := c.getConnectionArgs(name)
	if err != nil {
		return nil, err
	}

	// Unix socket
	if strings.HasPrefix(remote.Addr, "unix:") {
		d, err := lxd.ConnectLXDUnix(strings.TrimPrefix(strings.TrimPrefix(remote.Addr, "unix:"), "//"), args)
		if err != nil {
			return nil, err
		}

		if remote.Project != "" && remote.Project != "default" {
			d = d.UseProject(remote.Project)
		}

		if c.ProjectOverride != "" {
			d = d.UseProject(c.ProjectOverride)
		}

		return d, nil
	}

	// HTTPs
	if remote.AuthType != "candid" && (args.TLSClientCert == "" || args.TLSClientKey == "") {
		return nil, fmt.Errorf("Missing TLS client certificate and key")
	}

	d, err := lxd.ConnectLXD(remote.Addr, args)
	if err != nil {
		return nil, err
	}

	if remote.Project != "" && remote.Project != "default" {
		d = d.UseProject(remote.Project)
	}

	if c.ProjectOverride != "" {
		d = d.UseProject(c.ProjectOverride)
	}

	return d, nil
}
func ( c * Config ) GetContainerServer ( name string ) ( lxd . ContainerServer , error ) { // Get the remote remote , ok := c . Remotes [ name ] if ! ok { return nil , fmt . Errorf ( " \" \" " , name ) } // Sanity checks if remote . Public || remote . Protocol == " " { return nil , fmt . Errorf ( " " ) } // Get connection arguments args , err := c . getConnectionArgs ( name ) if err != nil { return nil , err } // Unix socket if strings . HasPrefix ( remote . Addr , " " ) { d , err := lxd . ConnectLXDUnix ( strings . TrimPrefix ( strings . TrimPrefix ( remote . Addr , " " ) , " " ) , args ) if err != nil { return nil , err } if remote . Project != " " && remote . Project != " " { d = d . UseProject ( remote . Project ) } if c . ProjectOverride != " " { d = d . UseProject ( c . ProjectOverride ) } return d , nil } // HTTPs if remote . AuthType != " " && ( args . TLSClientCert == " " || args . TLSClientKey == " " ) { return nil , fmt . Errorf ( " " ) } d , err := lxd . ConnectLXD ( remote . Addr , args ) if err != nil { return nil , err } if remote . Project != " " && remote . Project != " " { d = d . UseProject ( remote . Project ) } if c . ProjectOverride != " " { d = d . UseProject ( c . ProjectOverride ) } return d , nil }
// GetContainerServer returns a ContainerServer struct for the remote
GetContainerServer returns a ContainerServer struct for the remote