-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathprocess_userdata.py
More file actions
executable file
·55 lines (45 loc) · 1.59 KB
/
process_userdata.py
File metadata and controls
executable file
·55 lines (45 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
import argparse
import shutil
import os
import subprocess
nspreboot_str = '''\
<NS-PRE-BOOT-CONFIG>
<NS-CONFIG>
add route 0.0.0.0 0.0.0.0 %s
add ha node 1 %s
</NS-CONFIG>
<NS-BOOTSTRAP>
<SKIP-DEFAULT-BOOTSTRAP>YES</SKIP-DEFAULT-BOOTSTRAP>
<NEW-BOOTSTRAP-SEQUENCE>YES</NEW-BOOTSTRAP-SEQUENCE>
<MGMT-INTERFACE-CONFIG>
<INTERFACE-NUM>eth0</INTERFACE-NUM>
<IP>%s</IP>
<SUBNET-MASK>%s</SUBNET-MASK>
</MGMT-INTERFACE-CONFIG>
</NS-BOOTSTRAP>
</NS-PRE-BOOT-CONFIG>
'''
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--nsip', required=True)
parser.add_argument('--other-node-nsip', required=True)
parser.add_argument('--netmask', default="255.255.255.0")
parser.add_argument('--gateway', required=True)
parser.add_argument('--output-dir', default="iso_preboot_config")
args = parser.parse_args()
output_str = nspreboot_str % (args.gateway, args.other_node_nsip, args.nsip, args.netmask)
# Check if output directory exists
if os.path.exists(args.output_dir):
print('Deleting existing output dir %s', args.output_dir)
shutil.rmtree(args.output_dir)
os.makedirs(args.output_dir)
output_file = os.path.join(args.output_dir, 'userdata')
with open(output_file, 'w') as fh:
fh.write(output_str)
# Create iso file
iso_output_file = '.'.join([args.output_dir,'iso'])
cp = subprocess.run(['mkisofs', '-o', iso_output_file, args.output_dir])
cp.check_returncode()
if __name__ == '__main__':
main()