saklient 0.0.1.1 → 0.0.2.2

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.
@@ -0,0 +1,248 @@
1
+ $: << File.dirname(__dir__) + '/lib'
2
+ require 'saklient/cloud/api'
3
+ require 'date'
4
+ require 'SecureRandom'
5
+ require 'ipaddr'
6
+
7
+ describe 'LoadBalancer' do
8
+
9
+
10
+
11
+ TESTS_CONFIG_READYMADE_LB_ID = '112600809060'
12
+
13
+ before do
14
+
15
+ # load config file
16
+ root = File.dirname(__dir__)
17
+ test_ok_file = root + '/testok'
18
+ expect(File).to exist(test_ok_file)
19
+ config_file = root + '/config.sh'
20
+ expect(File).to exist(config_file)
21
+ @config = {}
22
+ fh = open(config_file)
23
+ fh.each {|line|
24
+ if /^\s*export\s+(\w+)\s*=\s*(.+?)\s*$/.match(line) then
25
+ key = $1
26
+ value = $2
27
+ @config[key.to_sym] = value.gsub(/'([^']*)'|"([^"]*)"|\\(.)|(.)/) {|m|
28
+ $1 || $2 || $3 || $4
29
+ }
30
+ end
31
+ }
32
+ fh.close
33
+ expect(@config[:SACLOUD_TOKEN]).not_to be_empty #'SACLOUD_TOKEN must be defined in config.sh'
34
+ expect(@config[:SACLOUD_SECRET]).not_to be_empty #'SACLOUD_SECRET must be defined in config.sh'
35
+ #expect(@config[:SACLOUD_ZONE]).not_to be_empty #'SACLOUD_ZONE must be defined in config.sh'
36
+
37
+ # authorize
38
+ @api = Saklient::Cloud::API::authorize(@config[:SACLOUD_TOKEN], @config[:SACLOUD_SECRET])
39
+ @api = @api.in_zone(@config[:SACLOUD_ZONE]) if @config[:SACLOUD_ZONE]
40
+ expect(@api).to be_an_instance_of Saklient::Cloud::API
41
+
42
+ end
43
+
44
+
45
+
46
+ it 'should be CRUDed' do
47
+ name = '!ruby_rspec-' + DateTime.now.strftime('%Y%m%d_%H%M%S') + '-' + SecureRandom.uuid[0, 8]
48
+ description = 'This instance was created by saklient.ruby rspec'
49
+ tag = 'saklient-test'
50
+
51
+
52
+
53
+ # create a LB
54
+ if ! TESTS_CONFIG_READYMADE_LB_ID then
55
+
56
+ # search a switch
57
+ puts 'searching a swytch...'
58
+ swytches = @api.swytch.with_tag('lb-attached').limit(1).find()
59
+ expect(swytches.length).to be > 0
60
+ swytch = swytches[0]
61
+ expect(swytch).to be_an_instance_of Saklient::Cloud::Resources::Swytch
62
+ expect(swytch.ipv4_nets.length).to be > 0
63
+ net = swytch.ipv4_nets[0]
64
+ printf "%s/%d -> %s\n", net.address, net.mask_len, net.default_route
65
+
66
+ # create a loadbalancer
67
+ puts 'creating a LB...'
68
+ vrid = 123
69
+ lb = @api.appliance.create_load_balancer(swytch, vrid, ['133.242.255.244', '133.242.255.245'], true)
70
+
71
+ ok = false
72
+ begin
73
+ lb.save()
74
+ rescue Saklient::Errors::SaklientException
75
+ ok = true
76
+ end
77
+ fail 'Requiredフィールドが未set時は SaklientException がスローされなければなりません' unless ok
78
+ lb.name = name
79
+ lb.description = ''
80
+ lb.tags = [tag]
81
+ lb.save
82
+
83
+ lb.reload
84
+ expect(lb.default_route).to eq net.default_route
85
+ expect(lb.mask_len).to eq net.mask_len
86
+ expect(lb.vrid).to eq vrid
87
+ expect(lb.swytch_id).to eq swytch.id
88
+
89
+ # wait the LB becomes up
90
+ puts 'waiting the LB becomes up...'
91
+ fail 'ロードバランサが正常に起動しません' unless lb.sleep_until_up
92
+
93
+ else
94
+
95
+ lb = @api.appliance.get_by_id(TESTS_CONFIG_READYMADE_LB_ID)
96
+ expect(lb).to be_an_instance_of Saklient::Cloud::Resources::LoadBalancer
97
+ swytch = lb.get_swytch
98
+ expect(swytch).to be_an_instance_of Saklient::Cloud::Resources::Swytch
99
+ net = swytch.ipv4_nets[0]
100
+ expect(net).to be_an_instance_of Saklient::Cloud::Resources::Ipv4Net
101
+ printf "%s/%d -> %s\n", net.address, net.mask_len, net.default_route
102
+
103
+ end
104
+
105
+
106
+
107
+ # clear virtual ips
108
+
109
+ lb.clear_virtual_ips
110
+ lb.save
111
+ lb.reload
112
+ expect(lb.virtual_ips.length).to eq 0
113
+
114
+
115
+
116
+ # setting virtual ips test 1
117
+
118
+ vip1Ip = IPAddr.new(IPAddr.new(net.default_route).to_i + 5, Socket::AF_INET).to_s
119
+ vip1SrvIp1 = IPAddr.new(IPAddr.new(net.default_route).to_i + 6, Socket::AF_INET).to_s
120
+ vip1SrvIp2 = IPAddr.new(IPAddr.new(net.default_route).to_i + 7, Socket::AF_INET).to_s
121
+ vip1SrvIp3 = IPAddr.new(IPAddr.new(net.default_route).to_i + 8, Socket::AF_INET).to_s
122
+ vip1SrvIp4 = IPAddr.new(IPAddr.new(net.default_route).to_i + 9, Socket::AF_INET).to_s
123
+
124
+ lb.add_virtual_ip({
125
+ :vip => vip1Ip,
126
+ :port => 80,
127
+ :delay => 15,
128
+ :servers => [
129
+ { :ip=>vip1SrvIp1, :port=>80, :protocol=>'http', :path_to_check=>'/index.html', :response_expected=>200 },
130
+ { :ip=>vip1SrvIp2, :port=>80, :protocol=>'https', :path_to_check=>'/', :response_expected=>200 },
131
+ { :ip=>vip1SrvIp3, :port=>80, :protocol=>'tcp' }
132
+ ]
133
+ })
134
+
135
+ vip2Ip = IPAddr.new(IPAddr.new(net.default_route).to_i + 10, Socket::AF_INET).to_s
136
+ vip2SrvIp1 = IPAddr.new(IPAddr.new(net.default_route).to_i + 11, Socket::AF_INET).to_s
137
+ vip2SrvIp2 = IPAddr.new(IPAddr.new(net.default_route).to_i + 12, Socket::AF_INET).to_s
138
+
139
+ vip2 = lb.add_virtual_ip
140
+ vip2.virtual_ip_address = vip2Ip
141
+ vip2.port = 80
142
+ vip2.delay_loop = 15
143
+ vip2Srv1 = vip2.add_server
144
+ vip2Srv1.ip_address = vip2SrvIp1
145
+ vip2Srv1.port = 80
146
+ vip2Srv1.protocol = 'http'
147
+ vip2Srv1.path_to_check = '/index.html'
148
+ vip2Srv1.response_expected = 200
149
+ vip2Srv2 = vip2.add_server
150
+ vip2Srv2.ip_address = vip2SrvIp2
151
+ vip2Srv2.port = 80
152
+ vip2Srv2.protocol = 'tcp'
153
+ lb.save
154
+ lb.reload
155
+
156
+ expect(lb.virtual_ips.length).to eq 2
157
+ expect(lb.virtual_ips[0].virtual_ip_address).to eq vip1Ip
158
+ expect(lb.virtual_ips[0].servers.length).to eq 3
159
+ expect(lb.virtual_ips[0].servers[0].ip_address).to eq vip1SrvIp1
160
+ expect(lb.virtual_ips[0].servers[0].port).to eq 80
161
+ expect(lb.virtual_ips[0].servers[0].protocol).to eq 'http'
162
+ expect(lb.virtual_ips[0].servers[0].path_to_check).to eq '/index.html'
163
+ expect(lb.virtual_ips[0].servers[0].response_expected).to eq 200
164
+ expect(lb.virtual_ips[0].servers[1].ip_address).to eq vip1SrvIp2
165
+ expect(lb.virtual_ips[0].servers[1].port).to eq 80
166
+ expect(lb.virtual_ips[0].servers[1].protocol).to eq 'https'
167
+ expect(lb.virtual_ips[0].servers[1].path_to_check).to eq '/'
168
+ expect(lb.virtual_ips[0].servers[1].response_expected).to eq 200
169
+ expect(lb.virtual_ips[0].servers[2].ip_address).to eq vip1SrvIp3
170
+ expect(lb.virtual_ips[0].servers[2].port).to eq 80
171
+ expect(lb.virtual_ips[0].servers[2].protocol).to eq 'tcp'
172
+ expect(lb.virtual_ips[1].virtual_ip_address).to eq vip2Ip
173
+ expect(lb.virtual_ips[1].servers.length).to eq 2
174
+ expect(lb.virtual_ips[1].servers[0].ip_address).to eq vip2SrvIp1
175
+ expect(lb.virtual_ips[1].servers[0].port).to eq 80
176
+ expect(lb.virtual_ips[1].servers[0].protocol).to eq 'http'
177
+ expect(lb.virtual_ips[1].servers[0].path_to_check).to eq '/index.html'
178
+ expect(lb.virtual_ips[1].servers[0].response_expected).to eq 200
179
+ expect(lb.virtual_ips[1].servers[1].ip_address).to eq vip2SrvIp2
180
+ expect(lb.virtual_ips[1].servers[1].port).to eq 80
181
+ expect(lb.virtual_ips[1].servers[1].protocol).to eq 'tcp'
182
+
183
+
184
+
185
+ # setting virtual ips test 2
186
+
187
+ lb.get_virtual_ip_by_address(vip1Ip).add_server({
188
+ :ip => vip1SrvIp4,
189
+ :port => 80,
190
+ :protocol => 'ping'
191
+ })
192
+ lb.save
193
+ lb.reload
194
+
195
+ expect(lb.virtual_ips.length).to eq 2
196
+ expect(lb.virtual_ips[0].servers.length).to eq 4
197
+ expect(lb.virtual_ips[0].servers[3].ip_address).to eq vip1SrvIp4
198
+ expect(lb.virtual_ips[0].servers[3].port).to eq 80
199
+ expect(lb.virtual_ips[0].servers[3].protocol).to eq 'ping'
200
+ expect(lb.virtual_ips[1].servers.length).to eq 2
201
+
202
+
203
+
204
+ # checking status
205
+
206
+ lb.reload_status
207
+ for vip in lb.virtual_ips do
208
+ printf " vip %s:%s every %ssec(s)\n", vip.virtual_ip_address, vip.port, vip.delay_loop
209
+ for server in vip.servers do
210
+ printf ' [%s(%s)]', server.status, server.active_connections
211
+ printf ' server %s://%s', server.protocol, server.ip_address
212
+ printf ':%d', server.port if server.port
213
+ print server.path_to_check if server.path_to_check
214
+ print ' answers'
215
+ printf ' %d', server.response_expected if server.response_expected
216
+ print "\n"
217
+ expect(server.status).to eq 'down'
218
+ end
219
+ end
220
+
221
+
222
+
223
+ # delete the LB
224
+ if ! TESTS_CONFIG_READYMADE_LB_ID then
225
+
226
+ # stop the LB
227
+ sleep 1
228
+ puts 'stopping the LB...'
229
+ fail 'ロードバランサが正常に停止しません' unless lb.stop.sleep_until_down
230
+
231
+ # delete the LB
232
+ puts 'deleting the LB...'
233
+ lb.destroy
234
+
235
+ end
236
+
237
+ end
238
+
239
+
240
+
241
+ after do
242
+ @config = nil
243
+ @api = nil
244
+ end
245
+
246
+
247
+
248
+ end
data/spec/router_spec.rb CHANGED
@@ -48,7 +48,7 @@ describe 'Router' do
48
48
 
49
49
  #
50
50
  swytch = nil
51
- if false then
51
+ if true then
52
52
  puts 'ルータ+スイッチの帯域プランを検索しています...'
53
53
  plans = @api.product.router.find
54
54
  min_mbps = 0x7FFFFFFF
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.1.1
4
+ version: 0.0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - townewgokgok
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-26 00:00:00.000000000 Z
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -194,6 +194,9 @@ files:
194
194
  - lib/saklient/cloud/resources/ipv4_net.rb
195
195
  - lib/saklient/cloud/resources/ipv6_net.rb
196
196
  - lib/saklient/cloud/resources/iso_image.rb
197
+ - lib/saklient/cloud/resources/lb_server.rb
198
+ - lib/saklient/cloud/resources/lb_virtual_ip.rb
199
+ - lib/saklient/cloud/resources/load_balancer.rb
197
200
  - lib/saklient/cloud/resources/resource.rb
198
201
  - lib/saklient/cloud/resources/router.rb
199
202
  - lib/saklient/cloud/resources/router_plan.rb
@@ -202,6 +205,7 @@ files:
202
205
  - lib/saklient/cloud/resources/server_instance.rb
203
206
  - lib/saklient/cloud/resources/server_plan.rb
204
207
  - lib/saklient/cloud/resources/swytch.rb
208
+ - lib/saklient/cloud/resources/vpc_router.rb
205
209
  - lib/saklient/errors/exception_factory.rb
206
210
  - lib/saklient/errors/http_bad_gateway_exception.rb
207
211
  - lib/saklient/errors/http_bad_request_exception.rb
@@ -243,6 +247,7 @@ files:
243
247
  - spec/enum_spec.rb
244
248
  - spec/exception_spec.rb
245
249
  - spec/iso_image_spec.rb
250
+ - spec/loadbalancer_spec.rb
246
251
  - spec/router_spec.rb
247
252
  - spec/server_spec.rb
248
253
  - spec/util_spec.rb
@@ -276,6 +281,8 @@ test_files:
276
281
  - spec/enum_spec.rb
277
282
  - spec/exception_spec.rb
278
283
  - spec/iso_image_spec.rb
284
+ - spec/loadbalancer_spec.rb
279
285
  - spec/router_spec.rb
280
286
  - spec/server_spec.rb
281
287
  - spec/util_spec.rb
288
+ has_rdoc: