Skip to content

Instantly share code, notes, and snippets.

View toabctl's full-sized avatar

Thomas Bechtold toabctl

  • Canonical
  • Berlin/Germany
View GitHub Profile
@toabctl
toabctl / aws-images-delete.py
Last active December 12, 2024 17:58
delete images and snapshots
#!/usr/bin/env python3
"""
Delete all snapshots
!!!!!!!!!!!!!!!! BE CAREFUL !!!!!!!!!!!!!!!!!!!!!!!!!
AWS_DEFAULT_REGION=sa-east-1 AWS_PROFILE=my-profile ./aws-snapshots-delete.py
Or to iterate over all regions:
@toabctl
toabctl / aws-snapshots-delete.py
Created December 12, 2024 17:57
Delete snapshots in region and account
#!/usr/bin/python3
"""
Delete all snapshots
!!!!!!!!!!!!!!!! BE CAREFUL !!!!!!!!!!!!!!!!!!!!!!!!!
AWS_DEFAULT_REGION=sa-east-1 AWS_PROFILE=my-profile ./aws-snapshots-delete.py
"""
@toabctl
toabctl / aws-marketplace.py
Created February 27, 2023 05:42
AWS Marketplace interactions
#!/usr/bin/env python
import click
import boto3
import json
import prettytable
client = boto3.client('marketplace-catalog', region_name='us-east-1')
#!/usr/bin/python3
import boto3
ec2res = boto3.resource('ec2')
ec2client = boto3.client('ec2')
region_name = ec2client.meta.region_name
snapshots = ec2res.snapshots.filter(OwnerIds=['self'])
@toabctl
toabctl / aws-snapshots-size.py
Last active December 1, 2022 10:56
Get the total amount of snapshots in GiB
#!/usr/bin/python3
"""
Get the total amount of GiB snapshots use and calculate the average snapshot size
Use eg. with:
AWS_DEFAULT_REGION=sa-east-1 AWS_PROFILE=my-profile ./aws-snapshots-size.py
"""
import boto3
@toabctl
toabctl / ssm-images.sh
Created November 22, 2022 10:57
Images from SSM for different regions
#!/bin/bash -eu
# this is 2P Ubuntu Pro Xenial
SSM_ID=prod-f6ogoaqs7lwre/ubuntu-pro-16.04-lts
# get a AMI via SSM from us-east-1
US_EAST_1_AMI=$(aws --region us-east-1 ssm get-parameters --names "/aws/service/marketplace/${SSM_ID}" --query 'Parameters[0].Value' --output text)
echo $US_EAST_1_AMI
# get the AMI name via describe-images
@toabctl
toabctl / aws-marketplace.py
Created February 22, 2022 12:18
AWS marketplace interactions
#!/usr/bin/python3
# Author: Thomas Bechtold <[email protected]>
import click
import boto3
import json
import prettytable
@toabctl
toabctl / jenkins-jobs-delete
Created September 22, 2021 07:46
Delete jenkins jobs with python-jenkins
#!/usr/bin/python3
import argparse
import configparser
import re
import jenkins
def _config(args):
$ cat aws-images.sh
#!/bin/bash
OUTFILE=out.txt
AWS_REGIONS=(ap-east-1 ap-northeast-1 ap-northeast-2 ap-northeast-3 ap-south-1 ap-southeast-1 ap-southeast-2 af-south-1 ca-central-1 cn-north-1 cn-northwest-1 eu-central-1 eu-north-1 eu-west-1 eu-west-2 eu-west-3 eu-south-1 sa-east-1 me-south-1 us-east-1 us-east-2 us-gov-west-1 us-gov-east-1 us-west-1 us-west-2)
for region in ${AWS_REGIONS[@]}; do
export AWS_DEFAULT_REGION=$region
echo "Getting images for region $region ..."
aws ec2 describe-images --owner 099720109477 --query 'Images[?Name!=`null`]|[? (starts_with(Name, `ubuntu/images/`) == `true`) || (starts_with(Name, `ubuntu-minimal/images/`) == `true`) || (starts_with(Name, `ubuntu-eks/`) == `true`)]|[? (contains(Name, `precise`) == `false`) && (contains(Name, `quantal`) == `false`) && (contains(Name, `raring`) == `false`) && (contains(Name, `saucy`) == `false`) && (contains(Name, `trusty`) == `false`) && (contains(Name, `utopic`) == `false`) && (contains(Name, `vivid`) == `false`) && (contain
@toabctl
toabctl / os-server-running.py
Created April 2, 2020 18:38
Running OpenStack servers
#!/usr/bin/python3
import argparse
import datetime
import sys
import openstack
def _parser():
parser = argparse.ArgumentParser(