MCPcopy
hub / github.com/lxc/incus / CreateStoragePoolBucketFromBackup

Method CreateStoragePoolBucketFromBackup

client/incus_storage_buckets.go:576–626  ·  view source on GitHub ↗

CreateStoragePoolBucketFromBackup creates a new storage bucket from a backup.

(pool string, args StoragePoolBucketBackupArgs)

Source from the content-addressed store, hash-verified

574
575// CreateStoragePoolBucketFromBackup creates a new storage bucket from a backup.
576func (r *ProtocolIncus) CreateStoragePoolBucketFromBackup(pool string, args StoragePoolBucketBackupArgs) (Operation, error) {
577 if !r.HasExtension("storage_bucket_backup") {
578 return nil, errors.New(`The server is missing the required "custom_volume_backup" API extension`)
579 }
580
581 path := fmt.Sprintf("/storage-pools/%s/buckets", url.PathEscape(pool))
582
583 // Prepare the HTTP request.
584 reqURL, err := r.setQueryAttributes(fmt.Sprintf("%s/1.0%s", r.httpBaseURL.String(), path))
585 if err != nil {
586 return nil, err
587 }
588
589 req, err := http.NewRequest("POST", reqURL, args.BackupFile)
590 if err != nil {
591 return nil, err
592 }
593
594 req.Header.Set("Content-Type", "application/octet-stream")
595
596 if args.Name != "" {
597 req.Header.Set("X-Incus-name", args.Name)
598 }
599
600 // Send the request.
601 resp, err := r.DoHTTP(req)
602 if err != nil {
603 return nil, err
604 }
605
606 defer logger.WarnOnError(resp.Body.Close, "Failed to close response body")
607
608 // Handle errors.
609 response, _, err := incusParseResponse(resp)
610 if err != nil {
611 return nil, err
612 }
613
614 respOperation, err := response.MetadataAsOperation()
615 if err != nil {
616 return nil, err
617 }
618
619 op := operation{
620 Operation: *respOperation,
621 r: r,
622 chActive: make(chan bool),
623 }
624
625 return &op, nil
626}

Callers

nothing calls this directly

Calls 8

HasExtensionMethod · 0.95
setQueryAttributesMethod · 0.95
DoHTTPMethod · 0.95
WarnOnErrorFunction · 0.92
incusParseResponseFunction · 0.85
MetadataAsOperationMethod · 0.80
StringMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected