Class: VScripts::Commands::Tags2facts
- Inherits:
-
Object
- Object
- VScripts::Commands::Tags2facts
- Includes:
- Util::LocalSystem
- Defined in:
- lib/vscripts/commands/tags2facts.rb
Overview
Tags2Facts Class
Constant Summary collapse
- USAGE =
HELP
"\n This command can only be run on an AWS EC2 instance. It looks for all tags\n associated with it and dumps them in a JSON file. By default this file is\n `/etc/facter/facts.d/ec2_tags.json`. It can be overridden with the\n ***`--file`*** argument.\n\n The `Name` and `Domain` tags are excluded by default because this command is\n intended to add Facter facts and these 2 already exist in Facter. This\n behaviour can be overridden by adding `[-a|--all]` command line option.\n\n Usage:\n $ vscripts tags2facts [options]\n\n Options:\n"
Instance Attribute Summary collapse
-
#arguments ⇒ Array
readonly
Command specific arguments.
-
#ec2 ⇒ AWS::EC2
readonly
EC2 SDK.
Instance Method Summary collapse
-
#cli ⇒ Object
Parses command line arguments.
-
#exclude_list ⇒ Array
A list of tags to be excluded.
-
#execute ⇒ Object
Writes the formatted JSON to a file.
-
#initialize(argv = []) ⇒ Tags2facts
constructor
A new instance of Tags2facts.
-
#parser ⇒ Object
Specifies command line options.
-
#tags_hash ⇒ Hash
Tags table.
-
#tags_json ⇒ JSON
Formatted JSON.
Methods included from Util::LocalSystem
#checks, #ensure_file_content, #ensure_file_dir, #external_dns, #hostname_path, #hosts_path, #local_domain_name, #local_fqdn, #local_host_name, #process_checks, #status_codes, #write_file
Constructor Details
#initialize(argv = []) ⇒ Tags2facts
Returns a new instance of Tags2facts.
37 38 39 40 |
# File 'lib/vscripts/commands/tags2facts.rb', line 37 def initialize(argv = []) @arguments ||= argv @ec2 ||= VScripts::AWS::EC2.new end |
Instance Attribute Details
#arguments ⇒ Array (readonly)
Returns Command specific arguments.
33 34 35 |
# File 'lib/vscripts/commands/tags2facts.rb', line 33 def arguments @arguments end |
#ec2 ⇒ AWS::EC2 (readonly)
Returns EC2 SDK.
35 36 37 |
# File 'lib/vscripts/commands/tags2facts.rb', line 35 def ec2 @ec2 end |
Instance Method Details
#cli ⇒ Object
Parses command line arguments
54 55 56 57 58 |
# File 'lib/vscripts/commands/tags2facts.rb', line 54 def cli @cli ||= Trollop.with_standard_exception_handling parser do parser.parse arguments end end |
#exclude_list ⇒ Array
Returns A list of tags to be excluded.
61 62 63 |
# File 'lib/vscripts/commands/tags2facts.rb', line 61 def exclude_list cli.all ? [] : %w(Name Domain) end |
#execute ⇒ Object
Writes the formatted JSON to a file
76 77 78 79 80 81 |
# File 'lib/vscripts/commands/tags2facts.rb', line 76 def execute file = cli.file puts "Writing tags to \"#{file}\"" ensure_file_content(file, ) puts 'Done.' end |
#parser ⇒ Object
Specifies command line options
43 44 45 46 47 48 49 50 51 |
# File 'lib/vscripts/commands/tags2facts.rb', line 43 def parser Trollop::Parser.new do USAGE opt :file, 'The file that will store the tags', type: :string, default: '/etc/facter/facts.d/ec2_tags.json' opt :all, 'Collect all tags' stop_on_unknown end end |
#tags_hash ⇒ Hash
Returns Tags table.
66 67 68 |
# File 'lib/vscripts/commands/tags2facts.rb', line 66 def ec2.(exclude_list).to_h end |
#tags_json ⇒ JSON
Returns Formatted JSON.
71 72 73 |
# File 'lib/vscripts/commands/tags2facts.rb', line 71 def JSON.pretty_generate(.to_h) end |