self._last_inode = None
self._last_mtime = None
self._last_size = None
+
+ self._config_data = None
+ self._inst_ips_by_link = None
+ self._ip_to_inst_by_link = None
+ self._instances_ips = None
+ self._mc_primary_ips = None
+ self._nodes_primary_ips = None
+
# we need a forced reload at class init time, to initialize _last_*
self._Load(force=True)
mtime = cfg_stat.st_mtime
size = cfg_stat.st_size
- reload = False
- if force or inode != self._last_inode or \
- mtime > self._last_mtime or \
- size != self._last_size:
+ if (force or inode != self._last_inode or
+ mtime > self._last_mtime or
+ size != self._last_size):
self._last_inode = inode
self._last_mtime = mtime
self._last_size = size
- reload = True
-
- if not reload:
+ else:
+ # Don't reload
return False
try:
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]
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 = []
def GetClusterSerialNo(self):
return self._config_data["cluster"]["serial_no"]
+ def GetDefaultNicParams(self):
+ return self._config_data["cluster"]["nicparams"][constants.PP_DEFAULT]
+
+ def GetDefaultNicLink(self):
+ return self.GetDefaultNicParams()[constants.NIC_LINK]
+
def GetNodeStatusFlags(self, node):
"""Get a node's status flags
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
+ if not ip in self._ip_to_inst_by_link[link]:
return None
- return self._ip_to_instance[ip]
+ return self._ip_to_inst_by_link[link][ip]
def GetNodePrimaryIp(self, node):
"""Get a node's primary ip
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:
if debug:
sys.stderr.write("Not master candidate, exiting.\n")
sys.exit(constants.EXIT_NOTCANDIDATE)
-