### Create and Parse Domain XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Demonstrates creating a libvirt Domain configuration in Go and then marshaling it to an XML string. It also shows how to unmarshal an existing XML string back into a Domain struct. Ensure the libvirtxml package is imported.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create a new domain configuration
domcfg := &libvirtxml.Domain{
Type: "kvm",
Name: "my-vm",
UUID: "4dea22b3-1d52-d8f3-2516-782e98ab3fa0",
Memory: &libvirtxml.DomainMemory{
Unit: "GiB",
Value: 4,
},
VCPU: &libvirtxml.DomainVCPU{
Placement: "static",
Value: 2,
},
OS: &libvirtxml.DomainOS{
Type: &libvirtxml.DomainOSType{
Arch: "x86_64",
Machine: "pc-q35-6.2",
Type: "hvm",
},
BootDevices: []libvirtxml.DomainBootDevice{
{Dev: "hd"},
},
},
Devices: &libvirtxml.DomainDeviceList{
Disks: []libvirtxml.DomainDisk{
{
Device: "disk",
Driver: &libvirtxml.DomainDiskDriver{
Name: "qemu",
Type: "qcow2",
},
Source: &libvirtxml.DomainDiskSource{
File: &libvirtxml.DomainDiskSourceFile{
File: "/var/lib/libvirt/images/my-vm.qcow2",
},
},
Target: &libvirtxml.DomainDiskTarget{
Dev: "vda",
Bus: "virtio",
},
},
},
Interfaces: []libvirtxml.DomainInterface{
{
MAC: &libvirtxml.DomainInterfaceMAC{
Address: "52:54:00:12:34:56",
},
Source: &libvirtxml.DomainInterfaceSource{
Network: &libvirtxml.DomainInterfaceSourceNetwork{
Network: "default",
},
},
Model: &libvirtxml.DomainInterfaceModel{
Type: "virtio",
},
},
},
},
}
// Marshal to XML string
xmlStr, err := domcfg.Marshal()
if err != nil {
panic(err)
}
fmt.Println(xmlStr)
// Unmarshal from XML string
var parsed libvirtxml.Domain
err = parsed.Unmarshal(xmlStr)
if err != nil {
panic(err)
}
fmt.Printf("Domain name: %s, Memory: %d %s\n", parsed.Name, parsed.Memory.Value, parsed.Memory.Unit)
}
```
--------------------------------
### Create and Parse Network XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Demonstrates creating a libvirt Network configuration with NAT and DHCP settings, marshaling it to XML, and then unmarshaling an existing network XML string. Ensure the libvirtxml package is imported.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create a NAT network with DHCP
netcfg := &libvirtxml.Network{
Name: "my-network",
UUID: "5dea22b3-1d52-d8f3-2516-782e98ab3fa1",
Forward: &libvirtxml.NetworkForward{
Mode: "nat",
NAT: &libvirtxml.NetworkForwardNAT{
Ports: []libvirtxml.NetworkForwardNATPort{
{Start: 1024, End: 65535},
},
},
},
Bridge: &libvirtxml.NetworkBridge{
Name: "virbr1",
STP: "on",
},
Domain: &libvirtxml.NetworkDomain{
Name: "example.local",
LocalOnly: "yes",
},
IPs: []libvirtxml.NetworkIP{
{
Address: "192.168.100.1",
Netmask: "255.255.255.0",
DHCP: &libvirtxml.NetworkDHCP{
Ranges: []libvirtxml.NetworkDHCPRange{
{Start: "192.168.100.100", End: "192.168.100.200"},
},
Hosts: []libvirtxml.NetworkDHCPHost{
{
MAC: "52:54:00:12:34:56",
Name: "my-vm",
IP: "192.168.100.50",
},
},
},
},
},
DNS: &libvirtxml.NetworkDNS{
Enable: "yes",
Host: []libvirtxml.NetworkDNSHost{
{
IP: "192.168.100.1",
Hostnames: []libvirtxml.NetworkDNSHostHostname{
{Hostname: "gateway.example.local"},
},
},
},
},
}
xmlStr, err := netcfg.Marshal()
if err != nil {
panic(err)
}
fmt.Println(xmlStr)
// Parse existing network XML
existingXML := `
default
`
var parsed libvirtxml.Network
err = parsed.Unmarshal(existingXML)
if err != nil {
panic(err)
}
fmt.Printf("Network: %s, Bridge: %s\n", parsed.Name, parsed.Bridge.Name)
}
```
--------------------------------
### Marshal Domain Devices for Hot-plugging in Go
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Demonstrates marshalling XML for a disk device and a network interface, suitable for dynamic attachment (hot-plugging) to a domain. Also shows marshalling XML for a PCI host device for passthrough.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create and marshal a disk device for hot-plug
disk := &libvirtxml.DomainDisk{
Device: "disk",
Driver: &libvirtxml.DomainDiskDriver{
Name: "qemu",
Type: "qcow2",
Cache: "none",
IO: "native",
},
Source: &libvirtxml.DomainDiskSource{
File: &libvirtxml.DomainDiskSourceFile{
File: "/var/lib/libvirt/images/data-disk.qcow2",
},
},
Target: &libvirtxml.DomainDiskTarget{
Dev: "vdb",
Bus: "virtio",
},
}
diskXML, _ := disk.Marshal()
fmt.Println("Disk XML for attach:")
fmt.Println(diskXML)
// Create and marshal a network interface for hot-plug
iface := &libvirtxml.DomainInterface{
MAC: &libvirtxml.DomainInterfaceMAC{
Address: "52:54:00:ab:cd:ef",
},
Source: &libvirtxml.DomainInterfaceSource{
Network: &libvirtxml.DomainInterfaceSourceNetwork{
Network: "isolated-net",
},
},
Model: &libvirtxml.DomainInterfaceModel{
Type: "virtio",
},
}
ifaceXML, _ := iface.Marshal()
fmt.Println("\nInterface XML for attach:")
fmt.Println(ifaceXML)
// Create a hostdev for PCI passthrough
domain := uint(0)
bus := uint(3)
slot := uint(0)
function := uint(0)
hostdev := &libvirtxml.DomainHostdev{
Mode: "subsystem",
Type: "pci",
Managed: "yes",
SubsysPCI: &libvirtxml.DomainHostdevSubsysPCI{
Source: &libvirtxml.DomainHostdevSubsysPCISource{
Address: &libvirtxml.DomainAddressPCI{
Domain: &domain,
Bus: &bus,
Slot: &slot,
Function: &function,
},
},
},
}
hostdevXML, _ := hostdev.Marshal()
fmt.Println("\nHostdev XML for PCI passthrough:")
fmt.Println(hostdevXML)
}
```
--------------------------------
### Create qcow2 Storage Volume XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Defines a qcow2 storage volume configuration. Specify capacity, allocation, and target path.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create a qcow2 volume
volcfg := &libvirtxml.StorageVolume{
Type: "file",
Name: "my-disk.qcow2",
Capacity: &libvirtxml.StorageVolumeSize{
Unit: "GiB",
Value: 50,
},
Allocation: &libvirtxml.StorageVolumeSize{
Unit: "MiB",
Value: 256,
},
Target: &libvirtxml.StorageVolumeTarget{
Path: "/var/lib/libvirt/images/my-disk.qcow2",
Format: &libvirtxml.StorageVolumeTargetFormat{
Type: "qcow2",
},
Permissions: &libvirtxml.StorageVolumeTargetPermissions{
Mode: "0644",
Owner: "107",
Group: "107",
},
Compat: "1.1",
},
}
xmlStr, err := volcfg.Marshal()
if err != nil {
panic(err)
}
fmt.Println(xmlStr)
}
```
--------------------------------
### Create and Marshal Domain Snapshot XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Use DomainSnapshot to define VM snapshot configurations, including memory and disk states. Marshal the struct to generate XML for libvirt.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create a domain snapshot configuration
snapcfg := &libvirtxml.DomainSnapshot{
Name: "pre-upgrade-snapshot",
Description: "Snapshot taken before system upgrade",
Memory: &libvirtxml.DomainSnapshotMemory{
Snapshot: "internal",
},
Disks: &libvirtxml.DomainSnapshotDisks{
Disks: []libvirtxml.DomainSnapshotDisk{
{
Name: "vda",
Snapshot: "internal",
},
{
Name: "vdb",
Snapshot: "no",
},
},
},
}
xmlStr, err := snapcfg.Marshal()
if err != nil {
panic(err)
}
fmt.Println(xmlStr)
// Parse snapshot with external disk
externalSnap := `
external-snap
`
var parsed libvirtxml.DomainSnapshot
err = parsed.Unmarshal(externalSnap)
if err != nil {
panic(err)
}
fmt.Printf("Snapshot: %s\n", parsed.Name)
}
```
--------------------------------
### Create and Marshal Network Port XML in Go
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Creates a network port configuration with specified UUID, owner, MAC address, group, and bandwidth limits, then marshals it into an XML string. Ensure all required fields are populated for correct XML generation.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create a network port configuration
portcfg := &libvirtxml.NetworkPort{
UUID: "adea22b3-1d52-d8f3-2516-782e98ab3fa6",
Owner: &libvirtxml.NetworkPortOwner{
UUID: "4dea22b3-1d52-d8f3-2516-782e98ab3fa0",
Name: "my-vm",
},
MAC: &libvirtxml.NetworkPortMAC{
Address: "52:54:00:12:34:56",
},
Group: "web-servers",
Bandwidth: &libvirtxml.NetworkBandwidth{
Inbound: &libvirtxml.NetworkBandwidthParams{},
Outbound: &libvirtxml.NetworkBandwidthParams{},
},
Plug: &libvirtxml.NetworkPortPlug{
Bridge: &libvirtxml.NetworkPortPlugBridge{
Bridge: "virbr0",
MacTableManager: "libvirt",
},
},
}
// Set bandwidth limits
inbound := uint(1000)
outbound := uint(500)
portcfg.Bandwidth.Inbound.Average = &inbound
portcfg.Bandwidth.Outbound.Average = &outbound
xmlStr, err := portcfg.Marshal()
if err != nil {
panic(err)
}
fmt.Println(xmlStr)
}
```
--------------------------------
### Create Directory Storage Pool XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Defines a directory-based storage pool configuration. Ensure the target path is accessible by libvirt.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create a directory-based storage pool
poolcfg := &libvirtxml.StoragePool{
Type: "dir",
Name: "my-pool",
UUID: "6dea22b3-1d52-d8f3-2516-782e98ab3fa2",
Target: &libvirtxml.StoragePoolTarget{
Path: "/var/lib/libvirt/images/my-pool",
Permissions: &libvirtxml.StoragePoolTargetPermissions{
Mode: "0755",
Owner: "0",
Group: "0",
},
},
}
xmlStr, err := poolcfg.Marshal()
if err != nil {
panic(err)
}
fmt.Println(xmlStr)
}
```
--------------------------------
### Create Storage Volume with Backing Store XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Defines a storage volume that uses a backing store, suitable for snapshots or clones. Specify the backing store path and format.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create a volume with backing store (snapshot/clone)
cloneVol := &libvirtxml.StorageVolume{
Type: "file",
Name: "my-clone.qcow2",
Capacity: &libvirtxml.StorageVolumeSize{
Unit: "GiB",
Value: 50,
},
Target: &libvirtxml.StorageVolumeTarget{
Format: &libvirtxml.StorageVolumeTargetFormat{
Type: "qcow2",
},
},
BackingStore: &libvirtxml.StorageVolumeBackingStore{
Path: "/var/lib/libvirt/images/base-image.qcow2",
Format: &libvirtxml.StorageVolumeTargetFormat{
Type: "qcow2",
},
},
}
cloneXML, _ := cloneVol.Marshal()
fmt.Println(cloneXML)
}
```
--------------------------------
### Parse Host Capabilities XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Use the Caps struct to parse host capabilities XML, typically obtained from libvirt. This allows programmatic access to CPU features, NUMA topology, and guest architectures.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Parse host capabilities XML (typically obtained from libvirt)
capsXML := `
44454c4c-4800-1036-8058-b8c04f595732
x86_64
Skylake-Server-IBRS
Intel
|
65536000
|
hvm
64
/usr/bin/qemu-system-x86_64
pc-q35-6.2
`
var caps libvirtxml.Caps
err := caps.Unmarshal(capsXML)
if err != nil {
panic(err)
}
fmt.Printf("Host UUID: %s\n", caps.Host.UUID)
fmt.Printf("CPU Model: %s\n", caps.Host.CPU.Model)
fmt.Printf("CPU Vendor: %s\n", caps.Host.CPU.Vendor)
if caps.Host.CPU.Topology != nil {
fmt.Printf("Topology: %d sockets, %d cores, %d threads\n",
caps.Host.CPU.Topology.Sockets,
caps.Host.CPU.Topology.Cores,
caps.Host.CPU.Topology.Threads)
}
for _, guest := range caps.Guests {
fmt.Printf("Guest OS: %s, Arch: %s\n", guest.OSType, guest.Arch.Name)
}
}
```
--------------------------------
### Create NFS Storage Pool XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Defines an NFS-based storage pool configuration. Requires specifying the NFS host and export path.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create an NFS storage pool
nfsPool := &libvirtxml.StoragePool{
Type: "netfs",
Name: "nfs-pool",
Source: &libvirtxml.StoragePoolSource{
Host: []libvirtxml.StoragePoolSourceHost{
{Name: "192.168.1.100"},
},
Dir: &libvirtxml.StoragePoolSourceDir{
Path: "/exports/vms",
},
Format: &libvirtxml.StoragePoolSourceFormat{
Type: "nfs",
},
},
Target: &libvirtxml.StoragePoolTarget{
Path: "/var/lib/libvirt/images/nfs",
},
}
nfsXML, _ := nfsPool.Marshal()
fmt.Println(nfsXML)
}
```
--------------------------------
### Create and Marshal Network Filter (NWFilter) XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Define network traffic filtering rules for VM interfaces using the NWFilter struct. Marshal the configuration to generate XML for libvirt.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create a network filter with rules
filtercfg := &libvirtxml.NWFilter{
Name: "allow-ssh-http",
Chain: "root",
Priority: -700,
Entries: []libvirtxml.NWFilterEntry{
{
Ref: &libvirtxml.NWFilterRef{
Filter: "clean-traffic",
},
},
{
Rule: &libvirtxml.NWFilterRule{
Action: "accept",
Direction: "in",
Priority: 500,
TCP: &libvirtxml.NWFilterRuleTCP{
NWFilterRuleCommonPort: libvirtxml.NWFilterRuleCommonPort{
DstPortStart: libvirtxml.NWFilterField{Str: "22"},
},
},
},
},
{
Rule: &libvirtxml.NWFilterRule{
Action: "accept",
Direction: "in",
Priority: 500,
TCP: &libvirtxml.NWFilterRuleTCP{
NWFilterRuleCommonPort: libvirtxml.NWFilterRuleCommonPort{
DstPortStart: libvirtxml.NWFilterField{Str: "80"},
},
},
},
},
{
Rule: &libvirtxml.NWFilterRule{
Action: "accept",
Direction: "in",
Priority: 500,
TCP: &libvirtxml.NWFilterRuleTCP{
NWFilterRuleCommonPort: libvirtxml.NWFilterRuleCommonPort{
DstPortStart: libvirtxml.NWFilterField{Str: "443"},
},
},
},
},
},
}
xmlStr, err := filtercfg.Marshal()
if err != nil {
panic(err)
}
fmt.Println(xmlStr)
}
```
--------------------------------
### Create iSCSI CHAP Secret XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Defines a libvirt secret for iSCSI CHAP authentication. Requires a UUID and target information.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create an iSCSI CHAP secret
iscsiSecret := &libvirtxml.Secret{
Ephemeral: "no",
Private: "yes",
UUID: "8dea22b3-1d52-d8f3-2516-782e98ab3fa4",
Usage: &libvirtxml.SecretUsage{
Type: "iscsi",
Target: "iqn.2023-01.com.example:storage",
},
}
iscsiXML, _ := iscsiSecret.Marshal()
fmt.Println(iscsiXML)
}
```
--------------------------------
### Host Capabilities XML API
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
The Caps struct represents host capabilities including CPU features, NUMA topology, and supported guest architectures. This snippet demonstrates parsing host capabilities XML.
```APIDOC
## Host Capabilities XML API
### Description
The Caps struct represents host capabilities including CPU features, NUMA topology, and supported guest architectures.
### Method
N/A (This is a library usage example, not a direct API endpoint)
### Endpoint
N/A
### Parameters
N/A
### Request Example
```json
{
"host": {
"uuid": "44454c4c-4800-1036-8058-b8c04f595732",
"cpu": {
"arch": "x86_64",
"model": "Skylake-Server-IBRS",
"vendor": "Intel",
"topology": {
"sockets": 2,
"cores": 8,
"threads": 2
},
"features": [
{"name": "vmx"},
{"name": "avx2"},
{"name": "aes"}
]
},
"topology": {
"cells": [
{
"id": 0,
"memory": {"unit": "KiB", "value": 65536000},
"cpus": {
"num": 16,
"cpus": [
{"id": 0, "socket_id": 0, "core_id": 0}
]
}
}
]
}
},
"guest": [
{
"os_type": "hvm",
"arch": {
"name": "x86_64",
"wordsize": 64,
"emulator": "/usr/bin/qemu-system-x86_64",
"machine": {"maxCpus": 240, "name": "pc-q35-6.2"},
"domain": {"type": "kvm"}
}
}
]
}
```
### Response
#### Success Response (200)
N/A (This is a library usage example)
#### Response Example
```xml
44454c4c-4800-1036-8058-b8c04f595732
x86_64
Skylake-Server-IBRS
Intel
65536000
|
hvm
64
/usr/bin/qemu-system-x86_64
pc-q35-6.2
```
```
--------------------------------
### Create Volume Encryption Secret XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Defines a libvirt secret for volume encryption. Requires a UUID and the path to the encrypted volume.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create a volume encryption secret
volSecret := &libvirtxml.Secret{
Ephemeral: "no",
Private: "yes",
UUID: "9dea22b3-1d52-d8f3-2516-782e98ab3fa5",
Usage: &libvirtxml.SecretUsage{
Type: "volume",
Volume: "/var/lib/libvirt/images/encrypted.qcow2",
},
}
volXML, _ := volSecret.Marshal()
fmt.Println(volXML)
}
```
--------------------------------
### Create RBD (Ceph) Storage Pool XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Defines an RBD (Ceph) storage pool configuration. Requires Ceph monitor details and authentication credentials.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create an RBD (Ceph) storage pool
rbdPool := &libvirtxml.StoragePool{
Type: "rbd",
Name: "ceph-pool",
Source: &libvirtxml.StoragePoolSource{
Name: "libvirt-pool",
Host: []libvirtxml.StoragePoolSourceHost{
{Name: "mon1.ceph.local", Port: "6789"},
{Name: "mon2.ceph.local", Port: "6789"},
},
Auth: &libvirtxml.StoragePoolSourceAuth{
Type: "ceph",
Username: "libvirt",
Secret: &libvirtxml.StoragePoolSourceAuthSecret{
UUID: "secret-uuid-here",
},
},
},
}
rbdXML, _ := rbdPool.Marshal()
fmt.Println(rbdXML)
}
```
--------------------------------
### Parse Node Device XML in Go
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Parses an XML string representing a PCI node device into a libvirtxml.NodeDevice struct. Ensure the XML is valid and conforms to the expected schema.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Parse a PCI device XML (typically obtained from libvirt)
deviceXML := `
pci_0000_03_00_0
/sys/devices/pci0000:00/0000:00:01.0/0000:03:00.0
pci_0000_00_01_0
nvidia
0x030000
0
3
0
0
GeForce GTX 1080
NVIDIA Corporation
`
var device libvirtxml.NodeDevice
err := device.Unmarshal(deviceXML)
if err != nil {
panic(err)
}
fmt.Printf("Device: %s\n", device.Name)
fmt.Printf("Path: %s\n", device.Path)
if device.Driver != nil {
fmt.Printf("Driver: %s\n", device.Driver.Name)
}
if device.Capability.PCI != nil {
pci := device.Capability.PCI
fmt.Printf("PCI: %04x:%02x:%02x.%x\n", *pci.Domain, *pci.Bus, *pci.Slot, *pci.Function)
fmt.Printf("Product: %s (%s)\n", pci.Product.Name, pci.Product.ID)
fmt.Printf("Vendor: %s (%s)\n", pci.Vendor.Name, pci.Vendor.ID)
}
}
```
--------------------------------
### Domain Snapshot XML API
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
The DomainSnapshot struct represents VM snapshot configurations including disk states and memory snapshots. This snippet demonstrates creating and parsing domain snapshot XML.
```APIDOC
## Domain Snapshot XML API
### Description
The DomainSnapshot struct represents VM snapshot configurations including disk states and memory snapshots.
### Method
N/A (This is a library usage example, not a direct API endpoint)
### Endpoint
N/A
### Parameters
N/A
### Request Example
```json
{
"name": "pre-upgrade-snapshot",
"description": "Snapshot taken before system upgrade",
"memory": {
"snapshot": "internal"
},
"disks": {
"disks": [
{
"name": "vda",
"snapshot": "internal"
},
{
"name": "vdb",
"snapshot": "no"
}
]
}
}
```
### Response
#### Success Response (200)
N/A (This is a library usage example)
#### Response Example
```xml
pre-upgrade-snapshot
Snapshot taken before system upgrade
```
```
--------------------------------
### Create Ceph Authentication Secret XML
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
Defines a libvirt secret for Ceph authentication. Requires a UUID and usage details.
```go
package main
import (
"fmt"
"libvirt.org/go/libvirtxml"
)
func main() {
// Create a Ceph authentication secret
secretcfg := &libvirtxml.Secret{
Ephemeral: "no",
Private: "no",
Description: "Ceph client key for libvirt",
UUID: "7dea22b3-1d52-d8f3-2516-782e98ab3fa3",
Usage: &libvirtxml.SecretUsage{
Type: "ceph",
Name: "client.libvirt secret",
},
}
xmlStr, err := secretcfg.Marshal()
if err != nil {
panic(err)
}
fmt.Println(xmlStr)
}
```
--------------------------------
### Network Filter (NWFilter) XML API
Source: https://context7.com/libvirt/libvirt-go-xml-module/llms.txt
The NWFilter struct defines network traffic filtering rules for virtual machine interfaces. This snippet demonstrates creating a network filter with specific rules.
```APIDOC
## Network Filter (NWFilter) XML API
### Description
The NWFilter struct defines network traffic filtering rules for virtual machine interfaces.
### Method
N/A (This is a library usage example, not a direct API endpoint)
### Endpoint
N/A
### Parameters
N/A
### Request Example
```json
{
"name": "allow-ssh-http",
"chain": "root",
"priority": -700,
"entries": [
{
"ref": {
"filter": "clean-traffic"
}
},
{
"rule": {
"action": "accept",
"direction": "in",
"priority": 500,
"tcp": {
"dst_port_start": "22"
}
}
},
{
"rule": {
"action": "accept",
"direction": "in",
"priority": 500,
"tcp": {
"dst_port_start": "80"
}
}
},
{
"rule": {
"action": "accept",
"direction": "in",
"priority": 500,
"tcp": {
"dst_port_start": "443"
}
}
}
]
}
```
### Response
#### Success Response (200)
N/A (This is a library usage example)
#### Response Example
```xml
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.