Santhosh Kumar Gunturu
2020-Apr-28 15:51 UTC
Re: Libvirt APIs for creating virtual networks
Okay. Thanks. Do we have any facility APIs to set the DHCP Options via XML ? Default gateway ? Dns-server ? domain-name ? Thanks & Regards Santhosh Kumar Gunturu On Tue, Apr 28, 2020 at 8:47 AM Daniel P. Berrangé <berrange@redhat.com> wrote:> On Tue, Apr 28, 2020 at 08:39:06AM -0700, Santhosh Kumar Gunturu wrote: > > I am using the Libvirt APIs to create the virtual networks to use the > > dnsmasq capabilities. > > I want to understand the APIs how to set the lease time in XML to control > > the dnsmasq lease time. > > Support for controlling lease time in the XML was only added last week, > and so won't be available until the 6.3.0 release due out next week. > > > Also, I need some DHCP statistics on the virtual network. > > > > Is there any API available to fetch the statistics ? > > No, we don't report any kind of statisticcs > > Regards, > Daniel > -- > |: https://berrange.com -o- > https://www.flickr.com/photos/dberrange :| > |: https://libvirt.org -o- > https://fstop138.berrange.com :| > |: https://entangle-photo.org -o- > https://www.instagram.com/dberrange :| > >
On Tue, Apr 28, 2020 at 08:51:45AM -0700, Santhosh Kumar Gunturu wrote:> Okay. Thanks. > > Do we have any facility APIs to set the DHCP Options via XML ? > Default gateway ? > Dns-server ? > domain-name ?Everything is controlled through the XML document described here: https://libvirt.org/formatnetwork.html We don't have separate APIs for each piece of info - just the one virNetworkDefineXML API that takes the XML document. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
On 4/28/20 12:01 PM, Daniel P. Berrangé wrote:> On Tue, Apr 28, 2020 at 08:51:45AM -0700, Santhosh Kumar Gunturu wrote: >> Okay. Thanks. >> >> Do we have any facility APIs to set the DHCP Options via XML ? >> Default gateway ?libvirt has no supported method of specifying a default gateway other than the IP of the bridge device on the virtualization host it self, and DHCP clients on these networks will always end up getting their default gateway set to the IP address of that bridge. Fortunately (for you :-) that's not because libvirt is explicitly setting that address in the dnsmasq config file, but just because that's what dnsmasq does when no gateway address is specified in the config file. You would set this in the dnsmasq.conf file with dhcp-option, e.g.: dhcp-option=option-router,192.168.122.5 and recent libvirt (5.6.0 and newer) allows adding arbitrary lines to the dnsmasq.conf files it creates for its networks, using the <dnsmasq:options> element in the network XML. For details on how to do this, look at: https://libvirt.org/formatnetwork.html#elementsNamespaces>> Dns-server ?Not exact, but <forwarder addr='8.8.8.8'/> is *kind of* what you're looking for. It doesn't set the IP address sent back in the dhcp reply, but sets up the dnsmasq instance listening for the network to forward all requests on to 8.8.8.8 (you can also refine this to forward the requests for only certain domains, by adding "domain='example.com'" to the <forwarder> element). (If you *really* need to have the guest send DNS requests directly to the upstream DNS server rather than via dnsmasq, then you would need to use <dnsmasq:options> to set something like "dhcp-option=option-dns-server,8/8/8/8")>> domain-name ?domain can be set with "<domain name='example.com'/>".> > Everything is controlled through the XML document described here: > > https://libvirt.org/formatnetwork.html > > We don't have separate APIs for each piece of info - just the one > virNetworkDefineXML API that takes the XML document. > > Regards, > Daniel >