Added an option to evacuate instances from a failed host
Change-Id: I9992b34e69bbcd67828515f395a121cee80a88ac
This commit is contained in:
parent
49f012795d
commit
e4541d9f52
@ -20,4 +20,9 @@ OPTS = [
|
||||
'nova_notifier.NovaNotifier',
|
||||
help='nova notifier class path',
|
||||
required=True),
|
||||
cfg.BoolOpt('enable_host_evacuate', default=False,
|
||||
help='Evacuate a host that is marked as down'),
|
||||
cfg.BoolOpt('on_shared_storage', default=False,
|
||||
help='Indicates that all instance files are '
|
||||
'on a shared storage'),
|
||||
]
|
||||
|
@ -31,11 +31,15 @@ class NovaNotifier(NotifierBase):
|
||||
def __init__(self, conf):
|
||||
super(NovaNotifier, self).__init__(conf)
|
||||
self.client = clients.nova_client(conf)
|
||||
self.enable_evacuate = conf.nova.enable_host_evacuate
|
||||
self.on_shared_storage = conf.nova.on_shared_storage
|
||||
|
||||
def process_event(self, data, event_type):
|
||||
if data and data.get(VProps.TYPE) is NOVA_HOST_DATASOURCE:
|
||||
if data and data.get(VProps.TYPE) == NOVA_HOST_DATASOURCE:
|
||||
if event_type == NotifierEventTypes.ACTIVATE_MARK_DOWN_EVENT:
|
||||
self._mark_host_down(data.get(VProps.ID), True)
|
||||
if self.enable_evacuate:
|
||||
self._evacuate(data.get(VProps.ID))
|
||||
elif event_type == NotifierEventTypes.DEACTIVATE_MARK_DOWN_EVENT:
|
||||
self._mark_host_down(data.get(VProps.ID), False)
|
||||
|
||||
@ -48,4 +52,29 @@ class NovaNotifier(NotifierBase):
|
||||
LOG.info('RESPONSE %s', str(response))
|
||||
except Exception as e:
|
||||
LOG.exception('Failed to services.force_down - %s', e)
|
||||
|
||||
def _evacuate(self, host_id):
|
||||
try:
|
||||
LOG.info('Going to evacuate all instances from host id: %s',
|
||||
str(host_id))
|
||||
hypervisors = self.client.hypervisors.search(host_id, servers=True)
|
||||
except Exception as e:
|
||||
LOG.exception('Failed to get hypervisors - %s', e)
|
||||
return
|
||||
|
||||
for hyper in hypervisors:
|
||||
if hasattr(hyper, 'servers'):
|
||||
for server in hyper.servers:
|
||||
self._evacuate_instance(server)
|
||||
|
||||
def _evacuate_instance(self, server):
|
||||
try:
|
||||
LOG.info('Calling Nova servers.evacuate - server: %s, '
|
||||
'on_shared_storage: %s',
|
||||
str(server), self.on_shared_storage)
|
||||
response = self.client.servers.evacuate(
|
||||
server=server['uuid'],
|
||||
on_shared_storage=self.on_shared_storage)
|
||||
LOG.info('RESPONSE %s', str(response))
|
||||
except Exception as e:
|
||||
LOG.exception('Failed to evacuate server - %s', e)
|
||||
|
Loading…
Reference in New Issue
Block a user