Skip to content

Commit

Permalink
Fix issues with semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
msajidmansoori12 committed Sep 19, 2024
1 parent e134bc6 commit ae90531
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion assets/css/reporting.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ body{
}
#cloud_table td {
font-size: 0.8em;
}
}
1 change: 1 addition & 0 deletions cloudwash/providers/aws.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""ec2 CR Cleanup Utilities"""

from cloudwash.client import compute_client
from cloudwash.config import settings
from cloudwash.constants import aws_data as data
Expand Down
1 change: 1 addition & 0 deletions cloudwash/providers/azure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Azure CR Cleanup Utilities"""

from cloudwash.client import compute_client
from cloudwash.config import settings
from cloudwash.constants import azure_data as data
Expand Down
1 change: 1 addition & 0 deletions cloudwash/providers/gce.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""GCE CR Cleanup Utilities"""

from cloudwash.client import compute_client
from cloudwash.config import settings
from cloudwash.logger import logger
Expand Down
57 changes: 36 additions & 21 deletions cloudwash/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
"""Common utils for cleanup activities of all CRs"""

from collections import namedtuple
from datetime import datetime

import dominate
import pytz
from dominate.tags import div
from dominate.tags import h1
from dominate.tags import h3
from dominate.tags import li
from dominate.tags import style
from dominate.tags import table
from dominate.tags import tbody
from dominate.tags import td
from dominate.tags import th
from dominate.tags import thead
from dominate.tags import tr
from dominate.tags import ul

from cloudwash.logger import logger

import dominate
from dominate.tags import *


_vms_dict = {"VMS": {"delete": [], "stop": [], "skip": []}}
dry_data = {
Expand All @@ -18,7 +29,7 @@
"RESOURCES": {"delete": []},
"STACKS": {"delete": []},
"IMAGES": {"delete": []},
"PROVIDER": ""
"PROVIDER": "",
}
dry_data.update(_vms_dict)

Expand All @@ -41,26 +52,29 @@ def echo_dry(dry_data=None) -> None:
"deletable_images": dry_data["IMAGES"]["delete"],
"deletable_pips": dry_data["PIPS"]["delete"] if "PIPS" in dry_data else None,
"deletable_resources": dry_data["RESOURCES"]["delete"],
"deletable_stacks": dry_data["STACKS"]["delete"] if "STACKS" in dry_data else None
"deletable_stacks": dry_data["STACKS"]["delete"] if "STACKS" in dry_data else None,
}
if any(value for key, value in resource_data.items() if key != 'provider'):
logger.info("Resources eligible for cleanup:")
for key, value in resource_data.items():
if value and key!="provider":
logger.info(f"{key.replace('_', ' ').title()}:\n\t{key.split('_')[0].title()}: {value}")
if value and key != "provider":
logger.info(
f"{key.replace('_', ' ').title()}:\n\t{key.split('_')[0].title()}: {value}"
)

logger.info("\n====================================\n")

create_html(**resource_data)
else:
logger.info("\nNo resources are eligible for cleanup!\n")


def create_html(**kwargs):
''' Creates a html based report file with deletable resources.'''
'''Creates a html based report file with deletable resources.'''
doc = dominate.document(title="Cloud resources page")

with doc.head:
with open('assets/css/reporting.css','r') as css:
with open('assets/css/reporting.css', 'r') as css:
style(css.read())

with doc:
Expand All @@ -71,19 +85,20 @@ def create_html(**kwargs):
with thead():
with tr():
for table_head in kwargs.keys():
if kwargs[table_head] and table_head!="provider":
th(table_head.replace("_"," ").title())
if kwargs[table_head] and table_head != "provider":
th(table_head.replace("_", " ").title())
with tbody():
for key,values in kwargs.items():
if key!="provider" and values:
if isinstance(values,list):
with td():
with ul():
[li(resource_name) for resource_name in values]
else:
td(values)
with open('cleanup_resource.html','w') as file:
file.write(doc.render())
for key, values in kwargs.items():
if key != "provider" and values:
if isinstance(values, list):
with td():
with ul():
[li(resource_name) for resource_name in values]
else:
td(values)
with open('cleanup_resource.html', 'w') as file:
file.write(doc.render())


def total_running_time(vm_obj) -> namedtuple:
"""Calculates the VMs total running time
Expand Down

0 comments on commit ae90531

Please sign in to comment.