Exemple #1
0
def guess_default_cloud(conf_d):
    (h, cloud_name) = conf_d["cloud"]["type"]
    if cloud_name != cloudmetadata.CLOUD_TYPES.UNKNOWN:
        return
    conf = config.AgentConfig([])
    name = cloudmetadata.guess_effective_cloud(conf)
    if name is None:
        raise Exception("Cloud %s is not a known type." % cloud_name)
    print("The detected cloud is " + name)
    conf_d["cloud"]["type"] = (h, name)
Exemple #2
0
def _gather_info(conf):
    output_tar_path = "/tmp/agent_info.tar.gz"
    tar = tarfile.open(output_tar_path, "w:gz")

    if os.path.exists(conf.storage_base_dir):
        tar.add(conf.storage_base_dir)
    try:
        effective_cloud = cm.guess_effective_cloud(conf)
    except:
        effective_cloud = "Not able to determine cloud"

    platform = (conf.platform_name, conf.platform_version)

    try:
        startup_script = conf.meta_data_object.get_startup_script()
    except Exception as ex:
        startup_script = "Not able to retrieve startup script: " + str(ex)

    version = dcm.agent.g_version
    protocol_version = dcm.agent.g_protocol_version
    message = "Effective cloud is: " + effective_cloud + "\n"
    message += "Platform is %s %s" % (platform[0], platform[1]) + "\n"
    message += "Version: " + version + "\n"
    message += "Protocol version: " + str(protocol_version)

    if startup_script:
        with open("/tmp/startup_script.txt", "w") as ss:
            ss.write(startup_script)

    with open("/tmp/meta_info.txt", "w") as mi:
        mi.write(message)

    # gather processes
    with open("/tmp/process_info.txt", "w") as pi:
        for p in [
                x for x in psutil.process_iter()
                if x.username() == conf.system_user
        ]:
            try:
                pi.write(p.name() + " : " + str(p.pid) + os.linesep)
                pi.write("\tstarted at: " + str(p.create_time()) + os.linesep)
                pi.write("\t: " + str(p.cmdline()) + os.linesep)
                pi.write("\t" + str(p.get_cpu_times()) + os.linesep)
                pi.write("\t" + str(p.get_memory_info()) + os.linesep)
            except psutil.AccessDenied:
                # the process list may change
                pass
            except psutil.NoSuchProcess:
                pass

    files_to_collect = [
        "/tmp/boot.log", "/tmp/error.log", "/var/log/cloud-init-output.log",
        "/var/log/cloud-init.log", "/var/log/boot.log", "/tmp/meta_info.txt",
        "/tmp/startup_script.txt", "/tmp/process_info.txt"
    ]

    for f in files_to_collect:
        if os.path.isfile(f):
            tar.add(f)

    tar.close()

    print("""
**********************************************************************
To get all log and configuration file copy %s to
your local machine
**********************************************************************
""" % output_tar_path)
    return output_tar_path
Exemple #3
0
def _gather_info(conf):
    output_tar_path = "/tmp/agent_info.tar.gz"
    tar = tarfile.open(output_tar_path, "w:gz")

    if os.path.exists(conf.storage_base_dir):
        tar.add(conf.storage_base_dir)
    try:
        effective_cloud = cm.guess_effective_cloud(conf)
    except:
        effective_cloud = "Not able to determine cloud"

    platform = (conf.platform_name, conf.platform_version)

    try:
        startup_script = conf.meta_data_object.get_startup_script()
    except Exception as ex:
        startup_script = "Not able to retrieve startup script: " + str(ex)

    version = dcm.agent.g_version
    protocol_version = dcm.agent.g_protocol_version
    message = "Effective cloud is: " + effective_cloud + "\n"
    message += "Platform is %s %s" % (platform[0], platform[1]) + "\n"
    message += "Version: " + version + "\n"
    message += "Protocol version: " + str(protocol_version)

    if startup_script:
        with open("/tmp/startup_script.txt", "w") as ss:
            ss.write(startup_script)

    with open("/tmp/meta_info.txt", "w") as mi:
        mi.write(message)

    # gather processes
    with open("/tmp/process_info.txt", "w") as pi:
        for p in [x for x in psutil.process_iter() if x.username() == conf.system_user]:
            try:
                pi.write(p.name() + " : " + str(p.pid) + os.linesep)
                pi.write("\tstarted at: " + str(p.create_time()) + os.linesep)
                pi.write("\t: " + str(p.cmdline()) + os.linesep)
                pi.write("\t" + str(p.get_cpu_times()) + os.linesep)
                pi.write("\t" + str(p.get_memory_info()) + os.linesep)
            except psutil.AccessDenied:
                # the process list may change
                pass
            except psutil.NoSuchProcess:
                pass

    files_to_collect = [
        "/tmp/boot.log",
        "/tmp/error.log",
        "/var/log/cloud-init-output.log",
        "/var/log/cloud-init.log",
        "/var/log/boot.log",
        "/tmp/meta_info.txt",
        "/tmp/startup_script.txt",
        "/tmp/process_info.txt",
    ]

    for f in files_to_collect:
        if os.path.isfile(f):
            tar.add(f)

    tar.close()

    print(
        """
**********************************************************************
To get all log and configuration file copy %s to
your local machine
**********************************************************************
"""
        % output_tar_path
    )
    return output_tar_path