Class: Fog::Rackspace::Compute::Server
- Defined in:
- lib/fog/rackspace/models/compute/server.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#private_key_path ⇒ Object
Returns the value of attribute private_key_path.
-
#public_key_path ⇒ Object
Returns the value of attribute public_key_path.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from Model
Instance Method Summary collapse
- #destroy ⇒ Object
- #flavor ⇒ Object
- #image ⇒ Object
- #images ⇒ Object
-
#initialize(attributes = {}) ⇒ Server
constructor
A new instance of Server.
- #ready? ⇒ Boolean
- #reboot(type = 'SOFT') ⇒ Object
- #save ⇒ Object
- #setup(credentials = {}) ⇒ Object
- #ssh(commands) ⇒ Object
Methods inherited from Model
#collection, #inspect, #reload, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
23 24 25 26 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 23 def initialize(attributes={}) @flavor_id ||= 1 super end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
21 22 23 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 21 def password @password end |
#private_key_path ⇒ Object
Returns the value of attribute private_key_path.
21 22 23 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 21 def private_key_path @private_key_path end |
#public_key_path ⇒ Object
Returns the value of attribute public_key_path.
21 22 23 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 21 def public_key_path @public_key_path end |
#username ⇒ Object
Returns the value of attribute username.
21 22 23 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 21 def username @username end |
Instance Method Details
#destroy ⇒ Object
28 29 30 31 32 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 28 def destroy requires :id connection.delete_server(@id) true end |
#flavor ⇒ Object
34 35 36 37 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 34 def flavor requires :flavor_id connection.flavors.get(@flavor_id) end |
#image ⇒ Object
39 40 41 42 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 39 def image requires :image_id connection.images.get(@image_id) end |
#images ⇒ Object
44 45 46 47 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 44 def images requires :id connection.images(:server => self) end |
#ready? ⇒ Boolean
49 50 51 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 49 def ready? @status == 'ACTIVE' end |
#reboot(type = 'SOFT') ⇒ Object
53 54 55 56 57 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 53 def reboot(type = 'SOFT') requires :id connection.reboot_server(@id, type) true end |
#save ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fog/rackspace/models/compute/server.rb', line 67 def save requires :flavor_id, :image_id, :name = { 'metadata' => @metadata, 'name' => @name, 'personality' => @personality } = .reject {|key, value| value.nil?} data = connection.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 :addresses, :identity, :public_key_path, :username Fog::SSH.new(addresses['public'].first, username, credentials).run([ %{mkdir .ssh}, %{echo "#{File.read(File.(public_key_path))}" >> ~/.ssh/authorized_keys}, %{passwd -l root}, %{echo "#{attributes.to_json}" >> ~/attributes.json}, %{echo "#{.to_json}" >> ~/metadata.json} ]) rescue Errno::ECONNREFUSED sleep(1) retry end |