Class: Fog::Slicehost::Compute::Server
- Inherits:
-
Model
- Object
- Model
- Fog::Slicehost::Compute::Server
show all
- Defined in:
- lib/fog/compute/models/slicehost/server.rb
Instance Attribute Summary collapse
Attributes inherited from Model
#collection, #connection
Instance Method Summary
collapse
Methods inherited from Model
#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.
25
26
27
28
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 25
def initialize(attributes={})
self.flavor_id ||= 1
super
end
|
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
21
22
23
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 21
def password
@password
end
|
#private_key ⇒ Object
55
56
57
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 55
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
|
#private_key_path ⇒ Object
50
51
52
53
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 50
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
|
#public_key ⇒ Object
68
69
70
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 68
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
|
#public_key_path ⇒ Object
63
64
65
66
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 63
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
|
#username ⇒ Object
120
121
122
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 120
def username
@username ||= 'root'
end
|
Instance Method Details
#destroy ⇒ Object
30
31
32
33
34
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 30
def destroy
requires :id
connection.delete_slice(id)
true
end
|
#flavor ⇒ Object
36
37
38
39
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 36
def flavor
requires :flavor_id
connection.flavors.get(flavor_id)
end
|
#image ⇒ Object
41
42
43
44
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 41
def image
requires :image_id
connection.images.get(image_id)
end
|
#private_ip_address ⇒ Object
46
47
48
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 46
def private_ip_address
nil
end
|
#public_ip_address ⇒ Object
59
60
61
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 59
def public_ip_address
addresses.first
end
|
#ready? ⇒ Boolean
72
73
74
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 72
def ready?
status == 'active'
end
|
#reboot(type = 'SOFT') ⇒ Object
76
77
78
79
80
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 76
def reboot(type = 'SOFT')
requires :id
connection.reboot_slice(id, type)
true
end
|
#save ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 82
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :flavor_id, :image_id, :name
data = connection.create_slice(flavor_id, image_id, name)
merge_attributes(data.body)
true
end
|
#scp(local_path, remote_path) ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 112
def scp(local_path, remote_path)
requires :addresses, :username
options = {}
options[:key_data] = [private_key] if private_key
Fog::SCP.new(addresses.first, username, options).upload(local_path, remote_path)
end
|
#setup(credentials = {}) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 91
def setup(credentials = {})
requires :addresses, :identity, :public_key, :username
Fog::SSH.new(addresses.first, username, credentials).run([
%{mkdir .ssh},
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
%{passwd -l #{username}},
%{echo "#{attributes.to_json}" >> ~/attributes.json}
])
rescue Errno::ECONNREFUSED
sleep(1)
retry
end
|
#ssh(commands) ⇒ Object
104
105
106
107
108
109
110
|
# File 'lib/fog/compute/models/slicehost/server.rb', line 104
def ssh(commands)
requires :addresses, :identity, :username
options = {}
options[:key_data] = [private_key] if private_key
Fog::SSH.new(addresses.first, username, options).run(commands)
end
|