Re: [libvirt] [ 5/5] qemu domain allow to set ip address, peer address and route
On Mon, Apr 04, 2016 at 09:00:06PM +, Vasiliy Tolstov wrote: > Signed-off-by: Vasiliy Tolstov> --- > src/qemu/qemu_interface.c | 39 +++ > 1 file changed, 39 insertions(+) > > diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c > index 13a513152876..5729325fadb9 100644 > --- a/src/qemu/qemu_interface.c > +++ b/src/qemu/qemu_interface.c > @@ -474,6 +474,45 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, > if (virNetDevSetMAC(net->ifname, ) < 0) > goto cleanup; > > +for (j = 0; j < net->nips; j++) { > +virDomainNetIpDefPtr ip = net->ips[j]; > +unsigned int prefix = (ip->prefix > 0) ? ip->prefix : > +VIR_SOCKET_ADDR_DEFAULT_PREFIX; > +char *ipStr = virSocketAddrFormat(>address); > + > +VIR_DEBUG("Adding IP address '%s/%u' to '%s'", > + ipStr, ip->prefix, net->ifname); > + > +if (virNetDevSetIPAddress(net->ifname, >address, >peer, > prefix) < 0) { > +virReportError(VIR_ERR_SYSTEM_ERROR, > + _("Failed to set IP address '%s' on %s"), > + ipStr, net->ifname); > +VIR_FREE(ipStr); > +goto cleanup; > +} > +VIR_FREE(ipStr); > +} > + > +if (net->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP || > +net->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT) { > +if (virNetDevSetOnline(net->ifname, true) < 0) > +goto cleanup; With this call added, we break the unit tests, but that's easy to fix by adding a stub to the qemuxml2argvmock.c file, so I've made that change ACK Regards, Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [ 5/5] qemu domain allow to set ip address, peer address and route
Signed-off-by: Vasiliy Tolstov--- src/qemu/qemu_interface.c | 39 +++ 1 file changed, 39 insertions(+) diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index 13a513152876..5729325fadb9 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -474,6 +474,45 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, if (virNetDevSetMAC(net->ifname, ) < 0) goto cleanup; +for (j = 0; j < net->nips; j++) { +virDomainNetIpDefPtr ip = net->ips[j]; +unsigned int prefix = (ip->prefix > 0) ? ip->prefix : +VIR_SOCKET_ADDR_DEFAULT_PREFIX; +char *ipStr = virSocketAddrFormat(>address); + +VIR_DEBUG("Adding IP address '%s/%u' to '%s'", + ipStr, ip->prefix, net->ifname); + +if (virNetDevSetIPAddress(net->ifname, >address, >peer, prefix) < 0) { +virReportError(VIR_ERR_SYSTEM_ERROR, + _("Failed to set IP address '%s' on %s"), + ipStr, net->ifname); +VIR_FREE(ipStr); +goto cleanup; +} +VIR_FREE(ipStr); +} + +if (net->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP || +net->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT) { +if (virNetDevSetOnline(net->ifname, true) < 0) +goto cleanup; + +/* Set the routes */ +for (j = 0; j < net->nroutes; j++) { +virNetworkRouteDefPtr route = net->routes[j]; + +if (virNetDevAddRoute(net->ifname, + virNetworkRouteDefGetAddress(route), + virNetworkRouteDefGetPrefix(route), + virNetworkRouteDefGetGateway(route), + virNetworkRouteDefGetMetric(route)) < 0) { +goto cleanup; +} +} +} + + if (net->script && qemuExecuteEthernetScript(net->ifname, net->script) < 0) goto cleanup; -- 2.7.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list