• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

localstack / localstack / 16820655284

07 Aug 2025 05:03PM UTC coverage: 86.841% (-0.05%) from 86.892%
16820655284

push

github

web-flow
CFNV2: support CDK bootstrap and deployment (#12967)

32 of 38 new or added lines in 5 files covered. (84.21%)

2013 existing lines in 125 files now uncovered.

66606 of 76699 relevant lines covered (86.84%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.08
/localstack-core/localstack/utils/iputils.py
1
"""
2
IP utils wraps the 'ip' cli command (from iproute2) and creates a pythonic OO interface around
3
some of its functionality.
4
"""
5

6
import ipaddress
1✔
7
import json
1✔
8
import subprocess as sp
1✔
9
from collections.abc import Generator
1✔
10
from typing import Any, TypedDict
1✔
11

12
from cachetools import TTLCache, cached
1✔
13

14

15
def ip_available() -> bool:
1✔
16
    try:
×
17
        output = sp.run(["ip"], capture_output=True)
×
18
        return "Usage:" in output.stderr.decode("utf8")
×
19
    except FileNotFoundError:
×
UNCOV
20
        return False
×
21

22

23
class Route(TypedDict):
1✔
24
    """
25
    Represents an entry in the routing table.
26
    """
27

28
    dst: str | ipaddress.IPv4Network
1✔
29
    dev: str
1✔
30
    protocol: str
1✔
31
    prefsrc: ipaddress.IPv4Address
1✔
32
    gateway: ipaddress.IPv4Address | None
1✔
33
    metric: int | None
1✔
34
    flags: list[str]
1✔
35

36

37
# Cache with 10 second expiry for the outputs of the results of running the IP command
38
IP_RESULTS_CACHE = TTLCache(maxsize=100, ttl=10)
1✔
39

40

41
def get_routes() -> Generator[Route, None, None]:
1✔
42
    """
43
    Return a generator over the routes.
44

45
    :return: a generator over route descriptions
46
    """
47
    yield from _run_ip_command("route", "show")
1✔
48

49

50
def get_route(name: str) -> Route:
1✔
51
    """
52
    Get information about a single route.
53

54
    :param name: name of the route to get details for
55
    :return: the route definition
56
    """
57
    return _run_ip_command("route", "show", name)[0]
1✔
58

59

60
def get_default_route() -> Route:
1✔
61
    """
62
    Get information about the default route.
63

64
    :return: the definition of the default route
65
    """
66
    return get_route("default")
1✔
67

68

69
def get_default_gateway() -> ipaddress.IPv4Address:
1✔
70
    """
71
    Get the IPv4 address for the default gateway.
72

73
    :return: the IPv4 address for the default gateway
74
    """
75
    return ipaddress.IPv4Address(get_default_route()["gateway"])
1✔
76

77

78
# Internal command to run `ip --json ...`
79
@cached(cache=IP_RESULTS_CACHE)
1✔
80
def _run_ip_command(*args) -> Any:
1✔
81
    cmd = ["ip", "--json"] + list(args)
1✔
82

83
    try:
1✔
84
        result = sp.check_output(cmd)
1✔
85
    except FileNotFoundError:
×
UNCOV
86
        raise RuntimeError("could not find ip binary on path")
×
87
    return json.loads(result.decode("utf8"))
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc