Commit d58a209b authored by Tom Hite's avatar Tom Hite

added network and disk driver options, also a source comment on the kickstart...

added network and disk driver options, also a source comment on the kickstart file in the docs (I can't find the original source).
parent 30d00402
...@@ -14,7 +14,24 @@ import ( ...@@ -14,7 +14,24 @@ import (
"time" "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 { type Builder struct {
config config config config
...@@ -48,6 +65,8 @@ type config struct { ...@@ -48,6 +65,8 @@ type config struct {
VNCPortMin uint `mapstructure:"vnc_port_min"` VNCPortMin uint `mapstructure:"vnc_port_min"`
VNCPortMax uint `mapstructure:"vnc_port_max"` VNCPortMax uint `mapstructure:"vnc_port_max"`
VMName string `mapstructure:"vm_name"` VMName string `mapstructure:"vm_name"`
NetDevice string `mapstructure:"net_device"`
DiskInterface string `mapstructure:"disk_interface"`
RawBootWait string `mapstructure:"boot_wait"` RawBootWait string `mapstructure:"boot_wait"`
RawSingleISOUrl string `mapstructure:"iso_url"` RawSingleISOUrl string `mapstructure:"iso_url"`
...@@ -135,6 +154,14 @@ func (b *Builder) Prepare(raws ...interface{}) error { ...@@ -135,6 +154,14 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b.config.Format = "qcow2" b.config.Format = "qcow2"
} }
if b.config.NetDevice == "" {
b.config.NetDevice = "virtio"
}
if b.config.DiskInterface == "" {
b.config.DiskInterface = "virtio"
}
// Errors // Errors
templates := map[string]*string{ templates := map[string]*string{
"http_directory": &b.config.HTTPDir, "http_directory": &b.config.HTTPDir,
...@@ -151,6 +178,8 @@ func (b *Builder) Prepare(raws ...interface{}) error { ...@@ -151,6 +178,8 @@ func (b *Builder) Prepare(raws ...interface{}) error {
"shutdown_timeout": &b.config.RawShutdownTimeout, "shutdown_timeout": &b.config.RawShutdownTimeout,
"ssh_wait_timeout": &b.config.RawSSHWaitTimeout, "ssh_wait_timeout": &b.config.RawSSHWaitTimeout,
"accelerator": &b.config.Accelerator, "accelerator": &b.config.Accelerator,
"net_device": &b.config.NetDevice,
"disk_interface": &b.config.DiskInterface,
} }
for n, ptr := range templates { for n, ptr := range templates {
...@@ -198,6 +227,16 @@ func (b *Builder) Prepare(raws ...interface{}) error { ...@@ -198,6 +227,16 @@ func (b *Builder) Prepare(raws ...interface{}) error {
errs, errors.New("invalid format, only 'kvm' or 'xen' are allowed")) 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 { if b.config.HTTPPortMin > b.config.HTTPPortMax {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, errors.New("http_port_min must be less than http_port_max")) errs, errors.New("http_port_min must be less than http_port_max"))
......
...@@ -65,9 +65,9 @@ func (s *stepRun) runVM( ...@@ -65,9 +65,9 @@ func (s *stepRun) runVM(
"-name", vmName, "-name", vmName,
"-machine", fmt.Sprintf("type=pc-1.0,accel=%s", config.Accelerator), "-machine", fmt.Sprintf("type=pc-1.0,accel=%s", config.Accelerator),
"-display", guiArgument, "-display", guiArgument,
"-net", "nic,model=virtio", "-net", fmt.Sprintf("nic,model=%s", config.NetDevice),
"-net", "user", "-net", "user",
"-drive", fmt.Sprintf("file=%s,if=virtio", imgPath), "-drive", fmt.Sprintf("file=%s,if=%s", imgPath, config.DiskInterface),
"-cdrom", isoPath, "-cdrom", isoPath,
"-boot", bootDrive, "-boot", bootDrive,
"-m", "512m", "-m", "512m",
......
...@@ -47,6 +47,8 @@ paths to files, URLS for ISOs and checksums. ...@@ -47,6 +47,8 @@ paths to files, URLS for ISOs and checksums.
"ssh_port": 22, "ssh_port": 22,
"ssh_wait_timeout": "90m", "ssh_wait_timeout": "90m",
"vm_name": "tdhtest", "vm_name": "tdhtest",
"net_device": "virtio",
"disk_interface": "virtio",
"boot_command": "boot_command":
[ [
"<tab><wait>", "<tab><wait>",
...@@ -57,8 +59,9 @@ paths to files, URLS for ISOs and checksums. ...@@ -57,8 +59,9 @@ paths to files, URLS for ISOs and checksums.
} }
</pre> </pre>
The following is a sample CentOS kickstart file you should place in the The following is a working CentOS 6.x kickstart file adapted from
ttp_files directory with the name centos6-ks.cfg: an unknown source. You would place such a file in the http_files
directory with the name centos6-ks.cfg:
<pre class="prettyprint"> <pre class="prettyprint">
text text
...@@ -172,6 +175,11 @@ Optional: ...@@ -172,6 +175,11 @@ Optional:
* `disk_size` (int) - The size, in megabytes, of the hard disk to create * `disk_size` (int) - The size, in megabytes, of the hard disk to create
for the VM. By default, this is 40000 (40 GB). 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 * `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 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 most useful for unattended Windows installs, which look for an
...@@ -212,6 +220,12 @@ Optional: ...@@ -212,6 +220,12 @@ Optional:
must point to the same file (same checksum). By default this is empty 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. 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 * `output_directory` (string) - This is the path to the directory where the
resulting virtual machine will be created. This may be relative or absolute. resulting virtual machine will be created. This may be relative or absolute.
If relative, the path is relative to the working directory when `packer` If relative, the path is relative to the working directory when `packer`
...@@ -251,8 +265,6 @@ Optional: ...@@ -251,8 +265,6 @@ Optional:
available. By default this is "20m", or 20 minutes. Note that this should 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. 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 * `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 the new virtual machine, without the file extension. By default this is
"packer-BUILDNAME", where "BUILDNAME" is the name of the build. "packer-BUILDNAME", where "BUILDNAME" is the name of the build.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment