]> git.proxmox.com Git - pve-common.git/commitdiff
add 'map_id' helper for ID maps
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 9 Feb 2022 13:07:30 +0000 (14:07 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 9 Feb 2022 17:31:27 +0000 (18:31 +0100)
currently these are used by qemu-server for mapping source and target
storages, but this mechanism will be extended to network bridge maps and
re-used in pve-container as well, so let's put it next to the schema
definitions/helpers.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
src/PVE/JSONSchema.pm

index 38be3f8e9df00db3b310a463e7610edf8bd0ce7c..65055e0155f307355b746cc5831cb42e37f04410 100644 (file)
@@ -249,6 +249,21 @@ sub pve_verify_node_name {
     return $node;
 }
 
+# maps source to target ID using an ID map
+sub map_id {
+    my ($map, $source) = @_;
+
+    return $source if !defined($map);
+
+    return $map->{entries}->{$source}
+       if $map->{entries} && defined($map->{entries}->{$source});
+
+    return $map->{default} if $map->{default};
+
+    # identity (fallback)
+    return $source;
+}
+
 sub parse_idmap {
     my ($idmap, $idformat) = @_;