Class: Fog::Compute::Rackspace::Server
- Inherits:
-
Server
show all
- Defined in:
- lib/fog/rackspace/models/compute/server.rb
Instance Attribute Summary collapse
Attributes inherited from Server
#private_key, #private_key_path, #public_key, #public_key_path, #ssh_port, #username
Attributes inherited from Model
#collection, #service
Instance Method Summary
collapse
Methods inherited from Server
#scp, #scp_download, #ssh, #sshable?
Methods inherited from Model
#inspect, #reload, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#connection, #connection=, #prepare_service_value
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
23
24
25
26
27
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 23
def initialize(attributes={})
self.flavor_id ||= 1 self.image_id ||= 49 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
|
Instance Method Details
#destroy ⇒ Object
29
30
31
32
33
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 29
def destroy
requires :id
service.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
service.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
service.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
service.images(:server => self)
end
|
#private_ip_address ⇒ Object
50
51
52
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 50
def private_ip_address
addresses['private'].first
end
|
#public_ip_address ⇒ Object
54
55
56
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 54
def public_ip_address
addresses['public'].first
end
|
#ready? ⇒ Boolean
58
59
60
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 58
def ready?
self.state == 'ACTIVE'
end
|
#reboot(type = 'SOFT') ⇒ Object
62
63
64
65
66
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 62
def reboot(type = 'SOFT')
requires :id
service.reboot_server(id, type)
true
end
|
#save ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 68
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :flavor_id, :image_id
options = {
'metadata' => metadata,
'name' => name,
'personality' => personality
}
options = options.reject {|key, value| value.nil?}
data = service.create_server(flavor_id, image_id, options)
merge_attributes(data.body['server'])
true
end
|
#setup(credentials = {}) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/fog/rackspace/models/compute/server.rb', line 82
def setup(credentials = {})
requires :public_ip_address, :identity, :public_key, :username
Fog::SSH.new(public_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)}" >> ~/metadata.json}
])
rescue Errno::ECONNREFUSED
sleep(1)
retry
end
|