Пример #1
0
    def start(self):
        '''
           Start a jboss instance
        '''
        logging = logger.Logger().logger

        address = self.options.jboss_address
        instance = self.options.jboss_instance

        jboss_run_path = self.options.jboss_home + "/bin/run.sh"

        status = self.status()

        if len(self.search_by_address(address=address, status=status)) != 0:
            return (-1, "Another instances listening on this address, ")

        if len(self.search_by_instance(instance=instance, status=status)) != 0:
            return (-1, "This instances is just instanced")

        launcher = "sh " + str(
            jboss_run_path) + " -c " + instance + " -b " + address + " &"
        logging.info(launcher)

        comm = command.Command()
        comm.run(launcher)

        return "OK, instance " + instance + " started on address " + address
Пример #2
0
    def __init__(self, config=None):
        self.config = config

        self.acldir = self.config.acl_dir
        self.acls = {}
        self.logger = logger.Logger().logger
        self.certmaster_overrides_acls = self.config.certmaster_overrides_acls
        self.load()
Пример #3
0
def load_methods(path, main_class, parent_class=None):
    log = logger.Logger().logger
    methods = {}
    modules = load_modules(path, main_class, parent_class=parent_class)
    for x in modules.keys():
        for method in dir(modules[x]):
            if is_public_valid_method(modules[x], method):
                methods["%s.%s" % (x, method)] = getattr(modules[x], method)
    return methods
Пример #4
0
    def __init__(self, config=None):
        self.config = config

        self.acldir = self.config.acl_dir
        self._acl_glob = '%s/*.acl' % self.acldir
        self._acls = {}
        self.logger = logger.Logger().logger
        self.certmaster_overrides_acls = self.config.certmaster_overrides_acls
        self.last_load_time = 0
        self.load()
Пример #5
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()
Пример #6
0
def excepthook(exctype, value, tracebackobj):
    exctype_blurb = "Exception occured: %s" % exctype
    excvalue_blurb = "Exception value: %s" % value
    exctb_blurb = "Exception Info:\n%s" % string.join(
        traceback.format_list(traceback.extract_tb(tracebackobj)))

    print exctype_blurb
    print excvalue_blurb
    print exctb_blurb

    log = logger.Logger().logger
    log.info(exctype_blurb)
    log.info(excvalue_blurb)
    log.info(exctb_blurb)
Пример #7
0
    def stop(self):
        '''
            Stop a jboss instance, It suppose you are using
            use standard JNDI port 1099.
        '''
        logging = logger.Logger().logger

        address = self.options.jboss_address
        instance = self.options.jboss_instance

        jboss_sd_path = self.options.jboss_home + "/bin/shutdown.sh"
        data = self.search_by_address(address)

        if len(data) == 0:
            return (-1, "Istance on " + address + " not running")

        launcher = "sh " + str(
            jboss_sd_path) + " -s jnp://" + address + ":1099 &"
        logging.info(launcher)

        comm = command.Command()
        comm.run(launcher)

        return "OK, stopped instance listening address " + address
Пример #8
0
## general public license.
##
## 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., 675 Mass Ave, Cambridge, MA 02139, USA.
##
##

import distutils.sysconfig
import os
import sys
from gettext import gettext
_ = gettext

from func import logger
logger = logger.Logger().logger

from inspect import isclass
from func.minion.modules import func_module


def module_walker(topdir):
    module_files = []
    for root, dirs, files in os.walk(topdir):
        # we should get here for each subdir
        for filename in files:
            # ASSUMPTION: all module files will end with .py, .pyc, .pyo
            if filename[-3:] == ".py" or filename[-4:] == ".pyc" or filename[
                    -4:] == ".pyo":
                # the normpath is important, since we eventually replace /'s with .'s
                # in the module name, and foo..bar doesnt work -akl
Пример #9
0
 def __init_log(self):
     log = logger.Logger()
     self.logger = log.logger
Пример #10
0
def load_modules(path='func/minion/modules/',
                 main_class=func_module.FuncModule,
                 blacklist=None,
                 parent_class=None):
    log = logger.Logger().logger
    python_path = distutils.sysconfig.get_python_lib()
    module_file_path = "%s/%s" % (python_path, path)
    (mod_path, mod_dir) = os.path.split(os.path.normpath(module_file_path))
    mod_dir = "func." + module_file_path[len(python_path + '/func/'):].replace(
        "/", ".")

    sys.path.insert(0, mod_path)
    mods = {}
    bad_mods = {}

    filenames = module_walker(module_file_path)

    # FIXME: this is probably more complicated than it needs to be -akl
    for fn in filenames:
        # aka, everything after the module_file_path
        module_name_part = fn[len(module_file_path):]
        dirname, basename = os.path.split(module_name_part)

        if basename[:8] == "__init__":
            modname = dirname
            dirname = ""
        elif basename[-3:] == ".py":
            modname = basename[:-3]
        elif basename[-4:] in [".pyc", ".pyo"]:
            modname = basename[:-4]

        pathname = modname
        if dirname != "":
            pathname = "%s/%s" % (dirname, modname)

        mod_imp_name = pathname.replace("/", ".")

        if mods.has_key(mod_imp_name):
            # If we've already imported mod_imp_name, don't import it again
            continue

        # ignore modules that we've already determined aren't valid modules
        if bad_mods.has_key(mod_imp_name):
            continue

        try:
            # Auto-detect and load all FuncModules
            blip = __import__("%s%s" % (mod_dir, mod_imp_name), globals(),
                              locals(), [mod_imp_name])
            for obj in dir(blip):
                attr = getattr(blip, obj)
                if isclass(attr) and issubclass(attr, main_class):
                    log.debug("Loading %s module" % attr)
                    if parent_class:
                        mods[mod_imp_name] = attr(parent_class)
                    else:
                        mods[mod_imp_name] = attr()

        except ImportError, e:
            # A module that raises an ImportError is (for now) simply not loaded.
            errmsg = _("Could not load %s module: %s")
            log.warning(errmsg % (mod_imp_name, e))
            bad_mods[mod_imp_name] = True
            continue
        except:
Пример #11
0
    def status(self):
        """
            Get jboss information
            (instance name, ports, bind address, pid)
        """  
        processo = process.ProcessModule()
        results = processo.info("ax") 
		
	logging = logger.Logger().logger
        output = []
        for items in results:
            if "-Dprogram.name=run.sh" in items:
                for item in items:
                    if "java" in item:
                        java = True

                if java == True:
                    if items.__contains__("-c"):
                        instance = items[items.index("-c")+1]
                    else:
                        instance = ""

                    if items.__contains__("-b"):
                        address = items[items.index("-b")+1]
                    else:
                        address = ""

                    output.append((int(items[0]),instance,address,[]))

        # Retrieve information about network (netstat -tupln)

	net_status = networktest.NetworkTest()
	results = net_status.netstat("-tupln")

        for string in results:#netstat_list:
            address = None
            port = None
            pid = None

            try:
                address_port = string.split()[3]
                pid_name = string.split()[6]
            except:
                address_port = None
                pid_name = None
	    
            if address_port != None:
                try:
                    address = address_port.split(":")[0]
                    port =  int(address_port.split(":")[1])
                except:
                    address = None
                    port = None

            if pid_name != None:
                try:
                    pid = int(pid_name.split("/")[0])
                except:
                    pid = None
            
            if pid != None:
                for data in output:
                    if data[0] == pid:
                        #verify address
                        if address != None:
                            if data[2] == address:
                                data[3].append(port)

        return output