|
8 | 8 | def main(): |
9 | 9 | parser = argparse.ArgumentParser() |
10 | 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 | 11 | args = parser.parse_args() |
13 | 12 |
|
14 | | - builds = getBuildsForStream(args.stream, args.arch) |
| 13 | + builds = getBuildsForStream(args.stream) |
15 | 14 | 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 |
| 15 | + build_id=build['id'] |
| 16 | + arches=build['arches'] |
| 17 | + for arch in arches: |
| 18 | + print(f"The build is {build_id}") |
| 19 | + buildFetch(args.stream, build_id, arch) |
| 20 | + meta = open('builds/'+build_id+'/'+arch+'/meta.json') |
| 21 | + data = json.load(meta) |
| 22 | + |
| 23 | + # Delete this when actually running. Just here while I make this script |
| 24 | + data ={"amis":[{ |
| 25 | + "name": "us-east-1", |
| 26 | + "hvm": "ami-0016d5df3041499f9", |
| 27 | + "snapshot": "snap-0c1ca4850fcd5e573" |
| 28 | + }]} |
| 29 | + amis = data['amis'] |
| 30 | + for ami in amis: |
| 31 | + checkAndAddTag(ami["hvm"], ami["name"]) |
| 32 | + checkAndAddTag(ami["snapshot"], ami["name"]) |
| 33 | + return |
| 34 | + |
| 35 | +def checkAndAddTag(resourceId, region): |
| 36 | + tagExists = checkTag(resourceId) |
| 37 | + if tagExists: |
| 38 | + print(f"{resourceId} already tagged with FedoraUser=coreos tag") |
| 39 | + else: |
| 40 | + addTag(resourceId, region) |
| 41 | + print(f"FedoraUser=coreos tag successfully added to {resourceId}") |
| 42 | + |
| 43 | +def checkTag(resourceId): |
| 44 | + checkTagCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} Name=value,Values=coreos' |
| 45 | + try: |
| 46 | + tagCheck=subprocess.run([checkTagCmd], shell=True, capture_output=True, text=True) |
| 47 | + if "FedoraUser" and "coreos" in tagCheck.stdout: |
| 48 | + return True |
| 49 | + return False |
| 50 | + except subprocess.CalledProcessError as e: |
| 51 | + return(e.output) |
| 52 | + |
| 53 | +def addTag(resourceId, region): |
| 54 | + UpdateTagCmd = f'aws ec2 create-tags --resource {resourceId} --tags Key="FedoraUser",Value="coreos" --region {region}' |
| 55 | + try: |
| 56 | + subprocess.run([UpdateTagCmd], shell=True) |
| 57 | + except subprocess.CalledProcessError as e: |
| 58 | + return(e.output) |
| 59 | + |
| 60 | +def getBuildsForStream(stream): |
| 61 | + buildFetch = 'cosa buildfetch --stream='+ stream + ' --arch=all' |
38 | 62 | try: |
39 | 63 | subprocess.call(['/bin/bash', '-i', '-c', buildFetch]) |
40 | 64 | except subprocess.CalledProcessError as e: |
41 | 65 | return(e.output) |
42 | 66 |
|
43 | 67 | f = open('builds/builds.json') |
44 | 68 | data = json.load(f) |
45 | | - builds = [] |
46 | | - |
47 | | - for i in data['builds']: |
48 | | - builds.append(i['id']) |
49 | | - return builds |
| 69 | + return data['builds'] |
50 | 70 |
|
51 | 71 | def buildFetch(stream, build, arch): |
52 | | - buildFetchCmd = 'cosa buildfetch --stream='+ stream + '--build=' + build + '--arch=' + arch |
| 72 | + buildFetchCmd = 'cosa buildfetch --stream='+ stream + ' --build=' + build + ' --arch=' + arch |
53 | 73 | try: |
54 | 74 | subprocess.call(['/bin/bash', '-i', '-c', buildFetchCmd]) |
55 | 75 | except subprocess.CalledProcessError as e: |
|
0 commit comments