Skip to content

Commit

Permalink
Merge pull request #7047 from Obihoernchen/vm-macvtap
Browse files Browse the repository at this point in the history
Create macvtap VM nics
  • Loading branch information
Obihoernchen authored Aug 28, 2024
2 parents 0570cda + 3f244c7 commit 3930b55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion perl-xCAT/xCAT/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ qq{ link,ro - The file is readonly, and will be placed in tmpfs on the booted no
'memory' => 'Megabytes of memory the VM currently should be set to.',
'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',
'cpus' => 'Number of CPUs the node should see.',
'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.',
'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.',
'nicmodel' => 'Model of NICs that will be provided to VMs (i.e. e1000, rtl8139, virtio, etc)',
'bootorder' => 'Boot sequence (i.e. net,hd)',
'clockoffset' => 'Whether to have guest RTC synced to "localtime" or "utc" If not populated, xCAT will guess based on the nodetype.os contents.',
Expand Down
26 changes: 23 additions & 3 deletions xCAT-server/lib/xcat/plugins/kvm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ sub build_nicstruct {
my $rethash;
my $nic = shift @nics;
my $type = 'virtio'; #better default fake nic than rtl8139, relevant to most
my $nictype = 'bridge';
unless ($nic) {
last; #Don't want to have multiple vnics tied to the same switch
}
Expand All @@ -666,9 +667,17 @@ sub build_nicstruct {
if ($nic =~ /=/) {
($nic, $type) = split /=/, $nic, 2;
}
$rethash->{type} = 'bridge';
if ($nic =~ /\|/) {
($nic, $nictype) = split /\|/, $nic, 2;
}
$rethash->{type} = $nictype;
$rethash->{mac}->{address} = $_;
$rethash->{source}->{bridge} = $nic;
if ($nictype eq 'bridge') {
$rethash->{source}->{bridge} = $nic;
} elsif ($nictype eq 'direct') {
$rethash->{source}->{dev} = $nic;
$rethash->{source}->{mode} = 'bridge';
}
$rethash->{model}->{type} = $type;
push @rethashes, $rethash;
}
Expand Down Expand Up @@ -3082,13 +3091,15 @@ sub fixup_clone_network {
my $bridge = shift @nics;
$bridge =~ s/.*://;
$bridge =~ s/=.*//;
$bridge =~ s/\|.*//;
$nicstruct->findnodes("./mac")->[0]->setAttribute("address" => shift @macs);
$nicstruct->findnodes("./source")->[0]->setAttribute("bridge" => $bridge);
}
my $nic;
my $deviceroot = $newnodexml->findnodes("/domain/devices")->[0];
foreach $nic (@nics) { #need more xml to throw at it..
my $type = 'virtio'; #better default fake nic than rtl8139, relevant to most
my $nictype = 'bridge';
$nic =~ s/.*://; #the detail of how the bridge was built is of no
#interest to this segment of code
if ($confdata->{vm}->{$node}->[0]->{nicmodel}) {
Expand All @@ -3097,7 +3108,16 @@ sub fixup_clone_network {
if ($nic =~ /=/) {
($nic, $type) = split /=/, $nic, 2;
}
my $xmlsnippet = "<interface type='bridge'><mac address='" . (shift @macs) . "'/><source bridge='" . $nic . "'/><model type='$type'/></interface>";
if ($nic =~ /\|/) {
($nic, $nictype) = split /\|/, $nic, 2;
}
my $xmlsnippet = "<interface type='" . $nictype . "'><mac address='" . (shift @macs) . "'/>";
if ($nictype eq 'bridge') {
$xmlsnippet .= "<source bridge='" . $nic . "'/>";
} elsif ($nictype eq 'direct') {
$xmlsnippet .= "<source dev='" . $nic . "' mode='bridge'/>";
}
$xmlsnippet .= "<model type='$type'/></interface>";
my $chunk = $parser->parse_balanced_chunk($xmlsnippet);
$deviceroot->appendChild($chunk);
}
Expand Down

0 comments on commit 3930b55

Please sign in to comment.