一种简化aws标签固定群集的工具

aws-tag-a-da的Python项目详细描述


AWS-每日标签

一个工具,它通过给一个标签添加一天标签来简化多个标签的固定。

Build StatusPyPI version

安装

pip install aws-tag-a-day

快速启动

# Generate configuration file
mkdir -p ~/.config/tagaday/
cat > ~/.config/tagaday/config.yml <<EOYdynamodb-table-name: 'tag-proposals'dynamodb-table-region: 'eu-west-2'services:- rds- ec2- s3- emrregions:- us-east-1- us-west-1- eu-west-1- ap-southeast-1- ap-northeast-1required-tags:- Project- Owner- Name- Service- AvailabilityEOY# Create dynamodb table defined in the above config file.# If the table exists already, the utility will not overwrite it.
tag-a-day-initialise

# Start proposing tags
tag-a-day

动机

处理批标记的工具很多,但帮助大规模填充空标记的工具不多。

建议的工作流程是:

  1. 创建配置文件。
  2. 通过运行tag-a-day-initialise创建dynamodb表。这不是破坏性操作,现有的表将不会被修改或删除。如果表已经存在,则实用程序将引发错误。
  3. 让一个或多个用户开始使用tag-a-day
  4. 通过运行tag-a-day-reconcile协调任何不同或重复的标记,并讨论任何重复的标记建议。
  5. 对资源应用标记。

note:此实用程序尚未实现步骤4和5。

参考

支持的服务

配置文件&cli选项

Configuration File KeyTypeCLI OptionTypeDescription
^{}List^{}Comma separated stringList of regions to audit resources in
^{}List^{}Comma separated stringList of services to audit
^{}List^{}Comma separated stringList of tags which must be present on all resources
^{}String^{}StringName of the DynamoDB table to propose tags to. If used in conjunction with ^{}, this will be the DynamoDB table to be created.
^{}String^{}StringAWS Region in which to look for ^{}. If used in conjunction with ^{} this will be the region which the DynamoDB table will be created in.
^{}Comma separated stringList of resource ids, to filter only for specific resources to propose tags for.
^{}StringFile path pointing to a folder where tag profiles are located
^{}StringFile name (including .yaml/.yml suffix) point to a particular tagging profile in ^{}

延伸

aws-tag-a-day是在插件体系结构上构建的,使用^{}中的entry_point

若要添加更多标记处理程序,可以向此repo添加类,也可以使用 拥有setup.py,并使用tag_a_day.tag_handlers入口点连接到插件体系结构。

  1. 创建一个新类,继承自tag_a_day.services.service.Service

    fromtag_a_day.services.serviceimportServiceclassCustomTagHandler(Service):pass
  2. 为标记处理程序设置唯一的名称

    fromtag_a_day.services.serviceimportServiceclassCustomTagHandler(Service):name='custom_handler'
  3. 创建两个stub方法,resourceshandler匹配下面的签名:

    fromtag_a_day.services.serviceimportServiceclassVpcTagHandler(Service):name='ec2_vpc'defresources(self,session):passdefhandler(self,resource,expected_tags,region,session,cache,proposals):pass
  4. 实现resources(...)以返回iterable。如果使用BOTO3资源, 看起来应该是:

    defresources(self,session):returnsession.resource('ec2').vpc.all()

    如果使用boto3客户机,不要忘记实现分页,应该如下所示:

    defresources(self,session):ec2=session.client('ec2')paginator=ec2.get_paginator('describe_vpcs')forpageinpaginator.paginate():forvpcinpage:yieldvpc
  5. 实现handle(...)以产生描述标记建议的有效负载(例如使用boto3.resources):

    defhandle(self,vpc,expected_tags,region,session,cache,proposals):# This boilerplate logic will handle checking the tags which have already been# evaluated for this user.evaluated_tags=self._progress.evaluated_tags(vpc.vpc_id)vpc_info,missing_tags= \
            self._build_tag_sets(expected_tags,evaluated_tags,vpc.tags)# Check if the user has proposed values for all the missing tags ifself._progress.has_finished(vpc.vpc_id,expected_tags):# Print a skip messageself._skip(vpc.vpc_id)returnifany(missing_tags):# Print information about this resource, which could be useful # to provide context around tagging.self._print_table(("VpcID",vpc.vpc_id),*vpc_info)# Allow the user to skip auditing this resource       ifself._user_skip():return# Build our user prompt to ask for new tagstag_prompt=self._build_tag_prompt(missing_tags)fortag_keyinmissing_tags:# Yield a proposal for a new tag key/value pair for the given# resource id.yield{'resource_id':vpc.vpc_id,'tag_key':tag_key,'tag_value':tag_prompt(tag_key),}
  6. 最后,通过扩展setup.py

    fromsetuptoolsimportsetupsetup(...,entry_points={'tag_a_day.tag_handlers':['vpc = my_package.my_module:VPCTagHandler',],})

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java HttpSession API   如果模式可用,xml java将忽略DTD进行验证   java从远程位置调用Jersey API   在Java中直接从URL读取html   如何使用#Hibernate#Spring#Java在MySql中存储“日期”?   java如何在JSP中迭代列表对象?   java如何使用PDFBox确定实际PDF内容的位置?   utf 8计算Java字符串的UTF8长度,而不实际对其进行编码   java我正在尝试通过whatsapp或任何其他messenger应用程序发送/共享mp3原始文件。   使用Java定期将记录写入CSV文件   用于队列和工作程序设计的java实时执行器池   java与t1的区别是什么。当前线程和线程。当前线程?   java将大字符串写入文本文件?   java传递给侦听器   java如何从对象列表向JComboBox添加项