Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> --- network.go | 80 ++++++++++++++ network_port.go | 233 ++++++++++++++++++++++++++++++++++++++++ network_port_compat.h | 67 ++++++++++++ network_port_wrapper.go | 197 +++++++++++++++++++++++++++++++++ network_port_wrapper.h | 79 ++++++++++++++ network_wrapper.go | 73 +++++++++++++ network_wrapper.h | 23 ++++ 7 files changed, 752 insertions(+) create mode 100644 network_port.go create mode 100644 network_port_compat.h create mode 100644 network_port_wrapper.go create mode 100644 network_port_wrapper.h diff --git a/network.go b/network.go index 99954aa..a0bc361 100644 --- a/network.go +++ b/network.go @@ -34,6 +34,7 @@ package libvirt import "C" import ( + "fmt" "reflect" "time" "unsafe" @@ -333,3 +334,82 @@ func (n *Network) GetDHCPLeases() ([]NetworkDHCPLease, error) { C.free(unsafe.Pointer(cLeases)) return leases, nil } + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkPortLookupByUUIDString +func (n *Network) LookupNetworkPortByUUIDString(uuid string) (*NetworkPort, error) { + if C.LIBVIR_VERSION_NUMBER < 5005000 { + return nil, makeNotImplementedError("virNetworkPortLookupByUUIDString") + } + + cUuid := C.CString(uuid) + defer C.free(unsafe.Pointer(cUuid)) + var err C.virError + ptr := C.virNetworkPortLookupByUUIDStringWrapper(n.ptr, cUuid, &err) + if ptr == nil { + return nil, makeError(&err) + } + return &NetworkPort{ptr: ptr}, nil +} + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkPortLookupByUUID +func (n *Network) LookupNetworkPortByUUID(uuid []byte) (*NetworkPort, error) { + if C.LIBVIR_VERSION_NUMBER < 5005000 { + return nil, makeNotImplementedError("virNetworkPortLookupByUUID") + } + + if len(uuid) != C.VIR_UUID_BUFLEN { + return nil, fmt.Errorf("UUID must be exactly %d bytes in size", + int(C.VIR_UUID_BUFLEN)) + } + cUuid := make([]C.uchar, C.VIR_UUID_BUFLEN) + for i := 0; i < C.VIR_UUID_BUFLEN; i++ { + cUuid[i] = C.uchar(uuid[i]) + } + var err C.virError + ptr := C.virNetworkPortLookupByUUIDWrapper(n.ptr, &cUuid[0], &err) + if ptr == nil { + return nil, makeError(&err) + } + return &NetworkPort{ptr: ptr}, nil +} + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkPortCreateXML +func (n *Network) PortCreateXML(xmlConfig string, flags uint) (*NetworkPort, error) { + if C.LIBVIR_VERSION_NUMBER < 5005000 { + return nil, makeNotImplementedError("virNetworkPortCreateXML") + } + cXml := C.CString(string(xmlConfig)) + defer C.free(unsafe.Pointer(cXml)) + var err C.virError + ptr := C.virNetworkPortCreateXMLWrapper(n.ptr, cXml, C.uint(flags), &err) + if ptr == nil { + return nil, makeError(&err) + } + return &NetworkPort{ptr: ptr}, nil +} + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkListAllPorts +func (n *Network) ListAllPorts(flags uint) ([]NetworkPort, error) { + if C.LIBVIR_VERSION_NUMBER < 5005000 { + return []NetworkPort{}, makeNotImplementedError("virNetworkListAllPorts") + } + + var cList *C.virNetworkPortPtr + var err C.virError + numPorts := C.virNetworkListAllPortsWrapper(n.ptr, (**C.virNetworkPortPtr)(&cList), C.uint(flags), &err) + if numPorts == -1 { + return []NetworkPort{}, makeError(&err) + } + hdr := reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(cList)), + Len: int(numPorts), + Cap: int(numPorts), + } + var ports []NetworkPort + slice := *(*[]C.virNetworkPortPtr)(unsafe.Pointer(&hdr)) + for _, ptr := range slice { + ports = append(ports, NetworkPort{ptr}) + } + C.free(unsafe.Pointer(cList)) + return ports, nil +} diff --git a/network_port.go b/network_port.go new file mode 100644 index 0000000..e701c2d --- /dev/null +++ b/network_port.go @@ -0,0 +1,233 @@ +/* + * This file is part of the libvirt-go project + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * Copyright (C) 2019 Red Hat, Inc. + * + */ + +package libvirt + +/* +#cgo pkg-config: libvirt +#include <stdlib.h> +#include "network_port_wrapper.h" +*/ +import "C" + +import ( + "unsafe" +) + +type NetworkPortCreateFlags int + +const ( + NETWORK_PORT_CREATE_RECLAIM = NetworkPortCreateFlags(C.VIR_NETWORK_PORT_CREATE_RECLAIM) +) + +type NetworkPort struct { + ptr C.virNetworkPortPtr +} + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkPortFree +func (n *NetworkPort) Free() error { + if C.LIBVIR_VERSION_NUMBER < 5005000 { + return makeNotImplementedError("virNetworkPortFree") + } + + var err C.virError + ret := C.virNetworkPortFreeWrapper(n.ptr, &err) + if ret == -1 { + return makeError(&err) + } + return nil +} + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkPortRef +func (c *NetworkPort) Ref() error { + if C.LIBVIR_VERSION_NUMBER < 5005000 { + return makeNotImplementedError("virNetworkPortRef") + } + + var err C.virError + ret := C.virNetworkPortRefWrapper(c.ptr, &err) + if ret == -1 { + return makeError(&err) + } + return nil +} + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkPortGetUUID +func (n *NetworkPort) GetUUID() ([]byte, error) { + if C.LIBVIR_VERSION_NUMBER < 5005000 { + return []byte{}, makeNotImplementedError("virNetworkPortGetUUID") + } + + var cUuid [C.VIR_UUID_BUFLEN](byte) + cuidPtr := unsafe.Pointer(&cUuid) + var err C.virError + result := C.virNetworkPortGetUUIDWrapper(n.ptr, (*C.uchar)(cuidPtr), &err) + if result != 0 { + return []byte{}, makeError(&err) + } + return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil +} + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkPortGetUUIDString +func (n *NetworkPort) GetUUIDString() (string, error) { + if C.LIBVIR_VERSION_NUMBER < 5005000 { + return "", makeNotImplementedError("virNetworkPortGetUUIDString") + } + + var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char) + cuidPtr := unsafe.Pointer(&cUuid) + var err C.virError + result := C.virNetworkPortGetUUIDStringWrapper(n.ptr, (*C.char)(cuidPtr), &err) + if result != 0 { + return "", makeError(&err) + } + return C.GoString((*C.char)(cuidPtr)), nil +} + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkPortDelete +func (n *NetworkPort) Delete(flags uint) error { + if C.LIBVIR_VERSION_NUMBER < 5005000 { + return makeNotImplementedError("virNetworkPortDelete") + } + + var err C.virError + result := C.virNetworkPortDeleteWrapper(n.ptr, C.uint(flags), &err) + if result == -1 { + return makeError(&err) + } + return nil +} + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkPortGetXMLDesc +func (d *NetworkPort) GetXMLDesc(flags uint) (string, error) { + var err C.virError + result := C.virNetworkPortGetXMLDescWrapper(d.ptr, C.uint(flags), &err) + if result == nil { + return "", makeError(&err) + } + xml := C.GoString(result) + C.free(unsafe.Pointer(result)) + return xml, nil +} + +type NetworkPortParameters struct { + BandwidthInAverageSet bool + BandwidthInAverage uint + BandwidthInPeakSet bool + BandwidthInPeak uint + BandwidthInBurstSet bool + BandwidthInBurst uint + BandwidthInFloorSet bool + BandwidthInFloor uint + BandwidthOutAverageSet bool + BandwidthOutAverage uint + BandwidthOutPeakSet bool + BandwidthOutPeak uint + BandwidthOutBurstSet bool + BandwidthOutBurst uint +} + +func getNetworkPortParametersFieldInfo(params *NetworkPortParameters) map[string]typedParamsFieldInfo { + return map[string]typedParamsFieldInfo{ + C.VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE: typedParamsFieldInfo{ + set: ¶ms.BandwidthInAverageSet, + ui: ¶ms.BandwidthInAverage, + }, + C.VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK: typedParamsFieldInfo{ + set: ¶ms.BandwidthInPeakSet, + ui: ¶ms.BandwidthInPeak, + }, + C.VIR_NETWORK_PORT_BANDWIDTH_IN_BURST: typedParamsFieldInfo{ + set: ¶ms.BandwidthInBurstSet, + ui: ¶ms.BandwidthInBurst, + }, + C.VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR: typedParamsFieldInfo{ + set: ¶ms.BandwidthInFloorSet, + ui: ¶ms.BandwidthInFloor, + }, + C.VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE: typedParamsFieldInfo{ + set: ¶ms.BandwidthOutAverageSet, + ui: ¶ms.BandwidthOutAverage, + }, + C.VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK: typedParamsFieldInfo{ + set: ¶ms.BandwidthOutPeakSet, + ui: ¶ms.BandwidthOutPeak, + }, + C.VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST: typedParamsFieldInfo{ + set: ¶ms.BandwidthOutBurstSet, + ui: ¶ms.BandwidthOutBurst, + }, + } +} + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkPortGetParameters +func (d *NetworkPort) GetParameters(flags uint) (*NetworkPortParameters, error) { + if C.LIBVIR_VERSION_NUMBER < 5005000 { + return nil, makeNotImplementedError("virNetworkPortGetParameters") + } + + params := &NetworkPortParameters{} + info := getNetworkPortParametersFieldInfo(params) + + var cparams C.virTypedParameterPtr + var cnparams C.int + var err C.virError + ret := C.virNetworkPortGetParametersWrapper(d.ptr, &cparams, &cnparams, C.uint(flags), &err) + if ret == -1 { + return nil, makeError(&err) + } + + defer C.virTypedParamsFree(cparams, cnparams) + + _, gerr := typedParamsUnpack(cparams, cnparams, info) + if gerr != nil { + return nil, gerr + } + + return params, nil +} + +// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkPortSetParameters +func (d *NetworkPort) SetParameters(params *NetworkPortParameters, flags uint) error { + if C.LIBVIR_VERSION_NUMBER < 5005000 { + return makeNotImplementedError("virNetworkPortSetParameters") + } + + info := getNetworkPortParametersFieldInfo(params) + + cparams, cnparams, gerr := typedParamsPackNew(info) + if gerr != nil { + return gerr + } + defer C.virTypedParamsFree(cparams, cnparams) + + var err C.virError + ret := C.virNetworkPortSetParametersWrapper(d.ptr, cparams, cnparams, C.uint(flags), &err) + if ret == -1 { + return makeError(&err) + } + + return nil +} diff --git a/network_port_compat.h b/network_port_compat.h new file mode 100644 index 0000000..77f541b --- /dev/null +++ b/network_port_compat.h @@ -0,0 +1,67 @@ +/* + * This file is part of the libvirt-go project + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * Copyright (C) 2019 Red Hat, Inc. + * + */ + +#ifndef LIBVIRT_GO_NETWORK_PORT_COMPAT_H__ +#define LIBVIRT_GO_NETWORK_PORT_COMPAT_H__ + +/* 5.5.0 */ + +#if LIBVIR_VERSION_NUMBER < 5005000 +typedef struct _virNetworkPort *virNetworkPortPtr; +#endif + +#ifndef VIR_NETWORK_PORT_CREATE_RECLAIM +#define VIR_NETWORK_PORT_CREATE_RECLAIM (1 << 0) +#endif + +#ifndef VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE +#define VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE "inbound.average" +#endif + +#ifndef VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK +#define VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK "inbound.peak" +#endif + +#ifndef VIR_NETWORK_PORT_BANDWIDTH_IN_BURST +#define VIR_NETWORK_PORT_BANDWIDTH_IN_BURST "inbound.burst" +#endif + +#ifndef VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR +#define VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR "inbound.floor" +#endif + +#ifndef VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE +#define VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE "outbound.average" +#endif + +#ifndef VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK +#define VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK "outbound.peak" +#endif + +#ifndef VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST +#define VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST "outbound.burst" +#endif + +#endif /* LIBVIRT_GO_NETWORK_PORT_COMPAT_H__ */ diff --git a/network_port_wrapper.go b/network_port_wrapper.go new file mode 100644 index 0000000..2b69167 --- /dev/null +++ b/network_port_wrapper.go @@ -0,0 +1,197 @@ +/* + * This file is part of the libvirt-go project + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * Copyright (C) 2019 Red Hat, Inc. + * + */ + +package libvirt + +/* +#cgo pkg-config: libvirt +#include <assert.h> +#include "network_port_wrapper.h" + +virNetworkPtr +virNetworkPortGetNetworkWrapper(virNetworkPortPtr port, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + virNetworkPtr ret; + ret = virNetworkPortGetNetwork(port); + if (!ret) { + virCopyLastError(err); + } + return ret; +#endif +} + + +char * +virNetworkPortGetXMLDescWrapper(virNetworkPortPtr port, + unsigned int flags, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + char *ret; + ret = virNetworkPortGetXMLDesc(port, flags); + if (!ret) { + virCopyLastError(err); + } + return ret; +#endif +} + + +int +virNetworkPortGetUUIDWrapper(virNetworkPortPtr port, + unsigned char *uuid, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + int ret; + ret = virNetworkPortGetUUID(port, uuid); + if (ret < 0) { + virCopyLastError(err); + } + return ret; +#endif +} + + +int +virNetworkPortGetUUIDStringWrapper(virNetworkPortPtr port, + char *buf, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + int ret; + ret = virNetworkPortGetUUIDString(port, buf); + if (ret < 0) { + virCopyLastError(err); + } + return ret; +#endif +} + + +int +virNetworkPortSetParametersWrapper(virNetworkPortPtr port, + virTypedParameterPtr params, + int nparams, + unsigned int flags, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + int ret; + ret = virNetworkPortSetParameters(port, params, nparams, flags); + if (ret < 0) { + virCopyLastError(err); + } + return ret; +#endif +} + + +int +virNetworkPortGetParametersWrapper(virNetworkPortPtr port, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + int ret; + ret = virNetworkPortGetParameters(port, params, nparams, flags); + if (ret < 0) { + virCopyLastError(err); + } + return ret; +#endif +} + + +int +virNetworkPortDeleteWrapper(virNetworkPortPtr port, + unsigned int flags, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + int ret; + ret = virNetworkPortDelete(port, flags); + if (ret < 0) { + virCopyLastError(err); + } + return ret; +#endif +} + + +int +virNetworkPortFreeWrapper(virNetworkPortPtr port, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + int ret; + ret = virNetworkPortFree(port); + if (ret < 0) { + virCopyLastError(err); + } + return ret; +#endif +} + + +int +virNetworkPortRefWrapper(virNetworkPortPtr port, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + int ret; + ret = virNetworkPortRef(port); + if (ret < 0) { + virCopyLastError(err); + } + return ret; +#endif +} + + +*/ +import "C" diff --git a/network_port_wrapper.h b/network_port_wrapper.h new file mode 100644 index 0000000..054d459 --- /dev/null +++ b/network_port_wrapper.h @@ -0,0 +1,79 @@ +/* + * This file is part of the libvirt-go project + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * Copyright (C) 2019 Red Hat, Inc. + * + */ + +#ifndef LIBVIRT_GO_NETWORK_PORT_WRAPPER_H__ +#define LIBVIRT_GO_NETWORK_PORT_WRAPPER_H__ + +#include <libvirt/libvirt.h> +#include <libvirt/virterror.h> +#include "network_port_compat.h" + + +virNetworkPtr +virNetworkPortGetNetworkWrapper(virNetworkPortPtr port, + virErrorPtr err); + +char * +virNetworkPortGetXMLDescWrapper(virNetworkPortPtr port, + unsigned int flags, + virErrorPtr err); + +int +virNetworkPortGetUUIDWrapper(virNetworkPortPtr port, + unsigned char *uuid, + virErrorPtr err); +int +virNetworkPortGetUUIDStringWrapper(virNetworkPortPtr port, + char *buf, + virErrorPtr err); + +int +virNetworkPortSetParametersWrapper(virNetworkPortPtr port, + virTypedParameterPtr params, + int nparams, + unsigned int flags, + virErrorPtr err); +int +virNetworkPortGetParametersWrapper(virNetworkPortPtr port, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags, + virErrorPtr err); + +int +virNetworkPortDeleteWrapper(virNetworkPortPtr port, + unsigned int flags, + virErrorPtr err); + +int +virNetworkPortFreeWrapper(virNetworkPortPtr port, + virErrorPtr err); + +int +virNetworkPortRefWrapper(virNetworkPortPtr port, + virErrorPtr err); + + +#endif /* LIBVIRT_GO_NETWORK_PORT_WRAPPER_H__ */ diff --git a/network_wrapper.go b/network_wrapper.go index 2fc443f..6105612 100644 --- a/network_wrapper.go +++ b/network_wrapper.go @@ -263,5 +263,78 @@ virNetworkUpdateWrapper(virNetworkPtr network, } +virNetworkPortPtr +virNetworkPortLookupByUUIDWrapper(virNetworkPtr net, + const unsigned char *uuid, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + virNetworkPortPtr ret; + ret = virNetworkPortLookupByUUID(net, uuid); + if (!ret) { + virCopyLastError(err); + } + return ret; +#endif +} + +virNetworkPortPtr +virNetworkPortLookupByUUIDStringWrapper(virNetworkPtr net, + const char *uuidstr, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + virNetworkPortPtr ret; + ret = virNetworkPortLookupByUUIDString(net, uuidstr); + if (!ret) { + virCopyLastError(err); + } + return ret; +#endif +} + + +virNetworkPortPtr +virNetworkPortCreateXMLWrapper(virNetworkPtr net, + const char *xmldesc, + unsigned int flags, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + virNetworkPortPtr ret; + ret = virNetworkPortCreateXML(net, xmldesc, flags); + if (!ret) { + virCopyLastError(err); + } + return ret; +#endif +} + + +int +virNetworkListAllPortsWrapper(virNetworkPtr network, + virNetworkPortPtr **ports, + unsigned int flags, + virErrorPtr err) +{ +#if LIBVIR_VERSION_NUMBER < 5005000 + assert(0); // Caller should have checked version +#else + int ret; + ret = virNetworkListAllPorts(network, ports, flags); + if (ret < 0) { + virCopyLastError(err); + } + return ret; +#endif +} + + */ import "C" diff --git a/network_wrapper.h b/network_wrapper.h index 405bf89..d76167b 100644 --- a/network_wrapper.h +++ b/network_wrapper.h @@ -30,6 +30,7 @@ #include <libvirt/libvirt.h> #include <libvirt/virterror.h> #include "network_compat.h" +#include "network_port_compat.h" int virNetworkCreateWrapper(virNetworkPtr network, @@ -115,5 +116,27 @@ virNetworkUpdateWrapper(virNetworkPtr network, unsigned int flags, virErrorPtr err); +virNetworkPortPtr +virNetworkPortLookupByUUIDWrapper(virNetworkPtr net, + const unsigned char *uuid, + virErrorPtr err); + +virNetworkPortPtr +virNetworkPortLookupByUUIDStringWrapper(virNetworkPtr net, + const char *uuidstr, + virErrorPtr err); + +virNetworkPortPtr +virNetworkPortCreateXMLWrapper(virNetworkPtr net, + const char *xmldesc, + unsigned int flags, + virErrorPtr err); + +int +virNetworkListAllPortsWrapper(virNetworkPtr network, + virNetworkPortPtr **ports, + unsigned int flags, + virErrorPtr err); + #endif /* LIBVIRT_GO_NETWORK_WRAPPER_H__ */ -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list