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 "interface_wrapper.h"
40 type InterfaceXMLFlags int
43 INTERFACE_XML_INACTIVE = InterfaceXMLFlags(C.VIR_INTERFACE_XML_INACTIVE)
46 type Interface struct {
50 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceCreate
51 func (n *Interface) Create(flags uint32) error {
53 result := C.virInterfaceCreateWrapper(n.ptr, C.uint(flags), &err)
55 return makeError(&err)
60 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDestroy
61 func (n *Interface) Destroy(flags uint32) error {
63 result := C.virInterfaceDestroyWrapper(n.ptr, C.uint(flags), &err)
65 return makeError(&err)
70 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceIsActive
71 func (n *Interface) IsActive() (bool, error) {
73 result := C.virInterfaceIsActiveWrapper(n.ptr, &err)
75 return false, makeError(&err)
83 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetMACString
84 func (n *Interface) GetMACString() (string, error) {
86 result := C.virInterfaceGetMACStringWrapper(n.ptr, &err)
88 return "", makeError(&err)
90 mac := C.GoString(result)
94 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetName
95 func (n *Interface) GetName() (string, error) {
97 result := C.virInterfaceGetNameWrapper(n.ptr, &err)
99 return "", makeError(&err)
101 name := C.GoString(result)
105 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetXMLDesc
106 func (n *Interface) GetXMLDesc(flags InterfaceXMLFlags) (string, error) {
108 result := C.virInterfaceGetXMLDescWrapper(n.ptr, C.uint(flags), &err)
110 return "", makeError(&err)
112 xml := C.GoString(result)
113 C.free(unsafe.Pointer(result))
117 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceUndefine
118 func (n *Interface) Undefine() error {
120 result := C.virInterfaceUndefineWrapper(n.ptr, &err)
122 return makeError(&err)
127 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceFree
128 func (n *Interface) Free() error {
130 ret := C.virInterfaceFreeWrapper(n.ptr, &err)
132 return makeError(&err)
137 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceRef
138 func (c *Interface) Ref() error {
140 ret := C.virInterfaceRefWrapper(c.ptr, &err)
142 return makeError(&err)