-
Notifications
You must be signed in to change notification settings - Fork 937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storage: Attach VM snapshots as disk devices #14930
Open
MggMuggins
wants to merge
10
commits into
canonical:main
Choose a base branch
from
MggMuggins:snapshot-disk-devices
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b6ae165
api: Update instance_root_volume_attachment
MggMuggins bd6b834
lxd/device: Attach VM snapshots as disk devices
MggMuggins eba299a
lxd/device: Mount snapshot disks readonly
MggMuggins 39d77c8
lxc: Support attach/detach snapshot disk devices
MggMuggins 26099cc
doc/howto/storage_volumes: VM snapshot disk devices
MggMuggins dc77ece
doc/reference/devices_disk: Storage volume update
MggMuggins dec6fe4
lxd/storage_volume: Factor volume attach arg parsing
MggMuggins 8c66652
lxd/storage: Disambiguate snapshots from parent volumes
MggMuggins 7cf96ef
doc: Update metadata
MggMuggins 16abd2c
i18n: Update translations.
MggMuggins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MggMuggins marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,17 @@ func parseVolume(defaultType string, name string) (volName string, volType strin | |
return volName, volType | ||
} | ||
|
||
func parseVolumeSnapshot(defaultType string, name string) (volName string, volType string, snapshot string) { | ||
volName, volType = parseVolume(defaultType, name) | ||
|
||
parts := strings.SplitN(volName, "/", 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. strings.Cut would also be an option here |
||
if len(parts) == 2 { | ||
volName, snapshot = parts[0], parts[1] | ||
} | ||
|
||
return volName, volType, snapshot | ||
} | ||
|
||
func (c *cmdStorageVolume) command() *cobra.Command { | ||
cmd := &cobra.Command{} | ||
cmd.Use = usage("volume") | ||
|
@@ -164,7 +175,7 @@ type cmdStorageVolumeAttach struct { | |
|
||
func (c *cmdStorageVolumeAttach) command() *cobra.Command { | ||
cmd := &cobra.Command{} | ||
cmd.Use = usage("attach", i18n.G("[<remote>:]<pool> [<type>/]<volume> <instance> [<device name>] [<path>]")) | ||
cmd.Use = usage("attach", i18n.G("[<remote>:]<pool> [<type>/]<volume>[/<snapshot>] <instance> [<device name>] [<path>]")) | ||
cmd.Short = i18n.G("Attach new storage volumes to instances") | ||
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G( | ||
`Attach new storage volumes to instances | ||
|
@@ -211,7 +222,7 @@ func (c *cmdStorageVolumeAttach) run(cmd *cobra.Command, args []string) error { | |
return errors.New(i18n.G("Missing pool name")) | ||
} | ||
|
||
volName, volType := parseVolume("custom", args[1]) | ||
volName, volType, snapshot := parseVolumeSnapshot("custom", args[1]) | ||
if volType != "custom" && volType != "virtual-machine" { | ||
return errors.New(i18n.G(`Only "custom" and "virtual-machine" volumes can be attached to instances`)) | ||
} | ||
|
@@ -268,6 +279,10 @@ func (c *cmdStorageVolumeAttach) run(cmd *cobra.Command, args []string) error { | |
device["source.type"] = volType | ||
} | ||
|
||
if snapshot != "" { | ||
device["source.snapshot"] = snapshot | ||
} | ||
|
||
// Add the device to the instance | ||
err = instanceDeviceAdd(resource.server, args[2], devName, device) | ||
if err != nil { | ||
|
@@ -286,7 +301,7 @@ type cmdStorageVolumeAttachProfile struct { | |
|
||
func (c *cmdStorageVolumeAttachProfile) command() *cobra.Command { | ||
cmd := &cobra.Command{} | ||
cmd.Use = usage("attach-profile", i18n.G("[<remote:>]<pool> [<type>/]<volume> <profile> [<device name>] [<path>]")) | ||
cmd.Use = usage("attach-profile", i18n.G("[<remote:>]<pool> [<type>/]<volume>[/<snapshot>] <profile> [<device name>] [<path>]")) | ||
cmd.Short = i18n.G("Attach new storage volumes to profiles") | ||
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G( | ||
`Attach new storage volumes to profiles | ||
|
@@ -348,7 +363,7 @@ func (c *cmdStorageVolumeAttachProfile) run(cmd *cobra.Command, args []string) e | |
devPath = args[4] | ||
} | ||
|
||
volName, volType := parseVolume("custom", args[1]) | ||
volName, volType, snapshot := parseVolumeSnapshot("custom", args[1]) | ||
if volType != "custom" && volType != "virtual-machine" { | ||
return errors.New(i18n.G(`Only "custom" and "virtual-machine" volumes can be attached to profiles`)) | ||
} | ||
|
@@ -376,6 +391,10 @@ func (c *cmdStorageVolumeAttachProfile) run(cmd *cobra.Command, args []string) e | |
device["source.type"] = volType | ||
} | ||
|
||
if snapshot != "" { | ||
device["source.snapshot"] = snapshot | ||
} | ||
|
||
// Add the device to the instance | ||
err = profileDeviceAdd(resource.server, args[2], devName, device) | ||
if err != nil { | ||
|
@@ -817,7 +836,7 @@ type cmdStorageVolumeDetach struct { | |
|
||
func (c *cmdStorageVolumeDetach) command() *cobra.Command { | ||
cmd := &cobra.Command{} | ||
cmd.Use = usage("detach", i18n.G("[<remote>:]<pool> [<type>/]<volume> <instance> [<device name>]")) | ||
cmd.Use = usage("detach", i18n.G("[<remote>:]<pool> [<type>/]<volume>[/<snapshot>] <instance> [<device name>]")) | ||
cmd.Short = i18n.G("Detach storage volumes from instances") | ||
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G( | ||
`Detach storage volumes from instances`)) | ||
|
@@ -874,7 +893,7 @@ func (c *cmdStorageVolumeDetach) run(cmd *cobra.Command, args []string) error { | |
return err | ||
} | ||
|
||
volName, volType := parseVolume("custom", args[1]) | ||
volName, volType, snapshot := parseVolumeSnapshot("custom", args[1]) | ||
|
||
// Find the device | ||
if devName == "" { | ||
|
@@ -884,7 +903,7 @@ func (c *cmdStorageVolumeDetach) run(cmd *cobra.Command, args []string) error { | |
sourceType = d["source.type"] | ||
} | ||
|
||
if d["type"] == "disk" && d["pool"] == resource.name && volType == sourceType && volName == d["source"] { | ||
if d["type"] == "disk" && d["pool"] == resource.name && volType == sourceType && volName == d["source"] && snapshot == d["source.snapshot"] { | ||
if devName != "" { | ||
return errors.New(i18n.G("More than one device matches, specify the device name")) | ||
} | ||
|
@@ -922,7 +941,7 @@ type cmdStorageVolumeDetachProfile struct { | |
|
||
func (c *cmdStorageVolumeDetachProfile) command() *cobra.Command { | ||
cmd := &cobra.Command{} | ||
cmd.Use = usage("detach-profile", i18n.G("[<remote:>]<pool> [<type>/]<volume> <profile> [<device name>]")) | ||
cmd.Use = usage("detach-profile", i18n.G("[<remote:>]<pool> [<type>/]<volume>[/<snapshot>] <profile> [<device name>]")) | ||
cmd.Short = i18n.G("Detach storage volumes from profiles") | ||
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G( | ||
`Detach storage volumes from profiles`)) | ||
|
@@ -978,7 +997,7 @@ func (c *cmdStorageVolumeDetachProfile) run(cmd *cobra.Command, args []string) e | |
return err | ||
} | ||
|
||
volName, volType := parseVolume("custom", args[1]) | ||
volName, volType, snapshot := parseVolumeSnapshot("custom", args[1]) | ||
|
||
// Find the device | ||
if devName == "" { | ||
|
@@ -988,7 +1007,7 @@ func (c *cmdStorageVolumeDetachProfile) run(cmd *cobra.Command, args []string) e | |
sourceType = d["source.type"] | ||
} | ||
|
||
if d["type"] == "disk" && d["pool"] == resource.name && volType == sourceType && volName == d["source"] { | ||
if d["type"] == "disk" && d["pool"] == resource.name && volType == sourceType && volName == d["source"] && snapshot == d["source.snapshot"] { | ||
if devName != "" { | ||
return errors.New(i18n.G("More than one device matches, specify the device name")) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MggMuggins shall we rename this to
vm_root_volume_attachment
as my understanding is that we dont support containers yet, and we dont plan to before LXD 6.3 is released?