1
+ import logging
1
2
from functools import cached_property
2
3
3
4
from .esxhost import ESXHost
4
5
from .network_data import NetworkData
5
6
from .nic import NIC
6
7
from .nic_list import NICList
7
8
9
+ logger = logging .getLogger (__name__ )
10
+
8
11
9
12
class ESXConfig :
10
13
def __init__ (self , network_data : NetworkData , dry_run = False ) -> None :
11
14
self .network_data = network_data
12
15
self .dry_run = dry_run
13
16
self .host = ESXHost (dry_run )
14
17
15
- def add_default_mgmt_interface (
16
- self , portgroup_name , switch_name , interface_name = "vmk0"
17
- ):
18
- self .host .portgroup_add (portgroup_name = portgroup_name , switch_name = switch_name )
19
- self .host .add_ip_interface (name = interface_name , portgroup_name = portgroup_name )
20
-
21
18
def clean_default_network_setup (self , portgroup_name , switch_name ):
22
19
"""Removes default networking setup left by the installer."""
23
20
self .host .delete_vmknic (portgroup_name = portgroup_name )
@@ -26,6 +23,11 @@ def clean_default_network_setup(self, portgroup_name, switch_name):
26
23
)
27
24
self .host .destroy_vswitch (name = switch_name )
28
25
26
+ def configure_portgroups (self , switch_name : str , portgroups ):
27
+ """Adds each requested portgroup to the specified switch."""
28
+ for portgroup_name in portgroups :
29
+ self .host .portgroup_add (portgroup_name , switch_name )
30
+
29
31
def configure_default_route (self ):
30
32
"""Configures default route.
31
33
@@ -34,7 +36,7 @@ def configure_default_route(self):
34
36
route = self .network_data .default_route ()
35
37
self .host .configure_default_route (route .gateway )
36
38
37
- def configure_portgroups (self , switch_name = "vSwitch0" ):
39
+ def configure_vlans (self , switch_name = "vSwitch0" ):
38
40
portgroups = []
39
41
for link in self .network_data .links :
40
42
if link .type == "vlan" :
@@ -45,13 +47,23 @@ def configure_portgroups(self, switch_name="vSwitch0"):
45
47
portgroups .append (pg_name )
46
48
return portgroups
47
49
48
- def configure_management_interface (self ):
49
- mgmt_network = next (
50
- net for net in self .network_data .networks if net .default_routes ()
51
- )
52
- return self .host .change_ip (
53
- "vmk0" , mgmt_network .ip_address , mgmt_network .netmask
54
- )
50
+ def configure_management_interface (self , mgmt_portgroup : str ):
51
+ for net in self .network_data .networks :
52
+ logger .info (
53
+ "Creating %s with MAC %s for network %s" ,
54
+ net .id ,
55
+ net .link .ethernet_mac_address ,
56
+ net .network_id ,
57
+ )
58
+ self .host .add_ip_interface (
59
+ net .id , mgmt_portgroup , net .link .ethernet_mac_address , net .link .mtu
60
+ )
61
+ if net .type == "ipv4" :
62
+ self .host .set_static_ipv4 (net .id , net .ip_address , net .netmask )
63
+ elif net .type == "ipv4_dhcp" :
64
+ self .host .set_dhcp_ipv4 (net .id )
65
+ else :
66
+ raise NotImplementedError (f"net type { net .type } " )
55
67
56
68
def configure_vswitch (self , uplink : NIC , switch_name : str , mtu : int ):
57
69
"""Sets up vSwitch."""
0 commit comments