Class: MyKnifePlugins::OverRide
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- MyKnifePlugins::OverRide
- Defined in:
- lib/chef/knife/super_rax.rb
Overview
Make sure you subclass from Chef::Knife
Instance Method Summary collapse
-
#generate_map_template ⇒ Object
This method will be executed when you run this knife command.
- #launch_build ⇒ Object
-
#parse_server_map(map_file) ⇒ Object
Populates server_calls with map data.
- #run ⇒ Object
Instance Method Details
#generate_map_template ⇒ Object
This method will be executed when you run this knife command.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/chef/knife/super_rax.rb', line 49 def generate_map_template file_name = "./map_template.json" template = %q( { "servers" : [ { "name_convention" : "web", "run_list" : [ "role[base]", "role[narciss]" ], "quantity" : 2, "chef_env" : "dev", "image_ref" : "c195ef3b-9195-4474-b6f7-16e5bd86acd0", "flavor" : 2 } ] }) File.open(file_name, 'w') { |file| file.write(template)} end |
#launch_build ⇒ Object
104 105 106 107 |
# File 'lib/chef/knife/super_rax.rb', line 104 def launch_build yield end |
#parse_server_map(map_file) ⇒ Object
Populates server_calls with map data
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/chef/knife/super_rax.rb', line 71 def parse_server_map(map_file) map_contents = JSON.parse(File.read(map_file)) server_calls = {} if map_contents.has_key?("servers") for i in map_contents['servers'] server_calls[i['name_convention']] = { "run_list" => i['run_list'] , "quantity" => i['quantity'], "chef_env" => i['chef_env'], "image_ref" => i['image_ref'] } #i['quantity'].times do run_list = i['run_list'].join(', ') #Thread.new { create_server = Chef::Knife::RackspaceServerCreate.new #create_server.config[:image] = i['image_ref'] Chef::Config[:knife][:image] = i['image_ref'] create_server.config[:server_name] = i['name_convention'] create_server.config[:environment] = i['chef_env'] create_server.config[:run_list] = i['run_list'] #create_server.config[:flavor] = i['flavor'] Chef::Config[:knife][:flavor] = i['flavor'] create_server.run ##} #end end else ui.fatal "JSON file incorrect format" end end |
#run ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/chef/knife/super_rax.rb', line 109 def run #Generate template config if config[:generate_map_template] generate_map_template() end #Parses Map and takes action if config[:server_map] parse_server_map(config[:server_map]) end end |