2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-30 17:46:38 +00:00

Create macvtap VM nics

This commit is contained in:
Markus Hilger 2021-10-13 16:40:14 +02:00
parent 5219302ac8
commit 3f244c7ef1
2 changed files with 24 additions and 4 deletions

View File

@ -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.',

View File

@ -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
}
@ -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;
}
@ -3082,6 +3091,7 @@ 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);
}
@ -3089,6 +3099,7 @@ sub fixup_clone_network {
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}) {
@ -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);
}