Module: KnifeTopo::CommandHelper
- Included in:
- BootstrapHelper, KnifeHelper, TopoCreate, TopoDelete, TopoExport, TopoImport, TopoSearch
- Defined in:
- lib/chef/knife/topo/command_helper.rb
Overview
Knife topo helpers
Instance Method Summary collapse
-
#check_chef_env(chef_env_name) ⇒ Object
make sure the chef environment exists.
-
#initialize_cmd_args(args, name_args, new_name_args) ⇒ Object
initialize args for another knife command.
- #most_common(vals) ⇒ Object
-
#resource_exists?(relative_path) ⇒ Boolean
check if resource exists.
-
#run_cmd(command_class, args) ⇒ Object
run another knife command.
Instance Method Details
#check_chef_env(chef_env_name) ⇒ Object
make sure the chef environment exists
52 53 54 55 56 57 58 59 60 61 62 |
# 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) ⇒ Object
initialize args for another knife command
25 26 27 28 29 |
# 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) ⇒ Object
64 65 66 67 68 69 |
# 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) ⇒ Boolean
check if resource exists
43 44 45 46 47 48 49 |
# 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) ⇒ Object
run another knife command
32 33 34 35 36 37 38 39 40 |
# 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 |