[pve-devel] [PATCH manager] ceph: make all service name regexes the same

Dominik Csapak d.csapak at proxmox.com
Mon Feb 24 16:32:19 CET 2020


instead of having multiple regexes in various places for the name,
define a 'SERVICE_REGEX' in PVE::Ceph::Services, and use that
everywhere in the api where we need it

additionally limit new sevices to 200 characters, since
systemd units have a limit of 256 characters[0] (including suffix), and
200 seems to be enough.

users can now create ceph services on machines with hostnames
longer than 32 characters

0: https://www.freedesktop.org/software/systemd/man/systemd.unit.html

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
replaces my patch "ceph: increase allowed service names to 63 characters"

 PVE/API2/Ceph.pm     | 6 +++---
 PVE/API2/Ceph/MDS.pm | 5 +++--
 PVE/API2/Ceph/MGR.pm | 5 +++--
 PVE/API2/Ceph/MON.pm | 5 +++--
 PVE/Ceph/Services.pm | 4 +++-
 5 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index 391382f8..85a04101 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -424,7 +424,7 @@ __PACKAGE__->register_method ({
 		type => 'string',
 		optional => 1,
 		default => 'ceph.target',
-		pattern => '(ceph|mon|mds|osd|mgr)(\.[A-Za-z0-9\-]{1,32})?',
+		pattern => '(ceph|mon|mds|osd|mgr)(\.'.PVE::Ceph::Services::SERVICE_REGEX.')?',
 	    },
 	},
     },
@@ -475,7 +475,7 @@ __PACKAGE__->register_method ({
 		type => 'string',
 		optional => 1,
 		default => 'ceph.target',
-		pattern => '(ceph|mon|mds|osd|mgr)(\.[A-Za-z0-9\-]{1,32})?',
+		pattern => '(ceph|mon|mds|osd|mgr)(\.'.PVE::Ceph::Services::SERVICE_REGEX.')?',
 	    },
 	},
     },
@@ -526,7 +526,7 @@ __PACKAGE__->register_method ({
 		type => 'string',
 		optional => 1,
 		default => 'ceph.target',
-		pattern => '(mon|mds|osd|mgr)(\.[A-Za-z0-9\-]{1,32})?',
+		pattern => '(mon|mds|osd|mgr)(\.'.PVE::Ceph::Services::SERVICE_REGEX.')?',
 	    },
 	},
     },
diff --git a/PVE/API2/Ceph/MDS.pm b/PVE/API2/Ceph/MDS.pm
index 532eb404..1cb0b74f 100644
--- a/PVE/API2/Ceph/MDS.pm
+++ b/PVE/API2/Ceph/MDS.pm
@@ -104,7 +104,8 @@ __PACKAGE__->register_method ({
 		type => 'string',
 		optional => 1,
 		default => 'nodename',
-		pattern => '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
+		pattern => PVE::Ceph::Services::SERVICE_REGEX,
+		maxLength => 200,
 		description => "The ID for the mds, when omitted the same as the nodename",
 	    },
 	    hotstandby => {
@@ -195,7 +196,7 @@ __PACKAGE__->register_method ({
 	    name => {
 		description => 'The name (ID) of the mds',
 		type => 'string',
-		pattern => '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
+		pattern => PVE::Ceph::Services::SERVICE_REGEX,
 	    },
 	},
     },
diff --git a/PVE/API2/Ceph/MGR.pm b/PVE/API2/Ceph/MGR.pm
index ffae7495..2dc679ef 100644
--- a/PVE/API2/Ceph/MGR.pm
+++ b/PVE/API2/Ceph/MGR.pm
@@ -97,7 +97,8 @@ __PACKAGE__->register_method ({
 	    id => {
 		type => 'string',
 		optional => 1,
-		pattern => '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
+		pattern => PVE::Ceph::Services::SERVICE_REGEX,
+		maxLength => 200,
 		description => "The ID for the manager, when omitted the same as the nodename",
 	    },
 	},
@@ -144,7 +145,7 @@ __PACKAGE__->register_method ({
 	    id => {
 		description => 'The ID of the manager',
 		type => 'string',
-		pattern => '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
+		pattern => PVE::Ceph::Services::SERVICE_REGEX,
 	    },
 	},
     },
diff --git a/PVE/API2/Ceph/MON.pm b/PVE/API2/Ceph/MON.pm
index 0432ca67..18b563c9 100644
--- a/PVE/API2/Ceph/MON.pm
+++ b/PVE/API2/Ceph/MON.pm
@@ -172,7 +172,8 @@ __PACKAGE__->register_method ({
 	    monid => {
 		type => 'string',
 		optional => 1,
-		pattern => '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
+		pattern => PVE::Ceph::Services::SERVICE_REGEX,
+		maxLength => 200,
 		description => "The ID for the monitor, when omitted the same as the nodename",
 	    },
 	    'mon-address' => {
@@ -320,7 +321,7 @@ __PACKAGE__->register_method ({
 	    monid => {
 		description => 'Monitor ID',
 		type => 'string',
-		pattern => '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
+		pattern => PVE::Ceph::Services::SERVICE_REGEX,
 	    },
 	},
     },
diff --git a/PVE/Ceph/Services.pm b/PVE/Ceph/Services.pm
index 45eb6c3f..c17008cf 100644
--- a/PVE/Ceph/Services.pm
+++ b/PVE/Ceph/Services.pm
@@ -11,6 +11,8 @@ use PVE::RADOS;
 use JSON;
 use File::Path;
 
+use constant SERVICE_REGEX => '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?';
+
 # checks /etc/systemd/system/ceph-* to list all services, even if not running
 # also checks /var/lib/ceph/$type
 sub get_local_services {
@@ -62,7 +64,7 @@ sub ceph_service_cmd {
     my ($action, $service) = @_;
 
     my $pve_ceph_cfgpath = PVE::Ceph::Tools::get_config('pve_ceph_cfgpath');
-    if ($service && $service =~ m/^(mon|osd|mds|mgr|radosgw)(\.([A-Za-z0-9\-]{1,32}))?$/) {
+    if ($service && $service =~ m/^(mon|osd|mds|mgr|radosgw)(\.(${\SERVICE_REGEX}))?$/) {
 	$service = defined($3) ? "ceph-$1\@$3" : "ceph-$1.target";
     } else {
 	$service = "ceph.target";
-- 
2.20.1





More information about the pve-devel mailing list