Class: Ey::Core::Client::UntrackedServer

Inherits:
Model
  • Object
show all
Extended by:
Associations
Defined in:
lib/ey-core/models/untracked_server.rb

Instance Method Summary collapse

Methods included from Associations

assoc_accessor, assoc_coverage, assoc_reader, assoc_writer, associations, collection_reader

Methods inherited from Model

#destroy, range_parser, #save, #to_s, #update!, #url

Instance Method Details

#save!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ey-core/models/untracked_server.rb', line 15

def save!
  request_attributes = {
    "provider" => self.provider_id,
    "url"      => self.collection.url,
  }

  response = if new_record?
               requires :location, :provisioned_id

               request_attributes.merge!(
                 "untracked_server" => Cistern::Hash.slice(
                   Cistern::Hash.stringify_keys(self.attributes), "location", "provisioned_id", "provisioner_id", "state"
                 ),
               )

               connection.create_untracked_server(request_attributes)
             else
               requires :identity

               request_attributes.merge!(
                 "untracked_server" => Cistern::Hash.slice(
                   Cistern::Hash.stringify_keys(self.attributes), "location", "provisioner_id", "state"
                 ),
               )

               connection.update_untracked_server(request_attributes.merge("id" => self.identity))
             end

  merge_attributes(response.body["untracked_server"])
end