Compare commits
No commits in common. "2aa243d2d24de0f2c27919ecd9eac87e41fa73b8" and "b6e80b7288ef24d942fc7422cd2e0d6f55205fdb" have entirely different histories.
2aa243d2d2
...
b6e80b7288
|
@ -1,3 +0,0 @@
|
||||||
# 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):
|
def set_hostname(self, hostname):
|
||||||
self._hostname = hostname
|
self._hostname = hostname
|
||||||
|
|
||||||
def conf_network(self, interface, address=None, gateway=None, *extra_routes):
|
def conf_network(self, interface, address=None, gateway=None):
|
||||||
if not address and gateway:
|
if not address and gateway:
|
||||||
raise ValueError("You cannot define a gateway, but supply no address")
|
raise ValueError("You cannot define a gateway, but supply no address")
|
||||||
|
|
||||||
|
@ -66,16 +66,6 @@ class ConfigDrive:
|
||||||
if gateway:
|
if gateway:
|
||||||
self._interfaces.append(" gateway %s" % str(ipaddress.ip_address(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):
|
def conf_resolve(self, resolvers):
|
||||||
if not self._hostname:
|
if not self._hostname:
|
||||||
raise ValueError("Please set a hostname before calling this function")
|
raise ValueError("Please set a hostname before calling this function")
|
||||||
|
@ -273,16 +263,12 @@ def main():
|
||||||
parser.add_argument("-o", "--output", required=True, help="Path to write iso to")
|
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("-n", "--nameservers", "--ns", default=["1.1.1.1", "8.8.8.8"], nargs="+", help="Nameservers")
|
||||||
parser.add_argument("-i", "--networks", "--net", default=[], nargs="+",
|
parser.add_argument("-i", "--networks", "--net", default=[], nargs="+",
|
||||||
help="Specify all networks, in format of interface[:address[:gateway[:route-gateway[:...]]]]. "
|
help="Specify all networks, in format of interface[:address:[gateway]]. "
|
||||||
"Both : and ; can be used as delimiter (but only one per net config). "
|
"Both : and ; can be used as delimiter (but only one per net config). "
|
||||||
"Address MUST be a network in CIDR notation. Additional "
|
"Address MUST be a network in CIDR notation")
|
||||||
"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("-u", "--disable-upgrades", action="store_true", default=False)
|
||||||
parser.add_argument("-v", "--verbose", 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-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("--set-root-password", "--srp", default=None)
|
||||||
parser.add_argument("-a", "--add-user", default=[], nargs="+",
|
parser.add_argument("-a", "--add-user", default=[], nargs="+",
|
||||||
help="Add users, format is username:key?:sudo?:gecos?:password?, "
|
help="Add users, format is username:key?:sudo?:gecos?:password?, "
|
||||||
|
@ -322,6 +308,7 @@ def main():
|
||||||
"rm /etc/apt/sources.list.d/*", True)
|
"rm /etc/apt/sources.list.d/*", True)
|
||||||
cfgdrv.add_command("sed -rni '/^([^#]|## template)/p' "
|
cfgdrv.add_command("sed -rni '/^([^#]|## template)/p' "
|
||||||
"/etc/resolv.conf /etc/cloud/templates/resolv.conf.tmpl", True)
|
"/etc/resolv.conf /etc/cloud/templates/resolv.conf.tmpl", True)
|
||||||
|
|
||||||
if args.set_root_password:
|
if args.set_root_password:
|
||||||
cfgdrv.set_password("root", args.set_root_password)
|
cfgdrv.set_password("root", args.set_root_password)
|
||||||
|
|
||||||
|
@ -353,9 +340,6 @@ def main():
|
||||||
password = user[4]
|
password = user[4]
|
||||||
cfgdrv.add_user(user[0], keys, sudo=sudo, gecos=gecos, password=password)
|
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:
|
if args.output:
|
||||||
cfgdrv.write_drive(args.output, args.format)
|
cfgdrv.write_drive(args.output, args.format)
|
||||||
finally:
|
finally:
|
||||||
|
|
Loading…
Reference in New Issue