Skip to content

Commit 6644cdd

Browse files
committed
code review
1 parent af976fa commit 6644cdd

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/osbuild-manifests/aws_tag.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import os
2+
import subprocess
3+
import json
4+
import argparse
5+
6+
7+
8+
def main():
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument('--stream', dest='stream', type=str, help='Fedora stream', required=True)
11+
parser.add_argument('--arch', dest='arch', type=str, help='Architecture', default='x86_64')
12+
args = parser.parse_args()
13+
14+
builds = getBuildsForStream(args.stream, args.arch)
15+
for build in builds:
16+
print("The build is "+build)
17+
buildFetch(args.stream, build, args.arch)
18+
meta = open('builds/'+build+'/'+args.arch+'/meta.json')
19+
data = json.load(meta)
20+
21+
# Delete this when actually running. Just here while I make this script
22+
# data ={"amis":[{
23+
# "name": "us-east-1",
24+
# "hvm": "ami-0016d5df3041499f9",
25+
# "snapshot": "snap-0c1ca4850fcd5e573"
26+
# }]}
27+
amis = data['amis']
28+
for ami in amis:
29+
UpdateTagCmd = 'aws ec2 create-tags --resource ' + ami['hvm'] + ' --tags '+ 'Key="FedoraUser",Value="coreos"' + ' --region=' + ami['name']
30+
try:
31+
subprocess.call(['/bin/bash', '-i', '-c', UpdateTagCmd])
32+
except subprocess.CalledProcessError as e:
33+
return(e.output)
34+
return
35+
36+
def getBuildsForStream(stream, arch):
37+
buildFetch = 'cosa buildfetch --stream='+ stream + ' --arch='+ arch
38+
try:
39+
subprocess.call(['/bin/bash', '-i', '-c', buildFetch])
40+
except subprocess.CalledProcessError as e:
41+
return(e.output)
42+
43+
f = open('builds/builds.json')
44+
data = json.load(f)
45+
builds = []
46+
47+
for i in data['builds']:
48+
builds.append(i['id'])
49+
return builds
50+
51+
def buildFetch(stream, build, arch):
52+
buildFetchCmd = 'cosa buildfetch --stream='+ stream + '--build=' + build + '--arch=' + arch
53+
try:
54+
subprocess.call(['/bin/bash', '-i', '-c', buildFetchCmd])
55+
except subprocess.CalledProcessError as e:
56+
return(e.output)
57+
58+
if __name__ == '__main__':
59+
main()

0 commit comments

Comments
 (0)