Class: Magellan::Cli::Resources::Worker
- Defined in:
- lib/magellan/cli/resources/worker.rb
Constant Summary
Constants included from FileAccess
FileAccess::DEFAULT_SELECTION_FILENAME
Instance Method Summary collapse
Methods included from FileAccess
ensure_config_dir, load_selection, load_selections, remove_selection_file, selection_filename, update_selections
Methods inherited from Base
command_help, help, log_error, log_info, log_success, log_verbose, log_warning, puts_with_color, sorted_commands, sorted_printable_commands, update_common_help_message
Instance Method Details
#create(name, image_name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/magellan/cli/resources/worker.rb', line 19 def create(name, image_name) s = load_selection!(Stage::VERSION_PARAMETER_NAME) attrs = if path = [:attributes_yaml] YAML.load_file(path) else {} end params = { "functions_worker" => { "stage_version_id" => s["id"], "name" => name, "image_name" => image_name, }.update(attrs) } post_json("/admin/#{self.resource_key}/new.js", params) select(name) end |
#prepare_images ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/magellan/cli/resources/worker.rb', line 58 def prepare_images s = load_selection!(Worker) id = s["id"] r = post_json("/admin/functions~worker/#{id}/simple_method_call.json", {method_name: "prepare_images"}) targets = r["result"].select{|i| i["instance_amount"] > 0 } if targets.length == 1 img = r["result"].first Image.new.select(img["name"]) end Image.new.show_list(r["result"]) end |
#update(attrs) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/magellan/cli/resources/worker.rb', line 39 def update(attrs) if File.readable?(attrs) attrs = YAML.load_file(attrs) else attrs = JSON.parse(attrs) end w = load_selection!(self.class) self.class.hidden_fields.each do |f| attrs.delete(f) end self.class.field_associations.keys.each do |f| attrs.delete(f) end params = { parameter_name => attrs } put_json("/admin/#{resource_key}/#{w["id"]}/edit.js", params) if v = attrs[self.class.caption_attr] select(v) end end |