Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.28 KB | None | 0 0
  1. diff --git a/nova/objects/instance.py b/nova/objects/instance.py
  2. index ca805b7..74785f5 100644
  3. --- a/nova/objects/instance.py
  4. +++ b/nova/objects/instance.py
  5. @@ -1362,46 +1362,51 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
  6.              instance.obj_reset_changes(['fault'])
  7.  
  8.          return faults_by_uuid.keys()
  9.  
  10.      @base.remotable_classmethod
  11.      def get_uuids_by_host(cls, context, host):
  12.          # NOTE(danms): We could potentially do this a little more efficiently
  13.          # but for now just pull all the instances and scrape the uuids.
  14.          db_instances = db.instance_get_all_by_host(context, host,
  15.                                                     columns_to_join=[])
  16.          return [inst['uuid'] for inst in db_instances]
  17.  
  18.  
  19.  @db_api.pick_context_manager_writer
  20.  def _migrate_instance_keypairs(ctxt, count):
  21.      db_extras = ctxt.session.query(models.InstanceExtra).\
  22.          options(joinedload('instance')).\
  23.          filter_by(keypairs=None).\
  24.          filter_by(deleted=0).\
  25.          limit(count).\
  26.          all()
  27.  
  28.      count_all = len(db_extras)
  29.      count_hit = 0
  30.      for db_extra in db_extras:
  31. +        if db_extra.instance is None:
  32. +            LOG.warning(('Instance %(uuid)s is deleted, but has an undeleted '
  33. +                         'InstanceExtra record. Ignoring'),
  34. +                        {'uuid': db_extra.instance_uuid})
  35. +            continue
  36.          key_name = db_extra.instance.key_name
  37.          keypairs = objects.KeyPairList(objects=[])
  38.          if key_name:
  39.              try:
  40.                  key = objects.KeyPair.get_by_name(ctxt,
  41.                                                    db_extra.instance.user_id,
  42.                                                    key_name)
  43.                  keypairs.objects.append(key)
  44.              except exception.KeypairNotFound:
  45.                  LOG.warning(
  46.                      _LW('Instance %(uuid)s keypair %(keyname)s not found'),
  47.                      {'uuid': db_extra.instance_uuid, 'keyname': key_name})
  48.          db_extra.keypairs = jsonutils.dumps(keypairs.obj_to_primitive())
  49.          db_extra.save(ctxt.session)
  50.          count_hit += 1
  51.  
  52.      return count_all, count_hit
  53.  
  54.  
  55.  def migrate_instance_keypairs(ctxt, count):
  56.      return _migrate_instance_keypairs(ctxt, count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement