summaryrefslogtreecommitdiff
path: root/pxeboot.check
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-10-09 09:48:01 (GMT)
committerRichard Maw <richard.maw@codethink.co.uk>2014-11-10 17:59:58 (GMT)
commit00f5bb8550a7e852b544817d00671be68936137c (patch)
tree2d780e734e622d56f4fe4e43b90bc90f7f7dfcff /pxeboot.check
parentd2ec7e9f3b30af999637c3f918621fe2b5385bc8 (diff)
downloaddefinitions-baserock/richardmaw/pxeboot-write.tar.gz
Add pxeboot write extension.baserock/richardmaw/pxeboot-write
It has 4 modes. 1. Specify PXEBOOT_DEPLOYER_INTERFACE and PXEBOOT_VLAN to configure the target to pxeboot on a vlan and spawn a dhcp, nfs and tftp server. This is potentially the fastest, since it doesn't need to copy data to other servers. 2. Specify PXEBOOT_DEPLOYER_INTERFACE without PXEBOOT_VLAN to configure do 1, but without creating the vlan interface. This assumes that you have exclusive access to the interface, such as if you're plugged in to the device directly, or your interface is vlanned by your infrastructure team. This is required if you are serving from a VM and bridging it to the correct network via macvtap. For this to work, you need to macvtap bridge to a pre-vlanned interface on your host machine. 3. Specify PXEBOOT_DEPLOYER_INTERFACE and PXEBOOT_CONFIG_TFTP_ADDRESS to put config on an existing tftp server, already configured by the dhcp server. This spawns a tftp server and configures the local nfs server, but doesn't do a dhcp server. This is useful if you have already got a dhcp server that serves PXE images. 4. Specify at least PXEBOOT_CONFIG_TFTP_ADDRESS and PXEBOOT_ROOTFS_RSYNC_ADDRESS to specify existing servers to copy config, kernels and the rootfs to. The mode detection can be overridden by specifying PXEBOOT_MODE. Mode 1 is `spawn-vlan`. Mode 2 is `spawn-novlan`, Mode 3 is `existing-dhcp` and Mode 4 is `existing-server`.
Diffstat (limited to 'pxeboot.check')
-rwxr-xr-xpxeboot.check69
1 files changed, 69 insertions, 0 deletions
diff --git a/pxeboot.check b/pxeboot.check
new file mode 100755
index 0000000..d7eb9b5
--- /dev/null
+++ b/pxeboot.check
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+
+import itertools
+import os
+import sys
+flatten = itertools.chain.from_iterable
+
+def powerset(iterable):
+ "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
+ s = list(iterable)
+ return flatten(itertools.combinations(s, r) for r in range(len(s)+1))
+
+valid_option_sets = frozenset((
+ ('spawn-novlan', frozenset(('PXEBOOT_DEPLOYER_INTERFACE',))),
+ ('spawn-vlan', frozenset(('PXEBOOT_DEPLOYER_INTERFACE', 'PXEBOOT_VLAN'))),
+ ('existing-dhcp', frozenset(('PXEBOOT_DEPLOYER_INTERFACE',
+ 'PXEBOOT_CONFIG_TFTP_ADDRESS'))),
+ ('existing-server', frozenset(('PXEBOOT_CONFIG_TFTP_ADDRESS',
+ 'PXEBOOT_ROOTFS_RSYNC_ADDRESS'))),
+))
+valid_modes = frozenset(mode for (mode, opt_set in valid_option_sets))
+
+
+def compute_matches(env):
+ complete_matches = set()
+ for mode, opt_set in valid_option_sets:
+ if all(k in env for k in opt_set):
+ complete_matches.add(opt_set)
+ return complete_matches
+complete_matches = compute_matches(os.environ)
+
+def word_separate_options(options):
+ assert options
+ s = options.pop(-1)
+ if options:
+ s = '%s and %s' % (', '.join(options), s)
+ return s
+
+
+valid_options = frozenset(flatten(opt_set for (mode, opt_set)
+ in valid_option_sets))
+matched_options = frozenset(o for o in valid_options)
+ if o in os.environ)
+if not complete_matches:
+ addable_sets = frozenset(frozenset(os) - matched_options for os in
+ valid_options
+ if frozenset(os) - matched_options)
+ print('Please provide %s' % ' or '.join(
+ word_separate_options(list(opt_set))
+ for opt_set in addable_sets if opt_set))
+ sys.exit(1)
+elif len(complete_matches) > 1:
+ removable_sets = frozenset(matched_options - frozenset(os) for os in
+ powerset(matched_options)
+ if len(compute_matches(os)) == 1)
+ print('Please unset %s' % ' or '.join(
+ word_separate_options(list(opt_set))
+ for opt_set in removable_sets if opt_set))
+ sys.exit(1)
+
+if 'PXEBOOT_MODE' in os.environ:
+ mode = os.environ['PXEBOOT_MODE']
+else:
+ mode, = (mode for (mode, opt_set) in valid_option_sets
+ if all(o in os.environ for o in opt_set))
+
+if mode not in valid_modes:
+ print('%s is not a valid PXEBOOT_MODE' % mode)
+ sys.exit(1)