def configureNodes(clusterDelta, nagiosServerAddress, mode, timeout): for host in clusterDelta['_hosts']: # Only when a new node is added or whole cluster is added freshly. if (clusterDelta.get(CHANGE_MODE) == CHANGE_MODE_ADD or host.get(CHANGE_MODE) == CHANGE_MODE_ADD) \ and (host['use'] == 'gluster-host'): if not nagiosServerAddress: # Nagios server address should be specified as arg in auto mode if mode == "manual": nagiosServerAddress = getNagiosAddress( clusterDelta['hostgroup_name']) else: print "Nagios server address is not specified in " \ "'auto' mode" sys.exit(utils.PluginStatusCode.CRITICAL) # Configure the nodes. clusterName, Nagios server address and # host_name is passed as an argument to nrpe command # 'configure_gluster_node' server_utils.execNRPECommand(host['address'], 'configure_gluster_node', arguments=[ clusterDelta['hostgroup_name'], nagiosServerAddress, host['host_name'] ], timeout=timeout, json_output=False) return nagiosServerAddress
def configureNodes(clusterDelta, nagiosServerAddress, mode, timeout): for host in clusterDelta['_hosts']: # Only when a new node is added or whole cluster is added freshly. if (clusterDelta.get(CHANGE_MODE) == CHANGE_MODE_ADD or host.get(CHANGE_MODE) == CHANGE_MODE_ADD) \ and (host['use'] == 'gluster-host'): if not nagiosServerAddress: # Nagios server address should be specified as arg in auto mode if mode == "manual": nagiosServerAddress = getNagiosAddress( clusterDelta['hostgroup_name']) else: print "Nagios server address is not specified in " \ "'auto' mode" sys.exit(utils.PluginStatusCode.CRITICAL) # Configure the nodes. clusterName, Nagios server address and # host_name is passed as an argument to nrpe command # 'configure_gluster_node' server_utils.execNRPECommand( host['address'], 'configure_gluster_node', arguments=[clusterDelta['hostgroup_name'], nagiosServerAddress, host['host_name']], timeout=timeout, json_output=False) return nagiosServerAddress
def discoverCluster(hostip, cluster, timeout): """ This method helps to discover the nodes, volumes and bricks in the given gluster. It uses NRPE commands to contact the gluster nodes. Assumptions: First node returned by the "discoverpeers" NRPE command should be the same node where "discoverpeers" is executed. Parameters ---------- hostip: Address of a node in the gluster cluster. cluster: Cluster Name Returns --------- Returns cluster details in the following dictionary format { 'name': cluster-name, 'volumes': [list-volumes], 'host': [list-hosts] } each host in the list will a have list of bricks from the host. """ clusterdata = {} # Discover the logical components componentlist = discoverVolumes(hostip, timeout) # Discover the peers hostlist = server_utils.execNRPECommand(hostip, "discoverpeers", timeout=timeout) # 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 for all the connected hosts if host['status'] == HostStatus.CONNECTED: hostDetails = server_utils.execNRPECommand( host['hostip'], "discoverhostparams", timeout=timeout) 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 # Host names returned by "discoverhostparams" supposed to be unique. # So host name can be used to configure the host_name in nagios host. # But if host names are not unique then we have to use IP address to # configure host_name in nagios. if not isHostsNamesUnique(clusterdata): setHostNameWithIP(clusterdata) return clusterdata
def discoverCluster(hostip, cluster, timeout): """ This method helps to discover the nodes, volumes and bricks in the given gluster. It uses NRPE commands to contact the gluster nodes. Assumptions: First node returned by the "discoverpeers" NRPE command should be the same node where "discoverpeers" is executed. Parameters ---------- hostip: Address of a node in the gluster cluster. cluster: Cluster Name Returns --------- Returns cluster details in the following dictionary format { 'name': cluster-name, 'volumes': [list-volumes], 'host': [list-hosts] } each host in the list will a have list of bricks from the host. """ clusterdata = {} # Discover the logical components componentlist = discoverVolumes(hostip, timeout) # Discover the peers hostlist = server_utils.execNRPECommand(hostip, "discoverpeers", timeout=timeout) # 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 for all the connected hosts if host['status'] == HostStatus.CONNECTED: hostDetails = server_utils.execNRPECommand(host['hostip'], "discoverhostparams", timeout=timeout) 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 # Host names returned by "discoverhostparams" supposed to be unique. # So host name can be used to configure the host_name in nagios host. # But if host names are not unique then we have to use IP address to # configure host_name in nagios. if not isHostsNamesUnique(clusterdata): setHostNameWithIP(clusterdata) return clusterdata
def discoverVolumes(hostip, timeout): resultDict = {'volumes': []} volumeList = server_utils.execNRPECommand(hostip, "discover_volume_list", timeout=timeout) for volumeName in volumeList.keys(): volumeDetail = server_utils.execNRPECommand(hostip, "discover_volume_info", arguments=[volumeName], timeout=timeout) resultDict['volumes'].append(volumeDetail.get(volumeName)) return resultDict