Pino Toscano
2020-Jan-28 13:46 UTC
[Libguestfs] [v2v PATCH 1/2] Add back guestcaps as parameter of output#prepare_targets
It will be used to do extra checks in the output before copying the disks. Partially revert commit 3bafec4e693a25ef1c84abc0fd1bc3251862c7de. --- v2v/output_glance.ml | 2 +- v2v/output_json.ml | 2 +- v2v/output_libvirt.ml | 2 +- v2v/output_local.ml | 2 +- v2v/output_null.ml | 2 +- v2v/output_openstack.ml | 2 +- v2v/output_qemu.ml | 2 +- v2v/output_rhv.ml | 2 +- v2v/output_rhv_upload.ml | 2 +- v2v/output_vdsm.ml | 2 +- v2v/types.ml | 2 +- v2v/types.mli | 2 +- v2v/v2v.ml | 3 ++- 13 files changed, 14 insertions(+), 13 deletions(-) diff --git a/v2v/output_glance.ml b/v2v/output_glance.ml index 0eb8b5e6..21e8cc62 100644 --- a/v2v/output_glance.ml +++ b/v2v/output_glance.ml @@ -59,7 +59,7 @@ object method supported_firmware = [ TargetBIOS; TargetUEFI ] - method prepare_targets _ overlays + method prepare_targets _ overlays _ (* Write targets to a temporary local file - see above for reason. *) List.map (fun (_, ov) -> TargetFile (tmpdir // ov.ov_sd)) overlays diff --git a/v2v/output_json.ml b/v2v/output_json.ml index 29c4a1d0..b23420a7 100644 --- a/v2v/output_json.ml +++ b/v2v/output_json.ml @@ -71,7 +71,7 @@ class output_json dir json_options = object method as_options = sprintf "-o json -os %s" dir - method prepare_targets source_name overlays + method prepare_targets source_name overlays _ List.mapi ( fun i (_, ov) -> let outname diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml index dfd5d1a3..6c6b23ed 100644 --- a/v2v/output_libvirt.ml +++ b/v2v/output_libvirt.ml @@ -75,7 +75,7 @@ object (self) | None -> sprintf "-o libvirt -os %s" output_pool | Some uri -> sprintf "-o libvirt -oc %s -os %s" uri output_pool - method prepare_targets source_name overlays + method prepare_targets source_name overlays _ (* Get the capabilities from libvirt. *) let xml try diff --git a/v2v/output_local.ml b/v2v/output_local.ml index 5eb743a4..48c29eeb 100644 --- a/v2v/output_local.ml +++ b/v2v/output_local.ml @@ -31,7 +31,7 @@ class output_local dir = object method as_options = sprintf "-o local -os %s" dir - method prepare_targets source_name overlays + method prepare_targets source_name overlays _ List.map ( fun (_, ov) -> TargetFile (dir // source_name ^ "-" ^ ov.ov_sd) ) overlays diff --git a/v2v/output_null.ml b/v2v/output_null.ml index df451f9f..36710e68 100644 --- a/v2v/output_null.ml +++ b/v2v/output_null.ml @@ -89,7 +89,7 @@ object (* Force raw output, ignoring -of command line option. *) method override_output_format _ = Some "raw" - method prepare_targets _ overlays + method prepare_targets _ overlays _ if can_use_qemu_null_co_device () then ( let json_params = [ "file.driver", JSON.String "null-co"; diff --git a/v2v/output_openstack.ml b/v2v/output_openstack.ml index caaedf45..81c55a43 100644 --- a/v2v/output_openstack.ml +++ b/v2v/output_openstack.ml @@ -400,7 +400,7 @@ object (* Create the Cinder volumes, wait for them to attach to the * appliance, and return the paths of the /dev devices. *) - method prepare_targets source_name overlays + method prepare_targets source_name overlays _ (* Set up an at-exit handler so we: * (1) Unconditionally detach volumes. * (2) Delete the volumes, but only if conversion was not successful. diff --git a/v2v/output_qemu.ml b/v2v/output_qemu.ml index 22e8581a..0156370e 100644 --- a/v2v/output_qemu.ml +++ b/v2v/output_qemu.ml @@ -36,7 +36,7 @@ object method as_options sprintf "-o qemu -os %s%s" dir (if qemu_boot then " --qemu-boot" else "") - method prepare_targets source_name overlays + method prepare_targets source_name overlays _ List.map ( fun (_, ov) -> TargetFile (dir // source_name ^ "-" ^ ov.ov_sd) diff --git a/v2v/output_rhv.ml b/v2v/output_rhv.ml index a9102c06..133d03a8 100644 --- a/v2v/output_rhv.ml +++ b/v2v/output_rhv.ml @@ -151,7 +151,7 @@ object * 'os' is the output storage (-os nfs:/export). 'targets' describes * the destination files. We modify and return this list. *) - method prepare_targets _ overlays + method prepare_targets _ overlays _ let mp, uuid mount_and_check_storage_domain (s_"Export Storage Domain") os in esd_mp <- mp; diff --git a/v2v/output_rhv_upload.ml b/v2v/output_rhv_upload.ml index 14153db3..01b1ce4a 100644 --- a/v2v/output_rhv_upload.ml +++ b/v2v/output_rhv_upload.ml @@ -290,7 +290,7 @@ object (* rhev-apt.exe will be installed (if available). *) method install_rhev_apt = true - method prepare_targets source_name overlays + method prepare_targets source_name overlays _ let uuids match rhv_options.rhv_disk_uuids with | None -> diff --git a/v2v/output_vdsm.ml b/v2v/output_vdsm.ml index 1c84439e..bfb9856d 100644 --- a/v2v/output_vdsm.ml +++ b/v2v/output_vdsm.ml @@ -144,7 +144,7 @@ object * 'os' is the output storage domain (-os /rhv/data/<data center>/<data domain>) * this is already mounted path. *) - method prepare_targets _ overlays + method prepare_targets _ overlays _ if List.length vdsm_options.image_uuids <> List.length overlays || List.length vdsm_options.vol_uuids <> List.length overlays then error (f_"the number of ‘-oo vdsm-image-uuid’ and ‘-oo vdsm-vol-uuid’ parameters passed on the command line has to match the number of guest disk images (for this guest: %d)") diff --git a/v2v/types.ml b/v2v/types.ml index 8de48aec..a6a52294 100644 --- a/v2v/types.ml +++ b/v2v/types.ml @@ -530,7 +530,7 @@ class virtual output = object method check_target_firmware (_ : guestcaps) (_ : target_firmware) = () method override_output_format (_ : overlay) = (None : string option) method transfer_format t = t.target_format - method virtual prepare_targets : string -> (string * overlay) list -> target_file list + method virtual prepare_targets : string -> (string * overlay) list -> guestcaps -> target_file list method disk_create = (open_guestfs ())#disk_create method disk_copied (_ : target) (_ : int) (_ : int) = () method virtual create_metadata : source -> target list -> target_buses -> guestcaps -> inspect -> target_firmware -> unit diff --git a/v2v/types.mli b/v2v/types.mli index 9ceee8a2..483b8910 100644 --- a/v2v/types.mli +++ b/v2v/types.mli @@ -492,7 +492,7 @@ class virtual output : object (** Typically the transfer format is same as the target format, but some outputs may need to overide the transfer format, but create disk using target format. *) - method virtual prepare_targets : string -> (string * overlay) list -> target_file list + method virtual prepare_targets : string -> (string * overlay) list -> guestcaps -> target_file list (** Called after conversion but before copying to prepare (but {b not} create) the target file. The [(string * overlay list)] parameter is a list of the (format, overlay) for each target disk. If diff --git a/v2v/v2v.ml b/v2v/v2v.ml index dc1dedd7..9fd63442 100644 --- a/v2v/v2v.ml +++ b/v2v/v2v.ml @@ -173,7 +173,8 @@ let rec main () let target_formats = get_target_formats cmdline output overlays in let target_files output#prepare_targets source.s_name - (List.combine target_formats overlays) in + (List.combine target_formats overlays) + guestcaps in List.map ( fun (target_file, target_format, target_overlay) -> { target_file; target_format; target_overlay } -- 2.24.1
Pino Toscano
2020-Jan-28 13:46 UTC
[Libguestfs] [v2v PATCH 2/2] -o rhv-upload: check guest arch with cluster
Get the CPU architecture of the specified cluster, and error out in case the architecture of the guest is not the same as the cluster one. --- .../ovirtsdk4/types.py | 16 ++++++++++++++++ v2v/output_rhv_upload.ml | 18 +++++++++++++++++- v2v/rhv-upload-precheck.py | 5 +++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py index b8d4a728..732887aa 100644 --- a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py +++ b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py @@ -22,9 +22,25 @@ from enum import Enum from ovirtsdk4 import imageio_port +class Architecture(Enum): + UNDEFINED = "undefined" + X86_64 = "x86_64" + + def __init__(self, arch): + self._arch = arch + + def __str__(self): + return self._arch + + +class Cpu(object): + architecture = Architecture.X86_64 + + class Cluster(object): id = "2e97537b-a783-4706-af9e-75cb2e032dcd" name = "Default" + cpu = Cpu() class Configuration(object): diff --git a/v2v/output_rhv_upload.ml b/v2v/output_rhv_upload.ml index 01b1ce4a..db14755c 100644 --- a/v2v/output_rhv_upload.ml +++ b/v2v/output_rhv_upload.ml @@ -248,6 +248,8 @@ object val mutable rhv_storagedomain_uuid = None (* The cluster UUID. *) val mutable rhv_cluster_uuid = None + (* The cluster CPU architecture *) + val mutable rhv_cluster_cpu_architecture = None (* List of disk UUIDs. *) val mutable disks_uuids = [] (* If we didn't finish successfully, delete on exit. *) @@ -272,6 +274,8 @@ object Some (JSON_parser.object_get_string "rhv_storagedomain_uuid" json); rhv_cluster_uuid <- Some (JSON_parser.object_get_string "rhv_cluster_uuid" json); + rhv_cluster_cpu_architecture <- + Some (JSON_parser.object_get_string "rhv_cluster_cpu_architecture" json); if have_selinux then error_unless_nbdkit_compiled_with_selinux () @@ -290,7 +294,19 @@ object (* rhev-apt.exe will be installed (if available). *) method install_rhev_apt = true - method prepare_targets source_name overlays _ + method prepare_targets source_name overlays guestcaps + let rhv_cluster_name + match List.assoc "rhv_cluster" json_params with + | JSON.String s -> s + | _ -> assert false in + (match rhv_cluster_cpu_architecture with + | None -> assert false + | Some arch -> + if arch <> guestcaps.gcaps_arch then + error (f_"the cluster ‘%s’ does not support the architecture %s but %s") + rhv_cluster_name guestcaps.gcaps_arch arch + ); + let uuids match rhv_options.rhv_disk_uuids with | None -> diff --git a/v2v/rhv-upload-precheck.py b/v2v/rhv-upload-precheck.py index 5f33db98..ec3fcf4e 100644 --- a/v2v/rhv-upload-precheck.py +++ b/v2v/rhv-upload-precheck.py @@ -92,11 +92,16 @@ if len(clusters) == 0: (params['rhv_cluster'], datacenter.name, params['output_storage'])) cluster = clusters[0] +cpu = cluster.cpu +if cpu.architecture == types.Architecture.UNDEFINED: + raise RuntimeError("The cluster ‘%s’ has an unknown architecture" % + (params['rhv_cluster'])) # Otherwise everything is OK, print a JSON with the results. results = { "rhv_storagedomain_uuid": storage_domain.id, "rhv_cluster_uuid": cluster.id, + "rhv_cluster_cpu_architecture": cpu.architecture.value, } json.dump(results, sys.stdout) -- 2.24.1
Richard W.M. Jones
2020-Feb-03 12:08 UTC
Re: [Libguestfs] [v2v PATCH 2/2] -o rhv-upload: check guest arch with cluster
On Tue, Jan 28, 2020 at 02:46:28PM +0100, Pino Toscano wrote:> Get the CPU architecture of the specified cluster, and error out in case > the architecture of the guest is not the same as the cluster one. > --- > .../ovirtsdk4/types.py | 16 ++++++++++++++++ > v2v/output_rhv_upload.ml | 18 +++++++++++++++++- > v2v/rhv-upload-precheck.py | 5 +++++ > 3 files changed, 38 insertions(+), 1 deletion(-) > > diff --git a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py > index b8d4a728..732887aa 100644 > --- a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py > +++ b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py > @@ -22,9 +22,25 @@ from enum import Enum > from ovirtsdk4 import imageio_port > > > +class Architecture(Enum): > + UNDEFINED = "undefined" > + X86_64 = "x86_64" > + > + def __init__(self, arch): > + self._arch = arch > + > + def __str__(self): > + return self._arch > + > + > +class Cpu(object): > + architecture = Architecture.X86_64 > + > + > class Cluster(object): > id = "2e97537b-a783-4706-af9e-75cb2e032dcd" > name = "Default" > + cpu = Cpu() > > > class Configuration(object): > diff --git a/v2v/output_rhv_upload.ml b/v2v/output_rhv_upload.ml > index 01b1ce4a..db14755c 100644 > --- a/v2v/output_rhv_upload.ml > +++ b/v2v/output_rhv_upload.ml > @@ -248,6 +248,8 @@ object > val mutable rhv_storagedomain_uuid = None > (* The cluster UUID. *) > val mutable rhv_cluster_uuid = None > + (* The cluster CPU architecture *) > + val mutable rhv_cluster_cpu_architecture = None > (* List of disk UUIDs. *) > val mutable disks_uuids = [] > (* If we didn't finish successfully, delete on exit. *) > @@ -272,6 +274,8 @@ object > Some (JSON_parser.object_get_string "rhv_storagedomain_uuid" json); > rhv_cluster_uuid <- > Some (JSON_parser.object_get_string "rhv_cluster_uuid" json); > + rhv_cluster_cpu_architecture <- > + Some (JSON_parser.object_get_string "rhv_cluster_cpu_architecture" json); > if have_selinux then > error_unless_nbdkit_compiled_with_selinux () > > @@ -290,7 +294,19 @@ object > (* rhev-apt.exe will be installed (if available). *) > method install_rhev_apt = true > > - method prepare_targets source_name overlays _ > + method prepare_targets source_name overlays guestcaps > + let rhv_cluster_name > + match List.assoc "rhv_cluster" json_params with > + | JSON.String s -> s > + | _ -> assert false in > + (match rhv_cluster_cpu_architecture with > + | None -> assert false > + | Some arch -> > + if arch <> guestcaps.gcaps_arch then > + error (f_"the cluster ‘%s’ does not support the architecture %s but %s") > + rhv_cluster_name guestcaps.gcaps_arch arch > + ); > + > let uuids > match rhv_options.rhv_disk_uuids with > | None -> > diff --git a/v2v/rhv-upload-precheck.py b/v2v/rhv-upload-precheck.py > index 5f33db98..ec3fcf4e 100644 > --- a/v2v/rhv-upload-precheck.py > +++ b/v2v/rhv-upload-precheck.py > @@ -92,11 +92,16 @@ if len(clusters) == 0: > (params['rhv_cluster'], datacenter.name, > params['output_storage'])) > cluster = clusters[0] > +cpu = cluster.cpu > +if cpu.architecture == types.Architecture.UNDEFINED: > + raise RuntimeError("The cluster ‘%s’ has an unknown architecture" % > + (params['rhv_cluster'])) > > # Otherwise everything is OK, print a JSON with the results. > results = { > "rhv_storagedomain_uuid": storage_domain.id, > "rhv_cluster_uuid": cluster.id, > + "rhv_cluster_cpu_architecture": cpu.architecture.value, > } > > json.dump(results, sys.stdout) > --ACK series, thanks. Rich. -- 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
Maybe Matching Threads
- [v2v PATCH 2/2] -o rhv-upload: check guest arch with cluster
- [PATCH 0/8] v2v: various fixed for -o rhv-upload
- [v2v PATCH 0/6] Various Python pycodestyle fixes
- Re: [PATCH 3/3] v2v: add -o json output mode
- [PATCH v2v v3 0/2] rhv-upload: Validate UUIDs and check they don't exist already