mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-07 13:02:46 +00:00
implement a few bash completion helpers
This commit is contained in:
parent
f3e76e36bc
commit
65e866e5da
@ -271,12 +271,13 @@ __PACKAGE__->register_method({
|
|||||||
properties => PVE::QemuServer::json_config_properties(
|
properties => PVE::QemuServer::json_config_properties(
|
||||||
{
|
{
|
||||||
node => get_standard_option('pve-node'),
|
node => get_standard_option('pve-node'),
|
||||||
vmid => get_standard_option('pve-vmid'),
|
vmid => get_standard_option('pve-vmid', { completion => \&PVE::Cluster::complete_next_vmid }),
|
||||||
archive => {
|
archive => {
|
||||||
description => "The backup file.",
|
description => "The backup file.",
|
||||||
type => 'string',
|
type => 'string',
|
||||||
optional => 1,
|
optional => 1,
|
||||||
maxLength => 255,
|
maxLength => 255,
|
||||||
|
completion => \&PVE::QemuServer::complete_backup_archives,
|
||||||
},
|
},
|
||||||
storage => get_standard_option('pve-storage-id', {
|
storage => get_standard_option('pve-storage-id', {
|
||||||
description => "Default storage.",
|
description => "Default storage.",
|
||||||
|
@ -6385,4 +6385,62 @@ sub scsihw_infos {
|
|||||||
return ($maxdev, $controller, $controller_prefix);
|
return ($maxdev, $controller, $controller_prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# bash completion helper
|
||||||
|
|
||||||
|
sub complete_backup_archives {
|
||||||
|
my ($cmdname, $pname, $cvalue) = @_;
|
||||||
|
|
||||||
|
my $cfg = PVE::Storage::config();
|
||||||
|
|
||||||
|
my $storeid;
|
||||||
|
|
||||||
|
if ($cvalue =~ m/^([^:]+):/) {
|
||||||
|
$storeid = $1;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $data = PVE::Storage::template_list($cfg, $storeid, 'backup');
|
||||||
|
|
||||||
|
my $res = [];
|
||||||
|
foreach my $id (keys %$data) {
|
||||||
|
foreach my $item (@{$data->{$id}}) {
|
||||||
|
next if $item->{format} !~ m/^vma\.(gz|lzo)$/;
|
||||||
|
push @$res, $item->{volid} if defined($item->{volid});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $complete_vmid_full = sub {
|
||||||
|
my ($running) = @_;
|
||||||
|
|
||||||
|
my $idlist = vmstatus();
|
||||||
|
|
||||||
|
my $res = [];
|
||||||
|
|
||||||
|
foreach my $id (keys %$idlist) {
|
||||||
|
my $d = $idlist->{$id};
|
||||||
|
if (defined($running)) {
|
||||||
|
next if $d->{template};
|
||||||
|
next if $running && $d->{status} ne 'running';
|
||||||
|
next if !$running && $d->{status} eq 'running';
|
||||||
|
}
|
||||||
|
push @$res, $id;
|
||||||
|
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
};
|
||||||
|
|
||||||
|
sub complete_vmid {
|
||||||
|
return &$complete_vmid_full();
|
||||||
|
}
|
||||||
|
|
||||||
|
sub complete_vmid_stopped {
|
||||||
|
return &$complete_vmid_full(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub complete_vmid_running {
|
||||||
|
return &$complete_vmid_full(1);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user