lib/gaptool-client.rb in gaptool-client-0.5.6 vs lib/gaptool-client.rb in gaptool-client-0.5.7
- old
+ new
@@ -72,10 +72,29 @@
end
end
end
end
+def split_attrs(attribute_list)
+ opts = {}
+ attribute_list.each do |attr_|
+ key, value = attr_.split('=', 2)
+ split = key.split('.')
+ cur = opts
+ split.each_with_index do |part, idx|
+ if idx == split.size - 1
+ # leaf, add the value
+ cur[part] = value
+ else
+ cur[part] ||= {}
+ end
+ cur = cur[part]
+ end
+ end
+ opts
+end
+
module Gaptool
class InitCommand < Clamp::Command
option ["-r", "--role"], "ROLE", "Resource name to initilize", :required => true
option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
option ["-z", "--zone"], "ZONE", "AWS availability zone to put node in", :required => true
@@ -185,12 +204,14 @@
class ChefrunCommand < Clamp::Command
option ["-r", "--role"], "ROLE", "Role name to ssh to", :required => true
option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
option ["-i", "--instance"], "INSTANCE", "Instance ID, e.g. i-12345678", :required => false
+ option ["-A", "--attribute"], "ATTRIBUTE", "Pass one or more parameters to the deploy recipe in recipe.attr=value format", :multivalued => true
def execute
+ attrs = split_attrs(attribute_list)
if !instance.nil?
nodes = [$api.getonenode(instance)]
else
nodes = $api.getenvroles(role, environment)
end
@@ -204,11 +225,11 @@
'hostname' => node['hostname'],
'instance' => node['instance'],
'zone' => node['zone'],
'itype' => node['itype'],
'apps' => eval(node['apps'])
- }.to_json
+ }.merge(attrs).to_json
commands = [
"cd ~admin/ops; git pull",
"echo '#{json}' > ~admin/solo.json",
"sudo chef-solo -c ~admin/ops/cookbooks/solo.rb -j ~admin/solo.json"
]
@@ -222,12 +243,14 @@
option ["-m", "--migrate"], :flag, "Toggle running migrations"
option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
option ["-b", "--branch"], "BRANCH", "Git branch to deploy, default is master", :required => false
option ["-r", "--rollback"], :flag, "Toggle this to rollback last deploy"
option ["-i", "--instance"], "INSTANCE", "Instance ID, e.g. i-12345678", :required => false
+ option ["-A", "--attribute"], "ATTRIBUTE", "Pass one or more parameters to the deploy recipe in recipe.attr=value format", :multivalued => true
def execute
+ attrs = split_attrs(attribute_list)
if instance
nodes = [$api.getonenode(instance)]
else
nodes = $api.getappnodes(app, environment)
end
@@ -246,10 +269,10 @@
'app_name' => app,
'app' => app,
'rollback' => rollback?,
'branch' => branch || 'master',
'migrate' => migrate?
- }.to_json
+ }.merge(attrs).to_json
commands = [
"cd ~admin/ops; git pull",
"echo '#{json}' > ~admin/solo.json",
"sudo chef-solo -c ~admin/ops/cookbooks/solo.rb -j ~admin/solo.json"
]