def setx(cname, cself, value): cls = cself.__class__.__annotations__[cname] if value == None: cself._attributes[cname] = None return if isinstance(cls, int) or cls == int: if not none_null_stringNone(value): cself._attributes[cname] = int(value) elif isinstance(cls, (list, tuple)) or cls in (list, tuple): if not isinstance(value, (list, tuple)) and not none_null_stringNone(value): cself._attributes[cname] = value.split(',') elif isinstance(value, (list, tuple)): cself._attributes[cname] = value else: cself._attributes[cname] = (value, ) elif isinstance(cls, dict) or cls == dict: if not isinstance(value, dict): if not getattr(cself._attributes, cname, None): cself._attributes[cname] = {} for item in value.split(','): if str(item).find(':') > 0: cself._attributes[cname][item.split(':')[0]] = item.split( ':')[1] else: cself._attributes[cname] = value elif isinstance(cls, bool) or cls == bool: cself._attributes[cname] = True if value and str( value).upper() == 'TRUE' else False else: cself._attributes[cname] = value
def get_yml_value(obj:dict,*attrs): if none_null_stringNone(attrs): return obj if none_null_stringNone(obj): return None for i in range(1,len(attrs)+1): s = get_yml_value(obj.get('.'.join(attrs[0:i]),None),*attrs[i:]) if not none_null_stringNone(s): return s return None
def _launchSnapshotWrap(): config = ESSnapshotRestoreConfig() if not none_null_stringNone(self.indexLineText.text().rstrip()): config.index_name = self.indexLineText.text().rstrip() config.http_connect = self.httpConnLineEdit.text().rstrip() _content = self.repositoryLineText.text().rstrip() if none_null_stringNone(_content): log.error('repository is null.') return False if _content.startswith('/'): config.directory = _content else: config.repository = _content self._launchTask(_launchSnapshot,ES_BACKUP,'snapshot',(config,))
def checkBackupOk(self, *args): if none_null_stringNone(self.full_dir[1]) or \ self._config.backup_mode == MysqlBackupConfig._CONS_BACKUP_MODE_INCREMENT and none_null_stringNone(self.incremental_dir[1]): return False for item in (self.full_dir[1], self.incremental_dir[1]): if item: if not self._checkBackupOk(item): return False return True
def check_config(self): result = True result_msg = '' if (none_null_stringNone(self.master_conn_user) or none_null_stringNone(self.master_conn_password) or none_null_stringNone(self.master_host) or \ none_null_stringNone(self.master_port) or none_null_stringNone(self.slave_conn_user) or none_null_stringNone(self.slave_conn_password) or \ none_null_stringNone(self.slave_host) or none_null_stringNone(self.slave_port)): result = False result_msg += ' user or password or host or port is null ' if not self.gtid_enable: if (none_null_stringNone(self.binlog_file) or none_null_stringNone(self.binlog_pos)): result = False result_msg += ' binlog file or binlog pos if null ' return result, result_msg
def expand(param={}): body = '{' for k, v in param.items(): if not none_null_stringNone(v): body += '"' + k + '":' if isinstance(v, bool): body += str(v).lower() elif isinstance(v, (int, float)): body += str(v) elif isinstance(v, str): body += '"' + v + '"' elif isinstance(v, (tuple, list)): _v = [_i for _i in v if not none_null_stringNone(_i)] body += _v.__repr__() if isinstance(v, dict): # value = expand(v) # if value != '{}': # body += value body += expand(v) body += ',' if body[-1] == ',': body = body[:-1] body += '}' return body
def setBackupCnfFile(self, cnffile=None, force=False): if not none_null_stringNone(self.defaults_file[1]) and not force: return data = to_text(self.getMysqldCommand()) if data: self.setSocket(self.getSocketFromCommand(data)) # r = re.search('(defaults-file)=([\S]+)',data) # if r: # self.defaults_file[1] = r.group(2) # else: # self.defaults_file[1] = self.makeCnf() self.defaults_file[1] = self.makeCnf() else: raise MysqldNotRunningException( 'mysqld process not running , it shoud be')
def updateRestoreConfig(self): super(MysqlHotBackup, self).updateRestoreConfig() self.restore_target_dir = self._config.restore_target_dir if not self._sshobject.fileExists(self.restore_target_dir): self._sshobject.mkdir(self.restore_target_dir) if self._sshobject.listdir(self.restore_target_dir): raise EnvironmentCheckException( 'Restore target directory %s must be empty' % self.restore_target_dir) paramf = path_join(self.full_dir[1], self.backup_param_filename) self.getBackupParam(paramf, self.full_backup_param_config) self.mysql_version[1] = self.full_backup_param_config.get( configparser.DEFAULTSECT, self.mysql_version[0], fallback=None) tmpmysqlpath = self.full_backup_param_config.get( configparser.DEFAULTSECT, self.mysql_base[0].replace('-', ''), fallback=None) self.mysql_base[1] = self.getRestoredMysqlBase( (self._config.mysql_software_path, tmpmysqlpath)) if not none_null_stringNone(self._config.server_id): self.server_id[1] = self._config.server_id if self.full_backup_param_config.get(configparser.DEFAULTSECT, self.compress[0].replace('-', ''), fallback=None): self.full_backup_decompress = True if self.incremental_dir[1]: cmd = 'cp -a %s %s' % (self.incremental_dir[1], self.tmp_dir) self._sshobject.execute_cmd(cmd) self.incremental_dir[1] = path_join( self.tmp_dir, self.incremental_dir[1].rpartition('/')[2]) paramf = path_join(self.incremental_dir[1], self.backup_param_filename) if self.incremental_backup_param_config == None: self.incremental_backup_param_config = ConfigParser( allow_no_value=True) self.getBackupParam(paramf, self.incremental_backup_param_config) if self.incremental_backup_param_config.get( configparser.DEFAULTSECT, self.compress[0].replace('-', ''), fallback=None): self.incremental_backup_decompress = True self._sshobject.execute_cmd('cd {};mkdir -p data var log'.format( self.restore_target_dir)) self.datadir[1] = path_join(self.restore_target_dir, 'data') self.log_err_dir = path_join(self.restore_target_dir, 'log') self.setRestoreCnfFile()
def compactItem(self, erase, *args): cmd = '' for item in args: if isinstance(item, (list, tuple)): if len(item) > 2 and string_true_bool( item[2]) or len(item) == 2: name = item[0] if erase: name = item[0].lstrip('-') cmd += ' ' + name if not none_null_stringNone(item[1]): s = item[1] if not isinstance(s, (tuple, list)): s = (s, ) cmd += '=' for k in s: cmd += str(k) + ',' cmd = cmd[:-1] else: cmd += ' ' + str(item) return cmd
def install_check(configs): if none_null_stringNone(configs): log.error('can not install es with no config setting') for config in configs: with ParamikoConnection(config.ssh_host, config.ssh_user, config.ssh_passwd, config.ssh_port) as pk: if not testSSHConnect(pk): log.error('ssh connect to %s@%s:/%s failed, please check!' % (config.ssh_host, config.ssh_user, config.ssh_port)) raise ESInstallCheckException( 'ssh connect to %s@%s:/%s failed, please check!' % (config.ssh_host, config.ssh_user, config.ssh_port)) return False if not pk.fileExists(config.es_tgz_path): log.error( 'elasticsearch software tgz file not exists, stop install!' ) raise ESInstallCheckException( 'elasticsearch software tgz file not exists, stop install!' ) return False if isPortBusy(get_yml_value( config.yml_config, *('http', 'port')), pk) or isPortBusy( get_yml_value(config.yml_config, *('transport', 'tcp', 'port')), pk): log.error( 'http port %s or transport port %s is busy, stop install!' % (get_yml_value(config.yml_config, *('http', 'port')), get_yml_value(config.yml_config, *('transport', 'tcp', 'port')))) raise ESInstallCheckException( 'http port %s or transport port %s is busy, stop install!' % (get_yml_value(config.yml_config, *('http', 'port')), get_yml_value(config.yml_config, *('transport', 'tcp', 'port')))) return False
def checkAndSet(obj, attr, target, t_attr=None): _v = getattr(obj, attr, None) if not none_null_stringNone(_v): if not t_attr: t_attr = attr target[t_attr] = _v
def checkConfig(self): result = True result_msg = '' if (none_null_stringNone(self.host) or none_null_stringNone(self.port) or none_null_stringNone(self.ssh_password) \ or none_null_stringNone(self.ssh_port) or none_null_stringNone(self.ssh_user) or none_null_stringNone(self.backup_base_dir)): result = False result_msg += ' host or port or ssh_user or ssh_password or ssh_port is null ' if self.operate == self._CONS_OPERATE_BACKUP: if (none_null_stringNone(self.user) or none_null_stringNone(self.password)): result = False result_msg += ' user or password is null ' if self.backup_mode == self._CONS_BACKUP_MODE_INCREMENT: if none_null_stringNone(self.backup_base_dir): result = False result_msg += ' user or password is null ' else: if (none_null_stringNone(self.restore_target_dir) or none_null_stringNone(self.mysql_software_path)): result = False result_msg += ' restore_target_dir or mysql_software_path is null ' if self.operate == self._CONS_BACKUP_MODE_LOGIC: if (none_null_stringNone(self.user) or none_null_stringNone(self.password)): result = False result_msg += ' user or password is null ' else: if self.create_slave: if ( none_null_stringNone(self.master_ip) or none_null_stringNone(self.master_password) or none_null_stringNone(self.master_port)\ or none_null_stringNone(self.master_user) or none_null_stringNone(self.replica_password) or none_null_stringNone(self.replica_user) \ or none_null_stringNone(self.server_id)): result = False result_msg += ' create slave ,but master info is null ' if self.operate == self._CONS_BACKUP_MODE_INCREMENT: if none_null_stringNone(self.backup_base_dir): result = False result_msg += ' user or password is null ' return result, result_msg
def setSocket(self, socketfile=None, force=False): if not none_null_stringNone(self.socket[1]) and not force: return self.socket[1] = socketfile if socketfile else getVariable( 'socket', self._conn)