Replace nova client with cinder client to use volume
Now cinder support a few new features like extend volume which used in Trove. We can't use nova client to enjoy this new feature, so we should change to use cinder client as volume management. implement bp implement-volume-extend Change-Id: I4f9139bacd7d8b4c2538bff6aa54416b27c9026e
This commit is contained in:
parent
a9eb50ec60
commit
4907ccca2a
@ -10,6 +10,9 @@ $ tox
|
||||
To quickly run the tests for Python 2.7, run:
|
||||
$ tox -epy27
|
||||
|
||||
To quickly run PEP8, run:
|
||||
$ to -epep8
|
||||
|
||||
To generate a coverage report,run:
|
||||
$ tox -ecover
|
||||
(note: on some boxes, the results may not be accurate unless you run it twice)
|
||||
|
@ -3,9 +3,9 @@
|
||||
# Fake out the remote implementations
|
||||
remote_implementation = fake
|
||||
remote_nova_client = trove.tests.fakes.nova.fake_create_nova_client
|
||||
remote_nova_volume_client = trove.tests.fakes.nova.fake_create_nova_volume_client
|
||||
remote_guest_client = trove.tests.fakes.guestagent.fake_create_guest_client
|
||||
remote_swift_client = trove.tests.fakes.swift.fake_create_swift_client
|
||||
remote_cinder_client = trove.tests.fakes.nova.fake_create_cinder_client
|
||||
|
||||
# This will remove some of the verbose logging when trying to diagnose tox issues
|
||||
#default_log_levels=routes.middleware=ERROR,trove.common.auth=WARN
|
||||
|
@ -13,6 +13,7 @@ netaddr
|
||||
httplib2
|
||||
lxml
|
||||
python-novaclient
|
||||
python-cinderclient>=1.0.4
|
||||
python-keystoneclient
|
||||
python-swiftclient
|
||||
iso8601
|
||||
|
@ -41,7 +41,7 @@ common_opts = [
|
||||
default="real",
|
||||
help='Remote implementation for using fake integration code'),
|
||||
cfg.StrOpt('nova_compute_url', default='http://localhost:8774/v2'),
|
||||
cfg.StrOpt('nova_volume_url', default='http://localhost:8776/v2'),
|
||||
cfg.StrOpt('cinder_url', default='http://localhost:8776/v2'),
|
||||
cfg.StrOpt('swift_url', default='http://localhost:8080/v1/AUTH_'),
|
||||
cfg.StrOpt('trove_auth_url', default='http://0.0.0.0:5000/v2.0'),
|
||||
cfg.StrOpt('host', default='0.0.0.0'),
|
||||
@ -156,8 +156,8 @@ common_opts = [
|
||||
default='trove.common.remote.guest_client'),
|
||||
cfg.StrOpt('remote_nova_client',
|
||||
default='trove.common.remote.nova_client'),
|
||||
cfg.StrOpt('remote_nova_volume_client',
|
||||
default='trove.common.remote.nova_volume_client'),
|
||||
cfg.StrOpt('remote_cinder_client',
|
||||
default='trove.common.remote.cinder_client'),
|
||||
cfg.StrOpt('remote_swift_client',
|
||||
default='trove.common.remote.swift_client'),
|
||||
cfg.StrOpt('exists_notification_transformer',
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
from trove.common import cfg
|
||||
from trove.openstack.common.importutils import import_class
|
||||
from cinderclient.v2 import client as CinderClient
|
||||
from novaclient.v1_1.client import Client
|
||||
from swiftclient.client import Connection
|
||||
|
||||
@ -24,7 +25,7 @@ CONF = cfg.CONF
|
||||
|
||||
COMPUTE_URL = CONF.nova_compute_url
|
||||
PROXY_AUTH_URL = CONF.trove_auth_url
|
||||
VOLUME_URL = CONF.nova_volume_url
|
||||
VOLUME_URL = CONF.cinder_url
|
||||
OBJECT_STORE_URL = CONF.swift_url
|
||||
USE_SNET = CONF.backup_use_snet
|
||||
|
||||
@ -58,14 +59,12 @@ def create_admin_nova_client(context):
|
||||
return client
|
||||
|
||||
|
||||
def nova_volume_client(context):
|
||||
# Quite annoying but due to a paste config loading bug.
|
||||
# TODO(hub-cap): talk to the openstack-common people about this
|
||||
client = Client(context.user, context.auth_token,
|
||||
project_id=context.tenant, auth_url=PROXY_AUTH_URL)
|
||||
def cinder_client(context):
|
||||
client = CinderClient.Client(context.user, context.auth_token,
|
||||
project_id=context.tenant,
|
||||
auth_url=PROXY_AUTH_URL)
|
||||
client.client.auth_token = context.auth_token
|
||||
client.client.management_url = "%s/%s/" % (VOLUME_URL, context.tenant)
|
||||
|
||||
return client
|
||||
|
||||
|
||||
@ -80,5 +79,5 @@ def swift_client(context):
|
||||
create_dns_client = import_class(CONF.remote_dns_client)
|
||||
create_guest_client = import_class(CONF.remote_guest_client)
|
||||
create_nova_client = import_class(CONF.remote_nova_client)
|
||||
create_nova_volume_client = import_class(CONF.remote_nova_volume_client)
|
||||
create_swift_client = import_class(CONF.remote_swift_client)
|
||||
create_cinder_client = import_class(CONF.remote_cinder_client)
|
||||
|
@ -99,7 +99,7 @@ class DetailedMgmtInstance(SimpleMgmtInstance):
|
||||
@classmethod
|
||||
def load(cls, context, id):
|
||||
instance = load_mgmt_instance(cls, context, id)
|
||||
client = remote.create_nova_volume_client(context)
|
||||
client = remote.create_cinder_client(context)
|
||||
try:
|
||||
instance.volume = client.volumes.get(instance.volume_id)
|
||||
except Exception:
|
||||
|
@ -21,7 +21,7 @@ Model classes that extend the instances functionality for volumes.
|
||||
|
||||
from trove.openstack.common import log as logging
|
||||
|
||||
from trove.common.remote import create_nova_volume_client
|
||||
from trove.common.remote import create_cinder_client
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -44,7 +44,7 @@ class StorageDevices(object):
|
||||
|
||||
@staticmethod
|
||||
def load(context):
|
||||
client = create_nova_volume_client(context)
|
||||
client = create_cinder_client(context)
|
||||
rdstorages = client.rdstorage.list()
|
||||
for rdstorage in rdstorages:
|
||||
LOG.debug("rdstorage=" + str(rdstorage))
|
||||
|
@ -24,7 +24,7 @@ from trove.common import exception
|
||||
from trove.common.remote import create_dns_client
|
||||
from trove.common.remote import create_guest_client
|
||||
from trove.common.remote import create_nova_client
|
||||
from trove.common.remote import create_nova_volume_client
|
||||
from trove.common.remote import create_cinder_client
|
||||
from trove.extensions.security_group.models import SecurityGroup
|
||||
from trove.db import models as dbmodels
|
||||
from trove.backup.models import Backup
|
||||
@ -386,7 +386,7 @@ class BaseInstance(SimpleInstance):
|
||||
@property
|
||||
def volume_client(self):
|
||||
if not self._volume_client:
|
||||
self._volume_client = create_nova_volume_client(self.context)
|
||||
self._volume_client = create_cinder_client(self.context)
|
||||
return self._volume_client
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ from trove.common.exception import VolumeCreationFailure
|
||||
from trove.common.exception import TroveError
|
||||
from trove.common.remote import create_dns_client
|
||||
from trove.common.remote import create_nova_client
|
||||
from trove.common.remote import create_nova_volume_client
|
||||
from trove.common.remote import create_cinder_client
|
||||
from swiftclient.client import ClientException
|
||||
from trove.common.utils import poll_until
|
||||
from trove.instance import models as inst_models
|
||||
@ -78,7 +78,7 @@ class NotifyMixin(object):
|
||||
payload = {
|
||||
'availability_zone': az,
|
||||
'created_at': created_time,
|
||||
'display_name': self.name,
|
||||
'name': self.name,
|
||||
'instance_id': self.id,
|
||||
'instance_name': self.name,
|
||||
'instance_size': instance_size or flavor.ram,
|
||||
@ -290,12 +290,10 @@ class FreshInstanceTasks(FreshInstance, NotifyMixin, ConfigurationMixin):
|
||||
LOG.info("Entering create_volume")
|
||||
LOG.debug(_("Starting to create the volume for the instance"))
|
||||
|
||||
volume_client = create_nova_volume_client(self.context)
|
||||
volume_client = create_cinder_client(self.context)
|
||||
volume_desc = ("mysql volume for %s" % self.id)
|
||||
volume_ref = volume_client.volumes.create(
|
||||
volume_size,
|
||||
display_name="mysql-%s" % self.id,
|
||||
display_description=volume_desc)
|
||||
volume_size, name="mysql-%s" % self.id, description=volume_desc)
|
||||
|
||||
# Record the volume ID in case something goes wrong.
|
||||
self.update_db(volume_id=volume_ref.id)
|
||||
@ -404,7 +402,7 @@ class BuiltInstanceTasks(BuiltInstance, NotifyMixin, ConfigurationMixin):
|
||||
"""
|
||||
|
||||
def get_volume_mountpoint(self):
|
||||
volume = create_nova_volume_client(self.context).volumes.get(volume_id)
|
||||
volume = create_cinder_client(self.context).volumes.get(volume_id)
|
||||
mountpoint = volume.attachments[0]['device']
|
||||
if mountpoint[0] is not "/":
|
||||
return "/%s" % mountpoint
|
||||
|
@ -387,15 +387,15 @@ class FakeServerVolumes(object):
|
||||
|
||||
class FakeVolume(object):
|
||||
|
||||
def __init__(self, parent, owner, id, size, display_name,
|
||||
display_description):
|
||||
def __init__(self, parent, owner, id, size, name,
|
||||
description):
|
||||
self.attachments = []
|
||||
self.parent = parent
|
||||
self.owner = owner # This is a context.
|
||||
self.id = id
|
||||
self.size = size
|
||||
self.display_name = display_name
|
||||
self.display_description = display_description
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.event_spawn = get_event_spawer()
|
||||
self._current_status = "BUILD"
|
||||
# For some reason we grab this thing from device then call it mount
|
||||
@ -403,10 +403,10 @@ class FakeVolume(object):
|
||||
self.device = "vdb"
|
||||
|
||||
def __repr__(self):
|
||||
msg = ("FakeVolume(id=%s, size=%s, display_name=%s, "
|
||||
"display_description=%s, _current_status=%s)")
|
||||
params = (self.id, self.size, self.display_name,
|
||||
self.display_description, self._current_status)
|
||||
msg = ("FakeVolume(id=%s, size=%s, name=%s, "
|
||||
"description=%s, _current_status=%s)")
|
||||
params = (self.id, self.size, self.name,
|
||||
self.description, self._current_status)
|
||||
return (msg % params)
|
||||
|
||||
@property
|
||||
@ -476,10 +476,10 @@ class FakeVolumes(object):
|
||||
else:
|
||||
raise nova_exceptions.NotFound(404, "Bad permissions")
|
||||
|
||||
def create(self, size, display_name=None, display_description=None):
|
||||
def create(self, size, name=None, description=None):
|
||||
id = "FAKE_VOL_%s" % uuid.uuid4()
|
||||
volume = FakeVolume(self, self.context, id, size, display_name,
|
||||
display_description)
|
||||
volume = FakeVolume(self, self.context, id, size, name,
|
||||
description)
|
||||
self.db[id] = volume
|
||||
if size == 9:
|
||||
volume.schedule_status("error", 2)
|
||||
@ -778,3 +778,7 @@ def fake_create_nova_client(context):
|
||||
|
||||
def fake_create_nova_volume_client(context):
|
||||
return get_client_data(context)['volume']
|
||||
|
||||
|
||||
def fake_create_cinder_client(context):
|
||||
return get_client_data(context)['volume']
|
||||
|
Loading…
Reference in New Issue
Block a user