Skip to content

Instantly share code, notes, and snippets.

View gmcculloug's full-sized avatar

Greg McCullough gmcculloug

View GitHub Profile
@gmcculloug
gmcculloug / provision.rb
Created December 11, 2017 19:06
API Provision
require 'rest-client'
require 'json'
def provisioning_parameters
{"version"=>"1.1",
"template_fields"=>
{"guid"=>"b420edc4-e6cd-11e5-b810-000a27020066",
"name"=>"gm-empty-template"},
"vm_fields"=>
{"sysprep_server_license_mode"=>"perServer",
@gmcculloug
gmcculloug / custom_button_export.rb
Last active May 4, 2020 16:42
Custom Button Export
class ExportArInstances
EXCLUDE_ATTRS = %w(id created_on updated_on created_at updated_at).freeze
def self.export_object(obj, hash)
class_name = obj.class.name.underscore
puts "Exporting #{obj.class.name} [#{obj.try('name')}] with ID: #{obj.id}"
(hash[class_name] ||= []) << item = {'attributes' => export_attributes(obj)}
try(class_name).tap do |has_many_assoc, has_one_assoc|
@gmcculloug
gmcculloug / base_model_walker.rb
Created August 3, 2018 12:36
Prints hierarchical view of Rails models
# active_record model descendant walker
def model
(ARGV.first || 'ApplicationRecord').classify.safe_constantize.tap do |model|
raise "Provide valid model name. Argv: #{ARGV.first}" unless model
raise "Model must be a sub-class of ActiveRecord::Base Argv: #{ARGV.first}" unless model < ActiveRecord::Base || model == ActiveRecord::Base
end
end
def base_model(model)
$dry_run = true
def clean_automation(klass)
puts "#{$dry_run ? 'DRY RUN' : 'Processing'} #{klass.name}"
klass.where(:state => %w[pending queued]).in_batches.each_with_index do |relation, batch_index|
ids = relation.pluck(:id)
queue_relation = MiqQueue.where(:class_name => klass.name, :instance_id => ids)
puts " Batch #{batch_index} Size #{ids.size} Queue Item Count: #{queue_relation.size}"
@gmcculloug
gmcculloug / list_code_owners.rb
Last active December 13, 2019 16:43
List code owners
def walk(start = ".", prefix = "")
Dir.foreach(start) do |x|
next if x[0] == "."
path = File.join(start, x)
next if File.symlink?(path)
print_directory(path, prefix) if File.directory?(path)
end
end
def setup
app_name = ENV['OPENSHIFT_BUILD_NAME'].split('-')[0..-3].join('-') || ENV['APP_NAME']
raise 'Missing ENV variable APP_NAME' unless app_name
@product_component = "#{app_name}:api"
# Prefix defined at https://pp.engineering.redhat.com/pp/
@prefix = case app_name
when /catalog/, /approval/ then 'services-automation-services-catalog'
when /sources/ then 'services-sources'
# Catalog UI manifest
jq --arg prefix services-automation-services-catalog/catalog:ui/ -r '[ [ .. | .resolved? | select(type == "string") ] | .[] | sub("^.*/";""+$prefix+"npmjs-") ] | unique | sort []' package-lock.json
# Approval UI manifest
jq --arg prefix services-automation-services-catalog/approval:ui/ -r '[ [ .. | .resolved? | select(type == "string") ] | .[] | sub("^.*/";""+$prefix+"npmjs-") ] | unique | sort []' package-lock.json
# Sources UI manifest
jq --arg prefix services-sources/sources:ui/ -r '[ [ .. | .resolved? | select(type == "string") ] | .[] | sub("^.*/";""+$prefix+"npmjs-") ] | unique | sort []' package-lock.json