summaryrefslogtreecommitdiff
path: root/libvirt/disk_def.go
blob: 26cf513ea2ad21344b3778f417a9c23393ad1cc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package libvirt

import (
	"encoding/xml"
	"math/rand"
)

const OUI = "05abcd"

type defDisk struct {
	XMLName xml.Name `xml:"disk"`
	Type    string   `xml:"type,attr"`
	Device  string   `xml:"device,attr"`
	Wwn     string   `xml:"wwn,omitempty"`
	Format  struct {
		Type string `xml:"type,attr"`
	} `xml:"format"`
	Source struct {
		File string `xml:"file,attr,omitempty"`
		// retain Pool/Volume for compatibility with existing tfstate
		Pool   string `xml:"pool,attr,omitempty"`
		Volume string `xml:"volume,attr,omitempty"`
	} `xml:"source"`
	Target struct {
		Dev string `xml:"dev,attr"`
		Bus string `xml:"bus,attr"`
	} `xml:"target"`
	Driver struct {
		Name string `xml:"name,attr"`
		Type string `xml:"type,attr"`
	} `xml:"driver"`
}

func newDefDisk() defDisk {
	disk := defDisk{}
	disk.Type = "file"
	disk.Device = "disk"
	disk.Format.Type = "qcow2"
	disk.Target.Bus = "virtio"

	disk.Driver.Name = "qemu"
	disk.Driver.Type = "qcow2"

	return disk
}

func newCDROM() defDisk {
	disk := defDisk{}
	disk.Type = "file"
	disk.Device = "cdrom"
	disk.Target.Dev = "hda"
	disk.Target.Bus = "ide"

	disk.Driver.Name = "qemu"
	disk.Driver.Type = "raw"

	return disk
}

func randomWWN(strlen int) string {
	const chars = "abcdef0123456789"
	result := make([]byte, strlen)
	for i := 0; i < strlen; i++ {
		result[i] = chars[rand.Intn(len(chars))]
	}
	return OUI + string(result)
}