Skip to content

Commit

Permalink
#123 Extend debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Seichter committed Nov 10, 2024
1 parent 44c421f commit 2ad9dd6
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/aws_cloudfront.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

# get all cloudfront distributions and return a list of distributions
def get_cloudfront_distributions():
logger.debug('START - get_cloudfront_distributions()')
session = aws_session_handler.get_session()
cloudfront = session.client('cloudfront')
distributions = cloudfront.list_distributions()
Expand All @@ -36,6 +37,8 @@ def get_cloudfront_distributions():

# get information about a cloudfront distribution
def get_cloudfront_distribution(distribution_id):
logger.debug('START - get_cloudfront_distribution(distribution_id)')
logger.debug('distribution_id: %s', distribution_id)
session = aws_session_handler.get_session()
cloudfront = session.client('cloudfront')
distribution = cloudfront.get_distribution(Id=distribution_id)
Expand All @@ -44,6 +47,9 @@ def get_cloudfront_distribution(distribution_id):

# invalidate a cloudfront distribution
def invalidate_cloudfront_distribution(distribution_id, paths):
logger.debug('START - invalidate_cloudfront_distribution(distribution_id, paths)')
logger.debug('distribution_id: %s', distribution_id)
logger.debug('paths: %s', paths)
session = aws_session_handler.get_session()
cloudfront = session.client('cloudfront')
response = cloudfront.create_invalidation(DistributionId=distribution_id, InvalidationBatch={'Paths': {'Quantity': len(paths), 'Items': paths}, 'CallerReference': 'awsmanager'})
Expand All @@ -52,6 +58,8 @@ def invalidate_cloudfront_distribution(distribution_id, paths):

# load tags of a cloudfront distribution
def get_cloudfront_distribution_tags(distribution_id):
logger.debug('START - get_cloudfront_distribution_tags(distribution_id)')
logger.debug('distribution_id: %s', distribution_id)
session = aws_session_handler.get_session()
cloudfront = session.client('cloudfront')
tags = cloudfront.list_tags_for_resource(Resource=distribution_id)
Expand Down
20 changes: 20 additions & 0 deletions src/aws_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

# get information about an ec2 instance
def get_ec2_instance(region, instance_id):
logger.debug('START - get_ec2_instance(region, instance_id)')
logger.debug('region: %s', region)
logger.debug('instance_id: %s', instance_id)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
instance = ec2.describe_instances(InstanceIds=[instance_id])
Expand All @@ -32,6 +35,9 @@ def get_ec2_instance(region, instance_id):

# get all information about a volumeid
def get_ec2_volume(region, volume_id):
logger.debug('START - get_ec2_volume(region, volume_id)')
logger.debug('region: %s', region)
logger.debug('volume_id: %s', volume_id)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
volume = ec2.describe_volumes(VolumeIds=[volume_id])
Expand All @@ -40,6 +46,8 @@ def get_ec2_volume(region, volume_id):

# get all ec2 instances of a region and return a list of instances
def get_ec2_instances(region):
logger.debug('START - get_ec2_instances(region)')
logger.debug('region: %s', region)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
instances = ec2.describe_instances()
Expand All @@ -52,27 +60,39 @@ def get_ec2_instances(region):

# start a given instance
def start_ec2_instance(region, instance_id):
logger.debug('START - start_ec2_instance(region, instance_id)')
logger.debug('region: %s', region)
logger.debug('instance_id: %s', instance_id)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
ec2.start_instances(InstanceIds=[instance_id])


# stop a given instance
def stop_ec2_instance(region, instance_id):
logger.debug('START - stop_ec2_instance(region, instance_id)')
logger.debug('region: %s', region)
logger.debug('instance_id: %s', instance_id)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=[instance_id])


# reboot a given instance
def reboot_ec2_instance(region, instance_id):
logger.debug('START - reboot_ec2_instance(region, instance_id)')
logger.debug('region: %s', region)
logger.debug('instance_id: %s', instance_id)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
ec2.reboot_instances(InstanceIds=[instance_id])


# terminate a given instance
def terminate_ec2_instance(region, instance_id):
logger.debug('START - terminate_ec2_instance(region, instance_id)')
logger.debug('region: %s', region)
logger.debug('instance_id: %s', instance_id)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
ec2.terminate_instances(InstanceIds=[instance_id])
18 changes: 18 additions & 0 deletions src/aws_ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

# get all ECS clusters of a region and return a list of ECS clusters
def get_ecs_clusters(region):
logger.debug('START - get_ecs_clusters(region)')
logger.debug('region: %s', region)
session = aws_session_handler.get_session()
ecs = session.client("ecs", region_name=region)
clusters = ecs.list_clusters()
Expand All @@ -35,6 +37,9 @@ def get_ecs_clusters(region):

# get all ECS services of a cluster and return a list of ECS services
def get_ecs_services(region, cluster):
logger.debug('START - get_ecs_services(region, cluster)')
logger.debug('region: %s', region)
logger.debug('cluster: %s', cluster)
session = aws_session_handler.get_session()
ecs = session.client("ecs", region_name=region)
services = ecs.list_services(cluster=cluster)
Expand All @@ -46,6 +51,10 @@ def get_ecs_services(region, cluster):

# get all ECS tasks of a service and return a list of ECS tasks
def get_ecs_tasks(region, cluster, service):
logger.debug('START - get_ecs_tasks(region, cluster, service)')
logger.debug('region: %s', region)
logger.debug('cluster: %s', cluster)
logger.debug('service: %s', service)
session = aws_session_handler.get_session()
ecs = session.client("ecs", region_name=region)
tasks = ecs.list_tasks(cluster=cluster, serviceName=service)
Expand All @@ -57,6 +66,10 @@ def get_ecs_tasks(region, cluster, service):

# load the details of the service
def get_ecs_service_details(region, cluster, service):
logger.debug('START - get_ecs_service_details(region, cluster, service)')
logger.debug('region: %s', region)
logger.debug('cluster: %s', cluster)
logger.debug('service: %s', service)
session = aws_session_handler.get_session()
ecs = session.client("ecs", region_name=region)
service_details = ecs.describe_services(cluster=cluster, services=[service])
Expand All @@ -65,6 +78,11 @@ def get_ecs_service_details(region, cluster, service):

# set the desired count of a service
def set_ecs_desired_count(region, cluster, service, count):
logger.debug('START - set_ecs_desired_count(region, cluster, service, count)')
logger.debug('region: %s', region)
logger.debug('cluster: %s', cluster)
logger.debug('service: %s', service)
logger.debug('count: %s', count)
session = aws_session_handler.get_session()
ecs = session.client("ecs", region_name=region)
response = ecs.update_service(cluster=cluster, service=service, desiredCount=count)
Expand Down
9 changes: 9 additions & 0 deletions src/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

# get all lambda functions of a region and return a list of functions
def get_lambda_functions(region):
logger.debug('START - get_lambda_functions(region)')
logger.debug('region: %s', region)
session = aws_session_handler.get_session()
lambda_client = session.client('lambda', region_name=region)
functions = lambda_client.list_functions()
Expand All @@ -36,6 +38,9 @@ def get_lambda_functions(region):

# get information about a lambda function
def get_lambda_function(region, function_name):
logger.debug('START - get_lambda_function(region, function_name)')
logger.debug('region: %s', region)
logger.debug('function_name: %s', function_name)
session = aws_session_handler.get_session()
lambda_client = session.client('lambda', region_name=region)
lambdafunction = lambda_client.get_function(FunctionName=function_name)
Expand All @@ -44,6 +49,10 @@ def get_lambda_function(region, function_name):

# invoke a lambda function
def invoke_lambda_function(region, function_name, payload):
logger.debug('START - invoke_lambda_function(region, function_name, payload)')
logger.debug('region: %s', region)
logger.debug('function_name: %s', function_name)
logger.debug('payload: %s', payload)
session = aws_session_handler.get_session()
lambda_client = session.client('lambda', region_name=region)
response = lambda_client.invoke(FunctionName=function_name, Payload=payload)
Expand Down
17 changes: 17 additions & 0 deletions src/aws_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

# get all rds databases of a region and return a list of rds databases
def get_rds_databases(region):
logger.debug('START - get_rds_databases(region)')
logger.debug('region: %s', region)
session = aws_session_handler.get_session()
rds = session.client("rds", region_name=region)
databases = rds.describe_db_instances()
Expand All @@ -34,34 +36,49 @@ def get_rds_databases(region):


def get_rds_database(region, db_instance_identifier):
logger.debug('START - get_rds_database(region, db_instance_identifier)')
logger.debug('region: %s', region)
logger.debug('db_instance_identifier: %s', db_instance_identifier)
session = aws_session_handler.get_session()
rds = session.client("rds", region_name=region)
database = rds.describe_db_instances(DBInstanceIdentifier=db_instance_identifier)
return database["DBInstances"][0]


def start_rds_database(region, db_instance_identifier):
logger.debug('START - start_rds_database(region, db_instance_identifier)')
logger.debug('region: %s', region)
logger.debug('db_instance_identifier: %s', db_instance_identifier)
session = aws_session_handler.get_session()
rds = session.client("rds", region_name=region)
response = rds.start_db_instance(DBInstanceIdentifier=db_instance_identifier)
return response


def stop_rds_database(region, db_instance_identifier):
logger.debug('START - stop_rds_database(region, db_instance_identifier)')
logger.debug('region: %s', region)
logger.debug('db_instance_identifier: %s', db_instance_identifier)
session = aws_session_handler.get_session()
rds = session.client("rds", region_name=region)
response = rds.stop_db_instance(DBInstanceIdentifier=db_instance_identifier)
return response


def reboot_rds_database(region, db_instance_identifier):
logger.debug('START - reboot_rds_database(region, db_instance_identifier)')
logger.debug('region: %s', region)
logger.debug('db_instance_identifier: %s', db_instance_identifier)
session = aws_session_handler.get_session()
rds = session.client("rds", region_name=region)
response = rds.reboot_db_instance(DBInstanceIdentifier=db_instance_identifier)
return response


def delete_rds_database(region, db_instance_identifier):
logger.debug('START - delete_rds_database(region, db_instance_identifier)')
logger.debug('region: %s', region)
logger.debug('db_instance_identifier: %s', db_instance_identifier)
session = aws_session_handler.get_session()
rds = session.client("rds", region_name=region)
response = rds.delete_db_instance(DBInstanceIdentifier=db_instance_identifier)
Expand Down
19 changes: 19 additions & 0 deletions src/aws_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

# get all s3 buckets of a region and return a list of buckets
def get_s3_buckets(region):
logger.debug('START - get_s3_buckets(region)')
logger.debug('region: %s', region)
session = aws_session_handler.get_session()
s3 = session.client('s3', region_name=region)
buckets = s3.list_buckets()
Expand All @@ -35,6 +37,9 @@ def get_s3_buckets(region):

# get all objects of a bucket
def get_s3_bucket_objects(region, bucket_name):
logger.debug('START - get_s3_bucket_objects(region, bucket_name)')
logger.debug('region: %s', region)
logger.debug('bucket_name: %s', bucket_name)
s3 = boto3.client('s3', region_name=region)
objects = s3.list_objects_v2(Bucket=bucket_name)
objects_list = []
Expand All @@ -45,20 +50,34 @@ def get_s3_bucket_objects(region, bucket_name):

# download an object from a bucket into given file
def download_object(region, bucket_name, object_name, file_name):
logger.debug('START - download_object(region, bucket_name, object_name, file_name)')
logger.debug('region: %s', region)
logger.debug('bucket_name: %s', bucket_name)
logger.debug('object_name: %s', object_name)
logger.debug('file_name: %s', file_name)
session = aws_session_handler.get_session()
s3 = session.client('s3', region_name=region)
s3.download_file(bucket_name, object_name, file_name)


# upload a file to a bucket
def upload_file(region, bucket_name, file_name, object_name):
logger.debug('START - upload_file(region, bucket_name, file_name, object_name)')
logger.debug('region: %s', region)
logger.debug('bucket_name: %s', bucket_name)
logger.debug('file_name: %s', file_name)
logger.debug('object_name: %s', object_name)
session = aws_session_handler.get_session()
s3 = session.client('s3', region_name=region)
s3.upload_file(file_name, bucket_name, object_name)


# delete an object from a bucket
def delete_object(region, bucket_name, object_name):
logger.debug('START - delete_object(region, bucket_name, object_name)')
logger.debug('region: %s', region)
logger.debug('bucket_name: %s', bucket_name)
logger.debug('object_name: %s', object_name)
session = aws_session_handler.get_session()
s3 = session.client('s3', region_name=region)
s3.delete_object(Bucket=bucket_name, Key=object_name)
4 changes: 4 additions & 0 deletions src/configuration_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# import workdir specific libraries
import settings
import icons
import webbrowser

import logging_config # Setup the logging # noqa: F401
import logging
Expand Down Expand Up @@ -91,3 +92,6 @@ def reloadAwsProfiles(self, event):
# set the values
self.comboBoxAwsProfile.Clear()
self.comboBoxAwsProfile.Append(profiles)

def openLogfile(self, event):
webbrowser.open_new_tab(self.textCtrlConfigLogfile.GetValue())

0 comments on commit 2ad9dd6

Please sign in to comment.