Conversation
| # "snapshot": "snap-0c1ca4850fcd5e573" | ||
| # }]} | ||
| amis = data['amis'] | ||
| for ami in amis: |
There was a problem hiding this comment.
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.
| if tagExists: | ||
| print(f"{resourceId} already tagged with FedoraUser=coreos tag") | ||
| else: | ||
| addTag(resourceId, region) | ||
| print(f"FedoraUser=coreos tag successfully added to {resourceId}") |
There was a problem hiding this comment.
I still think it would be nice to add a --dry-run option to this script and do something like:
| if tagExists: | |
| print(f"{resourceId} already tagged with FedoraUser=coreos tag") | |
| else: | |
| addTag(resourceId, region) | |
| print(f"FedoraUser=coreos tag successfully added to {resourceId}") | |
| if tagExists: | |
| print(f"{resourceId} already tagged with FedoraUser=coreos tag") | |
| return | |
| if dryrun: | |
| print(f"--dry-run specified. Would add FedoraUser=coreos tag to {resourceId}") | |
| else: | |
| addTag(resourceId, region) | |
| print(f"FedoraUser=coreos tag successfully added to {resourceId}") |
| print(f"FedoraUser=coreos tag successfully added to {resourceId}") | ||
|
|
||
| def checkTag(resourceId): | ||
| checkTagCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} Name=value,Values=coreos' |
There was a problem hiding this comment.
what does the Name=value,Values=coreos do here?
Also do we need to add --region to this command too?
There was a problem hiding this comment.
We don't need --region when we are giving --resource-id as an arg.
And for Name=value,Values=coreos, that's the way to filter out data where Name is basically "key" and Values is well "value" from tags json data that's spit out from aws ec2 describe tags
An example of what I get from this ami is this:
{
"Tags": [
{
"Key": "FedoraUser",
"ResourceId": "ami-xyx12345",
"ResourceType": "image",
"Value": "coreos"
}
]
}
| amis = data['amis'] | ||
| else: | ||
| print(f"{build_id} does not have any AMIs for {arch} in meta.json") | ||
| return |
There was a problem hiding this comment.
we probably shouldn't return here but rather continue the loop because we want to continue to process later builds and other architectures
| print(f"FedoraGroup=coreos tag successfully added to {resourceId}") | ||
| def checkTag(resourceId, region): | ||
| checkTagCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} Name=value,Values=coreos Name=key,Values=FedoraGroup --region {region} --output=json' |
There was a problem hiding this comment.
Let's try with: Name=tag:FedoraGroup,Values=coreos, which is a bit easier to follow.
efcfd1b to
2144e8f
Compare
| amis = data['amis'] | ||
| else: | ||
| print(f"{build_id} does not have any AMIs for {arch} in meta.json") | ||
| break |
There was a problem hiding this comment.
I think we need to continue and not break here? if we break then we won't check all architectures for a build ID
| break | |
| continue | |
| return | ||
|
|
||
| def checkAndAddTag(resourceId, region, dry_run): | ||
| checkTagCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} --region {region} --output=json' |
There was a problem hiding this comment.
optional: for clarity I would rename this:
| checkTagCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} --region {region} --output=json' | |
| describeTagsCmd = f'aws ec2 describe-tags --filters Name=resource-id,Values={resourceId} --region {region} --output=json' | |
| else: | ||
| if dry_run: | ||
| print(f"Would add tag 'FedoraGroup=coreos' to {resourceId} in region {region}") | ||
| return | ||
| else: | ||
| addTag(resourceId, region) | ||
| print(f"FedoraGroup=coreos tag successfully added to {resourceId}") | ||
| return |
There was a problem hiding this comment.
We should be able to move this logic into addTag() then this becomes easier to read:
else:
addTag(resourceId, region, dry_run)
| except subprocess.CalledProcessError as e: | ||
| return(e.output) |
There was a problem hiding this comment.
I think we should drop catching these exceptions
|
let's drop all try/catch blocks. We shouldn't be ignoring the exceptions I don't think. Is there any place where it makes sense for us to continue and ignore it? |
2144e8f to
26f4307
Compare
|
|
||
|
|
||
| def getBuildsForStream(stream): | ||
| buildFetch = 'cosa buildfetch --stream='+ stream + ' --arch=all' |
There was a problem hiding this comment.
maybe for consistency with other vars
| buildFetch = 'cosa buildfetch --stream='+ stream + ' --arch=all' | |
| buildFetchCmd = 'cosa buildfetch --stream='+ stream + ' --arch=all' | |
26f4307 to
c2ba0a9
Compare
c2ba0a9 to
179bfd6
Compare
| if dry_run: | ||
| print(f"Would add tag 'FedoraGroup=coreos' to {resourceId} in region {region}") | ||
| return | ||
| else: | ||
| addTag(resourceId, region, dry_run) |
There was a problem hiding this comment.
| if dry_run: | |
| print(f"Would add tag 'FedoraGroup=coreos' to {resourceId} in region {region}") | |
| return | |
| else: | |
| addTag(resourceId, region, dry_run) | |
| addTag(resourceId, region, dry_run) |
179bfd6 to
fd814ca
Compare
fd814ca to
4f37b1f
Compare
No description provided.