]>
Commit | Line | Data |
---|---|---|
ee31ad01 MR |
1 | package PVE::Storage::LunCmd::Comstar; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use Digest::MD5 qw(md5_hex); | |
6 | use PVE::Tools qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach); | |
7 | use Data::Dumper; | |
8 | ||
9 | my @ssh_opts = ('-o', 'BatchMode=yes'); | |
10 | my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts); | |
11 | ||
12 | my $get_lun_cmd_map = sub { | |
13 | my ($method) = @_; | |
14 | ||
15 | my $stmfadmcmd = "/usr/sbin/stmfadm"; | |
16 | my $sbdadmcmd = "/usr/sbin/sbdadm"; | |
17 | ||
18 | my $cmdmap = { | |
19 | create_lu => { cmd => $stmfadmcmd, method => 'create-lu' }, | |
20 | delete_lu => { cmd => $stmfadmcmd, method => 'delete-lu' }, | |
21 | import_lu => { cmd => $stmfadmcmd, method => 'import-lu' }, | |
22 | modify_lu => { cmd => $stmfadmcmd, method => 'modify-lu' }, | |
23 | add_view => { cmd => $stmfadmcmd, method => 'add-view' }, | |
24 | list_view => { cmd => $stmfadmcmd, method => 'list-view' }, | |
25 | list_lu => { cmd => $sbdadmcmd, method => 'list-lu' }, | |
26 | }; | |
27 | ||
28 | die "unknown command '$method'" unless exists $cmdmap->{$method}; | |
29 | ||
30 | return $cmdmap->{$method}; | |
31 | }; | |
32 | ||
33 | sub get_base { | |
34 | return '/dev/zvol/rdsk'; | |
35 | } | |
36 | ||
37 | sub run_lun_command { | |
38 | my ($scfg, $timeout, $method, @params) = @_; | |
39 | ||
40 | my $msg = ''; | |
41 | my $luncmd; | |
42 | my $target; | |
43 | my $guid; | |
44 | $timeout = 10 if !$timeout; | |
45 | ||
46 | my $output = sub { | |
47 | my $line = shift; | |
48 | $msg .= "$line\n"; | |
49 | }; | |
50 | ||
51 | if ($method eq 'create_lu') { | |
52 | my $prefix = '600144f'; | |
53 | my $digest = md5_hex($params[0]); | |
54 | $digest =~ /(\w{7}(.*))/; | |
55 | $guid = "$prefix$2"; | |
56 | @params = ('-p', 'wcd=false', '-p', "guid=$guid", @params); | |
57 | } elsif ($method eq 'modify_lu') { | |
58 | @params = ('-s', @params); | |
59 | } elsif ($method eq 'list_view') { | |
60 | @params = ('-l', @params); | |
61 | } elsif ($method eq 'list_lu') { | |
62 | $guid = $params[0]; | |
63 | @params = undef; | |
64 | } | |
65 | ||
66 | my $cmdmap = $get_lun_cmd_map->($method); | |
67 | $luncmd = $cmdmap->{cmd}; | |
68 | my $lunmethod = $cmdmap->{method}; | |
69 | ||
70 | $target = 'root@' . $scfg->{portal}; | |
71 | ||
72 | my $cmd = [@ssh_cmd, $target, $luncmd, $lunmethod, @params]; | |
73 | ||
74 | run_command($cmd, outfunc => $output, timeout => $timeout); | |
75 | ||
76 | if ($method eq 'list_view') { | |
77 | my @lines = split /\n/, $msg; | |
78 | $msg = undef; | |
79 | foreach my $line (@lines) { | |
80 | if ($line =~ /^\s*LUN\s*:\s*(\d+)$/) { | |
81 | $msg = $1; | |
82 | last; | |
83 | } | |
84 | } | |
85 | } elsif ($method eq 'list_lu') { | |
86 | my $object = $guid; | |
87 | my @lines = split /\n/, $msg; | |
88 | $msg = undef; | |
89 | foreach my $line (@lines) { | |
90 | if ($line =~ /(\w+)\s+\d+\s+$object$/) { | |
91 | $msg = $1; | |
92 | last; | |
93 | } | |
94 | } | |
95 | } elsif ($method eq 'create_lu') { | |
96 | $msg = $guid; | |
97 | } | |
98 | ||
99 | return $msg; | |
100 | } | |
101 |