Volume RPC API Versioning

Add versioning to Volume Rpc API version.  This is initial version
1.0, which is compatible with previous non-versioned RPC API.

Note: this patch slightly change the db.volume_update() behavior,
which now returns updated volume info.

Change-Id: I78036b6ed97c5bc369d8c85307ecaaad8e31ff90
This commit is contained in:
Zhiteng Huang
2012-11-10 01:32:22 +08:00
parent 4206f0db05
commit 2940ce438f
9 changed files with 324 additions and 194 deletions

97
cinder/volume/rpcapi.py Normal file
View File

@@ -0,0 +1,97 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012, Intel, Inc.
#
# 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.
"""
Client side of the volume RPC API.
"""
from cinder import exception
from cinder import flags
from cinder.openstack.common import rpc
import cinder.openstack.common.rpc.proxy
FLAGS = flags.FLAGS
class VolumeAPI(cinder.openstack.common.rpc.proxy.RpcProxy):
'''Client side of the volume rpc API.
API version history:
1.0 - Initial version.
'''
BASE_RPC_API_VERSION = '1.0'
def __init__(self):
super(VolumeAPI, self).__init__(topic=FLAGS.volume_topic,
default_version=self.BASE_RPC_API_VERSION)
def create_volume(self, ctxt, volume, host,
snapshot_id=None, image_id=None):
self.cast(ctxt, self.make_msg('create_volume',
volume_id=volume['id'],
snapshot_id=snapshot_id,
image_id=image_id),
topic=rpc.queue_get_for(ctxt, self.topic, host))
def delete_volume(self, ctxt, volume):
self.cast(ctxt, self.make_msg('delete_volume',
volume_id=volume['id']),
topic=rpc.queue_get_for(ctxt, self.topic, volume['host']))
def create_snapshot(self, ctxt, volume, snapshot):
self.cast(ctxt, self.make_msg('create_snapshot',
volume_id=volume['id'],
snapshot_id=snapshot['id']),
topic=rpc.queue_get_for(ctxt, self.topic, volume['host']))
def delete_snapshot(self, ctxt, snapshot, host):
self.cast(ctxt, self.make_msg('delete_snapshot',
snapshot_id=snapshot['id']),
topic=rpc.queue_get_for(ctxt, self.topic, host))
def attach_volume(self, ctxt, volume, instance_uuid, mountpoint):
return self.call(ctxt, self.make_msg('attach_volume',
volume_id=volume['id'],
instance_uuid=instance_uuid,
mountpoint=mountpoint),
topic=rpc.queue_get_for(ctxt, self.topic, volume['host']))
def detach_volume(self, ctxt, volume):
return self.call(ctxt, self.make_msg('detach_volume',
volume_id=volume['id']),
topic=rpc.queue_get_for(ctxt, self.topic, volume['host']))
def copy_volume_to_image(self, ctxt, volume, image_id):
self.cast(ctxt, self.make_msg('copy_volume_to_image',
volume_id=volume['id'],
image_id=image_id),
topic=rpc.queue_get_for(ctxt, self.topic, volume['host']))
def initialize_connection(self, ctxt, volume, connector):
return self.call(ctxt, self.make_msg('initialize_connection',
volume_id=volume['id'],
connector=connector),
topic=rpc.queue_get_for(ctxt, self.topic, volume['host']))
def terminate_connection(self, ctxt, volume, connector, force=False):
return self.call(ctxt, self.make_msg('terminate_connection',
volume_id=volume['id'],
connector=connector,
force=force),
topic=rpc.queue_get_for(ctxt, self.topic, volume['host']))