Add live migration support
story: 2005585 Task: #30774 Change-Id: I5dc6db643900a6bfcc427b4b9ee23b5557b091a4 Signed-off-by: Tomi Juvonen <tomi.juvonen@nokia.com>
This commit is contained in:
parent
a232dda364
commit
228b050a34
|
@ -164,7 +164,7 @@ def remove_session(session_id):
|
|||
downloads = _download_get_all(session, session_id)
|
||||
if downloads:
|
||||
for download in downloads:
|
||||
download.delete(download)
|
||||
session.delete(download)
|
||||
|
||||
hosts = _hosts_get(session, session_id)
|
||||
if hosts:
|
||||
|
|
|
@ -565,6 +565,10 @@ class Workflow(BaseWorkflow):
|
|||
self.notify_action_done(project, instance)
|
||||
elif instance.action == 'OWN_ACTION':
|
||||
pass
|
||||
elif instance.action == 'LIVE_MIGRATE':
|
||||
if not self.live_migrate_server(instance):
|
||||
return False
|
||||
self.notify_action_done(project, instance)
|
||||
else:
|
||||
# TBD LIVE_MIGRATE not supported
|
||||
raise Exception('%s: instance %s action '
|
||||
|
@ -576,7 +580,7 @@ class Workflow(BaseWorkflow):
|
|||
def _wait_host_empty(self, host):
|
||||
hid = self.nova.hypervisors.search(host)[0].id
|
||||
vcpus_used_last = 0
|
||||
# wait 4min to get host empty
|
||||
# wait 4min to get host emptys
|
||||
for j in range(48):
|
||||
hvisor = self.nova.hypervisors.get(hid)
|
||||
vcpus_used = hvisor.__getattr__('vcpus_used')
|
||||
|
@ -592,6 +596,44 @@ class Workflow(BaseWorkflow):
|
|||
LOG.info('%s host still not empty' % host)
|
||||
return False
|
||||
|
||||
def live_migrate_server(self, instance):
|
||||
server_id = instance.instance_id
|
||||
server = self.nova.servers.get(server_id)
|
||||
instance.state = server.__dict__.get('OS-EXT-STS:vm_state')
|
||||
orig_host = str(server.__dict__.get('OS-EXT-SRV-ATTR:host'))
|
||||
LOG.info('live_migrate_server %s state %s host %s' % (server_id,
|
||||
instance.state,
|
||||
orig_host))
|
||||
last_vm_state = instance.state
|
||||
try:
|
||||
server.live_migrate()
|
||||
retries = 0
|
||||
while retries != 120:
|
||||
time.sleep(5)
|
||||
server = self.nova.servers.get(server_id)
|
||||
host = str(server.__dict__.get('OS-EXT-SRV-ATTR:host'))
|
||||
instance.state = server.__dict__.get('OS-EXT-STS:vm_state')
|
||||
instance.host = host
|
||||
if instance.state == 'error':
|
||||
LOG.error('instance %s live migration failed'
|
||||
% server_id)
|
||||
return False
|
||||
elif last_vm_state != instance.state:
|
||||
LOG.info('instance %s state changed: %s' % (server_id,
|
||||
instance.state))
|
||||
elif host != orig_host:
|
||||
LOG.info('instance %s live migrated to host %s' %
|
||||
(server_id, host))
|
||||
return True
|
||||
retries = retries + 1
|
||||
LOG.error('instance %s live migration did not finish in %s, '
|
||||
'state: %s' % (server_id, retries, instance.state))
|
||||
return False
|
||||
except Exception as e:
|
||||
LOG.error('server %s live migration failed, Exception=%s' %
|
||||
(server_id, e))
|
||||
return False
|
||||
|
||||
def migrate_server(self, instance):
|
||||
# TBD this method should be enhanced for errors and to have failed
|
||||
# instance back to state active instead of error
|
||||
|
@ -599,8 +641,9 @@ class Workflow(BaseWorkflow):
|
|||
server = self.nova.servers.get(server_id)
|
||||
instance.state = server.__dict__.get('OS-EXT-STS:vm_state')
|
||||
orig_host = str(server.__dict__.get('OS-EXT-SRV-ATTR:host'))
|
||||
LOG.info('server %s state %s host %s' % (server_id, instance.state,
|
||||
orig_host))
|
||||
LOG.info('migrate_server %s state %s host %s' % (server_id,
|
||||
instance.state,
|
||||
orig_host))
|
||||
last_vm_state = instance.state
|
||||
retry_migrate = 2
|
||||
while True:
|
||||
|
|
Loading…
Reference in New Issue