Skip to content

Commit

Permalink
Merge pull request #152 from jyejare/master
Browse files Browse the repository at this point in the history
Merging the Develop branch into Master
  • Loading branch information
jyejare authored Dec 5, 2024
2 parents 2dd30c3 + f2df30e commit b11236a
Show file tree
Hide file tree
Showing 32 changed files with 1,174 additions and 440 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: "CodeQL"

on:
push:
branches: [ "master" ]
branches: ["master", "develop"]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
branches: [ "master", "develop"]
schedule:
- cron: '35 01 * * 4'

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
rev: 7.1.0
hooks:
- id: flake8
- repo: https://github.com/gitleaks/gitleaks
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include cloudwash/assets/css/*.css
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ cloudwash supports following cloud providers:
* RedHat Openstack (_Support yet To be added_)
* OCP Clusters deplyed on Public clouds (_Support yet To be added_)

**And the Containerization tools:**

* Podman

NOTE: You can use `--all` flag with all the cloud providers to clean all supported resources.

The list of resource types it helps to clean could be found under settings.yaml.template](https://github.com/RedHatQE/cloudwash/blob/master/settings.yaml.template) file for individual cloud providers along with cleanup criteria.
Expand Down Expand Up @@ -109,6 +113,7 @@ azure Cleanup Azure provider
aws Cleanup Amazon provider
gce Cleanup GCE provider
openstack Cleanup OSP provider
podman Cleanup Podman provider
rhev Cleanup RHEV provider
vmware Cleanup VMWare provider
```
Expand Down
Empty file added cloudwash/assets/__init__.py
Empty file.
Empty file.
53 changes: 53 additions & 0 deletions cloudwash/assets/css/reporting.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
body {
font-family: sans-serif;
}
h1, h3 {
margin-left: 15px;
}
table, th, td {
border-collapse: collapse;
margin-left: 0;
}
#cloud_table {
border-collapse: collapse;
margin: 25px 0;
font: 0.9em sans-serif;
min-width: 800px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
border-radius: 5px 5px 0 0;
overflow: hidden;
table-layout: fixed; /* Ensure the first column has a fixed width */
width: 100%; /* Set the table width */
}
/* Styling the first column */
#cloud_table tbody td:first-child {
background-color: #009879;
color: #ffffff;
text-align: center;
font-weight: bold;
width: 250px; /* Set a fixed width for the first column */
white-space: nowrap; /* Prevent text wrapping in the first column */
}
#cloud_table th, #cloud_table td {
padding: 12px 15px;
}
#cloud_table th:not(:last-child), #cloud_table td:not(:last-child) {
border-right: 0.1px solid black;
}
#cloud_table tbody tr {
border-bottom: 1px solid #dddddd;
color: #488b8b;
font-weight: bold;
}
#cloud_table tbody tr:nth-of-type(odd) {
background-color: #f3f3f3;
}
#cloud_table tbody tr:last-of-type {
border-bottom: 2px solid #009879;
}
#cloud_table tbody td {
text-align: left;
}
#cloud_table td {
font-size: 0.8em;
}
27 changes: 24 additions & 3 deletions cloudwash/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from cloudwash.providers.aws import cleanup as awsCleanup
from cloudwash.providers.azure import cleanup as azureCleanup
from cloudwash.providers.gce import cleanup as gceCleanup
from cloudwash.providers.podman import cleanup as podmanCleanup
from cloudwash.providers.vmware import cleanup as vmwareCleanup

# Adding the pythonpath for importing modules from cloudwash packages
Expand Down Expand Up @@ -51,8 +52,9 @@ def cleanup_providers(ctx, dry, version):
click.echo(f"Version: {cloudwash_version}")
click.echo(f"Settings File: {settings.settings_file}")
if ctx.invoked_subcommand:
settings.set('dry_run', dry)
logger.info(
f"\n<<<<<<< Running the cleanup script in {'DRY' if dry else 'ACTION'} RUN mode >>>>>>>"
f"\n<<<<<<< Running the cleanup script in {'DRY' if dry else 'ACTION'} mode >>>>>>>"
)


Expand Down Expand Up @@ -121,13 +123,32 @@ def aws(ctx, vms, discs, nics, images, pips, stacks, ocps, _all):
)


@cleanup_providers.command(help="Cleanup Podman provider")
@click.option("--containers", is_flag=True, help="Remove containers from the podman host")
@click.pass_context
def podman(ctx, containers):
# Validate Podman Settings
validate_provider(ctx.command.name)
is_dry_run = ctx.parent.params["dry"]
podmanCleanup(
containers=containers,
dry_run=is_dry_run,
)


@cleanup_providers.command(help="Cleanup VMWare provider")
@common_options
@click.pass_context
def vmware(ctx, vms, discs, nics, _all):
validate_provider(ctx.command.name)
is_dry_run = ctx.parent.params["dry"]
vmwareCleanup(vms=vms, discs=discs, nics=nics, _all=_all, dry_run=is_dry_run)
is_dry_run = ctx.parant.params['dry']
vmwareCleanup(
vms=vms,
discs=discs,
nics=nics,
_all=_all,
dry_run=is_dry_run,
)


@cleanup_providers.command(help="Cleanup RHEV provider")
Expand Down
7 changes: 6 additions & 1 deletion cloudwash/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def compute_client(compute_resource, **kwargs):
password=settings.aws.auth.secret_key,
region=kwargs['aws_region'],
)
elif compute_resource == "podman":
client = wrapanapi.Podman(
hostname=settings.podman.auth.hostname,
username=settings.podman.auth.username,
port=settings.podman.auth.ssh_port,
)
elif compute_resource == "vmware":
client = wrapanapi.VMWareSystem(
hostname=settings.vmware.auth.vcenter,
Expand All @@ -44,7 +50,6 @@ def compute_client(compute_resource, **kwargs):
raise ValueError(
f"{compute_resource} is an incorrect value. It should be one of azure or gce or ec2"
)

try:
yield client
finally:
Expand Down
5 changes: 5 additions & 0 deletions cloudwash/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
aws_data = ['VMS', 'NICS', 'DISCS', 'PIPS', 'RESOURCES', 'STACKS', 'OCPS']
azure_data = ['VMS', 'NICS', 'DISCS', 'IMAGES', 'PIPS', 'RESOURCES']
gce_data = ['VMS', 'NICS', 'DISCS']
vmware_data = ['VMS', 'NICS', 'DISCS']
container_data = ['CONTAINERS']
Empty file added cloudwash/entities/__init__.py
Empty file.
112 changes: 112 additions & 0 deletions cloudwash/entities/providers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from cloudwash.entities.resources.containers import CleanPodmanContainers
from cloudwash.entities.resources.discs import CleanAWSDiscs
from cloudwash.entities.resources.discs import CleanAzureDiscs
from cloudwash.entities.resources.images import CleanAWSImages
from cloudwash.entities.resources.images import CleanAzureImages
from cloudwash.entities.resources.nics import CleanAWSNics
from cloudwash.entities.resources.nics import CleanAzureNics
from cloudwash.entities.resources.ocps import CleanAWSOcps
from cloudwash.entities.resources.pips import CleanAWSPips
from cloudwash.entities.resources.pips import CleanAzurePips
from cloudwash.entities.resources.stacks import CleanAWSStacks
from cloudwash.entities.resources.vms import CleanAWSVms
from cloudwash.entities.resources.vms import CleanAzureVMs
from cloudwash.entities.resources.vms import CleanGCEVMs
from cloudwash.entities.resources.vms import CleanVMWareVMs


class providerCleanup:
def __init__(self, client):
self.client = client

@property
def ocps(self):
providerclass = self.__class__.__name__
if 'AWS' in providerclass:
return CleanAWSOcps(client=self.client)
else:
raise NotImplementedError(f'The OCPs cleanup on {providerclass} is not implemented')

@property
def vms(self):
providerclass = self.__class__.__name__
if 'Azure' in providerclass:
return CleanAzureVMs(client=self.client)
elif 'AWS' in providerclass:
return CleanAWSVms(client=self.client)
elif 'GCE' in providerclass:
return CleanGCEVMs(client=self.client)
elif 'VMWare' in providerclass:
return CleanVMWareVMs(client=self.client)

@property
def discs(self):
providerclass = self.__class__.__name__
if 'Azure' in providerclass:
return CleanAzureDiscs(client=self.client)
elif 'AWS' in providerclass:
return CleanAWSDiscs(client=self.client)

@property
def nics(self):
providerclass = self.__class__.__name__
if 'Azure' in providerclass:
return CleanAzureNics(client=self.client)
elif 'AWS' in providerclass:
return CleanAWSNics(client=self.client)

@property
def pips(self):
providerclass = self.__class__.__name__
if 'Azure' in providerclass:
return CleanAzurePips(client=self.client)
elif 'AWS' in providerclass:
return CleanAWSPips(client=self.client)

@property
def images(self):
providerclass = self.__class__.__name__
if 'Azure' in providerclass:
return CleanAzureImages(client=self.client)
elif 'AWS' in providerclass:
return CleanAWSImages(client=self.client)

@property
def stacks(self):
providerclass = self.__class__.__name__
if 'AWS' in providerclass:
return CleanAWSStacks(client=self.client)


class AzureCleanup(providerCleanup):
def __init__(self, client):
self.client = client
super().__init__(client)


class AWSCleanup(providerCleanup):
def __init__(self, client):
self.client = client
super().__init__(client)


class GCECleanup(providerCleanup):
def __init__(self, client):
self.client = client
super().__init__(client)


class VMWareCleanup(providerCleanup):
def __init__(self, client):
self.client = client
super().__init__(self.client)


class PodmanCleanup(providerCleanup):
def __init__(self, client):
self.client = client
super().__init__(client)

@property
def containers(self):
return CleanPodmanContainers(client=self.client)
Empty file.
Loading

0 comments on commit b11236a

Please sign in to comment.