Esempio n. 1
0
    def __init__(self, config, hypervisor_iface, host_monitor, guest_manager):
        threading.Thread.__init__(self, name="PolicyEngine")
        self.setDaemon(True)
        self.config = config
        self.logger = logging.getLogger('mom.PolicyEngine')
        self.properties = {
            'hypervisor_iface': hypervisor_iface,
            'host_monitor': host_monitor,
            'guest_manager': guest_manager,
        }

        self.policy = Policy()
        self.load_policy()
        self.start()
    def __init__(self, config, hypervisor_iface, host_monitor, guest_manager):
        threading.Thread.__init__(self, name="PolicyEngine")
        self.setDaemon(True)
        self.config = config
        self.logger = logging.getLogger('mom.PolicyEngine')
        self.properties = {
            'hypervisor_iface': hypervisor_iface,
            'host_monitor': host_monitor,
            'guest_manager': guest_manager,
        }

        # Modified by DRG
        policy_type = self.config.get('main', 'policy-type')
        # vmpres_threshold = self.config.get('main', 'vmpres_threshold')
        # hostpres_threshold = self.config.get('main', 'hostpres_threshold')
        total_mem = self.config.get('main', 'total-mem')
        plot_dir = config.get('__int__', 'plot-subdir')
        if policy_type == "customized":
            self.policy = Policy()
            self.load_policy()
        elif policy_type == 'wfm-instant' or policy_type == 'wfm-longterm':
            self.policy = WFMPolicy()
            self.policy.set_policy(total_mem, plot_dir)
        elif policy_type == 'fupolicy':
            self.policy = FUPolicy()
        elif policy_type == 'rppolicy':
            alpha = float(self.config.get('main', 'alpha'))
            beta = float(self.config.get('main', 'beta'))
            self.policy = RPPolicy()
            self.policy.set_policy(policy_type, total_mem, plot_dir, alpha,
                                   beta)
            #self.policy.set_policy(policy_type, total_mem, plot_dir)
        self.start()
Esempio n. 3
0
class PolicyEngine(threading.Thread):
    """
    At a regular interval, this thread triggers system reconfiguration by
    sampling host and guest data, evaluating the policy and reporting the
    results to all enabled Controller plugins.
    """
    def __init__(self, config, hypervisor_iface, host_monitor, guest_manager):
        threading.Thread.__init__(self, name="PolicyEngine")
        self.setDaemon(True)
        self.config = config
        self.logger = logging.getLogger('mom.PolicyEngine')
        self.properties = {
            'hypervisor_iface': hypervisor_iface,
            'host_monitor': host_monitor,
            'guest_manager': guest_manager,
        }

        self.policy = Policy()
        self.load_policy()
        self.start()

    def load_policy(self):
        def read_policy(file_name, policy_name):
            try:
                with open(file_name, 'r') as f:
                    policyStr = f.read()
            except IOError, e:
                self.logger.warn("Unable to read policy file: %s" % e)
                return False
            return self.policy.set_policy(policy_name, policyStr)

        fname = self.config.get('main', 'policy')
        if fname:
            return read_policy(fname, None)

        policy_dir = self.config.get('main', 'policy-dir')
        if policy_dir:
            try:
                names = sorted(os.listdir(policy_dir))
            except OSError, e:
                self.logger.warn("Unable to read directory '%s': %s" % (
                                    policy_dir, e.strerror))
                return False
            for name in names:
                if name.startswith('.') or not name.endswith('.policy'):
                    continue
                fname = os.path.join(policy_dir, name)
                read_policy(fname, name.split('.policy')[0])
            return True