summaryrefslogtreecommitdiff
path: root/cloudinit/dhclient_hook.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/dhclient_hook.py')
-rw-r--r--cloudinit/dhclient_hook.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/cloudinit/dhclient_hook.py b/cloudinit/dhclient_hook.py
index 72b51b6a..46b2e8d9 100644
--- a/cloudinit/dhclient_hook.py
+++ b/cloudinit/dhclient_hook.py
@@ -19,7 +19,7 @@ EVENTS = (UP, DOWN)
def _get_hooks_dir():
i = stages.Init()
- return os.path.join(i.paths.get_runpath(), 'dhclient.hooks')
+ return os.path.join(i.paths.get_runpath(), "dhclient.hooks")
def _filter_env_vals(info):
@@ -28,15 +28,16 @@ def _filter_env_vals(info):
new_info = {}
for k, v in info.items():
if k.startswith("DHCP4_") or k.startswith("new_"):
- key = (k.replace('DHCP4_', '').replace('new_', '')).lower()
+ key = (k.replace("DHCP4_", "").replace("new_", "")).lower()
new_info[key] = v
return new_info
def run_hook(interface, event, data_d=None, env=None):
if event not in EVENTS:
- raise ValueError("Unexpected event '%s'. Expected one of: %s" %
- (event, EVENTS))
+ raise ValueError(
+ "Unexpected event '%s'. Expected one of: %s" % (event, EVENTS)
+ )
if data_d is None:
data_d = _get_hooks_dir()
if env is None:
@@ -58,9 +59,11 @@ def get_parser(parser=None):
if parser is None:
parser = argparse.ArgumentParser(prog=NAME, description=__doc__)
parser.add_argument(
- "event", help='event taken on the interface', choices=EVENTS)
+ "event", help="event taken on the interface", choices=EVENTS
+ )
parser.add_argument(
- "interface", help='the network interface being acted upon')
+ "interface", help="the network interface being acted upon"
+ )
# cloud-init main uses 'action'
parser.set_defaults(action=(NAME, handle_args))
return parser
@@ -72,12 +75,14 @@ def handle_args(name, args, data_d=None):
return run_hook(interface=args.interface, event=args.event, data_d=data_d)
-if __name__ == '__main__':
+if __name__ == "__main__":
import sys
+
parser = get_parser()
args = parser.parse_args(args=sys.argv[1:])
return_value = handle_args(
- NAME, args, data_d=os.environ.get('_CI_DHCP_HOOK_DATA_D'))
+ NAME, args, data_d=os.environ.get("_CI_DHCP_HOOK_DATA_D")
+ )
if return_value:
sys.exit(return_value)