Sorry, I sent this patch twice by mistake.

On Mon, Sep 9, 2013 at 4:29 PM, Jose A. Lopes <[email protected]> wrote:

> In "lib/cmdlib/node.py", in lines 1315-1316, 1354, and 1359-1370,
> replace string literals with constants.
>
> Signed-off-by: Jose A. Lopes <[email protected]>
> ---
>  lib/cmdlib/node.py | 31 ++++++++++++++++---------------
>  lib/constants.py   |  9 +++++++++
>  2 files changed, 25 insertions(+), 15 deletions(-)
>
> diff --git a/lib/cmdlib/node.py b/lib/cmdlib/node.py
> index 8fa1a9c..101ef05 100644
> --- a/lib/cmdlib/node.py
> +++ b/lib/cmdlib/node.py
> @@ -1312,8 +1312,9 @@ class LUNodeQueryvols(NoHooksLU):
>    REQ_BGL = False
>
>    def CheckArguments(self):
> -    _CheckOutputFields(utils.FieldSet("node", "phys", "vg", "name",
> "size",
> -                                      "instance"),
> +    _CheckOutputFields(utils.FieldSet(constants.VF_NODE,
> constants.VF_PHYS,
> +                                      constants.VF_VG, constants.VF_NAME,
> +                                      constants.VF_SIZE,
> constants.VF_INSTANCE),
>                         self.op.output_fields)
>
>    def ExpandNames(self):
> @@ -1351,24 +1352,24 @@ class LUNodeQueryvols(NoHooksLU):
>          continue
>
>        node_vols = sorted(nresult.payload,
> -                         key=operator.itemgetter("dev"))
> +                         key=operator.itemgetter(constants.VF_DEV))
>
>        for vol in node_vols:
>          node_output = []
>          for field in self.op.output_fields:
> -          if field == "node":
> +          if field == constants.VF_NODE:
>              val = self.cfg.GetNodeName(node_uuid)
> -          elif field == "phys":
> -            val = vol["dev"]
> -          elif field == "vg":
> -            val = vol["vg"]
> -          elif field == "name":
> -            val = vol["name"]
> -          elif field == "size":
> -            val = int(float(vol["size"]))
> -          elif field == "instance":
> -            inst = vol2inst.get((node_uuid, vol["vg"] + "/" +
> vol["name"]),
> -                                None)
> +          elif field == constants.VF_PHYS:
> +            val = vol[constants.VF_DEV]
> +          elif field == constants.VF_VG:
> +            val = vol[constants.VF_VG]
> +          elif field == constants.VF_NAME:
> +            val = vol[constants.VF_NAME]
> +          elif field == constants.VF_SIZE:
> +            val = int(float(vol[constants.VF_SIZE]))
> +          elif field == constants.VF_INSTANCE:
> +            inst = vol2inst.get((node_uuid, vol[constants.VF_VG] + "/" +
> +                                 vol[constants.VF_NAME]), None)
>              if inst is not None:
>                val = inst.name
>              else:
> diff --git a/lib/constants.py b/lib/constants.py
> index 87bd753..f31a84a 100644
> --- a/lib/constants.py
> +++ b/lib/constants.py
> @@ -433,6 +433,15 @@ VALID_STORAGE_OPERATIONS = {
>    ST_LVM_VG: frozenset([SO_FIX_CONSISTENCY]),
>    }
>
> +# Volume fields
> +VF_DEV = "dev"
> +VF_INSTANCE = "instance"
> +VF_NAME = "name"
> +VF_NODE = "node"
> +VF_PHYS = "phys"
> +VF_SIZE = "size"
> +VF_VG = "vg"
> +
>  # Local disk status
>  # Note: Code depends on LDS_OKAY < LDS_UNKNOWN < LDS_FAULTY
>  (LDS_OKAY,
> --
> 1.8.4
>
>

Reply via email to