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.
42 43 44 |
# File 'lib/ey-core/models/server.rb', line 42 def force @force end |
#iops ⇒ Object
Returns the value of attribute iops.
42 43 44 |
# File 'lib/ey-core/models/server.rb', line 42 def iops @iops end |
#mnt_volume_size ⇒ Object
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_id ⇒ Object
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_size ⇒ Object
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_log ⇒ Object
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_log ⇒ Object
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 |
#reboot ⇒ Object
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 |
#reconcile ⇒ Object
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 |
#start ⇒ Object
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 |
#stop ⇒ Object
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 |