Files
deb-nova/nova/objects/keypair.py
Dan Smith ff221c6cc6 Require List objects to be able to backlevel their contents
Right now, a client declares its supported version of a given object
automatically in the remoted calls it makes to conductor. However,
in the case of things like InstanceList.get_by_foo(), they are
reporting the version of their InstanceList object, not their
Instance object. Conductor fills a version-matching InstanceList
object with brand new Instance objects, which the client, of course,
barfs on.

There may be a better way to handle this going forward, but for now,
stop the bleeding by requiring a version bump to the corresponding
List object whenever the object type it contains takes a version
bump. This adds a test to validate that all the objects registered
have a suitable mapping for the current version in the tree.

Since this actually caused a breakage in the Instance object
recently, this also bumps the InstanceList version so that
conductors running this commit (or later) will properly send
version 1.9 Instance objects to Havana clients and version 1.10+
to newer ones.

Change-Id: I2668dead4784fbd0411d1b6372a9a8006eeb2e84
Related-Bug: #1258256
Closes-Bug: #1254902
2013-12-13 11:35:15 -08:00

82 lines
2.7 KiB
Python

# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova import db
from nova.objects import base
from nova.objects import fields
class KeyPair(base.NovaPersistentObject, base.NovaObject):
# Version 1.0: Initial version
# Version 1.1: String attributes updated to support unicode
VERSION = '1.1'
fields = {
'id': fields.IntegerField(),
'name': fields.StringField(nullable=True),
'user_id': fields.StringField(nullable=True),
'fingerprint': fields.StringField(nullable=True),
'public_key': fields.StringField(nullable=True),
}
@staticmethod
def _from_db_object(context, keypair, db_keypair):
for key in keypair.fields:
keypair[key] = db_keypair[key]
keypair._context = context
keypair.obj_reset_changes()
return keypair
@base.remotable_classmethod
def get_by_name(cls, context, user_id, name):
db_keypair = db.key_pair_get(context, user_id, name)
return cls._from_db_object(context, cls(), db_keypair)
@base.remotable_classmethod
def destroy_by_name(cls, context, user_id, name):
db.key_pair_destroy(context, user_id, name)
@base.remotable
def create(self, context):
updates = self.obj_get_changes()
db_keypair = db.key_pair_create(context, updates)
self._from_db_object(context, self, db_keypair)
@base.remotable
def destroy(self, context):
db.key_pair_destroy(context, self.user_id, self.name)
class KeyPairList(base.ObjectListBase, base.NovaObject):
# Version 1.0: Initial version
# KeyPair <= version 1.1
VERSION = '1.0'
fields = {
'objects': fields.ListOfObjectsField('KeyPair'),
}
child_versions = {
'1.0': '1.1',
# NOTE(danms): KeyPair was at 1.1 before we added this
}
@base.remotable_classmethod
def get_by_user(cls, context, user_id):
db_keypairs = db.key_pair_get_all_by_user(context, user_id)
return base.obj_make_list(context, KeyPairList(), KeyPair, db_keypairs)
@base.remotable_classmethod
def get_count_by_user(cls, context, user_id):
return db.key_pair_count_by_user(context, user_id)