--- /dev/null
+package PVE::APIClient::Commands::start;
+
+use strict;
+use warnings;
+
+use PVE::APIClient::Helpers;
+use PVE::JSONSchema qw(get_standard_option);
+
+use PVE::CLIHandler;
+
+use base qw(PVE::CLIHandler);
+
+__PACKAGE__->register_method ({
+ name => 'start',
+ path => 'start',
+ method => 'POST',
+ description => "Start a Qemu VM/LinuX Container.",
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ remote => get_standard_option('pveclient-remote-name'),
+ vmid => get_standard_option('pve-vmid'),
+ },
+ },
+ returns => { type => 'null'},
+ code => sub {
+ my ($param) = @_;
+
+ my $config = PVE::APIClient::Config->load();
+ my $conn = PVE::APIClient::Config->remote_conn($config, $param->{remote});
+
+ my $resource = PVE::APIClient::Helpers::get_vmid_resource($conn, $param->{vmid});
+
+ my $upid = $conn->post("api2/json/nodes/$resource->{node}/$resource->{type}/$resource->{vmid}/status/start", {});
+
+ print PVE::APIClient::Helpers::poll_task($conn, $resource->{node}, $upid) . "\n";
+
+ return undef;
+ }});
+
+our $cmddef = [ __PACKAGE__, 'start', ['remote', 'vmid']];
+
+1;
return $info;
}
+sub get_vmid_resource {
+ my ($conn, $vmid) = @_;
+
+ my $resources = $conn->get('api2/json/cluster/resources', {type => 'vm'});
+
+ my $resource;
+ for my $tmp (@$resources) {
+ if ($tmp->{vmid} eq $vmid) {
+ $resource = $tmp;
+ last;
+ }
+ }
+
+ if (!defined($resource)) {
+ die "\"$vmid\" not found";
+ }
+
+ return $resource;
+}
+
+sub poll_task {
+ my ($conn, $node, $upid) = @_;
+
+ my $path = "api2/json/nodes/$node/tasks/$upid/status";
+
+ my $task_status;
+ while(1) {
+ $task_status = $conn->get($path, {});
+
+ if ($task_status->{status} eq "stopped") {
+ last;
+ }
+
+ sleep(10);
+ }
+
+ return $task_status->{exitstatus};
+}
+
1;
use PVE::APIClient::Commands::list;
use PVE::APIClient::Commands::lxc;
use PVE::APIClient::Commands::help;
+use PVE::APIClient::Commands::start;
use JSON;
list => $PVE::APIClient::Commands::list::cmddef,
lxc => $PVE::APIClient::Commands::lxc::cmddef,
remote => $PVE::APIClient::Commands::remote::cmddef,
+
+ start => $PVE::APIClient::Commands::start::cmddef,
api => {
get => [ __PACKAGE__, 'pveclient_get', ['remote', 'api_path']],