Skip to content

Commit

Permalink
ovirtlago: add 'ovirt start'/'ovirt stop'
Browse files Browse the repository at this point in the history
1. Add 'start_all_vms' method.
2. Move 'stop_all_vms' to use the waiters class.
3. Add 'lago ovirt start/stop'

Signed-off-by: Nadav Goldin <[email protected]>
  • Loading branch information
nvgoldin committed Mar 20, 2017
1 parent e57c3a7 commit 0e8a212
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 20 deletions.
43 changes: 43 additions & 0 deletions ovirtlago/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import ovirtlago
from lago.plugins.cli import (CLIPlugin, cli_plugin, cli_plugin_add_argument)
from lago.utils import (in_prefix, with_logging)
from lago.log_utils import LogTask
from lago.config import config as lago_config

LOGGER = logging.getLogger('ovirt-cli')
Expand Down Expand Up @@ -196,13 +197,55 @@ def do_ovirt_stop_vms(prefix, **kwargs):
prefix.virt_env.engine_vm().stop_all_vms()


@cli_plugin(help='Start all VMs that are down')
@in_ovirt_prefix
@with_logging
def do_ovirt_start_vms(prefix, **kwargs):
prefix.virt_env.engine_vm().start_all_vms()


@cli_plugin(help='Print oVirt setup status')
@in_ovirt_prefix
@with_logging
def do_ovirt_status(prefix, **kwargs):
prefix.virt_env.engine_vm().status()


@cli_plugin(
help=(
'Start the environment, put all hosts in activate mode and '
'start all Engine VMs'
)
)
@in_ovirt_prefix
@with_logging
def do_ovirt_start(prefix, **kwargs):
prefix.start()
with LogTask('Activating Engine Hosts'):
prefix.virt_env.engine_vm().start_all_hosts()
with LogTask('Starting Engine VMs'):
prefix.virt_env.engine_vm().start_all_vms()


@cli_plugin(
help=(
'Stop all Engine VMs, put all hosts in maintenance and turn off '
' Lago VMs.'
)
)
@in_ovirt_prefix
@with_logging
def do_ovirt_stop(prefix, **kwargs):
with LogTask('Stopping Engine VMs'):
prefix.virt_env.engine_vm().stop_all_vms()
with LogTask('Putting host in maintenance mode'):
prefix.virt_env.engine_vm().stop_all_hosts()
with LogTask('Shutdown Lago VMs'):
pass
# TO-DO: add shutdown command here
prefix.stop()


@cli_plugin(
help=(
'Collect logs from VMs, list of collected logs '
Expand Down
40 changes: 20 additions & 20 deletions ovirtlago/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import os
import time
import warnings

from waiters import waiters
import lago
import lago.vm
from lago.config import config as lago_config
Expand Down Expand Up @@ -184,9 +184,11 @@ def get_api_v3(self):
self._api_v3 = self._get_api(api_ver=3)
return self._api_v3

def get_api_v4(self):
def get_api_v4(self, check=False):
if self._api_v4 is None or not self._api_v4.test():
self._api_v4 = self._get_api(api_ver=4)
if check and self._api_v4 is None:
raise RuntimeError('Could not connect to engine')
return self._api_v4

def add_iso(self, path):
Expand Down Expand Up @@ -219,27 +221,25 @@ def engine_setup(self, config=None):
if result.code != 0:
raise RuntimeError('Failed to setup the engine')

def stop_all_vms(self):
api = self.get_api_v4()
if api is None:
raise RuntimeError('Could not connect to engine')

def _search_vms(self, api, query):
vms_service = api.system_service().vms_service()
vms = vms_service.list(search='status=up')
if vms:
for v in vms:
vm_service = vms_service.vm_service(v.id)
vm_service.stop()
time.sleep(10)
return [vm.id for vm in vms_service.list(search=query)]

def _vm_is_down():
vm_srv = vms_service.vm_service(v.id)
vm_obj = vm_srv.get()
if vm_obj.status == sdk4.types.VmStatus.DOWN:
return True
def start_all_vms(self):
api = self.get_api_v4(check=True)
ids = self._search_vms(api, query='status=down')
vms_service = api.system_service().vms_service()
[vms_service.vm_service(id).start() for id in ids]
for id in ids:
waiters.vm_up(api=api, id=id)

for v in vms:
testlib.assert_true_within(_vm_is_down, timeout=5 * 60)
def stop_all_vms(self):
api = self.get_api_v4(check=True)
ids = self._search_vms(api, query='status=up')
vms_service = api.system_service().vms_service()
[vms_service.vm_service(id).stop() for id in ids]
for id in ids:
waiters.vm_down(api=api, id=id)

def stop_all_hosts(self):
api = self.get_api_v4()
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ lago.plugins.ovirt.cli =
collect=ovirtlago.cmd:do_ovirt_collect
deploy=ovirtlago.cmd:do_deploy
engine-setup=ovirtlago.cmd:do_ovirt_engine_setup
start=ovirtlago.cmd:do_ovirt_start
stop=ovirtlago.cmd:do_ovirt_stop
start-hosts=ovirtlago.cmd:do_ovirt_start_hosts
stop-hosts=ovirtlago.cmd:do_ovirt_stop_hosts
stop-vms=ovirtlago.cmd:do_ovirt_stop_vms
start-vms=ovirtlago.cmd:do_ovirt_start_vms
status=ovirtlago.cmd:do_ovirt_status
reposetup=ovirtlago.cmd:do_ovirt_reposetup
runtest=ovirtlago.cmd:do_ovirt_runtest
Expand Down

0 comments on commit 0e8a212

Please sign in to comment.