client/lxd_containers.go
func (r *ProtocolLXD) GetContainerBackupFile(containerName string, name string, req *BackupFileRequest) (*BackupFileResponse, error) {
	if !r.HasExtension("container_backup") {
		return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
	}

	// Build the URL
	uri := fmt.Sprintf("%s/1.0/containers/%s/backups/%s/export", r.httpHost,
		url.QueryEscape(containerName), url.QueryEscape(name))
	if r.project != "" {
		uri += fmt.Sprintf("?project=%s", url.QueryEscape(r.project))
	}

	// Prepare the download request
	request, err := http.NewRequest("GET", uri, nil)
	if err != nil {
		return nil, err
	}

	if r.httpUserAgent != "" {
		request.Header.Set("User-Agent", r.httpUserAgent)
	}

	// Start the request
	response, doneCh, err := cancel.CancelableDownload(req.Canceler, r.http, request)
	if err != nil {
		return nil, err
	}
	defer response.Body.Close()
	defer close(doneCh)

	if response.StatusCode != http.StatusOK {
		_, _, err := lxdParseResponse(response)
		if err != nil {
			return nil, err
		}
	}

	// Handle the data
	body := response.Body
	if req.ProgressHandler != nil {
		body = &ioprogress.ProgressReader{
			ReadCloser: response.Body,
			Tracker: &ioprogress.ProgressTracker{
				Length: response.ContentLength,
				Handler: func(percent int64, speed int64) {
					req.ProgressHandler(ioprogress.ProgressData{Text: fmt.Sprintf("%d%% (%s/s)", percent, shared.GetByteSizeString(speed, 2))})
				},
			},
		}
	}

	size, err := io.Copy(req.BackupFile, body)
	if err != nil {
		return nil, err
	}

	resp := BackupFileResponse{}
	resp.Size = size

	return &resp, nil
}
func (r *ProtocolLXD) GetContainerBackupFile(containerName string, name string, req *BackupFileRequest) (*BackupFileResponse, error) {
	if !r.HasExtension("container_backup") {
		return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
	}

	// Build the URL
	uri := fmt.Sprintf("%s/1.0/containers/%s/backups/%s/export", r.httpHost,
		url.QueryEscape(containerName), url.QueryEscape(name))
	if r.project != "" {
		uri += fmt.Sprintf("?project=%s", url.QueryEscape(r.project))
	}

	// Prepare the download request
	request, err := http.NewRequest("GET", uri, nil)
	if err != nil {
		return nil, err
	}

	if r.httpUserAgent != "" {
		request.Header.Set("User-Agent", r.httpUserAgent)
	}

	// Start the request
	response, doneCh, err := cancel.CancelableDownload(req.Canceler, r.http, request)
	if err != nil {
		return nil, err
	}
	defer response.Body.Close()
	defer close(doneCh)

	if response.StatusCode != http.StatusOK {
		_, _, err := lxdParseResponse(response)
		if err != nil {
			return nil, err
		}
	}

	// Handle the data
	body := response.Body
	if req.ProgressHandler != nil {
		body = &ioprogress.ProgressReader{
			ReadCloser: response.Body,
			Tracker: &ioprogress.ProgressTracker{
				Length: response.ContentLength,
				Handler: func(percent int64, speed int64) {
					req.ProgressHandler(ioprogress.ProgressData{Text: fmt.Sprintf("%d%% (%s/s)", percent, shared.GetByteSizeString(speed, 2))})
				},
			},
		}
	}

	size, err := io.Copy(req.BackupFile, body)
	if err != nil {
		return nil, err
	}

	resp := BackupFileResponse{}
	resp.Size = size

	return &resp, nil
}
func ( r * ProtocolLXD ) GetContainerBackupFile ( containerName string , name string , req * BackupFileRequest ) ( * BackupFileResponse , error ) { if ! r . HasExtension ( " " ) { return nil , fmt . Errorf ( " \" \" " ) } // Build the URL uri := fmt . Sprintf ( " " , r . httpHost , url . QueryEscape ( containerName ) , url . QueryEscape ( name ) ) if r . project != " " { uri += fmt . Sprintf ( " " , url . QueryEscape ( r . project ) ) } // Prepare the download request request , err := http . NewRequest ( " " , uri , nil ) if err != nil { return nil , err } if r . httpUserAgent != " " { request . Header . Set ( " " , r . httpUserAgent ) } // Start the request response , doneCh , err := cancel . CancelableDownload ( req . Canceler , r . http , request ) if err != nil { return nil , err } defer response . Body . Close ( ) defer close ( doneCh ) if response . StatusCode != http . StatusOK { _ , _ , err := lxdParseResponse ( response ) if err != nil { return nil , err } } // Handle the data body := response . Body if req . ProgressHandler != nil { body = & ioprogress . ProgressReader { ReadCloser : response . Body , Tracker : & ioprogress . ProgressTracker { Length : response . ContentLength , Handler : func ( percent int64 , speed int64 ) { req . ProgressHandler ( ioprogress . ProgressData { Text : fmt . Sprintf ( " " , percent , shared . GetByteSizeString ( speed , 2 ) ) } ) } , } , } } size , err := io . Copy ( req . BackupFile , body ) if err != nil { return nil , err } resp := BackupFileResponse { } resp . Size = size return & resp , nil }
// GetContainerBackupFile requests the container backup content
GetContainerBackupFile requests the container backup content