Skip to content

Commit

Permalink
feat(#116): add namespace to container list
Browse files Browse the repository at this point in the history
Add tabulate to format tables.
Refactor `get_all_containers` to add namespace to tuple.
  • Loading branch information
SteinRobert committed Jul 28, 2022
1 parent 06d41bb commit 1f3eaba
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
21 changes: 1 addition & 20 deletions client/gefyra/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import logging

from gefyra.api import get_containers_and_print, get_bridges_and_print
from gefyra.configuration import ClientConfiguration
from gefyra.local.utils import StoreDictKeyPair

Expand Down Expand Up @@ -186,26 +187,6 @@ def up_command(args):
up(config=configuration)


def get_containers_and_print():
from gefyra.api import list_containers

containers = list_containers()
containers.insert(0, ("NAME", "IP_ADDRESS"))
for name, ip in containers:
print("{:<30}{}".format(name, ip))


def get_bridges_and_print():
from gefyra.api import list_interceptrequests

ireqs = list_interceptrequests()
if ireqs:
for ireq in ireqs:
print(ireq)
else:
logger.info("No active bridges found")


def version(config, check: bool):
import requests

Expand Down
23 changes: 23 additions & 0 deletions client/gefyra/api/list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from tabulate import tabulate
from typing import List

from gefyra.configuration import default_configuration
Expand All @@ -9,6 +10,28 @@
logger = logging.getLogger(__name__)


def get_containers_and_print():
from gefyra.api import list_containers

containers = list_containers()
print(
tabulate(
containers, headers=["NAME", "IP ADDRESS", "NAMESPACE"], tablefmt="plain"
)
)


def get_bridges_and_print():
from gefyra.api import list_interceptrequests

ireqs = list_interceptrequests()
if ireqs:
for ireq in ireqs:
print(ireq)
else:
logger.info("No active bridges found")


@stopwatch
def list_interceptrequests(config=default_configuration) -> List[str]:
from gefyra.local.bridge import get_all_interceptrequests
Expand Down
20 changes: 13 additions & 7 deletions client/gefyra/local/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,22 @@ def get_all_interceptrequests(config: ClientConfiguration) -> list:


def get_all_containers(config: ClientConfiguration) -> list:
containers_with_ips = []
container_information = []
gefyra_net = config.DOCKER.networks.get(config.NETWORK_NAME)
containers = gefyra_net.attrs.get("Containers")
containers = gefyra_net.containers
# filter out gefyra-cargo container as well as fields other than name and ip
for _, entry in containers.items():
if entry.get("Name") != "gefyra-cargo":
containers_with_ips.append(
(entry["Name"], entry["IPv4Address"].split("/")[0])
for container in containers:
if container.name != "gefyra-cargo":
container_information.append(
(
container.name,
container.attrs["NetworkSettings"]["Networks"]["gefyra"][
"IPAddress"
].split("/")[0],
container.attrs["HostConfig"]["DnsSearch"][0].split(".")[0],
)
)
return containers_with_ips
return container_information


def remove_interceptrequest_remainder(config: ClientConfiguration):
Expand Down
14 changes: 13 additions & 1 deletion client/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ classifiers = [
python = "^3.8"
kubernetes = "^19.15.0"
docker = "^5.0.3"
tabulate = "^0.8.10"

[tool.poetry.dev-dependencies]
flake8-bugbear = "^22.1.11"
Expand Down

0 comments on commit 1f3eaba

Please sign in to comment.