Revision fac489a5

b/lib/hypervisor/hv_base.py
229 229
    """
230 230
    raise NotImplementedError
231 231

  
232
  def GetNodeInfo(self):
232
  def GetNodeInfo(self, hvparams=None):
233 233
    """Return information about the node.
234 234

  
235
    @type hvparams: dict of strings
236
    @param hvparams: hypervisor parameters
237

  
235 238
    @return: a dict with the following keys (values in MiB):
236 239
          - memory_total: the total memory size on the node
237 240
          - memory_free: the available memory on the node for instances
b/lib/hypervisor/hv_chroot.py
246 246
    # Currently chroots don't have memory limits
247 247
    pass
248 248

  
249
  def GetNodeInfo(self):
249
  def GetNodeInfo(self, hvparams=None):
250 250
    """Return information about the node.
251 251

  
252 252
    This is just a wrapper over the base GetLinuxNodeInfo method.
253 253

  
254
    @type hvparams: dict of strings
255
    @param hvparams: hypervisor parameters, not used in this class
256

  
254 257
    @return: a dict with the following keys (values in MiB):
255 258
          - memory_total: the total memory size on the node
256 259
          - memory_free: the available memory on the node for instances
b/lib/hypervisor/hv_fake.py
205 205
      raise errors.HypervisorError("Failed to balloon memory for %s: %s" %
206 206
                                   (instance.name, utils.ErrnoOrStr(err)))
207 207

  
208
  def GetNodeInfo(self):
208
  def GetNodeInfo(self, hvparams=None):
209 209
    """Return information about the node.
210 210

  
211 211
    This is just a wrapper over the base GetLinuxNodeInfo method.
212 212

  
213
    @type hvparams: dict of strings
214
    @param hvparams: hypervisor parameters, not used in this class
215

  
213 216
    @return: a dict with the following keys (values in MiB):
214 217
          - memory_total: the total memory size on the node
215 218
          - memory_free: the available memory on the node for instances
b/lib/hypervisor/hv_kvm.py
1987 1987
    """
1988 1988
    self._CallMonitorCommand(instance.name, "balloon %d" % mem)
1989 1989

  
1990
  def GetNodeInfo(self):
1990
  def GetNodeInfo(self, hvparams=None):
1991 1991
    """Return information about the node.
1992 1992

  
1993
    @type hvparams: dict of strings
1994
    @param hvparams: hypervisor parameters, not used in this class
1995

  
1993 1996
    @return: a dict with the following keys (values in MiB):
1994 1997
          - memory_total: the total memory size on the node
1995 1998
          - memory_free: the available memory on the node for instances
b/lib/hypervisor/hv_lxc.py
393 393
    # Currently lxc instances don't have memory limits
394 394
    pass
395 395

  
396
  def GetNodeInfo(self):
396
  def GetNodeInfo(self, hvparams=None):
397 397
    """Return information about the node.
398 398

  
399 399
    This is just a wrapper over the base GetLinuxNodeInfo method.
400 400

  
401
    @type hvparams: dict of strings
402
    @param hvparams: hypervisor parameters, not used in this class
403

  
401 404
    @return: a dict with the following keys (values in MiB):
402 405
          - memory_total: the total memory size on the node
403 406
          - memory_free: the available memory on the node for instances
b/lib/hypervisor/hv_xen.py
225 225
  return result
226 226

  
227 227

  
228
def _MergeInstanceInfo(info, fn):
228
def _MergeInstanceInfo(info, instance_list):
229 229
  """Updates node information from L{_ParseNodeInfo} with instance info.
230 230

  
231 231
  @type info: dict
232 232
  @param info: Result from L{_ParseNodeInfo}
233
  @type fn: callable
234
  @param fn: Function retrieving the instance list
233
  @type instance_list: list of tuples
234
  @param instance_list: list of instance information; one tuple per instance
235 235
  @rtype: dict
236 236

  
237 237
  """
238 238
  total_instmem = 0
239 239

  
240
  for (name, _, mem, vcpus, _, _) in fn(True):
240
  for (name, _, mem, vcpus, _, _) in instance_list:
241 241
    if name == _DOM0_NAME:
242 242
      info["memory_dom0"] = mem
243 243
      info["dom0_cpus"] = vcpus
......
255 255
  return info
256 256

  
257 257

  
258
def _GetNodeInfo(info, fn):
258
def _GetNodeInfo(info, instance_list):
259 259
  """Combines L{_MergeInstanceInfo} and L{_ParseNodeInfo}.
260 260

  
261
  @type instance_list: list of tuples
262
  @param instance_list: list of instance information; one tuple per instance
263

  
261 264
  """
262
  return _MergeInstanceInfo(_ParseNodeInfo(info), fn)
265
  return _MergeInstanceInfo(_ParseNodeInfo(info), instance_list)
263 266

  
264 267

  
265 268
def _GetConfigFileDiskData(block_devices, blockdev_prefix,
......
604 607
                                   (instance.name, result.fail_reason,
605 608
                                    result.output))
606 609

  
607
  def GetNodeInfo(self):
610
  def GetNodeInfo(self, hvparams=None):
608 611
    """Return information about the node.
609 612

  
610 613
    @see: L{_GetNodeInfo} and L{_ParseNodeInfo}
611 614

  
612 615
    """
613
    result = self._RunXen(["info"])
616
    result = self._RunXen(["info"], hvparams=hvparams)
614 617
    if result.failed:
615 618
      logging.error("Can't retrieve xen hypervisor information (%s): %s",
616 619
                    result.fail_reason, result.output)
617 620
      return None
618 621

  
619
    return _GetNodeInfo(result.stdout, self._GetInstanceList)
622
    instance_list = self._GetInstanceList(True, hvparams=hvparams)
623
    return _GetNodeInfo(result.stdout, instance_list)
620 624

  
621 625
  @classmethod
622 626
  def GetInstanceConsole(cls, instance, hvparams, beparams):
b/test/py/ganeti.hypervisor.hv_xen_unittest.py
228 228

  
229 229
class TestMergeInstanceInfo(testutils.GanetiTestCase):
230 230
  def testEmpty(self):
231
    self.assertEqual(hv_xen._MergeInstanceInfo({}, lambda _: []), {})
231
    self.assertEqual(hv_xen._MergeInstanceInfo({}, []), {})
232 232

  
233 233
  def _FakeXmList(self, include_node):
234
    self.assertTrue(include_node)
235 234
    return [
236 235
      (hv_xen._DOM0_NAME, NotImplemented, 4096, 7, NotImplemented,
237 236
       NotImplemented),
......
240 239
      ]
241 240

  
242 241
  def testMissingNodeInfo(self):
243
    result = hv_xen._MergeInstanceInfo({}, self._FakeXmList)
242
    instance_list = self._FakeXmList(True)
243
    result = hv_xen._MergeInstanceInfo({}, instance_list)
244 244
    self.assertEqual(result, {
245 245
      "memory_dom0": 4096,
246 246
      "dom0_cpus": 7,
......
248 248

  
249 249
  def testWithNodeInfo(self):
250 250
    info = testutils.ReadTestData("xen-xm-info-4.0.1.txt")
251
    result = hv_xen._GetNodeInfo(info, self._FakeXmList)
251
    instance_list = self._FakeXmList(True)
252
    result = hv_xen._GetNodeInfo(info, instance_list)
252 253
    self.assertEqual(result, {
253 254
      "cpu_nodes": 1,
254 255
      "cpu_sockets": 2,

Also available in: Unified diff