]>
git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Commands/remote.pm
1 package PVE
::APIClient
::Commands
::remote
;
6 use PVE
::JSONSchema
qw(register_standard_option get_standard_option);
7 use PVE
::APIClient
::Config
;
11 use PVE
::APIClient
::LWP
;
14 use base
qw(PVE::CLIHandler);
16 my $complete_remote_name = sub {
18 my $config = PVE
::APIClient
::Config-
>new();
19 return $config->remote_names;
22 register_standard_option
('pveclient-remote-name', {
23 description
=> "The name of the remote.",
26 completion
=> $complete_remote_name,
30 return PVE
::PTY
::read_password
("Remote password: ")
33 __PACKAGE__-
>register_method ({
37 description
=> "List remotes from your config file.",
39 additionalProperties
=> 0,
41 returns
=> { type
=> 'null' },
43 my $config = PVE
::APIClient
::Config-
>new();
44 my $known_remotes = $config->remote_names;
46 printf("%10s %10s %10s %10s %100s\n", "Name", "Host", "Port", "Username", "Fingerprint");
47 for my $name (@$known_remotes) {
48 my $remote = $config->lookup_remote($name);
49 printf("%10s %10s %10s %10s %100s\n", $name, $remote->{'host'},
50 $remote->{'port'}, $remote->{'username'}, $remote->{'fingerprint'});
56 __PACKAGE__-
>register_method ({
60 description
=> "Add a remote to your config file.",
62 additionalProperties
=> 0,
64 name
=> get_standard_option
('pveclient-remote-name', { completion
=> sub {} }),
66 description
=> "The host.",
71 description
=> "The username.",
75 description
=> "The users password",
79 description
=> "The port",
86 returns
=> { type
=> 'null'},
90 my $config = PVE
::APIClient
::Config-
>new();
91 my $known_remotes = $config->remotes;
93 if (exists($known_remotes->{$param->{name
}})) {
94 die "Remote \"$param->{name}\" exists, remove it first\n";
98 my $api = PVE
::APIClient
::LWP-
>new(
99 username
=> $param->{username
},
100 password
=> $param->{password
},
101 host
=> $param->{host
},
102 port
=> $param->{port
} // 8006,
103 manual_verification
=> 1,
104 register_fingerprint_cb
=> sub {
111 $config->add_remote($param->{name
}, $param->{host
}, $param->{port
} // 8006,
112 $last_fp, $param->{username
}, $param->{password
});
118 __PACKAGE__-
>register_method ({
122 description
=> "Removes a remote from your config file.",
124 additionalProperties
=> 0,
126 name
=> get_standard_option
('pveclient-remote-name'),
129 returns
=> { type
=> 'null'},
133 my $config = PVE
::APIClient
::Config-
>new();
134 $config->remove_remote($param->{name
});
141 add
=> [ __PACKAGE__
, 'add', ['name', 'host', 'username']],
142 remove
=> [ __PACKAGE__
, 'remove', ['name']],
143 list
=> [__PACKAGE__
, 'list'],