Skip to content

Commit

Permalink
Minor code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vladgh committed Jun 11, 2014
1 parent a32dbcc commit 8821acd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/vscripts/aws/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def functional_instances
# a Name tag
def similar_instances
check_instance
functional_instances.map do |functional_instance|
functional_instances.compact.map do |functional_instance|
next if functional_instance.id == instance_id
functional_instance.tags['Name']
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vscripts/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def verify_command
if Commands.list.include?(command_cls)
return command_cls
else
abort "Error: Unknown subcommand '#{command_cli}'\nTry --help."
abort "Error: unknown subcommand '#{command_cli}'\nTry --help."
end
end
end # class CommandLine
Expand Down
35 changes: 19 additions & 16 deletions lib/vscripts/commands/identify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Identify # rubocop:disable ClassLength

# Shows help
USAGE = <<-EOS
This command creates a themed host name and fully qualified domain name for
the server, using AWS EC2 tags. The default theme is `Group-Role-#` which means
that the command collects the value of the `Group` and the `Role` AWS EC2 tags
Expand All @@ -24,20 +25,20 @@ class Identify # rubocop:disable ClassLength
modified on the local instance and a new `Name` EC2 tag is created and
associated with the current instance.
If a ***--host*** argument is provided it will override the default theme.
*DOMAIN* is still looked up.
If a ***--domain*** argument is provided it will override the default
domain.
If a ***--host*** argument is provided it will override the default theme.
*DOMAIN* is still looked up.
If a ***--domain*** argument is provided it will override the default
domain.
EXAMPLES:
$ vscripts identify
MyGroup-MyRole-1.Example.tld
$ vscripts identify --ec2-tag-theme NAME-#
MyName-1.Example.tld`
$ vscripts identify --host myhost --domain example.com
myhost.example.com`
USAGE:
$ vscripts identify
MyGroup-MyRole-1.Example.tld
$ vscripts identify --ec2-tag-theme NAME-#
MyName-1.Example.tld`
$ vscripts identify --host myhost --domain example.com
myhost.example.com`
Options:
OPTIONS:
EOS

# @return [String] the theme
Expand Down Expand Up @@ -137,6 +138,7 @@ def set_name_tag

# Modifies the host name
def set_hostname
return unless File.exist?(hostname_path)
return if File.read(hostname_path).strip == new_hostname
puts "Setting local hostname (#{new_hostname})..."
write_file(hostname_path, new_hostname)
Expand All @@ -145,10 +147,11 @@ def set_hostname

# Modifies the hosts file
def update_hosts
return unless File.exist?(hosts_path)
return if File.readlines(hosts_path)
.grep(/#{new_fqdn} #{new_hostname}/)
.any?
hosts_body = hosts_file.gsub(
hosts_body = File.read(hosts_path).gsub(
/^127\.0\.0\.1.*/,
"127\.0\.0\.1 #{new_fqdn} #{new_hostname} localhost"
)
Expand All @@ -158,9 +161,9 @@ def update_hosts

# Executes the command
def execute
set_name_tag
set_hostname
update_hosts
puts 'EC2 tag not changed!' unless set_name_tag
puts 'Hostname not changed!' unless set_hostname
puts 'Hosts file not changed!' unless update_hosts
puts 'Done.'
end
end # class Identify
Expand Down
20 changes: 10 additions & 10 deletions lib/vscripts/commands/tags2facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ class Tags2facts
# Shows help
USAGE = <<-EOS
This command can only be run on an AWS EC2 instance. It looks for all tags
associated with it and dumps them in a JSON file. By default this file is
`/etc/facter/facts.d/ec2_tags.json`. It can be overridden with the
***`--file`*** argument.
This command can only be run on an AWS EC2 instance. It looks for all tags
associated with it and dumps them in a JSON file. By default this file is
`/etc/facter/facts.d/ec2_tags.json`. It can be overridden with the
***`--file`*** argument.
The `Name` and `Domain` tags are excluded by default because this command is
intended to add Facter facts and these 2 already exist in Facter. This
behaviour can be overridden by adding `[-a|--all]` command line option.
The `Name` and `Domain` tags are excluded by default because this command is
intended to add Facter facts and these 2 already exist in Facter. This
behaviour can be overridden by adding `[-a|--all]` command line option.
Usage:
$ vscripts tags2facts [options]
USAGE:
vscripts tags2facts [options]
Options:
OPTIONS:
EOS

# @return [Array] the command specific arguments
Expand Down
5 changes: 0 additions & 5 deletions lib/vscripts/util/local_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ def hosts_path
'/etc/hosts'
end

# @return [String] the contents of the hosts file
def hosts_file
File.read(hosts_path)
end

# @return [String] the hostname file path
def hostname_path
'/etc/hostname'
Expand Down

0 comments on commit 8821acd

Please sign in to comment.