saklient 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea3d7d1ce2e74631267fa33bef7aea4976c5e100
4
- data.tar.gz: 884896e9ea1cf5a42fd6e593977253d4c13abca0
3
+ metadata.gz: 888caa1a7e16911a83fc233a258817fe3fd23bf7
4
+ data.tar.gz: 9886629e6022f3c4a8ea5313fec7039e2f65999c
5
5
  SHA512:
6
- metadata.gz: e85eb5d462b07c79246dec157a0c350df22175c3239f541ef8fa597393afa0f400d708fddf4d18f7eb1534b030a3e1edb4aae3e9c6efde7f480d39bcd4acaec7
7
- data.tar.gz: 0d1877f0c22d22d7c9cecbb570fda2c8c59e0c16da9230d25dd4f4f8b48c71b8d647b090e5d676c480fdc8692dabbaffd0b6bc58dde0a828b7849dc0347a763c
6
+ metadata.gz: 59cd3006140c4e5c9afa72f6d8c287ede4c20eebf3f99925801ad6ab1623bc9e71dc01d988eab0691c6575b4bebbafbd28e04dbf491d444765c83a38a7092d73
7
+ data.tar.gz: dd0b47152232d3caae9e29aaa3cbe4043be34b6257851e9cc60fc897c03ba3fa0ce639bca43a2096000954b4e993803cc6466eaa680bd02c895ef62640bafa88
@@ -78,7 +78,7 @@ module Saklient
78
78
 
79
79
  extra_headers = {
80
80
  'Content-Type' => 'application/x-www-form-urlencoded',
81
- 'User-Agent' => 'saklient.ruby ver-0.0.7 rev-bab628f6f4c2a9d37b38c634b4a514cb66467939',
81
+ 'User-Agent' => 'saklient.ruby ver-0.0.8 rev-bab628f6f4c2a9d37b38c634b4a514cb66467939',
82
82
  'X-Requested-With' => 'XMLHttpRequest',
83
83
  'X-Sakura-HTTP-Method' => method,
84
84
  'X-Sakura-Error-Level' => 'warning',
@@ -167,6 +167,7 @@ module Saklient
167
167
  # ディスクのコピー中は待機し, 完了してからreturnします.
168
168
  #
169
169
  # 共有セグメントに接続されている場合はAPIによって自動的に割り当てられるため, 省略またはnullを指定してください.
170
+ # 文字列 "skip" を指定すると, ディスク修正処理をスキップします.
170
171
  # trueを指定した場合は, 複製元の現在のディスク#1から直接クローンします.
171
172
  # 省略またはnullを指定した場合は, 複製元のディスク#1が作成された時のコピー元リソースから再度クローンを試みます.
172
173
  # 既に削除されている場合は, 複製元の現在のディスク#1からの直接クローンにフォールバックします.
@@ -188,6 +189,8 @@ module Saklient
188
189
  server = Saklient::Cloud::Resources::Server.new(@_client, nil)
189
190
  names = []
190
191
  hostNames = []
192
+ skipConfig = userIpAddress == 'skip'
193
+ userIpAddress = nil if skipConfig
191
194
  if (name).nil? || (hostName).nil?
192
195
  model = Saklient::Util::create_class_instance('saklient.cloud.models.Model_Server', [@_client])
193
196
  servers = model.limit(0).find
@@ -209,31 +212,38 @@ module Saklient
209
212
  if 0 < self.ifaces.length
210
213
  iface = self.ifaces[0]
211
214
  iface.reload
212
- if (iface.ip_address).nil?
213
- raise Saklient::Errors::SaklientException.new('invalid_data', 'Setting an IP address to the disconnected interface is not allowed') if (userIpAddress).nil? && (iface.swytch_id).nil?
214
- else
215
- raise Saklient::Errors::SaklientException.new('invalid_data', 'Setting an IP address to the interface connected to a shared segment is not allowed') if !(userIpAddress).nil?
215
+ if !(userIpAddress).nil?
216
+ if (iface.ip_address).nil?
217
+ raise Saklient::Errors::SaklientException.new('invalid_data', 'Setting an IP address to the disconnected interface is not allowed') if (iface.swytch_id).nil?
218
+ else
219
+ raise Saklient::Errors::SaklientException.new('invalid_data', 'Setting an IP address to the interface connected to a shared segment is not allowed')
220
+ end
216
221
  end
217
222
  end
218
223
  srcDisks = find_disks
219
224
  if 0 < srcDisks.length
220
- direct = Saklient::Util::are_same(diskSource, true)
221
- if (diskSource).nil? || direct
222
- diskSource = srcDisks[0].source
223
- if !direct
224
- if diskSource.is_a?(Saklient::Cloud::Resources::Archive)
225
- begin
226
- diskSource.reload
227
- rescue Saklient::Errors::HttpNotFoundException
228
- diskSource = srcDisks[0]
229
- end
225
+ if Saklient::Util::are_same(diskSource, true)
226
+ diskSource = srcDisks[0]
227
+ else
228
+ if (diskSource).nil?
229
+ diskSource = srcDisks[0].source
230
+ if (diskSource).nil?
231
+ diskSource = srcDisks[0]
230
232
  else
231
- if diskSource.is_a?(Saklient::Cloud::Resources::Disk)
233
+ if diskSource.is_a?(Saklient::Cloud::Resources::Archive)
232
234
  begin
233
235
  diskSource.reload
234
236
  rescue Saklient::Errors::HttpNotFoundException
235
237
  diskSource = srcDisks[0]
236
238
  end
239
+ else
240
+ if diskSource.is_a?(Saklient::Cloud::Resources::Disk)
241
+ begin
242
+ diskSource.reload
243
+ rescue Saklient::Errors::HttpNotFoundException
244
+ diskSource = srcDisks[0]
245
+ end
246
+ end
237
247
  end
238
248
  end
239
249
  end
@@ -281,21 +291,23 @@ module Saklient
281
291
  end
282
292
  if !(disk).nil?
283
293
  disk.sleep_while_copying
284
- diskconf = disk.create_config
285
- diskconf.host_name = hostName
286
- diskconf.ssh_key = sshKey
287
- diskconf.ip_address = userIpAddress
288
- if !(userSwytch).nil?
289
- if 0 < userSwytch.ipv4_nets.length
290
- net = userSwytch.ipv4_nets[0]
291
- diskconf.default_route = net.default_route
292
- diskconf.network_mask_len = net.mask_len
293
- else
294
- diskconf.default_route = userSwytch.user_default_route
295
- diskconf.network_mask_len = userSwytch.user_mask_len
294
+ if !skipConfig
295
+ diskconf = disk.create_config
296
+ diskconf.host_name = hostName
297
+ diskconf.ssh_key = sshKey
298
+ diskconf.ip_address = userIpAddress
299
+ if !(userSwytch).nil?
300
+ if 0 < userSwytch.ipv4_nets.length
301
+ net = userSwytch.ipv4_nets[0]
302
+ diskconf.default_route = net.default_route
303
+ diskconf.network_mask_len = net.mask_len
304
+ else
305
+ diskconf.default_route = userSwytch.user_default_route
306
+ diskconf.network_mask_len = userSwytch.user_mask_len
307
+ end
296
308
  end
309
+ diskconf.write
297
310
  end
298
- diskconf.write
299
311
  end
300
312
  server.reload
301
313
  return server
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: UTF-8 -*-
2
2
 
3
3
  module Saklient
4
- VERSION = "0.0.7"
4
+ VERSION = "0.0.8"
5
5
  end
data/spec/server_spec.rb CHANGED
@@ -3,13 +3,15 @@ require 'saklient/cloud/api'
3
3
  require 'date'
4
4
  require 'SecureRandom'
5
5
 
6
+ SKIPS_SERVER_BOOT = true
6
7
  TESTS_EASY_DUPLICATE = true
7
8
  TESTS_DISK_EXPANSION = false
8
9
 
9
10
  BREAKS_AFTER_SERVER_UP = false
10
11
  BREAKS_AFTER_EASY_DUPLICATE = true
11
12
 
12
- USE_READYMADE_SERVER_ID = 112800244655 # For TESTS_EASY_DUPLICATE
13
+ USE_READYMADE_SERVER_ID = nil # 112800244655 # For TESTS_EASY_DUPLICATE
14
+ CREATES_EMPTY_DISK = true
13
15
 
14
16
 
15
17
 
@@ -77,7 +79,7 @@ describe 'Server' do
77
79
 
78
80
 
79
81
  it 'should be CRUDed' do
80
- name = '!ruby_rspec-' + DateTime.now.strftime('%Y%m%d_%H%M%S') + '-' + SecureRandom.uuid[0, 8]
82
+ name = '!ruby_rspec-' + DateTime.now.strftime('%Y%m%d_%H%M%S') + '-' + SecureRandom.uuid[0, 8] + "-001"
81
83
  description = 'This instance was created by saklient.ruby rspec'
82
84
  tag = 'saklient-test'
83
85
  cpu = 1
@@ -134,7 +136,11 @@ describe 'Server' do
134
136
  disk.description = 'This instance was created by saklient.ruby rspec'
135
137
  disk.tags = ['saklient-test']
136
138
  disk.plan = @api.product.disk.ssd
137
- disk.source = archive
139
+ if CREATES_EMPTY_DISK
140
+ disk.size_gib = archive.size_gib
141
+ else
142
+ disk.source = archive
143
+ end
138
144
  disk.save
139
145
  # p disk.dump
140
146
 
@@ -182,8 +188,10 @@ describe 'Server' do
182
188
  # p disk.dump
183
189
  disk.source = nil
184
190
  disk.reload
185
- expect(disk.source).to be_an_instance_of Saklient::Cloud::Resources::Archive
186
- expect(disk.source.id).to eq archive.id
191
+ unless CREATES_EMPTY_DISK
192
+ expect(disk.source).to be_an_instance_of Saklient::Cloud::Resources::Archive
193
+ expect(disk.source.id).to eq archive.id
194
+ end
187
195
  expect(disk.size_gib).to eq archive.size_gib
188
196
 
189
197
  # connect the disk to the server
@@ -196,91 +204,106 @@ describe 'Server' do
196
204
  expect(ip_address).not_to be_empty
197
205
 
198
206
  # config the disk
199
- puts 'writing configuration to the disk...'
200
- diskconf = disk.create_config
201
- diskconf.host_name = 'saklient-test'
202
- diskconf.password = password
203
- diskconf.ssh_key = ssh_public_key
204
- diskconf.ssh_keys.unshift(additional_ssh_public_key) if !additional_ssh_public_key.empty?
205
- diskconf.scripts.push(script)
206
- diskconf.write
207
-
208
- # boot
209
- puts 'booting the server...'
210
- server.boot
211
- sleep 3
212
- server.reload
213
- expect(server.instance.status).to eq Saklient::Cloud::Enums::EServerInstanceStatus::up
214
-
215
- # boot conflict
216
- puts 'checking the server power conflicts...'
217
- ok = false
218
- begin
219
- server.boot
220
- rescue Saklient::Errors::HttpConflictException
221
- ok = true
207
+ unless CREATES_EMPTY_DISK
208
+ puts 'writing configuration to the disk...'
209
+ diskconf = disk.create_config
210
+ diskconf.host_name = 'saklient-test'
211
+ diskconf.password = password
212
+ diskconf.ssh_key = ssh_public_key
213
+ diskconf.ssh_keys.unshift(additional_ssh_public_key) if !additional_ssh_public_key.empty?
214
+ diskconf.scripts.push(script)
215
+ diskconf.write
222
216
  end
223
- fail 'サーバ起動中の起動試行時は HttpConflictException がスローされなければなりません' unless ok
224
217
 
225
- # ssh
226
- cmd = '| ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -i' + ssh_private_key_file +
227
- ' root@' + ip_address + ' hostname 2>/dev/null'
228
- ssh_success = false
229
- puts 'trying to SSH to the server...'
230
- for i in 0..9 do
231
- sleep 5
232
- sh = open cmd
233
- host_name_got = ''
234
- while !sh.eof
235
- host_name_got += sh.gets
218
+ unless SKIPS_SERVER_BOOT
219
+
220
+ # boot
221
+ puts 'booting the server...'
222
+ server.boot
223
+ sleep 3
224
+ server.reload
225
+ expect(server.instance.status).to eq Saklient::Cloud::Enums::EServerInstanceStatus::up
226
+
227
+ # boot conflict
228
+ puts 'checking the server power conflicts...'
229
+ ok = false
230
+ begin
231
+ server.boot
232
+ rescue Saklient::Errors::HttpConflictException
233
+ ok = true
236
234
  end
237
- sh.close
238
- host_name_got.strip!
239
- next unless host_name == host_name_got
240
- ssh_success = true
241
- break
242
- end
243
- fail '作成したサーバへ正常にSSHできません' unless ssh_success
244
-
245
- fail 'SSHに成功後、処理を中断しました' if BREAKS_AFTER_SERVER_UP
246
-
247
- # stop
248
- sleep 1
249
- puts 'stopping the server...'
250
- server.stop
251
- fail 'サーバが正常に停止しません' unless server.sleep_until_down
252
-
253
- # activity
254
- for sample in server.activity.fetch.samples do
255
- expect(sample.at).to be_an_instance_of DateTime
235
+ fail 'サーバ起動中の起動試行時は HttpConflictException がスローされなければなりません' unless ok
236
+
237
+ # ssh
238
+ unless CREATES_EMPTY_DISK
239
+ cmd = '| ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -i' + ssh_private_key_file +
240
+ ' root@' + ip_address + ' hostname 2>/dev/null'
241
+ ssh_success = false
242
+ puts 'trying to SSH to the server...'
243
+ for i in 0..9 do
244
+ sleep 5
245
+ sh = open cmd
246
+ host_name_got = ''
247
+ while !sh.eof
248
+ host_name_got += sh.gets
249
+ end
250
+ sh.close
251
+ host_name_got.strip!
252
+ next unless host_name == host_name_got
253
+ ssh_success = true
254
+ break
255
+ end
256
+ fail '作成したサーバへ正常にSSHできません' unless ssh_success
257
+ end
258
+
259
+ fail 'サーバを起動後、処理を中断しました' if BREAKS_AFTER_SERVER_UP
260
+
261
+ # stop
262
+ sleep 1
263
+ puts 'stopping the server...'
264
+ server.stop
265
+ fail 'サーバが正常に停止しません' unless server.sleep_until_down
266
+
267
+ # activity
268
+ for sample in server.activity.fetch.samples do
269
+ expect(sample.at).to be_an_instance_of DateTime
270
+ end
271
+
256
272
  end
257
273
 
258
274
  end
259
275
 
260
276
  if TESTS_EASY_DUPLICATE
261
277
  puts 'running easy duplicate...'
262
- server2 = server.easy_duplicate()
278
+ server1 = server
279
+ server2 = server1.easy_duplicate(CREATES_EMPTY_DISK ? 'skip' : nil)
263
280
 
264
281
  # check the server properties
265
282
  expect(server2.id.to_i).to be > 0
266
- expect(server2.name.gsub(/-\d+/, '')).to eq name.gsub(/-\d+/, '')
267
- expect(server2.host_name.gsub(/-\d+/, '')).to eq host_name.gsub(/-\d+/, '')
268
- expect(server2.description).to eq description
283
+ expect(server2.name.gsub(/-\d+/, '')).to eq server1.name.gsub(/-\d+/, '')
284
+ expect(server2.host_name.gsub(/-\d+/, '')).to eq server1.host_name.gsub(/-\d+/, '')
285
+ expect(server2.description).to eq server1.description
269
286
  expect(server2.tags).to be_an_instance_of Array
270
- expect(server2.tags.length).to eq 1
271
- expect(server2.tags[0]).to eq tag
272
- expect(server2.plan.cpu).to eq cpu
273
- expect(server2.plan.memory_gib).to eq mem
287
+ expect(server2.tags.length).to eq server1.tags.length
288
+ expect(server2.tags[0]).to eq server1.tags[0]
289
+ expect(server2.plan.cpu).to eq server1.plan.cpu
290
+ expect(server2.plan.memory_gib).to eq server1.plan.memory_gib
274
291
 
275
- expect(server2.ifaces.length).to eq 1
292
+ expect(server2.ifaces.length).to eq server1.ifaces.length
276
293
  expect(server2.ifaces[0]).to be_an_instance_of Saklient::Cloud::Resources::Iface
277
294
  expect(server2.ifaces[0].id.to_i).to be > 0
278
- expect(server2.ifaces[0].ip_address).not_to eq server.ifaces[0].ip_address
295
+ expect(server2.ifaces[0].ip_address).not_to eq server1.ifaces[0].ip_address
279
296
 
297
+ disks1 = server1.find_disks()
280
298
  disks2 = server2.find_disks()
281
- expect(disks2.length).to eq 1
282
- expect(disks2[0].size_gib).to eq disk.size_gib
283
- expect(disks2[0].source.id).to eq disk.source.id
299
+ expect(disks2.length).to eq disks1.length
300
+ expect(disks2[0].size_gib).to eq disks1[0].size_gib
301
+ expect(disks2[0].source).not_to be_nil
302
+ if CREATES_EMPTY_DISK
303
+ expect(disks2[0].source.id).to eq disks1[0].id
304
+ else
305
+ expect(disks2[0].source.id).to eq disks1[0].source.id
306
+ end
284
307
 
285
308
  next if BREAKS_AFTER_EASY_DUPLICATE
286
309
 
@@ -288,14 +311,18 @@ describe 'Server' do
288
311
  server2.destroy()
289
312
  end
290
313
 
291
- # disconnect the disk from the server
292
- puts 'disconnecting the disk from the server...'
293
- disk.disconnect
294
-
295
- # delete the server
296
- puts 'deleting the server...'
297
- server.destroy
314
+ if USE_READYMADE_SERVER_ID.nil? then
298
315
 
316
+ # disconnect the disk from the server
317
+ puts 'disconnecting the disk from the server...'
318
+ disk.disconnect
319
+
320
+ # delete the server
321
+ puts 'deleting the server...'
322
+ server.destroy
323
+
324
+ end
325
+
299
326
  if TESTS_DISK_EXPANSION
300
327
 
301
328
  # duplicate the disk
@@ -323,9 +350,11 @@ describe 'Server' do
323
350
 
324
351
  end
325
352
 
326
- # delete the disks
327
- puts 'deleting the disk...'
328
- disk.destroy
353
+ if USE_READYMADE_SERVER_ID.nil? then
354
+ # delete the disks
355
+ puts 'deleting the disk...'
356
+ disk.destroy
357
+ end
329
358
 
330
359
  end
331
360
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saklient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - townewgokgok
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-04 00:00:00.000000000 Z
11
+ date: 2016-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec