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

	// 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 (simplestreams)
	if remote.Protocol == "simplestreams" {
		d, err := lxd.ConnectSimpleStreams(remote.Addr, args)
		if err != nil {
			return nil, err
		}

		return d, nil
	}

	// HTTPs (public LXD)
	if remote.Public {
		d, err := lxd.ConnectPublicLXD(remote.Addr, args)
		if err != nil {
			return nil, err
		}

		return d, nil
	}

	// HTTPs (private LXD)
	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) GetImageServer(name string) (lxd.ImageServer, error) {
	// Get the remote
	remote, ok := c.Remotes[name]
	if !ok {
		return nil, fmt.Errorf("The remote \"%s\" doesn't exist", name)
	}

	// 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 (simplestreams)
	if remote.Protocol == "simplestreams" {
		d, err := lxd.ConnectSimpleStreams(remote.Addr, args)
		if err != nil {
			return nil, err
		}

		return d, nil
	}

	// HTTPs (public LXD)
	if remote.Public {
		d, err := lxd.ConnectPublicLXD(remote.Addr, args)
		if err != nil {
			return nil, err
		}

		return d, nil
	}

	// HTTPs (private LXD)
	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 ) GetImageServer ( name string ) ( lxd . ImageServer , error ) { // Get the remote remote , ok := c . Remotes [ name ] if ! ok { return nil , fmt . Errorf ( " \" \" " , name ) } // 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 (simplestreams) if remote . Protocol == " " { d , err := lxd . ConnectSimpleStreams ( remote . Addr , args ) if err != nil { return nil , err } return d , nil } // HTTPs (public LXD) if remote . Public { d , err := lxd . ConnectPublicLXD ( remote . Addr , args ) if err != nil { return nil , err } return d , nil } // HTTPs (private LXD) 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 }
// GetImageServer returns a ImageServer struct for the remote
GetImageServer returns a ImageServer struct for the remote