File Coverage

blib/lib/Net/Proxmox/VE/Storage.pm
Criterion Covered Total %
statement 12 45 26.6
branch 0 36 0.0
condition n/a
subroutine 4 9 44.4
pod 5 5 100.0
total 21 95 22.1


line stmt bran cond sub pod time code
1             #!/bin/false
2             # vim: softtabstop=4 tabstop=4 shiftwidth=4 ft=perl expandtab smarttab
3             # PODNAME: Net::Proxmox::VE::Storage
4             # ABSTRACT: Store object
5              
6 2     2   185315 use strict;
  2         3  
  2         56  
7 2     2   6 use warnings;
  2         3  
  2         138  
8              
9             package Net::Proxmox::VE::Storage;
10             $Net::Proxmox::VE::Storage::VERSION = '0.44';
11 2     2   10 use parent 'Exporter';
  2         5  
  2         10  
12              
13 2     2   538 use Net::Proxmox::VE::Exception;
  2         4  
  2         801  
14              
15              
16             our @EXPORT = qw( storage );
17              
18             my $BASEPATH = '/storage';
19              
20              
21             sub storage {
22              
23 0 0   0 1   my $self = shift or return;
24              
25 0           return $self->get($BASEPATH);
26              
27             }
28              
29              
30             sub get_storage {
31              
32 0 0   0 1   my $self = shift or return;
33              
34 0 0         my $storageid = shift
35             or Net::Proxmox::VE::Exception->throw('No storageid for get_storage()');
36 0 0         Net::Proxmox::VE::Exception->throw(
37             'storageid must be a scalar for get_storage()')
38             if ref $storageid;
39              
40 0           return $self->get( $BASEPATH, $storageid );
41              
42             }
43              
44              
45             sub create_storage {
46              
47 0 0   0 1   my $self = shift or return;
48 0           my @p = @_;
49              
50 0 0         Net::Proxmox::VE::Exception->throw('No arguments for create_storage()')
51             unless @p;
52 0           my %args;
53              
54 0 0         if ( @p == 1 ) {
55 0 0         Net::Proxmox::VE::Exception->throw(
56             'Single argument not a hash for create_storage()')
57             unless ref $p[0] eq 'HASH';
58 0           %args = %{ $p[0] };
  0            
59             }
60             else {
61 0 0         Net::Proxmox::VE::Exception->throw(
62             'Odd number of arguments for create_storage()')
63             if ( scalar @p % 2 != 0 );
64 0           %args = @p;
65             }
66              
67 0           return $self->post( $BASEPATH, \%args );
68              
69             }
70              
71              
72             sub delete_storage {
73              
74 0 0   0 1   my $self = shift or return;
75 0 0         my $storageid = shift
76             or Net::Proxmox::VE::Exception->throw(
77             'No argument given for delete_storage()');
78              
79 0           return $self->delete( $BASEPATH, $storageid );
80              
81             }
82              
83              
84             sub update_storage {
85              
86 0 0   0 1   my $self = shift or return;
87 0 0         my $storageid = shift
88             or Net::Proxmox::VE::Exception->throw(
89             'No storageid provided for update_storage()');
90 0 0         Net::Proxmox::VE::Exception->throw(
91             'storageid must be a scalar for update_storage()')
92             if ref $storageid;
93 0           my @p = @_;
94              
95 0 0         Net::Proxmox::VE::Exception->throw('No arguments for update_storage()')
96             unless @p;
97 0           my %args;
98              
99 0 0         if ( @p == 1 ) {
100 0 0         Net::Proxmox::VE::Exception->throw(
101             'Single argument not a hash for update_storage()')
102             unless ref $p[0] eq 'HASH';
103 0           %args = %{ $p[0] };
  0            
104             }
105             else {
106 0 0         Net::Proxmox::VE::Exception->throw(
107             'Odd number of arguments for update_storage()')
108             if ( scalar @p % 2 != 0 );
109 0           %args = @p;
110             }
111              
112 0           return $self->put( $BASEPATH, $storageid, \%args );
113              
114             }
115              
116              
117             1;
118              
119             __END__
120              
121             =pod
122              
123             =encoding UTF-8
124              
125             =head1 NAME
126              
127             Net::Proxmox::VE::Storage - Store object
128              
129             =head1 VERSION
130              
131             version 0.44
132              
133             =head1 SYNOPSIS
134              
135             @storage = $obj->storage();
136             $storage = $obj->get_storage('storageid');
137              
138             $ok = $obj->create_storage(%args);
139             $ok = $obj->create_storage(\%args);
140              
141             $ok = $obj->delete_storage('storageid');
142              
143             $ok = $obj->update_storage('storageid', %args);
144             $ok = $obj->update_storage('storageid', \%args);
145              
146             =head1 DESCRIPTION
147              
148             This module implements the 'storages' section of the Proxmox API for L<Net::Proxmox::VE>,
149             you should use the API via that module. This documentation is for detailed reference.
150              
151             To be clear, this module isn't useful as a stand alone piece of software.
152              
153             =head1 NOTE
154              
155             String formats that are mentioned herein are done so for convenience and
156             are defined in detail in the Proxmox API documents on the Proxmox project website.
157              
158             This module doesnt enforce them, it will send whatever garbage you provide
159             straight to the server API. So garbage-in, garbage-out!
160              
161             =head1 METHODS
162              
163             =head2 storage
164              
165             Gets a list of storage (aka the a Storage Index)
166              
167             @storage = $obj->storage();
168              
169             =head2 get_storage
170              
171             Gets a single storage's configuration details
172              
173             $storage = $obj->get_storage('storageid');
174              
175             storageid is a string in pve-storageid format
176              
177             =head2 create_storage
178              
179             Creates a new storage
180              
181             $ok = $obj->create_storage( %args );
182             $ok = $obj->create_storage( \%args );
183              
184             I<%args> may items contain from the following list
185              
186             =over 4
187              
188             =item storage
189              
190             String. The id of the storage you wish to access in pve-storageid format. Required.
191              
192             =item type
193              
194             Enum. This is the type of storage, options are:
195              
196             =over 4
197              
198             =item btrfs
199              
200             =item cephfs
201              
202             =item cifs
203              
204             =item dir
205              
206             =item esxi
207              
208             =item glusterfs
209              
210             =item iscsi
211              
212             =item iscsidir
213              
214             =item lvm
215              
216             =item lvmthin
217              
218             =item nfs
219              
220             =item pbs
221              
222             =item rbd
223              
224             =item zfs
225              
226             =item zfspool
227              
228             =back
229              
230             Required.
231              
232             =item base
233              
234             String. A pve-volume-id, see the PVE documentation. Optional.
235              
236             =item content
237              
238             String. A pve-storage-content-list. Optional.
239              
240             =item disable
241              
242             Boolean. See the PVE documentation. Optional.
243              
244             =item export
245              
246             String. A pve-storage-path. Optional.
247              
248             =item format
249              
250             String. A pve-format-path. Optional.
251              
252             =item maxfiles
253              
254             Integer. See the PVE documentation. Optional.
255              
256             =item nodes
257              
258             String. A pve-node-list. Optional.
259              
260             =item options
261              
262             String. A pve-storage-options. Optional.
263              
264             =item path
265              
266             String. A pve-storage-path. Optional.
267              
268             =item portal
269              
270             String. A pve-storage-portal-dns. Optional.
271              
272             =item server
273              
274             String. A pve-storage-server. Optional.
275              
276             =item shared
277              
278             Boolean. See the PVE documentation. Optional.
279              
280             =back
281              
282             =head2 delete_storage
283              
284             Deletes a single storage
285              
286             $ok = $obj->delete_storage('storage')
287              
288             storage is a string in pve-storage-id format
289              
290             =head2 update_storage
291              
292             Updates (sets) a storage's data
293              
294             $ok = $obj->update_storage( 'storage', %args );
295             $ok = $obj->update_storage( 'storage', \%args );
296              
297             storage is a string in pve-storage-id format
298              
299             I<%args> may items contain from the following list
300              
301             =over 4
302              
303             =item content
304              
305             String. Storage content list. Optional.
306              
307             =item digest
308              
309             String. Prevent changes if current configuration file has a different SHA1 digest. This can be used to prevent concurrent modifications. Optional.
310              
311             =item disable
312              
313             Boolean. Disables the storage. Optional.
314              
315             =item format
316              
317             String. Storage format in pve-storage-format format (see the PVE documentation). Optional.
318              
319             =item maxfiles
320              
321             Integer. See PVE documentation. Optional.
322              
323             =item nodes
324              
325             String. List of cluster node names. Optional.
326              
327             =item options
328              
329             String. Storage options in pve-storage-options format. Optional.
330              
331             =item shared
332              
333             Boolean. See PVE documentation. Optional.
334              
335             =back
336              
337             =head1 SEE ALSO
338              
339             L<Net::Proxmox::VE>
340              
341             =head1 AUTHOR
342              
343             Dean Hamstead <dean@fragfest.com.au>
344              
345             =head1 COPYRIGHT AND LICENSE
346              
347             This software is Copyright (c) 2026 by Dean Hamstead.
348              
349             This is free software, licensed under:
350              
351             The MIT (X11) License
352              
353             =cut