Class: Fog::Compute::HP::Server
- Inherits:
-
Server
show all
- Defined in:
- lib/fog/hp/models/compute/server.rb
Instance Attribute Summary collapse
Attributes inherited from Model
#collection, #connection
Instance Method Summary
collapse
Methods inherited from Server
#scp, #scp_download, #ssh, #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.
36
37
38
39
40
41
42
|
# File 'lib/fog/hp/models/compute/server.rb', line 36
def initialize(attributes = {})
self.security_groups = attributes.delete(:security_groups)
self.min_count = attributes.delete(:min_count)
self.max_count = attributes.delete(:max_count)
super
end
|
Instance Attribute Details
#flavor_id ⇒ Object
112
113
114
|
# File 'lib/fog/hp/models/compute/server.rb', line 112
def flavor_id
@flavor_id ||= (flavor.nil? ? nil : flavor["id"])
end
|
#image_id ⇒ Object
104
105
106
|
# File 'lib/fog/hp/models/compute/server.rb', line 104
def image_id
@image_id ||= (image.nil? ? nil : image["id"])
end
|
#password ⇒ Object
Returns the value of attribute password.
33
34
35
|
# File 'lib/fog/hp/models/compute/server.rb', line 33
def password
@password
end
|
#private_key ⇒ Object
75
76
77
|
# File 'lib/fog/hp/models/compute/server.rb', line 75
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
|
#private_key_path ⇒ Object
70
71
72
73
|
# File 'lib/fog/hp/models/compute/server.rb', line 70
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
100
101
102
|
# File 'lib/fog/hp/models/compute/server.rb', line 100
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
|
#public_key_path ⇒ Object
95
96
97
98
|
# File 'lib/fog/hp/models/compute/server.rb', line 95
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
|
#username ⇒ Object
214
215
216
|
# File 'lib/fog/hp/models/compute/server.rb', line 214
def username
@username ||= 'root'
end
|
Instance Method Details
#change_password(admin_password) ⇒ Object
140
141
142
143
144
|
# File 'lib/fog/hp/models/compute/server.rb', line 140
def change_password(admin_password)
requires :id
connection.change_password_server(id, admin_password)
true
end
|
#confirm_resize ⇒ Object
170
171
172
173
174
|
# File 'lib/fog/hp/models/compute/server.rb', line 170
def confirm_resize
requires :id
connection.confirm_resized_server(id)
true
end
|
#create_image(name, metadata = {}) ⇒ Object
176
177
178
179
|
# File 'lib/fog/hp/models/compute/server.rb', line 176
def create_image(name, metadata={})
requires :id
connection.create_image(id, name, metadata)
end
|
#destroy ⇒ Object
44
45
46
47
48
|
# File 'lib/fog/hp/models/compute/server.rb', line 44
def destroy
requires :id
connection.delete_server(id)
true
end
|
#images ⇒ Object
50
51
52
53
|
# File 'lib/fog/hp/models/compute/server.rb', line 50
def images
requires :id
connection.images(:server => self)
end
|
#key_pair ⇒ Object
55
56
57
58
59
|
# File 'lib/fog/hp/models/compute/server.rb', line 55
def key_pair
requires :key_name
connection.key_pairs.get(key_name)
end
|
#key_pair=(new_keypair) ⇒ Object
61
62
63
|
# File 'lib/fog/hp/models/compute/server.rb', line 61
def key_pair=(new_keypair)
self.key_name = new_keypair && new_keypair.name
end
|
#max_count=(new_max_count) ⇒ Object
124
125
126
|
# File 'lib/fog/hp/models/compute/server.rb', line 124
def max_count=(new_max_count)
@max_count = new_max_count
end
|
#min_count=(new_min_count) ⇒ Object
120
121
122
|
# File 'lib/fog/hp/models/compute/server.rb', line 120
def min_count=(new_min_count)
@min_count = new_min_count
end
|
#private_ip_address ⇒ Object
65
66
67
68
|
# File 'lib/fog/hp/models/compute/server.rb', line 65
def private_ip_address
addr = addresses.nil? ? nil : addresses.fetch('private', []).first
addr["addr"] if addr
end
|
#public_ip_address ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/fog/hp/models/compute/server.rb', line 79
def public_ip_address
if !addresses.nil?
addr = addresses.fetch('private', [])
if addr.count > 1
addr[1]["addr"]
else
nil
end
else
nil
end
end
|
#ready? ⇒ Boolean
136
137
138
|
# File 'lib/fog/hp/models/compute/server.rb', line 136
def ready?
self.state == 'ACTIVE'
end
|
#reboot(type = 'SOFT') ⇒ Object
146
147
148
149
150
|
# File 'lib/fog/hp/models/compute/server.rb', line 146
def reboot(type = 'SOFT')
requires :id
connection.reboot_server(id, type)
true
end
|
#rebuild(image_id, name, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object
152
153
154
155
156
|
# File 'lib/fog/hp/models/compute/server.rb', line 152
def rebuild(image_id, name, admin_pass=nil, metadata=nil, personality=nil)
requires :id
connection.rebuild_server(id, image_id, name, admin_pass, metadata, personality)
true
end
|
#resize(flavor_id) ⇒ Object
158
159
160
161
162
|
# File 'lib/fog/hp/models/compute/server.rb', line 158
def resize(flavor_id)
requires :id
connection.resize_server(id, flavor_id)
true
end
|
#revert_resize ⇒ Object
164
165
166
167
168
|
# File 'lib/fog/hp/models/compute/server.rb', line 164
def revert_resize
requires :id
connection.revert_resized_server(id)
true
end
|
#save ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/fog/hp/models/compute/server.rb', line 181
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :flavor_id, :image_id, :name
options = {
'metadata' => metadata,
'personality' => personality,
'accessIPv4' => accessIPv4,
'accessIPv6' => accessIPv6,
'min_count' => @min_count,
'max_count' => @max_count,
'key_name' => key_name,
'security_groups' => @security_groups
}
options = options.reject {|key, value| value.nil?}
data = connection.create_server(name, flavor_id, image_id, options)
merge_attributes(data.body['server'])
true
end
|
#security_groups ⇒ Object
132
133
134
|
# File 'lib/fog/hp/models/compute/server.rb', line 132
def security_groups
@security_groups
end
|
#security_groups=(new_security_groups) ⇒ Object
128
129
130
|
# File 'lib/fog/hp/models/compute/server.rb', line 128
def security_groups=(new_security_groups)
@security_groups = new_security_groups
end
|
#setup(credentials = {}) ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/fog/hp/models/compute/server.rb', line 200
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
|