[pve-devel] r6361 - in pve-storage/pve2: . PVE PVE/API2/Storage

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Jul 26 08:49:36 CEST 2011


Author: dietmar
Date: 2011-07-26 08:49:36 +0200 (Tue, 26 Jul 2011)
New Revision: 6361

Modified:
   pve-storage/pve2/ChangeLog
   pve-storage/pve2/PVE/API2/Storage/Config.pm
   pve-storage/pve2/PVE/API2/Storage/Scan.pm
   pve-storage/pve2/PVE/Storage.pm
Log:
	* PVE/Storage.pm (verify_portal_dns): new type
	'pve-storage-portal-dns', which allows to use a DNS name.
	(resolv_portal_dns): helper to convert portal with DNS name to IP address.

	* PVE/API2/Storage/Config.pm: 'target' can be arbitrary string (we
	do not check format for now)



Modified: pve-storage/pve2/ChangeLog
===================================================================
--- pve-storage/pve2/ChangeLog	2011-07-26 05:09:16 UTC (rev 6360)
+++ pve-storage/pve2/ChangeLog	2011-07-26 06:49:36 UTC (rev 6361)
@@ -1,5 +1,12 @@
 2011-07-26  Proxmox Support Team  <support at proxmox.com>
 
+	* PVE/Storage.pm (verify_portal_dns): new type
+	'pve-storage-portal-dns', which allows to use a DNS name.
+	(resolv_portal_dns): helper to convert portal with DNS name to IP address.
+
+	* PVE/API2/Storage/Config.pm: 'target' can be arbitrary string (we
+	do not check format for now)
+
 	* PVE/API2/Storage/Scan.pm (iscsiscan): rename 'server' to 'portal'
 
 2010-11-08  Proxmox Support Team  <support at proxmox.com>

Modified: pve-storage/pve2/PVE/API2/Storage/Config.pm
===================================================================
--- pve-storage/pve2/PVE/API2/Storage/Config.pm	2011-07-26 05:09:16 UTC (rev 6360)
+++ pve-storage/pve2/PVE/API2/Storage/Config.pm	2011-07-26 06:49:36 UTC (rev 6361)
@@ -125,7 +125,7 @@
 		optional => 1,
 	    },
             target => {
-		type => 'string', format => 'pve-storage-server',
+		type => 'string',
 		optional => 1,
             },
             vgname => {
@@ -133,7 +133,7 @@
 		optional => 1,
             },
             portal => {
-		type => 'string', format => 'pve-storage-portal',
+		type => 'string', format => 'pve-storage-portal-dns',
 		optional => 1,
             },
 	    content => {
@@ -164,8 +164,13 @@
 	my $storeid = $param->{storage};
 	delete $param->{storage};
 
+	if ($param->{portal}) {
+	    $param->{portal} = PVE::Storage::resolv_portal_dns($param->{portal});
+	}
+
 	my $opts = PVE::Storage::parse_options($storeid, $type, $param, 1);
 
+
         PVE::Storage::lock_storage_config(
 	    sub {
 

Modified: pve-storage/pve2/PVE/API2/Storage/Scan.pm
===================================================================
--- pve-storage/pve2/PVE/API2/Storage/Scan.pm	2011-07-26 05:09:16 UTC (rev 6360)
+++ pve-storage/pve2/PVE/API2/Storage/Scan.pm	2011-07-26 06:49:36 UTC (rev 6361)
@@ -91,7 +91,7 @@
     	additionalProperties => 0,
 	properties => {
 	    node => get_standard_option('pve-node'),
-	    portal => { type => 'string', format => 'pve-storage-server' },
+	    portal => { type => 'string', format => 'pve-storage-portal-dns' },
 	},
     },
     returns => {
@@ -107,7 +107,7 @@
     code => sub {
 	my ($param) = @_;
 
-	my $portal = $param->{portal};
+	my $portal = PVE::Storage::resolv_portal_dns($param->{portal});
 	my $res = PVE::Storage::scan_iscsi($portal);
 
 	my $data = [];

Modified: pve-storage/pve2/PVE/Storage.pm
===================================================================
--- pve-storage/pve2/PVE/Storage.pm	2011-07-26 05:09:16 UTC (rev 6360)
+++ pve-storage/pve2/PVE/Storage.pm	2011-07-26 06:49:36 UTC (rev 6361)
@@ -257,6 +257,35 @@
     return $portal;
 }
 
+PVE::JSONSchema::register_format('pve-storage-portal-dns', \&verify_portal_dns);
+sub verify_portal_dns {
+    my ($portal, $noerr) = @_;
+
+    # IP or DNS name with optional port
+    if ($portal !~ m/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|[[:alnum:]\-\.]+)(:\d+)?$/) {
+	return undef if $noerr;
+	die "value does not look like a valid portal address\n";
+    }
+    return $portal;
+}
+
+sub resolv_portal_dns {
+    my ($portal_dns) = @_;
+    
+    if ($portal_dns =~ m/^([^:]+)(:(\d+))?$/) {
+	my $server = $1;
+	my $port = $3;
+
+	my $packed_ip = gethostbyname($server);
+	if (defined $packed_ip) {
+	    $server = inet_ntoa($packed_ip);
+	    return $port ? "$server:$port" : $server;
+	}
+
+	raise_param_exc({ portal => "unable to resolve portal address" });
+    }
+}
+
 PVE::JSONSchema::register_format('pve-storage-content', \&verify_content);
 sub verify_content {
     my ($ct, $noerr) = @_;
@@ -336,8 +365,8 @@
 	return parse_lvm_name ($value, $noerr);
     } elsif ($ct eq 'portal') {
 	return verify_portal($value, $noerr);
-   } elsif ($ct eq 'target') {
-	return verify_server($value, $noerr);
+    } elsif ($ct eq 'target') {
+	return $value;
     } elsif ($ct eq 'string') {
 	return $value;
     } elsif ($ct eq 'format') {




More information about the pve-devel mailing list