Revision 810c50b7

b/lib/cli.py
41 41
           "cli_option", "GenerateTable", "AskUser",
42 42
           "ARGS_NONE", "ARGS_FIXED", "ARGS_ATLEAST", "ARGS_ANY", "ARGS_ONE",
43 43
           "USEUNITS_OPT", "FIELDS_OPT", "FORCE_OPT",
44
           "ListTags", "AddTags", "RemoveTags",
44
           "ListTags", "AddTags", "RemoveTags", "TAG_SRC_OPT",
45 45
           ]
46 46

  
47 47

  
......
66 66
  return retval
67 67

  
68 68

  
69
def _ExtendTags(opts, args):
70
  """Extend the args if a source file has been given.
71

  
72
  This function will extend the tags with the contents of the file
73
  passed in the 'tags_source' attribute of the opts parameter. A file
74
  named '-' will be replaced by stdin.
75

  
76
  """
77
  fname = opts.tags_source
78
  if fname is None:
79
    return
80
  if fname == "-":
81
    new_fh = sys.stdin
82
  else:
83
    new_fh = open(fname, "r")
84
  new_data = []
85
  try:
86
    # we don't use the nice 'new_data = [line.strip() for line in fh]'
87
    # because of python bug 1633941
88
    while True:
89
      line = new_fh.readline()
90
      if not line:
91
        break
92
      new_data.append(line.strip())
93
  finally:
94
    new_fh.close()
95
  args.extend(new_data)
96

  
97

  
69 98
def ListTags(opts, args):
70 99
  """List the tags on a given object.
71 100

  
......
94 123

  
95 124
  """
96 125
  kind, name = _ExtractTagsObject(opts, args)
126
  _ExtendTags(opts, args)
97 127
  if not args:
98 128
    raise errors.OpPrereqError("No tags to be added")
99 129
  op = opcodes.OpAddTags(kind=kind, name=name, tags=args)
......
110 140

  
111 141
  """
112 142
  kind, name = _ExtractTagsObject(opts, args)
143
  _ExtendTags(opts, args)
113 144
  if not args:
114 145
    raise errors.OpPrereqError("No tags to be removed")
115 146
  op = opcodes.OpDelTags(kind=kind, name=name, tags=args)
......
143 174
_LOCK_OPT = make_option("--lock-retries", default=None,
144 175
                        type="int", help=SUPPRESS_HELP)
145 176

  
177
TAG_SRC_OPT = make_option("--from", dest="tags_source",
178
                          default=None, help="File with tag names")
179

  
146 180
def ARGS_FIXED(val):
147 181
  """Macro-like function denoting a fixed number of arguments"""
148 182
  return -val
b/man/gnt-cluster.sgml
60 60

  
61 61
      <cmdsynopsis>
62 62
        <command>add-tags</command>
63
        <arg choice="opt">--from <replaceable>file</replaceable></arg>
63 64
        <arg choice="req"
64 65
        rep="repeat"><replaceable>tag</replaceable></arg>
65 66
      </cmdsynopsis>
......
68 69
        Add tags to the cluster. If any of the tags contains invalid
69 70
        characters, the entire operation will abort.
70 71
      </para>
72

  
73
      <para>
74
        If the <option>--from</option> option is given, the list of
75
        tags will be extended with the contents of that file (each
76
        line becomes a tag). In this case, there is not need to pass
77
        tags on the command line (if you do, both sources will be
78
        used). A file name of - will be interpreted as stdin.
79
      </para>
71 80
    </refsect2>
72 81

  
73 82
    <refsect2>
......
250 259

  
251 260
      <cmdsynopsis>
252 261
        <command>remove-tags</command>
262
        <arg choice="opt">--from <replaceable>file</replaceable></arg>
253 263
        <arg choice="req"
254 264
        rep="repeat"><replaceable>tag</replaceable></arg>
255 265
      </cmdsynopsis>
......
258 268
        Remove tags from the cluster. If any of the tags are not
259 269
        existing on the cluster, the entire operation will abort.
260 270
      </para>
271

  
272
      <para>
273
        If the <option>--from</option> option is given, the list of
274
        tags will be extended with the contents of that file (each
275
        line becomes a tag). In this case, there is not need to pass
276
        tags on the command line (if you do, both sources will be
277
        used). A file name of - will be interpreted as stdin.
278
      </para>
261 279
    </refsect2>
262 280

  
263 281
    <refsect2>
b/man/gnt-instance.sgml
758 758

  
759 759
        <cmdsynopsis>
760 760
          <command>add-tags</command>
761
          <arg choice="opt">--from <replaceable>file</replaceable></arg>
761 762
          <arg choice="req"><replaceable>instancename</replaceable></arg>
762 763
          <arg choice="req"
763 764
            rep="repeat"><replaceable>tag</replaceable></arg>
......
767 768
          Add tags to the given instance. If any of the tags contains
768 769
          invalid characters, the entire operation will abort.
769 770
        </para>
771
        <para>
772
          If the <option>--from</option> option is given, the list of
773
          tags will be extended with the contents of that file (each
774
          line becomes a tag). In this case, there is not need to pass
775
          tags on the command line (if you do, both sources will be
776
          used). A file name of - will be interpreted as stdin.
777
        </para>
770 778
      </refsect3>
771 779

  
772 780
      <refsect3>
......
784 792
        <title>REMOVE-TAGS</title>
785 793
        <cmdsynopsis>
786 794
          <command>remove-tags</command>
795
          <arg choice="opt">--from <replaceable>file</replaceable></arg>
787 796
          <arg choice="req"><replaceable>instancename</replaceable></arg>
788 797
          <arg choice="req"
789 798
            rep="repeat"><replaceable>tag</replaceable></arg>
......
793 802
          Remove tags from the given instance. If any of the tags are
794 803
          not existing on the node, the entire operation will abort.
795 804
        </para>
805

  
806
        <para>
807
          If the <option>--from</option> option is given, the list of
808
          tags will be extended with the contents of that file (each
809
          line becomes a tag). In this case, there is not need to pass
810
          tags on the command line (if you do, both sources will be
811
          used). A file name of - will be interpreted as stdin.
812
        </para>
796 813
      </refsect3>
797 814

  
798 815
    </refsect2>
b/man/gnt-node.sgml
105 105

  
106 106
      <cmdsynopsis>
107 107
        <command>add-tags</command>
108
        <arg choice="opt">--from <replaceable>file</replaceable></arg>
108 109
        <arg choice="req"><replaceable>nodename</replaceable></arg>
109 110
        <arg choice="req"
110 111
        rep="repeat"><replaceable>tag</replaceable></arg>
......
114 115
        Add tags to the given node. If any of the tags contains
115 116
        invalid characters, the entire operation will abort.
116 117
      </para>
118

  
119
      <para>
120
        If the <option>--from</option> option is given, the list of
121
        tags will be extended with the contents of that file (each
122
        line becomes a tag). In this case, there is not need to pass
123
        tags on the command line (if you do, both sources will be
124
        used). A file name of - will be interpreted as stdin.
125
      </para>
117 126
    </refsect2>
118 127

  
119 128
    <refsect2>
......
292 301
      <title>REMOVE-TAGS</title>
293 302
      <cmdsynopsis>
294 303
        <command>remove-tags</command>
304
        <arg choice="opt">--from <replaceable>file</replaceable></arg>
295 305
        <arg choice="req"><replaceable>nodename</replaceable></arg>
296 306
        <arg choice="req"
297 307
        rep="repeat"><replaceable>tag</replaceable></arg>
......
301 311
        Remove tags from the given node. If any of the tags are not
302 312
        existing on the node, the entire operation will abort.
303 313
      </para>
314

  
315
      <para>
316
        If the <option>--from</option> option is given, the list of
317
        tags will be extended with the contents of that file (each
318
        line becomes a tag). In this case, there is not need to pass
319
        tags on the command line (if you do, both sources will be
320
        used). A file name of - will be interpreted as stdin.
321
      </para>
304 322
    </refsect2>
305 323

  
306 324
    <refsect2>
b/scripts/gnt-cluster
265 265
                 "", "Show cluster configuration"),
266 266
  'list-tags': (ListTags, ARGS_NONE,
267 267
                [DEBUG_OPT], "", "List the tags of the cluster"),
268
  'add-tags': (AddTags, ARGS_ANY, [DEBUG_OPT],
268
  'add-tags': (AddTags, ARGS_ANY, [DEBUG_OPT, TAG_SRC_OPT],
269 269
               "tag...", "Add tags to the cluster"),
270
  'remove-tags': (RemoveTags, ARGS_ANY, [DEBUG_OPT],
270
  'remove-tags': (RemoveTags, ARGS_ANY, [DEBUG_OPT, TAG_SRC_OPT],
271 271
                  "tag...", "Remove tags from the cluster"),
272 272
  }
273 273

  
b/scripts/gnt-instance
756 756
                       "Deactivate an instance's disks"),
757 757
  'list-tags': (ListTags, ARGS_ONE, [DEBUG_OPT],
758 758
                "<node_name>", "List the tags of the given instance"),
759
  'add-tags': (AddTags, ARGS_ATLEAST(1), [DEBUG_OPT],
759
  'add-tags': (AddTags, ARGS_ATLEAST(1), [DEBUG_OPT, TAG_SRC_OPT],
760 760
               "<node_name> tag...", "Add tags to the given instance"),
761
  'remove-tags': (RemoveTags, ARGS_ATLEAST(1), [DEBUG_OPT],
761
  'remove-tags': (RemoveTags, ARGS_ATLEAST(1), [DEBUG_OPT, TAG_SRC_OPT],
762 762
                  "<node_name> tag...", "Remove tags from given instance"),
763 763
  }
764 764

  
b/scripts/gnt-node
183 183
              "[<node_name>...]", "List logical volumes on node(s)"),
184 184
  'list-tags': (ListTags, ARGS_ONE, [DEBUG_OPT],
185 185
                "<node_name>", "List the tags of the given node"),
186
  'add-tags': (AddTags, ARGS_ATLEAST(1), [DEBUG_OPT],
186
  'add-tags': (AddTags, ARGS_ATLEAST(1), [DEBUG_OPT, TAG_SRC_OPT],
187 187
               "<node_name> tag...", "Add tags to the given node"),
188
  'remove-tags': (RemoveTags, ARGS_ATLEAST(1), [DEBUG_OPT],
188
  'remove-tags': (RemoveTags, ARGS_ATLEAST(1), [DEBUG_OPT, TAG_SRC_OPT],
189 189
                  "<node_name> tag...", "Remove tags from the given node"),
190 190
  }
191 191

  

Also available in: Unified diff