[pve-devel] [PATCH RFC 13/21] code cleanup: factor out common code

Dietmar Maurer dietmar at proxmox.com
Mon Nov 28 08:09:05 CET 2016


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 data/PVE/CLI/pvecm.pm | 40 +++++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/data/PVE/CLI/pvecm.pm b/data/PVE/CLI/pvecm.pm
index 2e60cda..ad9a9b0 100755
--- a/data/PVE/CLI/pvecm.pm
+++ b/data/PVE/CLI/pvecm.pm
@@ -96,6 +96,22 @@ __PACKAGE__->register_method ({
 	return undef;
     }});
 
+my $update_cluster_files = sub {
+    my ($quorate,  $nodename, $local_ip_address, $force) = @_;
+
+    if ($quorate) {
+	PVE::Cluster::gen_pve_node_files($nodename, $local_ip_address, $force);
+	PVE::Cluster::setup_ssh_keys();
+	PVE::Cluster::ssh_merge_keys();
+	PVE::Cluster::ssh_merge_known_hosts($nodename, $local_ip_address);
+	PVE::Cluster::gen_pve_vzdump_files();
+    }
+
+    PVE::Cluster::setup_sshd_config(0, $force);
+    PVE::Cluster::setup_rootsshconfig($force);
+    PVE::Cluster::gen_pve_vzdump_symlink();
+};
+
 __PACKAGE__->register_method ({
     name => 'create', 
     path => 'create',
@@ -253,15 +269,7 @@ _EOD
 ;
 	PVE::Tools::file_set_contents($clusterconf, $config);
 
-	PVE::Cluster::gen_pve_node_files($nodename, $local_ip_address);
-	PVE::Cluster::setup_ssh_keys();
-	PVE::Cluster::ssh_merge_keys();
-	PVE::Cluster::ssh_merge_known_hosts($nodename, $local_ip_address, 1);
-	PVE::Cluster::gen_pve_vzdump_files();
-
-	PVE::Cluster::setup_sshd_config(1);
-	PVE::Cluster::setup_rootsshconfig();
-	PVE::Cluster::gen_pve_vzdump_symlink();
+	$update_cluster_files->(1, $nodename, $local_ip_address, 0);
 
 	PVE::Tools::run_command('systemctl restart pve-cluster'); # restart
 
@@ -815,19 +823,9 @@ __PACKAGE__->register_method ({
 
 	my $quorate = PVE::Cluster::check_cfs_quorum(1);
 
-	if ($quorate) {
-	    my $local_ip_address = PVE::Cluster::remote_node_ip($nodename);
-
-	    PVE::Cluster::gen_pve_node_files($nodename, $local_ip_address, $param->{force});
-	    PVE::Cluster::setup_ssh_keys();
-	    PVE::Cluster::ssh_merge_keys();
-	    PVE::Cluster::ssh_merge_known_hosts($nodename, $local_ip_address);
-	    PVE::Cluster::gen_pve_vzdump_files();
-	}
+	my $local_ip_address = PVE::Cluster::remote_node_ip($nodename);
 
-	PVE::Cluster::setup_sshd_config(0, $param->{force});
-	PVE::Cluster::setup_rootsshconfig($param->{force});
-	PVE::Cluster::gen_pve_vzdump_symlink();
+	$update_cluster_files->($quorate, $nodename, $local_ip_address, $param->{force});
 
 	if (!$quorate) {
 	    return undef if $param->{silent};
-- 
2.1.4




More information about the pve-devel mailing list