def parse_el_release(self): """ Heuristic garbage :return: """ release_info = dict() if not self.has_redhat_release: return release_info data = deployment.read(self.join_root(self.release_file)) data = data.strip() try: if 'oracle' in self.release_file: version = data.split()[-1] else: release_info['codename'] = data.split()[-1].strip('()') version = data.split()[-2] release_info['version'] = version # Sometimes need short version, not ones like '7.1.1503' # so splitting and then joining [0:2] to get '7.1' release_info['short_version'] = '.'.join(version.split('.')[:2]) # Also need major version, like '7' # rather than short_version like '7.1' release_info['major_version'] = version.split('.')[0] release_info['os'] = data.split('release')[0].strip() except IndexError: log.error('Error parsing {} release file'.format( self.release_file)) return release_info
def update_grub_configuration(self, match, newvalue): grub_configuration = deployment.read( self.join_root(self.grub2_cmdline_config_path)) log.info('Setting {} in {}'.format(newvalue, self.grub2_cmdline_config_path)) updated_grub_configuration = deployment.replace_line_matching( grub_configuration, match, newvalue) deployment.write( self.join_root(self.grub2_cmdline_config_path), updated_grub_configuration)
def copy_udev_rules(self, create_if_missing=False): rules_file = '/etc/udev/rules.d/70-persistent-net.rules' if not os.path.exists(rules_file): log.warn('Host 70-persistent-net.rules is missing') if create_if_missing: log.info('Generating 70-persistent-net.rules') deployment.write( self.join_root(rules_file), "\n\n".join(self.generate_udev_rules()) + "\n") return deployment.write(self.join_root(rules_file), deployment.read(rules_file))
def update_kernel_parameters(self): """ A little hacktastic :return: """ appending = self.kernel_parameters.get('append', list()) removing = self.kernel_parameters.get('remove', list()) modifying = self.kernel_parameters.get('modify', list()) if not (appending or removing): return full_path = self.join_root(self.grub_cmdline_config_path) if not os.path.exists(full_path): log.warn('Grub configuration is missing from image') return data = deployment.read(full_path, splitlines=True) modified = False for idx in range(len(data)): line = data[idx] line = line.strip() if line and line[0] == '#': continue # grub1 is not smart to find efi partition, # have to force it to find. if self.default_grub_root_partition in line and sysfs_info.has_efi( ): if modifying: data[idx] = util.misc.replace_grub_root_partition( line, self.default_grub_root_partition, modifying[0]) modified = True continue if self.grub_cmdline_name in line: data[idx] = util.misc.opts_modifier(line, appending, removing, quoted=False) log.debug('{} > {}'.format(line, data[idx])) modified = True continue if modified: log.info('Updating {}'.format(self.grub_cmdline_config_path)) deployment.replace_file(full_path, '\n'.join(data) + '\n') else: log.warn('Grub configuration was not updated, no matches!')
def set_hostname(self): network_configuration = self.press_configuration.get( 'networking', dict()) hostname = network_configuration.get('hostname') if not hostname: log.warn('Hostname not defined') return log.info('Setting hostname: %s' % hostname) sysconfig_network = deployment.read( self.join_root('/etc/sysconfig/network')) updated_sysconfig_network = deployment.replace_line_matching( sysconfig_network, 'HOSTNAME', 'HOSTNAME=%s' % hostname) deployment.write(self.join_root('/etc/sysconfig/network'), updated_sysconfig_network) deployment.write(self.join_root('/etc/hostname'), hostname + '\n')
def update_kernel_parameters(self): """ A little hacktastic :return: """ appending = self.kernel_parameters.get('append', list()) removing = self.kernel_parameters.get('remove', list()) if not (appending or removing): return full_path = self.join_root(self.grub2_cmdline_config_path) if not os.path.exists(full_path): log.warn('Grub configuration is missing from image') return data = deployment.read(full_path, splitlines=True) modified = False for idx in range(len(data)): line = data[idx] line = line.strip() if line and line[0] == '#': continue if self.grub2_cmdline_name in line: data[idx] = util.misc.opts_modifier(line, appending, removing) log.debug('%s > %s' % (line, data[idx])) modified = True continue if modified: log.info('Updating %s' % self.grub2_cmdline_config_path) deployment.replace_file(full_path, '\n'.join(data) + '\n') else: log.warn('Grub configuration was not updated, no matches!')
def copy_resolvconf(self): if not os.path.exists('/etc/resolv.conf'): log.warn('Host resolv.conf is missing') return deployment.write(self.join_root('/etc/resolv.conf'), deployment.read('/etc/resolv.conf'))