Pino Toscano
2019-Apr-15 16:01 UTC
[Libguestfs] [PATCH] v2v: -o rhv-upload: check whether the cluster exists
In the precheck script, check that the target cluster actually exists. This will avoid errors when creating the VM after the data copying. --- v2v/rhv-upload-precheck.py | 10 ++++++++++ v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/v2v/rhv-upload-precheck.py b/v2v/rhv-upload-precheck.py index 2798a29dd..b79f91b4a 100644 --- a/v2v/rhv-upload-precheck.py +++ b/v2v/rhv-upload-precheck.py @@ -70,4 +70,14 @@ if len(vms) > 0: raise RuntimeError("VM already exists with name ‘%s’, id ‘%s’" % (params['output_name'], vm.id)) +# Check whether the specified cluster exists. +clusters_service = system_service.clusters_service() +clusters = clusters_service.list( + search='name=%s' % params['rhv_cluster'], + case_sensitive=True, +) +if len(clusters) == 0: + raise RuntimeError("The cluster ‘%s’ does not exist" % + (params['rhv_cluster'])) + # Otherwise everything is OK, exit with no error. diff --git a/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py b/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py index 8d1058d67..cc4224ccd 100644 --- a/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py +++ b/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py @@ -39,6 +39,9 @@ class Connection(object): return SystemService() class SystemService(object): + def clusters_service(self): + return ClustersService() + def data_centers_service(self): return DataCentersService() @@ -54,6 +57,10 @@ class SystemService(object): def vms_service(self): return VmsService() +class ClustersService(object): + def list(self, search=None, case_sensitive=False): + return ["Default"] + class DataCentersService(object): def list(self, search=None, case_sensitive=False): return [] -- 2.20.1
Richard W.M. Jones
2019-Apr-16 07:50 UTC
Re: [Libguestfs] [PATCH] v2v: -o rhv-upload: check whether the cluster exists
On Mon, Apr 15, 2019 at 06:01:12PM +0200, Pino Toscano wrote:> In the precheck script, check that the target cluster actually exists. > This will avoid errors when creating the VM after the data copying. > --- > v2v/rhv-upload-precheck.py | 10 ++++++++++ > v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py | 7 +++++++ > 2 files changed, 17 insertions(+) > > diff --git a/v2v/rhv-upload-precheck.py b/v2v/rhv-upload-precheck.py > index 2798a29dd..b79f91b4a 100644 > --- a/v2v/rhv-upload-precheck.py > +++ b/v2v/rhv-upload-precheck.py > @@ -70,4 +70,14 @@ if len(vms) > 0: > raise RuntimeError("VM already exists with name ‘%s’, id ‘%s’" % > (params['output_name'], vm.id)) > > +# Check whether the specified cluster exists. > +clusters_service = system_service.clusters_service() > +clusters = clusters_service.list( > + search='name=%s' % params['rhv_cluster'], > + case_sensitive=True, > +) > +if len(clusters) == 0: > + raise RuntimeError("The cluster ‘%s’ does not exist" % > + (params['rhv_cluster'])) > + > # Otherwise everything is OK, exit with no error. > diff --git a/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py b/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py > index 8d1058d67..cc4224ccd 100644 > --- a/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py > +++ b/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py > @@ -39,6 +39,9 @@ class Connection(object): > return SystemService() > > class SystemService(object): > + def clusters_service(self): > + return ClustersService() > + > def data_centers_service(self): > return DataCentersService() > > @@ -54,6 +57,10 @@ class SystemService(object): > def vms_service(self): > return VmsService() > > +class ClustersService(object): > + def list(self, search=None, case_sensitive=False): > + return ["Default"] > + > class DataCentersService(object): > def list(self, search=None, case_sensitive=False): > return []Seems reasonable, ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Reasonably Related Threads
- [v2v PATCH 0/6] Various Python pycodestyle fixes
- [PATCH] v2v: -o rhv-upload: adapt phony ovirtsdk4 module to recent changes
- [PATCH] v2v: -o rhv-upload: fix the phony ovirtsdk4 module
- [PATCH 0/8] v2v: various fixed for -o rhv-upload
- [PATCH 1/8] v2v: -o rhv-upload: split vmcheck out of precheck