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._instances_ips = None
self._mc_primary_ips = None
self._nodes_primary_ips = None
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):
+ """Get instance name from its link and ip address.
+
+ @type ip: string
+ @param ip: ip address
+ @type link: string
+ @param link: nic link
+ @rtype: string
+ @return: instance name
+
+ """
+ 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
return self._mc_primary_ips
def GetInstancesIps(self, link):
- if link is None:
- return self._instances_ips
+ """Get list of nic ips connected to a certain link.
+
+ @type link: string
+ @param link: nic link
+ @rtype: list
+ @return: list of ips connected to that link
+
+ """
+ if not link:
+ link = self.GetDefaultNicLink()
+
if link in self._inst_ips_by_link:
return self._inst_ips_by_link[link]
else:
@param values: Dictionary of (name, value)
"""
- ssconf_lock = utils.FileLock(constants.SSCONF_LOCK_FILE)
+ ssconf_lock = utils.FileLock.Open(constants.SSCONF_LOCK_FILE)
# Get lock while writing files
ssconf_lock.Exclusive(blocking=True, timeout=SSCONF_LOCK_TIMEOUT)
if debug:
sys.stderr.write("Not master candidate, exiting.\n")
sys.exit(constants.EXIT_NOTCANDIDATE)
-