Quick actions

cmd+k|ctrl+k

Navigation

Languages

check_is_all_vms_migrated()

Snippet info

Language

Python

Visibility

public

Author

alexstav

Created

2015-11-15T20:57:08Z

Updated

2015-11-15T20:57:08Z

def check_is_all_vms_migrated(self, context):
        suspended_nodes = utils.get_compute_node_stats(
            context,
            read_suspended='suspending')
        for node in suspended_nodes:
            LOG.debug('Suspending host found: %s' % node)
            active_migrations = objects.migration.MigrationList\
                .get_in_progress_by_host_and_node(context,
                                                  node['hypervisor_hostname'],
                                                  node['hypervisor_hostname'])
            if active_migrations:
                LOG.debug('There is some migrations that are in active state')
                for migration in active_migrations:
                    if migration['status'] == 'finished':
                        self.minimizeSD.confirm_migration(
                            context,
                            migration['instace_uuid'])
                return
            else:
                if self._host_is_empty(context, node['hypervisor_hostname']):
                    mac = self.compute_rpc.prepare_host_for_suspending(
                        context, node['hypervisor_hostname'])
                    db.compute_node_update(context, node['compute_id'],
                                           {'mac_to_wake': mac})
                    self.compute_rpc.suspend_host(context,
                                                  node['hypervisor_hostname'])
                    db.compute_node_update(context, node['compute_id'],
                                           {'suspend_state': 'suspended'})
                else:
                    if not self.minimizeSD.migrate_all_vms_from_host(
                            context,
                            node['hypervisor_hostname']):
                        db.compute_node_update(context, node['compute_id'],
                                               {'suspend_state':
                                                'active'})
INFO