2 * This file is part of the libvirt-go project
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * Copyright (c) 2013 Alex Zorin
23 * Copyright (C) 2016 Red Hat, Inc.
30 #cgo pkg-config: libvirt
32 #include "node_device_wrapper.h"
40 type NodeDeviceEventID int
43 NODE_DEVICE_EVENT_ID_LIFECYCLE = NodeDeviceEventID(C.VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE)
44 NODE_DEVICE_EVENT_ID_UPDATE = NodeDeviceEventID(C.VIR_NODE_DEVICE_EVENT_ID_UPDATE)
47 type NodeDeviceEventLifecycleType int
50 NODE_DEVICE_EVENT_CREATED = NodeDeviceEventLifecycleType(C.VIR_NODE_DEVICE_EVENT_CREATED)
51 NODE_DEVICE_EVENT_DELETED = NodeDeviceEventLifecycleType(C.VIR_NODE_DEVICE_EVENT_DELETED)
54 type NodeDevice struct {
55 ptr C.virNodeDevicePtr
58 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceFree
59 func (n *NodeDevice) Free() error {
61 ret := C.virNodeDeviceFreeWrapper(n.ptr, &err)
63 return makeError(&err)
68 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceRef
69 func (c *NodeDevice) Ref() error {
71 ret := C.virNodeDeviceRefWrapper(c.ptr, &err)
73 return makeError(&err)
78 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDestroy
79 func (n *NodeDevice) Destroy() error {
81 result := C.virNodeDeviceDestroyWrapper(n.ptr, &err)
83 return makeError(&err)
88 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceReset
89 func (n *NodeDevice) Reset() error {
91 result := C.virNodeDeviceResetWrapper(n.ptr, &err)
93 return makeError(&err)
98 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDettach
99 func (n *NodeDevice) Detach() error {
101 result := C.virNodeDeviceDettachWrapper(n.ptr, &err)
103 return makeError(&err)
108 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDetachFlags
109 func (n *NodeDevice) DetachFlags(driverName string, flags uint32) error {
110 cDriverName := C.CString(driverName)
111 defer C.free(unsafe.Pointer(cDriverName))
113 result := C.virNodeDeviceDetachFlagsWrapper(n.ptr, cDriverName, C.uint(flags), &err)
115 return makeError(&err)
120 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceReAttach
121 func (n *NodeDevice) ReAttach() error {
123 result := C.virNodeDeviceReAttachWrapper(n.ptr, &err)
125 return makeError(&err)
130 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetName
131 func (n *NodeDevice) GetName() (string, error) {
133 name := C.virNodeDeviceGetNameWrapper(n.ptr, &err)
135 return "", makeError(&err)
137 return C.GoString(name), nil
140 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetXMLDesc
141 func (n *NodeDevice) GetXMLDesc(flags uint32) (string, error) {
143 result := C.virNodeDeviceGetXMLDescWrapper(n.ptr, C.uint(flags), &err)
145 return "", makeError(&err)
147 xml := C.GoString(result)
148 C.free(unsafe.Pointer(result))
152 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetParent
153 func (n *NodeDevice) GetParent() (string, error) {
155 result := C.virNodeDeviceGetParentWrapper(n.ptr, &err)
157 return "", makeError(&err)
159 defer C.free(unsafe.Pointer(result))
160 return C.GoString(result), nil
163 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceNumOfCaps
164 func (p *NodeDevice) NumOfCaps() (int, error) {
166 result := int(C.virNodeDeviceNumOfCapsWrapper(p.ptr, &err))
168 return 0, makeError(&err)
173 // See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceListCaps
174 func (p *NodeDevice) ListCaps() ([]string, error) {
176 var names [maxCaps](*C.char)
177 namesPtr := unsafe.Pointer(&names)
179 numCaps := C.virNodeDeviceListCapsWrapper(
181 (**C.char)(namesPtr),
184 return nil, makeError(&err)
186 goNames := make([]string, numCaps)
187 for k := 0; k < int(numCaps); k++ {
188 goNames[k] = C.GoString(names[k])
189 C.free(unsafe.Pointer(names[k]))