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
def sysuser_get_infos(self, username): """ get passwd entry for username """ __LOG.log_d("getting infos for user %s" % (username)) config = retrieve_config_infos(self)[1] fields_desc = ['username', 'password', 'uid', 'gid', 'infos', 'homedir', 'shell'] passwd_content = __fapi.get_file_content(self.srv_ip, config['passwdfile']) for line in passwd_content.lines: fields = line.split(':') if not len(fields) == 7: continue if fields[0] == username: return True, dict(zip(fields_desc, fields)) return False, None