Commit cee91e7e authored by Fernando Verdugo's avatar Fernando Verdugo
Browse files

fix(renewMAC): pulish code

Issue #1232
parent 0cbba594
......@@ -1612,7 +1612,7 @@ sub _xml_modify_network {
my $doc = shift;
my $network = shift;
my ($type, $source );
my ($type, $source );
if (ref($network) =~ /^Ravada/) {
($type, $source) = ($network->type , $network->source);
} else {
......@@ -1999,7 +1999,7 @@ sub _xml_modify_mac {
my @old_macs;
for my $dom ($self->vm->list_all_domains) {
my $doc = $XML->load_xml(string => $dom->get_xml_description()) or die "ERROR: $!\n";
my $doc = $XML->load_xml(string => $dom->get_xml_description()) or die "ERROR: $!\n";
for my $nic ( $doc->findnodes('/domain/devices/interface/mac')) {
my $nic_mac = $nic->getAttribute('address');
......@@ -2007,37 +2007,37 @@ sub _xml_modify_mac {
}
}
for my $if_mac ($doc->findnodes('/domain/devices/interface/mac') ) {
my $mac = $if_mac->getAttribute('address');
my @macparts0 = split/:/,$mac;
my $new_mac;
my @tried;
my $foundit;
for ( 1 .. 1000 ) {
for my $cont ( 1 .. 1000 ) {
my @macparts = @macparts0;
my $pos = int(rand(scalar(@macparts)-3))+3;
my $num =sprintf "%02X", rand(0xff);
die "Missing num " if !defined $num;
$macparts[$pos] = $num;
$new_mac = lc(join(":",@macparts));
push @tried,($new_mac);
last if !grep /^$new_mac$/i,@old_macs && $self->_unique_mac($new_mac);
push @old_macs,($new_mac);
}
if ( $self->_unique_mac($new_mac) ) {
$if_mac->setAttribute(address => $new_mac);
$foundit = 1;
last;
}
}
die "I can't find a new unique mac '$new_mac'\n".Dumper(\@tried) if !$foundit;
}
for my $if_mac ($doc->findnodes('/domain/devices/interface/mac') ) {
my $mac = $if_mac->getAttribute('address');
my @macparts0 = split/:/,$mac;
my $new_mac;
my @tried;
my $foundit;
for ( 1 .. 1000 ) {
for my $cont ( 1 .. 1000 ) {
my @macparts = @macparts0;
my $pos = int(rand(scalar(@macparts)-3))+3;
my $num =sprintf "%02X", rand(0xff);
die "Missing num " if !defined $num;
$macparts[$pos] = $num;
$new_mac = lc(join(":",@macparts));
push @tried,($new_mac);
last if !grep /^$new_mac$/i,@old_macs && $self->_unique_mac($new_mac);
push @old_macs,($new_mac);
}
if ( $self->_unique_mac($new_mac) ) {
$if_mac->setAttribute(address => $new_mac);
$foundit = 1;
last;
}
}
die "I can't find a new unique mac '$new_mac'\n".Dumper(\@tried) if !$foundit;
}
}
=pod
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment