Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/osbuild-manifests/aws_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import subprocess
import json
import argparse



def main():
parser = argparse.ArgumentParser()
parser.add_argument('--stream', dest='stream', type=str, help='Fedora stream', required=True)
parser.add_argument('--arch', dest='arch', type=str, help='Architecture', default='x86_64')
args = parser.parse_args()

builds = getBuildsForStream(args.stream, args.arch)
for build in builds:
print("The build is "+build)
buildFetch(args.stream, build, args.arch)
meta = open('builds/'+build+'/'+args.arch+'/meta.json')
data = json.load(meta)

# Delete this when actually running. Just here while I make this script
# data ={"amis":[{
# "name": "us-east-1",
# "hvm": "ami-0016d5df3041499f9",
# "snapshot": "snap-0c1ca4850fcd5e573"
# }]}
amis = data['amis']
for ami in amis:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before we update the tag it would be nice to check to see if the tag exists on the AMI first.

this will combine nicely with a dry-run feature.. in the case the user passed in --dry-run then if the tags didn't exist on the AMI we could print a statement saying would add tags "FedoraGroup=coreos" to ami-XXX in region foobar.

UpdateTagCmd = 'aws ec2 create-tags --resource ' + ami['hvm'] + ' --tags '+ 'Key="FedoraUser",Value="coreos"' + ' --region=' + ami['name']
try:
subprocess.call(['/bin/bash', '-i', '-c', UpdateTagCmd])
except subprocess.CalledProcessError as e:
return(e.output)
return

def getBuildsForStream(stream, arch):
buildFetch = 'cosa buildfetch --stream='+ stream + ' --arch='+ arch
try:
subprocess.call(['/bin/bash', '-i', '-c', buildFetch])
except subprocess.CalledProcessError as e:
return(e.output)

f = open('builds/builds.json')
data = json.load(f)
builds = []

for i in data['builds']:
builds.append(i['id'])
return builds

def buildFetch(stream, build, arch):
buildFetchCmd = 'cosa buildfetch --stream='+ stream + '--build=' + build + '--arch=' + arch
try:
subprocess.call(['/bin/bash', '-i', '-c', buildFetchCmd])
except subprocess.CalledProcessError as e:
return(e.output)

if __name__ == '__main__':
main()