Remove use of service_* conductor calls from xenapi host.py

This removes use of some service calls in the conductor by xenapi's
host.py module and replaces them with object usage. Existing tests
are sufficient to confirm the same behavior remains.

Related to blueprint virt-objects-juno

Change-Id: I908cca4fa1d297c5c9b1d84ae7ebe7452a30ba12
This commit is contained in:
Dan Smith 2014-04-29 08:20:20 -07:00
parent e03a2c84cb
commit 5c58a69910
1 changed files with 5 additions and 13 deletions

View File

@ -21,11 +21,11 @@ import re
from nova.compute import task_states
from nova.compute import vm_states
from nova import conductor
from nova import context
from nova import exception
from nova.objects import aggregate as aggregate_obj
from nova.objects import instance as instance_obj
from nova.objects import service as service_obj
from nova.openstack.common.gettextutils import _
from nova.openstack.common import jsonutils
from nova.openstack.common import log as logging
@ -41,7 +41,6 @@ class Host(object):
def __init__(self, session, virtapi):
self._session = session
self._virtapi = virtapi
self._conductor_api = conductor.API()
def host_power_action(self, _host, action):
"""Reboots or shuts down the host."""
@ -118,18 +117,11 @@ class Host(object):
"""Sets the specified host's ability to accept new instances."""
# Since capabilities are gone, use service table to disable a node
# in scheduler
status = {'disabled': not enabled,
'disabled_reason': 'set by xenapi host_state'
}
cntxt = context.get_admin_context()
service = self._conductor_api.service_get_by_args(
cntxt,
host,
'nova-compute')
self._conductor_api.service_update(
cntxt,
service,
status)
service = service_obj.Service.get_by_args(cntxt, host, 'nova-compute')
service.disabled = not enabled
service.disabled_reason = 'set by xenapi host_state'
service.save()
args = {"enabled": jsonutils.dumps(enabled)}
response = call_xenhost(self._session, "set_host_enabled", args)