sub
arpnip {
my
(
$self
,
$hostlabel
,
$ssh
,
$args
) =
@_
;
my
@arpentries
= ();
debug
"$hostlabel $$ arpnip()"
;
my
(
$pty
,
$pid
) =
$ssh
->open2pty;
unless
(
$pty
) {
debug
"unable to run remote command [$hostlabel] "
.
$ssh
->error;
return
();
}
my
$expect
= Expect->init(
$pty
);
my
(
$pos
,
$error
,
$match
,
$before
,
$after
);
my
$prompt
;
$prompt
=
qr/>/
;
(
$pos
,
$error
,
$match
,
$before
,
$after
) =
$expect
->expect(10, -re,
$prompt
);
$expect
->
send
(
"show virtual-system all\n"
);
(
$pos
,
$error
,
$match
,
$before
,
$after
) =
$expect
->expect(10, -re,
$prompt
);
my
@vsxentries
= ();
my
@lines
=
split
(m/\n/,
$before
);
my
$linereg
=
qr/(\d+)\s+([A-Za-z0-9_-]+)/
;
foreach
my
$line
(
@lines
) {
if
(
$line
=~
$linereg
) {
my
(
$vsid
,
$vsname
) = ($1, $2);
push
@vsxentries
, {
vsid
=>
$vsid
,
vsname
=>
$vsname
};
debug
"$hostlabel $$ $vsid, $vsname"
;
}
}
$expect
->
send
(
"expert\n"
);
$prompt
=
qr/Enter expert password:/
;
(
$pos
,
$error
,
$match
,
$before
,
$after
) =
$expect
->expect(10, -re,
$prompt
);
$expect
->
send
(
$args
->{expert_password} .
"\n"
);
$prompt
=
qr/#/
;
(
$pos
,
$error
,
$match
,
$before
,
$after
) =
$expect
->expect(10, -re,
$prompt
);
foreach
(
@vsxentries
) {
my
$vsid
=
$_
->{vsid};
debug
"$hostlabel $$ arpnip VSID: $vsid"
;
$expect
->
send
(
"vsenv $vsid\n"
);
(
$pos
,
$error
,
$match
,
$before
,
$after
) =
$expect
->expect(10, -re,
$prompt
);
$expect
->
send
(
"arp -n | tail -n +2\n"
);
(
$pos
,
$error
,
$match
,
$before
,
$after
) =
$expect
->expect(10, -re,
$prompt
);
@lines
=
split
(m/\n/,
$before
);
$linereg
=
qr/([0-9\.]+)\s+ether\s+([a-fA-F0-9:]+)/
;
foreach
my
$line
(
@lines
) {
if
(
$line
=~
$linereg
) {
my
(
$ip
,
$mac
) = ($1, $2);
push
@arpentries
, {
mac
=>
$mac
,
ip
=>
$ip
};
debug
"$hostlabel $$ arpnip VSID: $vsid IP: $ip MAC: $mac"
;
}
}
}
$expect
->
send
(
"exit\n"
);
$prompt
=
qr/>/
;
(
$pos
,
$error
,
$match
,
$before
,
$after
) =
$expect
->expect(5, -re,
$prompt
);
$expect
->
send
(
"exit\n"
);
$expect
->soft_close();
return
@arpentries
;
}
1;