]>
Commit | Line | Data |
---|---|---|
565bbc73 DM |
1 | package PVE::APIClient::Commands::remote; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
3454a319 DM |
6 | use PVE::JSONSchema qw(register_standard_option get_standard_option); |
7 | use PVE::APIClient::Config; | |
8 | ||
565bbc73 DM |
9 | use PVE::CLIHandler; |
10 | ||
11 | use base qw(PVE::CLIHandler); | |
12 | ||
3454a319 DM |
13 | my $remote_name_regex = qr(\w+); |
14 | ||
15 | my $complete_remote_name = sub { | |
16 | ||
17 | my $conf = PVE::APIClient::Config::load_config(); | |
18 | ||
19 | my $res = []; | |
20 | ||
21 | foreach my $k (keys %$conf) { | |
22 | if ($k =~ m/^remote_($remote_name_regex)$/) { | |
23 | push @$res, $1; | |
24 | } | |
25 | } | |
26 | ||
27 | return $res; | |
28 | }; | |
29 | ||
30 | register_standard_option('pveclient-remote-name', { | |
31 | description => "The name of the remote.", | |
32 | type => 'string', | |
33 | pattern => $remote_name_regex, | |
34 | completion => $complete_remote_name, | |
35 | }); | |
36 | ||
565bbc73 DM |
37 | __PACKAGE__->register_method ({ |
38 | name => 'add', | |
39 | path => 'add', | |
40 | method => 'POST', | |
41 | description => "Add a remote to your config file.", | |
42 | parameters => { | |
43 | additionalProperties => 0, | |
44 | properties => { | |
3454a319 | 45 | name => get_standard_option('pveclient-remote-name', { completion => sub {} }), |
565bbc73 DM |
46 | host => { |
47 | description => "The host, either host, host:port or https://host:port", | |
48 | type => 'string', | |
49 | }, | |
50 | username => { | |
3454a319 | 51 | description => "The username.", |
565bbc73 DM |
52 | type => 'string', |
53 | optional => 1, | |
54 | }, | |
55 | }, | |
56 | }, | |
57 | returns => { type => 'null'}, | |
58 | code => sub { | |
59 | my ($param) = @_; | |
60 | ||
61 | die "implement me"; | |
62 | ||
63 | }}); | |
64 | ||
65 | __PACKAGE__->register_method ({ | |
66 | name => 'remove', | |
67 | path => 'remove', | |
68 | method => 'DELETE', | |
69 | description => "Removes a remote from your config file.", | |
70 | parameters => { | |
71 | additionalProperties => 0, | |
72 | properties => { | |
3454a319 | 73 | name => get_standard_option('pveclient-remote-name'), |
565bbc73 DM |
74 | }, |
75 | }, | |
76 | returns => { type => 'null'}, | |
77 | code => sub { | |
78 | my ($param) = @_; | |
79 | ||
80 | die "implement me"; | |
81 | ||
82 | }}); | |
83 | ||
84 | our $cmddef = { | |
85 | add => [ __PACKAGE__, 'add', ['name', 'host']], | |
86 | remove => [ __PACKAGE__, 'remove', ['name']], | |
87 | }; | |
88 | ||
89 | 1; |