added network and disk driver options, also a source comment on the kickstart file in the docs (I can't find the original source).

This commit is contained in:
Tom Hite 2013-09-03 10:08:04 -05:00
parent 30d004022e
commit d58a209b73
3 changed files with 58 additions and 7 deletions

View File

@ -14,7 +14,24 @@ import (
"time"
)
const BuilderId = "tdhite.qemu"
const BuilderId = "transcend.qemu"
var netDevice = map[string]bool{
"ne2k_pci": true,
"i82551": true,
"i82557b": true,
"i82559er": true,
"rtl8139": true,
"e1000": true,
"pcnet": true,
"virtio": true,
}
var diskInterface = map[string]bool{
"ide": true,
"scsi": true,
"virtio": true,
}
type Builder struct {
config config
@ -48,6 +65,8 @@ type config struct {
VNCPortMin uint `mapstructure:"vnc_port_min"`
VNCPortMax uint `mapstructure:"vnc_port_max"`
VMName string `mapstructure:"vm_name"`
NetDevice string `mapstructure:"net_device"`
DiskInterface string `mapstructure:"disk_interface"`
RawBootWait string `mapstructure:"boot_wait"`
RawSingleISOUrl string `mapstructure:"iso_url"`
@ -135,6 +154,14 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b.config.Format = "qcow2"
}
if b.config.NetDevice == "" {
b.config.NetDevice = "virtio"
}
if b.config.DiskInterface == "" {
b.config.DiskInterface = "virtio"
}
// Errors
templates := map[string]*string{
"http_directory": &b.config.HTTPDir,
@ -151,6 +178,8 @@ func (b *Builder) Prepare(raws ...interface{}) error {
"shutdown_timeout": &b.config.RawShutdownTimeout,
"ssh_wait_timeout": &b.config.RawSSHWaitTimeout,
"accelerator": &b.config.Accelerator,
"net_device": &b.config.NetDevice,
"disk_interface": &b.config.DiskInterface,
}
for n, ptr := range templates {
@ -198,6 +227,16 @@ func (b *Builder) Prepare(raws ...interface{}) error {
errs, errors.New("invalid format, only 'kvm' or 'xen' are allowed"))
}
if _, ok := netDevice[b.config.NetDevice]; !ok {
errs = packer.MultiErrorAppend(
errs, errors.New("unrecognized network device type"))
}
if _, ok := diskInterface[b.config.DiskInterface]; !ok {
errs = packer.MultiErrorAppend(
errs, errors.New("unrecognized disk interface type"))
}
if b.config.HTTPPortMin > b.config.HTTPPortMax {
errs = packer.MultiErrorAppend(
errs, errors.New("http_port_min must be less than http_port_max"))

View File

@ -65,9 +65,9 @@ func (s *stepRun) runVM(
"-name", vmName,
"-machine", fmt.Sprintf("type=pc-1.0,accel=%s", config.Accelerator),
"-display", guiArgument,
"-net", "nic,model=virtio",
"-net", fmt.Sprintf("nic,model=%s", config.NetDevice),
"-net", "user",
"-drive", fmt.Sprintf("file=%s,if=virtio", imgPath),
"-drive", fmt.Sprintf("file=%s,if=%s", imgPath, config.DiskInterface),
"-cdrom", isoPath,
"-boot", bootDrive,
"-m", "512m",

View File

@ -47,6 +47,8 @@ paths to files, URLS for ISOs and checksums.
"ssh_port": 22,
"ssh_wait_timeout": "90m",
"vm_name": "tdhtest",
"net_device": "virtio",
"disk_interface": "virtio",
"boot_command":
[
"<tab><wait>",
@ -57,8 +59,9 @@ paths to files, URLS for ISOs and checksums.
}
</pre>
The following is a sample CentOS kickstart file you should place in the
ttp_files directory with the name centos6-ks.cfg:
The following is a working CentOS 6.x kickstart file adapted from
an unknown source. You would place such a file in the http_files
directory with the name centos6-ks.cfg:
<pre class="prettyprint">
text
@ -172,6 +175,11 @@ Optional:
* `disk_size` (int) - The size, in megabytes, of the hard disk to create
for the VM. By default, this is 40000 (40 GB).
* `disk_interface` (string) - The interface to use for the disk. Allowed
values include any of "ide," "scsi" or "virtio." Note also that any boot
commands or kickstart type scripts must have proper adjustments for
resulting device names. The Qemu builder uses "virtio" by default.
* `floppy_files` (array of strings) - A list of files to put onto a floppy
disk that is attached when the VM is booted for the first time. This is
most useful for unattended Windows installs, which look for an
@ -212,6 +220,12 @@ Optional:
must point to the same file (same checksum). By default this is empty
and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified.
* `net_device` (string) - The driver to use for the network interface. Allowed
values "ne2k_pci," "i82551," "i82557b," "i82559er," "rtl8139," "e1000,"
"pcnet" or "virtio." The Qemu builder uses "virtio" by default.
* `qemuargs` (array of strings reserved for future use).
* `output_directory` (string) - This is the path to the directory where the
resulting virtual machine will be created. This may be relative or absolute.
If relative, the path is relative to the working directory when `packer`
@ -251,8 +265,6 @@ Optional:
available. By default this is "20m", or 20 minutes. Note that this should
be quite long since the timer begins as soon as the virtual machine is booted.
* `qemuargs` (array of strings reserved for future use).
* `vm_name` (string) - This is the name of the image (QCOW2 or IMG) file for
the new virtual machine, without the file extension. By default this is
"packer-BUILDNAME", where "BUILDNAME" is the name of the build.