forked from xenserver/packer-plugin-xenserver
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add option to destroy vifs #43
Open
heindsight
wants to merge
4
commits into
ddelnano:main
Choose a base branch
from
sohonetlabs:destroy-vifs
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 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
feb8791
Added destroy vifs step
dongyuzheng 374a26c
Update destroy vifs implementation
heindsight 7635d3d
Merge branch 'master' of https://github.com/ddelnano/packer-plugin-xe…
heindsight 30400a4
Merge branch 'master' of https://github.com/ddelnano/packer-plugin-xe…
heindsight 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/packer-plugin-sdk/multistep" | ||
"github.com/hashicorp/packer-plugin-sdk/packer" | ||
) | ||
|
||
type StepDestroyVIFs struct{} | ||
|
||
func (self *StepDestroyVIFs) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { | ||
c := state.Get("client").(*Connection) | ||
config := state.Get("config").(Config) | ||
ui := state.Get("ui").(packer.Ui) | ||
|
||
if !config.DestroyVIFs { | ||
log.Printf("Not destroying VIFs") | ||
return multistep.ActionContinue | ||
} | ||
|
||
ui.Say("Step: Destroy VIFs") | ||
|
||
uuid := state.Get("instance_uuid").(string) | ||
instance, err := c.client.VM.GetByUUID(c.session, uuid) | ||
if err != nil { | ||
ui.Error(fmt.Sprintf("Unable to get VM from UUID '%s': %s", uuid, err.Error())) | ||
return multistep.ActionHalt | ||
} | ||
|
||
vifs, err := c.client.VM.GetVIFs(c.session, instance) | ||
if err != nil { | ||
ui.Error(fmt.Sprintf("Error getting VIFs: %s", err.Error())) | ||
return multistep.ActionHalt | ||
} | ||
|
||
for _, vif := range vifs { | ||
err = c.client.VIF.Destroy(c.session, vif) | ||
if err != nil { | ||
ui.Error(fmt.Sprintf("Error destroying VIF: %s", err.Error())) | ||
return multistep.ActionHalt | ||
} | ||
} | ||
|
||
return multistep.ActionContinue | ||
} | ||
|
||
func (self *StepDestroyVIFs) Cleanup(state multistep.StateBag) {} |
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
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
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.
@heindsight can you explain a scenario where having the VIFs remain hurts the template's reusability? I understand the general sentiment that it is unnecessary to include extra configuration, but I don't quite see where this could manifest to a concrete problem.
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.
@ddelnano to be honest, I have not encountered such a situation myself. I cherry picked this from another fork that we were previously using at Sohonet because we have a number of existing templates that use this option.
The main reason for originally using this option in our templates really is just to avoid including unnecessary extra configuration.
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.
Hello - I couldn't resist chiming in.
On the surface, it seems sloppy to leave a 10MB container that will never be used again. Or is there an example where it could be?
What will happen if it is left in place and ends up inside a template. Will we get TWO of these things when a VM is deployed from the template, and if so - will the "current" or new one be used correctly for deployment?
Or instead will a new deployment just overwrite the existing one?
How will a Windows VM react to a snapshot request with a drive like this hanging around?
Additionally, it seems wasteful - I know we live in an age where we can be sloppy with diskspace because you can get 1TB drive for $40 or so, so... who cares about soaking up 10MB on these things. But not all VMs run on cheap harddrives
In principal, it would seem to be best if temporary drives were really temporary and cleaned up after the fact. Garbage collection seems to be a good practice, whether in terms of RAM or disk space.
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.
@Roche-Mike this PR adds an option to remove virtual network interfaces from the the VM template. It has nothing to do with any 10MB temporary drive.
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.
@Roche-Mike as Heinrich mentioned, this should be unrelated to what you described. However, I am interested in what you are describing and it's something we should consider if the plugin is having the correct behavior. Can you please open a new issue with the relevant context so we can have a focused discussion on that behavior?