Skip to content
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

Allow clone_template to use uuid:// #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions builder/xenserver/iso/step_create_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,35 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
ui.Say("Step: Create Instance")

// Get the template to clone from
var template *xsclient.VM
var err error

vms, err := client.GetVMByNameLabel(config.CloneTemplate)
if len(config.CloneTemplate) >= 7 && config.CloneTemplate[:7] == "uuid://" {
templateUuid := config.CloneTemplate[7:]

switch {
case len(vms) == 0:
ui.Error(fmt.Sprintf("Couldn't find a template with the name-label '%s'. Aborting.", config.CloneTemplate))
return multistep.ActionHalt
case len(vms) > 1:
ui.Error(fmt.Sprintf("Found more than one template with the name '%s'. The name must be unique. Aborting.", config.CloneTemplate))
return multistep.ActionHalt
}
template, err = client.GetVMByUuid(templateUuid)
if err != nil {
ui.Error(fmt.Sprintf("Could not get template with UUID '%s': %s", templateUuid, err.Error()))
return multistep.ActionHalt
}
} else {
templates, err := client.GetVMByNameLabel(config.CloneTemplate)
if err != nil {
ui.Error(fmt.Sprintf("Error getting template: %s", err.Error()))
return multistep.ActionHalt
}

template := vms[0]
switch {
case len(templates) == 0:
ui.Error(fmt.Sprintf("Couldn't find a template with the name-label '%s'.", config.CloneTemplate))
return multistep.ActionHalt
case len(templates) > 1:
ui.Error(fmt.Sprintf("Found more than one template with the name '%s'. The name must be unique. Aborting.", config.CloneTemplate))
return multistep.ActionHalt
}

template = templates[0]
}

// Clone that VM template
instance, err := template.Clone(config.VMName)
Expand Down
3 changes: 2 additions & 1 deletion docs/builders/xenserver-iso.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ each category, the available options are alphabetized and described.
media", this is "other", but you can get _dramatic_ performance improvements
by setting this to the proper value. To view all available values for this
run `xe template-list`. Setting the correct value hints to XenServer how to
optimize the virtual hardware to work best with that operating system.
optimize the virtual hardware to work best with that operating system. Setting
this to a template's UUID is also acceptable: "uuid://c6a9dee0-0069-24a5-d45d-4a4101a9d7f4".

* `disk_size` (integer) - The size, in megabytes, of the hard disk to create
for the VM. By default, this is 40000 (about 40 GB).
Expand Down