Class: Fog::Brightbox::Compute::Server
- Inherits:
-
Compute::Server
- Object
- Compute::Server
- Fog::Brightbox::Compute::Server
show all
- Includes:
- ResourceLocking, ModelHelper
- Defined in:
- lib/fog/brightbox/models/compute/server.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#lock!, #locked?, #unlock!
#collection_name, #resource_name
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
47
48
49
50
51
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 47
def initialize(attributes = {})
super
self.image_id ||= service.default_image
end
|
Instance Attribute Details
#volume_id ⇒ Object
Returns the value of attribute volume_id.
10
11
12
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 10
def volume_id
@volume_id
end
|
Instance Method Details
#activate_console ⇒ Object
177
178
179
180
181
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 177
def activate_console
requires :identity
response = service.activate_console_server(identity)
[response["console_url"], response["console_token"], response["console_token_expires"]]
end
|
#destroy ⇒ Object
133
134
135
136
137
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 133
def destroy
requires :identity
service.delete_server(identity)
true
end
|
#dns_name ⇒ String
Returns the public DNS name of the server
153
154
155
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 153
def dns_name
["public", fqdn].join(".")
end
|
#flavor ⇒ Object
139
140
141
142
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 139
def flavor
requires :flavor_id
service.flavors.get(flavor_id)
end
|
#flavor_id ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 61
def flavor_id
if t_flavour_id = attributes[:flavor_id]
t_flavour_id
elsif server_type
server_type[:id] || server_type["id"]
end
end
|
#flavor_id=(incoming_flavour_id) ⇒ Object
73
74
75
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 73
def flavor_id=(incoming_flavour_id)
attributes[:flavor_id] = incoming_flavour_id
end
|
#image ⇒ Object
144
145
146
147
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 144
def image
requires :image_id
service.images.get(image_id)
end
|
#mapping_identity ⇒ String
Replaces the server’s identifier with it’s interface’s identifier for Cloud IP mapping
211
212
213
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 211
def mapping_identity
interfaces.first["id"]
end
|
#private_ip_address ⇒ Object
157
158
159
160
161
162
163
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 157
def private_ip_address
if interfaces.empty?
nil
else
interfaces.first["ipv4_address"]
end
end
|
#public_ip_address ⇒ Object
165
166
167
168
169
170
171
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 165
def public_ip_address
if cloud_ips.empty?
nil
else
cloud_ips.first["public_ip"]
end
end
|
#ready? ⇒ Boolean
173
174
175
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 173
def ready?
state == "active"
end
|
#reboot(use_hard_reboot = true) ⇒ Boolean
Issues a hard reset to the server (or an OS level reboot command)
Default behaviour is a hard reboot because it is more reliable because the state of the server’s OS is irrelevant.
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 101
def reboot(use_hard_reboot = true)
requires :identity
if ready?
if use_hard_reboot
service.reset_server(identity)
else
service.reboot_server(identity)
end
else
false
end
end
|
#save ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 183
def save
raise Fog::Errors::Error.new("Resaving an existing object may create a duplicate") if persisted?
requires :image_id
options = {
:name => name,
:zone => zone_id,
:user_data => user_data,
:server_groups => server_groups
}.delete_if { |_k, v| v.nil? || v == "" }
options.merge!(:server_type => flavor_id) unless flavor_id.nil? || flavor_id == ""
options.merge!(:cloud_ip => cloud_ip) unless cloud_ip.nil? || cloud_ip == ""
options.merge!(:disk_encrypted => disk_encrypted) if disk_encrypted
if volume_id
options.merge!(:volumes => [:volume => volume_id])
else
options.merge!(:image => image_id)
end
data = service.create_server(options)
merge_attributes(data)
true
end
|
#shutdown ⇒ Object
127
128
129
130
131
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 127
def shutdown
requires :identity
service.shutdown_server(identity)
true
end
|
#snapshot(return_snapshot = false) ⇒ Object
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 77
def snapshot(return_snapshot = false)
requires :identity
response, snapshot_id = service.snapshot_server(identity, :return_link => return_snapshot)
if return_snapshot
service.images.get(snapshot_id)
else
response
end
end
|
#start ⇒ Object
115
116
117
118
119
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 115
def start
requires :identity
service.start_server(identity)
true
end
|
#stop ⇒ Object
121
122
123
124
125
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 121
def stop
requires :identity
service.stop_server(identity)
true
end
|
#zone_id ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 53
def zone_id
if t_zone_id = attributes[:zone_id]
t_zone_id
elsif zone
zone[:id] || zone["id"]
end
end
|
#zone_id=(incoming_zone_id) ⇒ Object
69
70
71
|
# File 'lib/fog/brightbox/models/compute/server.rb', line 69
def zone_id=(incoming_zone_id)
attributes[:zone_id] = incoming_zone_id
end
|