]> git.proxmox.com Git - pve-storage.git/blame - PVE/Storage/ISCSIDirectPlugin.pm
add nexenta plugin
[pve-storage.git] / PVE / Storage / ISCSIDirectPlugin.pm
CommitLineData
b345cad3
AD
1package PVE::Storage::ISCSIDirectPlugin;
2
3use strict;
4use warnings;
5use IO::File;
6use HTTP::Request;
7use LWP::UserAgent;
8use PVE::Tools qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach);
9use PVE::Storage::Plugin;
10use PVE::JSONSchema qw(get_standard_option);
11
12use base qw(PVE::Storage::Plugin);
13
14
15sub iscsi_ls{
16 my ($scfg, $storeid) = @_;
17
18
19 my $portal = $scfg->{portal};
20 my $cmd = ['/usr/bin/iscsi-ls', '-s', 'iscsi://'.$portal ];
21 my $list = {};
22 my $test = "";
23
24 my $errfunc = sub {
25 my $line = shift;
26 $line = trim($line);
27
28 die $line if $line;
29 };
30
31 eval {
32
33 run_command($cmd, errmsg => "iscsi error", errfunc => $errfunc,outfunc => sub {
34 my $line = shift;
35 $line = trim($line);
36 if( $line =~ /Lun:(\d+)\s+([A-Za-z0-9\-\_\.\:]*)\s+\(Size:(\d+)G\)/ ) {
37 $test = $1;
38
39 my $image = $1;
40 my $size = $3;
41
42 $list->{$storeid}->{$image} = {
43 name => $image,
44 size => $size,
45 };
46 }
47 });
48 };
49
50 my $err = $@;
51 die $err if $err && $err !~ m/TESTUNITREADY failed with SENSE KEY/ ;
52 return $list;
53
54}
55
56# Configuration
57
58sub type {
59 return 'iscsidirect';
60}
61
62sub plugindata {
63 return {
64 content => [ {images => 1, none => 1}, { images => 1 }],
65 };
66}
67
68sub options {
69 return {
70 portal => { fixed => 1 },
71 target => { fixed => 1 },
72 nodes => { optional => 1},
73 disable => { optional => 1},
74 content => { optional => 1},
75 };
76}
77
78
79# Storage implementation
80
81sub parse_volname {
82 my ($class, $volname) = @_;
83
84
85 if ($volname =~ m/^(\d+)$/) {
86 return ('images', $1, undef);
87 }
88
89 die "unable to parse iscsi volume name '$volname'\n";
90
91}
92
93sub path {
94 my ($class, $scfg, $volname) = @_;
95
96 my ($vtype, $lun, $vmid) = $class->parse_volname($volname);
97
98 my $target = $scfg->{target};
99 my $portal = $scfg->{portal};
100
101 my $path = "iscsi://$portal/$target/$lun";
102
103 return ($path, $vmid, $vtype);
104}
105
106
107sub alloc_image {
108 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
109
110 die "can't allocate space in iscsi storage\n";
111}
112
113sub free_image {
114 my ($class, $storeid, $scfg, $volname) = @_;
115
116 die "can't free space in iscsi storage\n";
117}
118
119
120sub list_images {
121 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
122
123 my $res = [];
124
125 $cache->{directiscsi} = iscsi_ls($scfg,$storeid) if !$cache->{directiscsi};
126
127 # we have no owner for iscsi devices
128
129 my $target = $scfg->{target};
130
131 if (my $dat = $cache->{directiscsi}->{$storeid}) {
132
133 foreach my $volname (keys %$dat) {
134
135 my $volid = "$storeid:$volname";
136
137 if ($vollist) {
138 my $found = grep { $_ eq $volid } @$vollist;
139 next if !$found;
140 } else {
141 # we have no owner for iscsi devices
142 next if defined($vmid);
143 }
144
145 my $info = $dat->{$volname};
146 $info->{volid} = $volid;
147
148 push @$res, $info;
149 }
150 }
151
152 return $res;
153}
154
155
156sub status {
157 my ($class, $storeid, $scfg, $cache) = @_;
158
159 my $total = 0;
160 my $free = 0;
161 my $used = 0;
162 my $active = 1;
163 return ($total,$free,$used,$active);
164
165 return undef;
166}
167
168sub activate_storage {
169 my ($class, $storeid, $scfg, $cache) = @_;
170 return 1;
171}
172
173sub deactivate_storage {
174 my ($class, $storeid, $scfg, $cache) = @_;
175 return 1;
176}
177
178sub activate_volume {
179 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
180 return 1;
181}
182
183sub deactivate_volume {
184 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
185 return 1;
186}
187
188
1891;