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_cmd = ('/usr/bin/ssh', @ssh_opts);
|
||||
my $id_rsa_path = '/etc/pve/priv/zfs';
|
||||
|
||||
my $get_lun_cmd_map = sub {
|
||||
my ($method) = @_;
|
||||
@ -69,7 +70,7 @@ sub run_lun_command {
|
||||
|
||||
$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);
|
||||
|
||||
|
||||
@ -33,6 +33,7 @@ my $OLD_CONFIG = undef;
|
||||
my @ssh_opts = ('-o', 'BatchMode=yes');
|
||||
my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
|
||||
my @scp_cmd = ('/usr/bin/scp', @ssh_opts);
|
||||
my $id_rsa_path = '/etc/pve/priv/zfs';
|
||||
my $ietadm = '/usr/sbin/ietadm';
|
||||
|
||||
my $execute_command = sub {
|
||||
@ -59,9 +60,9 @@ my $execute_command = sub {
|
||||
$target = 'root@' . $scfg->{portal};
|
||||
|
||||
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 {
|
||||
$cmd = [@ssh_cmd, $target, $method, @params];
|
||||
$cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $method, @params];
|
||||
}
|
||||
|
||||
eval {
|
||||
@ -103,7 +104,7 @@ my $read_config = sub {
|
||||
|
||||
$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 {
|
||||
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_cmd = ('/usr/bin/ssh', @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/):
|
||||
#
|
||||
@ -82,7 +83,7 @@ my $read_config = sub {
|
||||
my $daemon = 0;
|
||||
foreach my $config (@CONFIG_FILES) {
|
||||
$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 {
|
||||
run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout);
|
||||
};
|
||||
@ -518,9 +519,9 @@ sub run_lun_command {
|
||||
$method = $res->{method};
|
||||
@params = @{$res->{params}};
|
||||
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 {
|
||||
$cmd = [@ssh_cmd, $target, $method, @params];
|
||||
$cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $method, @params];
|
||||
}
|
||||
} else {
|
||||
return $res;
|
||||
@ -528,7 +529,7 @@ sub run_lun_command {
|
||||
} else {
|
||||
$luncmd = $cmdmap->{cmd};
|
||||
$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 {
|
||||
@ -542,7 +543,7 @@ sub run_lun_command {
|
||||
open(my $fh, '>', $file) or die "Could not open file '$file' $!";
|
||||
print $fh $OLD_CONFIG;
|
||||
close $fh;
|
||||
$cmd = [@scp_cmd, $file, $CONFIG_FILE];
|
||||
$cmd = [@scp_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $file, $CONFIG_FILE];
|
||||
eval {
|
||||
run_command($cmd, outfunc => $output, timeout => $timeout);
|
||||
};
|
||||
|
||||
@ -14,6 +14,7 @@ use PVE::Storage::LunCmd::Iet;
|
||||
|
||||
my @ssh_opts = ('-o', 'BatchMode=yes');
|
||||
my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
|
||||
my $id_rsa_path = '/etc/pve/priv/zfs';
|
||||
|
||||
my $lun_cmds = {
|
||||
create_lu => 1,
|
||||
@ -75,7 +76,7 @@ sub zfs_request {
|
||||
|
||||
$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 = '';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user