[pve-devel] pve api function for blkio limit

Игорь shinespb at gmail.com
Mon Sep 16 18:55:34 CEST 2013


diff --git a/PVE/API2/OpenVZ.pm b/PVE/API2/OpenVZ.pm
index 11b4a9d..b34134d 100644
--- a/PVE/API2/OpenVZ.pm
+++ b/PVE/API2/OpenVZ.pm
@@ -501,6 +501,92 @@ __PACKAGE__->register_method({
     }});

 __PACKAGE__->register_method({
+    name => 'set_io_limit',
+    path => '{vmid}/io_limit',
+    method => 'PUT',
+    protected => 1,
+    proxyto => 'node',
+    description => "Set virtual machine io limit",
+    permissions => {
+        check => ['perm', '/vms/{vmid}', $vm_config_perm_list, any => 1],
+    },
+    parameters => {
+        additionalProperties => 0,
+        properties => PVE::OpenVZ::json_config_properties(
+            {
+                node => get_standard_option('pve-node'),
+                vmid => get_standard_option('pve-vmid'),
+                iops_read_limit => {
+                        type => 'integer',
+                        description => 'iops read limit for container',
+                        optional => 1,
+                        minimum => 0,
+                },
+                iops_write_limit => {
+                        type => 'integer',
+                        description => 'iops write limit for container',
+                        minimum => 0,
+                        optional => 1,
+                },
+            }),
+    },
+    returns => { type => 'null'},
+    code => sub {
+        my ($param) = @_;
+
+        my $rpcenv = PVE::RPCEnvironment::get();
+
+        my $authuser = $rpcenv->get_user();
+
+        my $node = extract_param($param, 'node');
+
+        my $vmid = extract_param($param, 'vmid');
+
+        die "no options specified\n" if !(keys %$param);
+
+        my $iops_read_limit = extract_param($param, 'iops_read_limit');
+
+        my $iops_write_limit = extract_param($param, 'iops_write_limit');
+
+        my $veconf = PVE::OpenVZ::load_config($vmid);
+
+        my $path = PVE::OpenVZ::get_privatedir($veconf, $vmid);
+
+        my $realcmd = sub {
+                my $dnum = sub {
+
+                   my $deviceid = shift;
+
+                   if (defined $iops_write_limit) {
+
+
PVE::OpenVZ::container_blkio_limit_set("write", $vmid, $deviceid,
$iops_write_limit);
+
+                   }
+                   if (defined $iops_read_limit) {
+
+
PVE::OpenVZ::container_blkio_limit_set("read", $vmid, $deviceid,
$iops_read_limit);
+
+                   }
+
+                };
+
+                my $cmd = ['mountpoint', '-d', $path];
+
+                eval { PVE::Tools::run_command($cmd, outfunc => $dnum); };
+
+                my $err = $@;
+
+                syslog('err', $err) if $err;
+
+                return;
+        };
+
+        return $rpcenv->fork_worker('set_blklimit', $vmid, $authuser,
$realcmd);
+
+    }});
+
+
+__PACKAGE__->register_method({
     name => 'vmdiridx',
     path => '{vmid}',
     method => 'GET',


More information about the pve-devel mailing list