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.



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

def iops
  @iops
end

#mnt_volume_sizeObject

Returns the value of attribute mnt_volume_size.



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

def mnt_volume_size
  @mnt_volume_size
end

#snapshot_idObject

Returns the value of attribute snapshot_id.



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

def snapshot_id
  @snapshot_id
end

#volume_sizeObject

Returns the value of attribute volume_size.



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

def volume_size
  @volume_size
end

Instance Method Details

#apply(type = "main") ⇒ Object



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

def apply(type="main")
  requires :identity

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

#destroy!Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ey-core/models/server.rb', line 84

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



45
46
47
48
49
50
51
# File 'lib/ey-core/models/server.rb', line 45

def reboot
  requires :identity

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

#save!Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ey-core/models/server.rb', line 53

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

    server_attributes = {
      "environment" => environment.id,
      "wait_for_chef" => self.wait_for_chef,
      "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,
        "release_label"   => self.release_label,
      }
    }
    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