Revision ae130c81

b/lib/ssconf.py
95 95
      raise errors.ConfigurationError("Cannot load config file %s: %s" %
96 96
                                      (self._file_name, err))
97 97

  
98
    self._ip_to_instance = {}
99
    for iname in self._config_data['instances']:
100
      instance = self._config_data['instances'][iname]
101
      for nic in instance['nics']:
102
        if 'ip' in nic and nic['ip']:
103
          self._ip_to_instance[nic['ip']] = iname
104

  
98 105
    return True
99 106

  
100 107
  # Clients can request a reload of the config file, so we export our internal
......
148 155
    offline = self._config_data["nodes"][node]["offline"]
149 156
    return master_candidate, drained, offline
150 157

  
158
  def GetInstanceByIp(self, ip):
159
    if ip not in self._ip_to_instance:
160
      return None
161
    return self._ip_to_instance[ip]
162

  
163
  def GetNodePrimaryIp(self, node):
164
    """Get a node's primary ip
165

  
166
    @type node: string
167
    @param node: node name
168
    @rtype: string, or None
169
    @return: node's primary ip, or None if no such node
170

  
171
    """
172
    if node not in self._config_data["nodes"]:
173
      return None
174
    return self._config_data["nodes"][node]["primary_ip"]
175

  
176
  def GetInstancePrimaryNode(self, instance):
177
    """Get an instance's primary node
178

  
179
    @type instance: string
180
    @param instance: instance name
181
    @rtype: string, or None
182
    @return: primary node, or None if no such instance
183

  
184
    """
185
    if instance not in self._config_data["instances"]:
186
      return None
187
    return self._config_data["instances"][instance]["primary_node"]
188

  
151 189

  
152 190
class SimpleStore(object):
153 191
  """Interface to static cluster data.

Also available in: Unified diff