<commit_before>from epumgmt.defaults import RunVM
from epumgmt.api.exceptions import *
from epumgmt.main import em_args
from cloudinitd.user_api import CloudInitD
import os
import os.path

def load(p, c, m, run_name):
    ci_path = self.p.get_arg_or_none(em_args.CLOUDINITD_DIR)
    if not ci_path:
        ci_path = os.path.expanduser("~/.cloudinit")

    cb = CloudInitD(ci_path, db_name=run_name, terminate=False, boot=False, ready=False)
    svc_list = cb.get_all_services()


    for svc in svc_list:
        if svc.name.find("epu-") == 0:
            instance_id = svc.get_attr_from_bag("instance_id")
            hostname = svc.get_attr_from_bag("hostname")
            load_host(p, c, m, run_name, instance_id, hostname, svc.name[4:])


def load_host(p, c, m, run_name, instanceid, hostname, servicename):
    """Load a VM instance from cloudinit information
    
    p,c,m are seen everywhere: parameters, common, modules 
    """
    if c.trace:
        c.log.debug("load_host()")
        
    vm = RunVM()
    vm.instanceid = instanceid
    vm.hostname = hostname
    vm.service_type = servicename
    
    m.runlogs.new_vm(vm)
    m.persistence.new_vm(run_name, vm)
    c.log.debug("persisted info about '%s', host '%s'" % (vm.instanceid, vm.hostname))
    
    return vm<commit_msg>Load EPU related services from cloudinit.d<commit_after>from epumgmt.defaults import RunVM
from epumgmt.api.exceptions import *
from epumgmt.main import em_args
from cloudinitd.user_api import CloudInitD
from cloudinitd.exceptions import APIUsageException
import os
import os.path

def load(p, c, m, run_name):
    ci_path = p.get_arg_or_none(em_args.CLOUDINITD_DIR)
    if not ci_path:
        ci_path = os.path.expanduser("~/.cloudinitd")

    try:
        cb = CloudInitD(ci_path, db_name=run_name, terminate=False, boot=False, ready=False)
    except APIUsageException, e:
        raise IncompatibleEnvironment("Problem loading records from cloudinit.d: %s" % str(e))
    svc_list = cb.get_all_services()

    count = 0
    for svc in svc_list:
        if svc.name.find("epu-") == 0 or svc.name.find("provisioner") == 0:
            instance_id = svc.get_attr_from_bag("instance_id")
            hostname = svc.get_attr_from_bag("hostname")
            load_host(p, c, m, run_name, instance_id, hostname, svc.name[4:])
            count += 1

    if not count:
        msg = "Services must be named 'svc-epu-*' or 'svc-provisioner' in order to be recognized."
        c.log.info("No EPU related services in the cloudinit.d '%s' launch. %s" % (run_name, msg))
    elif count == 1:
        c.log.info("One EPU related service in cloudinit.d '%s' launch" % run_name)
    else:
        c.log.info("%d EPU related services in the cloudinit.d '%s' launch" % (count, run_name))

def load_host(p, c, m, run_name, instanceid, hostname, servicename):
    """Load a VM instance from cloudinit information
    
    p,c,m are seen everywhere: parameters, common, modules 
    """
        
    vm = RunVM()
    vm.instanceid = instanceid
    vm.hostname = hostname
    vm.service_type = servicename
    
    m.runlogs.new_vm(vm)
    if m.persistence.new_vm(run_name, vm):
        c.log.info("New EPU related service detected: '%s'.  Instance ID is '%s', host '%s'" % (servicename, vm.instanceid, vm.hostname))
    
    return vm
{'fraction_non_alphanumeric': 0.11500150920615757, 'fraction_numerical': 0.0024147298520977964, 'mean_word_length': 3.1373283395755305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '237252', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1150, 'n_words': 290}