/usr/share/pyshared/cobbler/modules/manage_in_tftpd.py is in python-maas-provision 2.2.2-0ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | """
This is some of the code behind 'cobbler sync'.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
"""
import os.path, traceback, errno
import re
import clogger
import pxegen
import utils
from cexceptions import *
import templar
from utils import _
def register():
"""
The mandatory cobbler module registration hook.
"""
return "manage"
class InTftpdManager:
def what(self):
return "tftpd"
def __init__(self,config,logger):
"""
Constructor
"""
self.logger = logger
if self.logger is None:
self.logger = clogger.Logger()
self.config = config
self.templar = templar.Templar(config)
self.settings_file = "/etc/xinetd.d/tftp"
self.pxegen = pxegen.PXEGen(config, self.logger)
self.systems = config.systems()
self.bootloc = utils.tftpboot_location()
def regen_hosts(self):
pass # not used
def write_dns_files(self):
pass # not used
def write_boot_files_distro(self,distro):
# collapse the object down to a rendered datastructure
# the second argument set to false means we don't collapse
# hashes/arrays into a flat string
target = utils.blender(self.config.api, False, distro)
# Create metadata for the templar function
# Right now, just using img_path, but adding more
# cobbler variables here would probably be good
metadata = {}
metadata["img_path"] = os.path.join(
utils.tftpboot_location(),
"images",distro.name)
# Create the templar instance. Used to template the target directory
templater = templar.Templar()
# Loop through the hash of boot files,
# executing a cp for each one
for file in target["boot_files"].keys():
file_dst = templater.render(file,metadata,None)
try:
shutil.copyfile(target["boot_files"][file], file_dst)
self.config.api.log("copied file %s to %s for %s" % (
target["boot_files"][file],
file_dst,
distro.name))
except:
self.logger.error("failed to copy file %s to %s for %s" % (
target["boot_files"][file],
file_dst,
distro.name))
# Continue on to sync what you can
return 0
def write_boot_files(self):
"""
Copy files in profile["boot_files"] into /tftpboot. Used for vmware
currently.
"""
for distro in self.config.distros():
self.write_boot_files_distro(distro)
return 0
def write_tftpd_files(self):
"""
xinetd files are written when manage_tftp is set in
/var/lib/cobbler/settings.
"""
template_file = "/etc/cobbler/tftpd.template"
try:
f = open(template_file,"r")
except:
raise CX(_("error reading template %s") % template_file)
template_data = ""
template_data = f.read()
f.close()
metadata = {
"user" : "root",
"binary" : "/usr/sbin/in.tftpd",
"args" : "-v -s %s" % self.bootloc
}
self.logger.info("generating %s" % self.settings_file)
self.templar.render(template_data, metadata, self.settings_file, None)
def update_netboot(self,name):
"""
Write out new gpxe or pxelinux.cfg files to /tftpboot
"""
system = self.systems.find(name=name)
if system is None:
utils.die(self.logger,"error in system lookup for %s" % name)
self.pxegen.write_all_system_files(system)
# generate any templates listed in the system
self.pxegen.write_templates(system)
def add_single_system(self,system):
"""
Write out new gpxe or pxelinux.cfg files to /tftpboot
"""
# write the PXE files for the system
self.pxegen.write_all_system_files(system)
# generate any templates listed in the distro
self.pxegen.write_templates(system)
def add_single_distro(self,distro):
self.pxegen.copy_single_distro_files(distro,self.bootloc,False)
self.write_boot_files_distro(distro)
def sync(self,verbose=True):
"""
Write out all files to /tftpdboot
"""
self.pxegen.verbose = verbose
self.logger.info("copying bootloaders")
self.pxegen.copy_bootloaders()
self.logger.info("copying distros to tftpboot")
# Adding in the exception handling to not blow up if files have
# been moved (or the path references an NFS directory that's no longer
# mounted)
for d in self.config.distros():
try:
self.logger.info("copying files for distro: %s" % d.name)
self.pxegen.copy_single_distro_files(d,self.bootloc,False)
except CX, e:
self.logger.error(e.value)
self.logger.info("copying images")
self.pxegen.copy_images()
# the actual pxelinux.cfg files, for each interface
self.logger.info("generating GPXE/PXE configuration files")
for x in self.systems:
self.pxegen.write_all_system_files(x)
self.logger.info("generating PXE menu structure")
self.pxegen.make_pxe_menu()
def get_manager(config,logger):
return InTftpdManager(config,logger)
|