Support explicitly configured DHCP interfaces

Based on

 http://git.openstack.org/cgit/openstack/nova/tree/nova/tests/unit/network/test_network_info.py#n941

there is the possibility to get an explicit request for an interface to
be configured with DHCP. Honor it.

Change-Id: Ic4282f58e3751827af2777bf99a9e0c5d674cdba
This commit is contained in:
Monty Taylor 2015-07-15 15:45:04 -04:00 committed by Chris Jones
parent cc401d456b
commit 923de8740c
35 changed files with 181 additions and 7 deletions

View File

@ -97,9 +97,14 @@ def write_redhat_interfaces(interfaces, sys_interfaces):
continue continue
if iname not in sys_interfaces: if iname not in sys_interfaces:
continue continue
if interface['type'] == 'ipv4':
interface_name = sys_interfaces[iname] interface_name = sys_interfaces[iname]
files_to_write.update( files_to_write.update(
_write_rh_interface(interface_name, interface)) _write_rh_interface(interface_name, interface))
if interface['type'] == 'ipv4_dhcp':
interface_name = sys_interfaces[iname]
files_to_write.update(
_write_rh_dhcp(interface_name, interface['mac_address']))
for mac, iname in sorted( for mac, iname in sorted(
sys_interfaces.items(), key=lambda x: x[1]): sys_interfaces.items(), key=lambda x: x[1]):
if _exists_rh_interface(iname): if _exists_rh_interface(iname):
@ -129,10 +134,22 @@ def write_debian_interfaces(interfaces, sys_interfaces):
if iname not in sys_interfaces: if iname not in sys_interfaces:
continue continue
interface = interfaces[iname] interface = interfaces[iname]
link_type = "inet" interface_name = sys_interfaces[iname]
iface_path = os.path.join(eni_d_path, '%s.cfg' % interface_name)
if interface['type'] == 'ipv4_dhcp':
result = "auto {0}\n".format(interface_name)
result += "iface {0} inet dhcp\n".format(interface_name)
files_to_write[iface_path] = result
continue
if interface['type'] == 'ipv6': if interface['type'] == 'ipv6':
link_type = "inet6" link_type = "inet6"
interface_name = sys_interfaces[iname] elif interface['type'] == 'ipv4':
link_type = "inet"
# We do not know this type of entry
if not link_type:
continue
result = "auto {0}\n".format(interface_name) result = "auto {0}\n".format(interface_name)
result += "iface {name} {link_type} static\n".format( result += "iface {name} {link_type} static\n".format(
name=interface_name, link_type=link_type) name=interface_name, link_type=link_type)
@ -148,7 +165,6 @@ def write_debian_interfaces(interfaces, sys_interfaces):
result += pre_down.format( result += pre_down.format(
net=route['network'], mask=route['netmask'], net=route['network'], mask=route['netmask'],
gw=route['gateway']) gw=route['gateway'])
iface_path = os.path.join(eni_d_path, '%s.cfg' % interface_name)
files_to_write[iface_path] = result files_to_write[iface_path] = result
for mac, iname in sorted( for mac, iname in sorted(
sys_interfaces.items(), key=lambda x: x[1]): sys_interfaces.items(), key=lambda x: x[1]):

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
bc:76:4e:12:a4:bb

View File

@ -0,0 +1 @@
1

View File

@ -59,7 +59,14 @@
], ],
"ip_address": "192.0.2.2", "ip_address": "192.0.2.2",
"id": "network2" "id": "network2"
},
{
"network_id": "33333333-3333-3333-3333-333333333333",
"type": "ipv4_dhcp",
"link": "tap8aac87b9-37",
"id": "network3"
} }
], ],
"links": [ "links": [
{ {
@ -82,6 +89,14 @@
"type": null, "type": null,
"id": "tap234ab34c-f1", "id": "tap234ab34c-f1",
"vif_id": "acdb875a-87da-76cb-984c-acd9a75dbca7" "vif_id": "acdb875a-87da-76cb-984c-acd9a75dbca7"
},
{
"ethernet_mac_address": "BC:76:4E:12:a4:bb",
"mtu": 1500,
"type": null,
"id": "tap8aac87b9-37",
"vif_id": "f12bedfa-87bv-a39f-1234-aaeb55bea7e6"
} }
] ]
} }

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
bc:76:4e:12:a4:bb

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
bc:76:4e:12:a4:bb

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
bc:76:4e:12:a4:bb

View File

@ -0,0 +1 @@
1

View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
TYPE=Ethernet TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

View File

@ -8,3 +8,6 @@ iface eth0 inet dhcp
### Write /etc/network/interfaces.d/eth1.cfg ### Write /etc/network/interfaces.d/eth1.cfg
auto eth1 auto eth1
iface eth1 inet dhcp iface eth1 inet dhcp
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp

View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
TYPE=Ethernet TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
TYPE=Ethernet TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

View File

@ -8,3 +8,6 @@ iface eth0 inet dhcp
### Write /etc/network/interfaces.d/eth1.cfg ### Write /etc/network/interfaces.d/eth1.cfg
auto eth1 auto eth1
iface eth1 inet dhcp iface eth1 inet dhcp
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp

View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0 NETMASK=255.255.224.0
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=BC:76:4E:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1 ### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0 ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0 NETMASK0=255.240.0.0

View File

@ -17,6 +17,9 @@ iface eth1 inet static
pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp
### Write /etc/resolv.conf ### Write /etc/resolv.conf
nameserver 72.3.128.241 nameserver 72.3.128.241
nameserver 72.3.128.240 nameserver 72.3.128.240

View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0 NETMASK=255.255.224.0
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=BC:76:4E:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1 ### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0 ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0 NETMASK0=255.240.0.0

View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0 NETMASK=255.255.224.0
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=BC:76:4E:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1 ### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0 ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0 NETMASK0=255.240.0.0

View File

@ -17,6 +17,9 @@ iface eth1 inet static
pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp
### Write /etc/resolv.conf ### Write /etc/resolv.conf
nameserver 72.3.128.241 nameserver 72.3.128.241
nameserver 72.3.128.240 nameserver 72.3.128.240

View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
TYPE=Ethernet TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

View File

@ -8,3 +8,6 @@ iface eth0 inet dhcp
### Write /etc/network/interfaces.d/eth1.cfg ### Write /etc/network/interfaces.d/eth1.cfg
auto eth1 auto eth1
iface eth1 inet dhcp iface eth1 inet dhcp
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp

View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
TYPE=Ethernet TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
TYPE=Ethernet TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

View File

@ -8,3 +8,6 @@ iface eth0 inet dhcp
### Write /etc/network/interfaces.d/eth1.cfg ### Write /etc/network/interfaces.d/eth1.cfg
auto eth1 auto eth1
iface eth1 inet dhcp iface eth1 inet dhcp
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp

View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0 NETMASK=255.255.224.0
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1 ### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0 ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0 NETMASK0=255.240.0.0

View File

@ -17,6 +17,9 @@ iface eth1 inet static
pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp
### Write /etc/resolv.conf ### Write /etc/resolv.conf
nameserver 72.3.128.241 nameserver 72.3.128.241
nameserver 72.3.128.240 nameserver 72.3.128.240

View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0 NETMASK=255.255.224.0
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1 ### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0 ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0 NETMASK0=255.240.0.0

View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0 NETMASK=255.255.224.0
ONBOOT=yes ONBOOT=yes
NM_CONTROLLED=no NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1 ### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0 ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0 NETMASK0=255.240.0.0

View File

@ -17,6 +17,9 @@ iface eth1 inet static
pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp
### Write /etc/resolv.conf ### Write /etc/resolv.conf
nameserver 72.3.128.241 nameserver 72.3.128.241
nameserver 72.3.128.240 nameserver 72.3.128.240

View File

@ -26,6 +26,17 @@ for vendor_dir in $(find $SAMPLE_DIR \
> $SAMPLE_DIR/test/$vendor.keys.out > $SAMPLE_DIR/test/$vendor.keys.out
for distro in debian ubuntu redhat fedora centos ; do for distro in debian ubuntu redhat fedora centos ; do
python glean/cmd.py \ python glean/cmd.py \
-n --root $vendor_dir --distro $distro > $SAMPLE_DIR/test/$vendor.$distro.network.out -n --root $vendor_dir --distro $distro | python -c 'import sys
skipping = False
for line in sys.stdin.readlines():
if "eth2" in line:
skipping = True
continue
if line.startswith("### Write"):
skipping = False
if skipping:
continue
sys.stdout.write(line)
' > $SAMPLE_DIR/test/$vendor.$distro.network.out
done done
done done