Beispiel #1
0
 def map_minions(self, get_only_alive=False):
     """
     Builds a recursive map of the minions currently assigned to this
     overlord
     """
     maphash = {}
     current_minions = []
     if get_only_alive:
         ping_results = fc.Overlord("*").test.ping()
         for minion in ping_results.keys():
             if ping_results[minion] == 1:  #if minion is alive
                 current_minions.append(minion)  #add it to the list
     else:
         cm = certmaster.CertMaster()
         if cm == None:  # this is minion only setup
             return maphash
         current_minions = cm.get_signed_certs()
     for current_minion in current_minions:
         if current_minion in func_utils.get_hostname_by_route():
             maphash[current_minion] = {}  #prevent infinite recursion
         else:
             next_hop = fc.Overlord(current_minion)
             mapresults = next_hop.overlord.map_minions()[current_minion]
             if not cm_utils.is_error(mapresults):
                 maphash[current_minion] = mapresults
             else:
                 maphash[current_minion] = {}
     return maphash
Beispiel #2
0
    def do(self, args):
        self.server_spec = self.parentCommand.server_spec

        # because this is mainly an interactive command, expand the server list and make seperate connections.
        # to make things look more speedy.

        minion_set = client.Minions(self.server_spec, port=self.port)
        if minion_set.overlord_config.puppet_minions:
            minion_set = client.PuppetMinions(self.server_spec, port=self.port)
        servers = minion_set.get_all_hosts()

        for server in servers:
            if server in minion_set.downed_hosts:
                continue

            overlord_obj = client.Overlord(server,
                                           interactive=False,
                                           verbose=self.verbose,
                                           noglobs=True)

            results = overlord_obj.run("test", "ping", [])
            if results == 1:
                print "[ ok ... ] %s" % server
            else:
                print "[ FAILED ] %s" % server

        return 1
Beispiel #3
0
 def map_minions(self,get_only_alive=False):
     """
     Builds a recursive map of the minions currently assigned to this
     overlord
     """
     maphash = {}
     current_minions = []
     if get_only_alive:
         ping_results = fc.Overlord("*").test.ping()
         for minion in ping_results.keys():
             if ping_results[minion] == 1: #if minion is alive
                 current_minions.append(minion) #add it to the list of current minions
     else:
         cm = certmaster.CertMaster()
         current_minions = cm.get_signed_certs()
     for current_minion in current_minions:
         maphash[current_minion] = fc.Overlord(current_minion).overlord.map_minions()[current_minion]
     return maphash
Beispiel #4
0
 def run(self,module,method,args,delegation_path):
     """
     Delegates commands down the path of delegation
     supplied as an argument
     """
     
     next_hop = delegation_path[0]
     overlord = fc.Overlord(next_hop)
     if len(delegation_path) == 1: #minion exists under this overlord
         overlord_module = getattr(overlord,module)
         return getattr(overlord_module,method)(*args[:])
     
     stripped_list = delegation_path[1:len(delegation_path)]
     delegation_results = overlord.delegation.run(module,method,args,stripped_list)
     return delegation_results[next_hop] #strip away nested hash data from results
Beispiel #5
0
    def build_map(self):

        minion_hash = func_client.Overlord("*").overlord.map_minions(
            self.options.only_alive == True)

        for minion in minion_hash.keys():  #clean hash of any top-level errors
            if utils.is_error(minion_hash[minion]):
                minion_hash[minion] = {}

        if self.options.verbose:
            print "- built the following map:"
            print minion_hash

        if self.options.append:
            try:
                oldmap = file(DEFAULT_TREE, 'r').read()
                old_hash = yaml.load(oldmap).next()
                oldmap.close()
            except e:
                sys.stderr.write(
                    "ERROR: old map could not be read, append failed\n")
                sys.exit(-1)

            merged_map = {}
            merged_map.update(old_hash)
            merged_map.update(minion_hash)

            if self.options.verbose:
                print "- appended new map to the following map:"
                print old_hash
                print "  resulting in:"
                print merged_map

            minion_hash = merged_map

        if self.options.verbose:
            print "- writing to %s" % DEFAULT_TREE

        mapfile = file(DEFAULT_TREE, 'w')
        data = yaml.dump(minion_hash)
        mapfile.write(data)
Beispiel #6
0
    def build_map(self):

        minion_hash = func_client.Overlord("*").overlord.map_minions(
            self.options.only_alive == True)

        if self.options.verbose:
            print "- built the following map:"
            print minion_hash

        if self.options.append:
            try:
                oldmap = file(DEFAULT_TREE, 'r').read()
                old_hash = yaml.load(oldmap).next()
                oldmap.close()
            except e:
                print "ERROR: old map could not be read, append failed"
                sys.exit(-1)

            merged_map = {}
            merged_map.update(old_hash)
            merged_map.update(minion_hash)

            if self.options.verbose:
                print "- appended new map to the following map:"
                print old_hash
                print "  resulting in:"
                print merged_map

            minion_hash = merged_map

        if self.options.verbose:
            print "- writing to %s" % DEFAULT_TREE

        mapfile = file(DEFAULT_TREE, 'w')
        data = yaml.dump(minion_hash)
        mapfile.write(data)
Beispiel #7
0
 def setUp(self):
     self.overlord = fc.Overlord(self.th,
                                 nforks=self.nforks,
                                 async=self.async)
Beispiel #8
0
    def run(self,args): 

        p = optparse.OptionParser()
        p.add_option("-v", "--verbose",
                     dest="verbose",
                     action="store_true",
                     help="provide extra output")
        p.add_option("-s", "--server-spec",
                     dest="server_spec",
                     default="*",
                     help="run against specific servers, default: '*'")
        p.add_option("-m", "--methods",
                     dest="methods",
                     default="inventory",
                     help="run inventory only on certain function names, default: 'inventory'")
        p.add_option("-M", "--modules",
                     dest="modules",
                     default="all",
                     help="run inventory only on certain module names, default: 'all'")
        p.add_option("-t", "--tree",
                     dest="tree",
                     default=DEFAULT_TREE,
                     help="output results tree here, default: %s" % DEFAULT_TREE)
        p.add_option("-n", "--no-git",
                     dest="nogit",
                     action="store_true",
                     help="disable useful change tracking features")
        p.add_option("-x", "--xmlrpc", dest="xmlrpc",
                     help="output data using XMLRPC format",
                     action="store_true")
        p.add_option("-j", "--json", dest="json",
                     help="output data using JSON",
                     action="store_true")


        (options, args) = p.parse_args(args)
        self.options = options

        filtered_module_list = options.modules.split(",")
        filtered_function_list = options.methods.split(",")

        self.git_setup(options)

        # see what modules each host provides (as well as what hosts we have)
        host_methods = func_client.Overlord(options.server_spec).system.list_methods()
       
        # call all remote info methods and handle them
        if options.verbose:
            print "- scanning ..."
        # for (host, modules) in host_modules.iteritems():

        for (host, methods) in host_methods.iteritems():

            if utils.is_error(methods):
                print "-- connection refused: %s" % host 
                break 

            for each_method in methods:

                #if type(each_method) == int:
                #    if self.options.verbose:
                #        print "-- connection refused: %s" % host
                #    break

                tokens = each_method.split(".")
                module_name = ".".join(tokens[:-1])
                method_name = tokens[-1]

                if not "all" in filtered_module_list and not module_name in filtered_module_list:
                    continue

                if not "all" in filtered_function_list and not method_name in filtered_function_list:
                    continue
               
                overlord = func_client.Overlord(host,noglobs=True) # ,noglobs=True)
                results = getattr(getattr(overlord,module_name),method_name)()
                if self.options.verbose:
                    print "-- %s: running: %s %s" % (host, module_name, method_name)
                self.save_results(options, host, module_name, method_name, results)
        self.git_update(options)
        return 1
Beispiel #9
0
# FIXME: should import the client lib, not XMLRPC lib, when we are done

import xmlrpclib
import sys

TEST_GETATTR = True
TEST_PROCESS = False
TEST_VIRT = False
TEST_SERVICES = False
TEST_HARDWARE = False
TEST_SMART = True

if TEST_GETATTR:
    import func.overlord.client as func_client
    print func_client.Overlord("*").hardware.pci_info()
    #print func_client.Overlord("*").test.add(1,2)
    #print func_client.Overlord("*").hardware.info()
    #print func_client.Overlord("*").run("hardware","info",[])
    #print func_client.Overlord(socket.gethostname(),noglobs=True).test.add("1","2")
    sys.exit(1)

# get a connecton (to be replaced by client lib logic)
s = xmlrpclib.ServerProxy("http://127.0.0.1:51234")

# here's the basic test...
print s.test.add(1, 2)

if TEST_SMART:
    print s.smart.info()
Beispiel #10
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Copyright (c) 2007 Red Hat, inc

import sys
import func.overlord.client as fc

if __name__ == '__main__':
    try:
        service = sys.argv[1]
    except Exception, ex:
        print "Usage: service_checker.py SERVICE"
        sys.exit(1)

    # Get the information from the systems
    info = fc.Overlord("*").service.status(service)
    for (host, details) in info.iteritems():
        status = "OFF"
        if details == 0:
            status = "ON"
        elif details == 3:
            status = "OFF"
        else:
            status = "ERR"
        print "%s: %s %s" % (host, service, status)
Beispiel #11
0
#!/usr/bin/python
# find all parts that need to be recalled
# (C) Michael DeHaan, 2007 <*****@*****.**>
# ===============================================

import func.overlord.client as fc
import func.utils as utils

bad = open("./part_data.txt").read().split()

info = fc.Overlord("*").hardware.hal_info()

for (host, details) in info.iteritems():

    if utils.is_error(details):
        print "%s had an error : %s" % (host, details[1:3])
        break

    for (device, full_output) in details.iteritems():
        for bad_value in bad:
            if full_output.find(bad_value) != -1:
                print "%s has flagged part: %s, matched %s" % (host, device,
                                                               bad_value)
                break
Beispiel #12
0
#!/usr/bin/python
# report on any drives with SMART issues
# these are likely going to kick the bucket
# (C) Michael DeHaan, 2007 <*****@*****.**>
# ===============================================

import func.overlord.client as fc
import func.utils as utils

info = fc.Overlord("*").smart.info()
failures = 0

for (host, details) in info.iteritems():

    if utils.is_error(details):
        print "%s had an error : %s" % (host, details[1:3])
        break

    (rc, list_of_output) = details
    if rc != 0:
        print "============================================"
        print "Host %s may have problems" % host
        print "\n".join(list_of_output[3:])
        failures = failures + 1

print "\n%s systems reported problems" % failures