Documentation
¶
Index ¶
- Variables
- func PortInUse(port int) bool
- func ProxyVNCToWebSocket(vncPort int) (int, error)
- type ACPI
- type Arch
- type Bank
- type Baselabel
- type CPUElement
- type CPUPage
- type CPUTopology
- type Cache
- type Capabilities
- type Capability
- type Cell
- type CellPage
- type Cells
- type Counter
- type Cpus
- type Default
- type Distances
- type Domain
- type DomainCreateOpt
- type DomainElement
- type DomainSnapshot
- type DomainState
- type DomainUnion
- type Feature
- type Features
- type Guest
- type Host
- type HostCPU
- type HostTopology
- type Iommu
- type Lib
- func (l *Lib) Connect() error
- func (l *Lib) CreateDomain(opt DomainCreateOpt) error
- func (l *Lib) CreateSnapshot(name string, opt DomainSnapshot) error
- func (l *Lib) DeleteSnapshot(name, snapshotName string, args libvirt.DomainSnapshotDeleteFlags) error
- func (l *Lib) DestroyDomain(name string) error
- func (l *Lib) DisConnect() error
- func (l *Lib) GetAllInterfaces()
- func (l *Lib) GetCapabilities() (string, error)
- func (l *Lib) GetCurrentSnapshot(domainName string) (libvirt.DomainSnapshot, error)
- func (l *Lib) GetDomCPUTime(domName string) ([]libvirt.TypedParam, error)
- func (l *Lib) GetDomCPUUsage(domName string, interval int) (float64, error)
- func (l *Lib) GetDomDiskUsage(domName string) (float64, error)
- func (l *Lib) GetDomMemStats(domName string) ([]libvirt.DomainMemoryStat, error)
- func (l *Lib) GetDomMemUsage(domName string) (float64, error)
- func (l *Lib) GetDomainByName(name string) (libvirt.Domain, error)
- func (l *Lib) GetDomainDiskPath(name string) string
- func (l *Lib) GetDomainIP(name string)
- func (l *Lib) GetDomainIPAddress(name string) (string, error)
- func (l *Lib) GetDomainState(name string) (DomainState, error)
- func (l *Lib) GetDomainVNCPort(name string) string
- func (l *Lib) GetDomainXML(name string) Domain
- func (l *Lib) GetNodeCPUStats() ([]libvirt.NodeGetCPUStats, error)
- func (l *Lib) GetNodeMemStats() ([]libvirt.NodeGetMemoryStats, error)
- func (l *Lib) GetSnapshotByName(domain, snapshotName string) (libvirt.DomainSnapshot, error)
- func (l *Lib) ListSnapshots(name string) ([]libvirt.DomainSnapshot, error)
- func (l *Lib) PullAllSnapshots(domainName string) error
- func (l *Lib) RebootDomain(name string) error
- func (l *Lib) ResumeDomain(name string) error
- func (l *Lib) RevertSnapshot(name string) error
- func (l *Lib) ShutdownDomain(name string) error
- func (l *Lib) StartDomain(name string) error
- func (l *Lib) SuspendDomain(name string) error
- func (l *Lib) UnDefineDomain(name string) error
- type MachineElement
- type MachineUnion
- type Memory
- type Microcode
- type MigrationFeatures
- type OSType
- type PowerManagement
- type PurpleMachine
- type Secmodel
- type Sibling
- type Support
- type Type
- type URITransports
- type Welcome4
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultCreateDomainOpt = DomainCreateOpt{ Type: "kvm", Name: "ubuntu", Uuid: "c7a5fdbd-cdaf-9455-926a-d65c16db1809", Memory: struct { Text string `xml:",chardata"` Unit string `xml:"unit,attr"` }{ Text: "4", Unit: "GiB", }, Vcpu: "4", Os: __os{ Type: struct { Text string `xml:",chardata"` Arch string `xml:"arch,attr"` Machine string `xml:"machine,attr"` }{ Text: "hvm", Arch: "x86_64", Machine: "pc", }, Boot: []__boot{ {Dev: "hd"}, {Dev: "cdrom"}, }, }, Devices: __devices{ Emulator: "/usr/bin/qemu-system-x86_64", Disk: []__disk{{ Type: "file", Device: "cdrom", Source: __source{ File: "/home/fangaoyang/work/ubuntu-20.04.3-desktop-amd64.iso", }, Target: __target{ Dev: "hdc", }, }, { Type: "file", Device: "disk", Driver: &__driver{ Name: "qemu", Type: "qcow2", }, Source: __source{ File: "/home/fangaoyang/work/desktop.qcow2", }, Target: __target{ Dev: "hda", }, }}, Interface: __interface{ Type: "network", Source: __interSource{Network: "default"}, }, Graphics: __graphics{ Type: "vnc", Port: "-1", Listen: "0.0.0.0", Passwd: "123", Keymap: "en-us", }, Serial: __serial{ Type: "pty", Target: __serTarget{ Port: "0", }, }, Console: __console{ Type: "pty", Target: __conTarget{ Type: "serial", Port: "0", }, }, }, }
Functions ¶
func ProxyVNCToWebSocket ¶
Types ¶
type Arch ¶
type Arch struct { Wordsize string `xml:"wordsize"` Emulator string `xml:"emulator"` Machine *MachineUnion `xml:"machine"` Domain *DomainUnion `xml:"domain"` Name string `xml:"_name"` }
type CPUElement ¶
type CPUTopology ¶
type Capabilities ¶
type Capability ¶
type Capability struct { XMLName xml.Name `xml:"capabilities"` Text string `xml:",chardata"` Host struct { Text string `xml:",chardata"` Uuid string `xml:"uuid"` Cpu struct { Text string `xml:",chardata"` Arch string `xml:"arch"` Model string `xml:"model"` Vendor string `xml:"vendor"` Microcode struct { Text string `xml:",chardata"` Version string `xml:"version,attr"` } `xml:"microcode"` Counter struct { Text string `xml:",chardata"` Name string `xml:"name,attr"` Frequency string `xml:"frequency,attr"` Scaling string `xml:"scaling,attr"` } `xml:"counter"` Topology struct { Text string `xml:",chardata"` Sockets string `xml:"sockets,attr"` Cores string `xml:"cores,attr"` Threads string `xml:"threads,attr"` } `xml:"topology"` Feature []struct { Text string `xml:",chardata"` Name string `xml:"name,attr"` } `xml:"feature"` Pages []struct { Text string `xml:",chardata"` Unit string `xml:"unit,attr"` Size string `xml:"size,attr"` } `xml:"pages"` } `xml:"cpu"` PowerManagement struct { Text string `xml:",chardata"` SuspendMem string `xml:"suspend_mem"` SuspendDisk string `xml:"suspend_disk"` SuspendHybrid string `xml:"suspend_hybrid"` } `xml:"power_management"` Iommu struct { Text string `xml:",chardata"` Support string `xml:"support,attr"` } `xml:"iommu"` MigrationFeatures struct { Text string `xml:",chardata"` Live string `xml:"live"` URITransports struct { Text string `xml:",chardata"` URITransport []string `xml:"uri_transport"` } `xml:"uri_transports"` } `xml:"migration_features"` Topology struct { Text string `xml:",chardata"` Cells struct { Text string `xml:",chardata"` Num string `xml:"num,attr"` Cell struct { Text string `xml:",chardata"` ID string `xml:"id,attr"` Memory struct { Text string `xml:",chardata"` Unit string `xml:"unit,attr"` } `xml:"memory"` Pages []struct { Text string `xml:",chardata"` Unit string `xml:"unit,attr"` Size string `xml:"size,attr"` } `xml:"pages"` Distances struct { Text string `xml:",chardata"` Sibling struct { Text string `xml:",chardata"` ID string `xml:"id,attr"` Value string `xml:"value,attr"` } `xml:"sibling"` } `xml:"distances"` Cpus struct { Text string `xml:",chardata"` Num string `xml:"num,attr"` Cpu []struct { Text string `xml:",chardata"` ID string `xml:"id,attr"` SocketID string `xml:"socket_id,attr"` CoreID string `xml:"core_id,attr"` Siblings string `xml:"siblings,attr"` } `xml:"cpu"` } `xml:"cpus"` } `xml:"cell"` } `xml:"cells"` } `xml:"topology"` Cache struct { Text string `xml:",chardata"` Bank struct { Text string `xml:",chardata"` ID string `xml:"id,attr"` Level string `xml:"level,attr"` Type string `xml:"type,attr"` Size string `xml:"size,attr"` Unit string `xml:"unit,attr"` Cpus string `xml:"cpus,attr"` } `xml:"bank"` } `xml:"cache"` Secmodel []struct { Text string `xml:",chardata"` Model string `xml:"model"` Doi string `xml:"doi"` Baselabel []struct { Text string `xml:",chardata"` Type string `xml:"type,attr"` } `xml:"baselabel"` } `xml:"secmodel"` } `xml:"host"` Guest []struct { Text string `xml:",chardata"` OsType string `xml:"os_type"` Arch struct { Text string `xml:",chardata"` Name string `xml:"name,attr"` Wordsize string `xml:"wordsize"` Emulator string `xml:"emulator"` Machine []struct { Text string `xml:",chardata"` MaxCpus string `xml:"maxCpus,attr"` Canonical string `xml:"canonical,attr"` } `xml:"machine"` Domain []struct { Text string `xml:",chardata"` Type string `xml:"type,attr"` } `xml:"domain"` } `xml:"arch"` Features struct { Text string `xml:",chardata"` Cpuselection string `xml:"cpuselection"` Deviceboot string `xml:"deviceboot"` Disksnapshot struct { Text string `xml:",chardata"` Default string `xml:"default,attr"` Toggle string `xml:"toggle,attr"` } `xml:"disksnapshot"` Acpi struct { Text string `xml:",chardata"` Default string `xml:"default,attr"` Toggle string `xml:"toggle,attr"` } `xml:"acpi"` Pae string `xml:"pae"` Nonpae string `xml:"nonpae"` Apic struct { Text string `xml:",chardata"` Default string `xml:"default,attr"` Toggle string `xml:"toggle,attr"` } `xml:"apic"` } `xml:"features"` } `xml:"guest"` }
type Cpus ¶
type Cpus struct { CPU []CPUElement `xml:"cpu"` Num string `xml:"_num"` }
type Domain ¶
type Domain struct { XMLName xml.Name `xml:"domain"` Type string `xml:"type,attr"` ID string `xml:"id,attr"` Name string `xml:"name"` Uuid string `xml:"uuid"` Memory memory `xml:"memory"` CurrentMemory currentMemory `xml:"currentMemory"` Vcpu vcpu `xml:"vcpu"` Resource resource `xml:"resource"` Os os `xml:"os"` Cpu cpu `xml:"cpu"` Clock clock `xml:"clock"` OnPoweroff string `xml:"on_poweroff"` OnReboot string `xml:"on_reboot"` OnCrash string `xml:"on_crash"` Devices devices `xml:"devices"` Seclabel seclabel `xml:"seclabel"` }
type DomainCreateOpt ¶
type DomainCreateOpt struct { XMLName xml.Name `xml:"domain"` Text string `xml:",chardata"` Type string `xml:"type,attr"` Name string `xml:"name"` Uuid string `xml:"uuid"` Memory __memo `xml:"memory"` CurrentMemory __currentMemory `xml:"currentMemory"` Vcpu string `xml:"vcpu"` Os __os `xml:"os"` Devices __devices `xml:"devices"` }
type DomainElement ¶
type DomainElement struct {
Type Type `xml:"_type"`
}
type DomainSnapshot ¶
type DomainState ¶
type DomainUnion ¶
type DomainUnion struct { DomainElement *DomainElement DomainElementArray []DomainElement }
type Host ¶
type Host struct { UUID string `xml:"uuid"` CPU HostCPU `xml:"cpu"` PowerManagement PowerManagement `xml:"power_management"` Iommu Iommu `xml:"iommu"` MigrationFeatures MigrationFeatures `xml:"migration_features"` Topology HostTopology `xml:"topology"` Cache Cache `xml:"cache"` Secmodel []Secmodel `xml:"secmodel"` }
type HostTopology ¶
type HostTopology struct {
Cells Cells `xml:"cells"`
}
type Lib ¶
type Lib struct {
// contains filtered or unexported fields
}
func GetConnectedLib ¶
func GetConnectedLib() *Lib
func (*Lib) CreateDomain ¶
func (l *Lib) CreateDomain(opt DomainCreateOpt) error
func (*Lib) CreateSnapshot ¶
func (l *Lib) CreateSnapshot(name string, opt DomainSnapshot) error
CreateSnapshot
libvirt不支持对于external snapshot的管理操作:恢复快照、删除快照会有如下报错: unsupported configuration: deletion of 1 external disk snapshots not supported yet. 而如果在创建快照时flag为libvirt.DomainSnapshotCreateDiskOnly(libvirt.DomainSnapshotCreateFlags)时, 快照会被保存到外部,即快照是external的。这就需要手动来管理这些external的快照。 创建:将 libvirt.DomainSnapshotCreateFlags 传入函数,即可在Domain对应的镜像文件所在的目录中生成一个镜像文件, 镜像文件的后缀是snapshot的名称。 回滚:只能调用带 libvirt.DomainSnapshotDeleteMetadataOnly flag的函数,删除镜像元数据,然后手动将xml中的镜像 文件修改为parent的快照,并删除要删除的镜像文件。 手工操作可参考: https://fabianlee.org/2021/01/10/kvm-creating-and-reverting-libvirt-external-snapshots/
func (*Lib) DeleteSnapshot ¶
func (l *Lib) DeleteSnapshot(name, snapshotName string, args libvirt.DomainSnapshotDeleteFlags) error
DeleteSnapshot
args: libvirt.DomainSnapshotDeleteChildren 此快照和任何后代快照都将被删除 libvirt.DomainSnapshotDeleteChildrenOnly 删除任何后代快照,但保留此快照 libvirt.DomainSnapshotDeleteMetadataOnly 任何由libvirt追踪的快照元数据都会被移除,同时保持快照内容不变; 如果管理程序不需要任何libvirt元数据来追踪快照,那么这个标志会被默默地忽略。 => 可以删除external快照的metadata,但不删除文件,需要手动管理文件
func (*Lib) DisConnect ¶
func (*Lib) GetAllInterfaces ¶
func (l *Lib) GetAllInterfaces()
func (*Lib) GetCapabilities ¶
func (*Lib) GetCurrentSnapshot ¶
func (*Lib) GetDomCPUTime ¶
func (*Lib) GetDomCPUUsage ¶
func (*Lib) GetDomMemStats ¶
func (*Lib) GetDomainByName ¶
func (*Lib) GetDomainDiskPath ¶
func (*Lib) GetDomainIPAddress ¶
GetDomainIPAddress 不知道为什么会返回一个数组
func (*Lib) GetDomainState ¶
func (l *Lib) GetDomainState(name string) (DomainState, error)
func (*Lib) GetDomainVNCPort ¶
func (*Lib) GetDomainXML ¶
func (*Lib) GetNodeCPUStats ¶
func (*Lib) GetNodeMemStats ¶
func (*Lib) GetSnapshotByName ¶
func (*Lib) ListSnapshots ¶
func (*Lib) PullAllSnapshots ¶
func (*Lib) RevertSnapshot ¶
func (*Lib) StartDomain ¶
func (*Lib) UnDefineDomain ¶
type MachineElement ¶
type MachineUnion ¶
type MachineUnion struct { MachineElementArray []MachineElement PurpleMachine *PurpleMachine }
type MigrationFeatures ¶
type MigrationFeatures struct { Live string `xml:"live"` URITransports URITransports `xml:"uri_transports"` }
type PowerManagement ¶
type PurpleMachine ¶
type URITransports ¶
type URITransports struct {
URITransport []string `xml:"uri_transport"`
}
type Welcome4 ¶
type Welcome4 struct {
Capabilities Capabilities `xml:"capabilities"`
}
Click to show internal directories.
Click to hide internal directories.