saklient 0.0.2.11 → 0.0.5
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 +4 -4
- data/lib/saklient/cloud/api.rb +25 -0
- data/lib/saklient/cloud/client.rb +1 -1
- data/lib/saklient/cloud/models/model_common_service_item.rb +157 -0
- data/lib/saklient/cloud/resources/common_service_item.rb +499 -0
- data/lib/saklient/cloud/resources/common_service_provider.rb +196 -0
- data/lib/saklient/cloud/resources/disk_activity.rb +12 -0
- data/lib/saklient/cloud/resources/gslb.rb +293 -0
- data/lib/saklient/cloud/resources/gslb_server.rb +157 -0
- data/lib/saklient/cloud/resources/iface.rb +54 -0
- data/lib/saklient/cloud/resources/iface_activity.rb +12 -0
- data/lib/saklient/cloud/resources/resource.rb +13 -2
- data/lib/saklient/cloud/resources/router.rb +4 -2
- data/lib/saklient/cloud/resources/router_activity.rb +12 -0
- data/lib/saklient/cloud/resources/server.rb +20 -0
- data/lib/saklient/cloud/resources/server_activity.rb +12 -0
- data/lib/saklient/util.rb +1 -1
- data/lib/saklient/version.rb +1 -1
- data/spec/gslb_spec.rb +99 -0
- data/spec/iso_image_spec.rb +1 -1
- data/spec/server_spec.rb +5 -0
- data/spec/swytch_spec.rb +8 -0
- metadata +9 -2
@@ -0,0 +1,157 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
# This code is automatically transpiled by Saklient Translator
|
4
|
+
|
5
|
+
require_relative '../../util'
|
6
|
+
|
7
|
+
module Saklient
|
8
|
+
module Cloud
|
9
|
+
module Resources
|
10
|
+
|
11
|
+
# GSLBの監視対象サーバ設定.
|
12
|
+
class GslbServer
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
# @private
|
17
|
+
# @return [bool]
|
18
|
+
attr_accessor :_enabled
|
19
|
+
|
20
|
+
public
|
21
|
+
|
22
|
+
# @private
|
23
|
+
# @return [bool]
|
24
|
+
def get_enabled
|
25
|
+
return @_enabled
|
26
|
+
end
|
27
|
+
|
28
|
+
# @private
|
29
|
+
# @param [bool] v
|
30
|
+
# @return [bool]
|
31
|
+
def set_enabled(v)
|
32
|
+
Saklient::Util::validate_type(v, 'bool')
|
33
|
+
@_enabled = v
|
34
|
+
return @_enabled
|
35
|
+
end
|
36
|
+
|
37
|
+
# 有効状態
|
38
|
+
#
|
39
|
+
# @return [bool]
|
40
|
+
attr_accessor :enabled
|
41
|
+
|
42
|
+
def enabled
|
43
|
+
get_enabled
|
44
|
+
end
|
45
|
+
|
46
|
+
def enabled=(v)
|
47
|
+
set_enabled(v)
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
# @private
|
53
|
+
# @return [String]
|
54
|
+
attr_accessor :_ip_address
|
55
|
+
|
56
|
+
public
|
57
|
+
|
58
|
+
# @private
|
59
|
+
# @return [String]
|
60
|
+
def get_ip_address
|
61
|
+
return @_ip_address
|
62
|
+
end
|
63
|
+
|
64
|
+
# @private
|
65
|
+
# @param [String] v
|
66
|
+
# @return [String]
|
67
|
+
def set_ip_address(v)
|
68
|
+
Saklient::Util::validate_type(v, 'String')
|
69
|
+
@_ip_address = v
|
70
|
+
return @_ip_address
|
71
|
+
end
|
72
|
+
|
73
|
+
# IPアドレス
|
74
|
+
#
|
75
|
+
# @return [String]
|
76
|
+
attr_accessor :ip_address
|
77
|
+
|
78
|
+
def ip_address
|
79
|
+
get_ip_address
|
80
|
+
end
|
81
|
+
|
82
|
+
def ip_address=(v)
|
83
|
+
set_ip_address(v)
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
|
88
|
+
# @private
|
89
|
+
# @return [Fixnum]
|
90
|
+
attr_accessor :_weight
|
91
|
+
|
92
|
+
public
|
93
|
+
|
94
|
+
# @private
|
95
|
+
# @return [Fixnum]
|
96
|
+
def get_weight
|
97
|
+
return @_weight
|
98
|
+
end
|
99
|
+
|
100
|
+
# @private
|
101
|
+
# @param [Fixnum] v
|
102
|
+
# @return [Fixnum]
|
103
|
+
def set_weight(v)
|
104
|
+
Saklient::Util::validate_type(v, 'Fixnum')
|
105
|
+
@_weight = v
|
106
|
+
return @_weight
|
107
|
+
end
|
108
|
+
|
109
|
+
# 重み値
|
110
|
+
#
|
111
|
+
# @return [Fixnum]
|
112
|
+
attr_accessor :weight
|
113
|
+
|
114
|
+
def weight
|
115
|
+
get_weight
|
116
|
+
end
|
117
|
+
|
118
|
+
def weight=(v)
|
119
|
+
set_weight(v)
|
120
|
+
end
|
121
|
+
|
122
|
+
# @private
|
123
|
+
# @param [any] obj
|
124
|
+
def initialize(obj = nil)
|
125
|
+
obj = {} if (obj).nil?
|
126
|
+
enabled = Saklient::Util::get_by_path_any([obj], ['Enabled', 'enabled'])
|
127
|
+
@_enabled = nil
|
128
|
+
if !(enabled).nil?
|
129
|
+
enabledStr = enabled
|
130
|
+
@_enabled = enabledStr.downcase() == 'true'
|
131
|
+
end
|
132
|
+
@_ip_address = Saklient::Util::get_by_path_any([obj], [
|
133
|
+
'IPAddress',
|
134
|
+
'ipAddress',
|
135
|
+
'ip_address',
|
136
|
+
'ip'
|
137
|
+
])
|
138
|
+
weight = Saklient::Util::get_by_path_any([obj], ['Weight', 'weight'])
|
139
|
+
@_weight = nil
|
140
|
+
@_weight = (weight).to_s().to_i(10) if !(weight).nil?
|
141
|
+
@_weight = nil if @_weight == 0
|
142
|
+
end
|
143
|
+
|
144
|
+
# @return [any]
|
145
|
+
def to_raw_settings
|
146
|
+
return {
|
147
|
+
Enabled: (@_enabled).nil? ? nil : (@_enabled ? 'True' : 'False'),
|
148
|
+
IPAddress: @_ip_address,
|
149
|
+
Weight: @_weight
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -42,6 +42,11 @@ module Saklient
|
|
42
42
|
# @return [String]
|
43
43
|
attr_accessor :m_server_id
|
44
44
|
|
45
|
+
# このインタフェースの接続先スイッチのID
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
attr_accessor :m_swytch_id
|
49
|
+
|
45
50
|
# @private
|
46
51
|
# @return [String]
|
47
52
|
def _api_path
|
@@ -316,6 +321,47 @@ module Saklient
|
|
316
321
|
|
317
322
|
protected
|
318
323
|
|
324
|
+
# @return [bool]
|
325
|
+
attr_accessor :n_swytch_id
|
326
|
+
|
327
|
+
# (This method is generated in Translator_default#buildImpl)
|
328
|
+
#
|
329
|
+
# @private
|
330
|
+
# @return [String]
|
331
|
+
def get_swytch_id
|
332
|
+
return @m_swytch_id
|
333
|
+
end
|
334
|
+
|
335
|
+
# (This method is generated in Translator_default#buildImpl)
|
336
|
+
#
|
337
|
+
# @private
|
338
|
+
# @param [String] v
|
339
|
+
# @return [String]
|
340
|
+
def set_swytch_id(v)
|
341
|
+
Saklient::Util::validate_type(v, 'String')
|
342
|
+
raise Saklient::Errors::SaklientException.new('immutable_field', 'Immutable fields cannot be modified after the resource creation: ' + 'Saklient::Cloud::Resources::Iface#swytch_id') if !@is_new
|
343
|
+
@m_swytch_id = v
|
344
|
+
@n_swytch_id = true
|
345
|
+
return @m_swytch_id
|
346
|
+
end
|
347
|
+
|
348
|
+
public
|
349
|
+
|
350
|
+
# このインタフェースの接続先スイッチのID
|
351
|
+
#
|
352
|
+
# @return [String]
|
353
|
+
attr_accessor :swytch_id
|
354
|
+
|
355
|
+
def swytch_id
|
356
|
+
get_swytch_id
|
357
|
+
end
|
358
|
+
|
359
|
+
def swytch_id=(v)
|
360
|
+
set_swytch_id(v)
|
361
|
+
end
|
362
|
+
|
363
|
+
protected
|
364
|
+
|
319
365
|
# (This method is generated in Translator_default#buildImpl)
|
320
366
|
#
|
321
367
|
# @param [any] r
|
@@ -358,6 +404,13 @@ module Saklient
|
|
358
404
|
@is_incomplete = true
|
359
405
|
end
|
360
406
|
@n_server_id = false
|
407
|
+
if Saklient::Util::exists_path(r, 'Switch.ID')
|
408
|
+
@m_swytch_id = (Saklient::Util::get_by_path(r, 'Switch.ID')).nil? ? nil : Saklient::Util::get_by_path(r, 'Switch.ID').to_s
|
409
|
+
else
|
410
|
+
@m_swytch_id = nil
|
411
|
+
@is_incomplete = true
|
412
|
+
end
|
413
|
+
@n_swytch_id = false
|
361
414
|
end
|
362
415
|
|
363
416
|
# @private
|
@@ -376,6 +429,7 @@ module Saklient
|
|
376
429
|
else
|
377
430
|
missing << 'server_id' if @is_new
|
378
431
|
end
|
432
|
+
Saklient::Util::set_by_path(ret, 'Switch.ID', @m_swytch_id) if withClean || @n_swytch_id
|
379
433
|
raise Saklient::Errors::SaklientException.new('required_field', 'Required fields must be set before the Iface creation: ' + missing.join(', ')) if missing.length > 0
|
380
434
|
return ret
|
381
435
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# This code is automatically transpiled by Saklient Translator
|
4
4
|
|
5
|
+
require_relative '../client'
|
5
6
|
require_relative 'activity'
|
6
7
|
require_relative 'iface_activity_sample'
|
7
8
|
|
@@ -48,6 +49,17 @@ module Saklient
|
|
48
49
|
return '/monitor'
|
49
50
|
end
|
50
51
|
|
52
|
+
public
|
53
|
+
|
54
|
+
# @private
|
55
|
+
# @param [Saklient::Cloud::Client] client
|
56
|
+
def initialize(client)
|
57
|
+
super(client)
|
58
|
+
Saklient::Util::validate_type(client, 'Saklient::Cloud::Client')
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
51
63
|
# @private
|
52
64
|
# @param [String] atStr
|
53
65
|
# @param [any] data
|
@@ -110,6 +110,13 @@ module Saklient
|
|
110
110
|
def _on_before_save(query)
|
111
111
|
end
|
112
112
|
|
113
|
+
# @private
|
114
|
+
# @param [any] r
|
115
|
+
# @param [any] root
|
116
|
+
# @return [void]
|
117
|
+
def _on_before_api_deserialize(r, root)
|
118
|
+
end
|
119
|
+
|
113
120
|
# @private
|
114
121
|
# @param [any] r
|
115
122
|
# @param [any] root
|
@@ -161,6 +168,7 @@ module Saklient
|
|
161
168
|
record = obj[rkey.to_sym]
|
162
169
|
end
|
163
170
|
end
|
171
|
+
_on_before_api_deserialize(record, root)
|
164
172
|
api_deserialize_impl(record)
|
165
173
|
_on_after_api_deserialize(record, root)
|
166
174
|
end
|
@@ -251,8 +259,11 @@ module Saklient
|
|
251
259
|
# @private
|
252
260
|
# @return [Resource] this
|
253
261
|
def _reload
|
254
|
-
|
255
|
-
|
262
|
+
id = _id
|
263
|
+
if !(id).nil?
|
264
|
+
result = request_retry('GET', _api_path + '/' + Saklient::Util::url_encode(id))
|
265
|
+
api_deserialize(result, true)
|
266
|
+
end
|
256
267
|
return self
|
257
268
|
end
|
258
269
|
|
@@ -166,19 +166,21 @@ module Saklient
|
|
166
166
|
def sleep_while_creating(timeoutSec = 120)
|
167
167
|
Saklient::Util::validate_type(timeoutSec, 'Fixnum')
|
168
168
|
step = 3
|
169
|
+
isOk = false
|
169
170
|
while 0 < timeoutSec do
|
170
171
|
begin
|
171
172
|
if exists
|
172
173
|
reload
|
173
|
-
|
174
|
+
isOk = true
|
174
175
|
end
|
175
176
|
rescue Saklient::Errors::HttpException
|
176
177
|
{}
|
177
178
|
end
|
178
179
|
timeoutSec -= step
|
180
|
+
timeoutSec = 0 if isOk
|
179
181
|
sleep(step) if 0 < timeoutSec
|
180
182
|
end
|
181
|
-
return
|
183
|
+
return isOk
|
182
184
|
end
|
183
185
|
|
184
186
|
# このルータが接続されているスイッチを取得します.
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# This code is automatically transpiled by Saklient Translator
|
4
4
|
|
5
|
+
require_relative '../client'
|
5
6
|
require_relative 'activity'
|
6
7
|
require_relative 'router_activity_sample'
|
7
8
|
|
@@ -42,6 +43,17 @@ module Saklient
|
|
42
43
|
return '/internet'
|
43
44
|
end
|
44
45
|
|
46
|
+
public
|
47
|
+
|
48
|
+
# @private
|
49
|
+
# @param [Saklient::Cloud::Client] client
|
50
|
+
def initialize(client)
|
51
|
+
super(client)
|
52
|
+
Saklient::Util::validate_type(client, 'Saklient::Cloud::Client')
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
|
45
57
|
# @private
|
46
58
|
# @param [String] atStr
|
47
59
|
# @param [any] data
|
@@ -155,6 +155,26 @@ module Saklient
|
|
155
155
|
|
156
156
|
protected
|
157
157
|
|
158
|
+
# @private
|
159
|
+
# @param [any] r
|
160
|
+
# @param [any] root
|
161
|
+
# @return [void]
|
162
|
+
def _on_before_api_deserialize(r, root)
|
163
|
+
return nil if (r).nil?
|
164
|
+
id = r[:ID]
|
165
|
+
ifaces = r[:Interfaces]
|
166
|
+
if !(ifaces).nil?
|
167
|
+
for iface in ifaces
|
168
|
+
server = iface[:Server]
|
169
|
+
if (server).nil?
|
170
|
+
server = {}
|
171
|
+
iface[:Server] = server
|
172
|
+
end
|
173
|
+
server[:ID] = id
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
158
178
|
# @private
|
159
179
|
# @param [any] r
|
160
180
|
# @param [any] root
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# This code is automatically transpiled by Saklient Translator
|
4
4
|
|
5
|
+
require_relative '../client'
|
5
6
|
require_relative 'activity'
|
6
7
|
require_relative 'server_activity_sample'
|
7
8
|
|
@@ -42,6 +43,17 @@ module Saklient
|
|
42
43
|
return '/server'
|
43
44
|
end
|
44
45
|
|
46
|
+
public
|
47
|
+
|
48
|
+
# @private
|
49
|
+
# @param [Saklient::Cloud::Client] client
|
50
|
+
def initialize(client)
|
51
|
+
super(client)
|
52
|
+
Saklient::Util::validate_type(client, 'Saklient::Cloud::Client')
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
|
45
57
|
# @private
|
46
58
|
# @param [String] atStr
|
47
59
|
# @param [any] data
|
data/lib/saklient/util.rb
CHANGED
data/lib/saklient/version.rb
CHANGED
data/spec/gslb_spec.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
$: << File.dirname(__dir__) + '/lib'
|
2
|
+
require 'saklient/cloud/api'
|
3
|
+
require 'date'
|
4
|
+
require 'SecureRandom'
|
5
|
+
|
6
|
+
describe 'GSLB' do
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
before do
|
11
|
+
|
12
|
+
# load config file
|
13
|
+
root = File.dirname(__dir__)
|
14
|
+
test_ok_file = root + '/testok'
|
15
|
+
expect(File).to exist(test_ok_file)
|
16
|
+
config_file = root + '/config.sh'
|
17
|
+
expect(File).to exist(config_file)
|
18
|
+
@config = {}
|
19
|
+
fh = open(config_file)
|
20
|
+
fh.each {|line|
|
21
|
+
if /^\s*export\s+(\w+)\s*=\s*(.+?)\s*$/.match(line) then
|
22
|
+
key = $1
|
23
|
+
value = $2
|
24
|
+
@config[key.to_sym] = value.gsub(/'([^']*)'|"([^"]*)"|\\(.)|(.)/) {|m|
|
25
|
+
$1 || $2 || $3 || $4
|
26
|
+
}
|
27
|
+
end
|
28
|
+
}
|
29
|
+
fh.close
|
30
|
+
expect(@config[:SACLOUD_TOKEN]).not_to be_empty #'SACLOUD_TOKEN must be defined in config.sh'
|
31
|
+
expect(@config[:SACLOUD_SECRET]).not_to be_empty #'SACLOUD_SECRET must be defined in config.sh'
|
32
|
+
#expect(@config[:SACLOUD_ZONE]).not_to be_empty #'SACLOUD_ZONE must be defined in config.sh'
|
33
|
+
|
34
|
+
# authorize
|
35
|
+
@api = Saklient::Cloud::API::authorize(@config[:SACLOUD_TOKEN], @config[:SACLOUD_SECRET])
|
36
|
+
@api = @api.in_zone(@config[:SACLOUD_ZONE]) if @config[:SACLOUD_ZONE]
|
37
|
+
expect(@api).to be_an_instance_of Saklient::Cloud::API
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
it 'should be CRUDed' do
|
44
|
+
name = '!ruby_rspec-' + DateTime.now.strftime('%Y%m%d_%H%M%S') + '-' + SecureRandom.uuid[0, 8]
|
45
|
+
|
46
|
+
#
|
47
|
+
puts 'GSLBを作成しています...'
|
48
|
+
gslb = @api.common_service_item.create_gslb("http", 10, true)
|
49
|
+
expect(gslb).to be_an_instance_of Saklient::Cloud::Resources::Gslb
|
50
|
+
gslb.path_to_check = '/index.html'
|
51
|
+
gslb.response_expected = 200
|
52
|
+
gslb.name = name
|
53
|
+
gslb.description = 'This is a test'
|
54
|
+
gslb.save
|
55
|
+
id = gslb.id.to_i
|
56
|
+
expect(id).to be > 0
|
57
|
+
expect(gslb.name).to eq name
|
58
|
+
expect(gslb.servers.length).to eq 0
|
59
|
+
|
60
|
+
gslb = @api.common_service_item.get_by_id(id)
|
61
|
+
expect(gslb.id.to_i).to eq id
|
62
|
+
expect(gslb.path_to_check).to eq '/index.html'
|
63
|
+
expect(gslb.response_expected).to eq 200
|
64
|
+
expect(gslb.name).to eq name
|
65
|
+
expect(gslb.servers.length).to eq 0
|
66
|
+
|
67
|
+
server = gslb.add_server
|
68
|
+
server.enabled = true
|
69
|
+
server.weight = 10
|
70
|
+
server.ip_address = "49.212.82.90"
|
71
|
+
gslb.save
|
72
|
+
expect(gslb.servers.length).to eq 1
|
73
|
+
|
74
|
+
gslb = @api.common_service_item.get_by_id(id)
|
75
|
+
expect(gslb.servers.length).to eq 1
|
76
|
+
|
77
|
+
puts 'GSLBを削除しています...'
|
78
|
+
gslb.destroy
|
79
|
+
|
80
|
+
ok = false
|
81
|
+
begin
|
82
|
+
gslb = @api.common_service_item.get_by_id(id)
|
83
|
+
rescue Saklient::Errors::HttpNotFoundException
|
84
|
+
ok = true
|
85
|
+
end
|
86
|
+
fail 'GSLBが正しく削除されていません' unless ok
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
after do
|
93
|
+
@config = nil
|
94
|
+
@api = nil
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
end
|