Module: Rackconnect::BulkNodes::InstanceMethods

Defined in:
lib/rackconnect/lib/bulk_nodes.rb

Instance Method Summary collapse

Instance Method Details

#add_nodes(ids) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rackconnect/lib/bulk_nodes.rb', line 9

def add_nodes(ids)
  body = ids.inject({}) do |hash, id|
    h = {}
    h[key] = {id: id}
    h["server_group"] = {id: self.id}
    hash.merge(h)
  end.to_json

  path = self.class.instance_variable_get("@_endpoint") + "/nodes" # sorry
  resp = Rackconnect::Request.post(path, body: body)
  resp.body.map{ |obj| node_class.new(json: obj) }
end

#remove_nodes(ids) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rackconnect/lib/bulk_nodes.rb', line 22

def remove_nodes(ids)
  body = ids.inject({}) do |hash, id|
    hash.merge({
      cloud_server: {id: id},
      server_group: {id: self.id}
    }).to_json
  end

  path = self.class.instance_variable_get("@_endpoint") + "/nodes" # sorry
  Rackconnect::Request.delete(path)
end