Exemple #1
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
Exemple #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()
Exemple #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"]
Exemple #4
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
Exemple #5
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