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!(skip_snapshot = "false") ⇒ 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.
41 42 43 |
# File 'lib/ey-core/models/server.rb', line 41 def force @force end |
#iops ⇒ Object
Returns the value of attribute iops.
41 42 43 |
# File 'lib/ey-core/models/server.rb', line 41 def iops @iops end |
#mnt_volume_size ⇒ Object
Returns the value of attribute mnt_volume_size.
41 42 43 |
# File 'lib/ey-core/models/server.rb', line 41 def mnt_volume_size @mnt_volume_size end |
#snapshot_id ⇒ Object
Returns the value of attribute snapshot_id.
41 42 43 |
# File 'lib/ey-core/models/server.rb', line 41 def snapshot_id @snapshot_id end |
#volume_size ⇒ Object
Returns the value of attribute volume_size.
41 42 43 |
# File 'lib/ey-core/models/server.rb', line 41 def volume_size @volume_size end |
Instance Method Details
#apply(type = "main") ⇒ Object
43 44 45 46 47 |
# File 'lib/ey-core/models/server.rb', line 43 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
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ey-core/models/server.rb', line 134 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_log ⇒ Object
53 54 55 |
# File 'lib/ey-core/models/server.rb', line 53 def latest_custom_log logs.select{|l| l.filename.match(/custom/)}.sort_by(&:created_at).last end |
#latest_main_log ⇒ Object
49 50 51 |
# File 'lib/ey-core/models/server.rb', line 49 def latest_main_log logs.select{|l| l.filename.match(/main/)}.sort_by(&:created_at).last end |
#reboot ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/ey-core/models/server.rb', line 57 def reboot requires :identity connection.requests.new( self.connection.reboot_server("id" => self.identity).body["request"] ) end |
#reconcile ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/ey-core/models/server.rb', line 81 def reconcile requires :identity connection.requests.new( self.connection.reconcile_server("id" => self.identity).body["request"] ) end |
#reset_state(state) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ey-core/models/server.rb', line 89 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
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 131 132 |
# File 'lib/ey-core/models/server.rb', line 101 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, } } 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
73 74 75 76 77 78 79 |
# File 'lib/ey-core/models/server.rb', line 73 def start requires :identity connection.requests.new( self.connection.start_server("id" => self.identity).body["request"] ) end |
#stop ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/ey-core/models/server.rb', line 65 def stop requires :identity connection.requests.new( self.connection.stop_server("id" => self.identity).body["request"] ) end |