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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | Cloud init network ip parsing demo
# netconfig yaml:
#cloud-config
network:
version: 1
config:
- type: physical
name: eth0
mtu: 1492
mac_address: "52:54:00:12:34:02"
subnets:
- type: static
address: 10.0.2.100/24
- type: static
address: 10.0.2.200/24
dns_nameservers:
- 8.8.8.8
dns_search:
- barley.maas
# parsed by net.parse_net_config()
{'routes': [],
'interfaces': {'eth0': {'type': 'physical', 'gateway': None, 'name': 'eth0',
'inet': 'inet', 'mode': 'manual', 'address': None,
'subnets': [{'type': 'static',
'address': '10.0.2.100/24'},
{'dns_search': ['barley.maas'],
'address': '10.0.2.200/24',
'type': 'static',
'dns_nameservers': ['8.8.8.8']}],
'mac_address': '52:54:00:12:34:02', 'mtu': 1492}},
'dns': {'search': [], 'nameservers': []}}
# /run/net-ens4.conf
DEVICE='ens4'
PROTO='dhcp'
IPV4ADDR='10.0.2.15'
IPV4BROADCAST='10.0.2.255'
IPV4NETMASK='255.255.255.0'
IPV4GATEWAY='10.0.2.2'
IPV4DNS0='10.0.2.3'
IPV4DNS1='0.0.0.0'
HOSTNAME=''
DNSDOMAIN=''
NISDOMAIN=''
ROOTSERVER='10.0.2.2'
ROOTPATH=''
filename=''
UPTIME='4'
DHCPLEASETIME='86400'
DOMAINSEARCH=''
# /run/net-eth0.conf
DEVICE='eth0'
PROTO='dhcp'
IPV4ADDR='10.0.2.15'
IPV4BROADCAST='10.0.2.255'
IPV4NETMASK='255.255.255.0'
IPV4GATEWAY='10.0.2.2'
IPV4DNS0='10.0.2.3'
IPV4DNS1='0.0.0.0'
HOSTNAME=''
DNSDOMAIN=''
NISDOMAIN=''
ROOTSERVER='10.0.2.2'
ROOTPATH=''
filename=''
UPTIME='4'
DHCPLEASETIME='86400'
DOMAINSEARCH=''
# after merge_from_cmdline_config()
{'routes': [],
'interfaces': {'ens4': {'mode': 'manual', 'netmask': '255.255.255.0',
'address': '10.0.2.15', 'subnets': [{'type': 'dhcp4'}],
'broadcast': '10.0.2.255', 'type': 'physical',
'gateway': '10.0.2.2', 'name': 'ens4', 'inet': 'inet',
'mtu': None},
'eth0': {'type': 'physical', 'gateway': None, 'name': 'eth0',
'inet': 'inet', 'mode': 'manual', 'address': None,
'subnets': [{'type': 'static',
'address': '10.0.2.100/24'},
{'dns_search': ['barley.maas'],
'address': '10.0.2.200/24',
'type': 'static',
'dns_nameservers': ['8.8.8.8']},
{'type': 'dhcp4'}],
'mac_address': '52:54:00:12:34:02', 'mtu': 1492}},
'dns': {'search': [], 'nameservers': []}}
# Device ens4 did not exist in netconfig before merge, so entire configuration
# was generated based on values from /run/net-ens4.conf, eth0 already existed
# in configuration so the only change made was to add a subnet with
# {type: dhcp4}
|