Class: Ey::Core::Client::Server
- Extended by:
- Associations
- Defined in:
- lib/ey-core/models/server.rb
Instance Attribute Summary collapse
-
#force ⇒ Object
Returns the value of attribute force.
-
#iops ⇒ Object
Returns the value of attribute iops.
-
#mnt_volume_size ⇒ Object
Returns the value of attribute mnt_volume_size.
-
#snapshot_id ⇒ Object
Returns the value of attribute snapshot_id.
-
#volume_size ⇒ Object
Returns the value of attribute volume_size.
Instance Method Summary collapse
- #apply(type = "main") ⇒ Object
- #destroy! ⇒ Object
- #latest_custom_log ⇒ Object
- #latest_main_log ⇒ Object
- #reboot ⇒ Object
- #reconcile ⇒ Object
- #reset_state(state) ⇒ Object
- #save! ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
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
#force ⇒ Object
Returns the value of attribute force.
40 41 42 |
# File 'lib/ey-core/models/server.rb', line 40 def force @force end |
#iops ⇒ Object
Returns the value of attribute iops.
40 41 42 |
# File 'lib/ey-core/models/server.rb', line 40 def iops @iops end |
#mnt_volume_size ⇒ Object
Returns the value of attribute mnt_volume_size.
40 41 42 |
# File 'lib/ey-core/models/server.rb', line 40 def mnt_volume_size @mnt_volume_size end |
#snapshot_id ⇒ Object
Returns the value of attribute snapshot_id.
40 41 42 |
# File 'lib/ey-core/models/server.rb', line 40 def snapshot_id @snapshot_id end |
#volume_size ⇒ Object
Returns the value of attribute volume_size.
40 41 42 |
# File 'lib/ey-core/models/server.rb', line 40 def volume_size @volume_size end |
Instance Method Details
#apply(type = "main") ⇒ Object
42 43 44 45 46 |
# File 'lib/ey-core/models/server.rb', line 42 def apply(type="main") requires :identity connection.requests.new(self.connection.apply_server_updates("id" => self.identity, "type" => type).body["request"]) end |
#destroy! ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ey-core/models/server.rb', line 132 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 |
#latest_custom_log ⇒ Object
52 53 54 |
# File 'lib/ey-core/models/server.rb', line 52 def latest_custom_log logs.select{|l| l.filename.match(/custom/)}.sort_by(&:created_at).last end |
#latest_main_log ⇒ Object
48 49 50 |
# File 'lib/ey-core/models/server.rb', line 48 def latest_main_log logs.select{|l| l.filename.match(/main/)}.sort_by(&:created_at).last end |
#reboot ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ey-core/models/server.rb', line 56 def reboot requires :identity connection.requests.new( self.connection.reboot_server("id" => self.identity).body["request"] ) end |
#reconcile ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/ey-core/models/server.rb', line 80 def reconcile requires :identity connection.requests.new( self.connection.reconcile_server("id" => self.identity).body["request"] ) end |
#reset_state(state) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ey-core/models/server.rb', line 88 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
100 101 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 |
# File 'lib/ey-core/models/server.rb', line 100 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" => { "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 |
#start ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/ey-core/models/server.rb', line 72 def start requires :identity connection.requests.new( self.connection.start_server("id" => self.identity).body["request"] ) end |
#stop ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/ey-core/models/server.rb', line 64 def stop requires :identity connection.requests.new( self.connection.stop_server("id" => self.identity).body["request"] ) end |