Class: Fog::GoGrid::Compute::Server
- Inherits:
-
Model
- Object
- Model
- Fog::GoGrid::Compute::Server
show all
- Defined in:
- lib/fog/compute/models/go_grid/server.rb
Instance Attribute Summary
Attributes inherited from Model
#collection, #connection
Instance Method Summary
collapse
Methods inherited from Model
#inspect, #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.
21
22
23
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 21
def initialize(attributes={})
super
end
|
Instance Method Details
#destroy ⇒ Object
25
26
27
28
29
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 25
def destroy
requires :id
connection.grid_server_delete(id)
true
end
|
#image ⇒ Object
31
32
33
34
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 31
def image
requires :image_id
connection.grid_image_get(:image => image_id)
end
|
#ready? ⇒ Boolean
36
37
38
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 36
def ready?
@state && @state["name"] == 'On'
end
|
#reload ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 40
def reload
requires :name
begin
if data = collection.get(name)
new_attributes = data.attributes
merge_attributes(new_attributes)
self
end
rescue Excon::Errors::BadRequest
false
end
end
|
#save ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 53
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :name, :image_id, :ip, :memory
options = {
'isSandbox' => sandbox,
'image' => image_id
}
options = options.reject {|key, value| value.nil?}
data = connection.grid_server_add(image, ip, name, memory, options)
merge_attributes(data.body)
true
end
|
#setup(credentials = {}) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 74
def setup(credentials = {})
requires :ip, :identity, :public_key, :username
Fog::SSH.new(ip['ip'], 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
66
67
68
69
70
71
72
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 66
def ssh(commands)
requires :ip, :identity, :username
options = {}
options[:key_data] = [private_key] if private_key
Fog::SSH.new(ip['ip'], username, options).run(commands)
end
|
#username ⇒ Object
88
89
90
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 88
def username
@username ||= 'root'
end
|