aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libvirt/disk_def.go15
-rw-r--r--libvirt/disk_def_test.go10
-rw-r--r--libvirt/resource_libvirt_domain.go33
-rw-r--r--libvirt/resource_libvirt_domain_test.go15
-rw-r--r--libvirt/testdata/tcl.isobin0 -> 16834560 bytes
-rwxr-xr-xtravis/setup-guest3
-rw-r--r--website/docs/r/domain.html.markdown8
7 files changed, 49 insertions, 35 deletions
diff --git a/libvirt/disk_def.go b/libvirt/disk_def.go
index f4e4e86a..6e4cceea 100644
--- a/libvirt/disk_def.go
+++ b/libvirt/disk_def.go
@@ -24,21 +24,6 @@ func newDefDisk(i int) libvirtxml.DomainDisk {
}
}
-func newCDROM() libvirtxml.DomainDisk {
- return libvirtxml.DomainDisk{
- Type: "file",
- Device: "cdrom",
- Target: &libvirtxml.DomainDiskTarget{
- Dev: "hda",
- Bus: "ide",
- },
- Driver: &libvirtxml.DomainDiskDriver{
- Name: "qemu",
- Type: "raw",
- },
- }
-}
-
func randomWWN(strlen int) string {
const chars = "abcdef0123456789"
result := make([]byte, strlen)
diff --git a/libvirt/disk_def_test.go b/libvirt/disk_def_test.go
index a6184cc6..d13d26d8 100644
--- a/libvirt/disk_def_test.go
+++ b/libvirt/disk_def_test.go
@@ -21,13 +21,3 @@ func TestDefaultDiskMarshall(t *testing.T) {
t.Fatalf("could not marshall this:\n%s", spew.Sdump(b))
}
}
-
-func TestDefaultCDROMMarshall(t *testing.T) {
- b := newCDROM()
- buf := new(bytes.Buffer)
- enc := xml.NewEncoder(buf)
- enc.Indent(" ", " ")
- if err := enc.Encode(b); err != nil {
- t.Fatalf("could not marshall this:\n%s", spew.Sdump(b))
- }
-}
diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go
index 95a7b7fe..95ac6c52 100644
--- a/libvirt/resource_libvirt_domain.go
+++ b/libvirt/resource_libvirt_domain.go
@@ -450,6 +450,24 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error
if !strings.HasSuffix(url.Path, ".qcow2") {
disk.Driver.Type = "raw"
}
+ } else if _, ok := diskMap["file"].(string); ok {
+ // support for local disks, e.g. CDs
+ disk.Type = "file"
+ disk.Source = &libvirtxml.DomainDiskSource{
+ File: diskMap["file"].(string),
+ }
+
+ if strings.HasSuffix(diskMap["file"].(string), ".iso") {
+ disk.Device = "cdrom"
+ disk.Target = &libvirtxml.DomainDiskTarget{
+ Dev: "hda",
+ Bus: "ide",
+ }
+ disk.Driver = &libvirtxml.DomainDiskDriver{
+ Name: "qemu",
+ Type: "raw",
+ }
+ }
}
disks = append(disks, disk)
@@ -899,7 +917,10 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error {
// Emulator is the same as the default don't set it in domainDef
// or it will show as changed
d.Set("emulator", domainDef.Devices.Emulator)
- var disks []map[string]interface{}
+ var (
+ disks []map[string]interface{}
+ disk map[string]interface{}
+ )
for _, diskDef := range domainDef.Devices.Disks {
// network drives do not have a volume associated
if diskDef.Type == "network" {
@@ -914,10 +935,14 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
- disk := map[string]interface{}{
+ disk = map[string]interface{}{
"url": url.String(),
}
disks = append(disks, disk)
+ } else if diskDef.Device == "cdrom" {
+ disk = map[string]interface{}{
+ "file": diskDef.Source.File,
+ }
} else {
var virVol *libvirt.StorageVol
if len(diskDef.Source.File) > 0 {
@@ -942,11 +967,11 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error retrieving volume for disk: %s", err)
}
- disk := map[string]interface{}{
+ disk = map[string]interface{}{
"volume_id": virVolKey,
}
- disks = append(disks, disk)
}
+ disks = append(disks, disk)
}
d.Set("disks", disks)
var filesystems []map[string]interface{}
diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go
index 47c99ef5..43ce2478 100644
--- a/libvirt/resource_libvirt_domain_test.go
+++ b/libvirt/resource_libvirt_domain_test.go
@@ -290,9 +290,15 @@ func TestAccLibvirtDomainKernelInitrdCmdline(t *testing.T) {
func TestAccLibvirtDomain_NetworkInterface(t *testing.T) {
var domain libvirt.Domain
+ currentDir, err := os.Getwd()
+ if err != nil {
+ t.Fatal("Unexpected error:", err)
+ }
+
var config = fmt.Sprintf(`
- resource "libvirt_volume" "acceptance-test-volume" {
- name = "terraform-test"
+ resource "libvirt_network" "acceptance-test-network" {
+ name = "terraform-test"
+ addresses = ["10.17.3.0/24"]
}
resource "libvirt_domain" "acceptance-test-domain" {
@@ -303,11 +309,12 @@ func TestAccLibvirtDomain_NetworkInterface(t *testing.T) {
network_interface = {
network_name = "default"
mac = "52:54:00:A9:F5:17"
+ wait_for_lease = 1
}
disk {
- volume_id = "${libvirt_volume.acceptance-test-volume.id}"
+ file = "%s/testdata/tcl.iso"
}
- }`)
+ }`, currentDir)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
diff --git a/libvirt/testdata/tcl.iso b/libvirt/testdata/tcl.iso
new file mode 100644
index 00000000..303088d0
--- /dev/null
+++ b/libvirt/testdata/tcl.iso
Binary files differ
diff --git a/travis/setup-guest b/travis/setup-guest
index 42568e81..0a671b2f 100755
--- a/travis/setup-guest
+++ b/travis/setup-guest
@@ -20,3 +20,6 @@ mkdir /pool-default
chmod a+rwx /pool-default
virsh pool-define pool.xml
virsh pool-start default
+echo -e 'user = "root"\ngroup = "root"' >> /etc/libvirt/qemu.conf
+systemctl restart libvirtd
+
diff --git a/website/docs/r/domain.html.markdown b/website/docs/r/domain.html.markdown
index 01ed1fc3..ff9ab0a3 100644
--- a/website/docs/r/domain.html.markdown
+++ b/website/docs/r/domain.html.markdown
@@ -237,9 +237,9 @@ The `disk` block supports:
* `volume_id` - (Optional) The volume id to use for this disk.
* `url` - (Optional) The http url to use as the block device for this disk (read-only)
+* `file` - (Optional) The filename to use as the block device for this disk (read-only)
-While both `volume_id` and `url` are optional, it is intended that you use either a volume or a
-url.
+While `volume_id`, `url` and `file` are optional, it is intended that you use one of them.
* `scsi` - (Optional) Use a scsi controller for this disk. The controller
model is set to `virtio-scsi`
@@ -268,6 +268,10 @@ resource "libvirt_domain" "domain1" {
disk {
url = "http://foo.com/install.iso"
}
+
+ disk {
+ file = "/absolute/path/to/disk.iso"
+ }
}
```