Commit cd195419 authored by Guido Trotter's avatar Guido Trotter
Browse files

SimpleConfigReader: ips are partitioned by link



We were already half-doing it, but this completes the process.

1) We don't maintain a list of ips or an ip->instance map
2) We add a new link,ip->instance map (link->ips list we had)
3) We add the link parameter to GetInstanceByIp (making it
   GetInstanceByLinkIp)
4) We change the GetInstanceByIp caller to pass None as link
   (thus for now using only the default link)
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 47a626b0
......@@ -161,7 +161,7 @@ class InstanceIpToNodePrimaryIpQuery(ConfdQuery):
pnodes_list = []
for instance_ip in instances_list:
instance = self.reader.GetInstanceByIp(instance_ip)
instance = self.reader.GetInstanceByLinkIp(instance_ip, None)
if not instance:
logging.debug("Invalid instance IP: %s" % instance)
pnodes_list.append(QUERY_UNKNOWN_ENTRY_ERROR)
......
......@@ -59,9 +59,8 @@ class SimpleConfigReader(object):
self._last_size = None
self._config_data = None
self._instances_ips = None
self._inst_ips_by_link = None
self._ip_to_instance = None
self._ip_to_inst_by_link = None
self._mc_primary_ips = None
self._nodes_primary_ips = None
......@@ -106,7 +105,7 @@ class SimpleConfigReader(object):
raise errors.ConfigurationError("Cannot load config file %s: %s" %
(self._file_name, err))
self._ip_to_instance = {}
self._ip_to_inst_by_link = {}
self._instances_ips = []
self._inst_ips_by_link = {}
c_nparams = self._config_data['cluster']['nicparams'][constants.PP_DEFAULT]
......@@ -114,11 +113,11 @@ class SimpleConfigReader(object):
instance = self._config_data['instances'][iname]
for nic in instance['nics']:
if 'ip' in nic and nic['ip']:
self._instances_ips.append(nic['ip'])
self._ip_to_instance[nic['ip']] = iname
params = objects.FillDict(c_nparams, nic['nicparams'])
if not params['link'] in self._inst_ips_by_link:
self._inst_ips_by_link[params['link']] = []
self._ip_to_inst_by_link[params['link']] = {}
self._ip_to_inst_by_link[params['link']][nic['ip']] = iname
self._inst_ips_by_link[params['link']].append(nic['ip'])
self._nodes_primary_ips = []
......@@ -185,10 +184,14 @@ class SimpleConfigReader(object):
offline = self._config_data["nodes"][node]["offline"]
return master_candidate, drained, offline
def GetInstanceByIp(self, ip):
if ip not in self._ip_to_instance:
def GetInstanceByLinkIp(self, ip, link):
if not link:
link = self.GetDefaultNicLink()
if not link in self._ip_to_inst_by_link:
return None
return self._ip_to_instance[ip]
if not ip in self._ip_to_inst_by_link[link]:
return None
return self._ip_to_inst_by_link[link][ip]
def GetNodePrimaryIp(self, node):
"""Get a node's primary ip
......@@ -223,8 +226,9 @@ class SimpleConfigReader(object):
return self._mc_primary_ips
def GetInstancesIps(self, link):
if link is None:
return self._instances_ips
if not link:
link = self.GetDefaultNicLink()
if link in self._inst_ips_by_link:
return self._inst_ips_by_link[link]
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment