From 86f5eae3a0a27eb87229e9e25c8781116d096224 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 14 Aug 2009 17:27:38 +0200 Subject: [PATCH] gnt-node: Use helper function to convert storage type Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- scripts/gnt-node | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/gnt-node b/scripts/gnt-node index cf2419068..1908c40a3 100755 --- a/scripts/gnt-node +++ b/scripts/gnt-node @@ -67,6 +67,16 @@ _USER_STORAGE_TYPE = { } +def ConvertStorageType(user_storage_type): + """Converts a user storage type to its internal name. + + """ + try: + return _USER_STORAGE_TYPE[user_storage_type] + except KeyError: + raise errors.OpPrereqError("Unknown storage type: %s" % user_storage_type) + + @UsesRPC def AddNode(opts, args): """Add a node to the cluster. @@ -448,10 +458,7 @@ def ListPhysicalVolumes(opts, args): if opts.user_storage_type is None: opts.user_storage_type = constants.ST_LVM_PV - try: - storage_type = _USER_STORAGE_TYPE[opts.user_storage_type] - except KeyError: - raise errors.OpPrereqError("Unknown storage type: %s" % user_storage_type) + storage_type = ConvertStorageType(opts.user_storage_type) default_fields = { constants.ST_FILE: [ @@ -519,10 +526,7 @@ def ModifyVolume(opts, args): """ (node_name, user_storage_type, volume_name) = args - try: - storage_type = _USER_STORAGE_TYPE[user_storage_type] - except KeyError: - raise errors.OpPrereqError("Unknown storage type: %s" % user_storage_type) + storage_type = ConvertStorageType(user_storage_type) changes = {} -- GitLab