Using libguestfs from Python

Create handle — Inspect — Modify — Shutdown

if type == "linux" and distro == "fedora":
    g.mkdir_p ("/etc/profile.d")
    g.write ("/etc/profile.d/proxy.sh",
             "http_proxy=http://cache:3128/")
else
    # etc