]>
git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Commands/remote.pm
8deac33dc61849c4cc42e707ae30a40780086e8a
1 package PVE
::APIClient
::Commands
::remote
;
6 use PVE
::APIClient
::JSONSchema
qw(get_standard_option);
7 use PVE
::APIClient
::Tools
qw(extract_param);
8 use PVE
::APIClient
::Config
;
10 use PVE
::APIClient
::CLIHandler
;
12 use PVE
::APIClient
::LWP
;
13 use PVE
::APIClient
::PTY
;
15 use base
qw(PVE::APIClient::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 $data = $config->{ids
}->{$name};
36 next if $data->{type
} ne 'remote';
37 printf("%10s %10s %10s %10s %100s\n", $name, $data->{'host'},
38 $data->{'port'} // '-', $data->{'username'}, $data->{'fingerprint'} // '-');
44 __PACKAGE__-
>register_method ({
48 description
=> "Add a remote to your config file.",
49 parameters
=> PVE
::APIClient
::RemoteConfig-
>createSchema(1),
50 returns
=> { type
=> 'null'},
54 # fixme: lock config file
56 my $remote = $param->{name
};
58 my $config = PVE
::APIClient
::Config-
>load();
60 die "Remote '$remote' already exists\n"
61 if $config->{ids
}->{$remote};
65 my $password = $param->{password
};
66 if (!defined($password)) {
67 $password = PVE
::PTY
::read_password
("Remote password: ");
71 username
=> $param->{username
},
72 password
=> $password,
73 host
=> $param->{host
},
74 port
=> $param->{port
} // 8006,
77 if ($param->{fingerprint
}) {
78 $setup->{cached_fingerprints
} = {
79 $param->{fingerprint
} => 1,
82 $setup->{manual_verification
} = 1;
83 $setup->{register_fingerprint_cb
} = sub {
89 my $api = PVE
::APIClient
::LWP-
>new(%$setup);
92 $param->{fingerprint
} = $last_fp if !defined($param->{fingerprint
});
93 my $plugin = PVE
::APIClient
::Config-
>lookup('remote');
94 my $opts = $plugin->check_config($remote, $param, 1, 1);
95 $config->{ids
}->{$remote} = $opts;
97 PVE
::APIClient
::Config-
>save($config);
102 __PACKAGE__-
>register_method ({
106 description
=> "Update a remote configuration.",
107 parameters
=> PVE
::APIClient
::RemoteConfig-
>updateSchema(1),
108 returns
=> { type
=> 'null'},
112 # fixme: lock config file
114 my $name = extract_param
($param, 'name');
115 my $digest = extract_param
($param, 'digest');
116 my $delete = extract_param
($param, 'delete');
118 my $config = PVE
::APIClient
::Config-
>load();
119 my $remote = PVE
::APIClient
::Config-
>lookup_remote($config, $name);
121 my $plugin = PVE
::APIClient
::Config-
>lookup('remote');
122 my $opts = $plugin->check_config($name, $param, 0, 1);
124 foreach my $k (%$opts) {
125 $remote->{$k} = $opts->{$k};
129 my $options = $plugin->private()->{options
}->{'remote'};
130 foreach my $k (PVE
::APIClient
::Tools
::APIClient
::split_list
($delete)) {
131 my $d = $options->{$k} ||
132 die "no such option '$k'\n";
133 die "unable to delete required option '$k'\n"
135 die "unable to delete fixed option '$k'\n"
137 delete $remote->{$k};
141 PVE
::APIClient
::Config-
>save($config);
146 __PACKAGE__-
>register_method ({
150 description
=> "Removes a remote from your config file.",
152 additionalProperties
=> 0,
154 name
=> get_standard_option
('pveclient-remote-name'),
157 returns
=> { type
=> 'null'},
163 my $config = PVE
::APIClient
::Config-
>load();
164 delete $config->{ids
}->{$param->{name
}};
165 PVE
::APIClient
::Config-
>save($config);
171 add
=> [ __PACKAGE__
, 'add', ['name', 'host', 'username']],
172 update
=> [ __PACKAGE__
, 'update', ['name']],
173 remove
=> [ __PACKAGE__
, 'remove', ['name']],
174 list
=> [__PACKAGE__
, 'list'],