3
3
import logging .handlers
4
4
import os
5
5
import sys
6
+ from pathlib import Path
6
7
7
8
from esxi_netinit .esxconfig import ESXConfig
9
+ from esxi_netinit .meta_data import MetaDataData
8
10
from esxi_netinit .network_data import NetworkData
9
11
10
12
OLD_MGMT_PG = "Management Network"
@@ -38,9 +40,24 @@ def setup_logger(log_level=logging.INFO):
38
40
logger .error ("Failed to setup syslog for logging" )
39
41
40
42
41
- def main (json_file , dry_run ):
42
- network_data = NetworkData .from_json_file (json_file )
43
- esx = ESXConfig (network_data , dry_run = dry_run )
43
+ def main (config_dir , dry_run ):
44
+ config_path = Path (config_dir )
45
+ network_data_file = config_path / "network_data.json"
46
+ meta_data_file = config_path / "meta_data.json"
47
+
48
+ if not network_data_file .exists ():
49
+ logger .error ("Missing network_data.json in %s" , config_dir )
50
+ sys .exit (1 )
51
+
52
+ if not meta_data_file .exists ():
53
+ logger .error ("Missing meta_data.json in %s" , config_dir )
54
+ sys .exit (1 )
55
+
56
+ network_data = NetworkData .from_json_file (network_data_file )
57
+ meta_data = MetaDataData .from_json_file (meta_data_file )
58
+
59
+ esx = ESXConfig (network_data , meta_data , dry_run = dry_run )
60
+ esx .configure_hostname ()
44
61
esx .clean_default_network_setup (OLD_MGMT_PG , OLD_VSWITCH )
45
62
esx .configure_vswitch (
46
63
uplink = esx .identify_uplink (), switch_name = NEW_VSWITCH , mtu = 9000
@@ -56,7 +73,11 @@ def main(json_file, dry_run):
56
73
57
74
if __name__ == "__main__" :
58
75
parser = argparse .ArgumentParser (description = "Network configuration script" )
59
- parser .add_argument ("json_file" , help = "Path to the JSON configuration file" )
76
+ parser .add_argument (
77
+ "config_dir" ,
78
+ help = "Path to the configuration dir containing "
79
+ "network_data.json, meta_data.json" ,
80
+ )
60
81
parser .add_argument (
61
82
"--dry-run" ,
62
83
action = "store_true" ,
@@ -67,7 +88,7 @@ def main(json_file, dry_run):
67
88
setup_logger ()
68
89
69
90
try :
70
- main (args .json_file , args .dry_run )
91
+ main (args .config_dir , args .dry_run )
71
92
except Exception :
72
93
logger .exception ("Error configuring network" )
73
94
sys .exit (1 )
0 commit comments