Class: Fog::Compute::Clodo::Server
- Inherits:
-
Server
show all
- Defined in:
- lib/fog/clodo/models/compute/server.rb
Instance Attribute Summary
Attributes inherited from Server
#private_key, #private_key_path, #public_key, #public_key_path, #username
Attributes inherited from Model
#collection, #connection
Instance Method Summary
collapse
Methods inherited from Server
#scp, #scp_download, #ssh_port, #sshable?
Methods inherited from Model
#inspect, #reload, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
43
44
45
46
|
# File 'lib/fog/clodo/models/compute/server.rb', line 43
def initialize(attributes={})
self.image_id ||= attributes[:vps_os] ? attributes[:vps_os] : 666
super attributes
end
|
Instance Method Details
#add_ip_address ⇒ Object
68
69
70
|
# File 'lib/fog/clodo/models/compute/server.rb', line 68
def add_ip_address
connection.add_ip_address(id)
end
|
#delete_ip_address(ip_address) ⇒ Object
76
77
78
|
# File 'lib/fog/clodo/models/compute/server.rb', line 76
def delete_ip_address(ip_address)
connection.delete_ip_address(id, ip_address)
end
|
#destroy ⇒ Object
48
49
50
51
52
|
# File 'lib/fog/clodo/models/compute/server.rb', line 48
def destroy
requires :id
connection.delete_server(id)
true
end
|
#image ⇒ Object
54
55
56
57
|
# File 'lib/fog/clodo/models/compute/server.rb', line 54
def image
requires :image_id
image_id end
|
#move_ip_address(ip_address) ⇒ Object
72
73
74
|
# File 'lib/fog/clodo/models/compute/server.rb', line 72
def move_ip_address(ip_address)
connection.move_ip_address(id, ip_address)
end
|
#password ⇒ Object
115
116
117
|
# File 'lib/fog/clodo/models/compute/server.rb', line 115
def password
vps_root_pass
end
|
#private_ip_address ⇒ Object
59
60
61
|
# File 'lib/fog/clodo/models/compute/server.rb', line 59
def private_ip_address
nil
end
|
#public_ip_address ⇒ Object
63
64
65
66
|
# File 'lib/fog/clodo/models/compute/server.rb', line 63
def public_ip_address
pubaddrs = addresses && addresses['public'] ? addresses['public'].select {|ip| ip['primary_ip']} : nil
pubaddrs && !pubaddrs.empty? ? pubaddrs.first['ip'] : nil
end
|
#ready? ⇒ Boolean
80
81
82
|
# File 'lib/fog/clodo/models/compute/server.rb', line 80
def ready?
self.state == 'is_running'
end
|
#reboot(type = 'SOFT') ⇒ Object
84
85
86
87
88
|
# File 'lib/fog/clodo/models/compute/server.rb', line 84
def reboot(type = 'SOFT')
requires :id
connection.reboot_server(id, type)
true
end
|
#save ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/fog/clodo/models/compute/server.rb', line 90
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :image_id
data = connection.create_server(image_id, attributes)
merge_attributes(data.body['server'])
true
end
|
#setup(credentials = {}) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/fog/clodo/models/compute/server.rb', line 98
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},
])
rescue Errno::ECONNREFUSED
sleep(1)
retry
end
|
#ssh(commands) ⇒ Object
111
112
113
|
# File 'lib/fog/clodo/models/compute/server.rb', line 111
def ssh(commands)
super(commands, password ? {:password => password} : {})
end
|