summaryrefslogtreecommitdiff
path: root/libvirt/domain_def.go
diff options
context:
space:
mode:
authorFlavio Castelli <fcastelli@suse.com>2017-06-19 21:09:04 +0200
committerFlavio Castelli <fcastelli@suse.com>2017-06-19 21:09:04 +0200
commit4307ba55c5d4cabf750756f243bed97505f8e61a (patch)
tree2e449e111ea5ae5411ccb95534dc921917d242dd /libvirt/domain_def.go
parent1b6657408ec4259426d7420fe48ae97415428f3c (diff)
downloadterraform-provider-libvirt-4307ba55c5d4cabf750756f243bed97505f8e61a.tar
terraform-provider-libvirt-4307ba55c5d4cabf750756f243bed97505f8e61a.tar.gz
Add support of filesystem device to domain
Allow sharing of directories of the host with the guest by using the filesystem device.
Diffstat (limited to 'libvirt/domain_def.go')
-rw-r--r--libvirt/domain_def.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/libvirt/domain_def.go b/libvirt/domain_def.go
index a4661bc2..c656d095 100644
--- a/libvirt/domain_def.go
+++ b/libvirt/domain_def.go
@@ -27,6 +27,7 @@ type defDomain struct {
Disks []defDisk `xml:"disk"`
NetworkInterfaces []defNetworkInterface `xml:"interface"`
Console []defConsole `xml:"console"`
+ Filesystems []defFilesystem `xml:"filesystem"`
Graphics *defGraphics `xml:"graphics,omitempty"`
// QEMU guest agent channel
QemuGAChannel struct {
@@ -121,6 +122,59 @@ type defConsole struct {
} `xml:"target"`
}
+type defFilesystemReadOnly bool
+
+type defFilesystem struct {
+ Type string `xml:"type,attr"`
+ AccessMode string `xml:"accessmode,attr"`
+ ReadOnly defFilesystemReadOnly `xml:"readonly",omitempty`
+ Source struct {
+ Dir string `xml:"dir,attr,omitempty"`
+ } `xml:"source"`
+ Target struct {
+ Dir string `xml:"dir,attr,omitempty"`
+ } `xml:"target"`
+}
+
+// The filesystem element has a <readonly/> tag when
+// the host directory cannot be written by the guest. When
+// the <readonly/> tag is omitted the read-write permissions
+// are granted.
+// To show the empty <readonly/> tag we have to define a
+// "alias" of bool and provide a custom marshaller for it.
+func (r defFilesystemReadOnly) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
+ if !r {
+ return nil
+ }
+ err := e.EncodeElement("", start)
+ return err
+}
+
+func (r *defFilesystemReadOnly) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
+ var value string
+ err := d.DecodeElement(&value, &start)
+ if err != nil {
+ return err
+ }
+
+ *r = value == ""
+
+ return nil
+}
+
+func newFilesystemDef() defFilesystem {
+ fs := defFilesystem{}
+
+ // This is the only type used by qemu/kvm
+ fs.Type = "mount"
+
+ // A safe default value
+ fs.AccessMode = "mapped"
+ fs.ReadOnly = true
+
+ return fs
+}
+
// Creates a domain definition with the defaults
// the provider uses
func newDomainDef() defDomain {