Class: Magellan::Cli::Resources::Worker

Inherits:
Base
  • Object
show all
Defined in:
lib/magellan/cli/resources/worker.rb

Instance Method Summary collapse

Methods included from FileAccess

#load_selection, #load_selections, #update_selections

Instance Method Details

#create(name, image_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/magellan/cli/resources/worker.rb', line 17

def create(name, image_name)
  s = load_selection("stage-version")
  attrs =
    if path = options[:attributes_yaml]
      YAML.load_file(path)
    else
      {}
    end
  params = {
    "functions_worker" => {
      "stage_version_id" => s["id"],
      "name" => name,
      "image_name" => image_name,
      # "instance_base_name" => name,
    }.update(attrs)
  }
  post_json("/admin/#{self.resource_name}/new.json", params)
end

#prepare_imagesObject



53
54
55
56
57
58
# File 'lib/magellan/cli/resources/worker.rb', line 53

def prepare_images
  s = load_selection("functions_worker")
  id = s["id"]
  r = post_json("/admin/functions~worker/#{id}/simple_method_call.json", {method_name: "prepare_images"})
  Image.new.show_list(r["result"])
end

#update(attrs) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/magellan/cli/resources/worker.rb', line 37

def update(attrs)
  if File.readable?(attrs)
    attrs = YAML.load_file(attrs)
  else
    attrs = JSON.parse(attrs)
  end
  w = load_selection(parameter_name)
  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_name}/#{w["id"]}/edit.js", params)
end