def run(self, **kwargs):
        """Since user IDs on SRC and DST may be different, we must update the
        DST ids for key pairs with IDs from DST (see `nova.key_pairs` table
        schema)"""
        src_keystone = self.src_cloud.resources[utl.IDENTITY_RESOURCE]
        dst_keystone = self.dst_cloud.resources[utl.IDENTITY_RESOURCE]

        dst_users = {}
        key_pairs = self.kp_db_broker.get_all_keypairs(self.src_cloud)

        # If we want to skip orphaned key pairs - we should not switch
        # to the admin if dst_user doesn't exist
        fallback_to_admin = not self.cfg.migrate.skip_orphaned_keypairs

        for key_pair in key_pairs:
            if key_pair.user_id not in dst_users:
                dst_user = keystone.get_dst_user_from_src_user_id(
                    src_keystone, dst_keystone, key_pair.user_id,
                    fallback_to_admin=fallback_to_admin)
                dst_users[key_pair.user_id] = dst_user
            else:
                dst_user = dst_users[key_pair.user_id]
            if dst_user is None:
                continue

            key_pair.user_id = dst_user.id

            LOG.debug('Adding key pair %s for user %s on DST', key_pair.name,
                      dst_user.name)
            self.kp_db_broker.store_keypair(key_pair, self.dst_cloud)
Example #2
0
    def run(self, **kwargs):
        """Since user IDs on SRC and DST may be different, we must update the
        DST ids for key pairs with IDs from DST (see `nova.key_pairs` table
        schema)"""
        src_keystone = self.src_cloud.resources[utl.IDENTITY_RESOURCE]
        dst_keystone = self.dst_cloud.resources[utl.IDENTITY_RESOURCE]

        dst_users = {}
        key_pairs = self.kp_db_broker.get_all_keypairs(self.src_cloud)

        # If we want to skip orphaned key pairs - we should not switch
        # to the admin if dst_user doesn't exist
        fallback_to_admin = not self.cfg.migrate.skip_orphaned_keypairs

        for key_pair in key_pairs:
            if key_pair.user_id not in dst_users:
                dst_user = keystone.get_dst_user_from_src_user_id(
                    src_keystone,
                    dst_keystone,
                    key_pair.user_id,
                    fallback_to_admin=fallback_to_admin)
                dst_users[key_pair.user_id] = dst_user
            else:
                dst_user = dst_users[key_pair.user_id]
            if dst_user is None:
                continue

            key_pair.user_id = dst_user.id

            LOG.debug('Adding key pair %s for user %s on DST', key_pair.name,
                      dst_user.name)
            self.kp_db_broker.store_keypair(key_pair, self.dst_cloud)
Example #3
0
    def _replace_user_ids(self, instance):
        """User IDs for VMs on DST by default is set to admin's ID. This
        replaces admin user IDs with correct user IDs"""

        src_user_id = instance['instance']['user_id']
        dst_user = keystone.get_dst_user_from_src_user_id(
            self.src_cloud.resources[utils.IDENTITY_RESOURCE],
            self.dst_cloud.resources[utils.IDENTITY_RESOURCE], src_user_id)
        instance['instance']['user_id'] = dst_user.id
        return instance
    def _replace_user_ids(self, instance):
        """User IDs for VMs on DST by default is set to admin's ID. This
        replaces admin user IDs with correct user IDs"""

        src_user_id = instance['instance']['user_id']
        dst_user = keystone.get_dst_user_from_src_user_id(
            self.src_cloud.resources[utils.IDENTITY_RESOURCE],
            self.dst_cloud.resources[utils.IDENTITY_RESOURCE],
            src_user_id
        )
        instance['instance']['user_id'] = dst_user.id
        return instance
Example #5
0
    def test_get_dst_user_from_src_user_id_7(self):
        """
        fallback_to_admin   1
        src_user            1
        dst_user            1
        """

        user = keystone.get_dst_user_from_src_user_id(self.fake_src_keystone,
                                                      self.fake_dst_keystone,
                                                      'fake_same_id',
                                                      fallback_to_admin=True)
        self.assertEquals(self.fake_same_user, user)
Example #6
0
    def test_get_dst_user_from_src_user_id_2(self):
        """
        fallback_to_admin   0
        src_user            1
        dst_user            0
        """

        user = keystone.get_dst_user_from_src_user_id(self.fake_src_keystone,
                                                      self.fake_dst_keystone,
                                                      'user_id_0',
                                                      fallback_to_admin=False)
        self.assertIsNone(user)