]> git.proxmox.com Git - pve-manager.git/commitdiff
implement startall/stopall
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 18 Apr 2012 07:57:51 +0000 (09:57 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 18 Apr 2012 08:05:20 +0000 (10:05 +0200)
bin/pvectl
debian/changelog.Debian
defines.mk

index ea72f30ccbd295a6085a63dde079b2905f5d36ad..74550aa9119d8e22a89f77d9727a445ff5162b62 100755 (executable)
@@ -35,6 +35,118 @@ my $upid_exit = sub {
     exit($status eq 'OK' ? 0 : -1);
 };
 
+__PACKAGE__->register_method ({
+    name => 'startall', 
+    path => 'startall', 
+    method => 'POST',
+    description => "Start all containers (when onboot=1).",
+    parameters => {
+       additionalProperties => 0,
+       properties => {},
+    },
+    returns => { type => 'null'},
+    code => sub {
+       my ($param) = @_;
+
+       # wait up to 10 seconds for quorum
+       for (my $i = 10; $i >= 0; $i--) {
+           last if PVE::Cluster::check_cfs_quorum($i != 0 ? 1 : 0);
+           sleep(1);
+       }
+       
+       my $vzlist = PVE::OpenVZ::vmstatus();
+
+       my $cc = PVE::Cluster::cfs_read_file('cluster.conf');
+
+       my $startList = {};
+       foreach my $vmid (keys %$vzlist) {
+           next if $vzlist->{$vmid}->{status} eq 'running'; # already running
+
+           my $conf;
+           eval { $conf = PVE::OpenVZ::load_config($vmid); };
+           if (my $err = $@) {
+               warn $err;
+               next;
+           }
+
+           next if !$conf;
+
+           next if !($conf->{onboot} && $conf->{onboot}->{value});
+
+           # skip ha managed VMs (started by rgmanager)
+           next if PVE::Cluster::cluster_conf_lookup_pvevm($cc, 0, $vmid, 1);
+
+           if ($conf->{bootorder} && defined($conf->{bootorder}->{value})) {
+               $vzlist->{$vmid}->{bootorder} = $conf->{bootorder}->{value};
+           } else {
+               $vzlist->{$vmid}->{bootorder} = -1000000000;
+           }
+           
+           $startList->{$vmid} = $vzlist->{$vmid};
+       }
+
+       foreach my $vmid (sort {
+           return $a <=> $b if $startList->{$b}->{bootorder} == $startList->{$a}->{bootorder};
+           return $startList->{$b}->{bootorder} <=> $startList->{$a}->{bootorder};
+           } keys %$startList) {
+
+           PVE::Cluster::check_cfs_quorum(); # abort when we loose quorum
+
+           eval {
+               print STDERR "Starting CT $vmid\n";
+               PVE::API2::OpenVZ->vm_start({node => $nodename, vmid => $vmid });
+           };
+           warn $@ if $@;
+       }
+
+       return undef;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'stopall', 
+    path => 'stopall', 
+    method => 'POST',
+    description => "Stop all containers.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           timeout => {
+               description => "Wait maximal timeout seconds.",
+               type => 'integer',
+               minimum => 0,
+               optional => 1,
+               default => 60,
+           },
+       },
+    },
+    returns => { type => 'null'},
+    code => sub {
+       my ($param) = @_;
+
+       my $vzlist = PVE::OpenVZ::vmstatus();
+       my $timeout = defined ($param->{timeout}) ? $param->{timeout} : 60;
+
+       syslog('info', "Stopping all Container");
+
+       foreach my $vmid (keys %$vzlist) {
+           next if $vzlist->{$vmid}->{status} ne 'running'; # not running
+
+           eval {
+               print STDERR "Stoping CT $vmid\n";
+
+               # Set fairsched parameters to maximum so CT will stop fast
+               # ignore any errors
+               system("vzctl set $vmid --cpuunits 2000 --cpulimit 0 >/dev/null 2>&1");
+
+               PVE::API2::OpenVZ->vm_shutdown({node => $nodename, vmid => $vmid, 
+                                               timeout => $timeout, forceStop => 1 });
+           };
+           warn $@ if $@;
+       }
+
+       return undef;
+    }});
+
 my $cmddef = {
 
     list => [ "PVE::API2::OpenVZ", 'vmlist', [],
@@ -79,6 +191,8 @@ my $cmddef = {
     umount => [ 'PVE::API2::OpenVZ', 'vm_umount', ['vmid'], { node => $nodename }, $upid_exit],
     migrate => [ "PVE::API2::OpenVZ", 'migrate_vm', ['vmid', 'target'], { node => $nodename }, $upid_exit],
 
+    startall => [ __PACKAGE__, 'startall', []],
+    stopall => [ __PACKAGE__, 'stopall', []],
 };
 
 my $cmd = shift;
index dd745d0e8c61c02e607134788d31a82475b79ec6..9e1d1c0569197b9f1693a1c41a57d281f19c4ee1 100644 (file)
@@ -1,3 +1,9 @@
+pve-manager (2.0-63) unstable; urgency=low
+
+  * fix bug 128: implement pvectl startall/stopall
+
+ -- Proxmox Support Team <support@proxmox.com>  Wed, 18 Apr 2012 10:02:54 +0200
+
 pve-manager (2.0-62) unstable; urgency=low
 
   * fix bug #115: simplify GUI for users without permissions.
index 472ad4106020aa6de870cd2813c614e894170f4f..e97576410ca935d97d300c8afb4242277039481d 100644 (file)
@@ -2,7 +2,7 @@ RELEASE=2.0
 
 VERSION=2.0
 PACKAGE=pve-manager
-PACKAGERELEASE=62
+PACKAGERELEASE=63
 
 BINDIR=${DESTDIR}/usr/bin
 PERLLIBDIR=${DESTDIR}/usr/share/perl5