mirror of
https://github.com/lxc/incus.git
synced 2026-02-05 09:46:19 +01:00
client: Allow config/device override on backup import
Signed-off-by: Helder Ardachnikoff Gomes <helder.versatti@gmail.com>
This commit is contained in:
committed by
Stéphane Graber
parent
7631bb682e
commit
1aca1e8fa9
@@ -522,7 +522,7 @@ func (r *ProtocolIncus) CreateInstanceFromBackup(args InstanceBackupArgs) (Opera
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if args.PoolName == "" && args.Name == "" {
|
||||
if args.PoolName == "" && args.Name == "" && args.Config == nil && args.Devices == nil {
|
||||
// Send the request
|
||||
op, _, err := r.queryOperation("POST", path, args.BackupFile, "")
|
||||
if err != nil {
|
||||
@@ -540,6 +540,10 @@ func (r *ProtocolIncus) CreateInstanceFromBackup(args InstanceBackupArgs) (Opera
|
||||
return nil, errors.New(`The server is missing the required "backup_override_name" API extension`)
|
||||
}
|
||||
|
||||
if (args.Config != nil || args.Devices != nil) && !r.HasExtension("backup_override_config") {
|
||||
return nil, errors.New(`The server is missing the required "backup_override_config" API extension`)
|
||||
}
|
||||
|
||||
// Prepare the HTTP request
|
||||
reqURL, err := r.setQueryAttributes(fmt.Sprintf("%s/1.0%s", r.httpBaseURL.String(), path))
|
||||
if err != nil {
|
||||
@@ -561,6 +565,16 @@ func (r *ProtocolIncus) CreateInstanceFromBackup(args InstanceBackupArgs) (Opera
|
||||
req.Header.Set("X-Incus-name", args.Name)
|
||||
}
|
||||
|
||||
if args.Config != nil {
|
||||
configOverride := strings.Join(args.Config, " ")
|
||||
req.Header.Set("X-Incus-config", configOverride)
|
||||
}
|
||||
|
||||
if args.Devices != nil {
|
||||
devicesOverride := strings.Join(args.Devices, " ")
|
||||
req.Header.Set("X-Incus-devices", devicesOverride)
|
||||
}
|
||||
|
||||
// Send the request
|
||||
resp, err := r.DoHTTP(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -585,6 +585,12 @@ type InstanceBackupArgs struct {
|
||||
|
||||
// Name to import backup as
|
||||
Name string
|
||||
|
||||
// Config overrides.
|
||||
Config []string
|
||||
|
||||
// Device overrides.
|
||||
Devices []string
|
||||
}
|
||||
|
||||
// The InstanceCopyArgs struct is used to pass additional options during instance copy.
|
||||
|
||||
Reference in New Issue
Block a user