From nobody Mon Apr 29 16:25:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1512467639432645.638691415082; Tue, 5 Dec 2017 01:53:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 417016868D; Tue, 5 Dec 2017 09:53:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC9E062461; Tue, 5 Dec 2017 09:53:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9278D4BB78; Tue, 5 Dec 2017 09:53:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vB59rtlZ007348 for ; Tue, 5 Dec 2017 04:53:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 408DB62461; Tue, 5 Dec 2017 09:53:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3713F62464 for ; Tue, 5 Dec 2017 09:53:52 +0000 (UTC) Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EE068553C for ; Tue, 5 Dec 2017 09:53:50 +0000 (UTC) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 10:53:49 +0100 Received: from laptop.tf.local (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 09:53:26 +0000 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= To: libvir-list@redhat.com Date: Tue, 5 Dec 2017 10:53:17 +0100 Message-Id: <20171205095322.24258-2-cbosdonnat@suse.com> In-Reply-To: <20171205095322.24258-1-cbosdonnat@suse.com> References: <20171205095322.24258-1-cbosdonnat@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 05 Dec 2017 09:53:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 05 Dec 2017 09:53:51 +0000 (UTC) for IP:'195.135.221.5' DOMAIN:'smtp.nue.novell.com' HELO:'smtp.nue.novell.com' FROM:'cbosdonnat@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 195.135.221.5 smtp.nue.novell.com 195.135.221.5 smtp.nue.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Subject: [libvirt] [sandbox 1/6] Pass debug and verbose values to init X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 05 Dec 2017 09:53:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" libvirt-sandbox-init-common is expecting -d and -v parameters to set it in debug or verbose mode... but those will never be passed by the launcher program. Writing the core.debug and core.verbose parameters in the sandbox configuration makes those values actually usable from the init. Reviewed-by: Daniel P. Berrange --- bin/virt-sandbox.c | 3 ++ libvirt-sandbox/libvirt-sandbox-config.c | 75 +++++++++++++++++++++++= ++++ libvirt-sandbox/libvirt-sandbox-config.h | 6 +++ libvirt-sandbox/libvirt-sandbox-init-common.c | 3 ++ libvirt-sandbox/libvirt-sandbox.sym | 4 ++ 5 files changed, 91 insertions(+) diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c index 3058013..6032562 100644 --- a/bin/virt-sandbox.c +++ b/bin/virt-sandbox.c @@ -273,6 +273,9 @@ int main(int argc, char **argv) { if (shell) gvir_sandbox_config_set_shell(cfg, TRUE); =20 + gvir_sandbox_config_set_debug(cfg, debug); + gvir_sandbox_config_set_verbose(cfg, verbose); + if (isatty(STDIN_FILENO)) gvir_sandbox_config_interactive_set_tty(icfg, TRUE); =20 diff --git a/libvirt-sandbox/libvirt-sandbox-config.c b/libvirt-sandbox/lib= virt-sandbox-config.c index 8709736..73a0fa4 100644 --- a/libvirt-sandbox/libvirt-sandbox-config.c +++ b/libvirt-sandbox/libvirt-sandbox-config.c @@ -68,6 +68,9 @@ struct _GVirSandboxConfigPrivate =20 gchar *secLabel; gboolean secDynamic; + + gboolean debug; + gboolean verbose; }; =20 G_DEFINE_ABSTRACT_TYPE(GVirSandboxConfig, gvir_sandbox_config, G_TYPE_OBJE= CT); @@ -1926,6 +1929,59 @@ gboolean gvir_sandbox_config_set_security_opts(GVirS= andboxConfig *config, return ret; } =20 +/** + * gvir_sandbox_config_set_debug: + * @config: (transfer none): the sandbox config + * @debug: true if the container init should print debugging messages + * + * Set whether the container init should print debugging messages. + */ +void gvir_sandbox_config_set_debug(GVirSandboxConfig *config, gboolean deb= ug) +{ + GVirSandboxConfigPrivate *priv =3D config->priv; + priv->debug =3D debug; +} + +/** + * gvir_sandbox_config_get_debug: + * @config: (transfer none): the sandbox config + * + * Retrieves the sandbox debug flag + * + * Returns: the debug flag + */ +gboolean gvir_sandbox_config_get_debug(GVirSandboxConfig *config) +{ + GVirSandboxConfigPrivate *priv =3D config->priv; + return priv->debug; +} + +/** + * gvir_sandbox_config_set_verbose: + * @config: (transfer none): the sandbox config + * @verbose: true if the container init should be verbose + * + * Set whether the container init should be verbose. + */ +void gvir_sandbox_config_set_verbose(GVirSandboxConfig *config, gboolean v= erbose) +{ + GVirSandboxConfigPrivate *priv =3D config->priv; + priv->verbose =3D verbose; +} + +/** + * gvir_sandbox_config_get_verbose: + * @config: (transfer none): the sandbox config + * + * Retrieves the sandbox verbose flag + * + * Returns: the verbose flag + */ +gboolean gvir_sandbox_config_get_verbose(GVirSandboxConfig *config) +{ + GVirSandboxConfigPrivate *priv =3D config->priv; + return priv->verbose; +} =20 static GVirSandboxConfigMount *gvir_sandbox_config_load_config_mount(GKeyF= ile *file, guint= i, @@ -2415,6 +2471,22 @@ static gboolean gvir_sandbox_config_load_config(GVir= SandboxConfig *config, priv->secDynamic =3D b; } =20 + b =3D g_key_file_get_boolean(file, "core", "debug", &e); + if (e) { + g_error_free(e); + e =3D NULL; + } else { + priv->debug =3D b; + } + + b =3D g_key_file_get_boolean(file, "core", "verbose", &e); + if (e) { + g_error_free(e); + e =3D NULL; + } else { + priv->verbose =3D b; + } + ret =3D TRUE; cleanup: return ret; @@ -2677,6 +2749,9 @@ static void gvir_sandbox_config_save_config(GVirSandb= oxConfig *config, if (priv->secLabel) g_key_file_set_string(file, "security", "label", priv->secLabel); g_key_file_set_boolean(file, "security", "dynamic", priv->secDynamic); + + g_key_file_set_boolean(file, "core", "debug", priv->debug); + g_key_file_set_boolean(file, "core", "verbose", priv->verbose); } =20 =20 diff --git a/libvirt-sandbox/libvirt-sandbox-config.h b/libvirt-sandbox/lib= virt-sandbox-config.h index e5e53f7..8950e25 100644 --- a/libvirt-sandbox/libvirt-sandbox-config.h +++ b/libvirt-sandbox/libvirt-sandbox-config.h @@ -180,6 +180,12 @@ gboolean gvir_sandbox_config_set_security_opts(GVirSan= dboxConfig *config, const gchar *optstr, GError**error); =20 +void gvir_sandbox_config_set_debug(GVirSandboxConfig *config, gboolean deb= ug); +gboolean gvir_sandbox_config_get_debug(GVirSandboxConfig *config); + +void gvir_sandbox_config_set_verbose(GVirSandboxConfig *config, gboolean v= erbose); +gboolean gvir_sandbox_config_get_verbose(GVirSandboxConfig *config); + gchar **gvir_sandbox_config_get_command(GVirSandboxConfig *config); =20 G_END_DECLS diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c b/libvirt-sandbo= x/libvirt-sandbox-init-common.c index 7ea63cf..240ca83 100644 --- a/libvirt-sandbox/libvirt-sandbox-init-common.c +++ b/libvirt-sandbox/libvirt-sandbox-init-common.c @@ -1442,6 +1442,9 @@ int main(int argc, char **argv) { goto cleanup; } =20 + debug =3D gvir_sandbox_config_get_debug(config); + verbose =3D gvir_sandbox_config_get_verbose(config); + setenv("PATH", "/bin:/usr/bin:/usr/local/bin:/sbin/:/usr/sbin", 1); unsetenv("LD_LIBRARY_PATH"); =20 diff --git a/libvirt-sandbox/libvirt-sandbox.sym b/libvirt-sandbox/libvirt-= sandbox.sym index b7c5921..1bead3e 100644 --- a/libvirt-sandbox/libvirt-sandbox.sym +++ b/libvirt-sandbox/libvirt-sandbox.sym @@ -120,6 +120,8 @@ LIBVIRT_SANDBOX_0.6.0 { gvir_sandbox_config_get_userid; gvir_sandbox_config_get_username; gvir_sandbox_config_get_uuid; + gvir_sandbox_config_get_debug; + gvir_sandbox_config_get_verbose; gvir_sandbox_config_find_mount; gvir_sandbox_config_has_networks; gvir_sandbox_config_has_mounts; @@ -143,6 +145,8 @@ LIBVIRT_SANDBOX_0.6.0 { gvir_sandbox_config_set_security_label; gvir_sandbox_config_set_security_opts; gvir_sandbox_config_set_uuid; + gvir_sandbox_config_set_debug; + gvir_sandbox_config_set_verbose; =20 gvir_sandbox_config_initrd_add_module; gvir_sandbox_config_initrd_get_init; --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:25:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 151246763933556.65061118216295; Tue, 5 Dec 2017 01:53:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 418B04E4C6; Tue, 5 Dec 2017 09:53:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBBF562501; Tue, 5 Dec 2017 09:53:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 725941800BDE; Tue, 5 Dec 2017 09:53:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vB59rsus007333 for ; Tue, 5 Dec 2017 04:53:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id A4CA6183D9; Tue, 5 Dec 2017 09:53:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E3065C661 for ; Tue, 5 Dec 2017 09:53:52 +0000 (UTC) Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF3C1883AB for ; Tue, 5 Dec 2017 09:53:50 +0000 (UTC) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 10:53:49 +0100 Received: from laptop.tf.local (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 09:53:26 +0000 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= To: libvir-list@redhat.com Date: Tue, 5 Dec 2017 10:53:18 +0100 Message-Id: <20171205095322.24258-3-cbosdonnat@suse.com> In-Reply-To: <20171205095322.24258-1-cbosdonnat@suse.com> References: <20171205095322.24258-1-cbosdonnat@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 05 Dec 2017 09:53:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 05 Dec 2017 09:53:51 +0000 (UTC) for IP:'195.135.221.5' DOMAIN:'smtp.nue.novell.com' HELO:'smtp.nue.novell.com' FROM:'cbosdonnat@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 195.135.221.5 smtp.nue.novell.com 195.135.221.5 smtp.nue.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Subject: [libvirt] [sandbox 2/6] machine: use squash security mode for non-root virt-sandbox mounts X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 05 Dec 2017 09:53:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When running virt-sandbox as a user with host-bind mount, the user can't write in the mounted folder. If run as root, use passthrough security mode, otherwise use squashed one to fix this. Reviewed-by: Daniel P. Berrange --- libvirt-sandbox/libvirt-sandbox-builder-machine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libvirt-sandbox/libvirt-sandbox-builder-machine.c b/libvirt-sa= ndbox/libvirt-sandbox-builder-machine.c index 7204f71..b6f2218 100644 --- a/libvirt-sandbox/libvirt-sandbox-builder-machine.c +++ b/libvirt-sandbox/libvirt-sandbox-builder-machine.c @@ -589,7 +589,10 @@ static gboolean gvir_sandbox_builder_machine_construct= _devices(GVirSandboxBuilde =20 fs =3D gvir_config_domain_filesys_new(); gvir_config_domain_filesys_set_type(fs, GVIR_CONFIG_DOMAIN_FIL= ESYS_MOUNT); - gvir_config_domain_filesys_set_access_type(fs, GVIR_CONFIG_DOM= AIN_FILESYS_ACCESS_PASSTHROUGH); + if (getuid() =3D=3D 0) + gvir_config_domain_filesys_set_access_type(fs, GVIR_CONFIG= _DOMAIN_FILESYS_ACCESS_PASSTHROUGH); + else + gvir_config_domain_filesys_set_access_type(fs, GVIR_CONFIG= _DOMAIN_FILESYS_ACCESS_SQUASH); gvir_config_domain_filesys_set_source(fs, gvir_sandbox_config_moun= t_file_get_source(mfile)); gvir_config_domain_filesys_set_target(fs, target); --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:25:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1512467648844357.10871900863117; Tue, 5 Dec 2017 01:54:08 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF1E3C01CB9A; Tue, 5 Dec 2017 09:54:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 990926375C; Tue, 5 Dec 2017 09:54:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 61CAC1800FC5; Tue, 5 Dec 2017 09:54:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vB59rsMH007334 for ; Tue, 5 Dec 2017 04:53:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id A7A375C661; Tue, 5 Dec 2017 09:53:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E1A760841 for ; Tue, 5 Dec 2017 09:53:51 +0000 (UTC) Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B8B82C04AC5F for ; Tue, 5 Dec 2017 09:53:50 +0000 (UTC) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 10:53:49 +0100 Received: from laptop.tf.local (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 09:53:27 +0000 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= To: libvir-list@redhat.com Date: Tue, 5 Dec 2017 10:53:19 +0100 Message-Id: <20171205095322.24258-4-cbosdonnat@suse.com> In-Reply-To: <20171205095322.24258-1-cbosdonnat@suse.com> References: <20171205095322.24258-1-cbosdonnat@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 05 Dec 2017 09:53:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 05 Dec 2017 09:53:51 +0000 (UTC) for IP:'195.135.221.5' DOMAIN:'smtp.nue.novell.com' HELO:'smtp.nue.novell.com' FROM:'cbosdonnat@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 195.135.221.5 smtp.nue.novell.com 195.135.221.5 smtp.nue.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Subject: [libvirt] [sandbox 3/6] Add tests .log and .trs files to gitignore X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 05 Dec 2017 09:54:08 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Reviewed-by: Daniel P. Berrange --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 83831bb..c4e2217 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,5 @@ bin/virt-sandbox bin/virt-sandbox-service-util build/ bin/*.1 +*.log +*.trs --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:25:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1512467639459766.4998526256352; Tue, 5 Dec 2017 01:53:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EE027EA92; Tue, 5 Dec 2017 09:53:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B51E960841; Tue, 5 Dec 2017 09:53:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 720394BB79; Tue, 5 Dec 2017 09:53:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vB59rsHT007332 for ; Tue, 5 Dec 2017 04:53:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id A47B8183D6; Tue, 5 Dec 2017 09:53:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E206183C0 for ; Tue, 5 Dec 2017 09:53:52 +0000 (UTC) Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82CED68686 for ; Tue, 5 Dec 2017 09:53:51 +0000 (UTC) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 10:53:49 +0100 Received: from laptop.tf.local (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 09:53:27 +0000 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= To: libvir-list@redhat.com Date: Tue, 5 Dec 2017 10:53:20 +0100 Message-Id: <20171205095322.24258-5-cbosdonnat@suse.com> In-Reply-To: <20171205095322.24258-1-cbosdonnat@suse.com> References: <20171205095322.24258-1-cbosdonnat@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 05 Dec 2017 09:53:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 05 Dec 2017 09:53:52 +0000 (UTC) for IP:'195.135.221.5' DOMAIN:'smtp.nue.novell.com' HELO:'smtp.nue.novell.com' FROM:'cbosdonnat@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 195.135.221.5 smtp.nue.novell.com 195.135.221.5 smtp.nue.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Subject: [libvirt] [sandbox 4/6] service: fix bad ConfigMountHostImage constructor call X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 05 Dec 2017 09:53:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since commit 68406aff8 ConfigMountHostImage needs a format parameter, virt-sandbox-service needs to fit the new API. Reviewed-by: Daniel P. Berrange --- bin/virt-sandbox-service | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service index 45f4517..c34c6f3 100755 --- a/bin/virt-sandbox-service +++ b/bin/virt-sandbox-service @@ -20,6 +20,8 @@ # =20 import gi +gi.require_version('LibvirtGConfig', '1.0') +from gi.repository import LibvirtGConfig gi.require_version('LibvirtGObject', '1.0') from gi.repository import LibvirtGObject gi.require_version('LibvirtSandbox', '1.0') @@ -223,7 +225,8 @@ class Container: def gen_filesystems(self): if self.use_image: self.image =3D self.DEFAULT_IMAGE % self.get_name() - mount =3D LibvirtSandbox.ConfigMountHostImage.new(self.image, = self.dest) + mount =3D LibvirtSandbox.ConfigMountHostImage.new(self.image, = self.dest, + LibvirtGConfig= .DomainDiskFormat.RAW) self.config.add_mount(mount) =20 def fix_stat(self, f): --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:25:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1512467648830454.24644412272573; Tue, 5 Dec 2017 01:54:08 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A6B47C02738C; Tue, 5 Dec 2017 09:54:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 808BA61984; Tue, 5 Dec 2017 09:54:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 477323D386; Tue, 5 Dec 2017 09:54:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vB59ruXC007380 for ; Tue, 5 Dec 2017 04:53:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id BA2175DA68; Tue, 5 Dec 2017 09:53:56 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B31D05DA67 for ; Tue, 5 Dec 2017 09:53:53 +0000 (UTC) Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B24888046E for ; Tue, 5 Dec 2017 09:53:51 +0000 (UTC) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 10:53:50 +0100 Received: from laptop.tf.local (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 09:53:27 +0000 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= To: libvir-list@redhat.com Date: Tue, 5 Dec 2017 10:53:21 +0100 Message-Id: <20171205095322.24258-6-cbosdonnat@suse.com> In-Reply-To: <20171205095322.24258-1-cbosdonnat@suse.com> References: <20171205095322.24258-1-cbosdonnat@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 05 Dec 2017 09:53:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 05 Dec 2017 09:53:52 +0000 (UTC) for IP:'195.135.221.5' DOMAIN:'smtp.nue.novell.com' HELO:'smtp.nue.novell.com' FROM:'cbosdonnat@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 195.135.221.5 smtp.nue.novell.com 195.135.221.5 smtp.nue.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Subject: [libvirt] [sandbox 5/6] Convert to python3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 05 Dec 2017 09:54:08 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Python2 is going to die soon, convert to python3. --- bin/virt-sandbox-service | 68 ++++++++++++++++++-----------= ---- libvirt-sandbox/image/cli.py | 18 ++++----- libvirt-sandbox/image/sources/docker.py | 41 ++++++++++---------- libvirt-sandbox/image/template.py | 8 ++-- 4 files changed, 71 insertions(+), 64 deletions(-) diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service index c34c6f3..e78defb 100755 --- a/bin/virt-sandbox-service +++ b/bin/virt-sandbox-service @@ -30,7 +30,6 @@ from gi.repository import GLib import gi import re import os, sys, shutil, errno, stat -import exceptions import rpm from subprocess import Popen, PIPE, STDOUT import gettext @@ -49,7 +48,6 @@ gettext.textdomain("libvirt-sandbox") try: gettext.install("libvirt-sandbox", localedir=3D"/usr/share/locale", - unicode=3DFalse, codeset =3D 'utf-8') except IOError: import __builtin__ @@ -235,7 +233,7 @@ class Container: path =3D "%s%s" % (self.dest, f) os.chown(path, s.st_uid, s.st_gid) os.chmod(path, s.st_mode) - except OSError, e: + except OSError as e: if not e.errno =3D=3D errno.ENOENT: raise =20 @@ -253,7 +251,7 @@ class Container: try: path =3D "%s%s" % (self.dest, d) os.makedirs(path) - except OSError, e: + except OSError as e: if not e.errno =3D=3D errno.EEXIST: raise =20 @@ -263,7 +261,7 @@ class Container: path =3D "%s%s" % (self.dest, f) fd=3Dopen(path, "w") fd.close() - except OSError, e: + except OSError as e: if not e.errno =3D=3D errno.EEXIST: raise =20 @@ -404,10 +402,10 @@ class GenericContainer(Container): def create(self): try: self.create_generic() - except Exception, e: + except Exception as e: try: self.delete() - except Exception, e2: + except Exception as e2: pass raise e =20 @@ -418,6 +416,18 @@ class GenericContainer(Container): def is_template_unit(unit): return '@' in unit =20 +# Python 2 / 3 compability helpers +def get_next(obj): + if hasattr(obj, 'next'): + return obj.next() + else: + return next(obj) + +def string(obj): + if isinstance(obj, bytes): + return str(obj, encoding=3D'utf-8') + return obj + class SystemdContainer(Container): IGNORE_DIRS =3D [ "/var/run/", "/etc/logrotate.d/", "/etc/pam.d= " ] DEFAULT_DIRS =3D [ "/etc", "/var" ] @@ -581,8 +591,8 @@ WantedBy=3Dmulti-user.target def get_rpm_for_unit(self, unitfile): mi =3D self.ts.dbMatch(rpm.RPMTAG_BASENAMES, unitfile) try: - h =3D mi.next(); - except exceptions.StopIteration: + h =3D get_next(mi); + except StopIteration: return None return h['name'] =20 @@ -590,8 +600,8 @@ WantedBy=3Dmulti-user.target def extract_rpm(self, rpm_name): mi =3D self.ts.dbMatch('name', rpm_name) try: - h =3D mi.next(); - except exceptions.StopIteration: + h =3D get_next(mi); + except StopIteration: raise ValueError([_("Cannot find package named %s") % rpm_name= ]) =20 for fentry in h.fiFromHeader(): @@ -602,16 +612,16 @@ WantedBy=3Dmulti-user.target if os.path.isfile(fname): self.add_file(fname) =20 - srcrpm =3D h[rpm.RPMTAG_SOURCERPM] + srcrpm =3D string(h[rpm.RPMTAG_SOURCERPM]) srcrpmbits =3D self.split_filename(srcrpm) =20 - if srcrpmbits[0] =3D=3D h[rpm.RPMTAG_NAME]: + if srcrpmbits[0] =3D=3D string(h[rpm.RPMTAG_NAME]): return =20 mi =3D self.ts.dbMatch(rpm.RPMTAG_NAME, srcrpmbits[0]) try: - h =3D mi.next(); - except exceptions.StopIteration: + h =3D get_next(mi); + except StopIteration: raise ValueError([_("Cannot find base package %s") % srcrpmbit= s[0]]) =20 for fentry in h.fiFromHeader(): @@ -771,7 +781,7 @@ PrivateNetwork=3Dfalse fd.write("[Unit]\n") fd.write("Description=3DSandbox multi-user target\n") fd.close() - except OSError, e: + except OSError as e: if not e.errno =3D=3D errno.EEXIST: raise =20 @@ -789,7 +799,7 @@ PrivateNetwork=3Dfalse jpath =3D "/var/log/journal/" + uuid if os.path.lexists(jpath): os.remove(jpath) - except Exception, e: + except Exception as e: sys.stderr.write("%s: %s\n" % (sys.argv[0], e)) sys.stderr.flush() =20 @@ -825,10 +835,10 @@ PrivateNetwork=3Dfalse =20 try: self.create_systemd() - except Exception, e: + except Exception as e: try: self.delete() - except Exception, e2: + except Exception as e2: sys.stderr.write("Cleanup failed: %s\n" % str(e2)) raise =20 @@ -923,10 +933,10 @@ def connect(args): execute(args) return =20 - print """\ + print ("""\ Connected to %s. Type 'Ctrl + ]' to detach from the console. -""" % ( args.name ) +""" % ( args.name )) os.execl("/usr/libexec/virt-sandbox-service-util", "virt-sandbox-service-util", "-c", args.uri, @@ -1014,7 +1024,7 @@ def clone(args): newcontainer.set_security(args.security) newcontainer.set_security_label() newcontainer.save_config() - except Exception, e: + except Exception as e: if newcontainer is not None: newcontainer.delete() raise @@ -1296,23 +1306,21 @@ if __name__ =3D=3D '__main__': sys.exit(1) args.func(args) sys.exit(0) - except KeyboardInterrupt, e: + except KeyboardInterrupt as e: sys.exit(0) - except ValueError, e: - for line in e: - for l in line: - sys.stderr.write("%s: %s\n" % (sys.argv[0], l)) + except ValueError as e: + sys.stderr.write("%s: %s\n" % (sys.argv[0], e)) sys.stderr.flush() sys.exit(1) - except IOError, e: + except IOError as e: sys.stderr.write("%s: %s: %s\n" % (sys.argv[0], e.filename, e.stre= rror)) sys.stderr.flush() sys.exit(1) - except OSError, e: + except OSError as e: sys.stderr.write("%s: %s\n" % (sys.argv[0], e)) sys.stderr.flush() sys.exit(1) - except GLib.GError, e: + except GLib.GError as e: sys.stderr.write("%s: %s\n" % (sys.argv[0], e)) sys.stderr.flush() sys.exit(1) diff --git a/libvirt-sandbox/image/cli.py b/libvirt-sandbox/image/cli.py index d5e624c..fa3cace 100644 --- a/libvirt-sandbox/image/cli.py +++ b/libvirt-sandbox/image/cli.py @@ -30,7 +30,6 @@ import os.path import re import shutil import sys -import urllib2 import subprocess import random import string @@ -52,7 +51,6 @@ gettext.textdomain("libvirt-sandbox") try: gettext.install("libvirt-sandbox", localedir=3D"/usr/share/locale", - unicode=3DFalse, codeset =3D 'utf-8') except IOError: import __builtin__ @@ -149,7 +147,7 @@ def list_cached(args): tmpls.extend(template.Template.get_all(source, "%s/%s" % (args.templat= e_dir, source))) for tmpl in tmpls: - print tmpl + print (tmpl) =20 def requires_template(parser): parser.add_argument("template", @@ -265,20 +263,20 @@ def main(): try: args.func(args) sys.exit(0) - except KeyboardInterrupt, e: + except KeyboardInterrupt as e: sys.exit(0) - except ValueError, e: + except ValueError as e: sys.stderr.write("%s: %s\n" % (sys.argv[0], e)) sys.stderr.flush() sys.exit(1) - except IOError, e: - sys.stderr.write("%s: %s: %s\n" % (sys.argv[0], e.filename, e.= reason)) + except IOError as e: + sys.stderr.write("%s: %s\n" % (sys.argv[0], e.filename)) sys.stderr.flush() sys.exit(1) - except OSError, e: + except OSError as e: sys.stderr.write("%s: %s\n" % (sys.argv[0], e)) sys.stderr.flush() sys.exit(1) - except Exception, e: - print e.message + except Exception as e: + print (e) sys.exit(1) diff --git a/libvirt-sandbox/image/sources/docker.py b/libvirt-sandbox/imag= e/sources/docker.py index 6ca086c..e979054 100755 --- a/libvirt-sandbox/image/sources/docker.py +++ b/libvirt-sandbox/image/sources/docker.py @@ -21,14 +21,15 @@ # Author: Eren Yagdiran # =20 -import urllib2 import sys import json import traceback import os import subprocess import shutil -import urlparse +import urllib.error +import urllib.parse +import urllib.request import hashlib from abc import ABCMeta, abstractmethod import copy @@ -133,7 +134,7 @@ class DockerAuthBasic(DockerAuth): req.add_header("X-Docker-Token", "true") =20 def process_res(self, res): - self.token =3D res.info().getheader('X-Docker-Token') + self.token =3D res.info().get('X-Docker-Token') =20 def process_err(self, err): return False @@ -194,10 +195,10 @@ class DockerAuthBearer(DockerAuth): if params !=3D "": url =3D url + "?" + params =20 - req =3D urllib2.Request(url=3Durl) + req =3D urllib.request.Request(url=3Durl) req.add_header("Accept", "application/json") =20 - res =3D urllib2.urlopen(req) + res =3D urllib.request.urlopen(req) data =3D json.loads(res.read()) self.token =3D data["token"] return True @@ -207,7 +208,7 @@ class DockerRegistry(): =20 def __init__(self, uri_base): =20 - self.uri_base =3D list(urlparse.urlparse(uri_base)) + self.uri_base =3D list(urllib.parse.urlparse(uri_base)) self.auth_handler =3D DockerAuthNop() =20 def set_auth_handler(self, auth_handler): @@ -216,8 +217,8 @@ class DockerRegistry(): def supports_v2(self): try: (data, res) =3D self.get_json("/v2/") - ver =3D res.info().getheader("Docker-Distribution-Api-Version") - except urllib2.HTTPError as e: + ver =3D res.info().get("Docker-Distribution-Api-Version") + except urllib.error.HTTPError as e: ver =3D e.headers.get("Docker-Distribution-Api-Version", None) =20 if ver is None: @@ -243,17 +244,17 @@ class DockerRegistry(): else: server =3D "%s:%s" % (hostname, port) =20 - url =3D urlparse.urlunparse((protocol, server, "", None, None, Non= e)) + url =3D urllib.parse.urlunparse((protocol, server, "", None, None,= None)) =20 return cls(url) =20 def get_url(self, path, headers=3DNone): url_bits =3D copy.copy(self.uri_base) url_bits[2] =3D path - url =3D urlparse.urlunparse(url_bits) + url =3D urllib.parse.urlunparse(url_bits) debug("Fetching %s..." % url) =20 - req =3D urllib2.Request(url=3Durl) + req =3D urllib.request.Request(url=3Durl) =20 if headers is not None: for h in headers.keys(): @@ -262,16 +263,16 @@ class DockerRegistry(): self.auth_handler.prepare_req(req) =20 try: - res =3D urllib2.urlopen(req) + res =3D urllib.request.urlopen(req) self.auth_handler.process_res(res) return res - except urllib2.HTTPError as e: + except urllib.error.HTTPError as e: if e.code =3D=3D 401: retry =3D self.auth_handler.process_err(e) if retry: debug("Re-Fetching %s..." % url) self.auth_handler.prepare_req(req) - res =3D urllib2.urlopen(req) + res =3D urllib.request.urlopen(req) self.auth_handler.process_res(res) return res else: @@ -284,7 +285,7 @@ class DockerRegistry(): try: res =3D self.get_url(path) =20 - datalen =3D res.info().getheader("Content-Length") + datalen =3D res.info().get("Content-Length") if datalen is not None: datalen =3D int(datalen) =20 @@ -296,7 +297,7 @@ class DockerRegistry(): patternIndex =3D 0 donelen =3D 0 =20 - with open(dest, "w") as f: + with open(dest, "wb") as f: while 1: buf =3D res.read(1024*64) if not buf: @@ -321,7 +322,7 @@ class DockerRegistry(): raise IOError("Checksum '%s' for data does not match '= %s'" % (csumstr, checksum)) debug("OK\n") return res - except Exception, e: + except Exception as e: debug("FAIL %s\n" % str(e)) raise =20 @@ -333,7 +334,7 @@ class DockerRegistry(): data =3D json.loads(res.read()) debug("OK\n") return (data, res) - except Exception, e: + except Exception as e: debug("FAIL %s\n" % str(e)) raise =20 @@ -426,10 +427,10 @@ class DockerSource(base.Source): (data, res) =3D registry.get_json("/v1/repositories/%s/%s/imag= es" % ( image.repo, image.name, )) - except urllib2.HTTPError, e: + except urllib.error.HTTPError as e: raise ValueError(["Image '%s' does not exist" % template]) =20 - registryendpoint =3D res.info().getheader('X-Docker-Endpoints') + registryendpoint =3D res.info().get('X-Docker-Endpoints') =20 if basicauth.token is not None: registry.set_auth_handler(DockerAuthToken(basicauth.token)) diff --git a/libvirt-sandbox/image/template.py b/libvirt-sandbox/image/temp= late.py index 79dc33d..ab2ea29 100644 --- a/libvirt-sandbox/image/template.py +++ b/libvirt-sandbox/image/template.py @@ -19,7 +19,7 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # =20 -import urlparse +import urllib.parse import importlib import re =20 @@ -71,7 +71,7 @@ class Template(object): classimpl =3D getattr(mod, classname) return classimpl() except Exception as e: - print e + print (e) raise Exception("Invalid source: '%s'" % source) =20 def get_source_impl(self): @@ -101,12 +101,12 @@ class Template(object): netloc =3D None =20 query =3D "&".join([key + "=3D" + self.params[key] for key in self= .params.keys()]) - ret =3D urlparse.urlunparse((scheme, netloc, self.path, None, quer= y, None)) + ret =3D urllib.parse.urlunparse((scheme, netloc, self.path, None, = query, None)) return ret =20 @classmethod def from_uri(klass, uri): - o =3D urlparse.urlparse(uri) + o =3D urllib.parse.urlparse(uri) =20 idx =3D o.scheme.find("+") if idx =3D=3D -1: --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:25:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1512467652846616.0892263115807; Tue, 5 Dec 2017 01:54:12 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E4558046E; Tue, 5 Dec 2017 09:54:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6701A18A4B; Tue, 5 Dec 2017 09:54:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 30CC6180474A; Tue, 5 Dec 2017 09:54:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vB59rtdv007358 for ; Tue, 5 Dec 2017 04:53:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id ED6BF60F8B; Tue, 5 Dec 2017 09:53:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E48726025B for ; Tue, 5 Dec 2017 09:53:53 +0000 (UTC) Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 632B7C0587DE for ; Tue, 5 Dec 2017 09:53:51 +0000 (UTC) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 10:53:49 +0100 Received: from laptop.tf.local (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Tue, 05 Dec 2017 09:53:28 +0000 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= To: libvir-list@redhat.com Date: Tue, 5 Dec 2017 10:53:22 +0100 Message-Id: <20171205095322.24258-7-cbosdonnat@suse.com> In-Reply-To: <20171205095322.24258-1-cbosdonnat@suse.com> References: <20171205095322.24258-1-cbosdonnat@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 05 Dec 2017 09:53:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 05 Dec 2017 09:53:52 +0000 (UTC) for IP:'195.135.221.5' DOMAIN:'smtp.nue.novell.com' HELO:'smtp.nue.novell.com' FROM:'cbosdonnat@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 195.135.221.5 smtp.nue.novell.com 195.135.221.5 smtp.nue.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Subject: [libvirt] [sandbox 6/6] Don't hardcode interpreter path X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 05 Dec 2017 09:54:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 This is particularly useful on operating systems that don't ship Python as part of the base system (eg. FreeBSD) while still working just as well as it did before on Linux. Reviewed-by: Daniel P. Berrange --- bin/virt-sandbox-image | 2 +- bin/virt-sandbox-service | 2 +- examples/demo.py | 2 +- examples/shell.py | 2 +- examples/virt-sandbox-mkinitrd.py | 2 +- examples/virt-sandbox.py | 2 +- libvirt-sandbox/image/cli.py | 2 +- libvirt-sandbox/image/sources/base.py | 1 - libvirt-sandbox/image/sources/docker.py | 1 - libvirt-sandbox/image/sources/virtbuilder.py | 1 - 10 files changed, 7 insertions(+), 10 deletions(-) diff --git a/bin/virt-sandbox-image b/bin/virt-sandbox-image index 7e0d76b..61346ef 100755 --- a/bin/virt-sandbox-image +++ b/bin/virt-sandbox-image @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- =20 from libvirt_sandbox.image import cli diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service index e78defb..b06f304 100755 --- a/bin/virt-sandbox-service +++ b/bin/virt-sandbox-service @@ -1,4 +1,4 @@ -#!/usr/bin/python -Es +#!/usr/bin/env python3 # # Authors: Dan Walsh # diff --git a/examples/demo.py b/examples/demo.py index 6252194..c61b091 100755 --- a/examples/demo.py +++ b/examples/demo.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 =20 from gi.repository import LibvirtGObject from gi.repository import LibvirtSandbox diff --git a/examples/shell.py b/examples/shell.py index 317d13e..86b2159 100755 --- a/examples/shell.py +++ b/examples/shell.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 =20 from gi.repository import LibvirtGObject from gi.repository import LibvirtSandbox diff --git a/examples/virt-sandbox-mkinitrd.py b/examples/virt-sandbox-mkin= itrd.py index 76df925..74d1b00 100755 --- a/examples/virt-sandbox-mkinitrd.py +++ b/examples/virt-sandbox-mkinitrd.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 =20 from gi.repository import LibvirtGObject from gi.repository import LibvirtSandbox diff --git a/examples/virt-sandbox.py b/examples/virt-sandbox.py index 922ad00..e4ed6e7 100755 --- a/examples/virt-sandbox.py +++ b/examples/virt-sandbox.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 =20 from gi.repository import LibvirtGObject from gi.repository import LibvirtSandbox diff --git a/libvirt-sandbox/image/cli.py b/libvirt-sandbox/image/cli.py index fa3cace..490c5e0 100644 --- a/libvirt-sandbox/image/cli.py +++ b/libvirt-sandbox/image/cli.py @@ -1,4 +1,4 @@ -#!/usr/bin/python -Es +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Authors: Daniel P. Berrange # Eren Yagdiran diff --git a/libvirt-sandbox/image/sources/base.py b/libvirt-sandbox/image/= sources/base.py index e4e4e41..0fc9243 100644 --- a/libvirt-sandbox/image/sources/base.py +++ b/libvirt-sandbox/image/sources/base.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright (C) 2015 Universitat Polit=C3=A8cnica de Catalunya. diff --git a/libvirt-sandbox/image/sources/docker.py b/libvirt-sandbox/imag= e/sources/docker.py index e979054..eaf41fc 100755 --- a/libvirt-sandbox/image/sources/docker.py +++ b/libvirt-sandbox/image/sources/docker.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright (C) 2015 Universitat Polit=C3=A8cnica de Catalunya. diff --git a/libvirt-sandbox/image/sources/virtbuilder.py b/libvirt-sandbox= /image/sources/virtbuilder.py index 6bd9695..1b32083 100755 --- a/libvirt-sandbox/image/sources/virtbuilder.py +++ b/libvirt-sandbox/image/sources/virtbuilder.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # # Copyright (C) 2015 SUSE LLC # --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list