]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/LunCmd/Comstar.pm
1 package PVE
::Storage
::LunCmd
::Comstar
;
6 use Digest
::MD5
qw(md5_hex);
7 use PVE
::Tools
qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach);
9 my @ssh_opts = ('-o', 'BatchMode=yes');
10 my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
11 my $id_rsa_path = '/etc/pve/priv/zfs';
13 my $get_lun_cmd_map = sub {
16 my $stmfadmcmd = "/usr/sbin/stmfadm";
17 my $sbdadmcmd = "/usr/sbin/sbdadm";
20 create_lu
=> { cmd
=> $stmfadmcmd, method => 'create-lu' },
21 delete_lu
=> { cmd
=> $stmfadmcmd, method => 'delete-lu' },
22 import_lu
=> { cmd
=> $stmfadmcmd, method => 'import-lu' },
23 modify_lu
=> { cmd
=> $stmfadmcmd, method => 'modify-lu' },
24 add_view
=> { cmd
=> $stmfadmcmd, method => 'add-view' },
25 list_view
=> { cmd
=> $stmfadmcmd, method => 'list-view' },
26 list_lu
=> { cmd
=> $sbdadmcmd, method => 'list-lu' },
29 die "unknown command '$method'" unless exists $cmdmap->{$method};
31 return $cmdmap->{$method};
35 return '/dev/zvol/rdsk';
39 my ($scfg, $timeout, $method, @params) = @_;
45 $timeout = 10 if !$timeout;
52 if ($method eq 'create_lu') {
54 if ($scfg->{nowritecache
}) {
57 my $prefix = '600144f';
58 my $digest = md5_hex
($params[0]);
59 $digest =~ /(\w{7}(.*))/;
61 @params = ('-p', "wcd=$wcd", '-p', "guid=$guid", @params);
62 } elsif ($method eq 'modify_lu') {
63 @params = ('-s', @params);
64 } elsif ($method eq 'list_view') {
65 @params = ('-l', @params);
66 } elsif ($method eq 'list_lu') {
69 } elsif ($method eq 'add_view') {
70 if ($scfg->{comstar_tg
}) {
71 unshift @params, $scfg->{comstar_tg
};
72 unshift @params, '--target-group';
74 if ($scfg->{comstar_hg
}) {
75 unshift @params, $scfg->{comstar_hg
};
76 unshift @params, '--host-group';
80 my $cmdmap = $get_lun_cmd_map->($method);
81 $luncmd = $cmdmap->{cmd
};
82 my $lunmethod = $cmdmap->{method};
84 $target = 'root@' . $scfg->{portal
};
86 my $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $lunmethod, @params];
88 run_command
($cmd, outfunc
=> $output, timeout
=> $timeout);
90 if ($method eq 'list_view') {
91 my @lines = split /\n/, $msg;
93 foreach my $line (@lines) {
94 if ($line =~ /^\s*LUN\s*:\s*(\d+)$/) {
99 } elsif ($method eq 'list_lu') {
101 my @lines = split /\n/, $msg;
103 foreach my $line (@lines) {
104 if ($line =~ /(\w+)\s+\d+\s+$object$/) {
109 } elsif ($method eq 'create_lu') {