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