Browse Source

Merge "Allow disabling DHCP fallback"

changes/26/788126/1
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
ee93fde849
7 changed files with 50 additions and 14 deletions
  1. +23
    -4
      glean/cmd.py
  2. +1
    -1
      glean/init/glean-networkd.service
  3. +1
    -1
      glean/init/glean-nm@.service
  4. +1
    -1
      glean/init/glean.conf
  5. +1
    -1
      glean/init/glean.init
  6. +1
    -1
      glean/init/glean@.service
  7. +22
    -5
      glean/install.py

+ 23
- 4
glean/cmd.py View File

@ -310,6 +310,11 @@ def write_redhat_interfaces(interfaces, sys_interfaces, args):
if interface['type'] == 'manual':
files_to_write.update(
_write_rh_manual(interface_name, interface, args))
if args.no_dhcp_fallback:
log.debug('DHCP fallback disabled')
return files_to_write
for mac, iname in sorted(
sys_interfaces.items(), key=lambda x: x[1]):
if _exists_rh_interface(iname, args.distro):
@ -569,6 +574,9 @@ def write_networkd_interfaces(interfaces, sys_interfaces, args):
# We have a config drive config, move on
log.debug("%s configured via config-drive" % mac)
continue
if args.no_dhcp_fallback:
log.debug('DHCP fallback disabled')
continue
interface = {'type': 'ipv4_dhcp', 'mac_address': mac}
files_struct = _write_networkd_interface(
iname, [interface], args, files_struct)
@ -731,7 +739,7 @@ def _create_gentoo_net_symlink_and_enable(interface_name):
_enable_gentoo_interface(interface_name)
def write_gentoo_interfaces(interfaces, sys_interfaces):
def write_gentoo_interfaces(interfaces, sys_interfaces, args):
files_to_write = dict()
gen_intfs = {}
# Sort the interfaces by id so that we'll have consistent output order
@ -774,6 +782,10 @@ def write_gentoo_interfaces(interfaces, sys_interfaces):
_write_gentoo_interface(interface_name, interfs))
_setup_gentoo_network_init(interface_name, interfs)
if args.no_dhcp_fallback:
log.debug('DHCP fallback disabled')
return files_to_write
for mac, iname in sorted(
sys_interfaces.items(), key=lambda x: x[1]):
if _exists_gentoo_interface(iname):
@ -812,7 +824,7 @@ def _write_debian_bond_conf(interface_name, interface, sys_interfaces):
return result
def write_debian_interfaces(interfaces, sys_interfaces):
def write_debian_interfaces(interfaces, sys_interfaces, args):
eni_path = '/etc/network/interfaces'
eni_d_path = eni_path + '.d'
files_to_write = dict()
@ -924,6 +936,10 @@ def write_debian_interfaces(interfaces, sys_interfaces):
sys_interfaces)
files_to_write[iface_path] = result
if args.no_dhcp_fallback:
log.debug('DHCP fallback disabled')
return files_to_write
# Configure any interfaces not mentioned in the config drive data for DHCP.
for mac, iname in sorted(
sys_interfaces.items(), key=lambda x: x[1]):
@ -1069,14 +1085,14 @@ def write_static_network_info(
if args.distro in ('debian', 'ubuntu'):
files_to_write.update(
write_debian_interfaces(interfaces, sys_interfaces))
write_debian_interfaces(interfaces, sys_interfaces, args))
elif args.distro in ('redhat', 'centos', 'fedora') or \
_is_suse(args.distro):
files_to_write.update(
write_redhat_interfaces(interfaces, sys_interfaces, args))
elif args.distro in 'gentoo':
files_to_write.update(
write_gentoo_interfaces(interfaces, sys_interfaces)
write_gentoo_interfaces(interfaces, sys_interfaces, args)
)
elif args.distro in 'networkd':
files_to_write.update(
@ -1522,6 +1538,9 @@ def main(argv=None):
parser.add_argument(
'--debug', dest='debug', action='store_true',
help="Enable debugging output")
parser.add_argument(
"--no-dhcp-fallback", action="store_true",
help="Do not fall back to DHCP")
args = parser.parse_args(argv)
if args.debug:


+ 1
- 1
glean/init/glean-networkd.service View File

@ -6,7 +6,7 @@ Requires=systemd-networkd.service
[Service]
Type=oneshot
User=root
ExecStart=%%GLEANSH_PATH%%/glean.sh --distro networkd
ExecStart=%%GLEANSH_PATH%%/glean.sh --distro networkd %%EXTRA_ARGS%%
RemainAfterExit=true
[Install]


+ 1
- 1
glean/init/glean-nm@.service View File

@ -13,7 +13,7 @@ ConditionPathExists=!/etc/sysconfig/network/ifcfg-%I
Type=oneshot
User=root
Environment="ARGS=--interface %I"
ExecStart=%%GLEANSH_PATH%%/glean.sh --use-nm --debug $ARGS
ExecStart=%%GLEANSH_PATH%%/glean.sh --use-nm --debug $ARGS %%EXTRA_ARGS%%
RemainAfterExit=true
StandardOutput=journal+console


+ 1
- 1
glean/init/glean.conf View File

@ -11,4 +11,4 @@ start on starting networking
task
exec /usr/local/bin/glean.sh
exec /usr/local/bin/glean.sh %%EXTRA_ARGS%%

+ 1
- 1
glean/init/glean.init View File

@ -18,7 +18,7 @@ SCRIPT_NAME=/usr/local/bin/${NAME}.sh
case "$1" in
start)
$SCRIPT_NAME
$SCRIPT_NAME %%EXTRA_ARGS%%
;;
stop)
;;


+ 1
- 1
glean/init/glean@.service View File

@ -15,7 +15,7 @@ ConditionPathExists=!/etc/network/interfaces.d/%I.cfg
Type=oneshot
User=root
Environment="ARGS=--interface %I"
ExecStartPre=%%GLEANSH_PATH%%/glean.sh ${ARGS}
ExecStartPre=%%GLEANSH_PATH%%/glean.sh ${ARGS} %%EXTRA_ARGS%%
ExecStart=/sbin/ifup %I
RemainAfterExit=true


+ 22
- 5
glean/install.py View File

@ -85,9 +85,21 @@ def main():
action="store_true")
parser.add_argument("-q", "--quiet", help="Be very quiet",
action="store_true")
# NOTE(dtantsur): there may be two reasons to disable the fallback:
# 1) Remote edge deployments where DHCP (if present at all) is likely
# incorrect and should not be used.
# 2) Co-existing with another tool that handles DHCP differently (IPv6,
# SLAAC) or does a more sophisticated configuration (like NetworkManager
# or, in case of ironic-python-agent, dhcp-all-interfaces, which is **not**
# recommended, but is done nonetheless, mostly for legacy reasons).
parser.add_argument("--no-dhcp-fallback", action="store_true",
help="Do not fall back to DHCP. If this is on, "
"something else must configure networking or "
"it will be left unconfigured.")
args = parser.parse_args()
p = _find_gleansh_path()
extra_args = '--no-dhcp-fallback' if args.no_dhcp_fallback else ''
if args.quiet:
logging.basicConfig(level=logging.ERROR)
@ -98,7 +110,8 @@ def main():
if os.path.exists('/etc/gentoo-release'):
log.info('installing openrc services')
install('glean.openrc', '/etc/init.d/glean',
replacements={'GLEANSH_PATH': p})
replacements={'GLEANSH_PATH': p,
'EXTRA_ARGS': extra_args})
# Needs to check for the presence of systemd and systemctl
# as apparently some packages may stage systemd init files
# when systemd is not present.
@ -118,7 +131,8 @@ def main():
'glean-networkd.service',
'/lib/systemd/system/glean.service',
mode='0644',
replacements={'GLEANSH_PATH': p})
replacements={'GLEANSH_PATH': p,
'EXTRA_ARGS': extra_args})
subprocess.call(['systemctl', 'enable', 'glean.service'])
else:
log.info("Installing %s NetworkManager support" %
@ -131,7 +145,8 @@ def main():
service_file,
'/usr/lib/systemd/system/glean@.service',
mode='0644',
replacements={'GLEANSH_PATH': p})
replacements={'GLEANSH_PATH': p,
'EXTRA_ARGS': extra_args})
install(
'glean-udev.rules',
'/etc/udev/rules.d/99-glean.rules',
@ -161,12 +176,14 @@ def main():
elif os.path.exists('/etc/init'):
log.info("Installing upstart services")
install('glean.conf', '/etc/init/glean.conf')
install('glean.conf', '/etc/init/glean.conf',
replacements={'EXTRA_ARGS': extra_args})
elif os.path.exists('/sbin/rc-update'):
subprocess.call(['rc-update', 'add', 'glean', 'boot'])
else:
log.info("Installing sysv services")
install('glean.init', '/etc/init.d/glean')
install('glean.init', '/etc/init.d/glean',
replacements={'EXTRA_ARGS': extra_args})
os.system('update-rc.d glean defaults')
if __name__ == '__main__':


Loading…
Cancel
Save