过去,您过去可以在 Web 控制台上查看 AWS 存储网关中的磁带标签,但现在看来 AWS 已删除该选项。查看标签的唯一方法是单独选择每个磁带并单击标签选项卡。
我有超过 100 个磁带,手动执行此操作会相当耗时。有没有一个命令可以输出每个磁带条码及其相关标签的列表?
或者,我们在所有这些磁带上只使用大约 10 个标签(每个磁带一个标签),我尝试使用 Python/boto3 脚本(虽然我不是 python 大师)输出特定标签的所有磁带,可悲的是,下面的脚本不能完全工作。它会输出一些磁带,但不是全部。例如,如果我搜索标签“仓库”,它将返回大约 8 个磁带 - 这听起来不正确。因此,在 AWS 控制台中手动查看我已经手动找到了 3-4 个带有此标签的磁带,并且没有使用此代码在列表中返回:
#Import the boto3 library
import boto3
#Create the tape gateway client
tgw_client = boto3.client('storagegateway')
#Create a list of the tapes
tapes = tgw_client.list_tapes()['TapeInfos']
#Create a for loop to process each tape in the tapes list
for tape in tapes:
#Set the TapeARN variable
tape_arn = tape['TapeARN']
#Describe the tags for the tape using the tape ARN
tape_tag = tgw_client.list_tags_for_resource(ResourceARN = tape_arn)
#Exception handing
try:
#Check to see if the first tag value matches job001
if tape_tag['Tags'][0]['Value'] == 'Warehouse':
#If the tag value matches job001, then print the list_tags_for_resource response for that tape
print(tape_tag)
#Ignore tapes which do not have the job001 tag
else:
pass
except:
pass
非常感谢您在获取磁带和标签的输出或如何修复此 python 脚本方面的任何帮助!