-
Notifications
You must be signed in to change notification settings - Fork 930
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
Require destination name when copying an instance on the same server #12447
Conversation
This looks like it needs some doc updates to |
lxc/copy.go
Outdated
@@ -153,6 +154,9 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR | |||
return fmt.Errorf(i18n.G("--instance-only can't be passed when the source is a snapshot")) | |||
} | |||
|
|||
// Remove snapshot suffix from destination name. |
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.
This comment say what but doesn't explain the why.
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.
Thanks for this one.
Snapshot suffix is removed to ensure consistency when copying/moving an instance (or snapshot) to a different remote (lxc move c1 remote2:
or lxc move c1/snap0 remote2:
).
However, I missed the fact, that this will trim the suffix even if the user provides the snapshot name in the destination name.
For example, the following commands produced the same error, although they should not:
lxc copy c1/snap0 c1/snap1
lxc copy c1/snap0 c1
# Error: Failed creating instance record: Add instance info to the database: This "instances" entry already exists`
Now, the snapshot name is trimmed only when destName is set from the source.
A bit unrelated, but is there a reason we do not output the instance name in the above error? (something like Database entry for instance "c1" already exists
)
Signed-off-by: Din Music <din.music@canonical.com>
Signed-off-by: Din Music <din.music@canonical.com>
1c9a4d1
to
48b37a7
Compare
@ru-fu I've checked the docs and to me everything seems up to date. It is most likely that the PR title is misleading. This PR requires the destination name to be provided if remote is not specified, as the command would fail anyway because the instance with that name already exists.
And it fixes the situation where an instance is created from a snapshot on a different remote:
The above command would previously fail with We had some code related to determining the generated instance name, which is no longer being used. To me it seems that |
OK, great! So |
I've double checked and it is working |
// If the instance is being copied to a different remote and no destination name is | ||
// specified, use the source name with snapshot suffix trimmed (in case a new instance | ||
// is being created from a snapshot). | ||
if destName == "" && destResource != "" && c.flagTarget == "" { |
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.
Do we need to consider copying a snapshot with --target specified too?
Removes unused code that determines generated name on copy or move (using copy).
It requires destination name to be provided, with only exception being when moving an instance to another remote (for example:
lxc move c1 remote2:
). In such case, the destination name is set to the source name.Fixes #12338