Example #1
0
def setup_tftp_root(tftp_rootdir):
    """
    [DESTRUCTIVELY!!!] Sets up a TFTP root to work

    It will wipe anything in some parts of there with 'rsync --delete'
    """
    def _rsync_files(dest, files):
        try:
            commonl.makedirs_p(dest, 0o0775)
            cmdline = ["rsync", "-a", "--delete"] + files + [dest]
            subprocess.check_output(cmdline,
                                    shell=False,
                                    stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            logging.error("PXE setup: root::%s: can't copy files %s "
                          " (do they exist?)\n%s" %
                          (dest, " ".join(files), e.output))
            raise

    # TFTP setup
    commonl.makedirs_p(os.path.join(tftp_rootdir, "pxelinux.cfg"), 0o0775)
    if 'root' in architectures:
        arch_data = architectures['root']
        _rsync_files(tftp_rootdir, arch_data['copy_files'])
    for arch_name, arch_data in architectures.iteritems():
        if arch_name == 'root':  # skip, we handled it ...
            continue  # ... differently
        tftp_arch_dir = os.path.join(tftp_rootdir, arch_name)
        _rsync_files(tftp_arch_dir, arch_data['copy_files'])
        # We use always the same configurations; because the rsync
        # above might remove the symlink, we re-create it
        # We use a relative symlink so in.tftpd doesn't nix it
        commonl.symlink_f("../pxelinux.cfg",
                          os.path.join(tftp_arch_dir, "pxelinux.cfg"))
Example #2
0
File: dhcp.py Project: intel/tcf
    def power_on_do(self, target):
        """
        Start DHCPd servers on the network interface
        described by `target`
        """
        if self.target == None:
            self.target = target
        else:
            assert self.target == target
        # FIXME: detect @target is an ipv4 capable network, fail otherwise
        self._init_for_process(target)
        # Create runtime directories where we place everything based
        # on the infomation in pxe_architectures
        shutil.rmtree(self.state_dir, ignore_errors = True)
        os.makedirs(self.state_dir)

        # TFTP setup
        commonl.makedirs_p(os.path.join(tftp_dir, tftp_prefix,
                                        "pxelinux.cfg"),
                           0o0775)
        for arch_name, arch_data in pxe_architectures.iteritems():
            tftp_arch_dir = os.path.join(tftp_dir, tftp_prefix, arch_name)
            commonl.makedirs_p(tftp_arch_dir, 0o0775)
            cmdline = [ "rsync", "-a", "--delete" ] \
                + arch_data['copy_files'] + [ tftp_arch_dir ]
            subprocess.call(cmdline, shell = False, stderr = subprocess.STDOUT)
            # We use always the same configurations; because the rsync
            # above might remove the symlink, we re-create it
            # We use a relative symlink so in.tftpd doesn't nix it
            commonl.symlink_f("../pxelinux.cfg",
                              os.path.join(tftp_arch_dir, "pxelinux.cfg"))

        # We set the parameters in a dictionary so we can use it to
        # format strings
        # FUGLY; relies on ttbl.conf_00_lib.vlan_pci renaming the
        # network interfaces like this.
        self._params['if_name'] = "b" + target.id

        # FIXME: if we get the parameters from the network here, we
        # have target -- so we don't need to set them on init
        with open(os.path.join(self.state_dir, "dhcpd.conf"), "wb") as f:
            self._dhcp_conf_write(f)

        # FIXME: before start, filter out leases file, anything in the
        # leases dhcpd.leases file that has a "binding state active"
        # shall be kept ONLY if we still have that client in the
        # configuration...or sth like that.
        # FIXME: rm old leases file, overwrite with filtered one

        self._dhcpd_start()
Example #3
0
    def power_on_do(self, target):
        """
        Start DHCPd servers on the network interface
        described by `target`
        """
        if self.target == None:
            self.target = target
        else:
            assert self.target == target
        # FIXME: detect @target is an ipv4 capable network, fail otherwise
        self._init_for_process(target)
        # Create runtime directories where we place everything based
        # on the infomation in pxe_architectures
        shutil.rmtree(self.state_dir, ignore_errors=True)
        os.makedirs(self.state_dir)

        # TFTP setup
        commonl.makedirs_p(os.path.join(tftp_dir, tftp_prefix, "pxelinux.cfg"),
                           0o0775)
        for arch_name, arch_data in pxe_architectures.iteritems():
            tftp_arch_dir = os.path.join(tftp_dir, tftp_prefix, arch_name)
            commonl.makedirs_p(tftp_arch_dir, 0o0775)
            cmdline = [ "rsync", "-a", "--delete" ] \
                + arch_data['copy_files'] + [ tftp_arch_dir ]
            subprocess.call(cmdline, shell=False, stderr=subprocess.STDOUT)
            # We use always the same configurations; because the rsync
            # above might remove the symlink, we re-create it
            # We use a relative symlink so in.tftpd doesn't nix it
            commonl.symlink_f("../pxelinux.cfg",
                              os.path.join(tftp_arch_dir, "pxelinux.cfg"))

        # We set the parameters in a dictionary so we can use it to
        # format strings
        # FUGLY; relies on ttbl.conf_00_lib.vlan_pci renaming the
        # network interfaces like this.
        self._params['if_name'] = "b" + target.id

        # FIXME: if we get the parameters from the network here, we
        # have target -- so we don't need to set them on init
        with open(os.path.join(self.state_dir, "dhcpd.conf"), "wb") as f:
            self._dhcp_conf_write(f)

        # FIXME: before start, filter out leases file, anything in the
        # leases dhcpd.leases file that has a "binding state active"
        # shall be kept ONLY if we still have that client in the
        # configuration...or sth like that.
        # FIXME: rm old leases file, overwrite with filtered one

        self._dhcpd_start()