Class: Ey::Core::Client::Server

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

Instance Attribute Summary collapse

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, #update!, #url

Instance Attribute Details

#iopsObject

Returns the value of attribute iops.



35
36
37
# File 'lib/ey-core/models/server.rb', line 35

def iops
  @iops
end

#mnt_volume_sizeObject

Returns the value of attribute mnt_volume_size.



35
36
37
# File 'lib/ey-core/models/server.rb', line 35

def mnt_volume_size
  @mnt_volume_size
end

#snapshot_idObject

Returns the value of attribute snapshot_id.



35
36
37
# File 'lib/ey-core/models/server.rb', line 35

def snapshot_id
  @snapshot_id
end

#volume_sizeObject

Returns the value of attribute volume_size.



35
36
37
# File 'lib/ey-core/models/server.rb', line 35

def volume_size
  @volume_size
end

Instance Method Details

#destroy!Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ey-core/models/server.rb', line 74

def destroy!
  if environment.servers.count == 1
    raise Ey::Core::Client::NotPermitted, "Terminating the last server in an environment is not allowed.  You must deprovision or destroy the environment instead."
  end

  requires :identity

  connection.requests.new(
    self.connection.destroy_server(self.identity).body["request"]
  )
end

#rebootObject



37
38
39
40
41
42
43
# File 'lib/ey-core/models/server.rb', line 37

def reboot
  requires :identity

  connection.requests.new(
    self.connection.reboot_server("id" => self.identity).body["request"]
  )
end

#save!Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ey-core/models/server.rb', line 45

def save!
  if new_record?
    requires :flavor_id, :role, :environment

    server_attributes = {
      "environment" => environment.id,
      "snapshot"    => self.snapshot_id,
      "server"      => {
        "flavor"          => self.flavor_id,
        "iops"            => self.iops,
        "location"        => self.location || environment.region,
        "mnt_volume_size" => self.mnt_volume_size,
        "name"            => self.name,
        "role"            => self.role,
        "volume_size"     => self.volume_size,
      }
    }
    connection.requests.new(connection.create_server(server_attributes).body["request"])
  else
    requires :identity
    server_attributes = Cistern::Hash.slice(Cistern::Hash.stringify_keys(self.attributes), "provisioned_at", "deprovisioned_at", "disappeared_at")
    server_attributes.merge!("status" => self.state) if self.state
    connection.update_server(
      "id"     => self.identity,
      "server" => server_attributes,
    )
  end
end