Compare commits

...

3 Commits

Author SHA1 Message Date
Sebastian Lohff 2aa243d2d2 Allow extra routes to be added to an interface
5 years ago
Sebastian Lohff 158c71c1cc Remove cloud-init after first run by default
5 years ago
Sebastian Lohff 4092a9a519 Add thin README
5 years ago

@ -0,0 +1,3 @@
# genconfdrv
Generate a config drive for cloud-init. Requires `genisoimage` to be installed.
Currently only tested with Debian and `.deb`-based Linux distributions.

@ -36,7 +36,7 @@ class ConfigDrive:
def set_hostname(self, hostname):
self._hostname = hostname
def conf_network(self, interface, address=None, gateway=None):
def conf_network(self, interface, address=None, gateway=None, *extra_routes):
if not address and gateway:
raise ValueError("You cannot define a gateway, but supply no address")
@ -66,6 +66,16 @@ class ConfigDrive:
if gateway:
self._interfaces.append(" gateway %s" % str(ipaddress.ip_address(gateway)))
for routedef in extra_routes:
if "-" not in routedef:
raise ValueError("Route {} is missing a gateway separated by a -".format(routedef))
route, gw = routedef.split('-')
if "/" not in route:
raise ValueError("Route {} is not a subnet".format(route))
route = ipaddress.ip_interface(route)
gw = ipaddress.ip_address(gw)
self._interfaces.append(" up ip route add {} via {}".format(route, gw))
def conf_resolve(self, resolvers):
if not self._hostname:
raise ValueError("Please set a hostname before calling this function")
@ -263,12 +273,16 @@ def main():
parser.add_argument("-o", "--output", required=True, help="Path to write iso to")
parser.add_argument("-n", "--nameservers", "--ns", default=["1.1.1.1", "8.8.8.8"], nargs="+", help="Nameservers")
parser.add_argument("-i", "--networks", "--net", default=[], nargs="+",
help="Specify all networks, in format of interface[:address:[gateway]]. "
help="Specify all networks, in format of interface[:address[:gateway[:route-gateway[:...]]]]. "
"Both : and ; can be used as delimiter (but only one per net config). "
"Address MUST be a network in CIDR notation")
"Address MUST be a network in CIDR notation. Additional "
"routes can be added in the form of cidr-gateway, e.g. "
"10.0.0.0/8-10.0.0.1")
parser.add_argument("-u", "--disable-upgrades", action="store_true", default=False)
parser.add_argument("-v", "--verbose", action="store_true", default=False)
parser.add_argument("--no-debian-cleanup", "--ndc", action="store_true", default=False)
parser.add_argument("--no-remove-cloud-init", action="store_true", default=False,
help="Do not purge cloud-init from system after execution")
parser.add_argument("--set-root-password", "--srp", default=None)
parser.add_argument("-a", "--add-user", default=[], nargs="+",
help="Add users, format is username:key?:sudo?:gecos?:password?, "
@ -308,7 +322,6 @@ def main():
"rm /etc/apt/sources.list.d/*", True)
cfgdrv.add_command("sed -rni '/^([^#]|## template)/p' "
"/etc/resolv.conf /etc/cloud/templates/resolv.conf.tmpl", True)
if args.set_root_password:
cfgdrv.set_password("root", args.set_root_password)
@ -340,6 +353,9 @@ def main():
password = user[4]
cfgdrv.add_user(user[0], keys, sudo=sudo, gecos=gecos, password=password)
if not args.no_remove_cloud_init:
cfgdrv.add_command("apt remove -y cloud-init")
if args.output:
cfgdrv.write_drive(args.output, args.format)
finally:

Loading…
Cancel
Save