[pve-devel] [RFC container 0/2] file modification update + /etc/hosts

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Feb 25 16:26:27 CET 2016


This series is an extension to the previous comment-section based
/etc/hosts replacement RFC patch.

Patch 1 introduces a ct_file_modify (replacing the existing
ct_modify_file_head_portion) which takes a file, a 'heading', data and
some options and modifies a section of an existing file in the
container.
The section is marked with begin and end comments of the form:
|  # --- BEGIN PVE $header ---
|  <data>
|  # --- BEGIN PVE $header ---

The options specify what to do in various cases as follows:
('empty' here means when not considering the BEGIN/END comments a
part of the file!)
If the old file did not exist:
    A new file will be created with only the comments + data inside,
    unless there is no data.
Otherwise:
    If an old section was found:
        Replace the old section.
    otherwise:
        option prepend: Put a new section on top of the file
        option replace: Replace the entire file
        otherwise: Append the new section to the bottom.
    finally:
    option delete: If the file is now empty, delete it.

This method is now used for /etc/resolv.conf with the 'replace'
option, and for routes in Redhat.pm and SUSE.pm (which previously
used ct_modify_file_head_portion()) with the 'delete' and 'prepend'
options.

Patch 2 changes update_etc_hosts() to use ct_modify_file after frist
checking the original one for 127.0.0.1 and ::1 entries, adding the
missing ones to be included in the section.
Here we use the default options which means missing sections will be
appended at the bottom and the file will never be deleted if empty
(since it can't be empty as we make sure we at least contain the
localhost lines anyway).

Finally I wanted to ask on behalf of a many users how we should
introduce the ability to prevent files from being edited entirely?
Since the entire setup code has been using the ct_*() set of file
modification functions it should be easy to add a unified check to all
of the write-functions which would then automatically work for all
files we'd touch.
Perhaps we could check for special files like .pve-ignore.$filename
(I like the idea of prefixing it with a dot to avoid regular 'ls'
output getting clobbered, but any other method is fine, too. If only
all filesystems had support for xattrs then we could just use those
;-) )

Wolfgang Bumiller (2):
  Setup::Base: more generic ct_modify_file function
  change update_etc_hosts to use ct_modify_file

 src/PVE/LXC/Setup/Base.pm                      | 178 ++++++++++++-------------
 src/PVE/LXC/Setup/Redhat.pm                    |  15 +--
 src/PVE/LXC/Setup/SUSE.pm                      |   4 +-
 src/test/test-centos6-001/etc/hosts.exp        |   3 +
 src/test/test-centos6-001/etc/resolv.conf.exp  |   2 +
 src/test/test-debian-001/etc/hosts.exp         |   3 +
 src/test/test-debian-002/etc/hosts.exp         |   3 +
 src/test/test-debian-003/etc/hosts.exp         |   3 +
 src/test/test-debian-004/etc/hosts.exp         |   3 +
 src/test/test-debian-005/etc/hosts.exp         |   3 +
 src/test/test-debian-006/etc/hosts.exp         |   3 +
 src/test/test-debian-007/etc/hosts.exp         |   3 +
 src/test/test-debian-007/etc/resolv.conf       |   2 +
 src/test/test-debian-007/etc/resolv.conf.exp   |   2 +
 src/test/test-debian-008/etc/hosts.exp         |   4 +
 src/test/test-debian-008/etc/resolv.conf       |   8 ++
 src/test/test-debian-008/etc/resolv.conf.exp   |   7 +
 src/test/test-debian-009/etc/hosts.exp         |   3 +
 src/test/test-debian-010/etc/hosts.exp         |   3 +
 src/test/test-debian-013/etc/hosts.exp         |   3 +
 src/test/test-opensuse-001/etc/hosts.exp       |   3 +
 src/test/test-opensuse-001/etc/resolv.conf.exp |   2 +
 22 files changed, 154 insertions(+), 106 deletions(-)
 create mode 100644 src/test/test-debian-007/etc/resolv.conf
 create mode 100644 src/test/test-debian-008/etc/resolv.conf

-- 
2.1.4





More information about the pve-devel mailing list