Class: ZZDeploy
Constant Summary collapse
- CMD =
"zz"
- RECIPES_DIR =
"/var/chef/cookbooks/zz-chef-repo"
- RECIPES_BUNDLE_DIR =
"/var/chef/cookbooks/zz-chef-repo_bundle"
Instance Method Summary collapse
-
#define_sub_commands ⇒ Object
define sub commands here.
- #force_fail(cmd = nil) ⇒ Object
-
#options ⇒ Object
the options that were set.
- #parse ⇒ Object
- #print_actions ⇒ Object
- #printer ⇒ Object
-
#required_options ⇒ Object
required options.
- #run(argv = ARGV) ⇒ Object
- #set_amazon_options ⇒ Object
- #setup ⇒ Object
- #sub_commands ⇒ Object
-
#validate(cmd, sub_cmd) ⇒ Object
validate the options passed.
Instance Method Details
#define_sub_commands ⇒ Object
define sub commands here
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/zz_deploy.rb', line 40 def define_sub_commands sub_commands[:deploy_group_create] = Commands::DeployGroupCreate.new sub_commands[:deploy_group_delete] = Commands::DeployGroupDelete.new sub_commands[:deploy_group_list] = Commands::DeployGroupList.new sub_commands[:deploy_group_modify] = Commands::DeployGroupModify.new sub_commands[:add] = Commands::AddInstance.new sub_commands[:delete] = Commands::DeleteInstances.new sub_commands[:list] = Commands::ListInstances.new sub_commands[:deploy] = Commands::DeployInstances.new sub_commands[:maint] = Commands::MaintInstances.new sub_commands[:ssh] = Commands::SSHInstance.new sub_commands[:multi_ssh] = Commands::MultiSSHInstance.new sub_commands[:chef_upload] = Commands::ChefUpload.new sub_commands[:chef_bake] = Commands::ChefBake.new sub_commands[:config_amazon] = Commands::ConfigAmazon.new end |
#force_fail(cmd = nil) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/zz_deploy.rb', line 91 def force_fail(cmd = nil) # force failure and show options ARGV.clear ARGV << "help" ARGV << cmd unless cmd.nil? opt_parse end |
#options ⇒ Object
the options that were set
27 28 29 |
# File 'lib/zz_deploy.rb', line 27 def @options ||= {} end |
#parse ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/zz_deploy.rb', line 125 def parse if ARGV.empty? ARGV << "help" end cmd = opt_parse() if cmd.nil? force_fail end # ok, we have a valid command so dispatch it # puts "cmd: #{cmd}" # puts "options ......" # p options # puts "ARGV:" # p ARGV sub_cmd = sub_commands[cmd.to_sym] validate(cmd, sub_cmd) # track both types of options ZZSharedLib::Options. = ZZSharedLib::Options. = sub_cmd. # dispatch the command amazon = ZZSharedLib::Amazon.new sub_cmd.send("run", , amazon) end |
#print_actions ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/zz_deploy.rb', line 177 def print_actions cmdtext = "Commands are:" @commands.sort.map do |c, opt| #puts "inside opt.call loop" desc = opt.call.description cmdtext << "\n #{c} : #{desc}" end # print aliases unless @aliases.empty? cmdtext << "\n\nAliases: \n" @aliases.each_pair { |name, val| cmdtext << " #{name} - #{val}\n" } end cmdtext << "\n\nSee '#{CMD} help COMMAND' for more information on a specific command." end |
#printer ⇒ Object
35 36 37 |
# File 'lib/zz_deploy.rb', line 35 def printer @printer ||= Printer.new end |
#required_options ⇒ Object
required options
21 22 23 24 |
# File 'lib/zz_deploy.rb', line 21 def @required_options ||= Set.new [ ] end |
#run(argv = ARGV) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/zz_deploy.rb', line 157 def run(argv = ARGV) exit_code = true begin setup parse rescue SystemExit => ex # ignore direct calls to exit rescue Exception => ex printer.error printer.color(ex., :red) # puts ex.backtrace exit_code = false end # make sure buffer is flushed # debugger doesn't seem to do this always STDOUT.flush return exit_code end |
#set_amazon_options ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/zz_deploy.rb', line 116 def json = File.open("/var/chef/amazon.json", 'r') {|f| f.read } ak = JSON.parse(json) [:access_key] = ak["aws_access_key_id"] [:secret_key] = ak["aws_secret_access_key"] rescue # do nothing end |
#setup ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/zz_deploy.rb', line 57 def setup .clear # global options do |opts| opts. = "Version: #{Info.version} - Usage: #{CMD} [options] [subcommand [options]]" opts.description = "ZangZing configuration and deploy tool. You must specify a valid sub command." opts.separator "" opts.separator "Global options are:" opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| [:verbose] = v end opts.on("--akey AmazonAccessKey", "Amazon access key, or environment AWS_ACCESS_KEY_ID.") do |v| [:access_key] = v end opts.on("--skey AmazonSecretKey", "Amazon secret key or environment AWS_SECRET_ACCESS_KEY") do |v| [:secret_key] = v end end add_help_option define_sub_commands sub_commands.each_pair do |command_name, sub_cmd| command command_name do |opts| sub_cmd.send("register", opts, ) end end end |
#sub_commands ⇒ Object
31 32 33 |
# File 'lib/zz_deploy.rb', line 31 def sub_commands @sub_commands ||= {} end |
#validate(cmd, sub_cmd) ⇒ Object
validate the options passed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/zz_deploy.rb', line 100 def validate(cmd, sub_cmd) .each do |r| if .has_key?(r) == false puts "Missing options" force_fail end end sub_cmd..each do |r| if sub_cmd..has_key?(r) == false puts "Missing options" force_fail(cmd) end end end |