forked from coreos/coreos-assembler
-
Notifications
You must be signed in to change notification settings - Fork 0
code review #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dustymabe
wants to merge
4
commits into
master
Choose a base branch
from
dusty-gursewak
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
code review #2
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
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('--dry-run', dest='dry_run', help='Check if the resources have tags but not add them', action='store_true') | ||
args = parser.parse_args() | ||
|
||
builds = getBuildsForStream(args.stream) | ||
for build in builds: | ||
build_id=build['id'] | ||
arches=build['arches'] | ||
for arch in arches: | ||
print(f"Parsing AMIs for {build_id} for {arch}") | ||
buildFetch(args.stream, build_id, arch) | ||
meta = open(f'builds/{build_id}/{arch}/meta.json') | ||
data = json.load(meta) | ||
|
||
if 'amis' in data.keys(): | ||
amis = data['amis'] | ||
else: | ||
print(f"{build_id} does not have any AMIs for {arch} in meta.json") | ||
continue | ||
# 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: | ||
region = ami["name"] | ||
checkAndAddTag(ami["hvm"], region, args.dry_run) | ||
checkAndAddTag(ami["snapshot"], region, args.dry_run) | ||
return | ||
|
||
def checkAndAddTag(resourceId, region, dry_run): | ||
describeTagsCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} --region {region} --output=json' | ||
tagCheck=subprocess.run([describeTagsCmd], shell=True, capture_output=True, text=True) | ||
if tagCheck.stdout == None or tagCheck.stdout == '': | ||
print(f"No tags detected for {resourceId}; assuming it doesn't exist") | ||
return | ||
tagCheck=json.loads(tagCheck.stdout) | ||
|
||
if any((tag['Key'] == 'FedoraGroup' and tag['Value'] == 'coreos') for tag in tagCheck['Tags']): | ||
print(f"{resourceId} already tagged with FedoraGroup=coreos tag") | ||
return | ||
else: | ||
if dry_run: | ||
print(f"Would add tag 'FedoraGroup=coreos' to {resourceId} in region {region}") | ||
return | ||
else: | ||
addTag(resourceId, region, dry_run) | ||
|
||
def addTag(resourceId, region, dry_run): | ||
if dry_run: | ||
print(f"Would add tag 'FedoraGroup=coreos' to {resourceId} in region {region}") | ||
else: | ||
UpdateTagCmd = f'aws ec2 create-tags --resource {resourceId} --tags Key="FedoraGroup",Value="coreos" --region {region}' | ||
subprocess.run([UpdateTagCmd], shell=True) | ||
print(f"'FedoraGroup=coreos' tag successfully added to {resourceId}") | ||
|
||
def getBuildsForStream(stream): | ||
buildFetchCmd = 'cosa buildfetch --stream='+ stream + ' --arch=all' | ||
subprocess.check_output(['/bin/bash', '-i', '-c', buildFetchCmd]) | ||
|
||
f = open(f'builds/builds.json') | ||
data = json.load(f) | ||
return data['builds'] | ||
|
||
def buildFetch(stream, build, arch): | ||
buildFetchCmd = 'cosa buildfetch --stream='+ stream + ' --build=' + build + ' --arch=' + arch | ||
subprocess.check_output(['/bin/bash', '-i', '-c', buildFetchCmd]) | ||
|
||
if __name__ == '__main__': | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.