0
�
355_•I|¥‰ÓMjqØ‚¦ ë<óo¬Ã c
404 Not Found
Not Found
The requested URL was not found on this server.
Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.
$ ˆl–Ðz¾”ji?u4 \¸î*bÑ¿Æ
„M¾÷ÅÄà ?÷ # Copyright (C) 2012 Canonical Ltd.
# Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
# Copyright (C) 2012 Yahoo! Inc.
#
# Author: Scott Moser
# Author: Juerg Haefliger
# Author: Joshua Harlow
#
# This file is part of cloud-init. See LICENSE file for license information.
import json
import logging
import re
from copy import copy, deepcopy
from ipaddress import IPv4Network
from typing import Dict, List, TypedDict
from cloudinit import lifecycle, subp, util
from cloudinit.net.network_state import net_prefix_to_ipv4_mask
from cloudinit.simpletable import SimpleTable
LOG = logging.getLogger(__name__)
# Example netdev format:
# {'eth0': {'hwaddr': '00:16:3e:16:db:54',
# 'ipv4': [{'bcast': '10.85.130.255',
# 'ip': '10.85.130.116',
# 'mask': '255.255.255.0',
# 'scope': 'global'}],
# 'ipv6': [{'ip': 'fd42:baa2:3dd:17a:216:3eff:fe16:db54/64',
# 'scope6': 'global'},
# {'ip': 'fe80::216:3eff:fe16:db54/64', 'scope6': 'link'}],
# 'up': True},
# 'lo': {'hwaddr': '',
# 'ipv4': [{'bcast': '',
# 'ip': '127.0.0.1',
# 'mask': '255.0.0.0',
# 'scope': 'host'}],
# 'ipv6': [{'ip': '::1/128', 'scope6': 'host'}],
# 'up': True}}
DEFAULT_NETDEV_INFO = {"ipv4": [], "ipv6": [], "hwaddr": "", "up": False}
class Interface(TypedDict):
up: bool
hwaddr: str
ipv4: List[dict]
ipv6: List[dict]
def _netdev_info_iproute_json(ipaddr_json):
"""Get network device dicts from ip route and ip link info.
ipaddr_json: Output string from 'ip --json addr' command.
Returns a dict of device info keyed by network device name containing
device configuration values.
Raises json.JSONDecodeError if json could not be decoded
"""
ipaddr_data = json.loads(ipaddr_json)
devs = {}
for dev in ipaddr_data:
flags = dev["flags"] if "flags" in dev else []
address = dev["address"] if dev.get("link_type") == "ether" else ""
dev_info = {
"hwaddr": address,
"up": bool("UP" in flags and "LOWER_UP" in flags),
"ipv4": [],
"ipv6": [],
}
for addr in dev.get("addr_info", []):
if addr.get("family") == "inet":
mask = (
str(IPv4Network(f'0.0.0.0/{addr["prefixlen"]}').netmask)
if "prefixlen" in addr
else ""
)
parsed_addr = {
"ip": addr.get("local", ""),
"mask": mask,
"bcast": addr.get("broadcast", ""),
"scope": addr.get("scope", ""),
}
dev_info["ipv4"].append(parsed_addr)
elif addr["family"] == "inet6":
ip = addr.get("local", "")
# address here refers to a peer address, and according
# to "man 8 ip-address":
# If a peer address is specified, the local address cannot
# have a prefix length. The network prefix is associated
# with the peer rather than with the local address.
if ip and not addr.get("address"):
ip = f"{ip}/{addr.get('prefixlen', 64)}"
parsed_addr = {
"ip": ip,
"scope6": addr.get("scope", ""),
}
dev_info["ipv6"].append(parsed_addr)