]> git.proxmox.com Git - pve-cluster.git/commitdiff
cluster: add get_guest_config_properties
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 16 Nov 2022 15:47:56 +0000 (16:47 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 17 Nov 2022 09:02:13 +0000 (10:02 +0100)
Akin to the singular get_guest_config_property, but with the
possibility to query a list of properties.

Uses the CFS_IPC_GET_GUEST_CONFIG_PROPERTIES introduced in the
previous patch.

Note that the same details apply w.r.t. parsing and permissions as
the singular variant, iow. one needs to take caution and filter
allowed guests views  on call site when using this.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
 [T: reword/extend commit message ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
data/PVE/Cluster.pm

index abcc46d36c00ce381279b4c61d26b69e1a94705f..99e7975cdc1ecc703b6bd737faa7a835cfc0dfed 100644 (file)
@@ -339,10 +339,37 @@ sub get_node_kv {
     return $res;
 }
 
+# properties: an array-ref of config properties you want to get, e.g., this
+# is perfect to get multiple properties of a guest _fast_
+# (>100 faster than manual parsing here)
+# vmid: optional, if a valid is passed we only check that one, else return all
+# NOTE: does *not* searches snapshot and PENDING entries sections!
+# NOTE: returns the guest config lines (excluding trailing whitespace) as is,
+#       so for non-trivial properties, checking the validity must be done
+# NOTE: no permission check is done, that is the responsibilty of the caller
+sub get_guest_config_properties {
+    my ($properties, $vmid) = @_;
+
+    die "properties required" if !defined($properties);
+
+    my $num_props = scalar(@$properties);
+    die "only up to 255 properties supported" if $num_props > 255;
+    my $bindata = pack "VC", $vmid // 0, $num_props;
+    for my $property (@$properties) {
+       $bindata .= pack "Z*", $property;
+    }
+    my $res = $ipcc_send_rec_json->(CFS_IPC_GET_GUEST_CONFIG_PROPERTIES, $bindata);
+
+    return $res;
+}
+
 # property: a config property you want to get, e.g., this is perfect to get
 # the 'lock' entry of a guest _fast_ (>100 faster than manual parsing here)
 # vmid: optional, if a valid is passed we only check that one, else return all
 # NOTE: does *not* searches snapshot and PENDING entries sections!
+# NOTE: returns the guest config lines (excluding trailing whitespace) as is,
+#       so for non-trivial properties, checking the validity must be done
+# NOTE: no permission check is done, that is the responsibilty of the caller
 sub get_guest_config_property {
     my ($property, $vmid) = @_;