From 4374bef0536846afe9be1156b340b34e6d4c8d2d Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Mon, 30 Aug 2010 20:42:31 -0700 Subject: more cleanup and pylint fixes --- nova/volume/driver.py | 76 +++++++++++++++++++++++++++++++------------------- nova/volume/manager.py | 21 ++++++++------ 2 files changed, 59 insertions(+), 38 deletions(-) (limited to 'nova/volume') diff --git a/nova/volume/driver.py b/nova/volume/driver.py index 990bfe958..e82449b27 100644 --- a/nova/volume/driver.py +++ b/nova/volume/driver.py @@ -35,36 +35,16 @@ flags.DEFINE_string('aoe_eth_dev', 'eth0', 'Which device to export the volumes on') -class FakeAOEDriver(object): - def create_volume(self, volume_id, size): - logging.debug("Fake AOE: create_volume %s, %s", volume_id, size) - - def delete_volume(self, volume_id): - logging.debug("Fake AOE: delete_volume %s", volume_id) - - def create_export(self, volume_id, shelf_id, blade_id): - logging.debug("Fake AOE: create_export %s, %s, %s", - volume_id, shelf_id, blade_id) - - def remove_export(self, volume_id, shelf_id, blade_id): - logging.debug("Fake AOE: remove_export %s, %s, %s", - volume_id, shelf_id, blade_id) - - def ensure_exports(self): - logging.debug("Fake AOE: ensure_export") - class AOEDriver(object): - def __init__(self, *args, **kwargs): - super(AOEDriver, self).__init__(*args, **kwargs) + """Executes commands relating to AOE volumes""" @defer.inlineCallbacks - def _ensure_vg(self): + @staticmethod + def create_volume(volume_id, size): + """Creates a logical volume""" + # NOTE(vish): makes sure that the volume group exists yield process.simple_execute("vgs | grep %s" % FLAGS.volume_group) - - @defer.inlineCallbacks - def create_volume(self, volume_id, size): - self._ensure_vg() if int(size) == 0: sizestr = '100M' else: @@ -76,14 +56,18 @@ class AOEDriver(object): terminate_on_stderr=False) @defer.inlineCallbacks - def delete_volume(self, volume_id): + @staticmethod + def delete_volume(volume_id): + """Deletes a logical volume""" yield process.simple_execute( "sudo lvremove -f %s/%s" % (FLAGS.volume_group, volume_id), terminate_on_stderr=False) @defer.inlineCallbacks - def create_export(self, volume_id, shelf_id, blade_id): + @staticmethod + def create_export(volume_id, shelf_id, blade_id): + """Creates an export for a logical volume""" yield process.simple_execute( "sudo vblade-persist setup %s %s %s /dev/%s/%s" % (shelf_id, @@ -94,7 +78,9 @@ class AOEDriver(object): terminate_on_stderr=False) @defer.inlineCallbacks - def remove_export(self, _volume_id, shelf_id, blade_id): + @staticmethod + def remove_export(_volume_id, shelf_id, blade_id): + """Removes an export for a logical volume""" yield process.simple_execute( "sudo vblade-persist stop %s %s" % (shelf_id, blade_id), terminate_on_stderr=False) @@ -103,10 +89,42 @@ class AOEDriver(object): terminate_on_stderr=False) @defer.inlineCallbacks - def ensure_exports(self): + @staticmethod + def ensure_exports(): + """Runs all existing exports""" # NOTE(ja): wait for blades to appear yield process.simple_execute("sleep 5") yield process.simple_execute("sudo vblade-persist auto all", check_exit_code=False) yield process.simple_execute("sudo vblade-persist start all", check_exit_code=False) + + +class FakeAOEDriver(AOEDriver): + """Logs calls instead of executing""" + @staticmethod + def create_volume(volume_id, size): + """Creates a logical volume""" + logging.debug("Fake AOE: create_volume %s, %s", volume_id, size) + + @staticmethod + def delete_volume(volume_id): + """Deletes a logical volume""" + logging.debug("Fake AOE: delete_volume %s", volume_id) + + @staticmethod + def create_export(volume_id, shelf_id, blade_id): + """Creates an export for a logical volume""" + logging.debug("Fake AOE: create_export %s, %s, %s", + volume_id, shelf_id, blade_id) + + @staticmethod + def remove_export(volume_id, shelf_id, blade_id): + """Removes an export for a logical volume""" + logging.debug("Fake AOE: remove_export %s, %s, %s", + volume_id, shelf_id, blade_id) + + @staticmethod + def ensure_exports(): + """Runs all existing exports""" + logging.debug("Fake AOE: ensure_export") diff --git a/nova/volume/manager.py b/nova/volume/manager.py index c57c920c9..ad5aa22a2 100644 --- a/nova/volume/manager.py +++ b/nova/volume/manager.py @@ -48,6 +48,7 @@ flags.DEFINE_integer('blades_per_shelf', class AOEManager(manager.Manager): + """Manages Ata-Over_Ethernet volumes""" def __init__(self, volume_driver=None, *args, **kwargs): if not volume_driver: # NOTE(vish): support the legacy fake storage flag @@ -59,6 +60,7 @@ class AOEManager(manager.Manager): super(AOEManager, self).__init__(*args, **kwargs) def _ensure_blades(self, context): + """Ensure that blades have been created in datastore""" total_blades = FLAGS.num_shelves * FLAGS.blades_per_shelf if self.db.export_device_count(context) >= total_blades: return @@ -69,8 +71,8 @@ class AOEManager(manager.Manager): @defer.inlineCallbacks def create_volume(self, context, volume_id): - """Creates and exports the volume.""" - logging.info("volume %s: creating" % (volume_id)) + """Creates and exports the volume""" + logging.info("volume %s: creating", volume_id) volume_ref = self.db.volume_get(context, volume_id) @@ -79,15 +81,15 @@ class AOEManager(manager.Manager): {'node_name': FLAGS.node_name}) size = volume_ref['size'] - logging.debug("volume %s: creating lv of size %sG" % (volume_id, size)) + logging.debug("volume %s: creating lv of size %sG", volume_id, size) yield self.driver.create_volume(volume_id, size) - logging.debug("volume %s: allocating shelf & blade" % (volume_id)) + logging.debug("volume %s: allocating shelf & blade", volume_id) self._ensure_blades(context) rval = self.db.volume_allocate_shelf_and_blade(context, volume_id) (shelf_id, blade_id) = rval - logging.debug("volume %s: exporting shelf %s & blade %s" % (volume_id, + logging.debug("volume %s: exporting shelf %s & blade %s", (volume_id, shelf_id, blade_id)) yield self.driver.create_export(volume_id, shelf_id, blade_id) @@ -96,15 +98,16 @@ class AOEManager(manager.Manager): self.db.volume_update(context, volume_id, {'status': 'available'}) - logging.debug("volume %s: re-exporting all values" % (volume_id)) + logging.debug("volume %s: re-exporting all values", volume_id) yield self.driver.ensure_exports() - logging.debug("volume %s: created successfully" % (volume_id)) + logging.debug("volume %s: created successfully", volume_id) defer.returnValue(volume_id) @defer.inlineCallbacks def delete_volume(self, context, volume_id): - logging.debug("Deleting volume with id of: %s" % (volume_id)) + """Deletes and unexports volume""" + logging.debug("Deleting volume with id of: %s", volume_id) volume_ref = self.db.volume_get(context, volume_id) if volume_ref['attach_status'] == "attached": raise exception.Error("Volume is still attached") @@ -113,6 +116,6 @@ class AOEManager(manager.Manager): shelf_id, blade_id = self.db.volume_get_shelf_and_blade(context, volume_id) yield self.driver.remove_export(volume_id, shelf_id, blade_id) - yield self.driver.delete_volume(volume_id) + yield self.driver.delete_volumevolume_id self.db.volume_destroy(context, volume_id) defer.returnValue(True) -- cgit