本文整理汇总了Python中utils.rmfile函数的典型用法代码示例。如果您正苦于以下问题:Python rmfile函数的具体用法?Python rmfile怎么用?Python rmfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rmfile函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_single_profile
def remove_single_profile(self, name, rebuild_menu=True):
# delete profiles/$name file in webdir
utils.rmfile(os.path.join(self.settings.webdir, "profiles", name))
# delete contents on kickstarts/$name directory in webdir
utils.rmtree(os.path.join(self.settings.webdir, "kickstarts", name))
if rebuild_menu:
self.sync.pxegen.make_pxe_menu()
示例2: clean_trees
def clean_trees(self):
"""
Delete any previously built pxelinux.cfg tree and virt tree info and then create
directories.
Note: for SELinux reasons, some information goes in /tftpboot, some in /var/www/cobbler
and some must be duplicated in both. This is because PXE needs tftp, and auto-kickstart
and Virt operations need http. Only the kernel and initrd images are duplicated, which is
unfortunate, though SELinux won't let me give them two contexts, so symlinks are not
a solution. *Otherwise* duplication is minimal.
"""
# clean out parts of webdir and all of /tftpboot/images and /tftpboot/pxelinux.cfg
for x in os.listdir(self.settings.webdir):
path = os.path.join(self.settings.webdir, x)
if os.path.isfile(path):
if not x.endswith(".py"):
utils.rmfile(path, logger=self.logger)
if os.path.isdir(path):
if x not in ["aux", "web", "webui", "localmirror", "repo_mirror", "ks_mirror", "images", "links", "pub", "repo_profile", "repo_system", "svc", "rendered", ".link_cache"]:
# delete directories that shouldn't exist
utils.rmtree(path, logger=self.logger)
if x in ["kickstarts", "kickstarts_sys", "images", "systems", "distros", "profiles", "repo_profile", "repo_system", "rendered"]:
# clean out directory contents
utils.rmtree_contents(path, logger=self.logger)
#
self.make_tftpboot()
utils.rmtree_contents(self.pxelinux_dir, logger=self.logger)
utils.rmtree_contents(self.grub_dir, logger=self.logger)
utils.rmtree_contents(self.images_dir, logger=self.logger)
utils.rmtree_contents(self.yaboot_bin_dir, logger=self.logger)
utils.rmtree_contents(self.yaboot_cfg_dir, logger=self.logger)
utils.rmtree_contents(self.rendered_dir, logger=self.logger)
示例3: remove_single_system
def remove_single_system(self, name):
bootloc = utils.tftpboot_location()
system_record = self.systems.find(name=name)
# delete contents of kickstarts_sys/$name in webdir
system_record = self.systems.find(name=name)
if self.settings.manage_dhcp:
if self.settings.omapi_enabled:
for (name,interface) in system_record.interfaces.iteritems():
self.sync.dhcp.remove_dhcp_lease(
self.settings.omapi_port,
interface["dns_name"]
)
itanic = False
profile = self.profiles.find(name=system_record.profile)
if profile is not None:
distro = self.distros.find(name=profile.distro)
if distro is not None and distro in [ "ia64", "IA64"]:
itanic = True
for (name,interface) in system_record.interfaces.iteritems():
filename = utils.get_config_filename(system_record,interface=name)
if not itanic:
utils.rmfile(os.path.join(bootloc, "pxelinux.cfg", filename))
else:
utils.rmfile(os.path.join(bootloc, filename))
示例4: remove_single_distro
def remove_single_distro(self, name):
bootloc = utils.tftpboot_location()
# delete contents of images/$name directory in webdir
utils.rmtree(os.path.join(self.settings.webdir, "images", name))
# delete contents of images/$name in tftpboot
utils.rmtree(os.path.join(bootloc, "images", name))
# delete potential symlink to tree in webdir/links
utils.rmfile(os.path.join(self.settings.webdir, "links", name))
示例5: remove_single_system
def remove_single_system(self, name):
bootloc = utils.tftpboot_location()
system_record = self.systems.find(name=name)
# delete contents of kickstarts_sys/$name in webdir
system_record = self.systems.find(name=name)
for (name, interface) in system_record.interfaces.iteritems():
filename = utils.get_config_filename(system_record, interface=name)
utils.rmfile(os.path.join(bootloc, "pxelinux.cfg", filename))
utils.rmfile(os.path.join(bootloc, "grub", filename.upper()))
示例6: remove_single_system
def remove_single_system(self, name):
bootloc = utils.tftpboot_location()
system_record = self.systems.find(name=name)
# delete contents of kickstarts_sys/$name in webdir
system_record = self.systems.find(name=name)
itanic = False
profile = self.profiles.find(name=system_record.profile)
if profile is not None:
distro = self.distros.find(name=profile.get_conceptual_parent().name)
if distro is not None and distro in [ "ia64", "IA64"]:
itanic = True
for (name,interface) in system_record.interfaces.iteritems():
filename = utils.get_config_filename(system_record,interface=name)
if not itanic:
utils.rmfile(os.path.join(bootloc, "pxelinux.cfg", filename))
else:
utils.rmfile(os.path.join(bootloc, filename))
示例7: write_pxe_file
#.........这里部分代码省略.........
# choose a template
if system:
if format == "grub":
template = os.path.join(self.settings.pxe_template_dir, "grubsystem.template")
else: # pxe
if system.netboot_enabled:
template = os.path.join(self.settings.pxe_template_dir,"pxesystem.template")
if arch.startswith("s390"):
template = os.path.join(self.settings.pxe_template_dir,"pxesystem_s390x.template")
elif arch == "ia64":
template = os.path.join(self.settings.pxe_template_dir,"pxesystem_ia64.template")
elif arch.startswith("ppc"):
template = os.path.join(self.settings.pxe_template_dir,"pxesystem_ppc.template")
elif arch.startswith("arm"):
template = os.path.join(self.settings.pxe_template_dir,"pxesystem_arm.template")
elif distro and distro.os_version.startswith("esxi"):
# ESXi uses a very different pxe method, using more files than
# a standard kickstart and different options - so giving it a dedicated
# PXE template makes more sense than shoe-horning it into the existing
# templates
template = os.path.join(self.settings.pxe_template_dir,"pxesystem_esxi.template")
else:
# local booting on ppc requires removing the system-specific dhcpd.conf filename
if arch is not None and arch.startswith("ppc"):
# Disable yaboot network booting for all interfaces on the system
for (name,interface) in system.interfaces.iteritems():
filename = "%s" % utils.get_config_filename(system, interface=name).lower()
# Remove symlink to the yaboot binary
f3 = os.path.join(self.bootloc, "ppc", filename)
if os.path.lexists(f3):
utils.rmfile(f3)
# Remove the interface-specific config file
f3 = os.path.join(self.bootloc, "etc", filename)
if os.path.lexists(f3):
utils.rmfile(f3)
# Yaboot/OF doesn't support booting locally once you've
# booted off the network, so nothing left to do
return None
elif arch is not None and arch.startswith("s390"):
template = os.path.join(self.settings.pxe_template_dir,"pxelocal_s390x.template")
elif arch is not None and arch.startswith("ia64"):
template = os.path.join(self.settings.pxe_template_dir,"pxelocal_ia64.template")
else:
template = os.path.join(self.settings.pxe_template_dir,"pxelocal.template")
else:
# not a system record, so this is a profile record or an image
if arch.startswith("s390"):
template = os.path.join(self.settings.pxe_template_dir,"pxeprofile_s390x.template")
if arch.startswith("arm"):
template = os.path.join(self.settings.pxe_template_dir,"pxeprofile_arm.template")
elif format == "grub":
template = os.path.join(self.settings.pxe_template_dir,"grubprofile.template")
elif distro and distro.os_version.startswith("esxi"):
# ESXi uses a very different pxe method, see comment above in the system section
template = os.path.join(self.settings.pxe_template_dir,"pxeprofile_esxi.template")
else:
template = os.path.join(self.settings.pxe_template_dir,"pxeprofile.template")
if kernel_path is not None:
metadata["kernel_path"] = kernel_path
示例8: write_all_system_files
def write_all_system_files(self, system):
profile = system.get_conceptual_parent()
if profile is None:
raise CX("system %(system)s references a missing profile %(profile)s" % { "system" : system.name, "profile" : system.profile})
distro = profile.get_conceptual_parent()
image_based = False
image = None
if distro is None:
if profile.COLLECTION_TYPE == "profile":
raise CX("profile %(profile)s references a missing distro %(distro)s" % { "profile" : system.profile, "distro" : profile.distro})
else:
image_based = True
image = profile
# hack: s390 generates files per system not per interface
if not image_based and distro.arch.startswith("s390"):
# Always write a system specific _conf and _parm file
f2 = os.path.join(self.bootloc, "s390x", "s_%s" % system.name)
cf = "%s_conf" % f2
pf = "%s_parm" % f2
template_cf = open("/etc/cobbler/pxe/s390x_conf.template")
template_pf = open("/etc/cobbler/pxe/s390x_parm.template")
blended = utils.blender(self.api, True, system)
self.templar.render(template_cf, blended, cf)
# FIXME: profiles also need this data!
# FIXME: the _conf and _parm files are limited to 80 characters in length
try:
ipaddress = socket.gethostbyname_ex(blended["http_server"])[2][0]
except socket.gaierror:
ipaddress = blended["http_server"]
kickstart_path = "http://%s/cblr/svc/op/ks/system/%s" % (ipaddress, system.name)
# gather default kernel_options and default kernel_options_s390x
kopts = blended.get("kernel_options","")
hkopts = shlex.split(utils.hash_to_string(kopts))
blended["kickstart_expanded"] = "ks=%s" % kickstart_path
blended["kernel_options"] = hkopts
self.templar.render(template_pf, blended, pf)
# Write system specific zPXE file
if system.is_management_supported():
self.write_pxe_file(f2, system, profile, distro, distro.arch)
else:
# ensure the file doesn't exist
utils.rmfile(f2)
return
pxe_metadata = {'pxe_menu_items': self.get_menu_items()['pxe'] }
# generate one record for each described NIC ..
for (name,interface) in system.interfaces.iteritems():
ip = interface["ip_address"]
f1 = utils.get_config_filename(system, interface=name)
if f1 is None:
self.logger.warning("invalid interface recorded for system (%s,%s)" % (system.name,name))
continue;
if image_based:
working_arch = image.arch
else:
working_arch = distro.arch
if working_arch is None:
raise "internal error, invalid arch supplied"
# for tftp only ...
grub_path = None
if working_arch in [ "i386", "x86", "x86_64", "arm", "standard"]:
# pxelinux wants a file named $name under pxelinux.cfg
f2 = os.path.join(self.bootloc, "pxelinux.cfg", f1)
# Only generating grub menus for these arch's:
grub_path = os.path.join(self.bootloc, "grub", f1.upper())
elif working_arch == "ia64":
# elilo expects files to be named "$name.conf" in the root
# and can not do files based on the MAC address
if ip is not None and ip != "":
self.logger.warning("Warning: Itanium system object (%s) needs an IP address to PXE" % system.name)
filename = "%s.conf" % utils.get_config_filename(system,interface=name)
f2 = os.path.join(self.bootloc, filename)
elif working_arch.startswith("ppc"):
# Determine filename for system-specific yaboot.conf
filename = "%s" % utils.get_config_filename(system, interface=name).lower()
f2 = os.path.join(self.bootloc, "etc", filename)
# Link to the yaboot binary
f3 = os.path.join(self.bootloc, "ppc", filename)
if os.path.lexists(f3):
utils.rmfile(f3)
os.symlink("../yaboot", f3)
else:
continue
#.........这里部分代码省略.........
示例9: write_all_system_files
def write_all_system_files(self, system, menu_items):
profile = system.get_conceptual_parent()
if profile is None:
raise CX("system %(system)s references a missing profile %(profile)s" % {"system": system.name, "profile": system.profile})
distro = profile.get_conceptual_parent()
image_based = False
image = None
if distro is None:
if profile.COLLECTION_TYPE == "profile":
raise CX("profile %(profile)s references a missing distro %(distro)s" % {"profile": system.profile, "distro": profile.distro})
else:
image_based = True
image = profile
pxe_metadata = {'pxe_menu_items': menu_items}
# generate one record for each described NIC ..
for (name, interface) in system.interfaces.iteritems():
f1 = utils.get_config_filename(system, interface=name)
if f1 is None:
self.logger.warning("invalid interface recorded for system (%s,%s)" % (system.name, name))
continue
if image_based:
working_arch = image.arch
else:
working_arch = distro.arch
if working_arch is None:
raise "internal error, invalid arch supplied"
# for tftp only ...
grub_path = None
if working_arch in ["i386", "x86", "x86_64", "arm", "standard"]:
# pxelinux wants a file named $name under pxelinux.cfg
f2 = os.path.join(self.bootloc, "pxelinux.cfg", f1)
# Only generating grub menus for these arch's:
grub_path = os.path.join(self.bootloc, "grub", f1.upper())
elif working_arch.startswith("ppc"):
# Determine filename for system-specific yaboot.conf
filename = "%s" % utils.get_config_filename(system, interface=name).lower()
f2 = os.path.join(self.bootloc, "etc", filename)
# Link to the yaboot binary
f3 = os.path.join(self.bootloc, "ppc", filename)
if os.path.lexists(f3):
utils.rmfile(f3)
os.symlink("../yaboot", f3)
else:
continue
if system.is_management_supported():
if not image_based:
self.write_pxe_file(f2, system, profile, distro, working_arch, metadata=pxe_metadata)
if grub_path:
self.write_pxe_file(grub_path, system, profile, distro, working_arch, format="grub")
else:
self.write_pxe_file(f2, system, None, None, working_arch, image=profile, metadata=pxe_metadata)
else:
# ensure the file doesn't exist
utils.rmfile(f2)
if grub_path:
utils.rmfile(grub_path)
示例10: write_pxe_file
def write_pxe_file(self,filename,system,profile,distro,arch,image=None,include_header=True):
"""
Write a configuration file for the boot loader(s).
More system-specific configuration may come in later, if so
that would appear inside the system object in api.py
NOTE: relevant to tftp and pseudo-PXE (s390) only
ia64 is mostly the same as syslinux stuff, s390 is a bit
short-circuited and simpler. All of it goes through the
templating engine, see the templates in /etc/cobbler for
more details
"""
if arch is None:
raise "missing arch"
if image and not os.path.exists(image.file):
return None # nfs:// URLs or something, can't use for TFTP
# ---
# just some random variables
template = None
metadata = {}
buffer = ""
# ---
kickstart_path = None
kernel_path = None
initrd_path = None
if image is None:
# not image based, it's something normalish
kernel_path = os.path.join("/images",distro.name,os.path.basename(distro.kernel))
initrd_path = os.path.join("/images",distro.name,os.path.basename(distro.initrd))
# Find the kickstart if we inherit from another profile
if system:
blended = utils.blender(self.api, True, system)
else:
blended = utils.blender(self.api, True, profile)
kickstart_path = blended.get("kickstart","")
else:
# this is an image we are making available, not kernel+initrd
if image.image_type == "direct":
kernel_path = os.path.join("/images2",image.name)
elif image.image_type == "memdisk":
kernel_path = "/memdisk"
initrd_path = os.path.join("/images2",image.name)
else:
# CD-ROM ISO or virt-clone image? We can't PXE boot it.
kernel_path = None
initrd_path = None
# ---
# choose a template
if system:
if system.netboot_enabled:
template = os.path.join(self.settings.pxe_template_dir,"pxesystem.template")
if arch.startswith("s390"):
template = os.path.join(self.settings.pxe_template_dir,"pxesystem_s390x.template")
elif arch == "ia64":
template = os.path.join(self.settings.pxe_template_dir,"pxesystem_ia64.template")
elif arch.startswith("ppc"):
template = os.path.join(self.settings.pxe_template_dir,"pxesystem_ppc.template")
else:
# local booting on ppc requires removing the system-specific dhcpd.conf filename
if arch is not None and arch.startswith("ppc"):
# Disable yaboot network booting for all interfaces on the system
for (name,interface) in system.interfaces.iteritems():
filename = "%s" % utils.get_config_filename(system, interface=name).lower()
# Remove symlink to the yaboot binary
f3 = os.path.join(self.bootloc, "ppc", filename)
if os.path.lexists(f3):
utils.rmfile(f3)
# Remove the interface-specific config file
f3 = os.path.join(self.bootloc, "etc", filename)
if os.path.lexists(f3):
utils.rmfile(f3)
# Yaboot/OF doesn't support booting locally once you've
# booted off the network, so nothing left to do
return None
elif arch is not None and arch.startswith("s390"):
template = os.path.join(self.settings.pxe_template_dir,"pxelocal_s390x.template")
elif arch is not None and arch.startswith("ia64"):
template = os.path.join(self.settings.pxe_template_dir,"pxelocal_ia64.template")
else:
template = os.path.join(self.settings.pxe_template_dir,"pxelocal.template")
else:
# not a system record, so this is a profile record
if arch.startswith("s390"):
template = os.path.join(self.settings.pxe_template_dir,"pxeprofile_s390x.template")
else:
#.........这里部分代码省略.........
示例11: remove_single_image
def remove_single_image(self, name):
bootloc = utils.tftpboot_location()
utils.rmfile(os.path.join(bootloc, "images2", name))
示例12: remove_single_profile
def remove_single_profile(self, name):
# delete profiles/$name file in webdir
utils.rmfile(os.path.join(self.settings.webdir, "profiles", name))
# delete contents on kickstarts/$name directory in webdir
utils.rmtree(os.path.join(self.settings.webdir, "kickstarts", name))
示例13: write_pxe_file
#.........这里部分代码省略.........
template = local
else: # pxe
if system.netboot_enabled:
template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxesystem.template")
if arch.startswith("ppc"):
# to inherit the distro and system's boot_loader values correctly
blended_system = utils.blender(self.api, False, system)
if blended_system["boot_loader"] == "pxelinux":
template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxesystem_ppc.template")
elif distro.boot_loader == "grub2" or blended_system["boot_loader"] == "grub2":
template = os.path.join(self.settings.boot_loader_conf_template_dir, "grub2_ppc.template")
else:
template = os.path.join(self.settings.boot_loader_conf_template_dir, "yaboot_ppc.template")
elif arch.startswith("arm"):
template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxesystem_arm.template")
elif distro and distro.os_version.startswith("esxi"):
# ESXi uses a very different pxe method, using more files than
# a standard automatic installation file and different options -
# so giving it a dedicated PXE template makes more sense than
# shoe-horning it into the existing templates
template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxesystem_esxi.template")
else:
# local booting on ppc requires removing the system-specific dhcpd.conf filename
if arch is not None and arch.startswith("ppc"):
# Disable yaboot network booting for all interfaces on the system
for (name, interface) in system.interfaces.iteritems():
filename = "%s" % utils.get_config_filename(system, interface=name).lower()
# Remove symlink to the yaboot binary
f3 = os.path.join(self.bootloc, "ppc", filename)
if os.path.lexists(f3):
utils.rmfile(f3)
# Remove the interface-specific config file
f3 = os.path.join(self.bootloc, "boot/grub", "grub.cfg-" + filename)
if os.path.lexists(f3):
utils.rmfile(f3)
f3 = os.path.join(self.bootloc, "etc", filename)
if os.path.lexists(f3):
utils.rmfile(f3)
# Yaboot/OF doesn't support booting locally once you've
# booted off the network, so nothing left to do
return None
else:
template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxelocal.template")
else:
# not a system record, so this is a profile record or an image
if arch.startswith("arm"):
template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxeprofile_arm.template")
elif format == "grub":
template = os.path.join(self.settings.boot_loader_conf_template_dir, "grubprofile.template")
elif distro and distro.os_version.startswith("esxi"):
# ESXi uses a very different pxe method, see comment above in the system section
template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxeprofile_esxi.template")
elif 'nexenta' == format:
template = os.path.join(self.settings.boot_loader_conf_template_dir, 'nexenta_profile.template')
else:
template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxeprofile.template")
if kernel_path is not None:
metadata["kernel_path"] = kernel_path
if initrd_path is not None:
metadata["initrd_path"] = initrd_path