Revision 3fe22abd lib/query.py

b/lib/query.py
1541 1541
  return constants.INSTST_ADMINOFFLINE
1542 1542

  
1543 1543

  
1544
def _GetInstDiskSize(index):
1545
  """Build function for retrieving disk size.
1544
def _GetInstDisk(index, cb):
1545
  """Build function for calling another function with an instance Disk.
1546 1546

  
1547 1547
  @type index: int
1548 1548
  @param index: Disk index
1549
  @type cb: callable
1550
  @param cb: Callback
1549 1551

  
1550 1552
  """
1551
  def fn(_, inst):
1552
    """Get size of a disk.
1553
  def fn(ctx, inst):
1554
    """Call helper function with instance Disk.
1553 1555

  
1556
    @type ctx: L{InstanceQueryData}
1554 1557
    @type inst: L{objects.Instance}
1555 1558
    @param inst: Instance object
1556 1559

  
1557 1560
    """
1558 1561
    try:
1559
      return inst.disks[index].size
1562
      nic = inst.disks[index]
1560 1563
    except IndexError:
1561 1564
      return _FS_UNAVAIL
1562 1565

  
1566
    return cb(ctx, index, nic)
1567

  
1563 1568
  return fn
1564 1569

  
1565 1570

  
1571
def _GetInstDiskSize(ctx, _, disk): # pylint: disable=W0613
1572
  """Get a Disk's size.
1573

  
1574
  @type ctx: L{InstanceQueryData}
1575
  @type disk: L{objects.Disk}
1576
  @param disk: The Disk object
1577

  
1578
  """
1579
  if disk.size is None:
1580
    return _FS_UNAVAIL
1581
  else:
1582
    return disk.size
1583

  
1584

  
1585
def _GetInstDeviceName(ctx, _, device): # pylint: disable=W0613
1586
  """Get a Device's Name.
1587

  
1588
  @type ctx: L{InstanceQueryData}
1589
  @type device: L{objects.NIC} or L{objects.Disk}
1590
  @param device: The NIC or Disk object
1591

  
1592
  """
1593
  if device.name is None:
1594
    return _FS_UNAVAIL
1595
  else:
1596
    return device.name
1597

  
1598

  
1599
def _GetInstDeviceUUID(ctx, _, device): # pylint: disable=W0613
1600
  """Get a Device's UUID.
1601

  
1602
  @type ctx: L{InstanceQueryData}
1603
  @type device: L{objects.NIC} or L{objects.Disk}
1604
  @param device: The NIC or Disk object
1605

  
1606
  """
1607
  if device.uuid is None:
1608
    return _FS_UNAVAIL
1609
  else:
1610
    return device.uuid
1611

  
1612

  
1566 1613
def _GetInstNic(index, cb):
1567 1614
  """Build function for calling another function with an instance NIC.
1568 1615

  
......
1739 1786
    (_MakeField("nic.ips", "NIC_IPs", QFT_OTHER,
1740 1787
                "List containing each network interface's IP address"),
1741 1788
     IQ_CONFIG, 0, lambda ctx, inst: [nic.ip for nic in inst.nics]),
1789
    (_MakeField("nic.names", "NIC_Names", QFT_OTHER,
1790
                "List containing each network interface's name"),
1791
     IQ_CONFIG, 0, lambda ctx, inst: [nic.name for nic in inst.nics]),
1792
    (_MakeField("nic.uuids", "NIC_UUIDs", QFT_OTHER,
1793
                "List containing each network interface's UUID"),
1794
     IQ_CONFIG, 0, lambda ctx, inst: [nic.uuid for nic in inst.nics]),
1742 1795
    (_MakeField("nic.modes", "NIC_modes", QFT_OTHER,
1743 1796
                "List containing each network interface's mode"), IQ_CONFIG, 0,
1744 1797
     lambda ctx, inst: [nicp[constants.NIC_MODE]
......
1768 1821
      (_MakeField("nic.mac/%s" % i, "NicMAC/%s" % i, QFT_TEXT,
1769 1822
                  "MAC address of %s network interface" % numtext),
1770 1823
       IQ_CONFIG, 0, _GetInstNic(i, nic_mac_fn)),
1824
      (_MakeField("nic.name/%s" % i, "NicName/%s" % i, QFT_TEXT,
1825
                  "Name address of %s network interface" % numtext),
1826
       IQ_CONFIG, 0, _GetInstNic(i, _GetInstDeviceName)),
1827
      (_MakeField("nic.uuid/%s" % i, "NicUUID/%s" % i, QFT_TEXT,
1828
                  "UUID address of %s network interface" % numtext),
1829
       IQ_CONFIG, 0, _GetInstNic(i, _GetInstDeviceUUID)),
1771 1830
      (_MakeField("nic.mode/%s" % i, "NicMode/%s" % i, QFT_TEXT,
1772 1831
                  "Mode of %s network interface" % numtext),
1773 1832
       IQ_CONFIG, 0, _GetInstNic(i, nic_mode_fn)),
......
1846 1905
     IQ_CONFIG, 0, lambda ctx, inst: len(inst.disks)),
1847 1906
    (_MakeField("disk.sizes", "Disk_sizes", QFT_OTHER, "List of disk sizes"),
1848 1907
     IQ_CONFIG, 0, lambda ctx, inst: [disk.size for disk in inst.disks]),
1908
    (_MakeField("disk.names", "Disk_names", QFT_OTHER, "List of disk names"),
1909
     IQ_CONFIG, 0, lambda ctx, inst: [disk.name for disk in inst.disks]),
1910
    (_MakeField("disk.uuids", "Disk_UUIDs", QFT_OTHER, "List of disk UUIDs"),
1911
     IQ_CONFIG, 0, lambda ctx, inst: [disk.uuid for disk in inst.disks]),
1849 1912
    ]
1850 1913

  
1851 1914
  # Disks by number
1852
  fields.extend([
1853
    (_MakeField("disk.size/%s" % i, "Disk/%s" % i, QFT_UNIT,
1854
                "Disk size of %s disk" % utils.FormatOrdinal(i + 1)),
1855
     IQ_CONFIG, 0, _GetInstDiskSize(i))
1856
    for i in range(constants.MAX_DISKS)])
1915
  for i in range(constants.MAX_DISKS):
1916
    numtext = utils.FormatOrdinal(i + 1)
1917
    fields.extend([
1918
        (_MakeField("disk.size/%s" % i, "Disk/%s" % i, QFT_UNIT,
1919
                    "Disk size of %s disk" % numtext),
1920
        IQ_CONFIG, 0, _GetInstDisk(i, _GetInstDiskSize)),
1921
        (_MakeField("disk.name/%s" % i, "DiskName/%s" % i, QFT_TEXT,
1922
                    "Name of %s disk" % numtext),
1923
        IQ_CONFIG, 0, _GetInstDisk(i, _GetInstDeviceName)),
1924
        (_MakeField("disk.uuid/%s" % i, "DiskUUID/%s" % i, QFT_TEXT,
1925
                    "UUID of %s disk" % numtext),
1926
        IQ_CONFIG, 0, _GetInstDisk(i, _GetInstDeviceUUID))])
1857 1927

  
1858 1928
  return fields
1859 1929

  

Also available in: Unified diff