Re: [Libguestfs] [PATCH 2/3] v2v: linux: install packages

2018-11-07 Thread Tomáš Golembiovský
On Tue, 6 Nov 2018 11:32:38 +
"Richard W.M. Jones"  wrote:

> On Tue, Nov 06, 2018 at 11:44:14AM +0100, Tomáš Golembiovský wrote:
> > Install packages from local files without touching network.  
> 
> In fact, not limited to local files, but is limited to guests which
> use ‘yum’.  So I think the function needs a better name unless you're
> planning to combine it with
> customize/customize_run.ml:guest_install_command (which would be overkill).

Uh, somehow I totally screwed this up. The plan was to use "rpm".

> 
> > Signed-off-by: Tomáš Golembiovský 
> > ---
> >  v2v/linux.ml  | 19 +++
> >  v2v/linux.mli |  3 +++
> >  2 files changed, 22 insertions(+)
> > 
> > diff --git a/v2v/linux.ml b/v2v/linux.ml
> > index 177724e39..6a5cae512 100644
> > --- a/v2v/linux.ml
> > +++ b/v2v/linux.ml
> > @@ -31,6 +31,25 @@ let augeas_reload g =
> >g#aug_load ();
> >debug_augeas_errors g
> >  
> > +let rec install g inspect packages =
> > +  if packages <> [] then (
> > +do_install g inspect packages;
> > +(* Reload Augeas in case anything changed. *)
> > +augeas_reload g
> > +  )
> > +
> > +and do_install g { i_package_format = package_format } packages =  
> 
> It's purely a matter of style, but it's also possible to nest
> functions, so:
> 
>   let install g inspect packages =
> let do_install () =
>   ...
> in
> if packages <> [] then (
>   do_install ();
>   ...
> 
> Of course you could also inline do_install.

I used the same style as remove(). I will inline the code as I prefer
that.

Tomas

> 
> Rich.
> 
> > +  assert (List.length packages > 0);
> > +  match package_format with
> > +  | "rpm" ->
> > +let cmd = [ "yum"; "--assumeyes"; "install" ] @ packages in
> > +let cmd = Array.of_list cmd in
> > +ignore (g#command cmd)
> > +
> > +  | format ->
> > +error (f_"don’t know how to install packages using %s: packages: %s")
> > +  format (String.concat " " packages)
> > +
> >  let rec remove g inspect packages =
> >if packages <> [] then (
> >  do_remove g inspect packages;
> > diff --git a/v2v/linux.mli b/v2v/linux.mli
> > index 1c604665e..0036f4769 100644
> > --- a/v2v/linux.mli
> > +++ b/v2v/linux.mli
> > @@ -23,6 +23,9 @@ val augeas_reload : Guestfs.guestfs -> unit
> >  additional debugging information about parsing problems
> >  that augeas found. *)
> >  
> > +val install: Guestfs.guestfs -> Types.inspect -> string list -> unit
> > +(** Install pacakge(s). *)
> > +
> >  val remove : Guestfs.guestfs -> Types.inspect -> string list -> unit
> >  (** Uninstall package(s). *)
> >  
> > -- 
> > 2.19.0
> > 
> > ___
> > Libguestfs mailing list
> > Libguestfs@redhat.com
> > https://www.redhat.com/mailman/listinfo/libguestfs  
> 
> -- 
> Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
> Read my programming and virtualization blog: http://rwmj.wordpress.com
> virt-top is 'top' for virtual machines.  Tiny program with many
> powerful monitoring features, net stats, disk stats, logging, etc.
> http://people.redhat.com/~rjones/virt-top


-- 
Tomáš Golembiovský 

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

Re: [Libguestfs] [PATCH 2/3] v2v: linux: install packages

2018-11-07 Thread Richard W.M. Jones
On Wed, Nov 07, 2018 at 11:24:48AM +0100, Tomáš Golembiovský wrote:
> I used the same style as remove(). I will inline the code as I prefer
> that.

This is a stylistic point, so whichever style is easier to read,
more consistent, etc.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

Re: [Libguestfs] [PATCH 2/3] v2v: linux: install packages

2018-11-06 Thread Richard W.M. Jones
On Tue, Nov 06, 2018 at 06:13:40PM +0100, Pino Toscano wrote:
> On Tuesday, 6 November 2018 11:44:14 CET Tomáš Golembiovský wrote:
> > Install packages from local files without touching network.
> > 
> > Signed-off-by: Tomáš Golembiovský 
> > ---
> 
> In this case, better name it local_install/install_local (or something
> along these lines) to make it more clear it is not a "classic install".
> 
> > +and do_install g { i_package_format = package_format } packages =
> > +  assert (List.length packages > 0);
> > +  match package_format with
> > +  | "rpm" ->
> > +let cmd = [ "yum"; "--assumeyes"; "install" ] @ packages in
> > +let cmd = Array.of_list cmd in
> > +ignore (g#command cmd)
> 
> Note that i_package_format and i_package_management are different
> things.  The code above breaks when the system is RPM-based, but does
> not use yum, so e.g. Fedora (supported), and ALT Linux (not supported).
> 
> So either use i_package_format with low-level package managers
> (rpm/dpkg/etc), or use i_package_management with yum/dnf/etc.

FWIW virt-customize does something similar:

https://github.com/libguestfs/libguestfs/blob/c7343a29dd52a1264785292ca71dd8f629aa6dfa/customize/customize_run.ml#L105-L135

It's probably too much effort to combine this right now, and in any
case you [Tomáš] only need the yum and maybe dnf cases.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

Re: [Libguestfs] [PATCH 2/3] v2v: linux: install packages

2018-11-06 Thread Pino Toscano
On Tuesday, 6 November 2018 11:44:14 CET Tomáš Golembiovský wrote:
> Install packages from local files without touching network.
> 
> Signed-off-by: Tomáš Golembiovský 
> ---

In this case, better name it local_install/install_local (or something
along these lines) to make it more clear it is not a "classic install".

> +and do_install g { i_package_format = package_format } packages =
> +  assert (List.length packages > 0);
> +  match package_format with
> +  | "rpm" ->
> +let cmd = [ "yum"; "--assumeyes"; "install" ] @ packages in
> +let cmd = Array.of_list cmd in
> +ignore (g#command cmd)

Note that i_package_format and i_package_management are different
things.  The code above breaks when the system is RPM-based, but does
not use yum, so e.g. Fedora (supported), and ALT Linux (not supported).

So either use i_package_format with low-level package managers
(rpm/dpkg/etc), or use i_package_management with yum/dnf/etc.

-- 
Pino Toscano

signature.asc
Description: This is a digitally signed message part.
___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

Re: [Libguestfs] [PATCH 2/3] v2v: linux: install packages

2018-11-06 Thread Richard W.M. Jones
On Tue, Nov 06, 2018 at 11:44:14AM +0100, Tomáš Golembiovský wrote:
> Install packages from local files without touching network.

In fact, not limited to local files, but is limited to guests which
use ‘yum’.  So I think the function needs a better name unless you're
planning to combine it with
customize/customize_run.ml:guest_install_command (which would be overkill).

> Signed-off-by: Tomáš Golembiovský 
> ---
>  v2v/linux.ml  | 19 +++
>  v2v/linux.mli |  3 +++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/v2v/linux.ml b/v2v/linux.ml
> index 177724e39..6a5cae512 100644
> --- a/v2v/linux.ml
> +++ b/v2v/linux.ml
> @@ -31,6 +31,25 @@ let augeas_reload g =
>g#aug_load ();
>debug_augeas_errors g
>  
> +let rec install g inspect packages =
> +  if packages <> [] then (
> +do_install g inspect packages;
> +(* Reload Augeas in case anything changed. *)
> +augeas_reload g
> +  )
> +
> +and do_install g { i_package_format = package_format } packages =

It's purely a matter of style, but it's also possible to nest
functions, so:

  let install g inspect packages =
let do_install () =
  ...
in
if packages <> [] then (
  do_install ();
  ...

Of course you could also inline do_install.

Rich.

> +  assert (List.length packages > 0);
> +  match package_format with
> +  | "rpm" ->
> +let cmd = [ "yum"; "--assumeyes"; "install" ] @ packages in
> +let cmd = Array.of_list cmd in
> +ignore (g#command cmd)
> +
> +  | format ->
> +error (f_"don’t know how to install packages using %s: packages: %s")
> +  format (String.concat " " packages)
> +
>  let rec remove g inspect packages =
>if packages <> [] then (
>  do_remove g inspect packages;
> diff --git a/v2v/linux.mli b/v2v/linux.mli
> index 1c604665e..0036f4769 100644
> --- a/v2v/linux.mli
> +++ b/v2v/linux.mli
> @@ -23,6 +23,9 @@ val augeas_reload : Guestfs.guestfs -> unit
>  additional debugging information about parsing problems
>  that augeas found. *)
>  
> +val install: Guestfs.guestfs -> Types.inspect -> string list -> unit
> +(** Install pacakge(s). *)
> +
>  val remove : Guestfs.guestfs -> Types.inspect -> string list -> unit
>  (** Uninstall package(s). *)
>  
> -- 
> 2.19.0
> 
> ___
> Libguestfs mailing list
> Libguestfs@redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

[Libguestfs] [PATCH 2/3] v2v: linux: install packages

2018-11-06 Thread Tomáš Golembiovský
Install packages from local files without touching network.

Signed-off-by: Tomáš Golembiovský 
---
 v2v/linux.ml  | 19 +++
 v2v/linux.mli |  3 +++
 2 files changed, 22 insertions(+)

diff --git a/v2v/linux.ml b/v2v/linux.ml
index 177724e39..6a5cae512 100644
--- a/v2v/linux.ml
+++ b/v2v/linux.ml
@@ -31,6 +31,25 @@ let augeas_reload g =
   g#aug_load ();
   debug_augeas_errors g
 
+let rec install g inspect packages =
+  if packages <> [] then (
+do_install g inspect packages;
+(* Reload Augeas in case anything changed. *)
+augeas_reload g
+  )
+
+and do_install g { i_package_format = package_format } packages =
+  assert (List.length packages > 0);
+  match package_format with
+  | "rpm" ->
+let cmd = [ "yum"; "--assumeyes"; "install" ] @ packages in
+let cmd = Array.of_list cmd in
+ignore (g#command cmd)
+
+  | format ->
+error (f_"don’t know how to install packages using %s: packages: %s")
+  format (String.concat " " packages)
+
 let rec remove g inspect packages =
   if packages <> [] then (
 do_remove g inspect packages;
diff --git a/v2v/linux.mli b/v2v/linux.mli
index 1c604665e..0036f4769 100644
--- a/v2v/linux.mli
+++ b/v2v/linux.mli
@@ -23,6 +23,9 @@ val augeas_reload : Guestfs.guestfs -> unit
 additional debugging information about parsing problems
 that augeas found. *)
 
+val install: Guestfs.guestfs -> Types.inspect -> string list -> unit
+(** Install pacakge(s). *)
+
 val remove : Guestfs.guestfs -> Types.inspect -> string list -> unit
 (** Uninstall package(s). *)
 
-- 
2.19.0

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs