Class: Fog::Compute::GoGrid::Server
Instance Attribute Summary
Attributes inherited from Model
#collection, #connection
Instance Method Summary
collapse
deprecate, self_deprecate
Methods inherited from Model
#inspect, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#_dump, #attributes, #dup, #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/compute/models/go_grid/server.rb', line 23
def initialize(attributes={})
image_id ||= 'ubuntu_10_04_LTS_64_base' super
end
|
Instance Method Details
#destroy ⇒ Object
28
29
30
31
32
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 28
def destroy
requires :id
connection.grid_server_delete(id)
true
end
|
#image ⇒ Object
34
35
36
37
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 34
def image
requires :image_id
connection.grid_image_get(:image => image_id)
end
|
#private_ip_address ⇒ Object
39
40
41
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 39
def private_ip_address
nil
end
|
#ready? ⇒ Boolean
43
44
45
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 43
def ready?
@state && @state["name"] == 'On'
end
|
#reload ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 47
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
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 60
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :name, :image_id, :memory, :public_ip_address
options = {
'isSandbox' => sandbox,
'image' => image_id
}
options = options.reject {|key, value| value.nil?}
data = connection.grid_server_add(image, public_ip_address, name, memory, options)
merge_attributes(data.body)
true
end
|
#scp(local_path, remote_path, upload_options = {}) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 81
def scp(local_path, remote_path, upload_options = {})
requires :public_ip_address, :username
scp_options = {}
scp_options[:key_data] = [private_key] if private_key
Fog::SCP.new(public_ip_address, username, scp_options).upload(local_path, remote_path, upload_options)
end
|
#setup(credentials = {}) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 89
def setup(credentials = {})
requires :identity, :public_ip_address, :public_key, :username
Fog::SSH.new(public_ip_address, 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
73
74
75
76
77
78
79
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 73
def ssh(commands)
requires :identity, :public_ip_address, :username
options = {}
options[:key_data] = [private_key] if private_key
Fog::SSH.new(public_ip_address, username, options).run(commands)
end
|
#username ⇒ Object
103
104
105
|
# File 'lib/fog/compute/models/go_grid/server.rb', line 103
def username
@username ||= 'root'
end
|