aboutsummaryrefslogtreecommitdiff
path: root/libvirt/disk_def.go
blob: ed65c290c915f7b16d181837017caa6ea18920e4 (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
package libvirt

import (
	"math/rand"

	"github.com/libvirt/libvirt-go-xml"
)

const OUI = "05abcd"

func newDefDisk() libvirtxml.DomainDisk {
	return libvirtxml.DomainDisk{
		Type:   "file",
		Device: "disk",
		Target: &libvirtxml.DomainDiskTarget{
			Bus: "virtio",
		},
		Driver: &libvirtxml.DomainDiskDriver{
			Name: "qemu",
			Type: "qcow2",
		},
	}
}

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)
	for i := 0; i < strlen; i++ {
		result[i] = chars[rand.Intn(len(chars))]
	}
	return OUI + string(result)
}