]>
git.proxmox.com Git - pve-storage.git/blob - PVE/API2/Disks/LVM.pm
ef341d1ce67ebd54bb4d9ee9c341f35a8fda385c
1 package PVE
::API2
::Disks
::LVM
;
6 use PVE
::Storage
::LVMPlugin
;
8 use PVE
::JSONSchema
qw(get_standard_option);
9 use PVE
::API2
::Storage
::Config
;
10 use PVE
::Tools
qw(lock_file run_command);
12 use PVE
::RPCEnvironment
;
15 use base
qw(PVE::RESTHandler);
17 __PACKAGE__-
>register_method ({
24 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
26 description
=> "List LVM Volume Groups",
28 additionalProperties
=> 0,
30 node
=> get_standard_option
('pve-node'),
49 description
=> 'The name of the volume group',
53 description
=> 'The size of the volume group in bytes',
57 description
=> 'The free bytes in the volume group',
62 description
=> 'The underlying physical volumes',
71 description
=> 'The name of the physical volume',
75 description
=> 'The size of the physical volume in bytes',
79 description
=> 'The free bytes in the physical volume',
94 my $vgs = PVE
::Storage
::LVMPlugin
::lvm_vgs
(1);
96 foreach my $vg_name (sort keys %$vgs) {
97 my $vg = $vgs->{$vg_name};
98 $vg->{name
} = $vg_name;
100 foreach my $pv (@{$vg->{pvs
}}) {
103 $vg->{children
} = delete $vg->{pvs
};
113 __PACKAGE__-
>register_method ({
120 check
=> ['perm', '/', ['Sys.Modify', 'Datastore.Allocate']],
122 description
=> "Create an LVM Volume Group",
124 additionalProperties
=> 0,
126 node
=> get_standard_option
('pve-node'),
127 name
=> get_standard_option
('pve-storage-id'),
130 description
=> 'The block device you want to create the volume group on',
133 description
=> "Configure storage using the Volume Group",
140 returns
=> { type
=> 'string' },
144 my $rpcenv = PVE
::RPCEnvironment
::get
();
145 my $user = $rpcenv->get_user();
147 my $name = $param->{name
};
148 my $dev = $param->{device
};
149 my $node = $param->{node
};
151 $dev = PVE
::Diskmanage
::verify_blockdev_path
($dev);
152 PVE
::Diskmanage
::assert_disk_unused
($dev);
153 PVE
::Storage
::assert_sid_unused
($name) if $param->{add_storage
};
156 PVE
::Diskmanage
::locked_disk_action
(sub {
157 PVE
::Diskmanage
::assert_disk_unused
($dev);
158 die "volume group with name '${name}' already exists on node '${node}'\n"
159 if PVE
::Storage
::LVMPlugin
::lvm_vgs
()->{$name};
161 if (PVE
::Diskmanage
::is_partition
($dev)) {
162 eval { PVE
::Diskmanage
::change_parttype
($dev, '8E00'); };
166 PVE
::Storage
::LVMPlugin
::lvm_create_volume_group
($dev, $name);
168 PVE
::Diskmanage
::udevadm_trigger
($dev);
170 if ($param->{add_storage
}) {
171 my $storage_params = {
175 content
=> 'rootdir,images',
180 PVE
::API2
::Storage
::Config-
>create($storage_params);
185 return $rpcenv->fork_worker('lvmcreate', $name, $user, $worker);
188 __PACKAGE__-
>register_method ({
195 check
=> ['perm', '/', ['Sys.Modify', 'Datastore.Allocate']],
197 description
=> "Remove an LVM Volume Group.",
199 additionalProperties
=> 0,
201 node
=> get_standard_option
('pve-node'),
202 name
=> get_standard_option
('pve-storage-id'),
203 'cleanup-config' => {
204 description
=> "Marks associated storage(s) as not available on this node anymore ".
205 "or removes them from the configuration (if configured for this node only).",
211 description
=> "Also wipe disks so they can be repurposed afterwards.",
218 returns
=> { type
=> 'string' },
222 my $rpcenv = PVE
::RPCEnvironment
::get
();
223 my $user = $rpcenv->get_user();
225 my $name = $param->{name
};
226 my $node = $param->{node
};
229 PVE
::Diskmanage
::locked_disk_action
(sub {
230 my $vgs = PVE
::Storage
::LVMPlugin
::lvm_vgs
(1);
231 die "no such volume group '$name'\n" if !$vgs->{$name};
233 PVE
::Storage
::LVMPlugin
::lvm_destroy_volume_group
($name);
236 if ($param->{'cleanup-config'}) {
239 return $scfg->{type
} eq 'lvm' && $scfg->{vgname
} eq $name;
241 eval { PVE
::API2
::Storage
::Config-
>cleanup_storages_for_node($match, $node); };
242 warn $config_err = $@ if $@;
245 if ($param->{'cleanup-disks'}) {
248 for my $pv ($vgs->{$name}->{pvs
}->@*) {
249 my $dev = PVE
::Diskmanage
::verify_blockdev_path
($pv->{name
});
250 PVE
::Diskmanage
::wipe_blockdev
($dev);
251 push $wiped->@*, $dev;
255 PVE
::Diskmanage
::udevadm_trigger
($wiped->@*);
256 die "cleanup failed - $err" if $err;
259 die "config cleanup failed - $config_err" if $config_err;
263 return $rpcenv->fork_worker('lvmremove', $name, $user, $worker);