Hi. Repeating same logic seems ugly. How about something like the following?
def _do_dom(self, action, instance_name) if self.readonly: tmpconn ...
action(dom) tmpconn.close() else: dom = ... action(dom)
def pause(...) ... self._do_dom(virtDoain.suspend)
...
thanks,
On Wed, May 25, 2011 at 08:23:29AM -0000, Kei Masumoto wrote: > Kei Masumoto has proposed merging lp:~nttdata/nova/kvm-pause-suspend into lp:nova. > > Requested reviews: > Nova Core (nova-core) > > For more details, see: > https://code.launchpad.net/~nttdata/nova/kvm-pause-suspend/+merge/62255 > > added pause/suspend implementation to nova.virt.libvirt_conn > -- > https://code.launchpad.net/~nttdata/nova/kvm-pause-suspend/+merge/62255 > You are subscribed to branch lp:nova.
> === modified file 'nova/virt/libvirt_conn.py' > --- nova/virt/libvirt_conn.py 2011-05-17 16:28:44 +0000 > +++ nova/virt/libvirt_conn.py 2011-05-25 08:17:27 +0000 > @@ -550,19 +550,54 @@ > > @exception.wrap_exception > def pause(self, instance, callback): > - raise exception.ApiError("pause not supported for libvirt.") > + """Pause VM instance""" > + if self.read_only: > + tmpconn = self._connect(self.libvirt_uri, False) > + dom = tmpconn.lookupByName(instance.name) > + dom.suspend() > + tmpconn.close() > + else: > + dom = self._conn.lookupByName(instance.name) > + dom.suspend() > > @exception.wrap_exception > def unpause(self, instance, callback): > - raise exception.ApiError("unpause not supported for libvirt.") > + """Unpause paused VM instance""" > + if self.read_only: > + tmpconn = self._connect(self.libvirt_uri, False) > + dom = tmpconn.lookupByName(instance.name) > + dom.resume() > + tmpconn.close() > + else: > + dom = self._conn.lookupByName(instance.name) > + dom.resume() > > @exception.wrap_exception > def suspend(self, instance, callback): > - raise exception.ApiError("suspend not supported for libvirt") > + """Suspend the specified instance""" > + if self.read_only: > + tmpconn = self._connect(self.libvirt_uri, False) > + dom = tmpconn.lookupByName(instance.name) > + dom.managedSave(0) > + tmpconn.close() > + else: > + dom = self._conn.lookupByName(instance.name) > + dom.managedSave(0) > > @exception.wrap_exception > def resume(self, instance, callback): > - raise exception.ApiError("resume not supported for libvirt") > + """resume the specified instance""" > + try: > + if self.read_only: > + tmpconn = self._connect(self.libvirt_uri, False) > + dom = tmpconn.lookupByName(instance.name) > + tmpconn.close() > + else: > + dom = self._conn.lookupByName(instance.name) > + dom.create() > + except libvirt.LibvirtError: > + xml = self.to_xml(instance, None) > + self._create_new_domain(xml) > > @exception.wrap_exception > def rescue(self, instance): >
-- yamahata
« Back to merge proposal
Hi. Repeating same logic seems ugly. How about something like the following?
def _do_dom(self, action, instance_name)
if self.readonly:
tmpconn ...
action(dom) close()
tmpconn.
else:
dom = ...
action(dom)
def pause(...) _do_dom( virtDoain. suspend)
...
self.
...
thanks,
On Wed, May 25, 2011 at 08:23:29AM -0000, Kei Masumoto wrote: /code.launchpad .net/~nttdata/ nova/kvm- pause-suspend/ +merge/ 62255 libvirt_ conn /code.launchpad .net/~nttdata/ nova/kvm- pause-suspend/ +merge/ 62255
> Kei Masumoto has proposed merging lp:~nttdata/nova/kvm-pause-suspend into lp:nova.
>
> Requested reviews:
> Nova Core (nova-core)
>
> For more details, see:
> https:/
>
> added pause/suspend implementation to nova.virt.
> --
> https:/
> You are subscribed to branch lp:nova.
> === modified file 'nova/virt/ libvirt_ conn.py' libvirt_ conn.py 2011-05-17 16:28:44 +0000 libvirt_ conn.py 2011-05-25 08:17:27 +0000 wrap_exception ApiError( "pause not supported for libvirt.") self.libvirt_ uri, False) lookupByName( instance. name) lookupByName( instance. name) wrap_exception ApiError( "unpause not supported for libvirt.") self.libvirt_ uri, False) lookupByName( instance. name) lookupByName( instance. name) wrap_exception ApiError( "suspend not supported for libvirt") self.libvirt_ uri, False) lookupByName( instance. name) lookupByName( instance. name) wrap_exception ApiError( "resume not supported for libvirt") self.libvirt_ uri, False) lookupByName( instance. name) lookupByName( instance. name) LibvirtError: xml(instance, None) new_domain( xml) wrap_exception
> --- nova/virt/
> +++ nova/virt/
> @@ -550,19 +550,54 @@
>
> @exception.
> def pause(self, instance, callback):
> - raise exception.
> + """Pause VM instance"""
> + if self.read_only:
> + tmpconn = self._connect(
> + dom = tmpconn.
> + dom.suspend()
> + tmpconn.close()
> + else:
> + dom = self._conn.
> + dom.suspend()
>
> @exception.
> def unpause(self, instance, callback):
> - raise exception.
> + """Unpause paused VM instance"""
> + if self.read_only:
> + tmpconn = self._connect(
> + dom = tmpconn.
> + dom.resume()
> + tmpconn.close()
> + else:
> + dom = self._conn.
> + dom.resume()
>
> @exception.
> def suspend(self, instance, callback):
> - raise exception.
> + """Suspend the specified instance"""
> + if self.read_only:
> + tmpconn = self._connect(
> + dom = tmpconn.
> + dom.managedSave(0)
> + tmpconn.close()
> + else:
> + dom = self._conn.
> + dom.managedSave(0)
>
> @exception.
> def resume(self, instance, callback):
> - raise exception.
> + """resume the specified instance"""
> + try:
> + if self.read_only:
> + tmpconn = self._connect(
> + dom = tmpconn.
> + tmpconn.close()
> + else:
> + dom = self._conn.
> + dom.create()
> + except libvirt.
> + xml = self.to_
> + self._create_
>
> @exception.
> def rescue(self, instance):
>
--
yamahata