Пример #1
0
    def load_domain0(self):
        """ load domain-0 running state """
        log.log_d("%s: loading domain0 infos" % (self.srv_ip))

        domustate_list = self.xenapi.xmlist_bydomu_raw('Domain-0')

        domustate_dict = scc.list2dict(eval(domustate_list))['domain']
        scc.dict2struct(self.infos.domain0, domustate_dict)
        return True
Пример #2
0
    def load_state(self):
        """ import domU running state """
        log.log_d("%s: loading domU running state" % (self.srv_ip))

        domustate_list = self.dom0.xenapi.xmlist_bydomu_raw(self.name)
        e_domustate_list = eval(domustate_list)
        if len(e_domustate_list):
            domustate_dict = scc.list2dict(e_domustate_list)['domain']
            self.state = scc.dict2struct(scc.AttStr("state structure"),
                                         domustate_dict)
        return True
Пример #3
0
    def load_config(self, config_content=list(), reinit=False):
        """ import domU configuration to config struct """
        log.log_d("%s: loading domU configuration" % (self.srv_ip))

        configfile = "%s/%s.cfg" % (self.dom0.xen.confpath_xen, self.name)

        if not len(config_content):
            config = fapi.get_file_content(self.dom0.srv_ip,
                                           configfile)
            if config == None:
                return False
            config = config.lines
        else: config = config_content

        clean_config = list()
        # cleaning config but formating is kept
        for line in config:
            clean_line = re.sub(r"#.*", r"", line)
            clean_line = re.sub(r"^\s+$", r"", clean_line)
            if len(clean_line):
                clean_config.extend([clean_line])

        # exec python domU configfile in a dict context
        plaintext_config = "\n".join(clean_config)
        config_dict = dict()
        unused = dict()
        exec plaintext_config in unused, config_dict

        # convert config dict in config structure
        self.config = scc.dict2struct(scc.AttStr("config structure"),
                                      config_dict)

        # check if domu is auto started
        configfile_auto = "%s/auto/%s.cfg" % (self.dom0.xen.confpath_xen,
                                              self.name)
        if fapi.file_exists(self.dom0.srv_ip,
                            configfile_auto):
            self.config.auto = True
        else: self.config.auto = False

        # store domu configuration filename
        self.config.configfile = configfile

        # reinit parent with IP and reload callbacks if asked
        domu_ip = self.dom0.xen.get_ip_domuconfig(config_dict)
        self.srv_ip = domu_ip
        if reinit:
            self.init_domu()

        return True