Use ssh key stored in pmxcfg. Use ssh -i /etc/pve/priv/zfs/portal_id_rsa for remote commands
Signed-off-by: Michael Rasmussen <mir@datanom.net>
This commit is contained in:
committed by
Dietmar Maurer
parent
86f00da603
commit
3b219e8037
@ -8,6 +8,7 @@ use Data::Dumper;
|
|||||||
|
|
||||||
my @ssh_opts = ('-o', 'BatchMode=yes');
|
my @ssh_opts = ('-o', 'BatchMode=yes');
|
||||||
my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
|
my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
|
||||||
|
my $id_rsa_path = '/etc/pve/priv/zfs';
|
||||||
|
|
||||||
my $get_lun_cmd_map = sub {
|
my $get_lun_cmd_map = sub {
|
||||||
my ($method) = @_;
|
my ($method) = @_;
|
||||||
@ -69,7 +70,7 @@ sub run_lun_command {
|
|||||||
|
|
||||||
$target = 'root@' . $scfg->{portal};
|
$target = 'root@' . $scfg->{portal};
|
||||||
|
|
||||||
my $cmd = [@ssh_cmd, $target, $luncmd, $lunmethod, @params];
|
my $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $lunmethod, @params];
|
||||||
|
|
||||||
run_command($cmd, outfunc => $output, timeout => $timeout);
|
run_command($cmd, outfunc => $output, timeout => $timeout);
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,7 @@ my $OLD_CONFIG = undef;
|
|||||||
my @ssh_opts = ('-o', 'BatchMode=yes');
|
my @ssh_opts = ('-o', 'BatchMode=yes');
|
||||||
my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
|
my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
|
||||||
my @scp_cmd = ('/usr/bin/scp', @ssh_opts);
|
my @scp_cmd = ('/usr/bin/scp', @ssh_opts);
|
||||||
|
my $id_rsa_path = '/etc/pve/priv/zfs';
|
||||||
my $ietadm = '/usr/sbin/ietadm';
|
my $ietadm = '/usr/sbin/ietadm';
|
||||||
|
|
||||||
my $execute_command = sub {
|
my $execute_command = sub {
|
||||||
@ -59,9 +60,9 @@ my $execute_command = sub {
|
|||||||
$target = 'root@' . $scfg->{portal};
|
$target = 'root@' . $scfg->{portal};
|
||||||
|
|
||||||
if ($exec eq 'scp') {
|
if ($exec eq 'scp') {
|
||||||
$cmd = [@scp_cmd, $method, "$target:$params[0]"];
|
$cmd = [@scp_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $method, "$target:$params[0]"];
|
||||||
} else {
|
} else {
|
||||||
$cmd = [@ssh_cmd, $target, $method, @params];
|
$cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $method, @params];
|
||||||
}
|
}
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
@ -103,7 +104,7 @@ my $read_config = sub {
|
|||||||
|
|
||||||
$target = 'root@' . $scfg->{portal};
|
$target = 'root@' . $scfg->{portal};
|
||||||
|
|
||||||
my $cmd = [@ssh_cmd, $target, $luncmd, $CONFIG_FILE];
|
my $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $CONFIG_FILE];
|
||||||
eval {
|
eval {
|
||||||
run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout);
|
run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -31,6 +31,7 @@ my $OLD_CONFIG = undef;
|
|||||||
my @ssh_opts = ('-o', 'BatchMode=yes');
|
my @ssh_opts = ('-o', 'BatchMode=yes');
|
||||||
my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
|
my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
|
||||||
my @scp_cmd = ('/usr/bin/scp', @ssh_opts);
|
my @scp_cmd = ('/usr/bin/scp', @ssh_opts);
|
||||||
|
my $id_rsa_path = '/etc/pve/priv/zfs';
|
||||||
|
|
||||||
#Current SIGHUP reload limitations (http://www.peach.ne.jp/archives/istgt/):
|
#Current SIGHUP reload limitations (http://www.peach.ne.jp/archives/istgt/):
|
||||||
#
|
#
|
||||||
@ -82,7 +83,7 @@ my $read_config = sub {
|
|||||||
my $daemon = 0;
|
my $daemon = 0;
|
||||||
foreach my $config (@CONFIG_FILES) {
|
foreach my $config (@CONFIG_FILES) {
|
||||||
$err = undef;
|
$err = undef;
|
||||||
my $cmd = [@ssh_cmd, $target, $luncmd, $config];
|
my $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $config];
|
||||||
eval {
|
eval {
|
||||||
run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout);
|
run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout);
|
||||||
};
|
};
|
||||||
@ -518,9 +519,9 @@ sub run_lun_command {
|
|||||||
$method = $res->{method};
|
$method = $res->{method};
|
||||||
@params = @{$res->{params}};
|
@params = @{$res->{params}};
|
||||||
if ($res->{cmd} eq 'scp') {
|
if ($res->{cmd} eq 'scp') {
|
||||||
$cmd = [@scp_cmd, $method, "$target:$params[0]"];
|
$cmd = [@scp_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $method, "$target:$params[0]"];
|
||||||
} else {
|
} else {
|
||||||
$cmd = [@ssh_cmd, $target, $method, @params];
|
$cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $method, @params];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return $res;
|
return $res;
|
||||||
@ -528,7 +529,7 @@ sub run_lun_command {
|
|||||||
} else {
|
} else {
|
||||||
$luncmd = $cmdmap->{cmd};
|
$luncmd = $cmdmap->{cmd};
|
||||||
$method = $cmdmap->{method};
|
$method = $cmdmap->{method};
|
||||||
$cmd = [@ssh_cmd, $target, $luncmd, $method, @params];
|
$cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $method, @params];
|
||||||
}
|
}
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
@ -542,7 +543,7 @@ sub run_lun_command {
|
|||||||
open(my $fh, '>', $file) or die "Could not open file '$file' $!";
|
open(my $fh, '>', $file) or die "Could not open file '$file' $!";
|
||||||
print $fh $OLD_CONFIG;
|
print $fh $OLD_CONFIG;
|
||||||
close $fh;
|
close $fh;
|
||||||
$cmd = [@scp_cmd, $file, $CONFIG_FILE];
|
$cmd = [@scp_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $file, $CONFIG_FILE];
|
||||||
eval {
|
eval {
|
||||||
run_command($cmd, outfunc => $output, timeout => $timeout);
|
run_command($cmd, outfunc => $output, timeout => $timeout);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -14,6 +14,7 @@ use PVE::Storage::LunCmd::Iet;
|
|||||||
|
|
||||||
my @ssh_opts = ('-o', 'BatchMode=yes');
|
my @ssh_opts = ('-o', 'BatchMode=yes');
|
||||||
my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
|
my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
|
||||||
|
my $id_rsa_path = '/etc/pve/priv/zfs';
|
||||||
|
|
||||||
my $lun_cmds = {
|
my $lun_cmds = {
|
||||||
create_lu => 1,
|
create_lu => 1,
|
||||||
@ -75,7 +76,7 @@ sub zfs_request {
|
|||||||
|
|
||||||
$target = 'root@' . $scfg->{portal};
|
$target = 'root@' . $scfg->{portal};
|
||||||
|
|
||||||
my $cmd = [@ssh_cmd, $target, $zfscmd, $method, @params];
|
my $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $zfscmd, $method, @params];
|
||||||
|
|
||||||
$msg = '';
|
$msg = '';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user