mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 10:52:22 +00:00
Added support for non-bridged networking
This commit is contained in:
parent
caaf9441f3
commit
6d8b20ce85
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
Tue Nov 14 18:42:01 EST 2006 Daniel Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* src/xend_internal.c: Added support for parsing non-bridge style
|
||||||
|
networking configs for guests.
|
||||||
|
* src/xml.c: Ensure the <ip address> element gets serialized to
|
||||||
|
the SEXPR for non-bridged networks.
|
||||||
|
* tests/xml2sexprtest.c, tests/sexpr2xmltest.c: Added new tests
|
||||||
|
covering different networking configs
|
||||||
|
* tests/xml2sexprdata/, tests/sexpr2xmldata/: Added more data
|
||||||
|
files for new test cases
|
||||||
|
|
||||||
Mon Nov 13 17:18:00 CET 2006 Daniel Veillard <veillard@redhat.com>
|
Mon Nov 13 17:18:00 CET 2006 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* src/xend_internal.c src/xml.c: fix for shareable drive support
|
* src/xend_internal.c src/xml.c: fix for shareable drive support
|
||||||
|
@ -1700,38 +1700,35 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi
|
|||||||
if (drvType)
|
if (drvType)
|
||||||
free(drvType);
|
free(drvType);
|
||||||
} else if (sexpr_lookup(node, "device/vif")) {
|
} else if (sexpr_lookup(node, "device/vif")) {
|
||||||
const char *tmp2;
|
char *tmp2;
|
||||||
|
|
||||||
tmp = sexpr_node(node, "device/vif/bridge");
|
|
||||||
tmp2 = sexpr_node(node, "device/vif/script");
|
tmp2 = sexpr_node(node, "device/vif/script");
|
||||||
if ((tmp != NULL) || (strstr(tmp2, "bridge"))) {
|
if (tmp2 && strstr(tmp2, "bridge")) {
|
||||||
virBufferVSprintf(&buf, " <interface type='bridge'>\n");
|
virBufferVSprintf(&buf, " <interface type='bridge'>\n");
|
||||||
|
tmp = sexpr_node(node, "device/vif/bridge");
|
||||||
if (tmp != NULL)
|
if (tmp != NULL)
|
||||||
virBufferVSprintf(&buf, " <source bridge='%s'/>\n",
|
virBufferVSprintf(&buf, " <source bridge='%s'/>\n",
|
||||||
tmp);
|
tmp);
|
||||||
tmp = sexpr_node(node, "device/vif/vifname");
|
|
||||||
if (tmp != NULL)
|
|
||||||
virBufferVSprintf(&buf, " <target dev='%s'/>\n",
|
|
||||||
tmp);
|
|
||||||
tmp = sexpr_node(node, "device/vif/mac");
|
|
||||||
if (tmp != NULL)
|
|
||||||
virBufferVSprintf(&buf, " <mac address='%s'/>\n",
|
|
||||||
tmp);
|
|
||||||
tmp = sexpr_node(node, "device/vif/ip");
|
|
||||||
if (tmp != NULL)
|
|
||||||
virBufferVSprintf(&buf, " <ip address='%s'/>\n",
|
|
||||||
tmp);
|
|
||||||
if (tmp2 != NULL)
|
|
||||||
virBufferVSprintf(&buf, " <script path='%s'/>\n",
|
|
||||||
tmp2);
|
|
||||||
virBufferAdd(&buf, " </interface>\n", 17);
|
|
||||||
} else {
|
} else {
|
||||||
char serial[1000];
|
virBufferVSprintf(&buf, " <interface type='ethernet'>\n");
|
||||||
|
|
||||||
TODO sexpr2string(node, serial, 1000);
|
|
||||||
virBufferVSprintf(&buf, "<!-- Failed to parse vif: %s -->\n",
|
|
||||||
serial);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmp = sexpr_node(node, "device/vif/vifname");
|
||||||
|
if (tmp)
|
||||||
|
virBufferVSprintf(&buf, " <target dev='%s'/>\n",
|
||||||
|
tmp);
|
||||||
|
tmp = sexpr_node(node, "device/vif/mac");
|
||||||
|
if (tmp)
|
||||||
|
virBufferVSprintf(&buf, " <mac address='%s'/>\n",
|
||||||
|
tmp);
|
||||||
|
tmp = sexpr_node(node, "device/vif/ip");
|
||||||
|
if (tmp)
|
||||||
|
virBufferVSprintf(&buf, " <ip address='%s'/>\n",
|
||||||
|
tmp);
|
||||||
|
if (tmp2)
|
||||||
|
virBufferVSprintf(&buf, " <script path='%s'/>\n",
|
||||||
|
tmp2);
|
||||||
|
|
||||||
|
virBufferAdd(&buf, " </interface>\n", 17);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
src/xml.c
13
src/xml.c
@ -1118,6 +1118,7 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
|
|||||||
xmlChar *source = NULL;
|
xmlChar *source = NULL;
|
||||||
xmlChar *mac = NULL;
|
xmlChar *mac = NULL;
|
||||||
xmlChar *script = NULL;
|
xmlChar *script = NULL;
|
||||||
|
xmlChar *ip = NULL;
|
||||||
int typ = 0;
|
int typ = 0;
|
||||||
|
|
||||||
type = xmlGetProp(node, BAD_CAST "type");
|
type = xmlGetProp(node, BAD_CAST "type");
|
||||||
@ -1133,7 +1134,6 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
|
|||||||
if (cur->type == XML_ELEMENT_NODE) {
|
if (cur->type == XML_ELEMENT_NODE) {
|
||||||
if ((source == NULL) &&
|
if ((source == NULL) &&
|
||||||
(xmlStrEqual(cur->name, BAD_CAST "source"))) {
|
(xmlStrEqual(cur->name, BAD_CAST "source"))) {
|
||||||
|
|
||||||
if (typ == 0)
|
if (typ == 0)
|
||||||
source = xmlGetProp(cur, BAD_CAST "bridge");
|
source = xmlGetProp(cur, BAD_CAST "bridge");
|
||||||
else
|
else
|
||||||
@ -1144,6 +1144,13 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
|
|||||||
} else if ((script == NULL) &&
|
} else if ((script == NULL) &&
|
||||||
(xmlStrEqual(cur->name, BAD_CAST "script"))) {
|
(xmlStrEqual(cur->name, BAD_CAST "script"))) {
|
||||||
script = xmlGetProp(cur, BAD_CAST "path");
|
script = xmlGetProp(cur, BAD_CAST "path");
|
||||||
|
} else if ((ip == NULL) &&
|
||||||
|
(xmlStrEqual(cur->name, BAD_CAST "ip"))) {
|
||||||
|
/* XXX in future expect to need to have > 1 ip
|
||||||
|
address element - eg ipv4 & ipv6. For now
|
||||||
|
xen only supports a single address though
|
||||||
|
so lets ignore that complication */
|
||||||
|
ip = xmlGetProp(cur, BAD_CAST "address");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
@ -1160,6 +1167,8 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
|
|||||||
}
|
}
|
||||||
if (script != NULL)
|
if (script != NULL)
|
||||||
virBufferVSprintf(buf, "(script '%s')", script);
|
virBufferVSprintf(buf, "(script '%s')", script);
|
||||||
|
if (ip != NULL)
|
||||||
|
virBufferVSprintf(buf, "(ip '%s')", ip);
|
||||||
if (hvm)
|
if (hvm)
|
||||||
virBufferAdd(buf, "(type ioemu)", 12);
|
virBufferAdd(buf, "(type ioemu)", 12);
|
||||||
|
|
||||||
@ -1170,6 +1179,8 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
|
|||||||
xmlFree(source);
|
xmlFree(source);
|
||||||
if (script != NULL)
|
if (script != NULL)
|
||||||
xmlFree(script);
|
xmlFree(script);
|
||||||
|
if (ip != NULL)
|
||||||
|
xmlFree(ip);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
tests/sexpr2xmldata/sexpr2xml-net-bridged.sexpr
Normal file
2
tests/sexpr2xmldata/sexpr2xml-net-bridged.sexpr
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(bridge 'xenbr2')(script 'vif-bridge'))))
|
||||||
|
|
27
tests/sexpr2xmldata/sexpr2xml-net-bridged.xml
Normal file
27
tests/sexpr2xmldata/sexpr2xml-net-bridged.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<domain type='xen' id='6'>
|
||||||
|
<name>pvtest</name>
|
||||||
|
<uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
|
||||||
|
<os>
|
||||||
|
<type>linux</type>
|
||||||
|
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
|
||||||
|
<initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
|
||||||
|
<cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
|
||||||
|
</os>
|
||||||
|
<memory>430080</memory>
|
||||||
|
<vcpu>2</vcpu>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>destroy</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<disk type='file' device='disk'>
|
||||||
|
<driver name='file'/>
|
||||||
|
<source file='/root/some.img'/>
|
||||||
|
<target dev='xvda'/>
|
||||||
|
</disk>
|
||||||
|
<interface type='bridge'>
|
||||||
|
<source bridge='xenbr2'/>
|
||||||
|
<mac address='00:11:22:33:44:55'/>
|
||||||
|
<script path='vif-bridge'/>
|
||||||
|
</interface>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
2
tests/sexpr2xmldata/sexpr2xml-net-routed.sexpr
Normal file
2
tests/sexpr2xmldata/sexpr2xml-net-routed.sexpr
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(dev 'eth3')(script 'vif-routed')(ip '172.14.5.6')))
|
||||||
|
|
27
tests/sexpr2xmldata/sexpr2xml-net-routed.xml
Normal file
27
tests/sexpr2xmldata/sexpr2xml-net-routed.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<domain type='xen' id='6'>
|
||||||
|
<name>pvtest</name>
|
||||||
|
<uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
|
||||||
|
<os>
|
||||||
|
<type>linux</type>
|
||||||
|
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
|
||||||
|
<initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
|
||||||
|
<cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
|
||||||
|
</os>
|
||||||
|
<memory>430080</memory>
|
||||||
|
<vcpu>2</vcpu>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>destroy</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<disk type='file' device='disk'>
|
||||||
|
<driver name='file'/>
|
||||||
|
<source file='/root/some.img'/>
|
||||||
|
<target dev='xvda'/>
|
||||||
|
</disk>
|
||||||
|
<interface type='ethernet'>
|
||||||
|
<mac address='00:11:22:33:44:55'/>
|
||||||
|
<ip address='172.14.5.6'/>
|
||||||
|
<script path='vif-routed'/>
|
||||||
|
</interface>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
@ -97,6 +97,19 @@ static int testCompareResizedMemory(void *data ATTRIBUTE_UNUSED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int testCompareNetRouted(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareFiles("sexpr2xmldata/sexpr2xml-net-routed.xml",
|
||||||
|
"sexpr2xmldata/sexpr2xml-net-routed.sexpr",
|
||||||
|
1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int testCompareNetBridged(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareFiles("sexpr2xmldata/sexpr2xml-net-bridged.xml",
|
||||||
|
"sexpr2xmldata/sexpr2xml-net-bridged.sexpr",
|
||||||
|
1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -145,5 +158,13 @@ main(int argc, char **argv)
|
|||||||
1, testCompareResizedMemory, NULL) != 0)
|
1, testCompareResizedMemory, NULL) != 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
|
if (virtTestRun("SEXPR-2-XML net routed",
|
||||||
|
1, testCompareNetRouted, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
if (virtTestRun("SEXPR-2-XML net bridged",
|
||||||
|
1, testCompareNetBridged, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
1
tests/xml2sexprdata/xml2sexpr-net-bridged.sexpr
Normal file
1
tests/xml2sexprdata/xml2sexpr-net-bridged.sexpr
Normal file
@ -0,0 +1 @@
|
|||||||
|
(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(bridge 'xenbr2')(script 'vif-bridge'))))
|
29
tests/xml2sexprdata/xml2sexpr-net-bridged.xml
Normal file
29
tests/xml2sexprdata/xml2sexpr-net-bridged.xml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<domain type='xen' id='15'>
|
||||||
|
<name>pvtest</name>
|
||||||
|
<uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
|
||||||
|
<os>
|
||||||
|
<type>linux</type>
|
||||||
|
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
|
||||||
|
<initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
|
||||||
|
<cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
|
||||||
|
</os>
|
||||||
|
<memory>430080</memory>
|
||||||
|
<vcpu>2</vcpu>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>destroy</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<disk type='file' device='disk'>
|
||||||
|
<source file='/root/some.img'/>
|
||||||
|
<target dev='xvda'/>
|
||||||
|
</disk>
|
||||||
|
<interface type="bridge">
|
||||||
|
<mac address="00:11:22:33:44:55"/>
|
||||||
|
<source bridge="xenbr2"/>
|
||||||
|
<script path="vif-bridge"/>
|
||||||
|
<target dev="vif4.0"/>
|
||||||
|
</interface>
|
||||||
|
<console tty='/dev/pts/4'/>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
||||||
|
|
1
tests/xml2sexprdata/xml2sexpr-net-routed.sexpr
Normal file
1
tests/xml2sexprdata/xml2sexpr-net-routed.sexpr
Normal file
@ -0,0 +1 @@
|
|||||||
|
(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(dev 'eth3')(script 'vif-routed')(ip '172.14.5.6'))))
|
30
tests/xml2sexprdata/xml2sexpr-net-routed.xml
Normal file
30
tests/xml2sexprdata/xml2sexpr-net-routed.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<domain type='xen' id='15'>
|
||||||
|
<name>pvtest</name>
|
||||||
|
<uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
|
||||||
|
<os>
|
||||||
|
<type>linux</type>
|
||||||
|
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
|
||||||
|
<initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
|
||||||
|
<cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
|
||||||
|
</os>
|
||||||
|
<memory>430080</memory>
|
||||||
|
<vcpu>2</vcpu>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>destroy</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<disk type='file' device='disk'>
|
||||||
|
<source file='/root/some.img'/>
|
||||||
|
<target dev='xvda'/>
|
||||||
|
</disk>
|
||||||
|
<interface type="ethernet">
|
||||||
|
<mac address="00:11:22:33:44:55"/>
|
||||||
|
<ip address="172.14.5.6"/>
|
||||||
|
<source dev="eth3"/>
|
||||||
|
<script path="vif-routed"/>
|
||||||
|
<target dev="vif4.0"/>
|
||||||
|
</interface>
|
||||||
|
<console tty='/dev/pts/4'/>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
||||||
|
|
@ -138,6 +138,21 @@ static int testCompareMemoryResize(void *data ATTRIBUTE_UNUSED) {
|
|||||||
2);
|
2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int testCompareNetRouted(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareFiles("xml2sexprdata/xml2sexpr-net-routed.xml",
|
||||||
|
"xml2sexprdata/xml2sexpr-net-routed.sexpr",
|
||||||
|
"pvtest",
|
||||||
|
2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int testCompareNetBridged(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareFiles("xml2sexprdata/xml2sexpr-net-bridged.xml",
|
||||||
|
"xml2sexprdata/xml2sexpr-net-bridged.sexpr",
|
||||||
|
"pvtest",
|
||||||
|
2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -202,6 +217,13 @@ main(int argc, char **argv)
|
|||||||
1, testCompareMemoryResize, NULL) != 0)
|
1, testCompareMemoryResize, NULL) != 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
|
if (virtTestRun("XML-2-SEXPR Net Routed",
|
||||||
|
1, testCompareNetRouted, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
if (virtTestRun("XML-2-SEXPR Net Bridged",
|
||||||
|
1, testCompareNetBridged, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user