]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/API2/PBS/Remote.pm
2eba9bb891f9febc921fbb18ae030c46c145b03d
1 package PMG
::API2
::PBS
::Remote
;
7 use PVE
::Tools
qw(extract_param);
8 use PVE
::JSONSchema
qw(get_standard_option);
14 use base
qw(PVE::RESTHandler);
16 __PACKAGE__-
>register_method ({
20 description
=> "List all configured Proxmox Backup Server instances.",
21 permissions
=> { check
=> [ 'admin', 'audit' ] },
25 additionalProperties
=> 0,
30 items
=> PMG
::PBSConfig-
>createSchema(1),
31 links
=> [ { rel
=> 'child', href
=> "{remote}" } ],
38 my $conf = PMG
::PBSConfig-
>new();
39 return $res if !defined($conf);
41 for my $remote (sort keys %{$conf->{ids
}}) {
42 my $d = $conf->{ids
}->{$remote};
45 server
=> $d->{server
},
46 datastore
=> $d->{datastore
},
47 username
=> $d->{username
},
48 disable
=> $d->{disable
},
55 __PACKAGE__-
>register_method ({
59 description
=> "Add Proxmox Backup Server remote instance.",
60 permissions
=> { check
=> [ 'admin' ] },
63 parameters
=> PMG
::PBSConfig-
>createSchema(1),
64 returns
=> { type
=> 'null' } ,
69 my $conf = PMG
::PBSConfig-
>new();
71 my $ids = $conf->{ids
};
73 my $remote = extract_param
($param, 'remote');
74 die "PBS remote '$remote' already exists\n" if $ids->{$remote};
76 my $remotecfg = PMG
::PBSConfig-
>check_config($remote, $param, 1);
78 my $password = extract_param
($remotecfg, 'password');
80 my $pbs = PVE
::PBSClient-
>new($remotecfg, $remote, $conf->{secret_dir
});
81 $pbs->set_password($password) if defined($password);
83 $ids->{$remote} = $remotecfg;
87 PMG
::PBSConfig
::lock_config
($code, "add PBS remote failed");
92 __PACKAGE__-
>register_method ({
93 name
=> 'read_config',
96 description
=> "Get Proxmox Backup Server remote configuration.",
98 permissions
=> { check
=> [ 'admin', 'audit' ] },
100 additionalProperties
=> 1,
103 description
=> "Proxmox Backup Server ID.",
104 type
=> 'string', format
=> 'pve-configid',
112 my $conf = PMG
::PBSConfig-
>new();
114 my $remote = $param->{remote
};
116 my $data = $conf->{ids
}->{$remote};
117 die "PBS remote '$remote' does not exist\n" if !$data;
119 delete $data->{type
};
121 $data->{digest
} = $conf->{digest
};
122 $data->{remote
} = $remote;
127 __PACKAGE__-
>register_method ({
128 name
=> 'update_config',
131 description
=> "Update PBS remote settings.",
132 permissions
=> { check
=> [ 'admin' ] },
135 parameters
=> PMG
::PBSConfig-
>updateSchema(),
136 returns
=> { type
=> 'null' },
142 my $conf = PMG
::PBSConfig-
>new();
143 my $ids = $conf->{ids
};
145 my $digest = extract_param
($param, 'digest');
146 PVE
::SectionConfig
::assert_if_modified
($conf, $digest);
148 my $remote = extract_param
($param, 'remote');
150 die "PBS remote '$remote' does not exist\n" if !$ids->{$remote};
152 my $delete_str = extract_param
($param, 'delete');
153 die "no options specified\n" if !$delete_str && !scalar(keys %$param);
155 my $pbs = PVE
::PBSClient-
>new($ids->{$remote}, $remote, $conf->{secret_dir
});
156 foreach my $opt (PVE
::Tools
::split_list
($delete_str)) {
157 if ($opt eq 'password') {
158 $pbs->delete_password();
160 delete $ids->{$remote}->{$opt};
163 if (defined(my $password = extract_param
($param, 'password'))) {
164 $pbs->set_password($password);
167 my $remoteconfig = PMG
::PBSConfig-
>check_config($remote, $param, 0, 1);
169 foreach my $p (keys %$remoteconfig) {
170 $ids->{$remote}->{$p} = $remoteconfig->{$p};
176 PMG
::PBSConfig
::lock_config
($code, "update PBS remote failed");
181 __PACKAGE__-
>register_method ({
185 description
=> "Delete an PBS remote",
186 permissions
=> { check
=> [ 'admin' ] },
190 additionalProperties
=> 0,
193 description
=> "Profile ID.",
194 type
=> 'string', format
=> 'pve-configid',
198 returns
=> { type
=> 'null' },
204 my $conf = PMG
::PBSConfig-
>new();
205 my $ids = $conf->{ids
};
207 my $remote = $param->{remote
};
208 die "PBS remote '$remote' does not exist\n" if !$ids->{$remote};
210 my $pbs = PVE
::PBSClient-
>new($ids->{$remote}, $remote, $conf->{secret_dir
});
211 $pbs->delete_password($remote);
212 delete $ids->{$remote};
217 PMG
::PBSConfig
::lock_config
($code, "delete PBS remote failed");