--- PVE/APIClient/Commands/help.pm | 2 ++ PVE/APIClient/Commands/start.pm | 39 +++++++++++++++++++++++++++++++++++++++ PVE/APIClient/Helpers.pm | 20 ++++++++++++++++++++ pveclient | 2 ++ 4 files changed, 63 insertions(+) create mode 100644 PVE/APIClient/Commands/start.pm
diff --git a/PVE/APIClient/Commands/help.pm b/PVE/APIClient/Commands/help.pm index 81d4d4a..c0de8e8 100644 --- a/PVE/APIClient/Commands/help.pm +++ b/PVE/APIClient/Commands/help.pm @@ -7,6 +7,7 @@ use PVE::APIClient::Commands::help; use PVE::APIClient::Commands::list; use PVE::APIClient::Commands::lxc; use PVE::APIClient::Commands::remote; +use PVE::APIClient::Commands::start; use PVE::CLIHandler; @@ -59,6 +60,7 @@ __PACKAGE__->register_method ({ $assemble_usage_string->('list', $PVE::APIClient::Commands::list::cmddef); $assemble_usage_string->('lxc', $PVE::APIClient::Commands::lxc::cmddef); $assemble_usage_string->('remote', $PVE::APIClient::Commands::remote::cmddef); + $assemble_usage_string->('start', $PVE::APIClient::Commands::start::cmddef); $text .= "pveclient <get/set/create/delete> <path> {options}\n\n"; diff --git a/PVE/APIClient/Commands/start.pm b/PVE/APIClient/Commands/start.pm new file mode 100644 index 0000000..4858bec --- /dev/null +++ b/PVE/APIClient/Commands/start.pm @@ -0,0 +1,39 @@ +package PVE::APIClient::Commands::start; + +use strict; +use warnings; + +use PVE::APIClient::Helpers; +use PVE::JSONSchema qw(get_standard_option); + +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}); + + $conn->post("api2/json/nodes/$resource->{node}/$resource->{type}/$resource->{vmid}/status/start", {}); + + return undef; + }}); + +our $cmddef = [ __PACKAGE__, 'start', ['remote', 'vmid']]; + +1; diff --git a/PVE/APIClient/Helpers.pm b/PVE/APIClient/Helpers.pm index e7f2216..6663ce3 100644 --- a/PVE/APIClient/Helpers.pm +++ b/PVE/APIClient/Helpers.pm @@ -66,4 +66,24 @@ sub lookup_api_method { return $data; } +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; +} + 1; diff --git a/pveclient b/pveclient index 6a06a88..609ad9f 100755 --- a/pveclient +++ b/pveclient @@ -16,6 +16,7 @@ use PVE::APIClient::Commands::remote; use PVE::APIClient::Commands::list; use PVE::APIClient::Commands::lxc; use PVE::APIClient::Commands::help; +use PVE::APIClient::Commands::start; use JSON; @@ -35,6 +36,7 @@ my $cli_class_handlers = { list => 'PVE::APIClient::Commands::list', lxc => 'PVE::APIClient::Commands::lxc', remote => 'PVE::APIClient::Commands::remote', + start => 'PVE::APIClient::Commands::start', help => 'PVE::APIClient::Commands::help', }; -- 2.11.0 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel