]> git.proxmox.com Git - pmg-api.git/blobdiff - PMG/ClusterConfig.pm
close #1887: register tls_policy file with reader/writer
[pmg-api.git] / PMG / ClusterConfig.pm
index 6a2425e86f34e065e0f09a8765808537ad96a53d..af58d76573f41357d98ec3d204df4fa8411906c4 100644 (file)
@@ -37,7 +37,6 @@ sub parse_section_header {
     return undef;
 }
 
-
 package PMG::ClusterConfig::Node;
 
 use strict;
@@ -52,7 +51,7 @@ sub properties {
     return {
        ip => {
            description => "IP address.",
-           type => 'string', format => 'address',
+           type => 'string', format => 'ip',
        },
        name => {
            description => "Node name.",
@@ -61,10 +60,17 @@ sub properties {
        hostrsapubkey => {
            description => "Public SSH RSA key for the host.",
            type => 'string',
+           pattern => '^[A-Za-z0-9\.\/\+]{200,}$',
        },
        rootrsapubkey => {
            description => "Public SSH RSA key for the root user.",
            type => 'string',
+           pattern => '^[A-Za-z0-9\.\/\+]{200,}$',
+       },
+       fingerprint => {
+           description => "SSL certificate fingerprint.",
+           type => 'string',
+           pattern => '^(:?[A-Z0-9][A-Z0-9]:){31}[A-Z0-9][A-Z0-9]$',
        },
     };
 }
@@ -75,6 +81,7 @@ sub options {
        name => { fixed => 1 },
        hostrsapubkey => {},
        rootrsapubkey => {},
+       fingerprint => {},
     };
 }
 
@@ -106,6 +113,7 @@ sub options {
        name => { fixed => 1 },
        hostrsapubkey => {},
        rootrsapubkey => {},
+       fingerprint => {},
     };
 }
 
@@ -147,10 +155,11 @@ my $lockfile = "/var/lock/pmgcluster.lck";
 sub lock_config {
     my ($code, $errmsg) = @_;
 
-    my $p = PVE::Tools::lock_file($lockfile, undef, $code);
+    my $res = PVE::Tools::lock_file($lockfile, undef, $code);
     if (my $err = $@) {
        $errmsg ? die "$errmsg: $err" : die $err;
     }
+    return $res;
 }
 
 sub read_cluster_conf {
@@ -161,14 +170,11 @@ sub read_cluster_conf {
     my $raw = defined($fh) ? <$fh> : undef;
 
     my $cinfo = PMG::ClusterConfig::Base->parse_config($filename, $raw);
-    print Dumper($cinfo);
 
     my $localname = PVE::INotify::nodename();
     my $localip = PMG::Utils::lookup_node_ip($localname);
 
     $cinfo->{remnodes} = [];
-    $cinfo->{configport}->{0} = 83;
-    $cinfo->{dbport}->{0} = 5432;
 
     $cinfo->{local} = {
        cid => 0,
@@ -200,16 +206,10 @@ sub read_cluster_conf {
        $cinfo->{master}->{maxcid} = $maxcid;
     }
 
-    my $ind = 0;
+    my $local_cid = $cinfo->{local}->{cid};
     foreach my $cid (sort keys %{$cinfo->{ids}}) {
-       if ($cinfo->{'local'}->{cid} == $cid) { # local CID
-           $cinfo->{configport}->{$cid} = 83;
-           $cinfo->{dbport}->{$cid} = 5432;
-       } else {
-           my $portid = $ind++;
-           $cinfo->{configport}->{$cid} = 50000 + $portid;
-           $cinfo->{dbport}->{$cid} = 50100 + $portid;
-           push @{$cinfo->{remnodes}}, $cinfo->{ids}->{$cid};
+       if ($local_cid != $cid) {
+           push @{$cinfo->{remnodes}}, $cid;
        }
     }
 
@@ -224,7 +224,7 @@ sub write_cluster_conf {
     PVE::Tools::safe_print($filename, $fh, $raw);
 }
 
-PVE::INotify::register_file('cluster.conf', "/etc/proxmox/cluster.conf",
+PVE::INotify::register_file('cluster.conf', "/etc/pmg/cluster.conf",
                            \&read_cluster_conf,
                            \&write_cluster_conf,
                            undef,