mirror of
https://git.proxmox.com/git/pve-common
synced 2025-07-27 10:01:38 +00:00
PBSClient: add get_repository to generate repository urls from configs
we can use this everywhere we need to have a repository url Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
83b0b7d185
commit
5640c3db26
@ -10,7 +10,35 @@ use JSON;
|
|||||||
use POSIX qw(strftime ENOENT);
|
use POSIX qw(strftime ENOENT);
|
||||||
|
|
||||||
use PVE::JSONSchema qw(get_standard_option);
|
use PVE::JSONSchema qw(get_standard_option);
|
||||||
use PVE::Tools qw(run_command file_set_contents file_get_contents file_read_firstline);
|
use PVE::Tools qw(run_command file_set_contents file_get_contents file_read_firstline $IPV6RE);
|
||||||
|
|
||||||
|
# returns a repository string suitable for proxmox-backup-client, pbs-restore, etc.
|
||||||
|
# $scfg must have the following structure:
|
||||||
|
# {
|
||||||
|
# datastore
|
||||||
|
# server
|
||||||
|
# port (optional defaults to 8007)
|
||||||
|
# username (optional defaults to 'root@pam')
|
||||||
|
# }
|
||||||
|
sub get_repository {
|
||||||
|
my ($scfg) = @_;
|
||||||
|
|
||||||
|
my $server = $scfg->{server};
|
||||||
|
die "no server given\n" if !defined($server);
|
||||||
|
|
||||||
|
$server = "[$server]" if $server =~ /^$IPV6RE$/;
|
||||||
|
|
||||||
|
if (my $port = $scfg->{port}) {
|
||||||
|
$server .= ":$port" if $port != 8007;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $datastore = $scfg->{datastore};
|
||||||
|
die "no datastore given\n" if !defined($datastore);
|
||||||
|
|
||||||
|
my $username = $scfg->{username} // 'root@pam';
|
||||||
|
|
||||||
|
return "$username\@$server:$datastore";
|
||||||
|
}
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, $scfg, $storeid, $sdir) = @_;
|
my ($class, $scfg, $storeid, $sdir) = @_;
|
||||||
@ -116,9 +144,7 @@ my sub do_raw_client_cmd {
|
|||||||
if ! -x $client_exe;
|
if ! -x $client_exe;
|
||||||
|
|
||||||
my $scfg = $self->{scfg};
|
my $scfg = $self->{scfg};
|
||||||
my $server = $scfg->{server};
|
my $repo = get_repository($scfg);
|
||||||
my $datastore = $scfg->{datastore};
|
|
||||||
my $username = $scfg->{username} // 'root@pam';
|
|
||||||
|
|
||||||
my $userns_cmd = delete $opts{userns_cmd};
|
my $userns_cmd = delete $opts{userns_cmd};
|
||||||
|
|
||||||
@ -144,7 +170,7 @@ my sub do_raw_client_cmd {
|
|||||||
|
|
||||||
push @$cmd, @$param if defined($param);
|
push @$cmd, @$param if defined($param);
|
||||||
|
|
||||||
push @$cmd, "--repository", "$username\@$server:$datastore";
|
push @$cmd, "--repository", $repo;
|
||||||
|
|
||||||
local $ENV{PBS_PASSWORD} = $self->get_password();
|
local $ENV{PBS_PASSWORD} = $self->get_password();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user