-
Notifications
You must be signed in to change notification settings - Fork 74
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
[Issue 71] Adds convert_to_template option to proxmox builders #72
Conversation
…lone and iso configs
Hi @LethalServant, |
@LethalServant do you have any update on @carlpett's question? |
It should keep the default behaviour of converting into a template. ie. |
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.
I see this is indeed changing the default behavior and I figure that's not your intention as you mentioned in our previous comment.
builder/proxmox/common/config.go
Outdated
@@ -64,6 +64,7 @@ type Config struct { | |||
|
|||
TemplateName string `mapstructure:"template_name"` | |||
TemplateDescription string `mapstructure:"template_description"` | |||
ConvertToTemplate bool `mapstructure:"convert_to_template"` |
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.
The default of this configuration will always be false which will indeed change the default behavior of the builder. Also, in the prepare
method you're explicitly setting it to false as default.
If the intention is to not change the default behavior, the default should be true
. In this case, you can:
- Use Trilian, a custom type available in the SDK for this type of configuration
- Rename it to
skip_convert_to_template
that will skip converting to template when set to true. The default will be automatically false.
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.
@sylviamoss Thanks for the feedback, this should be resolved now.
builder/proxmox/common/builder.go
Outdated
coreSteps = append(coreSteps, &stepStopVM{}) | ||
|
||
if b.config.ConvertToTemplate { | ||
coreSteps = append(coreSteps, &stepConvertToTemplate{}) |
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.
I like better when we pass the configuration to the step and within the step is determined if it should be skipped or not based on the configuration. It makes it easier to log "Skipping ..." and keeps this step slice clean.
It's been two months, any update on this? Would love to have this functionality. |
Hi @LethalServant thanks for working to push this forward. We haven't had a chance to review this since you last updated. But I'm adding it to our planning board so we can give it some cycles next week. Quickly looking at the approach I don't know if I will be releasing a new version of the plugin today v1.1.0 to address #119. After that change we can work to get this change in. Thanks again for pushing this change forward and for sticking with us. |
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.
Hi @LethalServant,
First off, apologies for letting this PR open without activity for so long, let's get the ball rolling on this one and get this feature in!
I left a couple of comments on your code, I think the Trilean
is not necessary in the current state as you inverted the condition, if it can safely default to false
, we can keep it as a bool
, which simplifies the interactions with it later on.
Also the code is out of sync since it was untouched for a while, so you will unfortunately need to rebase on top of the current main if we want to merge this later.
Please let me know if you're interested in continuing this work, and if you need help also feel free to reach out, I'll surely be able to help.
Thanks!
TemplateDescription string `mapstructure:"template_description"` | ||
TemplateName string `mapstructure:"template_name"` | ||
TemplateDescription string `mapstructure:"template_description"` | ||
SkipConvertToTemplate config.Trilean `mapstructure:"skip_convert_to_template"` |
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.
If there a reason why this is a Trilean? If the intent is that this is false
by default, bool
would work this way, and this would simplify using the option
ui.Error(err.Error()) | ||
return multistep.ActionHalt | ||
} | ||
if !c.SkipConvertToTemplate.True() { |
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.
I think this can be inverted here since this is the last step here
if !c.SkipConvertToTemplate.True() { | |
if c.SkipConvertToTemplate { | |
ui.Say("Skipping VM template conversion") | |
return multistep.ActionContinue | |
} |
The rest of the code can be left unchanged if we do it this way
@@ -109,6 +110,9 @@ func TestBasicExampleFromDocsIsValid(t *testing.T) { | |||
if b.config.CloudInit != false { | |||
t.Errorf("Expected CloudInit to be false, got %t", b.config.CloudInit) | |||
} | |||
if b.config.SkipConvertToTemplate.False() { | |||
t.Errorf("Expected ConvertToTemplate to be true, got %t", b.config.SkipConvertToTemplate.True()) |
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 should be rephrased, also I suspect the error was introduced in the first draft, so the value does not match what the condition highlights.
} | ||
"template_description": "Fedora 29-1.2, generated on {{ isotime \"2006-01-02T15:04:05Z\" }}", | ||
"skip_convert_to_template": true | ||
} |
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.
The indentation is not consistent with the rest of the template here, the verbatim template being only indented with spaces.
|
||
var _ templateConverter = &proxmox.Client{} | ||
|
||
func (s *stepStopVM) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { |
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.
I wonder why this becomes a step on its own here, it seems that the step_convert_to_template
does this already, why not move the check after the VM is shutdown so we don't have to introduce another step?
For the record, I don't hate this change by itself, it's just that this brings more changes to this PR which makes the diff larger and harder to understand.
// the VM has been converted into a template, such as updating name and description, or | ||
// unmounting the installation ISO. | ||
type stepFinalizeTemplateConfig struct{} | ||
type stepFinalizeVMConfig struct{} |
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.
Since we can either produce a template or a VM, might I suggest renaming this step as stepFinalize
instead? Just to avoid confusion
@@ -11,7 +11,8 @@ import ( | |||
|
|||
type Artifact struct { | |||
builderID string | |||
templateID int | |||
vmID int | |||
isTemplate bool |
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.
While I don't think there's other possible types than VM and template, I would maybe suggest changing this to a string, and have an enumeration to the side.
Something like
type ArtifactType string
const (
TemplateArtifact ArtifactType = "Template"
VMArtifact ArtifactType = "VM"
)
[...]
type Artifact struct {
builderID string
artifactID int
artifactType ArtifactType
[...]
}
Doing it this way also makes it possible to inject this in the String()
and Destroy()
methods without needing conditionals.
coreSteps = append(coreSteps, &stepConvertToTemplate{}) | ||
|
||
coreSteps = append(coreSteps, &stepFinalizeVMConfig{}) | ||
coreSteps = append(coreSteps, &stepSuccess{}) |
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.
Is there a reason for this change? This might be me only but I don't find this more readable than the original way of defining the steps, and it complexifies the diff so I would consider leaving this change out of the current patchset.
} | ||
|
||
artifact := &Artifact{ | ||
builderID: b.id, | ||
templateID: tplID, | ||
vmID: vmRef.VmId(), | ||
isTemplate: !b.config.SkipConvertToTemplate.True(), |
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.
If we decide to keep it as a Trilean, this could be changed to
isTemplate: !b.config.SkipConvertToTemplate.True(), | |
isTemplate: b.config.SkipConvertToTemplate.False(), |
// Verify that the template_id was set properly, otherwise we didn't progress through the last step | ||
tplID, ok := state.Get("template_id").(int) | ||
// Get vmRef for vmid in artifact storage | ||
vmRef, ok := state.Get("vmRef").(*proxmox.VmRef) |
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.
To be sure, if the artifact is a template, do we still get the appropriate ID from the vmRef in state?
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.
Note: yes we do, the current way this is implemented is by writing vmRef.VmId()
to the state as template_id
, which is not necessary since the vmRef
is already part of the state.
Note: removed the |
The author of this PR hasn't had any GitHub activity in a year or two. Is there a path forward to merge this? |
checking in on this. Is it possible to merge in this feature? As I understand the current builder methods (ISO, and Clone) only allow you to create templates instead of going straight to a running VM? Im looking to have packer build out a functional VM from ISO instead of a template. Is this possible in the proxmox environment? Currently we have a functional process using Vsphere but I am currently exploring proxmox as an alternative. |
Would love to see this merged in for our current workflow. |
Hi @AnthonyTippy @tacoman @mfisher87, This looks pretty stale still, haven't heard of feedback from @LethalServant yet (to be fair to them, we waited a really long time for reviewing the code so there's definitely a lot of blame on us). If someone wants to pickup that PR and add contributions on top to address the comments (that will likely need to be in a separate PR to supersede this one) I posted in my review, that would be very appreciated for sure, please let us know and we'll make sure to review the changes with minimal delay this time around. |
I started working on this feature back around v1.0.4 so I think the code base has changed a lot and it would take some effort to get this back in mergeable state. Not sure when I'll be able to get to this, if someone else is in a better position to add this feature either by picking this up or starting from scratch, go for it. Cheers! |
Since this one was left aside by @LethalServant's admission, and since @mpywell has opened a PR to implement this one, which is nearing completion, I believe we can close this open PR and refer to #283 for further updates. Thanks @LethalServant for the original proposal and implementation, sorry it didn't get to the point where we could merge it, but hopefully the feature will be part of the plugin soon :) |
Adds
convert_to_template
bool option to proxmox-iso and proxmox-clone builders configuration.This gives the user more control over the machine image, whether it stays a VM or is converted to a VM Template.
The
convert_to_template
option is optional, and the default value isfalse
, resulting in the VM not being converted to a template.In practice the option is only need if the user wants the machine image to become a VM Template.
Tests:
Given working proxmox-iso and proxmox-clone packer file configurations, the following values were changed and run for each builder:
Closes #71