Besides the obvious reduction of duplicated code, this also
streamlines the descriptions.

Suggested-by: Fabian Grünbichler <[email protected]>
Signed-off-by: Thomas Lamprecht <[email protected]>
---
 data/PVE/API2/ClusterConfig.pm | 89 +++++++++++++++++-------------------------
 data/PVE/CLI/pvecm.pm          | 25 +++---------
 2 files changed, 40 insertions(+), 74 deletions(-)

diff --git a/data/PVE/API2/ClusterConfig.pm b/data/PVE/API2/ClusterConfig.pm
index 8c88a17..daabcf1 100644
--- a/data/PVE/API2/ClusterConfig.pm
+++ b/data/PVE/API2/ClusterConfig.pm
@@ -17,6 +17,30 @@ use base qw(PVE::RESTHandler);
 my $clusterconf = "/etc/pve/corosync.conf";
 my $authfile = "/etc/corosync/authkey";
 
+my $ring0_desc = {
+    type => 'string', format => 'address',
+    description => "Hostname (or IP) of the corosync ring0 address of this 
node.",
+    default => "Hostname of the node",
+    optional => 1,
+};
+PVE::JSONSchema::register_standard_option("corosync-ring0-addr", $ring0_desc);
+
+my $ring1_desc = {
+    type => 'string', format => 'address',
+    description => "Hostname (or IP) of the corosync ring1 address of this 
node.".
+       " Requires a valid configured ring 1 (bindnet1_addr) in the cluster.",
+    optional => 1,
+};
+PVE::JSONSchema::register_standard_option("corosync-ring1-addr", $ring1_desc);
+
+my $nodeid_desc = {
+    type => 'integer',
+    description => "Node id for this node.",
+    minimum => 1,
+    optional => 1,
+};
+PVE::JSONSchema::register_standard_option("corosync-nodeid", $nodeid_desc);
+
 __PACKAGE__->register_method({
     name => 'index',
     path => '',
@@ -62,12 +86,7 @@ __PACKAGE__->register_method ({
                type => 'string', format => 'pve-node',
                maxLength => 15,
            },
-           nodeid => {
-               type => 'integer',
-               description => "Node id for this node.",
-               minimum => 1,
-               optional => 1,
-           },
+           nodeid => get_standard_option('corosync-nodeid'),
            votes => {
                type => 'integer',
                description => "Number of votes for this node.",
@@ -80,24 +99,14 @@ __PACKAGE__->register_method ({
                    " executive should bind to and defaults to the local IP 
address of the node.",
                optional => 1,
            },
-           ring0_addr => {
-               type => 'string', format => 'address',
-               description => "Hostname (or IP) of the corosync ring0 address 
of this node.".
-                   " Defaults to the hostname of the node.",
-               optional => 1,
-           },
+           ring0_addr => get_standard_option('corosync-ring0-addr'),
            bindnet1_addr => {
                type => 'string', format => 'ip',
                description => "This specifies the network address the corosync 
ring 1".
                    " executive should bind to and is optional.",
                optional => 1,
            },
-           ring1_addr => {
-               type => 'string', format => 'address',
-               description => "Hostname (or IP) of the corosync ring1 address, 
this".
-                   " needs an valid bindnet1_addr.",
-               optional => 1,
-           },
+           ring1_addr => get_standard_option('corosync-ring1-addr'),
        },
     },
     returns => { type => 'string' },
@@ -198,12 +207,7 @@ __PACKAGE__->register_method ({
        additionalProperties => 0,
        properties => {
            node => get_standard_option('pve-node'),
-           nodeid => {
-               type => 'integer',
-               description => "Node id for this node.",
-               minimum => 1,
-               optional => 1,
-           },
+           nodeid => get_standard_option('corosync-nodeid'),
            votes => {
                type => 'integer',
                description => "Number of votes for this node",
@@ -215,18 +219,8 @@ __PACKAGE__->register_method ({
                description => "Do not throw error if node already exists.",
                optional => 1,
            },
-           ring0_addr => {
-               type => 'string', format => 'address',
-               description => "Hostname (or IP) of the corosync ring0 address 
of this node.".
-                   " Defaults to nodes hostname.",
-               optional => 1,
-           },
-           ring1_addr => {
-               type => 'string', format => 'address',
-               description => "Hostname (or IP) of the corosync ring1 address, 
this".
-                   " needs an valid bindnet1_addr.",
-               optional => 1,
-           },
+           ring0_addr => get_standard_option('corosync-ring0-addr'),
+           ring1_addr => get_standard_option('corosync-ring1-addr'),
        },
     },
     returns => {
@@ -408,12 +402,7 @@ __PACKAGE__->register_method ({
                type => 'string',
                description => "Hostname (or IP) of an existing cluster member."
            },
-           nodeid => {
-               type => 'integer',
-               description => "Node id for this node.",
-               minimum => 1,
-               optional => 1,
-           },
+           nodeid => get_standard_option('corosync-nodeid'),
            votes => {
                type => 'integer',
                description => "Number of votes for this node",
@@ -425,18 +414,10 @@ __PACKAGE__->register_method ({
                description => "Do not throw error if node already exists.",
                optional => 1,
            },
-           ring0_addr => {
-               type => 'string', format => 'address',
-               description => "Hostname (or IP) of the corosync ring0 address 
of this node.".
-                   " Defaults to nodes hostname.",
-               optional => 1,
-           },
-           ring1_addr => {
-               type => 'string', format => 'address',
-               description => "Hostname (or IP) of the corosync ring1 address, 
this".
-                   " needs an valid configured ring 1 interface in the 
cluster.",
-               optional => 1,
-           },
+           ring0_addr => get_standard_option('corosync-ring0-addr', {
+               default => 'node\'s hostname',
+           }),
+           ring1_addr => get_standard_option('corosync-ring1-addr'),
            fingerprint => get_standard_option('fingerprint-sha256', {
                description => "SSL certificate fingerprint. Optional in CLI 
environment.",
                optional => 1,
diff --git a/data/PVE/CLI/pvecm.pm b/data/PVE/CLI/pvecm.pm
index 864d5f6..aec27f5 100755
--- a/data/PVE/CLI/pvecm.pm
+++ b/data/PVE/CLI/pvecm.pm
@@ -8,7 +8,7 @@ use File::Basename;
 use PVE::Tools qw(run_command);
 use PVE::Cluster;
 use PVE::INotify;
-use PVE::JSONSchema;
+use PVE::JSONSchema qw(get_standard_option);
 use PVE::RPCEnvironment;
 use PVE::CLIHandler;
 use PVE::PTY;
@@ -75,12 +75,7 @@ __PACKAGE__->register_method ({
                type => 'string',
                description => "Hostname (or IP) of an existing cluster member."
            },
-           nodeid => {
-               type => 'integer',
-               description => "Node id for this node.",
-               minimum => 1,
-               optional => 1,
-           },
+           nodeid => get_standard_option('corosync-nodeid'),
            votes => {
                type => 'integer',
                description => "Number of votes for this node",
@@ -92,19 +87,9 @@ __PACKAGE__->register_method ({
                description => "Do not throw error if node already exists.",
                optional => 1,
            },
-           ring0_addr => {
-               type => 'string', format => 'address',
-               description => "Hostname (or IP) of the corosync ring0 address 
of this node.".
-                   " Defaults to nodes hostname.",
-               optional => 1,
-           },
-           ring1_addr => {
-               type => 'string', format => 'address',
-               description => "Hostname (or IP) of the corosync ring1 address, 
this".
-                   " needs an valid configured ring 1 interface in the 
cluster.",
-               optional => 1,
-           },
-           fingerprint => 
PVE::JSONSchema::get_standard_option('fingerprint-sha256', {
+           ring0_addr => get_standard_option('corosync-ring0-addr'),
+           ring1_addr => get_standard_option('corosync-ring1-addr'),
+           fingerprint => get_standard_option('fingerprint-sha256', {
                optional => 1,
            }),
            'use_ssh' => {
-- 
2.14.2


_______________________________________________
pve-devel mailing list
[email protected]
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to