]>
git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Commands/remote.pm
1 package PVE
::APIClient
::Commands
::remote
;
6 use PVE
::JSONSchema
qw(get_standard_option);
7 use PVE
::Tools
qw(extract_param);
8 use PVE
::APIClient
::Config
;
12 use PVE
::APIClient
::LWP
;
15 use base
qw(PVE::CLIHandler);
18 return PVE
::PTY
::read_password
("Remote password: ")
21 __PACKAGE__-
>register_method ({
25 description
=> "List remotes from your config file.",
27 additionalProperties
=> 0,
29 returns
=> { type
=> 'null' },
31 my $config = PVE
::APIClient
::Config-
>load();
33 printf("%10s %10s %10s %10s %100s\n", "Name", "Host", "Port", "Username", "Fingerprint");
34 for my $name (keys %{$config->{ids
}}) {
35 my $remote = $config->{ids
}->{$name};
36 printf("%10s %10s %10s %10s %100s\n", $name, $remote->{'host'},
37 $remote->{'port'} // '-', $remote->{'username'}, $remote->{'fingerprint'} // '-');
43 __PACKAGE__-
>register_method ({
47 description
=> "Add a remote to your config file.",
48 parameters
=> PVE
::APIClient
::Config-
>createSchema(1),
49 returns
=> { type
=> 'null'},
53 # fixme: lock config file
55 my $remote = $param->{name
};
57 my $config = PVE
::APIClient
::Config-
>load();
59 die "Remote '$remote' already exists\n"
60 if $config->{ids
}->{$remote};
64 my $password = $param->{password
};
65 if (!defined($password)) {
66 $password = PVE
::PTY
::read_password
("Remote password: ");
70 username
=> $param->{username
},
71 password
=> $password,
72 host
=> $param->{host
},
73 port
=> $param->{port
} // 8006,
76 if ($param->{fingerprint
}) {
77 $setup->{cached_fingerprints
} = {
78 $param->{fingerprint
} => 1,
81 $setup->{manual_verification
} = 1;
82 $setup->{register_fingerprint_cb
} = sub {
88 my $api = PVE
::APIClient
::LWP-
>new(%$setup);
91 $param->{fingerprint
} = $last_fp if !defined($param->{fingerprint
});
92 my $plugin = PVE
::APIClient
::Config-
>lookup('remote');
93 my $opts = $plugin->check_config($remote, $param, 1, 1);
94 $config->{ids
}->{$remote} = $opts;
96 PVE
::APIClient
::Config-
>save($config);
101 __PACKAGE__-
>register_method ({
105 description
=> "Update a remote configuration.",
106 parameters
=> PVE
::APIClient
::Config-
>updateSchema(1),
107 returns
=> { type
=> 'null'},
111 # fixme: lock config file
113 my $name = extract_param
($param, 'name');
114 my $digest = extract_param
($param, 'digest');
115 my $delete = extract_param
($param, 'delete');
117 my $config = PVE
::APIClient
::Config-
>load();
118 my $remote = PVE
::APIClient
::Config-
>lookup_remote($config, $name);
120 my $plugin = PVE
::APIClient
::Config-
>lookup('remote');
121 my $opts = $plugin->check_config($name, $param, 0, 1);
123 foreach my $k (%$opts) {
124 $remote->{$k} = $opts->{$k};
128 my $options = $plugin->private()->{options
}->{'remote'};
129 foreach my $k (PVE
::Tools
::split_list
($delete)) {
130 my $d = $options->{$k} ||
131 die "no such option '$k'\n";
132 die "unable to delete required option '$k'\n"
134 die "unable to delete fixed option '$k'\n"
136 delete $remote->{$k};
140 PVE
::APIClient
::Config-
>save($config);
145 __PACKAGE__-
>register_method ({
149 description
=> "Removes a remote from your config file.",
151 additionalProperties
=> 0,
153 name
=> get_standard_option
('pveclient-remote-name'),
156 returns
=> { type
=> 'null'},
162 my $config = PVE
::APIClient
::Config-
>load();
163 delete $config->{ids
}->{$param->{name
}};
164 PVE
::APIClient
::Config-
>save($config);
170 add
=> [ __PACKAGE__
, 'add', ['name', 'host', 'username']],
171 update
=> [ __PACKAGE__
, 'update', ['name']],
172 remove
=> [ __PACKAGE__
, 'remove', ['name']],
173 list
=> [__PACKAGE__
, 'list'],