From b66ea57ae10bac1656e11663e273837dfae67814 Mon Sep 17 00:00:00 2001 From: "vladimir.p" Date: Fri, 12 Aug 2011 12:51:54 -0700 Subject: removed VSA/drive_type code from EC2 cloud. changed nova-manage not to use cloud APIs --- bin/nova-manage | 87 ++++++++++++++------------- nova/api/ec2/__init__.py | 4 -- nova/api/ec2/cloud.py | 153 ----------------------------------------------- nova/vsa/api.py | 2 +- nova/vsa/drive_types.py | 19 +++++- 5 files changed, 65 insertions(+), 200 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index a1732cb97..3b0bf47e2 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -96,6 +96,8 @@ from nova.auth import manager from nova.cloudpipe import pipelib from nova.compute import instance_types from nova.db import migration +from nova import vsa +from nova.vsa import drive_types FLAGS = flags.FLAGS flags.DECLARE('fixed_range', 'nova.network.manager') @@ -1028,9 +1030,8 @@ class VsaCommands(object): """Methods for dealing with VSAs""" def __init__(self, *args, **kwargs): - self.controller = cloud.CloudController() self.manager = manager.AuthManager() - + self.vsa_api = vsa.API() self.context = context.get_admin_context() def _list(self, vsas): @@ -1049,15 +1050,15 @@ class VsaCommands(object): for vsa in vsas: print format_str %\ - (vsa['vsaId'], + (vsa['id'], vsa['name'], - vsa['displayName'], - vsa['vcType'], - vsa['vcCount'], - vsa['volCount'], + vsa['display_name'], + vsa['vsa_instance_type'].get('name', None), + vsa['vc_count'], + vsa['vol_count'], vsa['status'], - vsa['availabilityZone'], - str(vsa['createTime'])) + vsa['availability_zone'], + str(vsa['created_at'])) @args('--storage', dest='storage', metavar="[{'drive_name': 'type', 'num_drives': N, 'size': M},..]", @@ -1124,6 +1125,9 @@ class VsaCommands(object): if instance_type_name == '': instance_type_name = None + if image_name == '': + image_name = None + if shared in [None, False, "--full_drives"]: shared = False elif shared in [True, "--shared"]: @@ -1136,15 +1140,15 @@ class VsaCommands(object): 'display_name': name, 'display_description': description, 'vc_count': int(vc_count), - 'vc_type': instance_type_name, + 'instance_type': instance_type_name, 'image_name': image_name, + 'availability_zone': az, 'storage': storage_list, 'shared': shared, - 'placement': {'AvailabilityZone': az} } - result = self.controller.create_vsa(ctxt, **values) - self._list(result['vsaSet']) + result = self.vsa_api.create(ctxt, **values) + self._list([result]) @args('--id', dest='vsa_id', metavar="", help='VSA ID') @args('--name', dest='name', metavar="", help='VSA name') @@ -1162,32 +1166,38 @@ class VsaCommands(object): if vc_count is not None: values['vc_count'] = int(vc_count) - self.controller.update_vsa(self.context, vsa_id, **values) + vsa_id = ec2utils.ec2_id_to_id(vsa_id) + result = self.vsa_api.update(self.context, vsa_id=vsa_id, **values) + self._list([result]) @args('--id', dest='vsa_id', metavar="", help='VSA ID') def delete(self, vsa_id): """Delete a VSA.""" - self.controller.delete_vsa(self.context, vsa_id) + vsa_id = ec2utils.ec2_id_to_id(vsa_id) + self.vsa_api.delete(self.context, vsa_id) @args('--id', dest='vsa_id', metavar="", help='VSA ID (optional)') def list(self, vsa_id=None): """Describe all available VSAs (or particular one).""" + vsas = [] if vsa_id is not None: - vsa_id = [vsa_id] + internal_id = ec2utils.ec2_id_to_id(vsa_id) + vsa = self.vsa_api.get(self.context, internal_id) + vsas.append(vsa) + else: + vsas = self.vsa_api.get_all(self.context) - result = self.controller.describe_vsas(self.context, vsa_id) - self._list(result['vsaSet']) + self._list(vsas) class VsaDriveTypeCommands(object): """Methods for dealing with VSA drive types""" def __init__(self, *args, **kwargs): - self.controller = cloud.CloudController() - self.manager = manager.AuthManager() super(VsaDriveTypeCommands, self).__init__(*args, **kwargs) + self.context = context.get_admin_context() def _list(self, drives): format_str = "%-5s %-30s %-10s %-10s %-10s %-20s %-10s %s" @@ -1234,23 +1244,17 @@ class VsaDriveTypeCommands(object): raise ValueError(_('Visible parameter should be set to --show '\ 'or --hide')) - values = { - 'type': type, - 'size_gb': int(size_gb), - 'rpm': rpm, - 'capabilities': capabilities, - 'visible': visible, - 'name': name - } - result = self.controller.create_drive_type(context.get_admin_context(), - **values) - self._list(result['driveTypeSet']) + result = drive_types.create(self.context, + type, int(size_gb), rpm, + capabilities, visible, name) + self._list([result]) @args('--name', dest='name', metavar="", help='Drive name') def delete(self, name): """Delete drive type.""" - self.controller.delete_drive_type(context.get_admin_context(), name) + dtype = drive_types.get_by_name(self.context, name) + drive_types.delete(self.context, dtype['id']) @args('--name', dest='name', metavar="", help='Drive name') @args('--new_name', dest='new_name', metavar="", @@ -1258,8 +1262,9 @@ class VsaDriveTypeCommands(object): def rename(self, name, new_name=None): """Rename drive type.""" - self.controller.rename_drive_type(context.get_admin_context(), - name, new_name) + dtype = drive_types.rename(self.context, + name, new_name) + self._list([dtype]) @args('--all', dest='visible', action="store_false", help='Show all drives') @@ -1271,11 +1276,12 @@ class VsaDriveTypeCommands(object): visible = False if visible in ["--all", False] else True if name is not None: - name = [name] + drive = drive_types.get_by_name(self.context, name) + drives = [drive] + else: + drives = drive_types.get_all(self.context, visible) - result = self.controller.describe_drive_types( - context.get_admin_context(), name, visible) - self._list(result['driveTypeSet']) + self._list(drives) @args('--name', dest='name', metavar="", help='Drive name') @args('--type', dest='type', metavar="", @@ -1305,8 +1311,9 @@ class VsaDriveTypeCommands(object): raise ValueError(_("Visible parameter should be set to "\ "--show or --hide")) - self.controller.update_drive_type(context.get_admin_context(), - name, **values) + dtype = drive_types.get_by_name(self.context, name) + dtype = drive_types.update(self.context, dtype['id'], **values) + self._list([dtype]) class VolumeCommands(object): diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index 35c809547..8b6e47cfb 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -268,10 +268,6 @@ class Authorizer(wsgi.Middleware): 'StartInstances': ['projectmanager', 'sysadmin'], 'StopInstances': ['projectmanager', 'sysadmin'], 'DeleteVolume': ['projectmanager', 'sysadmin'], - 'CreateVsa': ['projectmanager', 'sysadmin'], - 'DeleteVsa': ['projectmanager', 'sysadmin'], - 'DescribeVsas': ['projectmanager', 'sysadmin'], - 'DescribeDriveTypes': ['projectmanager', 'sysadmin'], 'DescribeImages': ['all'], 'DeregisterImage': ['projectmanager', 'sysadmin'], 'RegisterImage': ['projectmanager', 'sysadmin'], diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index ac0ff713b..87bba58c3 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -45,8 +45,6 @@ from nova import network from nova import rpc from nova import utils from nova import volume -from nova import vsa -from nova.vsa import drive_types from nova.api.ec2 import ec2utils from nova.compute import instance_types from nova.image import s3 @@ -184,7 +182,6 @@ class CloudController(object): self.compute_api = compute.API( network_api=self.network_api, volume_api=self.volume_api) - self.vsa_api = vsa.API(compute_api=self.compute_api) self.setup() def __str__(self): @@ -998,156 +995,6 @@ class CloudController(object): 'status': volume['attach_status'], 'volumeId': ec2utils.id_to_ec2_vol_id(volume_id)} - def _format_vsa(self, context, p_vsa): - vsa = {} - vsa['vsaId'] = p_vsa['id'] - vsa['status'] = p_vsa['status'] - vsa['availabilityZone'] = p_vsa['availability_zone'] - vsa['createTime'] = p_vsa['created_at'] - vsa['name'] = p_vsa['name'] - vsa['displayName'] = p_vsa['display_name'] - vsa['displayDescription'] = p_vsa['display_description'] - vsa['vcCount'] = p_vsa['vc_count'] - if p_vsa['vsa_instance_type']: - vsa['vcType'] = p_vsa['vsa_instance_type'].get('name', None) - else: - vsa['vcType'] = None - - vols = self.volume_api.get_all_by_vsa(context, p_vsa['id'], "to") - vsa['volCount'] = 0 if vols is None else len(vols) - - return vsa - - def create_vsa(self, context, **kwargs): - display_name = kwargs.get('display_name') - display_description = kwargs.get('display_description') - vc_count = int(kwargs.get('vc_count', 1)) - instance_type = instance_types.get_instance_type_by_name( - kwargs.get('vc_type', FLAGS.default_vsa_instance_type)) - image_name = kwargs.get('image_name') - availability_zone = kwargs.get('placement', {}).get( - 'AvailabilityZone') - storage = kwargs.get('storage', []) - shared = kwargs.get('shared', False) - - vc_type = instance_type['name'] - _storage = str(storage) - LOG.audit(_("Create VSA %(display_name)s vc_count:%(vc_count)d "\ - "vc_type:%(vc_type)s storage:%(_storage)s"), locals()) - - vsa = self.vsa_api.create(context, display_name, display_description, - vc_count, instance_type, image_name, - availability_zone, storage, shared) - return {'vsaSet': [self._format_vsa(context, vsa)]} - - def update_vsa(self, context, vsa_id, **kwargs): - LOG.audit(_("Update VSA %s"), vsa_id) - updatable_fields = ['display_name', 'display_description', 'vc_count'] - changes = {} - for field in updatable_fields: - if field in kwargs: - changes[field] = kwargs[field] - if changes: - vsa_id = ec2utils.ec2_id_to_id(vsa_id) - self.vsa_api.update(context, vsa_id=vsa_id, **changes) - return True - - def delete_vsa(self, context, vsa_id, **kwargs): - LOG.audit(_("Delete VSA %s"), vsa_id) - vsa_id = ec2utils.ec2_id_to_id(vsa_id) - - self.vsa_api.delete(context, vsa_id) - - return True - - def describe_vsas(self, context, vsa_id=None, status=None, - availability_zone=None, **kwargs): - LOG.audit(_("Describe VSAs")) - result = [] - vsas = [] - if vsa_id is not None: - for ec2_id in vsa_id: - internal_id = ec2utils.ec2_id_to_id(ec2_id) - vsa = self.vsa_api.get(context, internal_id) - vsas.append(vsa) - else: - vsas = self.vsa_api.get_all(context) - - if status: - result = [] - for vsa in vsas: - if vsa['status'] in status: - result.append(vsa) - vsas = result - - if availability_zone: - result = [] - for vsa in vsas: - if vsa['availability_zone'] in availability_zone: - result.append(vsa) - vsas = result - - return {'vsaSet': [self._format_vsa(context, vsa) for vsa in vsas]} - - def create_drive_type(self, context, **kwargs): - name = kwargs.get('name') - type = kwargs.get('type') - size_gb = int(kwargs.get('size_gb')) - rpm = kwargs.get('rpm') - capabilities = kwargs.get('capabilities') - visible = kwargs.get('visible', True) - - LOG.audit(_("Create Drive Type %(name)s: %(type)s %(size_gb)d "\ - "%(rpm)s %(capabilities)s %(visible)s"), - locals()) - - rv = drive_types.create(context, type, size_gb, rpm, - capabilities, visible, name) - return {'driveTypeSet': [dict(rv)]} - - def update_drive_type(self, context, name, **kwargs): - LOG.audit(_("Update Drive Type %s"), name) - - dtype = drive_types.get_by_name(context, name) - - updatable_fields = ['type', - 'size_gb', - 'rpm', - 'capabilities', - 'visible'] - changes = {} - for field in updatable_fields: - if field in kwargs and \ - kwargs[field] is not None and \ - kwargs[field] != '': - changes[field] = kwargs[field] - - if changes: - drive_types.update(context, dtype['id'], **changes) - return True - - def rename_drive_type(self, context, name, new_name): - drive_types.rename(context, name, new_name) - return True - - def delete_drive_type(self, context, name): - dtype = drive_types.get_by_name(context, name) - drive_types.delete(context, dtype['id']) - return True - - def describe_drive_types(self, context, names=None, visible=True): - - drives = [] - if names is not None: - for name in names: - drive = drive_types.get_by_name(context, name) - if drive['visible'] == visible: - drives.append(drive) - else: - drives = drive_types.get_all(context, visible) - # (VP-TMP): Change to EC2 compliant output later - return {'driveTypeSet': [dict(drive) for drive in drives]} - @staticmethod def _convert_to_set(lst, label): if lst is None or lst == []: diff --git a/nova/vsa/api.py b/nova/vsa/api.py index 3588e58cc..19185b907 100644 --- a/nova/vsa/api.py +++ b/nova/vsa/api.py @@ -159,7 +159,7 @@ class API(base.Base): shared = True # check if image is ready before starting any work - if image_name is None or image_name == '': + if image_name is None: image_name = FLAGS.vc_image_name try: image_service = self.compute_api.image_service diff --git a/nova/vsa/drive_types.py b/nova/vsa/drive_types.py index 86ff76b96..3c67fdbb9 100644 --- a/nova/vsa/drive_types.py +++ b/nova/vsa/drive_types.py @@ -64,8 +64,23 @@ def create(context, type, size_gb, rpm, capabilities='', def update(context, id, **kwargs): - LOG.debug(_("Updating drive type with id %(id)s"), locals()) - return db.drive_type_update(context, id, kwargs) + + LOG.debug(_("Updating drive type with id %(id)s: %(kwargs)s"), locals()) + + updatable_fields = ['type', + 'size_gb', + 'rpm', + 'capabilities', + 'visible'] + changes = {} + for field in updatable_fields: + if field in kwargs and \ + kwargs[field] is not None and \ + kwargs[field] != '': + changes[field] = kwargs[field] + + # call update regadless if changes is empty or not + return db.drive_type_update(context, id, changes) def rename(context, name, new_name=None): -- cgit