diff options
-rw-r--r-- | plugins/config_generator.py | 22 | ||||
-rwxr-xr-x | plugins/discovery.py | 61 | ||||
-rw-r--r-- | tests/test_config_generator.py | 5 | ||||
-rw-r--r-- | tests/test_discovery.py | 7 |
4 files changed, 60 insertions, 35 deletions
diff --git a/plugins/config_generator.py b/plugins/config_generator.py index 465eb61..ed32912 100644 --- a/plugins/config_generator.py +++ b/plugins/config_generator.py @@ -21,6 +21,7 @@ from pynag import Model import server_utils +from glusternagios.glustercli import HostStatus """ Change mode helps to identify the change in the defintion. @@ -41,7 +42,7 @@ class GlusterNagiosConfManager: #Create nagios host configuration with the given attributes def createHost(self, hostName, alias, template, - address, hostGroups, checkCommand, services): + address, hostGroups, checkCommand, services, uuid): host = {} host['host_name'] = hostName host['alias'] = alias @@ -55,6 +56,8 @@ class GlusterNagiosConfManager: #aggregate all the host services under the host if services: host['host_services'] = services + if uuid: + host['_HOST_UUID'] = uuid return host def __createVolumeUtilizationService(self, volume, clusterName): @@ -230,18 +233,19 @@ class GlusterNagiosConfManager: #Create host config for Gluster cluster with volume related services clusterHostConfig = self.createHost( cluster['name'], cluster['name'], "gluster-cluster", - cluster['name'], None, None, clusterServices) + cluster['name'], None, None, clusterServices, None) hostsConfigs.append(clusterHostConfig) #Create host config for all hosts in the cluster with brick related #services for host in cluster['hosts']: - brickServices = self.createBrickServices(host) - hostGroups = "gluster_hosts,%s" % (cluster['name']) - hostConfig = self.createHost( - host['hostname'], host['hostname'], "gluster-host", - host['hostip'], hostGroups, None, brickServices) - hostsConfigs.append(hostConfig) - + if host['status'] == HostStatus.CONNECTED: + brickServices = self.createBrickServices(host) + hostGroups = "gluster_hosts,%s" % (cluster['name']) + hostConfig = self.createHost( + host['hostname'], host['hostname'], "gluster-host", + host['hostip'], hostGroups, None, brickServices, + host.get('uuid')) + hostsConfigs.append(hostConfig) hostGroup["_hosts"] = hostsConfigs return hostGroup diff --git a/plugins/discovery.py b/plugins/discovery.py index 2f1b9f6..3e3b0a5 100755 --- a/plugins/discovery.py +++ b/plugins/discovery.py @@ -24,6 +24,7 @@ import shutil import sys from glusternagios import utils +from glusternagios.glustercli import HostStatus from config_generator import GlusterNagiosConfManager import server_utils import submit_external_command @@ -111,16 +112,17 @@ def discoverCluster(hostip, cluster): #Add the ip address of the root node given by the user to the peer list hostlist[0]['hostip'] = hostip for host in hostlist: - #Get host names - hostDetails = execNRPECommand(host['hostip'], "discoverhostparams") - host.update(hostDetails) - #Get the list of bricks for this host and add to dictionary - host['bricks'] = [] - for volume in componentlist['volumes']: - for brick in volume['bricks']: - if brick['hostUuid'] == host['uuid']: - brick['volumeName'] = volume['name'] - host['bricks'].append(brick) + #Get host names for all the connected hosts + if host['status'] == HostStatus.CONNECTED: + hostDetails = execNRPECommand(host['hostip'], "discoverhostparams") + host.update(hostDetails) + #Get the list of bricks for this host and add to dictionary + host['bricks'] = [] + for volume in componentlist['volumes']: + for brick in volume['bricks']: + if brick['hostUuid'] == host['uuid']: + brick['volumeName'] = volume['name'] + host['bricks'].append(brick) clusterdata['hosts'] = hostlist clusterdata['volumes'] = componentlist['volumes'] clusterdata['name'] = cluster @@ -143,10 +145,11 @@ def setHostNameWithIP(clusterdata): def isHostsNamesUnique(clusterdata): hostnames = {} for host in clusterdata['hosts']: - if hostnames.get(host['hostname']) is None: - hostnames[host['hostname']] = host['hostip'] - else: - return False + if host.get('status') == HostStatus.CONNECTED: + if hostnames.get(host.get('hostname')) is None: + hostnames[host.get('hostname')] = host['hostip'] + else: + return False return True @@ -244,29 +247,30 @@ def findAddUpdateHosts(hosts): #Find deleted hosts in the given cluster. -def findDeletedHosts(hostgroup, hosts): +def findDeletedHosts(hostgroup, hosts, ignoredHosts): deletedHosts = [] hostConfigs = server_utils.getHostConfigsForCluster(hostgroup) for hostConfig in hostConfigs: - host = findHostInList(hosts, hostConfig['host_name']) - if host is None: - deletedHosts.append({'host_name': hostConfig['host_name'], - 'changeMode': CHANGE_MODE_REMOVE}) + if hostConfig.get('_HOST_UUID') not in ignoredHosts: + host = findHostInList(hosts, hostConfig['host_name']) + if host is None: + deletedHosts.append({'host_name': hostConfig['host_name'], + 'changeMode': CHANGE_MODE_REMOVE}) return deletedHosts #Find Added/Deleted/Updated hosts in cluster -def findHostDelta(clusterConfig): +def findHostDelta(clusterConfig, ignoredHosts): hostDelta = [] updated = findAddUpdateHosts(clusterConfig['_hosts']) hostDelta.extend(updated) hostDelta.extend(findDeletedHosts(clusterConfig['hostgroup_name'], - clusterConfig['_hosts'])) + clusterConfig['_hosts'], ignoredHosts)) return hostDelta #Find changes to the cluster -def findDelta(clusterConfig): +def findDelta(clusterConfig, ignoredHosts): delta = {} delta['hostgroup_name'] = clusterConfig['hostgroup_name'] delta['alias'] = clusterConfig['alias'] @@ -277,7 +281,7 @@ def findDelta(clusterConfig): delta['_hosts'] = clusterConfig['_hosts'] return delta - hostDelta = findHostDelta(clusterConfig) + hostDelta = findHostDelta(clusterConfig, ignoredHosts) delta['_hosts'] = hostDelta if hostDelta: delta['changeMode'] = CHANGE_MODE_UPDATE @@ -449,6 +453,14 @@ def sendCustomNotification(cluster, summary): submit_external_command.submitExternalCommand(cmdStr) +def getAllNonConnectedHosts(hostList): + nonConnectedHosts = [] + for host in hostList: + if host.get('status') != HostStatus.CONNECTED: + nonConnectedHosts.append(host.get('uuid')) + return nonConnectedHosts + + if __name__ == '__main__': args = parse_input() clusterdata = discoverCluster(args.hostip, args.cluster) @@ -457,7 +469,8 @@ if __name__ == '__main__': if args.force: clusterDelta['changeMode'] = CHANGE_MODE_ADD else: - clusterDelta = findDelta(clusterDelta) + nonConnectedHosts = getAllNonConnectedHosts(clusterdata['hosts']) + clusterDelta = findDelta(clusterDelta, nonConnectedHosts) if clusterDelta.get('changeMode') is None: print "Cluster configurations are in sync" diff --git a/tests/test_config_generator.py b/tests/test_config_generator.py index 9d6d1ab..d54ddfe 100644 --- a/tests/test_config_generator.py +++ b/tests/test_config_generator.py @@ -17,6 +17,7 @@ # from plugins import config_generator +from glusternagios.glustercli import HostStatus from testrunner import PluginsTestCase as TestCaseBase @@ -116,10 +117,14 @@ class TestGlusterNagiosConfManager(TestCaseBase): cluster = {'name': 'Test-Cluster', 'hosts': [], 'volumes': []} cluster['hosts'].append({'hostip': '10.70.43.1', 'hostname': 'host-1', + 'uuid': '0000-1111', + 'status': HostStatus.CONNECTED, 'bricks': self.createBricks(1, "Volume1", '10.70.43.1')}) cluster['hosts'].append({'hostip': '10.70.43.2', 'hostname': 'host-2', + 'status': HostStatus.CONNECTED, + 'uuid': '0000-1112', 'bricks': self.createBricks(2, "Volume1", '10.70.43.2')}) cluster['volumes'].append({'name': 'Volume1', "type": "Replicate"}) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 122d8a1..5e03732 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -17,6 +17,7 @@ # from plugins import discovery +from glusternagios.glustercli import HostStatus from testrunner import PluginsTestCase as TestCaseBase @@ -63,8 +64,10 @@ class TestDiscovery(TestCaseBase): def _getPeers(self): result = [] - result.append({"hostip": "lo", "uuid": "0000-1111"}) - result.append({"hostip": "172.16.53.2", "uuid": "0000-1112"}) + result.append({"hostip": "lo", "uuid": "0000-1111", + 'status': HostStatus.CONNECTED}) + result.append({"hostip": "172.16.53.2", "uuid": "0000-1112", + 'status': HostStatus.CONNECTED}) return result def _getHostParams(self, hostip): |