Skip to content

Commit

Permalink
Drop -o option
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Sep 4, 2024
1 parent 2514af0 commit 849d316
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 172 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Docker image available at `ghcr.io/ricardobranco777/cloudview:latest`
## Usage

```
usage: cloudview.py [-h] [-c CONFIG] [-f FORMAT] [-l {none,debug,info,warning,error,critical}] [-o {text,json}] [-P {ec2,gce,azure_arm,openstack}] [-r]
usage: cloudview.py [-h] [-c CONFIG] [-f FORMAT] [-l {none,debug,info,warning,error,critical}] [-P {ec2,gce,azure_arm,openstack}] [-r]
[-s {name,state,time}] [-S {error,migrating,normal,paused,pending,rebooting,reconfiguring,running,starting,stopped,stopping,suspended,terminated,unknown,updating}]
[-t TIME_FORMAT] [-v] [--version]
Expand All @@ -25,8 +25,6 @@ options:
output fields (default: provider,name,size,state,time,location)
-l {none,debug,info,warning,error,critical}, --log {none,debug,info,warning,error,critical}
logging level (default: error)
-o {text,json}, --output {text,json}
output type (default: text)
-P {ec2,gce,azure_arm,openstack}, --providers {ec2,gce,azure_arm,openstack}
list only specified providers (default: None)
-r, --reverse reverse sort (default: False)
Expand Down
46 changes: 15 additions & 31 deletions cloudview/cloudview.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
from .azure import Azure
from .gce import GCE
from .openstack import Openstack
from .instance import CSP, STATES
from .output import Output
from .instance import CSP, Instance, STATES
from .utils import dateit, read_file
from . import __version__

Expand Down Expand Up @@ -69,9 +68,9 @@ def get_clients(
return clients


def print_instances(client: CSP) -> None:
def get_instances(client: CSP) -> list[Instance]:
"""
Print instances
Get instances
"""
instances = [
instance
Expand All @@ -82,23 +81,7 @@ def print_instances(client: CSP) -> None:
instances.sort(
key=itemgetter(args.sort, "name"), reverse=args.reverse # type:ignore
)
for instance in instances:
instance.provider = "/".join([instance.provider, instance.cloud])
assert not isinstance(instance.time, str)
instance.time = dateit(instance.time, args.time)
Output().info(instance)


def print_info() -> None:
"""
Print information about instances
"""
clients = get_clients(config_file=args.config)
Output().header()
if len(clients) > 0:
with ThreadPoolExecutor(max_workers=len(clients)) as executor:
executor.map(print_instances, clients)
Output().footer()
return instances


def parse_args() -> argparse.Namespace:
Expand All @@ -124,13 +107,6 @@ def parse_args() -> argparse.Namespace:
choices=["none", "debug", "info", "warning", "error", "critical"],
help="logging level",
)
argparser.add_argument(
"-o",
"--output",
default="text",
choices=["text", "json"],
help="output type",
)
argparser.add_argument(
"-P",
"--providers",
Expand Down Expand Up @@ -191,12 +167,20 @@ def main() -> None:
"location": "<15",
}
keys = {key: keys.get(key, "") for key in args.fields.split(",")}

if args.verbose:
keys |= {"id": ""}
output_format = " ".join(f"{{{key}:{align}}}" for key, align in keys.items())
print(output_format.format_map({key: key.upper() for key in keys}))

Output(type=args.output.lower(), keys=keys)
print_info()
clients = get_clients(config_file=args.config)
if len(clients) > 0:
with ThreadPoolExecutor(max_workers=len(clients)) as executor:
for instances in executor.map(get_instances, clients):
for instance in instances:
instance.provider = f"{instance.provider}/{instance.cloud}"
assert not isinstance(instance.time, str)
instance.time = dateit(instance.time, args.time)
print(output_format.format_map(instance.__dict__))


if __name__ == "__main__":
Expand Down
67 changes: 0 additions & 67 deletions cloudview/output.py

This file was deleted.

71 changes: 0 additions & 71 deletions tests/test_output.py

This file was deleted.

0 comments on commit 849d316

Please sign in to comment.