Skip to content

Commit

Permalink
Merge pull request #15957 from jrafanie/user_friendly_tools
Browse files Browse the repository at this point in the history
Make tools easier to run
  • Loading branch information
Fryguy committed Sep 8, 2017
2 parents 0bb0aee + 7deb5ac commit ccece2a
Show file tree
Hide file tree
Showing 45 changed files with 119 additions and 5 deletions.
3 changes: 3 additions & 0 deletions tools/create_evm_snapshot.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

def usage
puts "Error: Must pass only one of the following:"
puts " --vm=<vm id>"
Expand Down
1 change: 1 addition & 0 deletions tools/db_ping_remote.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)
require 'io/console'

Expand Down
4 changes: 3 additions & 1 deletion tools/db_printers/print_ae_tree.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Rails.logger.level = $log.level = 0
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', __dir__)

# Rails.logger.level = $log.level = 0
def print_ae_tree(nodes, indent = "")
nodes.sort_by { |n| n.name.downcase }.each do |node|
title = node.class.name.demodulize[5..-1]
Expand Down
3 changes: 3 additions & 0 deletions tools/db_printers/print_ems_metadata.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', __dir__)

def print_subtree(subtree, indent = '')
subtree = subtree.sort_by { |obj, _children| [obj.class.name, obj.name.downcase] }
subtree.each do |obj, children|
Expand Down
3 changes: 3 additions & 0 deletions tools/db_printers/print_ems_metadata_full.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', __dir__)

def print_subtree(subtree, indent = '')
subtree = subtree.sort_by { |obj, _children| [obj.class.name, obj.name.downcase] }
subtree.each do |obj, children|
Expand Down
3 changes: 3 additions & 0 deletions tools/db_printers/print_network.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', __dir__)

def print_switch(indent, switch)
puts "#{indent}Switch: #{switch.name}"
switch.lans.order("lower(name)").each do |lan|
Expand Down
3 changes: 3 additions & 0 deletions tools/db_printers/print_relationships.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', __dir__)

def print_rels(subtree, indent = '')
subtree = subtree.sort_by { |rel, _children| rel.resource_pair }
subtree.each do |rel, children|
Expand Down
3 changes: 3 additions & 0 deletions tools/db_printers/print_scsi.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', __dir__)

Host.all.each do |host|
puts "Host: #{host.name} (id: #{host.id})"

Expand Down
3 changes: 3 additions & 0 deletions tools/db_printers/print_vmdb_database.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', __dir__)

def print_records(recs, indent = '')
recs = recs.sort_by { |r| r.name.downcase }
recs.each do |r|
Expand Down
3 changes: 3 additions & 0 deletions tools/dba.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

module Dba
def self.select(*args)
ActiveRecord::Base.connection.send(:select, *args)
Expand Down
3 changes: 3 additions & 0 deletions tools/delete_all_error_timeout_queue_messages.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

cond = {:state => ["error", "timeout"]}
puts "Deleting #{MiqQueue.where(cond).count} queue messages"

Expand Down
3 changes: 3 additions & 0 deletions tools/delete_ems_metadata_relationships.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

puts "Deleting ems_metadata Relationships..."
Relationship.where(:relationship => "ems_metadata").delete_all
puts "Deleting ems_metadata Relationships...Complete"
3 changes: 3 additions & 0 deletions tools/doc/reportable_fields_to_csv.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', __dir__)

models = MiqReport.reportable_models.collect do |m|
[Dictionary.gettext(m, :type => :model, :notfound => :titleize).pluralize, m]
end.sort
Expand Down
3 changes: 3 additions & 0 deletions tools/doc/reports_to_csv.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', __dir__)

require 'csv'
CSV.open("reports.csv", "w") do |csv|
csv << %w(Name Title Group Sorting Graph Filter)
Expand Down
3 changes: 3 additions & 0 deletions tools/evm_dump.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

LOG_DIR = "./"
logfile = File.join(LOG_DIR, "evm_dump.log")
File.delete(logfile) if File.exist?(logfile)
Expand Down
3 changes: 3 additions & 0 deletions tools/export_tags.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

output = ARGV[0]
raise "No output file provided" if output.nil?

Expand Down
1 change: 1 addition & 0 deletions tools/feature_support_matrix.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)
require 'csv'

Expand Down
3 changes: 3 additions & 0 deletions tools/fix_binary_blobs_and_parts_size_column.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

puts "Fixing BinaryBlob and BinaryBlobPart sizes"

blob_ids = BinaryBlobPart.select(:binary_blob_id).where("size != LENGTH(data)")
Expand Down
3 changes: 3 additions & 0 deletions tools/fix_column_ordering.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

$LOAD_PATH << Rails.root.join("tools")

require 'column_ordering/column_ordering'
Expand Down
3 changes: 3 additions & 0 deletions tools/fix_disk_sizes.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

def getDinfo(vim)
dinfo = []
vim.virtualMachinesByMor.each do |_k, v|
Expand Down
3 changes: 3 additions & 0 deletions tools/fix_vm_relationships.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

### Used to fix VM to Parent Resource Pool relationship problems.
# Normally seen when user clicks on a VM to view VM summary page.
# Error is displayed "Couldn't find Relationship with id=XXXX [vm_or_template/tree_select]"
Expand Down
3 changes: 3 additions & 0 deletions tools/import_tags.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

input = ARGV[0]
raise "No input file provided" if input.nil?

Expand Down
3 changes: 3 additions & 0 deletions tools/import_v4_provision_dialogs.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

# Convert v4-style provisioning dialogs from Ruby files into YAML format
# and store in the miq_dialogs table.
Dir.glob(Rails.root.join("db/fixtures/*.rb")) do |dialog_file|
Expand Down
3 changes: 3 additions & 0 deletions tools/kill_provision.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

st = Time.now
@stop_message = "Provisioning stopped by external script."
@processed = []
Expand Down
3 changes: 3 additions & 0 deletions tools/ldap_ping.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

LOG_DIR = "./"
logfile = File.join(LOG_DIR, "ldap_ping.log")
# File.delete(logfile) if File.exist?(logfile)
Expand Down
2 changes: 2 additions & 0 deletions tools/list_evm_snapshots.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)
require 'rubygems'
require 'log4r'
require 'VMwareWebService/MiqVim'
Expand Down
3 changes: 2 additions & 1 deletion tools/log_processing/broker_registry_counts.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
RAILS_ROOT = ENV["RAILS_ENV"] ? Rails.root : File.expand_path(File.join(__dir__, %w(.. ..)))
#!/usr/bin/env ruby
RAILS_ROOT = File.expand_path(File.join(__dir__, %w(.. ..)))
require 'manageiq-gems-pending'
require 'miq_logger_processor'

Expand Down
3 changes: 2 additions & 1 deletion tools/log_processing/ems_refresh_timings.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
RAILS_ROOT = ENV['RAILS_ENV'] ? Rails.root : File.expand_path(File.join(__dir__, %w(.. ..)))
#!/usr/bin/env ruby
RAILS_ROOT = File.expand_path(File.join(__dir__, %w(.. ..)))

require 'manageiq-gems-pending'
require 'miq_logger_processor'
Expand Down
4 changes: 3 additions & 1 deletion tools/log_processing/perf_timings.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RAILS_ROOT = ENV["RAILS_ENV"] ? Rails.root : File.expand_path(File.join(__dir__, %w(.. ..)))
#!/usr/bin/env ruby

RAILS_ROOT = File.expand_path(File.join(__dir__, %w(.. ..)))
require 'manageiq-gems-pending'
require 'miq_logger_processor'

Expand Down
4 changes: 3 additions & 1 deletion tools/log_processing/split_log_by_pid_tid.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RAILS_ROOT = ENV["RAILS_ENV"] ? Rails.root : File.expand_path(File.join(__dir__, %w(.. ..)))
#!/usr/bin/env ruby

RAILS_ROOT = File.expand_path(File.join(__dir__, %w(.. ..)))
require 'manageiq-gems-pending'
require 'miq_logger_processor'

Expand Down
3 changes: 3 additions & 0 deletions tools/metrics_capture_gap.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

if ARGV.length != 2
puts "Usage: rails runner #{$0} start_date end_date"
puts
Expand Down
3 changes: 3 additions & 0 deletions tools/metrics_destroy_for_time_profile.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

if ARGV.length != 1
puts "Usage: rails runner #{$0} time_profile_id"
exit 1
Expand Down
3 changes: 3 additions & 0 deletions tools/metrics_populate_retro_tags.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

# Rails.logger.level = 0

start_ts, end_ts, id_spec = ARGV
Expand Down
3 changes: 3 additions & 0 deletions tools/purge_archived_vms.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

# Delete any records older than this:
ARCHIVE_CUTOFF = Time.now.utc - 1.month
# If true, do not delete anything; only report:
Expand Down
3 changes: 3 additions & 0 deletions tools/purge_ems_events.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

KEEP_EVENTS = 6.months
PURGE_WINDOW = 1000

Expand Down
3 changes: 3 additions & 0 deletions tools/purge_host_unknown_records.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

class HostUnknown < Host; end
HostUnknown.destroy_all
1 change: 1 addition & 0 deletions tools/purge_metrics.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)
require 'trollop'

Expand Down
1 change: 1 addition & 0 deletions tools/purge_miq_report_results.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)
require 'trollop'

Expand Down
1 change: 1 addition & 0 deletions tools/purge_orphaned_tag_values.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)
require 'trollop'

Expand Down
1 change: 1 addition & 0 deletions tools/rebuild_provision_request.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)
require 'trollop'
require 'rest-client'
Expand Down
2 changes: 2 additions & 0 deletions tools/rm_evm_snapshots.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)
require 'rubygems'
require 'log4r'
require 'VMwareWebService/MiqVim'
Expand Down
3 changes: 3 additions & 0 deletions tools/show_host_file_entries_for_vnc.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

ManageIQ::Providers::Vmware::Host.all.each do |host|
if host.ipaddress.blank?
STDERR.puts "Host ID=#{host.id.inspect}, Name=#{host.name.inspect} has no IP Address"
Expand Down
3 changes: 3 additions & 0 deletions tools/vim_collect_inventory.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

require 'trollop'
ARGV.shift if ARGV.first == "--" # Handle when called through script/runner
opts = Trollop.options do
Expand Down
3 changes: 3 additions & 0 deletions tools/vim_collect_perf_history.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

require 'trollop'
ARGV.shift if ARGV.first == "--" # Handle when called through script/runner
opts = Trollop.options do
Expand Down
3 changes: 3 additions & 0 deletions tools/vm_retirement.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

def header
output = "Name\tOwner\tOwner Userid\tOwning Group\tRetired?\tRetirement Date\tRetirement Warning"
output += "\n"
Expand Down

0 comments on commit ccece2a

Please sign in to comment.