use PVE::Cluster;
use PVE::INotify;
use PVE::JSONSchema;
-use PVE::RPCEnvironment;
use PVE::CLIHandler;
use base qw(PVE::CLIHandler);
mkdir $backupdir;
my $ctime = time();
- my $cmd = "echo '.dump' |";
- $cmd .= "sqlite3 '$dbfile' |";
- $cmd .= "gzip - >'${backupdir}/config-${ctime}.sql.gz'";
+ my $cmd = [
+ ['echo', '.dump'],
+ ['sqlite3', $dbfile],
+ ['gzip', '-', \">${backupdir}/config-${ctime}.sql.gz"],
+ ];
- system($cmd) == 0 ||
- die "can't backup old database: $!\n";
+ PVE::Tools::run_command($cmd, 'errmsg' => "can't backup old database\n");
# purge older backup
my $maxfiles = 10;
parameters => {
additionalProperties => 0,
properties => {
- node => PVE::JSONSchema::get_standard_option('pve-node'),
+ node => {
+ type => 'string',
+ description => "Hostname or IP of the corosync ring0 address of this node.",
+ },
},
},
returns => { type => 'null' },
my $nodelist = corosync_nodelist($conf);
- my $nd = delete $nodelist->{$param->{node}};
- die "no such node '$param->{node}'\n" if !$nd;
-
+ my $node;
+ my $nodeid;
+
+ foreach my $tmp_node (keys %$nodelist) {
+ my $d = $nodelist->{$tmp_node};
+ my $ring0_addr = $d->{ring0_addr};
+ my $ring1_addr = $d->{ring1_addr};
+ if (($tmp_node eq $param->{node}) ||
+ (defined($ring0_addr) && ($ring0_addr eq $param->{node})) ||
+ (defined($ring1_addr) && ($ring1_addr eq $param->{node}))) {
+ $node = $tmp_node;
+ $nodeid = $d->{nodeid};
+ last;
+ }
+ }
+
+ die "Node/IP: $param->{node} is not a known host of the cluster.\n"
+ if !defined($node);
+
+ delete $nodelist->{$node};
+
corosync_update_nodelist($conf, $nodelist);
+ PVE::Tools::run_command(['corosync-cfgtool','-k', $nodeid])
+ if defined($nodeid);
+
return undef;
}});
# make sure known_hosts is on local filesystem
PVE::Cluster::ssh_unmerge_known_hosts();
- my $cmd = "ssh-copy-id -i /root/.ssh/id_rsa 'root\@$host' >/dev/null 2>&1";
- system ($cmd) == 0 ||
- die "unable to copy ssh ID\n";
+ my $cmd = ['ssh-copy-id', '-i', '/root/.ssh/id_rsa', "root\@$host"];
+ PVE::Tools::run_command($cmd, 'outfunc' => sub {}, 'errfunc' => sub {},
+ 'errmsg' => "unable to copy ssh ID");
$cmd = ['ssh', $host, '-o', 'BatchMode=yes',
'pvecm', 'addnode', $nodename, '--force', 1];
code => sub {
my ($param) = @_;
+ PVE::Cluster::check_corosync_conf_exists();
+
my $cmd = ['corosync-quorumtool', '-siH'];
exec (@$cmd);
code => sub {
my ($param) = @_;
+ PVE::Cluster::check_corosync_conf_exists();
+
my $cmd = ['corosync-quorumtool', '-l'];
exec (@$cmd);
code => sub {
my ($param) = @_;
+ PVE::Cluster::check_corosync_conf_exists();
+
my $cmd = ['corosync-quorumtool', '-e', $param->{expected}];
exec (@$cmd);
return undef;
}});
+__PACKAGE__->register_method ({
+ name => 'mtunnel',
+ path => 'mtunnel',
+ method => 'POST',
+ description => "Used by VM/CT migration - do not use manually.",
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ get_migration_ip => {
+ type => 'boolean',
+ default => 0,
+ description => 'return the migration IP, if configured',
+ optional => 1,
+ },
+ migration_network => {
+ type => 'string',
+ format => 'CIDR',
+ description => 'the migration network used to detect the local migration IP',
+ optional => 1,
+ },
+ },
+ },
+ returns => { type => 'null'},
+ code => sub {
+ my ($param) = @_;
+
+ if (!PVE::Cluster::check_cfs_quorum(1)) {
+ print "no quorum\n";
+ return undef;
+ }
+
+ if ($param->{get_migration_ip}) {
+ my $network = $param->{migration_network};
+ if (my $ip = PVE::Cluster::get_local_migration_ip($network)) {
+ print "ip: '$ip'\n";
+ } else {
+ print "no ip\n";
+ }
+ # do not keep tunnel open when asked for migration ip
+ return undef;
+ }
+
+ print "tunnel online\n";
+ *STDOUT->flush();
+
+ while (my $line = <>) {
+ chomp $line;
+ last if $line =~ m/^quit$/;
+ }
+
+ return undef;
+ }});
+
our $cmddef = {
keygen => [ __PACKAGE__, 'keygen', ['filename']],
nodes => [ __PACKAGE__, 'nodes' ],
expected => [ __PACKAGE__, 'expected', ['expected']],
updatecerts => [ __PACKAGE__, 'updatecerts', []],
+ mtunnel => [ __PACKAGE__, 'mtunnel', []],
};
1;
-
-__END__
-
-=head1 NAME
-
-pvecm - Proxmox VE cluster manager toolkit
-
-=head1 SYNOPSIS
-
-=include synopsis
-
-=head1 DESCRIPTION
-
-pvecm is a program to manage the cluster configuration. It can be used
-to create a new cluster, join nodes to a cluster, leave the cluster,
-get status information and do various other cluster related tasks.
-
-=include pve_copyright
-
-