module KnifeTopo::CommandHelper
Knife topo helpers
Public Instance Methods
check_chef_env(chef_env_name)
click to toggle source
make sure the chef environment exists
# File lib/chef/knife/topo/command_helper.rb, line 52 def check_chef_env(chef_env_name) return unless chef_env_name Chef::Environment.load(chef_env_name) if chef_env_name rescue Net::HTTPServerException => e raise unless e.to_s =~ /^404/ ui.info 'Creating chef environment ' + chef_env_name chef_env = Chef::Environment.new chef_env.name(chef_env_name) chef_env.create chef_env end
initialize_cmd_args(args, name_args, new_name_args)
click to toggle source
initialize args for another knife command
# File lib/chef/knife/topo/command_helper.rb, line 25 def initialize_cmd_args(args, name_args, new_name_args) args = args.dup args.shift(2 + name_args.length) new_name_args + args end
most_common(vals)
click to toggle source
# File lib/chef/knife/topo/command_helper.rb, line 64 def most_common(vals) return if vals.empty? vals.group_by do |val| val end.values.max_by(&:size).first end
resource_exists?(relative_path)
click to toggle source
check if resource exists
# File lib/chef/knife/topo/command_helper.rb, line 43 def resource_exists?(relative_path) rest.get_rest(relative_path) true rescue Net::HTTPServerException => e raise unless e.response.code == '404' false end
run_cmd(command_class, args)
click to toggle source
run another knife command
# File lib/chef/knife/topo/command_helper.rb, line 32 def run_cmd(command_class, args) command = command_class.new(args) command.config[:config_file] = config[:config_file] command.configure_chef command_class.load_deps command.run command end