diff --git a/builder/xenserver/common/common_config.go b/builder/xenserver/common/common_config.go index 0c644c0..f505705 100644 --- a/builder/xenserver/common/common_config.go +++ b/builder/xenserver/common/common_config.go @@ -18,11 +18,11 @@ type CommonConfig struct { Password string `mapstructure:"remote_password"` HostIp string `mapstructure:"remote_host"` - VMName string `mapstructure:"vm_name"` - VMDescription string `mapstructure:"vm_description"` - SrName string `mapstructure:"sr_name"` - FloppyFiles []string `mapstructure:"floppy_files"` - NetworkName string `mapstructure:"network_name"` + VMName string `mapstructure:"vm_name"` + VMDescription string `mapstructure:"vm_description"` + SrName string `mapstructure:"sr_name"` + FloppyFiles []string `mapstructure:"floppy_files"` + NetworkNames map[string]string `mapstructure:"network_names"` HostPortMin uint `mapstructure:"host_port_min"` HostPortMax uint `mapstructure:"host_port_max"` diff --git a/builder/xenserver/iso/builder.go b/builder/xenserver/iso/builder.go index b40b73c..4276cd0 100644 --- a/builder/xenserver/iso/builder.go +++ b/builder/xenserver/iso/builder.go @@ -100,7 +100,6 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error templates := map[string]*string{ "clone_template": &self.config.CloneTemplate, - "network_name": &self.config.NetworkName, "iso_checksum": &self.config.ISOChecksum, "iso_checksum_type": &self.config.ISOChecksumType, "iso_url": &self.config.ISOUrl, diff --git a/builder/xenserver/iso/step_create_instance.go b/builder/xenserver/iso/step_create_instance.go index 8a0362b..a973af4 100644 --- a/builder/xenserver/iso/step_create_instance.go +++ b/builder/xenserver/iso/step_create_instance.go @@ -109,7 +109,7 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi var network *xsclient.Network - if config.NetworkName == "" { + if len(config.NetworkNames) == 0 { // No network has be specified. Use the management interface network = new(xsclient.Network) network.Ref = "" @@ -141,35 +141,39 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi return multistep.ActionHalt } - } else { - // Look up the network by it's name label - - networks, err := client.GetNetworkByNameLabel(config.NetworkName) + _, err = instance.ConnectNetwork(network, "0") if err != nil { - ui.Error(fmt.Sprintf("Error occured getting Network by name-label: %s", err.Error())) - return multistep.ActionHalt + ui.Say(err.Error()) } - switch { - case len(networks) == 0: - ui.Error(fmt.Sprintf("Couldn't find a network with the specified name-label '%s'. Aborting.", config.NetworkName)) - return multistep.ActionHalt - case len(networks) > 1: - ui.Error(fmt.Sprintf("Found more than one network with the name '%s'. The name must be unique. Aborting.", config.NetworkName)) - return multistep.ActionHalt + } else { + // Look up each network by it's name label + for i, networkNameLabel := range config.NetworkNames { + networks, err := client.GetNetworkByNameLabel(networkNameLabel) + + if err != nil { + ui.Error(fmt.Sprintf("Error occured getting Network by name-label: %s", err.Error())) + return multistep.ActionHalt + } + + switch { + case len(networks) == 0: + ui.Error(fmt.Sprintf("Couldn't find a network with the specified name-label '%s'. Aborting.", networkNameLabel)) + return multistep.ActionHalt + case len(networks) > 1: + ui.Error(fmt.Sprintf("Found more than one network with the name '%s'. The name must be unique. Aborting.", networkNameLabel)) + return multistep.ActionHalt + } + + //we need the VIF index string + vifIndexString := fmt.Sprintf("%d", i) + _, err = instance.ConnectNetwork(networks[0], vifIndexString) + + if err != nil { + ui.Say(err.Error()) + } } - - network = networks[0] - } - - if err != nil { - ui.Say(err.Error()) - } - _, err = instance.ConnectNetwork(network, "0") - - if err != nil { - ui.Say(err.Error()) } instanceId, err := instance.GetUuid() diff --git a/examples/centos-6.6.json b/examples/centos-6.6.json index 75d8d22..8eecfc7 100644 --- a/examples/centos-6.6.json +++ b/examples/centos-6.6.json @@ -15,6 +15,13 @@ "iso_checksum": "4ed6c56d365bd3ab12cd88b8a480f4a62e7c66d2", "iso_checksum_type": "sha1", "iso_url": "{{user `mirror`}}/6.6/isos/x86_64/CentOS-6.6-x86_64-minimal.iso", + "vm_other_config": { + "conversionvm":"true" + }, + "network_names": [ + "Host internal management network", + "Pool-wide network associated with eth0" + ], "output_directory": "packer-centos-6.6-x86_64-xenserver", "shutdown_command": "/sbin/halt", "ssh_username": "root",