Skip to content

Commit 2bb777d

Browse files
authored
CP-308116: Handle network-init with new netdev ordering (#6483)
1. network-init script need read inventory and get management address type. This item should be written to inventory by networkd, the same as management interface item. Because host-installer will not write it from the new netdev ordering, see xenserver/host-installer@33aa793. 2. networl-init renames network name label under common criteria. There was hard code ethx to determine the interface position. Now change to get position from the bridge which is right both on legacy and new ordering method.
2 parents babf619 + d23ff5e commit 2bb777d

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

ocaml/networkd/lib/network_config.ml

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ let parse_dns_config args =
9797
let domains = get_list_from ~sep:" " ~key:"DOMAIN" args in
9898
(nameservers, domains)
9999

100-
let write_manage_iface_to_inventory bridge_name =
100+
let write_manage_iface_to_inventory bridge_name management_address_type =
101101
info "Writing management interface to inventory: %s" bridge_name ;
102-
Inventory.update Inventory._management_interface bridge_name
102+
Inventory.update Inventory._management_interface bridge_name ;
103+
info "Writing management address type to inventory: %s"
104+
management_address_type ;
105+
Inventory.update Inventory._management_address_type management_address_type
103106

104107
let read_management_conf interface_order =
105108
try
@@ -142,6 +145,22 @@ let read_management_conf interface_order =
142145
(fun x -> if x.name = device then Some x.position else None)
143146
order
144147
in
148+
let (ipv4_conf, ipv4_gateway), (ipv6_conf, ipv6_gateway) =
149+
match (List.assoc_opt "MODE" args, List.assoc_opt "MODEV6" args) with
150+
| None, None ->
151+
error "%s: at least one of 'MODE', 'MODEV6' needs to be specified"
152+
__FUNCTION__ ;
153+
raise Read_error
154+
| v4, v6 ->
155+
(parse_ipv4_config args v4, parse_ipv6_config args v6)
156+
in
157+
let management_address_type =
158+
(* Default to IPv4 unless we have only got an IPv6 admin interface *)
159+
if ipv4_conf = None4 && ipv6_conf <> None6 then
160+
"IPv6"
161+
else
162+
"IPv4"
163+
in
145164
let bridge_name =
146165
let inventory_bridge =
147166
try Some (Inventory.lookup Inventory._management_interface)
@@ -160,23 +179,14 @@ let read_management_conf interface_order =
160179
in
161180
debug "No management bridge in inventory file... using %s" bridge ;
162181
if not device_already_renamed then
163-
write_manage_iface_to_inventory bridge ;
182+
write_manage_iface_to_inventory bridge management_address_type ;
164183
bridge
165184
| Some bridge ->
166185
debug "Management bridge in inventory file: %s" bridge ;
167186
bridge
168187
in
169188
let mac = Network_utils.Ip.get_mac device in
170189
let dns = parse_dns_config args in
171-
let (ipv4_conf, ipv4_gateway), (ipv6_conf, ipv6_gateway) =
172-
match (List.assoc_opt "MODE" args, List.assoc_opt "MODEV6" args) with
173-
| None, None ->
174-
error "%s: at least one of 'MODE', 'MODEV6' needs to be specified"
175-
__FUNCTION__ ;
176-
raise Read_error
177-
| v4, v6 ->
178-
(parse_ipv4_config args v4, parse_ipv6_config args v6)
179-
in
180190

181191
let phy_interface = {default_interface with persistent_i= true} in
182192
let bridge_interface =

scripts/network-init

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,28 @@ prepare_networking() {
100100

101101
rename_network_label() {
102102
# In common criteria certification deployment, user must ensure:
103-
# - The 1st NIC (eth0) is for Management Network
104-
# - The 2nd NIC (eth1) is for Storage Network
105-
# - others (ethX, X>=2) is for Guest Network
103+
# - The 1st NIC is for Management Network
104+
# - The 2nd NIC is for Storage Network
105+
# - others (X>=2) is for Guest Network
106106
# This function is to rename these network labels to appropriate.
107107

108108
if [ "${CC_PREPARATIONS}" != "true" ]; then
109109
echo "Skipped common criteria settings"
110110
return
111111
fi
112112

113-
for device in $(ls /sys/class/net | grep -E '^eth[0-9]+$')
113+
for device_path in /sys/class/net/*
114114
do
115-
device_id=$(echo ${device} | sed 's/^eth//')
115+
device=$(basename "${device_path}")
116+
network_uuid=$(${XE} pif-list device="${device}" params=network-uuid --minimal)
117+
if [ -z "${network_uuid}" ]; then
118+
continue
119+
fi
120+
bridge=$(${XE} network-list uuid="${network_uuid}" params=bridge --minimal)
121+
if [ -z "${bridge}" ]; then
122+
continue
123+
fi
124+
device_id=$(echo ${bridge} | sed 's/^xenbr//')
116125
if [ ${device_id} -eq 0 ]; then
117126
name_label="Management Network"
118127
elif [ ${device_id} -eq 1 ]; then
@@ -127,8 +136,7 @@ rename_network_label() {
127136
continue
128137
fi
129138

130-
network_uuid=$(${XE} pif-list device=${device} params=network-uuid --minimal)
131-
${XE} network-param-set uuid=${network_uuid} name-label="${name_label}"
139+
${XE} network-param-set uuid="${network_uuid}" name-label="${name_label}"
132140
echo "Renamed network label of ${network_uuid} to ${name_label}, device: ${device}"
133141
done
134142
}

0 commit comments

Comments
 (0)