Class: Fog::Compute::CloudSigma::Server
Instance Attribute Summary
Attributes inherited from Model
#collection, #service
Instance Method Summary
collapse
-
#add_nic(vlan = nil, ip_v4_conf = nil, ip_v6_conf = nil, model = 'virtio', boot_order = nil) ⇒ Object
-
#add_private_nic(vlan, model = 'virtio', boot_order = nil) ⇒ Object
-
#add_public_nic(ip_or_conf = :dhcp, model = 'virtio', boot_order = nil) ⇒ Object
-
#clone(clone_params = {}) ⇒ Object
-
#close_vnc ⇒ Object
-
#create ⇒ Object
-
#destroy ⇒ Object
(also: #delete)
-
#mount_volume(volume, device = 'virtio', dev_channel = nil, boot_order = nil) ⇒ Object
-
#open_vnc ⇒ Object
-
#remove_all_nics ⇒ Object
-
#remove_nic(mac_or_position) ⇒ Object
-
#save ⇒ Object
-
#start(start_params = {}) ⇒ Object
-
#stop ⇒ Object
-
#unmount_all_volumes ⇒ Object
-
#unmount_volume(volume_or_position) ⇒ Object
-
#update ⇒ Object
model_attribute, model_attribute_array
Methods inherited from Model
#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#connection, #connection=, #prepare_service_value
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Model
Instance Method Details
#add_nic(vlan = nil, ip_v4_conf = nil, ip_v6_conf = nil, model = 'virtio', boot_order = nil) ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/fog/cloudsigma/models/server.rb', line 161
def add_nic(vlan=nil, ip_v4_conf=nil, ip_v6_conf=nil, model='virtio', boot_order=nil)
nic_data = {
'model' => model,
'vlan' => vlan,
'ip_v4_conf' => ip_v4_conf,
'ip_v6_conf' => ip_v6_conf
}
if boot_order
nic_data['boot_order'] = boot_order
end
self.nics = self.nics << Nic.new(nic_data)
end
|
#add_private_nic(vlan, model = 'virtio', boot_order = nil) ⇒ Object
187
188
189
190
|
# File 'lib/fog/cloudsigma/models/server.rb', line 187
def add_private_nic(vlan, model='virtio', boot_order=nil)
vlan = vlan.kind_of?(String) ? vlan : vlan.identity
add_nic(vlan, nil, nil, model, boot_order)
end
|
#add_public_nic(ip_or_conf = :dhcp, model = 'virtio', boot_order = nil) ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/fog/cloudsigma/models/server.rb', line 175
def add_public_nic(ip_or_conf=:dhcp, model='virtio', boot_order=nil)
case ip_or_conf
when :dhcp
add_nic(nil, {:conf => :dhcp}, nil, model, boot_order)
when :manual
add_nic(nil, {:conf => :manual}, nil, model, boot_order)
else
ip = ip_or_conf.kind_of?(String) ? ip_or_conf : ip_or_conf.identity
add_nic(nil, {:conf => :static, :ip => ip}, nil, model, boot_order)
end
end
|
#clone(clone_params = {}) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/fog/cloudsigma/models/server.rb', line 89
def clone(clone_params={})
requires :identity
response = service.clone_server(identity, clone_params)
self.class.new(response.body)
end
|
#close_vnc ⇒ Object
84
85
86
87
|
# File 'lib/fog/cloudsigma/models/server.rb', line 84
def close_vnc
requires :identity
service.close_vnc(identity)
end
|
#create ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/fog/cloudsigma/models/server.rb', line 40
def create
requires :name, :cpu, :mem, :vnc_password
data = attributes
response = service.create_server(data)
new_attributes = response.body['objects'].first
merge_attributes(new_attributes)
end
|
#destroy ⇒ Object
Also known as:
delete
60
61
62
63
64
65
|
# File 'lib/fog/cloudsigma/models/server.rb', line 60
def destroy
requires :identity
service.delete_server(identity)
true
end
|
#mount_volume(volume, device = 'virtio', dev_channel = nil, boot_order = nil) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/fog/cloudsigma/models/server.rb', line 96
def mount_volume(volume, device = 'virtio', dev_channel = nil, boot_order = nil)
unless dev_channel
specified_channels = self.volumes.map { |v| v.dev_channel }.sort
if specified_channels
controller, controller_channel = 0, 0
max_ctlr, max_chnl = case device
when 'ide'
[4, 2]
else
[1024, 5]
end
dev_channel = "#{controller}:#{controller_channel}"
while specified_channels.include? dev_channel
controller_channel += 1
if controller_channel >= max_chnl
controller_channel = 0
controller += 1
if controller >= max_ctlr
raise Fog::CloudSigma::Errors::Error.new("Max channel reached, cannot attach more")
end
end
dev_channel = "#{controller}:#{controller_channel}"
end
else dev_channel = '0:0'
end
end
vol_id = volume.kind_of?(String) ? volume : volume.identity
mountpoint_data = {
'drive' => vol_id,
'device' => device,
'dev_channel' => dev_channel,
}
if boot_order
mountpoint_data['boot_order'] = boot_order
end
self.volumes = self.volumes << MountPoint.new(mountpoint_data)
end
|
#open_vnc ⇒ Object
79
80
81
82
|
# File 'lib/fog/cloudsigma/models/server.rb', line 79
def open_vnc
requires :identity
service.open_vnc(identity)
end
|
#remove_all_nics ⇒ Object
202
203
204
|
# File 'lib/fog/cloudsigma/models/server.rb', line 202
def remove_all_nics
self.nics = []
end
|
#remove_nic(mac_or_position) ⇒ Object
192
193
194
195
196
197
198
199
200
|
# File 'lib/fog/cloudsigma/models/server.rb', line 192
def remove_nic(mac_or_position)
if mac_or_position.kind_of? Fixnum
self.nics.delete_at(mac_or_position)
return self.nics = self.nics
end
self.nics = self.nics.reject { |n| n.mac == mac_or_position }
end
|
#save ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/fog/cloudsigma/models/server.rb', line 32
def save
if persisted?
update
else
create
end
end
|
#start(start_params = {}) ⇒ Object
69
70
71
72
|
# File 'lib/fog/cloudsigma/models/server.rb', line 69
def start(start_params={})
requires :identity
service.start_server(identity, start_params)
end
|
#stop ⇒ Object
74
75
76
77
|
# File 'lib/fog/cloudsigma/models/server.rb', line 74
def stop
requires :identity
service.stop_server(identity)
end
|
#unmount_all_volumes ⇒ Object
157
158
159
|
# File 'lib/fog/cloudsigma/models/server.rb', line 157
def unmount_all_volumes
self.volumes = []
end
|
#unmount_volume(volume_or_position) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/fog/cloudsigma/models/server.rb', line 140
def unmount_volume(volume_or_position)
if volume_or_position.kind_of? Fixnum
self.volumes.delete_at(volume_or_position)
return self.volumes = self.volumes
end
vol_id = volume_or_position.kind_of?(String) ? volume_or_position : volume_or_position.identity
self.volumes = self.volumes.reject do |v|
if v.volume.kind_of? Hash
v.volume['uuid'] == vol_id
else
v.volume == vol_id
end
end
end
|
#update ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/fog/cloudsigma/models/server.rb', line 49
def update
requires :identity, :name, :cpu, :mem, :vnc_password
data = attributes
response = service.update_server(identity, data)
new_attributes = response.body
merge_attributes(new_attributes)
end
|