From 7581edc59823c1c3b7cac442aaed91fc65e4a290 Mon Sep 17 00:00:00 2001 From: Pallab Pain Date: Sat, 27 Jul 2024 14:45:17 +0530 Subject: [PATCH] refactor(apply): remove apply summary and overview table The apply command provides an overview of how much time it may take and the actions that will be performed during apply. However, the calculation was based on estimates and are incorrect. Similary, the actions are also incorrect at many places and neither do we need it. This commit removes the chunk of code that prints that info. Wrike Ticket: https://www.wrike.com/open.htm?id=1183537395 --- riocli/apply/__init__.py | 5 ++- riocli/apply/parse.py | 70 ++-------------------------------------- riocli/utils/__init__.py | 6 ++++ 3 files changed, 13 insertions(+), 68 deletions(-) diff --git a/riocli/apply/__init__.py b/riocli/apply/__init__.py index 2ef2c6eb..088f9087 100644 --- a/riocli/apply/__init__.py +++ b/riocli/apply/__init__.py @@ -22,6 +22,7 @@ from riocli.apply.template import template from riocli.apply.util import process_files_values_secrets from riocli.constants import Colors +from riocli.utils import print_centered_text @click.command( @@ -74,7 +75,7 @@ def apply( click.secho('No files specified', fg=Colors.RED) raise SystemExit(1) - click.secho("----- Files Processed ----", fg=Colors.YELLOW) + print_centered_text('Files Processed') for file in glob_files: click.secho(file, fg=Colors.YELLOW) @@ -93,6 +94,7 @@ def apply( if not silent and not dryrun: click.confirm("Do you want to proceed?", default=True, abort=True) + print_centered_text('Applying Manifests') rc.apply(dryrun=dryrun, workers=workers, retry_count=retry_count, retry_interval=retry_interval) @@ -137,4 +139,5 @@ def delete( if not silent and not dryrun: click.confirm("Do you want to proceed?", default=True, abort=True) + print_centered_text('Deleting Resources') rc.delete(dryrun=dryrun) diff --git a/riocli/apply/parse.py b/riocli/apply/parse.py index a46811ed..03742bb2 100644 --- a/riocli/apply/parse.py +++ b/riocli/apply/parse.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import copy import json import queue import threading @@ -21,12 +20,11 @@ import click import jinja2 import yaml -from tabulate import tabulate from riocli.apply.resolver import ResolverCache from riocli.config import Configuration from riocli.constants import Colors, Symbols -from riocli.utils import dump_all_yaml, print_separator, run_bash +from riocli.utils import dump_all_yaml, run_bash from riocli.utils.graph import Graphviz from riocli.utils.spinner import with_spinner @@ -34,19 +32,6 @@ class Applier(object): DEFAULT_MAX_WORKERS = 6 - EXPECTED_TIME = { - "organization": 3, - "project": 3, - "secret": 3, - "package": 3, - "staticroute": 3, - "disk": 180, - "deployment": 240, - "network": 120, - "device": 5, - "user": 3, - } - def __init__(self, files: typing.List, values, secrets): self.environment = None self.input_file_paths = files @@ -179,28 +164,6 @@ def parse_dependencies( self._add_graph_node(key) number_of_objects = number_of_objects + 1 - resource_list = [] - total_time = 0 - - for node in copy.deepcopy(self.graph).static_order(): - action = 'UPDATE' - if not self.resolved_objects[node]['src'] == 'remote': - action = 'CREATE' - elif delete: - action = 'DELETE' - kind = node.split(":")[0] - expected_time = round( - self.EXPECTED_TIME.get(kind.lower(), 5) / 60, 2) - total_time += expected_time - resource_list.append([node, action, expected_time]) - - if not template: - self._display_context( - total_time=total_time, - total_objects=number_of_objects, - resource_list=resource_list - ) - if check_missing: missing_resources = [] for key, item in self.resolved_objects.items(): @@ -299,7 +262,7 @@ def _load_file_content(self, file_name, is_value=False, is_secret=False): loaded = yaml.safe_load_all(data) loaded_data = list(loaded) except yaml.YAMLError as e: - raise Exception(f'Failed to parse {file_name}: {str(ex)}') + raise Exception(f'Failed to parse {file_name}: {str(e)}') if not loaded_data: click.secho('{} file is empty'.format(file_name)) @@ -357,8 +320,7 @@ def _resolve_dependency(self, dependent_key, dependency): dependent_key, obj_guid, dependency, obj) if (name_or_guid == obj_name) and ( - 'version' in dependency and obj[ - 'packageVersion'] == dependency.get('version')): + 'version' in dependency and obj['packageVersion'] == dependency.get('version')): self._add_remote_object_to_resolve_tree( dependent_key, obj_guid, dependency, obj) @@ -409,32 +371,6 @@ def show_dependency_graph(self): self.diagram.visualize() # Utils - def _display_context( - self, - total_time: int, - total_objects: int, - resource_list: typing.List - ) -> None: - headers = [ - click.style('Resource Context', bold=True, fg=Colors.YELLOW)] - context = [ - ['Expected Time (mins)', round(total_time, 2)], - ['Files', len(self.files)], - ['Resources', total_objects], - ] - click.echo(tabulate(context, headers=headers, - tablefmt='simple', numalign='center')) - - # Display Resource Inventory - headers = [] - for header in ['Resource', 'Action', 'Expected Time (mins)']: - headers.append(click.style(header, fg=Colors.YELLOW, bold=True)) - - print_separator() - click.echo(tabulate(resource_list, headers=headers, - tablefmt='simple', numalign='center')) - print_separator() - @staticmethod def _get_attr(obj, accept_keys): metadata = None diff --git a/riocli/utils/__init__.py b/riocli/utils/__init__.py index 9158729b..bda73ed6 100644 --- a/riocli/utils/__init__.py +++ b/riocli/utils/__init__.py @@ -296,3 +296,9 @@ def sanitize_label(name): r = r + c return r + + +def print_centered_text(text: str, color: str = Colors.YELLOW): + col, _ = get_terminal_size() + text = click.style(f' {text} '.center(col, '-'), fg=color, bold=True) + click.echo(text)