2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-06-30 05:14:26 -04:00
|
|
|
package virtwrapper
|
|
|
|
|
|
|
|
import "libvirt.org/go/libvirt"
|
|
|
|
|
2022-11-09 09:57:54 -05:00
|
|
|
// Connect wraps a libvirt connection.
|
2022-06-30 05:14:26 -04:00
|
|
|
type Connect struct {
|
|
|
|
Conn *libvirt.Connect
|
|
|
|
}
|
|
|
|
|
2022-11-09 09:57:54 -05:00
|
|
|
// LookupNetworkByName looks up a network by name.
|
2022-06-30 05:14:26 -04:00
|
|
|
func (c *Connect) LookupNetworkByName(name string) (*Network, error) {
|
|
|
|
net, err := c.Conn.LookupNetworkByName(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &Network{Net: net}, nil
|
|
|
|
}
|
|
|
|
|
2022-11-09 09:57:54 -05:00
|
|
|
// Network wraps a libvirt network.
|
2022-06-30 05:14:26 -04:00
|
|
|
type Network struct {
|
|
|
|
Net virNetwork
|
|
|
|
}
|
|
|
|
|
2022-11-09 09:57:54 -05:00
|
|
|
// GetDHCPLeases returns the underlying DHCP leases.
|
2022-06-30 05:14:26 -04:00
|
|
|
func (n *Network) GetDHCPLeases() ([]libvirt.NetworkDHCPLease, error) {
|
|
|
|
return n.Net.GetDHCPLeases()
|
|
|
|
}
|
|
|
|
|
2022-11-09 09:57:54 -05:00
|
|
|
// Free the network resource.
|
2022-06-30 05:14:26 -04:00
|
|
|
func (n *Network) Free() {
|
|
|
|
_ = n.Net.Free()
|
|
|
|
}
|
|
|
|
|
|
|
|
type virNetwork interface {
|
|
|
|
GetDHCPLeases() ([]libvirt.NetworkDHCPLease, error)
|
|
|
|
Free() error
|
|
|
|
}
|