From 36d31ddfe0bbdc4071aa695a5a4db8b49840d7b3 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Fri, 25 Apr 2014 13:09:49 +0200 Subject: Added operation result logs. These will be visible with 'lmi -v'. --- commands/storage/lmi/scripts/storage/fs.py | 6 ++++++ commands/storage/lmi/scripts/storage/luks.py | 10 +++++++++- commands/storage/lmi/scripts/storage/lvm.py | 22 ++++++++++++++++++---- commands/storage/lmi/scripts/storage/partition.py | 9 ++++++++- commands/storage/lmi/scripts/storage/raid.py | 6 +++++- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/commands/storage/lmi/scripts/storage/fs.py b/commands/storage/lmi/scripts/storage/fs.py index 0dd2ee0..7a6ee5b 100644 --- a/commands/storage/lmi/scripts/storage/fs.py +++ b/commands/storage/lmi/scripts/storage/fs.py @@ -199,6 +199,10 @@ def create_fs(ns, devices, fs, label=None): values = service.LMI_CreateFileSystem.LMI_CreateFileSystemValues raise LmiFailed("Cannot format the device %s: %s." % (devs[0].Name, values.value_name(ret))) + + devnames = [device.Name for device in devs] + LOG().info("Created %s on %s", fs, "+".join(devnames)) + return outparams['TheElement'] def delete_format(ns, fmt): @@ -222,6 +226,8 @@ def delete_format(ns, fmt): raise LmiFailed("Cannot delete the format: %s." % (values.value_name(ret))) + LOG().info("Deleted data on %s", fmt.ElementName) + def get_format_label(_ns, fmt): """ Return short text description of the format, ready for printing. diff --git a/commands/storage/lmi/scripts/storage/luks.py b/commands/storage/lmi/scripts/storage/luks.py index 79b0fe0..35cccb7 100644 --- a/commands/storage/lmi/scripts/storage/luks.py +++ b/commands/storage/lmi/scripts/storage/luks.py @@ -74,6 +74,8 @@ def create_luks(ns, device, passphrase): values = service.CreateEncryptionFormat.CreateEncryptionFormatValues raise LmiFailed("Cannot create LUKS format: %s." % (values.value_name(ret),)) + + LOG().info("Created LUKS on %s", device.Name) return outparams['Format'] @@ -103,7 +105,10 @@ def open_luks(ns, fmt, name, passphrase): values = service.OpenEncryptionFormat.OpenEncryptionFormatValues raise LmiFailed("Cannot open LUKS format: %s." % (values.value_name(ret),)) - return outparams['Extent'] + + opened = outparams['Extent'].to_instance() + LOG().info("Opened LUKS on %s as %s", fmt.ElementName, opened.Name) + return opened def close_luks(ns, fmt): """ @@ -121,6 +126,7 @@ def close_luks(ns, fmt): values = service.CloseEncryptionFormat.CloseEncryptionFormatValues raise LmiFailed("Cannot close LUKS format: %s." % (values.value_name(ret),)) + LOG().info("Closed LUKS on %s", fmt.ElementName) def add_luks_passphrase(ns, fmt, passphrase, new_passphrase): """ @@ -152,6 +158,7 @@ def add_luks_passphrase(ns, fmt, passphrase, new_passphrase): values = service.AddPassphrase.AddPassphraseValues raise LmiFailed("Cannot add new passphrase: %s." % (values.value_name(ret),)) + LOG().info("Added passphrase to %s", fmt.ElementName) def delete_luks_passphrase(ns, fmt, passphrase): """ @@ -173,6 +180,7 @@ def delete_luks_passphrase(ns, fmt, passphrase): values = service.DeletePassphrase.DeletePassphraseValues raise LmiFailed("Cannot delete passphrase: %s." % (values.value_name(ret),)) + LOG().info("Deleted passphrase from %s", fmt.ElementName) def get_luks_device(ns, fmt): """ diff --git a/commands/storage/lmi/scripts/storage/lvm.py b/commands/storage/lmi/scripts/storage/lvm.py index 15db230..a54f670 100644 --- a/commands/storage/lmi/scripts/storage/lvm.py +++ b/commands/storage/lmi/scripts/storage/lvm.py @@ -101,7 +101,10 @@ def create_lv(ns, vg, name, size): values = service.CreateOrModifyLV.CreateOrModifyLVValues raise LmiFailed("Cannot create the logical volume: %s." % (values.value_name(ret),)) - return outparams['TheElement'] + + lv = outparams['TheElement'].to_instance() + LOG().info("Created logical volume %s", lv.Name) + return lv def create_tlv(ns, tp, name, size): tp = common.str2vg(ns, tp) @@ -112,7 +115,10 @@ def create_tlv(ns, tp, name, size): (ret, outparams, err) = service.SyncCreateOrModifyThinLV(**args) if ret != 0: raise LmiFailed("Cannot create thin LV: %s." % (err if err else ret)) - return outparams['TheElement'] + + tlv = outparams['TheElement'].to_instance() + LOG().info("Created thin logical volume %s", tlv.Name) + return tlv def delete_lv(ns, lv): """ @@ -130,6 +136,8 @@ def delete_lv(ns, lv): raise LmiFailed("Cannot delete the LV: %s." % (service.DeleteLV.DeleteLVValues.value_name(ret),)) + LOG().info("Deleted logical volume %s", lv.Name) + def get_vgs(ns): """ Retrieve list of all volume groups on the system. @@ -195,7 +203,9 @@ def create_vg(ns, devices, name, extent_size=None): if goal: goal.delete() - return outparams['Pool'] + pool = outparams['Pool'].to_instance() + LOG().info("Created volume group %s", pool.Name) + return pool def create_tp(ns, name, vg, size): vg = common.str2vg(ns, vg) @@ -206,7 +216,10 @@ def create_tp(ns, name, vg, size): (ret, outparams, err) = service.SyncCreateOrModifyThinPool(**args) if ret != 0: raise LmiFailed("Cannot create thin pool: %s." % (err if err else ret)) - return outparams['Pool'] + + pool = outparams['Pool'].to_instance() + LOG().info("Created thin volume group %s", pool.Name) + return pool def delete_vg(ns, vg): """ @@ -223,6 +236,7 @@ def delete_vg(ns, vg): raise LmiFailed("Cannot delete the VG: %s." % err) raise LmiFailed("Cannot delete the VG: %s." % (service.DeleteVG.DeleteVGValues.value_name(ret),)) + LOG().info("Deleted volume group %s", vg.Name) def get_vg_lvs(ns, vg): """ diff --git a/commands/storage/lmi/scripts/storage/partition.py b/commands/storage/lmi/scripts/storage/partition.py index 0a7d368..63c5403 100644 --- a/commands/storage/lmi/scripts/storage/partition.py +++ b/commands/storage/lmi/scripts/storage/partition.py @@ -172,7 +172,10 @@ def create_partition(ns, device, size=None, partition_type=None): finally: if setting: setting.delete() - return outparams['Partition'] + + part = outparams['Partition'].to_instance() + LOG().info("Created partition %s", part.Name) + return part def delete_partition(ns, partition): @@ -193,6 +196,8 @@ def delete_partition(ns, partition): raise LmiFailed("Cannot delete the partition: %s." % (values.value_name(ret))) + LOG().info("Deleted partition %s", partition.Name) + def create_partition_table(ns, device, table_type): """ Create new partition table on a device. The device must be empty, i.e. @@ -223,6 +228,8 @@ def create_partition_table(ns, device, table_type): raise LmiFailed("Cannot create partition table: %s." % (values.value_name(ret))) + LOG().info("Created partition table on %s", device.Name) + def get_partition_tables(ns, devices=None): """ diff --git a/commands/storage/lmi/scripts/storage/raid.py b/commands/storage/lmi/scripts/storage/raid.py index 269aa7e..1718d2c 100644 --- a/commands/storage/lmi/scripts/storage/raid.py +++ b/commands/storage/lmi/scripts/storage/raid.py @@ -73,7 +73,10 @@ def create_raid(ns, devices, level, name=None): values = service.CreateOrModifyMDRAID.CreateOrModifyMDRAIDValues raise LmiFailed("Cannot create the MD RAID: %s." % (values.value_name(ret),)) - return outparams['TheElement'] + + raid = outparams['TheElement'].to_instance() + LOG().info("Created MD RAID %s", raid.Name) + return raid def delete_raid(ns, raid): @@ -91,6 +94,7 @@ def delete_raid(ns, raid): raise LmiFailed("Cannot delete the MD RAID: %s." % err) raise LmiFailed("Cannot delete the raid: %s." % (service.DeleteMDRAID.DeleteMDRAIDValues.value_name(ret),)) + LOG().info("Deleted MD RAID %s", raid.Name) def get_raid_members(ns, raid): """ -- cgit