saklient 0.0.6 → 0.0.7

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: 9bd88b2b564abfa841ba4ea1d3a4690129c36fc5
4
- data.tar.gz: bf4d4494c832dc366f38c151631697cd5734fc67
3
+ metadata.gz: ea3d7d1ce2e74631267fa33bef7aea4976c5e100
4
+ data.tar.gz: 884896e9ea1cf5a42fd6e593977253d4c13abca0
5
5
  SHA512:
6
- metadata.gz: d95ad8fedd4a2da51becafba0dcd7d855c2b320a618b27280eb234148c009350c81f071a05fb3dd898798fea439d0a827a4377b6435f03b14aaa79fcf4f7329d
7
- data.tar.gz: f90d83eb6a37ff23b6ca447557d446d21b39c8e9e814d0d1cc451c818b4dbccfa7a33e2b7c8d001dbabc778ff9e4b0cc09338d1d3662b2730dce0f7e0de06a7a
6
+ metadata.gz: e85eb5d462b07c79246dec157a0c350df22175c3239f541ef8fa597393afa0f400d708fddf4d18f7eb1534b030a3e1edb4aae3e9c6efde7f480d39bcd4acaec7
7
+ data.tar.gz: 0d1877f0c22d22d7c9cecbb570fda2c8c59e0c16da9230d25dd4f4f8b48c71b8d647b090e5d676c480fdc8692dabbaffd0b6bc58dde0a828b7849dc0347a763c
@@ -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.6 rev-705e6fc541c30cec41e72e5e531418d64f196863',
81
+ 'User-Agent' => 'saklient.ruby ver-0.0.7 rev-bab628f6f4c2a9d37b38c634b4a514cb66467939',
82
82
  'X-Requested-With' => 'XMLHttpRequest',
83
83
  'X-Sakura-HTTP-Method' => method,
84
84
  'X-Sakura-Error-Level' => 'warning',
@@ -291,11 +291,7 @@ module Saklient
291
291
  missing << 'name' if @is_new
292
292
  end
293
293
  Saklient::Util::set_by_path(ret, 'Description', @m_description) if withClean || @n_description
294
- if withClean || @n_region
295
- Saklient::Util::set_by_path(ret, 'Region', withClean ? ((@m_region).nil? ? nil : @m_region.api_serialize(withClean)) : ((@m_region).nil? ? { ID: '0' } : @m_region.api_serialize_id))
296
- else
297
- missing << 'region' if @is_new
298
- end
294
+ Saklient::Util::set_by_path(ret, 'Region', withClean ? ((@m_region).nil? ? nil : @m_region.api_serialize(withClean)) : ((@m_region).nil? ? { ID: '0' } : @m_region.api_serialize_id)) if withClean || @n_region
299
295
  raise Saklient::Errors::SaklientException.new('required_field', 'Required fields must be set before the Bridge creation: ' + missing.join(', ')) if missing.length > 0
300
296
  return ret
301
297
  end
@@ -647,17 +647,34 @@ module Saklient
647
647
  return @m_server
648
648
  end
649
649
 
650
+ # (This method is generated in Translator_default#buildImpl)
651
+ #
652
+ # @private
653
+ # @param [Server] v
654
+ # @return [Server]
655
+ def set_server(v)
656
+ Saklient::Util::validate_type(v, 'Saklient::Cloud::Resources::Server')
657
+ raise Saklient::Errors::SaklientException.new('immutable_field', 'Immutable fields cannot be modified after the resource creation: ' + 'Saklient::Cloud::Resources::Disk#server') if !@is_new
658
+ @m_server = v
659
+ @n_server = true
660
+ return @m_server
661
+ end
662
+
650
663
  public
651
664
 
652
665
  # 接続先のサーバ
653
666
  #
654
667
  # @return [Server]
655
- attr_reader :server
668
+ attr_accessor :server
656
669
 
657
670
  def server
658
671
  get_server
659
672
  end
660
673
 
674
+ def server=(v)
675
+ set_server(v)
676
+ end
677
+
661
678
  protected
662
679
 
663
680
  # @return [bool]
@@ -226,10 +226,11 @@ module Saklient
226
226
  settings = self.raw_settings
227
227
  if !(settings).nil?
228
228
  raw = Saklient::Util::get_by_path(settings, 'GSLB.Servers')
229
- raw = [] if (raw).nil?
230
- servers = raw
231
- for server in servers
232
- @_servers << Saklient::Cloud::Resources::GslbServer.new(server)
229
+ if !(raw).nil?
230
+ servers = raw
231
+ for server in servers
232
+ @_servers << Saklient::Cloud::Resources::GslbServer.new(server)
233
+ end
233
234
  end
234
235
  end
235
236
  end
@@ -7,6 +7,7 @@ require_relative '../client'
7
7
  require_relative 'resource'
8
8
  require_relative 'swytch'
9
9
  require_relative 'iface_activity'
10
+ require_relative '../models/model_swytch'
10
11
 
11
12
  module Saklient
12
13
  module Cloud
@@ -176,6 +177,14 @@ module Saklient
176
177
  return reload
177
178
  end
178
179
 
180
+ # 接続先のスイッチを取得します.
181
+ #
182
+ # @return [Swytch]
183
+ def find_swytch
184
+ model = Saklient::Util::create_class_instance('saklient.cloud.models.Model_Swytch', [@_client])
185
+ return model.get_by_id(self.swytch_id)
186
+ end
187
+
179
188
  protected
180
189
 
181
190
  # @return [bool]
@@ -2,19 +2,24 @@
2
2
 
3
3
  # This code is automatically transpiled by Saklient Translator
4
4
 
5
+ require_relative '../../errors/http_not_found_exception'
5
6
  require_relative '../../errors/http_exception'
6
7
  require_relative '../../errors/saklient_exception'
7
8
  require_relative '../client'
8
9
  require_relative 'resource'
9
10
  require_relative 'icon'
11
+ require_relative 'archive'
10
12
  require_relative 'disk'
13
+ require_relative 'disk_config'
11
14
  require_relative 'iface'
12
15
  require_relative 'server_plan'
13
16
  require_relative 'server_instance'
14
17
  require_relative 'iso_image'
18
+ require_relative 'ipv4_net'
15
19
  require_relative 'server_activity'
16
20
  require_relative '../enums/eserver_instance_status'
17
21
  require_relative '../enums/eavailability'
22
+ require_relative '../models/model_server'
18
23
  require_relative '../models/model_disk'
19
24
  require_relative '../models/model_iface'
20
25
 
@@ -67,6 +72,11 @@ module Saklient
67
72
  # @return [ServerInstance]
68
73
  attr_accessor :m_instance
69
74
 
75
+ # ホスト名
76
+ #
77
+ # @return [String]
78
+ attr_accessor :m_host_name
79
+
70
80
  # 有効状態 {Saklient::Cloud::Enums::EAvailability}
71
81
  #
72
82
  # @return [String]
@@ -153,6 +163,144 @@ module Saklient
153
163
  api_deserialize(obj, wrapped)
154
164
  end
155
165
 
166
+ # サーバ および そのサーバに接続されている1台目のディスクを複製し, 同一ネットワークに接続します.
167
+ # ディスクのコピー中は待機し, 完了してからreturnします.
168
+ #
169
+ # 共有セグメントに接続されている場合はAPIによって自動的に割り当てられるため, 省略またはnullを指定してください.
170
+ # trueを指定した場合は, 複製元の現在のディスク#1から直接クローンします.
171
+ # 省略またはnullを指定した場合は, 複製元のディスク#1が作成された時のコピー元リソースから再度クローンを試みます.
172
+ # 既に削除されている場合は, 複製元の現在のディスク#1からの直接クローンにフォールバックします.
173
+ # いずれの場合も, 作成されるディスクのプランとサイズは複製元のサーバの1台目のディスクと同一のものが選択されます.
174
+ # 作成されるディスクは1台目だけで, 2台目以降は無視されます.
175
+ #
176
+ # @param [String] userIpAddress 最初のインタフェースに割り当てるIPアドレスを指定します.
177
+ # @param [any] diskSource ディスク#1のクローン元リソース(DiskまたはArchive)を指定します. 見つからないときは例外が発生します.
178
+ # @param hostname 新しいサーバのホスト名(自動的にホスト名をつける場合は省略またはnullを指定)
179
+ # @param [String] name 新しいサーバの名前(自動的に名前をつける場合は省略またはnullを指定)
180
+ # @param [String] sshKey
181
+ # @param [String] hostName
182
+ # @return [Server]
183
+ def easy_duplicate(userIpAddress = nil, diskSource = nil, sshKey = nil, hostName = nil, name = nil)
184
+ Saklient::Util::validate_type(userIpAddress, 'String')
185
+ Saklient::Util::validate_type(sshKey, 'String')
186
+ Saklient::Util::validate_type(hostName, 'String')
187
+ Saklient::Util::validate_type(name, 'String')
188
+ server = Saklient::Cloud::Resources::Server.new(@_client, nil)
189
+ names = []
190
+ hostNames = []
191
+ if (name).nil? || (hostName).nil?
192
+ model = Saklient::Util::create_class_instance('saklient.cloud.models.Model_Server', [@_client])
193
+ servers = model.limit(0).find
194
+ s = nil
195
+ for s in servers
196
+ names << s.get_name
197
+ hostNames << s.get_host_name
198
+ end
199
+ end
200
+ name = Saklient::Util::auto_rename(self.name, names) if (name).nil?
201
+ hostName = Saklient::Util::auto_rename(self.host_name, hostNames) if (hostName).nil?
202
+ server.set_name(name)
203
+ server.set_host_name(hostName)
204
+ server.set_description(self.description)
205
+ server.set_tags(self.tags)
206
+ server.set_icon(self.icon)
207
+ server.set_plan(self.plan)
208
+ iface = nil
209
+ if 0 < self.ifaces.length
210
+ iface = self.ifaces[0]
211
+ 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?
216
+ end
217
+ end
218
+ srcDisks = find_disks
219
+ 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
230
+ else
231
+ if diskSource.is_a?(Saklient::Cloud::Resources::Disk)
232
+ begin
233
+ diskSource.reload
234
+ rescue Saklient::Errors::HttpNotFoundException
235
+ diskSource = srcDisks[0]
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
241
+ if diskSource.is_a?(Saklient::Cloud::Resources::Archive)
242
+ diskSource.reload
243
+ else
244
+ diskSource.reload if diskSource.is_a?(Saklient::Cloud::Resources::Disk)
245
+ end
246
+ end
247
+ server.save
248
+ disk = nil
249
+ if !(diskSource).nil? && diskSource.is_a?(Saklient::Cloud::Resources::Resource)
250
+ disk = Saklient::Cloud::Resources::Disk.new(@_client, nil)
251
+ disk.source = diskSource
252
+ disk.name = (name).nil? ? srcDisks[0].name : name
253
+ disk.description = srcDisks[0].description
254
+ disk.tags = srcDisks[0].tags
255
+ disk.icon = srcDisks[0].icon
256
+ disk.plan = srcDisks[0].plan
257
+ disk.size_mib = srcDisks[0].size_mib
258
+ disk.server = server
259
+ disk.save
260
+ end
261
+ iface1st = nil
262
+ userSwytch = nil
263
+ for iface in self.ifaces
264
+ iface.reload
265
+ newIface = server.add_iface
266
+ if (iface1st).nil?
267
+ if !(iface.ip_address).nil?
268
+ newIface.connect_to_shared_segment
269
+ else
270
+ newIface.connect_to_swytch_by_id(iface.swytch_id) if !(iface.swytch_id).nil?
271
+ if !(userIpAddress).nil?
272
+ newIface.user_ip_address = userIpAddress
273
+ newIface.save
274
+ end
275
+ userSwytch = iface.find_swytch
276
+ iface1st = iface
277
+ end
278
+ else
279
+ newIface.connect_to_swytch_by_id(iface.swytch_id) if !(iface.swytch_id).nil?
280
+ end
281
+ end
282
+ if !(disk).nil?
283
+ 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
296
+ end
297
+ end
298
+ diskconf.write
299
+ end
300
+ server.reload
301
+ return server
302
+ end
303
+
156
304
  protected
157
305
 
158
306
  # @private
@@ -162,11 +310,13 @@ module Saklient
162
310
  def _on_before_api_deserialize(r, root)
163
311
  return nil if (r).nil?
164
312
  id = r[:ID]
165
- ifaces = r[:Interfaces]
313
+ ifaces = Saklient::Util::get_by_path(r, 'Interfaces')
166
314
  if !(ifaces).nil?
167
315
  for iface in ifaces
168
- server = iface[:Server]
169
- if (server).nil?
316
+ server = nil
317
+ if !iface.nil? && iface.key?(:Server)
318
+ server = iface[:Server]
319
+ else
170
320
  server = {}
171
321
  iface[:Server] = server
172
322
  end
@@ -309,7 +459,9 @@ module Saklient
309
459
  model = Saklient::Util::create_class_instance('saklient.cloud.models.Model_Iface', [@_client])
310
460
  res = model.create
311
461
  res.server_id = _id
312
- return res.save
462
+ res.save
463
+ reload
464
+ return res
313
465
  end
314
466
 
315
467
  # サーバにISOイメージを挿入します.
@@ -335,6 +487,35 @@ module Saklient
335
487
  return self
336
488
  end
337
489
 
490
+ # サーバに接続されているコピー中のディスクが利用可能になるまで待機します.
491
+ #
492
+ # @param [Fixnum] timeoutSec
493
+ # @return [bool] 成功時はtrue, タイムアウトやエラーによる失敗時はfalseを返します.
494
+ def sleep_while_copying(timeoutSec = 3600)
495
+ Saklient::Util::validate_type(timeoutSec, 'Fixnum')
496
+ step = 10
497
+ disks = find_disks
498
+ while 0 < timeoutSec do
499
+ disk = nil
500
+ begin
501
+ reload
502
+ for disk in disks
503
+ disk.reload
504
+ end
505
+ rescue Saklient::Errors::HttpException
506
+ {}
507
+ end
508
+ result = get_availability == Saklient::Cloud::Enums::EAvailability::available
509
+ for disk in disks
510
+ result = false if disk.availability != Saklient::Cloud::Enums::EAvailability::available
511
+ end
512
+ return true if result
513
+ timeoutSec -= step
514
+ sleep(step) if 0 < timeoutSec
515
+ end
516
+ return false
517
+ end
518
+
338
519
  protected
339
520
 
340
521
  # @return [bool]
@@ -611,6 +792,46 @@ module Saklient
611
792
 
612
793
  protected
613
794
 
795
+ # @return [bool]
796
+ attr_accessor :n_host_name
797
+
798
+ # (This method is generated in Translator_default#buildImpl)
799
+ #
800
+ # @private
801
+ # @return [String]
802
+ def get_host_name
803
+ return @m_host_name
804
+ end
805
+
806
+ # (This method is generated in Translator_default#buildImpl)
807
+ #
808
+ # @private
809
+ # @param [String] v
810
+ # @return [String]
811
+ def set_host_name(v)
812
+ Saklient::Util::validate_type(v, 'String')
813
+ @m_host_name = v
814
+ @n_host_name = true
815
+ return @m_host_name
816
+ end
817
+
818
+ public
819
+
820
+ # ホスト名
821
+ #
822
+ # @return [String]
823
+ attr_accessor :host_name
824
+
825
+ def host_name
826
+ get_host_name
827
+ end
828
+
829
+ def host_name=(v)
830
+ set_host_name(v)
831
+ end
832
+
833
+ protected
834
+
614
835
  # @return [bool]
615
836
  attr_accessor :n_availability
616
837
 
@@ -716,6 +937,13 @@ module Saklient
716
937
  @is_incomplete = true
717
938
  end
718
939
  @n_instance = false
940
+ if Saklient::Util::exists_path(r, 'HostName')
941
+ @m_host_name = (Saklient::Util::get_by_path(r, 'HostName')).nil? ? nil : Saklient::Util::get_by_path(r, 'HostName').to_s
942
+ else
943
+ @m_host_name = nil
944
+ @is_incomplete = true
945
+ end
946
+ @n_host_name = false
719
947
  if Saklient::Util::exists_path(r, 'Availability')
720
948
  @m_availability = (Saklient::Util::get_by_path(r, 'Availability')).nil? ? nil : Saklient::Util::get_by_path(r, 'Availability').to_s
721
949
  else
@@ -762,6 +990,7 @@ module Saklient
762
990
  end
763
991
  end
764
992
  Saklient::Util::set_by_path(ret, 'Instance', withClean ? ((@m_instance).nil? ? nil : @m_instance.api_serialize(withClean)) : ((@m_instance).nil? ? { ID: '0' } : @m_instance.api_serialize_id)) if withClean || @n_instance
993
+ Saklient::Util::set_by_path(ret, 'HostName', @m_host_name) if withClean || @n_host_name
765
994
  Saklient::Util::set_by_path(ret, 'Availability', @m_availability) if withClean || @n_availability
766
995
  raise Saklient::Errors::SaklientException.new('required_field', 'Required fields must be set before the Server creation: ' + missing.join(', ')) if missing.length > 0
767
996
  return ret
data/lib/saklient/util.rb CHANGED
@@ -154,6 +154,29 @@ module Saklient
154
154
  end
155
155
  raise Saklient::Errors::SaklientException.new('argument_type_mismatch', 'Argument type mismatch (expected '+typeName+' but got '+clazz+')') unless isOk
156
156
  end
157
+
158
+ def self.are_same(a, b)
159
+ return a.equal?(b)
160
+ end
161
+
162
+ def self.auto_rename(name, candidates)
163
+ m = /^(.*?)(\d+)(\W*)$/.match(name)
164
+ if m then
165
+ max = 0
166
+ len = 0
167
+ for c in candidates
168
+ n = /^(.*?)(\d+)(\W*)$/.match(c)
169
+ next unless n
170
+ next unless m[1]==n[1] and m[3]==n[3]
171
+ max = [max, n[2].to_i].max
172
+ len = [len, n[2].length].max
173
+ end
174
+ if 0 < len
175
+ return sprintf("%s%0" + len.to_s + "d%s", m[1], max+1, m[3])
176
+ end
177
+ end
178
+ return name + "-2"
179
+ end
157
180
 
158
181
  end
159
182
 
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: UTF-8 -*-
2
2
 
3
3
  module Saklient
4
- VERSION = "0.0.6"
4
+ VERSION = "0.0.7"
5
5
  end
data/spec/server_spec.rb CHANGED
@@ -3,6 +3,16 @@ require 'saklient/cloud/api'
3
3
  require 'date'
4
4
  require 'SecureRandom'
5
5
 
6
+ TESTS_EASY_DUPLICATE = true
7
+ TESTS_DISK_EXPANSION = false
8
+
9
+ BREAKS_AFTER_SERVER_UP = false
10
+ BREAKS_AFTER_EASY_DUPLICATE = true
11
+
12
+ USE_READYMADE_SERVER_ID = 112800244655 # For TESTS_EASY_DUPLICATE
13
+
14
+
15
+
6
16
  describe 'Server' do
7
17
 
8
18
 
@@ -77,160 +87,205 @@ describe 'Server' do
77
87
  ssh_private_key_file = File.dirname(__dir__) + '/test-sshkey.txt'
78
88
  password = SecureRandom.uuid[0, 8]
79
89
 
80
- # options
81
- additional_ssh_public_key = File.open(ENV['HOME'] + '/.ssh/id_rsa.pub').read.strip
82
- tests_disk_expansion = false
83
- breaks_after_server_up = false
84
-
85
- # search archives
86
- puts 'searching archives...'
87
- archives = @api.archive.with_name_like('CentOS 64bit').with_size_gib(20).with_shared_scope.limit(1).find
88
- expect(archives.length).to be > 0
89
- # printf "found %d archive(s)\n", archives.length
90
- archive = archives[0]
91
- expect(archive.id.to_i).to be > 0
92
- # p archive.dump
93
-
94
- # search scripts
95
- puts 'searching scripts...'
96
- scripts = @api.script.with_name_like('WordPress').with_shared_scope.limit(1).find
97
- # printf "found %d script(s)\n", scripts.length
98
- script = scripts[0]
99
- # p script.dump
90
+ server = nil
91
+ disk = nil
100
92
 
101
- # create a disk
102
- puts 'creating a disk...'
103
- disk = @api.disk.create
104
- ok = false
105
- begin
106
- disk.save
107
- rescue Saklient::Errors::SaklientException
108
- ok = true
109
- end
110
- fail 'Requiredフィールドが未set時は SaklientException がスローされなければなりません' unless ok
111
- disk.name = '!ruby_rspec-' + DateTime.now.strftime('%Y%m%d_%H%M%S') + '-' + SecureRandom.uuid[0, 8]
112
- disk.description = 'This instance was created by saklient.ruby rspec'
113
- disk.tags = ['saklient-test']
114
- disk.plan = @api.product.disk.ssd
115
- disk.source = archive
116
- disk.save
117
- # p disk.dump
93
+ if !USE_READYMADE_SERVER_ID.nil? then
94
+
95
+ server = @api.server.get_by_id(USE_READYMADE_SERVER_ID)
96
+ name = server.name
97
+ host_name = server.host_name
98
+ description = server.description
99
+ disks = server.find_disks()
100
+ disk = disks[0]
101
+
102
+ else
118
103
 
119
- # check an immutable field
120
- puts 'updating the disk...'
121
- ok = false
122
- begin
123
- disk.size_mib = 20480
104
+ # options
105
+ additional_ssh_public_key = File.open(ENV['HOME'] + '/.ssh/id_rsa.pub').read.strip
106
+
107
+ # search archives
108
+ puts 'searching archives...'
109
+ archives = @api.archive.with_name_like('CentOS 64bit').with_size_gib(20).with_shared_scope.limit(1).find
110
+ expect(archives.length).to be > 0
111
+ # printf "found %d archive(s)\n", archives.length
112
+ archive = archives[0]
113
+ expect(archive.id.to_i).to be > 0
114
+ # p archive.dump
115
+
116
+ # search scripts
117
+ puts 'searching scripts...'
118
+ scripts = @api.script.with_name_like('WordPress').with_shared_scope.limit(1).find
119
+ # printf "found %d script(s)\n", scripts.length
120
+ script = scripts[0]
121
+ # p script.dump
122
+
123
+ # create a disk
124
+ puts 'creating a disk...'
125
+ disk = @api.disk.create
126
+ ok = false
127
+ begin
128
+ disk.save
129
+ rescue Saklient::Errors::SaklientException
130
+ ok = true
131
+ end
132
+ fail 'Requiredフィールドが未set時は SaklientException がスローされなければなりません' unless ok
133
+ disk.name = '!ruby_rspec-' + DateTime.now.strftime('%Y%m%d_%H%M%S') + '-' + SecureRandom.uuid[0, 8]
134
+ disk.description = 'This instance was created by saklient.ruby rspec'
135
+ disk.tags = ['saklient-test']
136
+ disk.plan = @api.product.disk.ssd
137
+ disk.source = archive
124
138
  disk.save
125
- rescue Saklient::Errors::SaklientException
126
- ok = true
127
- end
128
- fail 'Immutableフィールドの再set時は SaklientException がスローされなければなりません' unless ok
129
-
130
- # create a server
131
- puts 'creating a server...'
132
- server = @api.server.create
133
- expect(server).to be_an_instance_of Saklient::Cloud::Resources::Server
134
- server.name = name
135
- server.description = description
136
- server.tags = [tag]
137
- server.plan = @api.product.server.get_by_spec(cpu, mem)
138
- server.save
139
-
140
- # check the server properties
141
- expect(server.id.to_i).to be > 0
142
- expect(server.name).to eq name
143
- expect(server.description).to eq description
144
- expect(server.tags).to be_an_instance_of Array
145
- expect(server.tags.length).to eq 1
146
- expect(server.tags[0]).to eq tag
147
- expect(server.plan.cpu).to eq cpu
148
- expect(server.plan.memory_gib).to eq mem
149
-
150
- # connect to shared segment
151
- puts 'connecting the server to shared segment...'
152
- iface = server.add_iface
153
- expect(iface).to be_an_instance_of Saklient::Cloud::Resources::Iface
154
- expect(iface.id.to_i).to be > 0
155
- iface.connect_to_shared_segment
156
-
157
- # wait disk copy
158
- puts 'waiting disk copy...'
159
- fail 'アーカイブからディスクへのコピーがタイムアウトしました' unless disk.sleep_while_copying
160
- # p disk.dump
161
- disk.source = nil
162
- disk.reload
163
- expect(disk.source).to be_an_instance_of Saklient::Cloud::Resources::Archive
164
- expect(disk.source.id).to eq archive.id
165
- expect(disk.size_gib).to eq archive.size_gib
166
-
167
- # connect the disk to the server
168
- puts 'connecting the disk to the server...'
169
- disk.connect_to(server)
170
- server.reload
171
- ip_address = server.ifaces[0].ip_address
172
- puts 'server IP address: ' + ip_address
173
- puts 'server password: ' + password
174
- expect(ip_address).not_to be_empty
175
-
176
- # config the disk
177
- puts 'writing configuration to the disk...'
178
- diskconf = disk.create_config
179
- diskconf.host_name = 'saklient-test'
180
- diskconf.password = password
181
- diskconf.ssh_key = ssh_public_key
182
- diskconf.ssh_keys.unshift(additional_ssh_public_key) if !additional_ssh_public_key.empty?
183
- diskconf.scripts.push(script)
184
- diskconf.write
185
-
186
- # boot
187
- puts 'booting the server...'
188
- server.boot
189
- sleep 3
190
- server.reload
191
- expect(server.instance.status).to eq Saklient::Cloud::Enums::EServerInstanceStatus::up
192
-
193
- # boot conflict
194
- puts 'checking the server power conflicts...'
195
- ok = false
196
- begin
139
+ # p disk.dump
140
+
141
+ # check an immutable field
142
+ puts 'updating the disk...'
143
+ ok = false
144
+ begin
145
+ disk.size_mib = 20480
146
+ disk.save
147
+ rescue Saklient::Errors::SaklientException
148
+ ok = true
149
+ end
150
+ fail 'Immutableフィールドの再set時は SaklientException がスローされなければなりません' unless ok
151
+
152
+ # create a server
153
+ puts 'creating a server...'
154
+ server = @api.server.create
155
+ expect(server).to be_an_instance_of Saklient::Cloud::Resources::Server
156
+ server.name = name
157
+ server.description = description
158
+ server.tags = [tag]
159
+ server.plan = @api.product.server.get_by_spec(cpu, mem)
160
+ server.save
161
+
162
+ # check the server properties
163
+ expect(server.id.to_i).to be > 0
164
+ expect(server.name).to eq name
165
+ expect(server.description).to eq description
166
+ expect(server.tags).to be_an_instance_of Array
167
+ expect(server.tags.length).to eq 1
168
+ expect(server.tags[0]).to eq tag
169
+ expect(server.plan.cpu).to eq cpu
170
+ expect(server.plan.memory_gib).to eq mem
171
+
172
+ # connect to shared segment
173
+ puts 'connecting the server to shared segment...'
174
+ iface = server.add_iface
175
+ expect(iface).to be_an_instance_of Saklient::Cloud::Resources::Iface
176
+ expect(iface.id.to_i).to be > 0
177
+ iface.connect_to_shared_segment
178
+
179
+ # wait disk copy
180
+ puts 'waiting disk copy...'
181
+ fail 'アーカイブからディスクへのコピーがタイムアウトしました' unless disk.sleep_while_copying
182
+ # p disk.dump
183
+ disk.source = nil
184
+ disk.reload
185
+ expect(disk.source).to be_an_instance_of Saklient::Cloud::Resources::Archive
186
+ expect(disk.source.id).to eq archive.id
187
+ expect(disk.size_gib).to eq archive.size_gib
188
+
189
+ # connect the disk to the server
190
+ puts 'connecting the disk to the server...'
191
+ disk.connect_to(server)
192
+ server.reload
193
+ ip_address = server.ifaces[0].ip_address
194
+ puts 'server IP address: ' + ip_address
195
+ puts 'server password: ' + password
196
+ expect(ip_address).not_to be_empty
197
+
198
+ # 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...'
197
210
  server.boot
198
- rescue Saklient::Errors::HttpConflictException
199
- ok = true
200
- end
201
- fail 'サーバ起動中の起動試行時は HttpConflictException がスローされなければなりません' unless ok
202
-
203
- # ssh
204
- cmd = '| ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -i' + ssh_private_key_file +
205
- ' root@' + ip_address + ' hostname 2>/dev/null'
206
- ssh_success = false
207
- puts 'trying to SSH to the server...'
208
- for i in 0..9 do
209
- sleep 5
210
- sh = open cmd
211
- host_name_got = ''
212
- while !sh.eof
213
- host_name_got += sh.gets
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
222
+ end
223
+ fail 'サーバ起動中の起動試行時は HttpConflictException がスローされなければなりません' unless ok
224
+
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
236
+ 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
214
256
  end
215
- sh.close
216
- host_name_got.strip!
217
- next unless host_name == host_name_got
218
- ssh_success = true
219
- break
257
+
220
258
  end
221
- fail '作成したサーバへ正常にSSHできません' unless ssh_success
222
-
223
- fail 'SSHに成功後、処理を中断しました' if breaks_after_server_up
224
-
225
- # stop
226
- sleep 1
227
- puts 'stopping the server...'
228
- server.stop
229
- fail 'サーバが正常に停止しません' unless server.sleep_until_down
230
-
231
- # activity
232
- for sample in server.activity.fetch.samples do
233
- expect(sample.at).to be_an_instance_of DateTime
259
+
260
+ if TESTS_EASY_DUPLICATE
261
+ puts 'running easy duplicate...'
262
+ server2 = server.easy_duplicate()
263
+
264
+ # check the server properties
265
+ 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
269
+ 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
274
+
275
+ expect(server2.ifaces.length).to eq 1
276
+ expect(server2.ifaces[0]).to be_an_instance_of Saklient::Cloud::Resources::Iface
277
+ 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
279
+
280
+ 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
284
+
285
+ next if BREAKS_AFTER_EASY_DUPLICATE
286
+
287
+ disks2[0].destroy()
288
+ server2.destroy()
234
289
  end
235
290
 
236
291
  # disconnect the disk from the server
@@ -241,7 +296,7 @@ describe 'Server' do
241
296
  puts 'deleting the server...'
242
297
  server.destroy
243
298
 
244
- if tests_disk_expansion
299
+ if TESTS_DISK_EXPANSION
245
300
 
246
301
  # duplicate the disk
247
302
  puts 'duplicating the disk (expanding to 40GiB)...'
data/spec/util_spec.rb CHANGED
@@ -97,4 +97,24 @@ describe 'Util' do
97
97
 
98
98
  end
99
99
 
100
+ it 'should access objects by path' do
101
+ candidates = [
102
+ "server-00001",
103
+ "server-00005",
104
+ "server-00030",
105
+ "swytch-00040",
106
+ "名称未設定 (1234)",
107
+ "名称未設定 (567)",
108
+ "0000099999",
109
+ "xxx99999",
110
+ ]
111
+ expect(Util::auto_rename("server-00001", candidates)).to eq "server-00031"
112
+ expect(Util::auto_rename("server-00005", candidates)).to eq "server-00031"
113
+ expect(Util::auto_rename("swytch-00005", candidates)).to eq "swytch-00041"
114
+ expect(Util::auto_rename("名称未設定 (1234)", candidates)).to eq "名称未設定 (1235)"
115
+ expect(Util::auto_rename("名称未設定 (567)", candidates)).to eq "名称未設定 (1235)"
116
+ expect(Util::auto_rename("0000099999", candidates)).to eq "0000100000"
117
+ expect(Util::auto_rename("xxx99999", candidates)).to eq "xxx100000"
118
+ end
119
+
100
120
  end
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - townewgokgok
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -317,4 +317,3 @@ test_files:
317
317
  - spec/server_spec.rb
318
318
  - spec/swytch_spec.rb
319
319
  - spec/util_spec.rb
320
- has_rdoc: