CP-18743: Make packer-build-xenserver support VIF configuration
Signed-off-by: kunm <kun.ma@citrix.com>
This commit is contained in:
parent
2183cb5869
commit
d1de461cdb
@ -18,11 +18,11 @@ type CommonConfig struct {
|
|||||||
Password string `mapstructure:"remote_password"`
|
Password string `mapstructure:"remote_password"`
|
||||||
HostIp string `mapstructure:"remote_host"`
|
HostIp string `mapstructure:"remote_host"`
|
||||||
|
|
||||||
VMName string `mapstructure:"vm_name"`
|
VMName string `mapstructure:"vm_name"`
|
||||||
VMDescription string `mapstructure:"vm_description"`
|
VMDescription string `mapstructure:"vm_description"`
|
||||||
SrName string `mapstructure:"sr_name"`
|
SrName string `mapstructure:"sr_name"`
|
||||||
FloppyFiles []string `mapstructure:"floppy_files"`
|
FloppyFiles []string `mapstructure:"floppy_files"`
|
||||||
NetworkName string `mapstructure:"network_name"`
|
NetworkNames map[string]string `mapstructure:"network_names"`
|
||||||
|
|
||||||
HostPortMin uint `mapstructure:"host_port_min"`
|
HostPortMin uint `mapstructure:"host_port_min"`
|
||||||
HostPortMax uint `mapstructure:"host_port_max"`
|
HostPortMax uint `mapstructure:"host_port_max"`
|
||||||
|
@ -100,7 +100,6 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error
|
|||||||
|
|
||||||
templates := map[string]*string{
|
templates := map[string]*string{
|
||||||
"clone_template": &self.config.CloneTemplate,
|
"clone_template": &self.config.CloneTemplate,
|
||||||
"network_name": &self.config.NetworkName,
|
|
||||||
"iso_checksum": &self.config.ISOChecksum,
|
"iso_checksum": &self.config.ISOChecksum,
|
||||||
"iso_checksum_type": &self.config.ISOChecksumType,
|
"iso_checksum_type": &self.config.ISOChecksumType,
|
||||||
"iso_url": &self.config.ISOUrl,
|
"iso_url": &self.config.ISOUrl,
|
||||||
|
@ -109,7 +109,7 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
|
|||||||
|
|
||||||
var network *xsclient.Network
|
var network *xsclient.Network
|
||||||
|
|
||||||
if config.NetworkName == "" {
|
if len(config.NetworkNames) == 0 {
|
||||||
// No network has be specified. Use the management interface
|
// No network has be specified. Use the management interface
|
||||||
network = new(xsclient.Network)
|
network = new(xsclient.Network)
|
||||||
network.Ref = ""
|
network.Ref = ""
|
||||||
@ -141,35 +141,39 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
|
|||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
_, err = instance.ConnectNetwork(network, "0")
|
||||||
// Look up the network by it's name label
|
|
||||||
|
|
||||||
networks, err := client.GetNetworkByNameLabel(config.NetworkName)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ui.Error(fmt.Sprintf("Error occured getting Network by name-label: %s", err.Error()))
|
ui.Say(err.Error())
|
||||||
return multistep.ActionHalt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
} else {
|
||||||
case len(networks) == 0:
|
// Look up each network by it's name label
|
||||||
ui.Error(fmt.Sprintf("Couldn't find a network with the specified name-label '%s'. Aborting.", config.NetworkName))
|
for i, networkNameLabel := range config.NetworkNames {
|
||||||
return multistep.ActionHalt
|
networks, err := client.GetNetworkByNameLabel(networkNameLabel)
|
||||||
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))
|
if err != nil {
|
||||||
return multistep.ActionHalt
|
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()
|
instanceId, err := instance.GetUuid()
|
||||||
|
@ -15,6 +15,13 @@
|
|||||||
"iso_checksum": "4ed6c56d365bd3ab12cd88b8a480f4a62e7c66d2",
|
"iso_checksum": "4ed6c56d365bd3ab12cd88b8a480f4a62e7c66d2",
|
||||||
"iso_checksum_type": "sha1",
|
"iso_checksum_type": "sha1",
|
||||||
"iso_url": "{{user `mirror`}}/6.6/isos/x86_64/CentOS-6.6-x86_64-minimal.iso",
|
"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",
|
"output_directory": "packer-centos-6.6-x86_64-xenserver",
|
||||||
"shutdown_command": "/sbin/halt",
|
"shutdown_command": "/sbin/halt",
|
||||||
"ssh_username": "root",
|
"ssh_username": "root",
|
||||||
|
Loading…
Reference in New Issue
Block a user