]>
git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Commands/remote.pm
1 package PVE
::APIClient
::Commands
::remote
;
6 use PVE
::APIClient
::Helpers
;
7 use PVE
::APIClient
::JSONSchema
qw(get_standard_option);
8 use PVE
::APIClient
::Tools
qw(extract_param);
9 use PVE
::APIClient
::Config
;
11 use PVE
::APIClient
::CLIHandler
;
13 use PVE
::APIClient
::LWP
;
14 use PVE
::APIClient
::PTY
;
16 use base
qw(PVE::APIClient::CLIHandler);
19 return PVE
::APIClient
::PTY
::read_password
("Remote password: ")
22 # define as array to keep ordering
23 my $remote_list_returns_properties = [
24 name
=> get_standard_option
('pveclient-remote-name'),
25 host
=> { type
=> 'string', format
=> 'address' },
26 username
=> { type
=> 'string' },
27 port
=> { type
=> 'integer', optional
=> 1 },
28 fingerprint
=> { type
=> 'string', optional
=> 1 },
31 __PACKAGE__-
>register_method ({
32 name
=> 'remote_list',
33 path
=> 'remote_list',
35 description
=> "List remotes from your config file.",
37 additionalProperties
=> 0,
44 properties
=> { @$remote_list_returns_properties },
50 my $config = PVE
::APIClient
::Config-
>load();
53 for my $name (keys %{$config->{ids
}}) {
54 my $data = $config->{ids
}->{$name};
55 next if $data->{type
} ne 'remote';
62 __PACKAGE__-
>register_method ({
66 description
=> "Add a remote to your config file.",
67 parameters
=> PVE
::APIClient
::RemoteConfig-
>createSchema(1),
68 returns
=> { type
=> 'null'},
72 my $remote = $param->{name
};
74 # Note: we try to keep lock time sort, and lock later when we have all info
75 my $config = PVE
::APIClient
::Config-
>load();
77 die "Remote '$remote' already exists\n"
78 if $config->{ids
}->{$remote};
82 my $password = $param->{password
};
83 if (!defined($password)) {
84 $password = PVE
::APIClient
::PTY
::read_password
("Remote password: ");
88 username
=> $param->{username
},
89 password
=> $password,
90 host
=> $param->{host
},
91 port
=> $param->{port
} // 8006,
94 if ($param->{fingerprint
}) {
95 $setup->{cached_fingerprints
} = {
96 $param->{fingerprint
} => 1,
99 $setup->{manual_verification
} = 1;
100 $setup->{register_fingerprint_cb
} = sub {
106 my $api = PVE
::APIClient
::LWP-
>new(%$setup);
109 $param->{fingerprint
} = $last_fp if !defined($param->{fingerprint
});
111 my $plugin = PVE
::APIClient
::Config-
>lookup('remote');
115 $config = PVE
::APIClient
::Config-
>load(); # reload
117 # check again (file is locked now)
118 die "Remote '$remote' already exists\n"
119 if $config->{ids
}->{$remote};
121 my $opts = $plugin->check_config($remote, $param, 1, 1);
123 $config->{ids
}->{$remote} = $opts;
125 PVE
::APIClient
::Config-
>save($config);
128 PVE
::APIClient
::Config-
>lock_config(undef, $code);
133 __PACKAGE__-
>register_method ({
134 name
=> 'remote_set',
135 path
=> 'remote_set',
137 description
=> "Update a remote configuration.",
138 parameters
=> PVE
::APIClient
::RemoteConfig-
>updateSchema(1),
139 returns
=> { type
=> 'null'},
143 my $name = extract_param
($param, 'name');
144 my $digest = extract_param
($param, 'digest');
145 my $delete = extract_param
($param, 'delete');
148 my $config = PVE
::APIClient
::Config-
>load();
149 my $remote = PVE
::APIClient
::Config-
>lookup_remote($config, $name);
151 my $plugin = PVE
::APIClient
::Config-
>lookup('remote');
152 my $opts = $plugin->check_config($name, $param, 0, 1);
154 foreach my $k (%$opts) {
155 $remote->{$k} = $opts->{$k};
159 my $options = $plugin->private()->{options
}->{'remote'};
160 foreach my $k (PVE
::APIClient
::Tools
::APIClient
::split_list
($delete)) {
161 my $d = $options->{$k} ||
162 die "no such option '$k'\n";
163 die "unable to delete required option '$k'\n"
165 die "unable to delete fixed option '$k'\n"
167 delete $remote->{$k};
171 PVE
::APIClient
::Config-
>save($config);
174 PVE
::APIClient
::Config-
>lock_config(undef, $code);
179 __PACKAGE__-
>register_method ({
180 name
=> 'remote_delete',
181 path
=> 'remote_delete',
183 description
=> "Removes a remote from your config file.",
185 additionalProperties
=> 0,
187 name
=> get_standard_option
('pveclient-remote-name'),
190 returns
=> { type
=> 'null'},
195 my $config = PVE
::APIClient
::Config-
>load();
196 delete $config->{ids
}->{$param->{name
}};
197 PVE
::APIClient
::Config-
>save($config);
200 PVE
::APIClient
::Config-
>lock_config(undef, $code);
206 add
=> [ __PACKAGE__
, 'remote_add', ['name', 'host', 'username']],
207 set
=> [ __PACKAGE__
, 'remote_set', ['name']],
208 delete => [ __PACKAGE__
, 'remote_delete', ['name']],
209 list
=> [__PACKAGE__
, 'remote_list', undef, {},
211 my ($data, $schema, $options) = @_;
212 PVE
::APIClient
::Helpers
::print_ordered_result
($remote_list_returns_properties, $data, $schema, $options);
214 $PVE::APIClient
::RESTHandler
::standard_output_options
,