Revision 2c0af7da

b/doc/hooks.rst
304 304
Modifies the instance parameters.
305 305

  
306 306
:directory: instance-modify
307
:env. vars: NEW_DISK_TEMPLATE
307
:env. vars: NEW_DISK_TEMPLATE, RUNTIME_MEMORY
308 308
:pre-execution: master node, primary and secondary nodes
309 309
:post-execution: master node, primary and secondary nodes
310 310

  
b/lib/cli.py
158 158
  "REMOVE_INSTANCE_OPT",
159 159
  "REMOVE_UIDS_OPT",
160 160
  "RESERVED_LVS_OPT",
161
  "RUNTIME_MEM_OPT",
161 162
  "ROMAN_OPT",
162 163
  "SECONDARY_IP_OPT",
163 164
  "SECONDARY_ONLY_OPT",
......
1361 1362
                                action="store_true", default=False,
1362 1363
                                help="Ignore instance policy violations")
1363 1364

  
1365
RUNTIME_MEM_OPT = cli_option("-m", "--runtime-memory", dest="runtime_mem",
1366
                             help="Sets the instance's runtime memory,"
1367
                             " ballooning it up or down to the new value",
1368
                             default=None, type="unit", metavar="<size>")
1364 1369

  
1365 1370
#: Options provided by all commands
1366 1371
COMMON_OPTS = [DEBUG_OPT]
b/lib/client/gnt_instance.py
1264 1264
  """
1265 1265
  if not (opts.nics or opts.disks or opts.disk_template or
1266 1266
          opts.hvparams or opts.beparams or opts.os or opts.osparams or
1267
          opts.offline_inst or opts.online_inst):
1267
          opts.offline_inst or opts.online_inst or opts.runtime_mem):
1268 1268
    ToStderr("Please give at least one of the parameters.")
1269 1269
    return 1
1270 1270

  
......
1317 1317
                                   remote_node=opts.node,
1318 1318
                                   hvparams=opts.hvparams,
1319 1319
                                   beparams=opts.beparams,
1320
                                   runtime_mem=opts.runtime_mem,
1320 1321
                                   os_name=opts.os,
1321 1322
                                   osparams=opts.osparams,
1322 1323
                                   force_variant=opts.force_variant,
......
1510 1511
    [BACKEND_OPT, DISK_OPT, FORCE_OPT, HVOPTS_OPT, NET_OPT, SUBMIT_OPT,
1511 1512
     DISK_TEMPLATE_OPT, SINGLE_NODE_OPT, OS_OPT, FORCE_VARIANT_OPT,
1512 1513
     OSPARAMS_OPT, DRY_RUN_OPT, PRIORITY_OPT, NWSYNC_OPT, OFFLINE_INST_OPT,
1513
     ONLINE_INST_OPT, IGNORE_IPOLICY_OPT],
1514
     ONLINE_INST_OPT, IGNORE_IPOLICY_OPT, RUNTIME_MEM_OPT],
1514 1515
    "<instance>", "Alters the parameters of an instance"),
1515 1516
  "shutdown": (
1516 1517
    GenericManyOps("shutdown", _ShutdownInstance), [ArgInstance()],
b/lib/cmdlib.py
11587 11587
  def CheckArguments(self):
11588 11588
    if not (self.op.nics or self.op.disks or self.op.disk_template or
11589 11589
            self.op.hvparams or self.op.beparams or self.op.os_name or
11590
            self.op.online_inst or self.op.offline_inst):
11590
            self.op.online_inst or self.op.offline_inst or
11591
            self.op.runtime_mem):
11591 11592
      raise errors.OpPrereqError("No changes submitted", errors.ECODE_INVAL)
11592 11593

  
11593 11594
    if self.op.hvparams:
......
11771 11772
    env = _BuildInstanceHookEnvByObject(self, self.instance, override=args)
11772 11773
    if self.op.disk_template:
11773 11774
      env["NEW_DISK_TEMPLATE"] = self.op.disk_template
11775
    if self.op.runtime_mem:
11776
      env["RUNTIME_MEMORY"] = self.op.runtime_mem
11774 11777

  
11775 11778
    return env
11776 11779

  
......
11975 11978
                                       " %s, due to not enough memory" % node,
11976 11979
                                       errors.ECODE_STATE)
11977 11980

  
11981
    if self.op.runtime_mem:
11982
      remote_info = self.rpc.call_instance_info(instance.primary_node,
11983
                                                instance.name,
11984
                                                instance.hypervisor)
11985
      remote_info.Raise("Error checking node %s" % instance.primary_node)
11986
      if not remote_info.payload: # not running already
11987
        raise errors.OpPrereqError("Instance %s is not running" % instance.name,
11988
                                   errors.ECODE_STATE)
11989

  
11990
      current_memory = remote_info.payload["memory"]
11991
      if (not self.op.force and
11992
           (self.op.runtime_mem > self.be_proposed[constants.BE_MAXMEM] or
11993
            self.op.runtime_mem < self.be_proposed[constants.BE_MINMEM])):
11994
        raise errors.OpPrereqError("Instance %s must have memory between %d"
11995
                                   " and %d MB of memory unless --force is"
11996
                                   " given" % (instance.name,
11997
                                    self.be_proposed[constants.BE_MINMEM],
11998
                                    self.be_proposed[constants.BE_MAXMEM]),
11999
                                   errors.ECODE_INVAL)
12000

  
12001
      if self.op.runtime_mem > current_memory:
12002
        _CheckNodeFreeMemory(self, instance.primary_node,
12003
                             "ballooning memory for instance %s" %
12004
                             instance.name,
12005
                             self.op.memory - current_memory,
12006
                             instance.hypervisor)
12007

  
11978 12008
    # NIC processing
11979 12009
    self.nic_pnew = {}
11980 12010
    self.nic_pinst = {}
......
12218 12248

  
12219 12249
    result = []
12220 12250
    instance = self.instance
12251

  
12252
    # runtime memory
12253
    if self.op.runtime_mem:
12254
      rpcres = self.rpc.call_instance_balloon_memory(instance.primary_node,
12255
                                                     instance,
12256
                                                     self.op.runtime_mem)
12257
      rpcres.Raise("Cannot modify instance runtime memory")
12258
      result.append(("runtime_memory", self.op.runtime_mem))
12259

  
12221 12260
    # disk changes
12222 12261
    for disk_op, disk_dict in self.op.disks:
12223 12262
      if disk_op == constants.DDM_REMOVE:
b/lib/ht.py
322 322
TPositiveInt = \
323 323
  TAnd(TInt, WithDesc("EqualGreaterZero")(lambda v: v >= 0))
324 324

  
325
#: a maybe positive integer (positive integer or None)
326
TMaybePositiveInt = TOr(TPositiveInt, TNone)
327

  
325 328
#: a strictly positive integer
326 329
TStrictPositiveInt = \
327 330
  TAnd(TInt, WithDesc("GreaterThanZero")(lambda v: v > 0))
328 331

  
332
#: a maybe strictly positive integer (strictly positive integer or None)
333
TMaybeStrictPositiveInt = TOr(TStrictPositiveInt, TNone)
334

  
329 335
#: a strictly negative integer (0 > value)
330 336
TStrictNegativeInt = \
331 337
  TAnd(TInt, WithDesc("LessThanZero")(compat.partial(operator.gt, 0)))
b/lib/opcodes.py
1372 1372
     (constants.DDM_ADD, constants.DDM_REMOVE)),
1373 1373
    ("disks", ht.EmptyList, ht.TList, "List of disk changes. See ``nics``."),
1374 1374
    ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
1375
    ("runtime_mem", None, ht.TMaybeStrictPositiveInt, "New runtime memory"),
1375 1376
    ("hvparams", ht.EmptyDict, ht.TDict,
1376 1377
     "Per-instance hypervisor parameters, hypervisor-dependent"),
1377 1378
    ("disk_template", None, ht.TOr(ht.TNone, _BuildDiskTemplateCheck(False)),
b/man/gnt-instance.rst
857 857
| **modify**
858 858
| [{-H|--hypervisor-parameters} *HYPERVISOR\_PARAMETERS*]
859 859
| [{-B|--backend-parameters} *BACKEND\_PARAMETERS*]
860
| [{-m|--runtime-memory} *SIZE*]
860 861
| [--net add*[:options]* \| --net remove \| --net *N:options*]
861 862
| [--disk add:size=*SIZE*[,vg=*VG*][,metavg=*VG*] \| --disk remove \|
862 863
|  --disk *N*:mode=*MODE*]
......
887 888
to the ``drbd`` template in order to make the instance available for
888 889
startup before DRBD has finished resyncing.
889 890

  
891
The ``-m (--runtime-memory)`` option will change an instance's runtime
892
memory to the given size (in MB if a different suffix is not specified),
893
by ballooning it up or down to the new value.
894

  
890 895
The ``--disk add:size=``*SIZE* option adds a disk to the instance. The
891 896
optional ``vg=``*VG* option specifies LVM volume group other than
892 897
default vg to create the disk on. For DRBD disks, the ``metavg=``*VG*

Also available in: Unified diff