def process_cartridge_commands(result)
commands = result.cart_commands
self.ssh_keys = {} unless self.ssh_keys
app_jobs = { 'add_ssh_keys' => [], 'remove_ssh_keys' => [], 'remove_env_vars' => [] }
commands.each do |command_item|
case command_item[:command]
when "SYSTEM_SSH_KEY_ADD"
key = command_item[:args][0]
self.user.add_system_ssh_key(self.name, key)
when "SYSTEM_SSH_KEY_REMOVE"
self.user.remove_system_ssh_key(self.name)
when "APP_SSH_KEY_ADD"
key_name = command_item[:args][0]
key = command_item[:args][1]
self.ssh_keys[key_name] = key
app_jobs['add_ssh_keys'] << [key_name,key]
when "APP_SSH_KEY_REMOVE"
key_name = command_item[:args][0]
key = self.ssh_keys.delete(key_name)
app_jobs['remove_ssh_keys'] << key unless key.nil?
when "ENV_VAR_ADD"
key = command_item[:args][0]
value = command_item[:args][1]
self.user.add_env_var(key,value)
when "ENV_VAR_REMOVE"
key = command_item[:args][0]
self.user.remove_env_var(key)
when "APP_ENV_VAR_REMOVE"
key = command_item[:args][0]
app_jobs['remove_env_vars'] << key unless key.nil?
when "BROKER_KEY_ADD"
iv, token = OpenShift::AuthService.instance.generate_broker_key(self)
self.user.add_save_job('adds', 'broker_auth_keys', [self.uuid, iv, token])
when "BROKER_KEY_REMOVE"
self.user.add_save_job('removes', 'broker_auth_keys', [self.uuid])
end
end
if user.save_jobs
user.save
end
handle = RemoteJob.create_parallel_job
tag = ""
RemoteJob.run_parallel_on_gears(self.gears, handle) { |exec_handle, gear|
app_jobs.each do |action,value|
case action
when "remove_env_vars"
value.each { |key|
job = gear.env_var_job_remove(key)
RemoteJob.add_parallel_job(exec_handle, tag, gear, job)
}
when "add_ssh_keys"
value.each { |key_info|
key_name,key = key_info
job = gear.ssh_key_job_add(key, nil, key_name)
RemoteJob.add_parallel_job(exec_handle, tag, gear, job)
}
when "remove_ssh_keys"
value.each { |key|
job = gear.ssh_key_job_remove(key, nil)
RemoteJob.add_parallel_job(exec_handle, tag, gear, job)
}
end
end
}
RemoteJob.get_parallel_run_results(handle) { |tag, gear, output, status|
if status != 0
raise OpenShift::NodeException.new("Error updating settings on gear: #{gear} with status: #{status} and output: #{output}", 143)
end
}
commands.clear
end