示例#1
0
    def __init__(self):
        """
        Constructor.
        """

        cm_config_file = '/etc/certmaster/minion.conf'
        self.cm_config = read_config(cm_config_file, CMConfig)
        config_file = "/etc/func/minion.conf"
        self.config = read_config(config_file, FuncdConfig)

        self.logger = logger.Logger().logger
        self.audit_logger = logger.AuditLogger()
        self.__setup_handlers()
示例#2
0
文件: server.py 项目: lmacken/func
    def __init__(self):

        """
        Constructor.
        """

        cm_config_file = '/etc/certmaster/minion.conf'
        self.cm_config = read_config(cm_config_file, CMConfig)
        config_file = "/etc/func/minion.conf"
        self.config = read_config(config_file, FuncdConfig)

        self.logger = logger.Logger().logger
        self.audit_logger = logger.AuditLogger()
        self.__setup_handlers()
示例#3
0
文件: utils.py 项目: lmacken/func
def get_hostname():

    # FIXME: this code ignores http proxies (which granted, we don't
    #      support elsewhere either. It also hardcodes the port number
    #      for the certmaster for now
    hostname = None
    hostname = socket.gethostname()
    try:
        ip = socket.gethostbyname(hostname)
    except:
        return hostname
    if ip != "127.0.0.1":
        return hostname


    config_file = '/etc/certmaster/minion.conf'
    minion_config = read_config(config_file, MinionConfig)

    server = minion_config.certmaster
    port = 51235

    try:
        s = socket.socket()
        s.settimeout(5)
        s.connect((server, port))
        (intf, port) = s.getsockname()
        hostname = socket.gethostbyaddr(intf)[0]
        s.close()
    except:
        s.close()
        raise

    return hostname
示例#4
0
def get_hostname():

    # FIXME: this code ignores http proxies (which granted, we don't
    #      support elsewhere either. It also hardcodes the port number
    #      for the certmaster for now
    hostname = None
    hostname = socket.gethostname()
    try:
        ip = socket.gethostbyname(hostname)
    except:
        return hostname
    if ip != "127.0.0.1":
        return hostname

    config_file = '/etc/certmaster/minion.conf'
    minion_config = read_config(config_file, MinionConfig)

    server = minion_config.certmaster
    port = 51235

    try:
        s = socket.socket()
        s.settimeout(5)
        s.connect((server, port))
        (intf, port) = s.getsockname()
        hostname = socket.gethostbyaddr(intf)[0]
        s.close()
    except:
        s.close()
        raise

    return hostname
示例#5
0
文件: logger.py 项目: lmacken/func
 def __init__(self, logfilepath ="/var/log/func/func.log"):
     config_file = '/etc/func/minion.conf'
     self.config = read_config(config_file, FuncdConfig)    
     self.loglevel = logging._levelNames[self.config.log_level]
     self._setup_logging()
     if self._no_handlers:
         self._setup_handlers(logfilepath=logfilepath)
示例#6
0
 def __init__(self, logfilepath="/var/log/func/func.log"):
     config_file = '/etc/func/minion.conf'
     self.config = read_config(config_file, FuncdConfig)
     self.loglevel = logging._levelNames[self.config.log_level]
     self._setup_logging()
     if self._no_handlers:
         self._setup_handlers(logfilepath=logfilepath)
示例#7
0
文件: call.py 项目: pombredanne/func
    def do(self, args):

        # I'm not really a fan of the "module methodname" approach
        # but we'll keep it for now -akl

        # I kind of feel like we shouldn't be parsing args here, but I'm
        # not sure what the write place is -al;

        if not args:
            self.outputUsage()
            return
        
        self.module           = args[0]
        if len(args) > 1:
            self.method       = args[1]
        else:
            self.method       = None
        if len(args) > 2:
            self.method_args  = args[2:]
        else:
            self.method_args  = []

        # this could get weird, sub sub classes might be calling this
        # this with multiple.parentCommand.parentCommands...
        # maybe command.py needs a way to set attrs on subCommands?
        # or some sort of shared datastruct?
        #        self.getOverlord()

        call_config = read_config(config_file, CallConfig)
        if self.method and (self.module+"."+self.method in call_config.force_async):
            self.options.async=True

        self.interactive = False
        self.async = self.options.async
示例#8
0
    def __init__(self):

        config_file = '/etc/func/minion.conf'
        self.config = read_config(config_file, FuncdConfig)
        self.__init_log()
        self.__base_methods = {
            # __'s so we don't clobber useful names
            "module_version" : self.__module_version,
            "module_api_version" : self.__module_api_version,
            "module_description" : self.__module_description,
            "list_methods"       : self.__list_methods,
            "get_method_args"    : self.__get_method_args,
        }
示例#9
0
    def __init__(self):

        config_file = '/etc/func/minion.conf'
        self.config = read_config(config_file, FuncdConfig)
        self.__init_log()
        self.__base_methods = {
            # __'s so we don't clobber useful names
            "module_version": self.__module_version,
            "module_api_version": self.__module_api_version,
            "module_description": self.__module_description,
            "list_methods": self.__list_methods,
            "get_method_args": self.__get_method_args,
        }
        self.__init_options()
示例#10
0
文件: check.py 项目: lmacken/func
 def check_talk_to_certmaster(self):
     config_file = "/etc/certmaster/minion.conf"
     minion_config = read_config(config_file, MinionConfig)
     cert_dir = minion_config.cert_dir
     # FIXME: don't hardcode port
     master_uri = "http://%s:51235/" % minion_config.certmaster
     print "* this minion is configured in /etc/certmaster/minion.conf to talk to host '%s' for certs, verify that is correct" % minion_config.certmaster
     # this will be a 501, unsupported GET, but we should be
     # able to tell if we can make contact
     connect_ok = True
     try:
         fd = urllib2.urlopen(master_uri)
         data = fd.read()
         fd.close()
     except urllib2.HTTPError:
         pass
     except:
         connect_ok = False
     if not connect_ok:
         print "cannot connect to certmaster at %s" % (master_uri)
示例#11
0
 def check_talk_to_certmaster(self):
     config_file = '/etc/certmaster/minion.conf'
     minion_config = read_config(config_file, MinionConfig)
     cert_dir = minion_config.cert_dir
     # FIXME: don't hardcode port
     master_uri = "http://%s:51235/" % minion_config.certmaster
     print "* this minion is configured in /etc/certmaster/minion.conf to talk to host '%s' for certs, verify that is correct" % minion_config.certmaster
     # this will be a 501, unsupported GET, but we should be
     # able to tell if we can make contact
     connect_ok = True
     try:
         fd = urllib2.urlopen(master_uri)
         data = fd.read()
         fd.close()
     except urllib2.HTTPError:
         pass
     except:
         connect_ok = False
     if not connect_ok:
         print "cannot connect to certmaster at %s" % (master_uri)
示例#12
0
文件: command.py 项目: lmacken/func
    def __init__(self, parentCommand=None, stdout=sys.stdout,
        stderr=sys.stderr):
        """
        Create a new command instance, with the given parent.
        Allows for redirecting stdout and stderr if needed.
        This redirection will be passed on to child commands.
        """
        if not self.name:
            self.name = str(self.__class__).split('.')[-1].lower()
        self.stdout = stdout
        self.stderr = stderr
        self.parentCommand = parentCommand

        self.config = read_config(CONFIG_FILE, CMConfig)

        # create subcommands if we have them
        self.subCommands = {}
        self.aliasedSubCommands = {}
        if self.subCommandClasses:
            for C in self.subCommandClasses:
                c = C(self, stdout=stdout, stderr=stderr)
                self.subCommands[c.name] = c
                if c.aliases:
                    for alias in c.aliases:
                        self.aliasedSubCommands[alias] = c

        # create our formatter and add subcommands if we have them
        formatter = CommandHelpFormatter()
        if self.subCommands:
            for name, command in self.subCommands.items():
                formatter.addCommand(name, command.summary or
                    command.description)

        # expand %command for the bottom usage
        usage = self.usage or self.name
        if usage.find("%command") > -1:
            usage = usage.split("%command")[0] + '[command]'
        usages = [usage, ]

        # FIXME: abstract this into getUsage that takes an optional
        # parentCommand on where to stop recursing up
        # useful for implementing subshells

        # walk the tree up for our usage
        c = self.parentCommand
        while c:
            usage = c.usage or c.name
            if usage.find(" %command") > -1:
                usage = usage.split(" %command")[0]
            usages.append(usage)
            c = c.parentCommand
        usages.reverse()
        usage = " ".join(usages)

        # create our parser
        description = self.description or self.summary
        self.parser = CommandOptionParser(
            usage=usage, description=description,
            formatter=formatter)
        self.parser.set_stdout(self.stdout)
        self.parser.disable_interspersed_args()

        # allow subclasses to add options
        self.addOptions()
示例#13
0
 def __init_options(self):
     options_file = '/etc/func/modules/' + self.__class__.__name__ + '.conf'
     self.options = read_config(options_file, self.Config)
     return
示例#14
0
    def __init__(self, parentCommand=None, stdout=sys.stdout,
        stderr=sys.stderr):
        """
        Create a new command instance, with the given parent.
        Allows for redirecting stdout and stderr if needed.
        This redirection will be passed on to child commands.
        """
        if not self.name:
            self.name = str(self.__class__).split('.')[-1].lower()
        self.stdout = stdout
        self.stderr = stderr
        self.parentCommand = parentCommand

        self.config = read_config(CONFIG_FILE, CMConfig)

        # create subcommands if we have them
        self.subCommands = {}
        self.aliasedSubCommands = {}
        if self.subCommandClasses:
            for C in self.subCommandClasses:
                c = C(self, stdout=stdout, stderr=stderr)
                self.subCommands[c.name] = c
                if c.aliases:
                    for alias in c.aliases:
                        self.aliasedSubCommands[alias] = c

        # create our formatter and add subcommands if we have them
        formatter = CommandHelpFormatter()
        if self.subCommands:
            for name, command in self.subCommands.items():
                formatter.addCommand(name, command.summary or
                    command.description)


        # expand %command for the bottom usage
        usage = self.usage or self.name
        if usage.find("%command") > -1:
            usage = usage.split("%command")[0] + '[command]'
        usages = [usage, ]

        # FIXME: abstract this into getUsage that takes an optional
        # parentCommand on where to stop recursing up
        # useful for implementing subshells

        # walk the tree up for our usage
        c = self.parentCommand
        while c:
            usage = c.usage or c.name
            if usage.find(" %command") > -1:
                usage = usage.split(" %command")[0]
            usages.append(usage)
            c = c.parentCommand
        usages.reverse()
        usage = " ".join(usages)

        # create our parser
        description = self.description or self.summary
        self.parser = CommandOptionParser(
            usage=usage, description=description,
            formatter=formatter)
        self.parser.set_stdout(self.stdout)
        self.parser.disable_interspersed_args()

        # allow subclasses to add options
        self.addOptions()