Revision 5eacbcae lib/cmdlib/instance_operation.py

b/lib/cmdlib/instance_operation.py
36 36
from ganeti import utils
37 37
from ganeti.cmdlib.base import LogicalUnit, NoHooksLU
38 38
from ganeti.cmdlib.common import INSTANCE_ONLINE, INSTANCE_DOWN, \
39
  _CheckHVParams, _CheckInstanceState, _CheckNodeOnline, _ExpandNodeName, \
40
  _GetUpdatedParams, _CheckOSParams, _ShareAll
41
from ganeti.cmdlib.instance_storage import _StartInstanceDisks, \
42
  _ShutdownInstanceDisks
43
from ganeti.cmdlib.instance_utils import _BuildInstanceHookEnvByObject, \
44
  _CheckInstanceBridgesExist, _CheckNodeFreeMemory, _CheckNodeHasOS
39
  CheckHVParams, CheckInstanceState, CheckNodeOnline, ExpandNodeName, \
40
  GetUpdatedParams, CheckOSParams, ShareAll
41
from ganeti.cmdlib.instance_storage import StartInstanceDisks, \
42
  ShutdownInstanceDisks
43
from ganeti.cmdlib.instance_utils import BuildInstanceHookEnvByObject, \
44
  CheckInstanceBridgesExist, CheckNodeFreeMemory, CheckNodeHasOS
45 45

  
46 46

  
47 47
class LUInstanceStartup(LogicalUnit):
......
77 77
      "FORCE": self.op.force,
78 78
      }
79 79

  
80
    env.update(_BuildInstanceHookEnvByObject(self, self.instance))
80
    env.update(BuildInstanceHookEnvByObject(self, self.instance))
81 81

  
82 82
    return env
83 83

  
......
107 107
      filled_hvp.update(self.op.hvparams)
108 108
      hv_type = hypervisor.GetHypervisorClass(instance.hypervisor)
109 109
      hv_type.CheckParameterSyntax(filled_hvp)
110
      _CheckHVParams(self, instance.all_nodes, instance.hypervisor, filled_hvp)
110
      CheckHVParams(self, instance.all_nodes, instance.hypervisor, filled_hvp)
111 111

  
112
    _CheckInstanceState(self, instance, INSTANCE_ONLINE)
112
    CheckInstanceState(self, instance, INSTANCE_ONLINE)
113 113

  
114 114
    self.primary_offline = self.cfg.GetNodeInfo(instance.primary_node).offline
115 115

  
......
119 119
      if self.op.hvparams or self.op.beparams:
120 120
        self.LogWarning("Overridden parameters are ignored")
121 121
    else:
122
      _CheckNodeOnline(self, instance.primary_node)
122
      CheckNodeOnline(self, instance.primary_node)
123 123

  
124 124
      bep = self.cfg.GetClusterInfo().FillBE(instance)
125 125
      bep.update(self.op.beparams)
126 126

  
127 127
      # check bridges existence
128
      _CheckInstanceBridgesExist(self, instance)
128
      CheckInstanceBridgesExist(self, instance)
129 129

  
130 130
      remote_info = self.rpc.call_instance_info(instance.primary_node,
131 131
                                                instance.name,
......
133 133
      remote_info.Raise("Error checking node %s" % instance.primary_node,
134 134
                        prereq=True, ecode=errors.ECODE_ENVIRON)
135 135
      if not remote_info.payload: # not running already
136
        _CheckNodeFreeMemory(self, instance.primary_node,
137
                             "starting instance %s" % instance.name,
138
                             bep[constants.BE_MINMEM], instance.hypervisor)
136
        CheckNodeFreeMemory(self, instance.primary_node,
137
                            "starting instance %s" % instance.name,
138
                            bep[constants.BE_MINMEM], instance.hypervisor)
139 139

  
140 140
  def Exec(self, feedback_fn):
141 141
    """Start the instance.
......
154 154
    else:
155 155
      node_current = instance.primary_node
156 156

  
157
      _StartInstanceDisks(self, instance, force)
157
      StartInstanceDisks(self, instance, force)
158 158

  
159 159
      result = \
160 160
        self.rpc.call_instance_start(node_current,
......
163 163
                                     self.op.startup_paused, reason)
164 164
      msg = result.fail_msg
165 165
      if msg:
166
        _ShutdownInstanceDisks(self, instance)
166
        ShutdownInstanceDisks(self, instance)
167 167
        raise errors.OpExecError("Could not start instance: %s" % msg)
168 168

  
169 169

  
......
184 184
    This runs on master, primary and secondary nodes of the instance.
185 185

  
186 186
    """
187
    env = _BuildInstanceHookEnvByObject(self, self.instance)
187
    env = BuildInstanceHookEnvByObject(self, self.instance)
188 188
    env["TIMEOUT"] = self.op.timeout
189 189
    return env
190 190

  
......
206 206
      "Cannot retrieve locked instance %s" % self.op.instance_name
207 207

  
208 208
    if not self.op.force:
209
      _CheckInstanceState(self, self.instance, INSTANCE_ONLINE)
209
      CheckInstanceState(self, self.instance, INSTANCE_ONLINE)
210 210
    else:
211 211
      self.LogWarning("Ignoring offline instance check")
212 212

  
......
216 216
    if self.primary_offline and self.op.ignore_offline_nodes:
217 217
      self.LogWarning("Ignoring offline primary node")
218 218
    else:
219
      _CheckNodeOnline(self, self.instance.primary_node)
219
      CheckNodeOnline(self, self.instance.primary_node)
220 220

  
221 221
  def Exec(self, feedback_fn):
222 222
    """Shutdown the instance.
......
242 242
      if msg:
243 243
        self.LogWarning("Could not shutdown instance: %s", msg)
244 244

  
245
      _ShutdownInstanceDisks(self, instance)
245
      ShutdownInstanceDisks(self, instance)
246 246

  
247 247

  
248 248
class LUInstanceReinstall(LogicalUnit):
......
262 262
    This runs on master, primary and secondary nodes of the instance.
263 263

  
264 264
    """
265
    return _BuildInstanceHookEnvByObject(self, self.instance)
265
    return BuildInstanceHookEnvByObject(self, self.instance)
266 266

  
267 267
  def BuildHooksNodes(self):
268 268
    """Build hooks nodes.
......
280 280
    instance = self.cfg.GetInstanceInfo(self.op.instance_name)
281 281
    assert instance is not None, \
282 282
      "Cannot retrieve locked instance %s" % self.op.instance_name
283
    _CheckNodeOnline(self, instance.primary_node, "Instance primary node"
284
                     " offline, cannot reinstall")
283
    CheckNodeOnline(self, instance.primary_node, "Instance primary node"
284
                    " offline, cannot reinstall")
285 285

  
286 286
    if instance.disk_template == constants.DT_DISKLESS:
287 287
      raise errors.OpPrereqError("Instance '%s' has no disks" %
288 288
                                 self.op.instance_name,
289 289
                                 errors.ECODE_INVAL)
290
    _CheckInstanceState(self, instance, INSTANCE_DOWN, msg="cannot reinstall")
290
    CheckInstanceState(self, instance, INSTANCE_DOWN, msg="cannot reinstall")
291 291

  
292 292
    if self.op.os_type is not None:
293 293
      # OS verification
294
      pnode = _ExpandNodeName(self.cfg, instance.primary_node)
295
      _CheckNodeHasOS(self, pnode, self.op.os_type, self.op.force_variant)
294
      pnode = ExpandNodeName(self.cfg, instance.primary_node)
295
      CheckNodeHasOS(self, pnode, self.op.os_type, self.op.force_variant)
296 296
      instance_os = self.op.os_type
297 297
    else:
298 298
      instance_os = instance.os
......
300 300
    nodelist = list(instance.all_nodes)
301 301

  
302 302
    if self.op.osparams:
303
      i_osdict = _GetUpdatedParams(instance.osparams, self.op.osparams)
304
      _CheckOSParams(self, True, nodelist, instance_os, i_osdict)
303
      i_osdict = GetUpdatedParams(instance.osparams, self.op.osparams)
304
      CheckOSParams(self, True, nodelist, instance_os, i_osdict)
305 305
      self.os_inst = i_osdict # the new dict (without defaults)
306 306
    else:
307 307
      self.os_inst = None
......
320 320
      # Write to configuration
321 321
      self.cfg.Update(inst, feedback_fn)
322 322

  
323
    _StartInstanceDisks(self, inst, None)
323
    StartInstanceDisks(self, inst, None)
324 324
    try:
325 325
      feedback_fn("Running the instance OS create scripts...")
326 326
      # FIXME: pass debug option from opcode to backend
......
330 330
      result.Raise("Could not install OS for instance %s on node %s" %
331 331
                   (inst.name, inst.primary_node))
332 332
    finally:
333
      _ShutdownInstanceDisks(self, inst)
333
      ShutdownInstanceDisks(self, inst)
334 334

  
335 335

  
336 336
class LUInstanceReboot(LogicalUnit):
......
356 356
      "SHUTDOWN_TIMEOUT": self.op.shutdown_timeout,
357 357
      }
358 358

  
359
    env.update(_BuildInstanceHookEnvByObject(self, self.instance))
359
    env.update(BuildInstanceHookEnvByObject(self, self.instance))
360 360

  
361 361
    return env
362 362

  
......
376 376
    self.instance = instance = self.cfg.GetInstanceInfo(self.op.instance_name)
377 377
    assert self.instance is not None, \
378 378
      "Cannot retrieve locked instance %s" % self.op.instance_name
379
    _CheckInstanceState(self, instance, INSTANCE_ONLINE)
380
    _CheckNodeOnline(self, instance.primary_node)
379
    CheckInstanceState(self, instance, INSTANCE_ONLINE)
380
    CheckNodeOnline(self, instance.primary_node)
381 381

  
382 382
    # check bridges existence
383
    _CheckInstanceBridgesExist(self, instance)
383
    CheckInstanceBridgesExist(self, instance)
384 384

  
385 385
  def Exec(self, feedback_fn):
386 386
    """Reboot the instance.
......
413 413
                                                 self.op.shutdown_timeout,
414 414
                                                 reason)
415 415
        result.Raise("Could not shutdown instance for full reboot")
416
        _ShutdownInstanceDisks(self, instance)
416
        ShutdownInstanceDisks(self, instance)
417 417
      else:
418 418
        self.LogInfo("Instance %s was already stopped, starting now",
419 419
                     instance.name)
420
      _StartInstanceDisks(self, instance, ignore_secondaries)
420
      StartInstanceDisks(self, instance, ignore_secondaries)
421 421
      result = self.rpc.call_instance_start(node_current,
422 422
                                            (instance, None, None), False,
423 423
                                            reason)
424 424
      msg = result.fail_msg
425 425
      if msg:
426
        _ShutdownInstanceDisks(self, instance)
426
        ShutdownInstanceDisks(self, instance)
427 427
        raise errors.OpExecError("Could not start instance for"
428 428
                                 " full reboot: %s" % msg)
429 429

  
430 430
    self.cfg.MarkInstanceUp(instance.name)
431 431

  
432 432

  
433
def _GetInstanceConsole(cluster, instance):
433
def GetInstanceConsole(cluster, instance):
434 434
  """Returns console information for an instance.
435 435

  
436 436
  @type cluster: L{objects.Cluster}
......
462 462
  REQ_BGL = False
463 463

  
464 464
  def ExpandNames(self):
465
    self.share_locks = _ShareAll()
465
    self.share_locks = ShareAll()
466 466
    self._ExpandAndLockInstance()
467 467

  
468 468
  def CheckPrereq(self):
......
474 474
    self.instance = self.cfg.GetInstanceInfo(self.op.instance_name)
475 475
    assert self.instance is not None, \
476 476
      "Cannot retrieve locked instance %s" % self.op.instance_name
477
    _CheckNodeOnline(self, self.instance.primary_node)
477
    CheckNodeOnline(self, self.instance.primary_node)
478 478

  
479 479
  def Exec(self, feedback_fn):
480 480
    """Connect to the console of an instance
......
499 499

  
500 500
    logging.debug("Connecting to console of %s on %s", instance.name, node)
501 501

  
502
    return _GetInstanceConsole(self.cfg.GetClusterInfo(), instance)
502
    return GetInstanceConsole(self.cfg.GetClusterInfo(), instance)

Also available in: Unified diff