Revision 572e52bf lib/hypervisor/hv_fake.py

b/lib/hypervisor/hv_fake.py
155 155
  def GetNodeInfo(self):
156 156
    """Return information about the node.
157 157

  
158
    This is just a wrapper over the base GetLinuxNodeInfo method.
159

  
158 160
    @return: a dict with the following keys (values in MiB):
159 161
          - memory_total: the total memory size on the node
160 162
          - memory_free: the available memory on the node for instances
161 163
          - memory_dom0: the memory used by the node itself, if available
162 164

  
163 165
    """
164
    # global ram usage from the xm info command
165
    # memory                 : 3583
166
    # free_memory            : 747
167
    # note: in xen 3, memory has changed to total_memory
168
    try:
169
      fh = file("/proc/meminfo")
170
      try:
171
        data = fh.readlines()
172
      finally:
173
        fh.close()
174
    except IOError, err:
175
      raise errors.HypervisorError("Failed to list node info: %s" % err)
176

  
177
    result = {}
178
    sum_free = 0
179
    for line in data:
180
      splitfields = line.split(":", 1)
181

  
182
      if len(splitfields) > 1:
183
        key = splitfields[0].strip()
184
        val = splitfields[1].strip()
185
        if key == 'MemTotal':
186
          result['memory_total'] = int(val.split()[0])/1024
187
        elif key in ('MemFree', 'Buffers', 'Cached'):
188
          sum_free += int(val.split()[0])/1024
189
        elif key == 'Active':
190
          result['memory_dom0'] = int(val.split()[0])/1024
191
    result['memory_free'] = sum_free
192

  
166
    result = self.GetLinuxNodeInfo()
193 167
    # substract running instances
194 168
    all_instances = self.GetAllInstancesInfo()
195 169
    result['memory_free'] -= min(result['memory_free'],
196 170
                                 sum([row[2] for row in all_instances]))
197

  
198
    cpu_total = 0
199
    try:
200
      fh = open("/proc/cpuinfo")
201
      try:
202
        cpu_total = len(re.findall("(?m)^processor\s*:\s*[0-9]+\s*$",
203
                                   fh.read()))
204
      finally:
205
        fh.close()
206
    except EnvironmentError, err:
207
      raise errors.HypervisorError("Failed to list node info: %s" % err)
208
    result['cpu_total'] = cpu_total
209
    # FIXME: export correct data here
210
    result['cpu_nodes'] = 1
211
    result['cpu_sockets'] = 1
212

  
213 171
    return result
214 172

  
215 173
  @classmethod

Also available in: Unified diff