public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH common 1/1] PBSClient: add get_repository to generate repository urls from configs
Date: Thu,  3 Dec 2020 12:43:38 +0100	[thread overview]
Message-ID: <20201203114340.23733-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20201203114340.23733-1-d.csapak@proxmox.com>

we can use this everywhere we need to have a repository url

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/PVE/PBSClient.pm | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/src/PVE/PBSClient.pm b/src/PVE/PBSClient.pm
index 44e3176..f05471c 100644
--- a/src/PVE/PBSClient.pm
+++ b/src/PVE/PBSClient.pm
@@ -10,7 +10,35 @@ use JSON;
 use POSIX qw(strftime ENOENT);
 
 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 {
     my ($class, $scfg, $storeid, $sdir) = @_;
@@ -116,9 +144,7 @@ my sub do_raw_client_cmd {
 	if ! -x $client_exe;
 
     my $scfg = $self->{scfg};
-    my $server = $scfg->{server};
-    my $datastore = $scfg->{datastore};
-    my $username = $scfg->{username} // 'root@pam';
+    my $repo = get_repository($scfg);
 
     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, "--repository", "$username\@$server:$datastore";
+    push @$cmd, "--repository", $repo;
 
     local $ENV{PBS_PASSWORD} = $self->get_password();
 
-- 
2.20.1





  reply	other threads:[~2020-12-03 11:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 11:43 [pve-devel] [PATCH common/storage/qemu-server] refactor pbs repo url generation Dominik Csapak
2020-12-03 11:43 ` Dominik Csapak [this message]
2020-12-03 15:43   ` [pve-devel] applied: [PATCH common 1/1] PBSClient: add get_repository to generate repository urls from configs Thomas Lamprecht
2020-12-03 11:43 ` [pve-devel] [PATCH storage 1/1] PBSPlugin: use get_repository from PVE::PBSClient Dominik Csapak
2020-12-03 16:23   ` [pve-devel] applied: " Thomas Lamprecht
2020-12-03 11:43 ` [pve-devel] [PATCH qemu-server 1/1] " Dominik Csapak
2020-12-03 17:04   ` [pve-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201203114340.23733-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal