[pve-devel] [PATCH v5 common 1/1] add 'map_id' helper for ID maps
Fabian Grünbichler
f.gruenbichler at proxmox.com
Wed Feb 9 14:07:30 CET 2022
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 at proxmox.com>
---
Notes:
new in v5, required by pve-container and qemu-server
src/PVE/JSONSchema.pm | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 38be3f8..65055e0 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -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) = @_;
--
2.30.2
More information about the pve-devel
mailing list