Beispiel #1
0
    def set_kindo_setting(self, key, value):
        ini_path = os.path.join(self.kindo_settings_path, "kindo.ini")
        if not os.path.isdir(self.kindo_settings_path):
            os.makedirs(self.kindo_settings_path)

        cf = ConfigParser(ini_path)
        cf.set("default", key, value)
        cf.write(ini_path)
Beispiel #2
0
    def get_images_list(self):
        ini_path = os.path.join(self.kindo_settings_path, "images.ini")
        if not os.path.isfile(ini_path):
            return {}

        cf = ConfigParser(ini_path)

        return cf.get()
Beispiel #3
0
    def get_image_path(self, section):
        ini_path = os.path.join(self.kindo_settings_path, "images.ini")
        if not os.path.isfile(ini_path):
            return ""

        cf = ConfigParser(ini_path)

        infos = cf.get()
        if section not in infos:
            return ""

        if "path" not in infos[section]:
            return ""
        return infos[section]["path"]
Beispiel #4
0
    def start(self):
        ini_path = os.path.join(self.kindo_settings_path, "kindo.ini")
        if not os.path.isfile(ini_path):
            self.logger.info("logout successfully")
            return

        try:
            cf = ConfigParser(ini_path)
            cf.remove("default", "username")
            cf.remove("default", "password")
            cf.write()

            self.logger.info("logout successfully")
        except Exception as e:
            self.logger.debug(traceback.format_exc())
            self.logger.error(e)
Beispiel #5
0
    def delete_image(self, image_name):
        ini_path = os.path.join(self.kindo_settings_path, "images.ini")
        if not os.path.isfile(ini_path):
            return False

        cf = ConfigParser(ini_path)
        infos = cf.get()

        if image_name not in infos:
            return True

        if "name" not in infos[image_name]:
            return True

        v = infos[image_name]["name"]
        kiname = v.replace("/", "-").replace(":", "-")

        if kiname[-3:] != ".ki":
            kiname = "%s.ki" % kiname

        target = os.path.join(self.kindo_images_path, kiname)
        if os.path.isfile(target):
            os.remove(target)

        cf.remove(image_name)
        cf.write()
        return True
Beispiel #6
0
    def get_hosts_setting(self):
        ini_path = os.path.join(self.kindo_settings_path, "hosts.ini")
        if not os.path.isfile(ini_path):
            return {}

        cf = ConfigParser(ini_path)
        infos = cf.get()

        hosts = {}
        for section in infos:
            items = infos[section]
            section = section.lower()

            hosts[section] = {}
            for host in items:
                host = host.strip()
                password = items[host].strip()

                host = "%s:22" % host if host is not None and host.rfind(":") == -1 else host
                host = "root@%s" % host if host is not None and host.rfind("@") == -1 else host

                hosts[section][host] = password
        return hosts
Beispiel #7
0
    def delete_image(self, image_name):
        ini_path = os.path.join(self.kindo_settings_path, "images.ini")
        if not os.path.isfile(ini_path):
            return False

        cf = ConfigParser(ini_path)
        infos = cf.get()

        if image_name not in infos:
            return True

        if "path" in infos[image_name]:
            target = infos[image_name]["path"]
            if os.path.isfile(target):
                os.remove(target)

        cf.remove(image_name)
        cf.write()
        return True
Beispiel #8
0
    def add_image_info(self, image_info, path):
        if not path:
            return False

        ini_path = os.path.join(self.kindo_settings_path, "images.ini")
        if not os.path.isdir(self.kindo_settings_path):
            os.makedirs(self.kindo_settings_path)

        cf = ConfigParser(ini_path)
        cf.set(image_info["name"], "name", image_info["name"])
        cf.set(image_info["name"], "version", image_info["version"])
        cf.set(image_info["name"], "buildtime", image_info["buildtime"])
        cf.set(image_info["name"], "pusher", image_info["pusher"])
        cf.set(image_info["name"], "size", image_info["size"])
        cf.set(image_info["name"], "url", image_info["url"])
        cf.set(image_info["name"], "path", path)
        cf.write()

        return True
Beispiel #9
0
    def add_image_info(self, image_info, path):
        if not path:
            return False

        ini_path = os.path.join(self.kindo_settings_path, "images.ini")
        if not os.path.isdir(self.kindo_settings_path):
            os.makedirs(self.kindo_settings_path)

        cf = ConfigParser(ini_path)
        section = "%s/%s:%s" % (image_info["author"], image_info["name"], image_info["version"])
        cf.set(section, "name", image_info["name"])
        cf.set(section, "author", image_info["author"])
        cf.set(section, "version", image_info["version"])
        cf.set(section, "buildtime", image_info.get("build_time", image_info.get("buildtime", "")))
        cf.set(section, "pusher", image_info.get("pusher", ""))
        cf.set(section, "size", os.path.getsize(path))
        cf.set(section, "url", "")
        cf.set(section, "path", path)
        cf.write()

        return True