Class: Fog::Compute::Rackspace::Server
- Inherits:
-
Server
- Object
- Server
- Fog::Compute::Rackspace::Server
- Defined in:
- lib/fog/rackspace/models/compute/server.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
Instance Method Summary collapse
- #destroy ⇒ Object
- #flavor ⇒ Object
- #image ⇒ Object
- #images ⇒ Object
-
#initialize(attributes = {}) ⇒ Server
constructor
A new instance of Server.
- #private_ip_address ⇒ Object
- #public_ip_address ⇒ Object
- #ready? ⇒ Boolean
- #reboot(type = 'SOFT') ⇒ Object
- #save(options = {}) ⇒ Object
- #setup(credentials = {}) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
21 22 23 24 25 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 21 def initialize(attributes={}) self.flavor_id ||= 1 # 256 server self.image_id ||= 49 # Ubuntu 10.04 LTS 64bit super end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
19 20 21 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 19 def password @password end |
Instance Method Details
#destroy ⇒ Object
27 28 29 30 31 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 27 def destroy requires :id service.delete_server(id) true end |
#flavor ⇒ Object
33 34 35 36 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 33 def flavor requires :flavor_id service.flavors.get(flavor_id) end |
#image ⇒ Object
38 39 40 41 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 38 def image requires :image_id service.images.get(image_id) end |
#images ⇒ Object
43 44 45 46 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 43 def images requires :id service.images(:server => self) end |
#private_ip_address ⇒ Object
48 49 50 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 48 def private_ip_address addresses['private'].first end |
#public_ip_address ⇒ Object
52 53 54 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 52 def public_ip_address addresses['public'].first end |
#ready? ⇒ Boolean
56 57 58 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 56 def ready? self.state == 'ACTIVE' end |
#reboot(type = 'SOFT') ⇒ Object
60 61 62 63 64 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 60 def reboot(type = 'SOFT') requires :id service.reboot_server(id, type) true end |
#save(options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 66 def save( = {}) raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? requires :flavor_id, :image_id = { 'metadata' => , 'name' => name, 'personality' => personality } = .reject {|key, value| value.nil?} data = service.create_server(flavor_id, image_id, ) merge_attributes(data.body['server']) true end |
#setup(credentials = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 80 def setup(credentials = {}) requires :ssh_ip_address, :identity, :public_key, :username Fog::SSH.new(ssh_ip_address, username, credentials).run([ %{mkdir .ssh}, %{echo "#{public_key}" >> ~/.ssh/authorized_keys}, %{passwd -l #{username}}, %{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json}, %{echo "#{Fog::JSON.encode()}" >> ~/metadata.json} ]) rescue Errno::ECONNREFUSED sleep(1) retry end |