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

Instance Attribute Details

#forceObject

Returns the value of attribute force.



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

def force
  @force
end

#iopsObject

Returns the value of attribute iops.



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

def iops
  @iops
end

#mnt_volume_sizeObject

Returns the value of attribute mnt_volume_size.



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

def mnt_volume_size
  @mnt_volume_size
end

#snapshot_idObject

Returns the value of attribute snapshot_id.



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

def snapshot_id
  @snapshot_id
end

#volume_sizeObject

Returns the value of attribute volume_size.



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

def volume_size
  @volume_size
end

Instance Method Details

#apply(type = "main") ⇒ Object



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

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

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

#destroy!(skip_snapshot = "false") ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/ey-core/models/server.rb', line 136

def destroy!(skip_snapshot="false")
  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

  params = {
     :skip_snapshot => skip_snapshot
  }

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

#latest_custom_logObject



54
55
56
# File 'lib/ey-core/models/server.rb', line 54

def latest_custom_log
  logs.select{|l| l.filename.match(/custom/)}.sort_by(&:created_at).last
end

#latest_main_logObject



50
51
52
# File 'lib/ey-core/models/server.rb', line 50

def latest_main_log
  logs.select{|l| l.filename.match(/main/)}.sort_by(&:created_at).last
end

#rebootObject



58
59
60
61
62
63
64
# File 'lib/ey-core/models/server.rb', line 58

def reboot
  requires :identity

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

#reconcileObject



82
83
84
85
86
87
88
# File 'lib/ey-core/models/server.rb', line 82

def reconcile
  requires :identity

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

#reset_state(state) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ey-core/models/server.rb', line 90

def reset_state(state)
  params = {
    "url"   => self.collection.url,
    "id"    => self.id,
    "state" => state
  }

  unless new_record?
    merge_attributes(self.connection.reset_server_state(params).body["server"])
  end
end

#save!Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/ey-core/models/server.rb', line 102

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,
      "force"       => self.force,
      "server"      => {
        "dedicated"       => self.dedicated,
        "flavor"          => self.flavor_id,
        "iops"            => self.iops,
        "location"        => self.location || environment.region,
        "mnt_volume_size" => self.mnt_volume_size,
        "name"            => self.name,
        "release_label"   => self.release_label,
        "role"            => self.role,
        "volume_size"     => self.volume_size,
        "ip_id"           => self.ip_id
      }
    }
    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

#startObject



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

def start
  requires :identity

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

#stopObject



66
67
68
69
70
71
72
# File 'lib/ey-core/models/server.rb', line 66

def stop
  requires :identity

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