def set_dhcp_hostname(self, hostname): dhcp_config_file_path = '/etc/sysconfig/network/dhcp' hostname_send_setting = fileutil.get_line_startingwith( 'DHCLIENT_HOSTNAME_OPTION', dhcp_config_file_path) if hostname_send_setting: value = hostname_send_setting.split('=')[-1] if value == '"AUTO"' or value == '"{0}"'.format(hostname): # Return if auto send host-name is configured or the current # hostname is already set up to be sent return else: # Do not use update_conf_file as it moves the setting to the # end of the file separating it from the contextual comment new_conf = [] dhcp_conf = fileutil.read_file(dhcp_config_file_path).split( '\n') for entry in dhcp_conf: if entry.startswith('DHCLIENT_HOSTNAME_OPTION'): new_conf.append( 'DHCLIENT_HOSTNAME_OPTION="{0}"'.format(hostname)) continue new_conf.append(entry) fileutil.write_file(dhcp_config_file_path, '\n'.join(new_conf)) else: fileutil.append_file( dhcp_config_file_path, 'DHCLIENT_HOSTNAME_OPTION="{0}"'.format(hostname))
def is_sys_user(self, username): """ Check whether use is a system user. If reset sys user is allowed in conf, return False Otherwise, check whether UID is less than UID_MIN """ if conf.get_allow_reset_sys_user(): return False userentry = self.get_userentry(username) uidmin = None try: uidmin_def = fileutil.get_line_startingwith( "UID_MIN", "/etc/login.defs") if uidmin_def is not None: uidmin = int(uidmin_def.split()[1]) except IOError as e: pass if uidmin == None: uidmin = 100 if userentry != None and userentry[2] < uidmin: return True else: return False
def is_sys_user(self, username): """ Check whether use is a system user. If reset sys user is allowed in conf, return False Otherwise, check whether UID is less than UID_MIN """ if conf.get_allow_reset_sys_user(): return False userentry = self.get_userentry(username) uidmin = None try: uidmin_def = fileutil.get_line_startingwith("UID_MIN", "/etc/login.defs") if uidmin_def is not None: uidmin = int(uidmin_def.split()[1]) except IOError as e: pass if uidmin == None: uidmin = 100 if userentry != None and userentry[2] < uidmin: return True else: return False