def apply(self, ksnet): path = self.path("/etc/network/interfaces") fs.makedirs(path) f = file(path, "w+") c = "auto lo\n" c += "iface lo inet loopback\n" f.write(c) useipv6 = False nodns = False hostname = None gateway = None nameservers = None for network in ksnet.network: if not network.device: raise errors.KickstartError("No --device specified with " "network kickstart command") if (network.onboot and network.bootProto.lower() != "dhcp" and not (network.ip and network.netmask)): raise errors.KickstartError("No IP address and/or netmask " "specified with static " "configuration for '%s'" % network.device) # self.write_ifcfg(network) # self.write_wepkey(network) if network.ipv6: useipv6 = True if network.nodns: nodns = True if network.hostname: hostname = network.hostname if network.gateway: gateway = network.gateway if network.nameserver: nameservers = network.nameserver.split(",") # self.write_sysconfig(useipv6, hostname, gateway) self.write_hosts(hostname) self.write_resolv(nodns, nameservers)
def apply(self, ksnet): path = self.path("/etc/network/interfaces") fs.makedirs(path) f = file(path, "w+") c = "auto lo\n" c += "iface lo inet loopback\n" f.write(c) useipv6 = False nodns = False hostname = None gateway = None nameservers = None for network in ksnet.network: if not network.device: raise errors.KickstartError("No --device specified with " "network kickstart command") if network.onboot and network.bootProto.lower() != "dhcp" and not (network.ip and network.netmask): raise errors.KickstartError( "No IP address and/or netmask " "specified with static " "configuration for '%s'" % network.device ) # self.write_ifcfg(network) # self.write_wepkey(network) if network.ipv6: useipv6 = True if network.nodns: nodns = True if network.hostname: hostname = network.hostname if network.gateway: gateway = network.gateway if network.nameserver: nameservers = network.nameserver.split(",") # self.write_sysconfig(useipv6, hostname, gateway) self.write_hosts(hostname) self.write_resolv(nodns, nameservers)
def apply(self, ksnet): fs.makedirs(self.path("/etc/sysconfig/network-scripts")) useipv6 = False nodns = False hostname = None gateway = None nameservers = None for network in ksnet.network: if not network.device: raise errors.KickstartError("No --device specified with " "network kickstart command") if (network.onboot and network.bootProto.lower() != "dhcp" and not (network.ip and network.netmask)): raise errors.KickstartError("No IP address and/or netmask " "specified with static " "configuration for '%s'" % network.device) self.write_ifcfg(network) self.write_wepkey(network) if network.ipv6: useipv6 = True if network.nodns: nodns = True if network.hostname: hostname = network.hostname if network.gateway: gateway = network.gateway if network.nameserver: nameservers = network.nameserver.split(",") self.write_sysconfig(useipv6, hostname, gateway) self.write_hosts(hostname) self.write_hostname(hostname) self.write_resolv(nodns, nameservers)
def mount(self, base_on=None, cachedir=None): self.__ensure_builddir() makedirs(self._instroot) makedirs(self._outdir) self._mount_instroot(base_on) self.__fstype = self.__separate_images.pop("/") key = lambda x: len(x.rstrip("/").split("/")) for mountpoint in sorted(self.__separate_images.keys(), key=key): makedirs(self._instroot + mountpoint) loop_disk = ExtDiskMount( SparseLoopbackDisk(self._get_image_name(mountpoint), 4 * 1024L * 1024 * 1024), self._instroot + mountpoint, self.__separate_images[mountpoint], 4096, # blocksize self.fslabel, self.tmpdir, ) self.__separate_images_disks.append(loop_disk) try: loop_disk.mount() except MountError, e: raise CreatorError("Failed to loopback mount '%s' : %s" % (self._get_image_name(mountpoint), e))
def mount(self, base_on=None, cachedir=None): self.__ensure_builddir() makedirs(self._instroot) makedirs(self._outdir) self._mount_instroot(base_on) self.__fstype = self.__separate_images.pop('/') key = lambda x: len(x.rstrip('/').split('/')) for mountpoint in sorted(self.__separate_images.keys(), key=key): makedirs(self._instroot + mountpoint) loop_disk = ExtDiskMount( SparseLoopbackDisk(self._get_image_name(mountpoint), 4 * 1024L * 1024 * 1024), self._instroot + mountpoint, self.__separate_images[mountpoint], 4096, # blocksize self.fslabel, self.tmpdir) self.__separate_images_disks.append(loop_disk) try: loop_disk.mount() except MountError, e: raise CreatorError("Failed to loopback mount '%s' : %s" % (self._get_image_name(mountpoint), e))
class ImageCreator(imgcreate.LoopImageCreator): MODULES = [ 'xenblk', 'xen_blkfront', 'virtio_net', 'virtio_pci', 'virtio_blk', 'virtio_balloon', 'e1000', 'sym53c8xx', 'scsi_transport_sas', 'mptbase', 'mptscsih', 'sd_mod', 'mptsas', 'sg' ] def __init__(self, ksfile, name, tmpdir=None, cachedir=None, export_kernel=False, separate_images=None, output_file=None): super(ImageCreator, self).__init__(imgcreate.read_kickstart(ksfile), name, '/') self.tmpdir = tmpdir or tempfile.gettempdir() if not os.path.exists(self.tmpdir): LOG.info('Creating tmp directory') os.makedirs(self.tmpdir) self.cachedir = cachedir or os.path.join(os.getcwd(), 'cache') self.export_kernel = export_kernel self.MODULES.extend(imgcreate.kickstart.get_modules(self.ks)) self.__selinux_mountpoint = "/sys/fs/selinux" # this will mount mirror into chroot and then unmount self.__output_file = output_file self.__ensure_builddir() self.__bindmounts = [BindChrootMount('/mirror', self._instroot)] self.__separate_images = {} self.__separate_images_disks = [] self.__imgdir = None for ent in separate_images.split(): mountpoint, fs_type = ent.split(',') self.__separate_images[mountpoint] = fs_type def __get_image(self): if self.__imgdir is None: self.__imgdir = self._mkdtemp() return self.__imgdir + "/" + self.name + ".img" _image = property(__get_image) def _get_fstab(self): s = 'LABEL=_/ / %s defaults 0 0\n' % self._fstype s += self._get_fstab_special() return s def _get_kernel_options(self): s = imgcreate.kickstart.get_kernel_args(self.ks, default='ro') return s def _create_bootconfig(self): LOG.info('Preparing bootloader config') imgtemplate = """ title %(title)s %(version)s root (hd0) kernel /boot/%(kernel)s root=LABEL=_/ %(bootargs)s initrd /boot/%(initrd)s """ cfg = """ default=0 timeout=%(timeout)s """ % { 'timeout': imgcreate.kickstart.get_timeout(self.ks, 5) } kernels = self._get_kernel_versions() for version in reduce(lambda x, y: x + y, kernels.values(), []): kernel = 'vmlinuz-%s' % version initrd = 'initrd-%s.img' % version if not os.path.exists(self._instroot + '/boot/' + initrd): initrd = 'initramfs-%s.img' % version cfg += imgtemplate % { 'title': self.name, 'initrd': initrd, 'kernel': kernel, 'version': version, 'bootargs': self._get_kernel_options() } with open(self._instroot + '/boot/grub/grub.conf', 'w') as f: f.write(cfg) def _custom_export_kernel(self): LOG.info('Extracting kernel and initramfs') for filename in os.listdir(self._instroot + '/boot'): if filename.startswith('initr') or filename.startswith('vmlinuz'): shutil.copyfile(self._instroot + '/boot/' + filename, os.path.join(os.getcwd(), filename)) def _custom_dracut_conf(self): LOG.info('Preparing dracut configuration') filename = os.path.join(self._instroot, '/etc/dracut.conf.d/fuel.conf') directory = os.path.dirname(filename) os.path.exists(directory) or os.makedirs(directory) config = """ filesystems+=' %(image_filesystem)s ' drivers+=' %(modules)s ' """ % { 'image_filesystem': self._fstype, 'modules': ' '.join(self.MODULES) } with open(filename, 'w') as f: f.write(config) def _get_image_name(self, mountpoint): return self._mkdtemp() + "/" + self.name + \ mountpoint.replace('/', '-') + ".img" def mount(self, base_on=None, cachedir=None): self.__ensure_builddir() makedirs(self._instroot) makedirs(self._outdir) self._mount_instroot(base_on) self.__fstype = self.__separate_images.pop('/') key = lambda x: len(x.rstrip('/').split('/')) for mountpoint in sorted(self.__separate_images.keys(), key=key): makedirs(self._instroot + mountpoint) loop_disk = ExtDiskMount( SparseLoopbackDisk(self._get_image_name(mountpoint), 4 * 1024L * 1024 * 1024), self._instroot + mountpoint, self.__separate_images[mountpoint], 4096, # blocksize self.fslabel, self.tmpdir) self.__separate_images_disks.append(loop_disk) try: loop_disk.mount() except MountError, e: raise CreatorError("Failed to loopback mount '%s' : %s" % (self._get_image_name(mountpoint), e)) self.__separate_images_disks.reverse() self.__separate_images_disks.append(self._LoopImageCreator__instloop) for d in ("/dev/pts", "/etc", "/boot", "/var/log", "/var/cache/yum", "/sys", "/proc"): makedirs(self._instroot + d) cachesrc = cachedir or (self.__builddir + "/yum-cache") makedirs(cachesrc) # bind mount system directories into _instroot for (f, dest) in [("/sys", None), ("/proc", None), ("/dev/pts", None), ("/dev/shm", None), (self.__selinux_mountpoint, self.__selinux_mountpoint), (cachesrc, "/var/cache/yum")]: if os.path.exists(f): self.__bindmounts.append( BindChrootMount(f, self._instroot, dest)) else: logging.warn("Skipping (%s,%s) because source doesn't exist." % (f, dest)) self._do_bindmounts() self.__create_selinuxfs() self.__create_minimal_dev() os.symlink("/proc/self/mounts", self._instroot + "/etc/mtab") self.__write_fstab()