Skip to content

Commit 3930b55

Browse files
authored
Merge pull request #7047 from Obihoernchen/vm-macvtap
Create macvtap VM nics
2 parents 0570cda + 3f244c7 commit 3930b55

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

perl-xCAT/xCAT/Schema.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ qq{ link,ro - The file is readonly, and will be placed in tmpfs on the booted no
209209
'memory' => 'Megabytes of memory the VM currently should be set to.',
210210
'master' => 'The name of a master image, if any, this virtual machine is linked to. This is generally set by clonevm and indicates the deletion of a master that would invalidate the storage of this virtual machine',
211211
'cpus' => 'Number of CPUs the node should see.',
212-
'nics' => 'Network configuration parameters. Of the general form [physnet:]interface,.. Generally, interface describes the vlan entity (default for native, tagged for tagged, vl[number] for a specific vlan. physnet is a virtual switch name or port description that is used for some virtualization technologies to construct virtual switches. hypervisor.netmap can map names to hypervisor specific layouts, or the descriptions described there may be used directly here where possible.',
212+
'nics' => 'Network configuration parameters. Of the general form [physnet:]interface,.. Generally, interface describes the vlan entity (default for native, tagged for tagged, vl[number] for a specific vlan. physnet is a virtual switch name or port description that is used for some virtualization technologies to construct virtual switches. hypervisor.netmap can map names to hypervisor specific layouts, or the descriptions described there may be used directly here where possible. A macvtap device can be created by adding the "|direct" suffix to the interface name.',
213213
'nicmodel' => 'Model of NICs that will be provided to VMs (i.e. e1000, rtl8139, virtio, etc)',
214214
'bootorder' => 'Boot sequence (i.e. net,hd)',
215215
'clockoffset' => 'Whether to have guest RTC synced to "localtime" or "utc" If not populated, xCAT will guess based on the nodetype.os contents.',

xCAT-server/lib/xcat/plugins/kvm.pm

+23-3
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ sub build_nicstruct {
655655
my $rethash;
656656
my $nic = shift @nics;
657657
my $type = 'virtio'; #better default fake nic than rtl8139, relevant to most
658+
my $nictype = 'bridge';
658659
unless ($nic) {
659660
last; #Don't want to have multiple vnics tied to the same switch
660661
}
@@ -666,9 +667,17 @@ sub build_nicstruct {
666667
if ($nic =~ /=/) {
667668
($nic, $type) = split /=/, $nic, 2;
668669
}
669-
$rethash->{type} = 'bridge';
670+
if ($nic =~ /\|/) {
671+
($nic, $nictype) = split /\|/, $nic, 2;
672+
}
673+
$rethash->{type} = $nictype;
670674
$rethash->{mac}->{address} = $_;
671-
$rethash->{source}->{bridge} = $nic;
675+
if ($nictype eq 'bridge') {
676+
$rethash->{source}->{bridge} = $nic;
677+
} elsif ($nictype eq 'direct') {
678+
$rethash->{source}->{dev} = $nic;
679+
$rethash->{source}->{mode} = 'bridge';
680+
}
672681
$rethash->{model}->{type} = $type;
673682
push @rethashes, $rethash;
674683
}
@@ -3082,13 +3091,15 @@ sub fixup_clone_network {
30823091
my $bridge = shift @nics;
30833092
$bridge =~ s/.*://;
30843093
$bridge =~ s/=.*//;
3094+
$bridge =~ s/\|.*//;
30853095
$nicstruct->findnodes("./mac")->[0]->setAttribute("address" => shift @macs);
30863096
$nicstruct->findnodes("./source")->[0]->setAttribute("bridge" => $bridge);
30873097
}
30883098
my $nic;
30893099
my $deviceroot = $newnodexml->findnodes("/domain/devices")->[0];
30903100
foreach $nic (@nics) { #need more xml to throw at it..
30913101
my $type = 'virtio'; #better default fake nic than rtl8139, relevant to most
3102+
my $nictype = 'bridge';
30923103
$nic =~ s/.*://; #the detail of how the bridge was built is of no
30933104
#interest to this segment of code
30943105
if ($confdata->{vm}->{$node}->[0]->{nicmodel}) {
@@ -3097,7 +3108,16 @@ sub fixup_clone_network {
30973108
if ($nic =~ /=/) {
30983109
($nic, $type) = split /=/, $nic, 2;
30993110
}
3100-
my $xmlsnippet = "<interface type='bridge'><mac address='" . (shift @macs) . "'/><source bridge='" . $nic . "'/><model type='$type'/></interface>";
3111+
if ($nic =~ /\|/) {
3112+
($nic, $nictype) = split /\|/, $nic, 2;
3113+
}
3114+
my $xmlsnippet = "<interface type='" . $nictype . "'><mac address='" . (shift @macs) . "'/>";
3115+
if ($nictype eq 'bridge') {
3116+
$xmlsnippet .= "<source bridge='" . $nic . "'/>";
3117+
} elsif ($nictype eq 'direct') {
3118+
$xmlsnippet .= "<source dev='" . $nic . "' mode='bridge'/>";
3119+
}
3120+
$xmlsnippet .= "<model type='$type'/></interface>";
31013121
my $chunk = $parser->parse_balanced_chunk($xmlsnippet);
31023122
$deviceroot->appendChild($chunk);
31033123
}

0 commit comments

Comments
 (0)