本文整理汇总了Python中GLIUtility.exitsuccess方法的典型用法代码示例。如果您正苦于以下问题:Python GLIUtility.exitsuccess方法的具体用法?Python GLIUtility.exitsuccess怎么用?Python GLIUtility.exitsuccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLIUtility
的用法示例。
在下文中一共展示了GLIUtility.exitsuccess方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _partition_resize_step
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
def _partition_resize_step(self, parted_disk, device, oldparts, newparts):
for oldpart in oldparts:
tmppart_old = oldparts[oldpart]
devnode = tmppart_old['devnode']
newminor = self._find_existing_in_new(oldpart, newparts)
if not newminor or not newparts[newminor]['resized']:
continue
tmppart_new = newparts[newminor]
type = tmppart_new['type']
start = tmppart_new['start']
end = start + (long(tmppart['mb']) * MEGABYTE / 512) - 1
total_sectors = end - start + 1
total_bytes = long(total_sectors) * 512
# Make sure calculated end sector doesn't overlap start sector of next partition
nextminor = self._find_next_partition(newminor, newparts)
if nextminor:
if newparts[nextminor]['start'] and end >= newparts[nextminor]['start']:
self._logger.log(" End sector for growing partition overlaps with start of next partition...fixing")
end = newparts[nextminor]['start'] - 1
# sleep a bit first
time.sleep(3)
# now sleep until it exists
while not GLIUtility.is_file(device + str(minor)):
self._logger.log("Waiting for device node " + devnode + " to exist before resizing")
time.sleep(1)
# one bit of extra sleep is needed, as there is a blip still
time.sleep(3)
if type in ("ext2", "ext3"):
ret = GLIUtility.spawn("resize2fs " + devnode + " " + str(total_sectors) + "s", logfile=self._compile_logfile, append_log=True)
if not GLIUtility.exitsuccess(ret): # Resize error
raise GLIException("PartitionResizeError", 'fatal', 'partition', "could not resize ext2/3 filesystem on " + devnode)
elif type == "ntfs":
ret = GLIUtility.spawn("yes | ntfsresize -v --size " + str(total_bytes) + " " + devnode, logfile=self._compile_logfile, append_log=True)
if not GLIUtility.exitsuccess(ret): # Resize error
raise GLIException("PartitionResizeError", 'fatal', 'partition', "could not resize NTFS filesystem on " + devnode)
elif type in ("linux-swap", "fat32", "fat16"):
parted_fs = parted_disk.get_partition(part).geom.file_system_open()
resize_constraint = parted_fs.get_resize_constraint()
if total_sectors < resize_constraint.min_size or start != resize_constraint.start_range.start:
raise GLIException("PartitionError", 'fatal', 'partition', "New size specified for " + device + str(minor) + " is not within allowed boundaries (blame parted)")
new_geom = resize_constraint.start_range.duplicate()
new_geom.set_start(start)
new_geom.set_end(end)
try:
parted_fs.resize(new_geom)
except:
raise GLIException("PartitionResizeError", 'fatal', 'partition', "could not resize " + device + str(minor))
self._logger.log(" Deleting old minor " + str(oldpart) + " to be recreated in 3rd pass")
self._delete_partition(parted_disk, oldpart)
parted_disk.delete_all()
parted_disk.commit()
示例2: _partition_format_step
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
def _partition_format_step(self, parted_disk, device, newparts):
for part in newparts:
newpart = newparts[part]
devnode = newpart['devnode']
# This little hack is necessary because parted sucks goat nuts
if newparts.get_disklabel() == "mac" and newpart['type'] == "free":
self._delete_partition(parted_disk, newpart)
continue
if newpart['format'] and newpart['type'] not in ('extended', 'free'):
# devnode = device + str(int(part))
if self._debug: self._logger.log("_partition_format_step(): devnode is %s in formatting code" % devnode)
# if you need a special command and
# some base options, place it here.
format_cmds = { 'linux-swap': "mkswap", 'fat16': "mkfs.vfat -F 16", 'fat32': "mkfs.vfat -F 32",
'ntfs': "mkntfs", 'xfs': "mkfs.xfs -f", 'jfs': "mkfs.jfs -f",
'reiserfs': "mkfs.reiserfs -f", 'ext2': "mkfs.ext2", 'ext3': "mkfs.ext3"
}
if newpart['type'] in format_cmds:
cmdname = format_cmds[newpart['type']]
else: # this should catch everything else
raise GLIException("PartitionFormatError", 'fatal', '_partition_format_step', "Unknown partition type " + newpart['type'])
# sleep a bit first
time.sleep(1)
for tries in range(10):
cmd = "%s %s %s" % (cmdname, newpart['mkfsopts'], devnode)
self._logger.log(" Formatting partition %s as %s with: %s" % (str(part),newpart['type'],cmd))
ret = GLIUtility.spawn(cmd, logfile=self._compile_logfile, append_log=True)
if not GLIUtility.exitsuccess(ret):
self._logger.log("Try %d failed formatting partition %s...waiting 5 seconds" % (tries+1, devnode))
time.sleep(5)
else:
break
else:
raise GLIException("PartitionFormatError", 'fatal', '_partition_format_step', "Could not create %s filesystem on %s" % (newpart['type'], devnode))
示例3: start_portmap
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
def start_portmap(self):
if self._configuration.get_verbose(): self._logger.log("DEBUG: beginning of start_portmap()")
status = GLIUtility.spawn('/etc/init.d/portmap start') #, display_on_tty8=True)
if not GLIUtility.exitsuccess(status):
self._logger.log("ERROR! : Could not start the portmap service!")
# raise GLIException("PortmapError", 'warning', 'start_portmap', "Could not start the portmap service!")
else:
self._logger.log("Portmap started.")
示例4: enable_ssh
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
def enable_ssh(self):
if self._configuration.get_verbose(): self._logger.log("DEBUG: beginning of enable_ssh()")
if self._configuration.get_enable_ssh():
status = GLIUtility.spawn("/etc/init.d/sshd start")
if not GLIUtility.exitsuccess(status):
self._logger.log("ERROR! : Could not start the SSH daemon!")
# raise GLIException("SSHError", 'warning','enable_ssh',"Could not start SSH daemon!")
else:
self._logger.log("SSH Started.")
示例5: set_root_passwd
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
def set_root_passwd(self):
self._logger.log("Setting root password.")
if self._configuration.get_root_passwd() != "":
# The password specified in the configuration is encrypted.
status = GLIUtility.spawn("echo 'root:" + self._configuration.get_root_passwd() + "' | chpasswd -e")
if not GLIUtility.exitsuccess(status):
self._logger.log("ERROR! : Could not set the root password on the livecd environment!")
# raise GLIException("PasswordError", 'warning', 'set_root_passwd', "Could not set the root password!")
else:
self._logger.log("Livecd root password set.")
示例6: load_kernel_modules
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
def load_kernel_modules(self):
if self._configuration.get_verbose(): self._logger.log("DEBUG: beginning of load_kernel_modules()")
modules = self._configuration.get_kernel_modules()
if self._configuration.get_verbose(): self._logger.log("DEBUG: load_kernel_modules(): modules are " + str(modules))
for module in modules:
try:
if self._configuration.get_verbose(): self._logger.log("DEBUG: load_kernel_modules(): trying to load module " + module)
ret = GLIUtility.spawn('modprobe ' + module)
if not GLIUtility.exitsuccess(ret):
self._logger.log("ERROR! : Could not load module: "+module)
# raise GLIException("KernelModuleError", 'warning', 'load_kernel_modules', 'Could not load module: ' + module)
else:
self._logger.log('kernel module: ' + module + ' loaded.')
except KernelModuleError, error:
self.output(error)
self._logger.log(error.get_error_level() + '! ' + error.get_error_msg())
示例7: _setup_grub
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
def _setup_grub(self):
#-------------------------------------------------------------
#OK, now that the file is built. Install grub.
#cp /proc/mounts /etc/mtab
#grub-install --root-directory=/boot /dev/hda
#shutil.copy("/proc/mounts",root +"/etc/mtab")
self._gather_grub_drive_info()
grubinstallstring = "echo -en 'root ("+self.grub_boot_drive + "," + self.grub_boot_minor + ")\n"
if not self._install_profile.get_boot_loader_mbr():
grubinstallstring +="setup ("+self.grub_boot_drive + "," + self.grub_boot_minor + ")\n"
else:
grubinstallstring +="setup ("+self.grub_mbr_drive+")\n"
grubinstallstring += "quit\n' | "+self._chroot_dir+"/sbin/grub --batch --no-floppy"
if self._debug: self._logger.log("DEBUG: _configure_grub(): Grub install string: " + grubinstallstring)
exitstatus = GLIUtility.spawn(grubinstallstring, logfile=self._compile_logfile, append_log=True)
if not GLIUtility.exitsuccess(exitstatus):
raise GLIException("GrubInstallError", 'fatal', '_setup_grub', "Could not install grub!")
self._logger.log("Bootloader: grub has been installed!")
示例8: copy_pkg_to_chroot
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False):
symlinks = { '/bin': '/mnt/livecd/bin/', '/boot': '/mnt/livecd/boot/', '/lib': '/mnt/livecd/lib/',
'/opt': '/mnt/livecd/opt/', '/sbin': '/mnt/livecd/sbin/', '/usr': '/mnt/livecd/usr/',
'/etc/gconf': '/usr/livecd/gconf/' }
tmpdir = "/var/tmp/portage"
image_dir = tmpdir + "/" + package.split("/")[1] + "/image"
root_cmd = ""
tmp_chroot_dir = self._chroot_dir
portage_tmpdir = "/var/tmp/portage"
vdb_dir = "/var/db/pkg/"
if use_root:
root_cmd = "ROOT=" + self._chroot_dir
tmp_chroot_dir = ""
portage_tmpdir = self._chroot_dir + "/var/tmp/portage"
vdb_dir = self._chroot_dir + "/var/db/pkg/"
# Create /tmp, /var/tmp, and /var/lib/portage with proper permissions
oldumask = os.umask(0)
if not os.path.exists(self._chroot_dir + "/tmp"):
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /tmp doesn't exist in chroot...creating with proper permissions")
try:
os.mkdir(self._chroot_dir + "/tmp", 01777)
except:
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /tmp in chroot")
if not os.path.exists(self._chroot_dir + "/var/tmp"):
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/tmp doesn't exist in chroot...creating with proper permissions")
try:
os.mkdir(self._chroot_dir + "/var", 0755)
except:
pass
try:
os.mkdir(self._chroot_dir + "/var/tmp", 01777)
except:
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/tmp in chroot")
if not os.path.exists(self._chroot_dir + "/var/lib/portage"):
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/lib/portage doesn't exist in chroot...creating with proper permissions")
try:
os.mkdir(self._chroot_dir + "/var/lib", 0755)
except:
pass
try:
os.mkdir(self._chroot_dir + "/var/lib/portage", 02750)
except:
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/lib/portage in chroot")
os.umask(oldumask)
# Check to see if package is actually in vdb
if not GLIUtility.is_file("/var/db/pkg/" + package):
if ignore_missing:
if self._debug:
self._logger.log("DEBUG: copy_pkg_to_chroot(): package " + package + " does not have a vdb entry but ignore_missing=True...ignoring error")
return
else:
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package)
# Copy the vdb entry for the package from the LiveCD to the chroot
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package)
if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + "/var/db/pkg/" + package + " && cp -a /var/db/pkg/" + package + "/* " + self._chroot_dir + "/var/db/pkg/" + package, logfile=self._compile_logfile, append_log=True)):
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package)
# Create the image dir in the chroot
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'")
if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package)
# Create list of files for tar to work with from CONTENTS file in vdb entry
entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS")
if not entries:
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup")
else:
# if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries))
try:
tarfiles = open("/tmp/tarfilelist", "w")
for entry in entries:
parts = entry.split(" ")
# # Hack for symlink crappiness
# for symlink in symlinks:
# if parts[0].startswith(symlink):
# parts[0] = symlinks[symlink] + parts[0][len(symlink):]
tarfiles.write(parts[0] + "\n")
tarfiles.close()
except:
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package)
# Use tar to transfer files into IMAGE directory
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'tar -cp --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -xp'")
if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -cp --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -xp", logfile=self._compile_logfile, append_log=True)):
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package)
# Fix mode, uid, and gid of directories
# if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running find " + self._chroot_dir + image_dir + " -type d 2>/dev/null | sed -e 's:^" + self._chroot_dir + image_dir + "::' | grep -v '^$'")
# dirlist = GLIUtility.spawn("find " + self._chroot_dir + image_dir + " -type d 2>/dev/null | sed -e 's:^" + self._chroot_dir + image_dir + "::' | grep -v '^$'", return_output=True)[1].strip().split("\n")
# if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): found the following directories: " + str(dirlist))
# if not dirlist or dirlist[0] == "":
# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "directory list entry for " + package + "...this shouldn't happen!")
# for dir in dirlist:
# dirstat = os.stat(dir)
# if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): setting mode " + str(dirstat[0]) + " and uid/gid " + str(dirstat[4]) + "/" + str(dirstat[5]) + " for directory " + self._chroot_dir + image_dir + dir)
# os.chown(self._chroot_dir + image_dir + dir, dirstat[4], dirstat[5])
#.........这里部分代码省略.........
示例9: GLIPortage
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
gliportage = GLIPortage(chroot_dir, True, None, False, None, None)
if mode == "stage3":
if not GLIUtility.is_file("/usr/livecd/systempkgs.txt"):
print "Required file /usr/livecd/systempkgs.txt does not exist!"
sys.exit(1)
try:
syspkgs = open("/usr/livecd/systempkgs.txt", "r")
systempkgs = syspkgs.readlines()
syspkgs.close()
except:
print "Could not open /usr/livecd/systempkgs.txt!"
sys.exit(1)
# Pre-create /lib (and possible /lib32 and /lib64)
if os.path.islink("/lib") and os.readlink("/lib") == "lib64":
if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir " + chroot_dir + "/lib64 && ln -s lib64 " + chroot_dir + "/lib")):
print "Could not precreate /lib64 dir and /lib -> /lib64 symlink"
sys.exit(1)
syspkglen = len(systempkgs)
for i, pkg in enumerate(systempkgs):
pkg = pkg.strip()
print "Copying " + pkg + " (" + str(i+1) + "/" + str(syspkglen) + ")"
gliportage.copy_pkg_to_chroot(pkg, True, ignore_missing=True)
GLIUtility.spawn("cp /etc/make.conf " + chroot_dir + "/etc/make.conf")
GLIUtility.spawn("ln -s `readlink /etc/make.profile` " + chroot_dir + "/etc/make.profile")
GLIUtility.spawn("cp -f /etc/inittab.old " + chroot_dir + "/etc/inittab")
# Nasty, nasty, nasty hack because vapier is a tool
for tmpfile in ("/etc/passwd", "/etc/group", "/etc/shadow"):
GLIUtility.spawn("grep -ve '^gentoo' " + tmpfile + " > " + chroot_dir + tmpfile)
示例10: _configure_grub
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
def _configure_grub(self):
self.build_mode = self._install_profile.get_kernel_build_method()
self._gather_grub_drive_info()
root = self._chroot_dir
exitstatus2, kernel_names = GLIUtility.spawn("ls -1 --color=no " + root + "/boot/pentoo", return_output=True)
self._logger.log("Output of Kernel Names:\n"+kernel_names)
if not GLIUtility.exitsuccess(exitstatus2):
raise GLIException("BootloaderError", 'fatal', '_configure_grub', "Error listing the kernels in /boot")
if self.build_mode == "genkernel" or self._install_profile.get_kernel_source_pkg() == "livecd-kernel":
exitstatus3, initrd_names = GLIUtility.spawn("ls -1 --color=no " + root + "/boot/pentoo.igz", return_output=True)
self._logger.log("Output of Initrd Names:\n"+initrd_names)
if not GLIUtility.exitsuccess(exitstatus3):
raise GLIException("BootloaderError", 'fatal', '_configure_grub', "Error listing the initrds")
self._logger.log("Bootloader: the three information gathering commands have been run")
if not kernel_names[0]:
raise GLIException("BootloaderError", 'fatal', '_configure_grub',"Error: We have no kernel in /boot to put in the grub.conf file!")
#-------------------------------------------------------------
#OK, now that we have all the info, let's build that grub.conf
newgrubconf = ""
newgrubconf += "default 0\ntimeout 30\n"
if self.foundboot: #we have a /boot
newgrubconf += "splashimage=(" + self.grub_boot_drive + "," + self.grub_boot_minor + ")/grub/splash.xpm.gz\n"
else: #we have / and /boot needs to be included
newgrubconf += "splashimage=(" + self.grub_boot_drive + "," + self.grub_boot_minor + ")/boot/grub/splash.xpm.gz\n"
if self._install_profile.get_bootloader_kernel_args():
bootloader_kernel_args = self._install_profile.get_bootloader_kernel_args()
else: bootloader_kernel_args = ""
kernel_names = map(string.strip, kernel_names.strip().split("\n"))
initrd_names = map(string.strip, initrd_names.strip().split("\n"))
grub_kernel_name = kernel_names[-1].split(root)[-1]
if initrd_names: grub_initrd_name = initrd_names[-1].split(root)[-1]
# for i in range(len(kernel_names)):
# grub_kernel_name = kernel_names[i].split(root)[-1]
# for i in range(len(initrd_names)): #this should be okay if blank.
# grub_initrd_name = initrd_names[i].split(root)[-1]
#i think this means take the last one it finds.. i.e. the newest.
newgrubconf += "title=Gentoo Linux\n"
newgrubconf += "root (" + self.grub_boot_drive + "," + self.grub_boot_minor + ")\n"
if self.build_mode != "genkernel" and self._install_profile.get_kernel_source_pkg() != "livecd-kernel": #using CUSTOM kernel
if self.foundboot:
newgrubconf += "kernel " + grub_kernel_name[5:] + " root="+self.root_device+self.root_minor+"\n"
else:
newgrubconf += "kernel /boot"+ grub_kernel_name[5:] + " root="+self.root_device+self.root_minor+"\n"
else: #using genkernel so it has an initrd.
if self.foundboot:
newgrubconf += "kernel " + grub_kernel_name[5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root="
newgrubconf += self.root_device + self.root_minor + " " + bootloader_kernel_args + "\n"
newgrubconf += "initrd " + grub_initrd_name[5:] + "\n"
else:
newgrubconf += "kernel /boot" + grub_kernel_name[5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root="
newgrubconf += self.root_device + self.root_minor + " " + bootloader_kernel_args + "\n"
newgrubconf += "initrd /boot" + grub_initrd_name[5:] + "\n"
newgrubconf = self._grub_add_windows(newgrubconf)
#now make the grub.conf file
file_name = root + "/boot/grub/grub.conf"
try:
shutil.move(file_name, file_name + ".OLDdefault")
except:
pass
f = open(file_name, 'w')
f.writelines(newgrubconf)
f.close()
self._logger.log("Grub installed and configured. Contents of grub.conf:\n"+newgrubconf)
self._logger.log("Grub has not yet been run. If a normal install, it will now be run.")
示例11: configure_networking
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
def configure_networking(self):
if self._configuration.get_verbose(): self._logger.log("DEBUG: beginning of configure_networking()")
# Do networking setup right here.
if self._configuration.get_network_type() != None:
type = self._configuration.get_network_type()
if type == "null" or type == "none":
# don't do anything, it's not our problem if the user specifies this.
return
elif type == "dhcp":
if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): DHCP selected")
# Run dhcpcd.
try:
interface = self._configuration.get_network_interface()
dhcp_options = self._configuration.get_network_dhcp_options()
except:
self._logger.log("No interface found.. defaulting to eth0.")
interface = "eth0"
dhcp_options = ""
if interface and not dhcp_options:
if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): running '/sbin/dhcpcd -n " + interface + "'")
status = GLIUtility.spawn("/sbin/dhcpcd -t 15 -n " + interface)
elif interface and dhcp_options:
if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): running '/sbin/dhcpcd " + dhcp_options + " " + interface + "'")
status = GLIUtility.spawn("/sbin/dhcpcd -t 15 " + dhcp_options + " " + interface)
else:
if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): running '/sbin/dhcpcd -n'")
status = GLIUtility.spawn("/sbin/dhcpcd -t 15 -n")
if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): call to /sbin/dhcpcd complete")
if not GLIUtility.exitsuccess(status):
raise GLIException("DHCPError", 'fatal', 'configure_networking', "Failed to get a dhcp address for " + interface + ".")
elif type == "manual" and self._configuration.get_interactive():
# Drop to bash shell and let them configure it themselves
print "Please configure & test your network device."
GLIUtility.spawn_bash()
elif type == "manual" and not self._interactive.get_interactive():
print "You cannot manually configure the network in non-interactive mode!"
print "Please fix either the network settings or the interactive mode!"
sys.exit(1)
elif type == "static":
if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): setting static IP")
# Configure the network from the settings they gave.
net_interface = self._configuration.get_network_interface()
net_ip = self._configuration.get_network_ip()
net_broadcast = self._configuration.get_network_broadcast()
net_netmask = self._configuration.get_network_netmask()
if not GLIUtility.set_ip(net_interface, net_ip, net_broadcast, net_netmask):
raise GLIException("SetIPError", 'fatal', 'configure_networking', "Could not set the IP address!")
route = self._configuration.get_network_gateway()
if not GLIUtility.set_default_route(route):
raise GLIException("DefaultRouteError", 'fatal','configure_networking', "Could not set the default route!")
dns_servers = self._configuration.get_dns_servers()
if dns_servers:
try:
resolv_conf = open("/etc/resolv.conf", "w")
for dns_server in dns_servers:
resolv_conf.write("nameserver " + dns_server + "\n")
resolv_conf.close()
except:
raise GLIException("DNSServerError", 'fatal','configure_networking', "Could not set the DNS servers!")
if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): done setting static IP")
示例12: _configure_yaboot
# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import exitsuccess [as 别名]
def _configure_yaboot(self):
build_mode = self._install_profile.get_kernel_build_method()
root_device = ""
root_minor = ""
parts = self._install_profile.get_partition_tables()
for device in parts:
tmp_partitions = parts[device]
for partition in tmp_partitions:
mountpoint = tmp_partitions[partition]['mountpoint']
if mountpoint == "/":
root_minor = str(int(tmp_partitions[partition]['minor']))
root_device = device
if self._install_profile.get_bootloader_kernel_args(): bootloader_kernel_args = self._install_profile.get_bootloader_kernel_args()
else: bootloader_kernel_args = ""
#Assuming the config program works as specified, it should do the majority of the work.
#this is the white rabbit object. antarus: it expects a full fstab, /proc mounted, and a kernel in /boot/vmlinux. The manaul also says /dev must be bind-mounted.
exitstatus = GLIUtility.spawn("yabootconfig --chroot "+self._chroot_dir+" --quiet", display_on_tty8=True)
if not GLIUtility.exitsuccess(exitstatus):
raise GLIException("YabootError",'fatal','_configure_yaboot',"Could not successfully run the yabootconfig command.")
#Hopefully now an /etc/yaboot.conf exists but does not have the correct kernel/Sysmap information.
#We must gather that info like we have done for the other bootloaders.
file_name = self._chroot_dir + "/boot/kernel_name"
file_name2 = self._chroot_dir + "/boot/initrd_name"
exitstatus2 = GLIUtility.spawn("ls "+root+"/boot/kernel-* > "+file_name)
if build_mode == "genkernel":
exitstatus3 = GLIUtility.spawn("ls "+root+"/boot/initramfs-* > "+file_name2)
else:
exitstatus3 = GLIUtility.spawn("touch "+file_name2)
if (exitstatus2 != 0) or (exitstatus3 != 0):
raise GLIException("BootloaderError", 'fatal', '_configure_yaboot', "Error in one of THE TWO run commands")
self._logger.log("Bootloader: the three information gathering commands have been run")
g = open(file_name)
h = open(file_name2)
initrd_name = h.readlines()
kernel_name = g.readlines()
g.close()
h.close()
if not kernel_name[0]:
raise GLIException("BootloaderError", 'fatal', '_configure_yaboot',"Error: We have no kernel in /boot to put in the yaboot.conf file!")
kernel_name = map(string.strip, kernel_name)
initrd_name = map(string.strip, initrd_name)
for i in range(len(kernel_name)):
kernel_name = kernel_name[i].split(root)[1]
for i in range(len(initrd_name)):
initrd_name = initrd_name[i].split(root)[1]
#Open the file and edit the right lines
f = open(self._chroot_dir+"/etc/yaboot.conf")
contents = f.readlines()
f.close()
for i in range(0, len(contents)):
if contents[i] == "image=/boot/vmlinux":
contents[i] = "image=/boot/"+kernel_name[5:]
if build_mode == "genkernel":
#insert /dev/ram0 line
contents.insert("root=/dev/ram0",i+2)
#insert partition line.
contents.insert("partition="+root_minor,i+3)
#edit append line. use root_device and root_minor.
contents.insert("append=\"real_root="+root_device+root_minor+ " init=/linuxrc "+bootloader_kernel_args + "\" \n", i+4)
f = open(self._chroot_dir+"/etc/yaboot.conf",'w')
f.writelines(contents)
f.close()