Class: Fog::Rackspace::Compute::Server
- Inherits:
-
Model
- Object
- Model
- Fog::Rackspace::Compute::Server
show all
- Defined in:
- lib/fog/rackspace/models/compute/server.rb
Instance Attribute Summary collapse
Attributes inherited from Model
#connection
Instance Method Summary
collapse
Methods inherited from Model
#collection, #inspect, #reload, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
24
25
26
27
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 24
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 ⇒ Object
64
65
66
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 64
def private_key
@private_key ||= File.read(private_key_path)
end
|
#private_key_path ⇒ Object
60
61
62
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 60
def private_key_path
File.expand_path(@private_key_path ||= Fog.credentials[:private_key_path])
end
|
#public_key ⇒ Object
72
73
74
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 72
def public_key
@public_key ||= File.read(public_key_path)
end
|
#public_key_path ⇒ Object
68
69
70
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 68
def public_key_path
File.expand_path(@public_key_path ||= Fog.credentials[: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
29
30
31
32
33
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 29
def destroy
requires :id
connection.delete_server(@id)
true
end
|
#flavor ⇒ Object
35
36
37
38
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 35
def flavor
requires :flavor_id
connection.flavors.get(@flavor_id)
end
|
#image ⇒ Object
40
41
42
43
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 40
def image
requires :image_id
connection.images.get(@image_id)
end
|
#images ⇒ Object
45
46
47
48
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 45
def images
requires :id
connection.images(:server => self)
end
|
#ready? ⇒ Boolean
50
51
52
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 50
def ready?
@status == 'ACTIVE'
end
|
#reboot(type = 'SOFT') ⇒ Object
54
55
56
57
58
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 54
def reboot(type = 'SOFT')
requires :id
connection.reboot_server(@id, type)
true
end
|
#save ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 76
def save
requires :flavor_id, :image_id, :name
options = {
'metadata' => @metadata,
'name' => @name,
'personality' => @personality
}
options = options.reject {|key, value| value.nil?}
data = connection.create_server(@flavor_id, @image_id, options)
merge_attributes(data.body['server'])
true
end
|
#setup(credentials = {}) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 89
def setup(credentials = {})
requires :addresses, :identity, :public_key, :username
Fog::SSH.new(addresses['public'].first, username, credentials).run([
%{mkdir .ssh},
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
%{passwd -l root},
%{echo "#{attributes.to_json}" >> ~/attributes.json},
%{echo "#{metadata.to_json}" >> ~/metadata.json}
])
rescue Errno::ECONNREFUSED
sleep(1)
retry
end
|
#ssh(commands) ⇒ Object
103
104
105
106
107
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 103
def ssh(commands)
requires :addresses, :identity, :private_key, :username
@ssh ||= Fog::SSH.new(addresses['public'].first, username, :key_data => [private_key])
@ssh.run(commands)
end
|