def quit(self): if any(is_running(brick) for brick in self.bricks): msg = _("Cannot close virtualbricks: there are running bricks") raise errors.BrickRunningError(msg) logger.info(engine_bye) for e in self.events: e.poweroff() self._notify("quit", self) if not self.quit_d.called: self.quit_d.callback(None)
def reset(self): if any(is_running(brick) for brick in self.bricks): msg = _("Project cannot be closed: there are running bricks") raise errors.BrickRunningError(msg) # Don't change the list while iterating over it for brick in list(self.bricks): if is_virtualmachine(brick): brick.image_changed.disconnect(self._image_changed) self.del_brick(brick) # Don't change the list while iterating over it for e in list(self.events): self.del_event(e) del self.socks[:] for image in self.disk_images[:]: self.remove_disk_image(image)
def del_brick(self, brick): if is_running(brick): msg = "Cannot delete brick {0:n}: brick is running".format(brick) raise errors.BrickRunningError(msg) logger.info(remove_brick, brick=brick.name) socks = set(brick.socks) if socks: logger.info(remove_socks, socks=", ".join(s.nickname for s in socks)) for _brick in self.bricks: for plug in _brick.plugs: if plug.configured() and plug.sock in socks: logger.info(disconnect_plug, sock=plug.sock.nickname) plug.disconnect() for sock in [s for s in self.socks if s.brick is brick]: self.socks.remove(sock) for plug in brick.plugs: if plug.configured(): plug.disconnect() self.bricks.remove(brick) brick.changed.disconnect(self._brick_changed) self._notify("brick-removed", brick)