hyperb 0.2.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 451eaa5bd6d96d215b204e67b80b087048cf5b91
4
- data.tar.gz: c4b03081daa2592a264504f31028cb94fc49d813
3
+ metadata.gz: 9200fb1c5348757773d70f6940a0e10cbee1564d
4
+ data.tar.gz: e15cc748b6142cb74c6fdcf34a82f8954eb0b448
5
5
  SHA512:
6
- metadata.gz: c23a4d03fb11785c4beb7529adf6342df4c2ad04fac7cd36a953626c4ab8dbef8c380fe2cebfc96e2251e3540fd64bac83c5b6c1af1bed3ea406f3d6d0941848
7
- data.tar.gz: 94ca447128b1273a91449c32cef90d20f414ab5e7ce2c5337f799c63d96b1095a38704dccbf625bd3a41b7f621bb01abea6d29f34a8bdf49c86e708caf536f5c
6
+ metadata.gz: 15bfbc0569c83146c717d82a641830a1d6d94f23f2e77bd543dcda5066f8aa652d3a0425634391ab150dc292b3900b5318e005d81ac5e614ba4077af9add91bf
7
+ data.tar.gz: 6a62201383ce5e56f50219daf4f2a83d3b76380cb9c313a8c077a615fc074f3e327addc4b865bf9aedc3f9049abc5349b7b0e2d1b2c7c8f8829e2f2ef1975850
data/Makefile CHANGED
@@ -1,5 +1,8 @@
1
1
  .PHONY: test
2
2
 
3
+ r:
4
+ docker run --rm -it -v $(PWD):/usr/src hyperb bundle exec ruby test.rb
5
+
3
6
  build:
4
7
  docker build -t hyperb .
5
8
 
@@ -13,4 +16,4 @@ rake:
13
16
  docker run --rm -it -v $(PWD):/usr/src hyperb bundle exec rake
14
17
 
15
18
  rubocop:
16
- docker run --rm -it -v $(PWD):/usr/src hyperb bundle exec rake rubocop
19
+ docker run --rm -it -v $(PWD):/usr/src hyperb bundle exec rake rubocop
data/README.md CHANGED
@@ -142,6 +142,7 @@ For more usage examples, please see the full [documentation]().
142
142
  * floating ip list
143
143
  * floating ip attach
144
144
  * floating ip detach
145
+ * floating ip name
145
146
 
146
147
  ### Compose
147
148
 
@@ -158,6 +159,8 @@ For more usage examples, please see the full [documentation]().
158
159
 
159
160
  * create service
160
161
  * remove service
162
+ * inspect service
163
+ * list services
161
164
 
162
165
  ### Misc.
163
166
 
data/circle.yml CHANGED
@@ -3,11 +3,9 @@ dependencies:
3
3
  - 'rvm-exec 2.2.0 bundle install'
4
4
  - 'rvm-exec 2.3.0 bundle install'
5
5
  - 'rvm-exec 2.4.0 bundle install'
6
- - 'rvm-exec ruby-head bundle install'
7
6
 
8
7
  test:
9
8
  override:
10
9
  - 'rvm-exec 2.2.0 bundle exec rake'
11
10
  - 'rvm-exec 2.3.0 bundle exec rake'
12
- - 'rvm-exec 2.4.0 bundle exec rake'
13
- - 'rvm-exec ruby-head bundle exec rake'
11
+ - 'rvm-exec 2.4.0 bundle exec rake'
data/examples/README.md CHANGED
@@ -284,6 +284,12 @@ Returns an array of floating ip objects
284
284
  client.fips_ls
285
285
  ```
286
286
 
287
+ #### fip_name
288
+
289
+ ```ruby
290
+ client.fip_name ip: '8.8.8.8', name: 'proxy'
291
+ ```
292
+
287
293
  #### fip_detach
288
294
 
289
295
  ```ruby
@@ -341,6 +347,22 @@ client.remove_service name: 'srvc1'
341
347
  client.remove_service name: 'srvc1', keep: true
342
348
  ````
343
349
 
350
+ #### services
351
+
352
+ Returns an Array of downcased symbols
353
+
354
+ ```ruby
355
+ client.services
356
+ ```
357
+
358
+ #### inspect_service
359
+
360
+ Returns an Hash containing service fields
361
+
362
+ ```ruby
363
+ client.inspect_service(name: 'srvc1')
364
+ ```
365
+
344
366
  ## Snapshot API
345
367
 
346
368
  Return hash containing snapshot information
@@ -57,7 +57,7 @@ module Hyperb
57
57
 
58
58
  # remove the container id
59
59
  #
60
- # @see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Container/delete.html
60
+ # @see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Container/remove.html
61
61
  #
62
62
  # @raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
63
63
  # @raise [Hyperb::Error::NotFound] raised when container can't be found.
@@ -98,5 +98,27 @@ module Hyperb
98
98
  fips = JSON.parse(Hyperb::Request.new(self, path, query, 'post').perform)
99
99
  fips
100
100
  end
101
+
102
+ # set a name for floating ip
103
+ #
104
+ # @see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Network/fip_name.html
105
+ #
106
+ # @raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
107
+ # @raise [Hyperb::Error::NotFound] raised when fip is not found
108
+ # @raise [Hyperb::Error::Conflict] raised when name already exists
109
+ # @raise [Hyperb::Error::InternalServerError] raised when server returns 5xx
110
+ #
111
+ #
112
+ # @param params [Hash] A customizable set of params.
113
+ # @option params [String] :ip fip
114
+ # @option params [String] :name the name
115
+ def fip_name(params = {})
116
+ raise ArgumentError, 'Invalid Arguments' unless check_arguments(params, 'ip', 'name')
117
+ path = '/fips/name'
118
+ query = {}
119
+ query[:ip] = params[:ip] if params.key?(:ip)
120
+ query[:name] = params[:name] if params.key?(:name)
121
+ Hyperb::Request.new(self, path, query, 'post').perform
122
+ end
101
123
  end
102
124
  end
@@ -18,20 +18,23 @@ module Hyperb
18
18
  # @return [Hash] Hash containing service information.
19
19
  #
20
20
  # @param params [Hash] A customizable set of params.
21
- # @param params image [String] service name
22
- # @param params name [String] image name
23
- # @param params replicas [Fixnum] numer of replicas
24
- # @param params service_port [Fixnum] service port
25
- # @param params container_port [Fixnum] container port
26
- # @param params labels [Hash] hash containing labels
27
- # @param params entrypoint [String] entrypoint
28
- # @param params cmd [String] command
29
- # @param params env [Array] array of envs ["env=value", ["env2=value"]]
30
- # @param params algorithm [String] algorithm of the service, 'roundrobin', 'leastconn'
31
- # @param params protocol [String] prot
32
- # @param params workingdir [String] working directory
21
+ # @param params [String] :image service name
22
+ # @param params [String] :name image name
23
+ # @param params [Fixnum] :replicas numer of replicas
24
+ # @param params [Fixnum] :serviceport service port
25
+ # @param params [Fixnum] :containerport container port
26
+ # @param params [Hash] :labels hash containing labels
27
+ # @param params [String] :entrypoint entrypoint
28
+ # @param params [String] :cmd command
29
+ # @param params [Boolean] :stdin keep STDIN open even if not attached.
30
+ # @param params [Array] :env array of envs ["env=value", ["env2=value"]]
31
+ # @param params [String] :algorithm algorithm of the service, 'roundrobin', 'leastconn'
32
+ # @param params [String] :protocol prot
33
+ # @param params [String] :workingdir working directory
34
+ # @param params [Boolean] :sessionaffinity whether the service uses sticky sessions.
35
+ # @param params [String] :securitygroups security group for the container.
33
36
  def create_service(params = {})
34
- valid = check_arguments(params, 'name', 'image', 'replicas', 'service_port', 'labels')
37
+ valid = check_arguments(params, 'name', 'image', 'replicas', 'serviceport', 'labels')
35
38
  raise ArgumentError, 'Invalid arguments.' unless valid
36
39
  path = '/services/create'
37
40
  body = {}
@@ -55,5 +58,32 @@ module Hyperb
55
58
  query[:keep] = params[:keep] if params.key?(:keep)
56
59
  Hyperb::Request.new(self, path, query, 'delete').perform
57
60
  end
61
+
62
+ # inspect a service
63
+ #
64
+ # @see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Service/inspect.html
65
+ #
66
+ # @raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
67
+ # @raise [Hyperb::Error::InternalServerError] raised hyper returns 5xx.
68
+ #
69
+ # @param params [Hash] A customizable set of params.
70
+ # @option params [String] :name service name.
71
+ def inspect_service(params = {})
72
+ valid = check_arguments(params, 'name')
73
+ raise ArgumentError, 'Invalid arguments.' unless valid
74
+ path = '/services/' + params[:name]
75
+ downcase_symbolize(JSON.parse(Hyperb::Request.new(self, path, {}, 'get').perform))
76
+ end
77
+
78
+ # list service
79
+ #
80
+ # @see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Service/list.html
81
+ #
82
+ # @raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
83
+ # @raise [Hyperb::Error::InternalServerError] raised hyper returns 5xx.
84
+ def services
85
+ path = '/services'
86
+ downcase_symbolize(JSON.parse(Hyperb::Request.new(self, path, {}, 'get').perform))
87
+ end
58
88
  end
59
89
  end
@@ -1,3 +1,3 @@
1
1
  module Hyperb
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.3.3'.freeze
3
3
  end
@@ -0,0 +1,39 @@
1
+ {
2
+ "Name": "http",
3
+ "Image": "nginx",
4
+ "WorkingDir": "",
5
+ "ContainerSize": "s4",
6
+ "SSLCert": "",
7
+ "NetMode": "bridge",
8
+ "StopSignal": "SIGTERM",
9
+ "ServicePort": 80,
10
+ "ContainerPort": 80,
11
+ "Replicas": 3,
12
+ "HealthCheckInterval": 3,
13
+ "HealthCheckFall": 3,
14
+ "HealthCheckRise": 2,
15
+ "Algorithm": "roundrobin",
16
+ "Protocol": "tcp",
17
+ "Stdin": false,
18
+ "Tty": false,
19
+ "SessionAffinity": false,
20
+ "Entrypoint": [],
21
+ "Cmd": [],
22
+ "Env": [],
23
+ "Volumes": {},
24
+ "Labels": {
25
+ "app": "nginx"
26
+ },
27
+ "SecurityGroups": {},
28
+ "IP": "172.16.55.36",
29
+ "Tenant": "b8dc36865f4b480683dabb25598d61c4",
30
+ "FIP": "",
31
+ "Message": "Scaling complete",
32
+ "Created": "2016-10-08T12:08:33.934Z",
33
+ "Status": "active",
34
+ "Containers": [
35
+ "33cd52f7af63391c9b9eb578130bd46f65f3e2c00ccbe80b9ee882cf40c6043b",
36
+ "54e3d0724f1d2b4429b08e3192c9ba13c93bd8d9077b391e6129e976eb713b7e",
37
+ "a35a66d91e0c0740e36f9f2e43db406fefe964f5a483a8137d9c08472860a53e"
38
+ ]
39
+ }
@@ -0,0 +1,41 @@
1
+ [
2
+ {
3
+ "Name": "http",
4
+ "Image": "nginx",
5
+ "WorkingDir": "",
6
+ "ContainerSize": "s4",
7
+ "SSLCert": "",
8
+ "NetMode": "bridge",
9
+ "StopSignal": "SIGTERM",
10
+ "ServicePort": 80,
11
+ "ContainerPort": 80,
12
+ "Replicas": 3,
13
+ "HealthCheckInterval": 3,
14
+ "HealthCheckFall": 3,
15
+ "HealthCheckRise": 2,
16
+ "Algorithm": "roundrobin",
17
+ "Protocol": "tcp",
18
+ "Stdin": false,
19
+ "Tty": false,
20
+ "SessionAffinity": false,
21
+ "Entrypoint": [],
22
+ "Cmd": [],
23
+ "Env": [],
24
+ "Volumes": {},
25
+ "Labels": {
26
+ "app": "nginx"
27
+ },
28
+ "SecurityGroups": {},
29
+ "IP": "172.16.55.36",
30
+ "Tenant": "b8dc36865f4b480683dabb25598d61c4",
31
+ "FIP": "",
32
+ "Message": "Scaling complete",
33
+ "Created": "2016-10-08T12:08:33.934Z",
34
+ "Status": "active",
35
+ "Containers": [
36
+ "33cd52f7af63391c9b9eb578130bd46f65f3e2c00ccbe80b9ee882cf40c6043b",
37
+ "54e3d0724f1d2b4429b08e3192c9ba13c93bd8d9077b391e6129e976eb713b7e",
38
+ "a35a66d91e0c0740e36f9f2e43db406fefe964f5a483a8137d9c08472860a53e"
39
+ ]
40
+ }
41
+ ]
data/spec/network_spec.rb CHANGED
@@ -88,6 +88,26 @@ RSpec.describe Hyperb::Network do
88
88
  end
89
89
  end
90
90
 
91
+ describe '#fip_name' do
92
+
93
+ it 'should raise ArgumentError when ip is not provided' do
94
+ expect { @client.fip_name(name: 'test') }.to raise_error(ArgumentError)
95
+ end
96
+
97
+ it 'should raise ArgumentError when name is not provided' do
98
+ expect { @client.fip_name(ip: '8.8.8.8') }.to raise_error(ArgumentError)
99
+ end
100
+
101
+ it 'request to the correct path should be made' do
102
+ path = @base_path + '/name?ip=8.8.8.8&name=haproxy'
103
+ stub_request(:post, path)
104
+ .to_return(body: "")
105
+
106
+ @client.fip_name(ip: '8.8.8.8', name: 'haproxy')
107
+ expect(a_request(:post, path)).to have_been_made
108
+ end
109
+ end
110
+
91
111
  describe '#fip_release' do
92
112
 
93
113
  it 'should raise ArgumentError when ip is not provided' do
@@ -8,7 +8,57 @@ RSpec.describe Hyperb::Services do
8
8
  @base_path = Hyperb::Request::BASE_URL + Hyperb::Request::VERSION + '/services'
9
9
  end
10
10
 
11
- describe '#remove_container' do
11
+ describe '#inspect_service' do
12
+
13
+ it 'should raise ArgumentError when name is missing' do
14
+ expect { @client.inspect_service }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it 'request to the correct path should be made' do
18
+ path = @base_path + '/service1'
19
+
20
+ stub_request(:get, path)
21
+ .to_return(body: fixture('./inspect_service.json'))
22
+
23
+ @client.inspect_service(name: 'service1')
24
+ expect(a_request(:get, path)).to have_been_made
25
+ end
26
+
27
+ it 'return correct attrs' do
28
+ path = @base_path + '/service1'
29
+
30
+ stub_request(:get, path)
31
+ .to_return(body: fixture('./inspect_service.json'))
32
+
33
+ s = @client.inspect_service(name: 'service1')
34
+ expect(s.is_a?(Hash)).to be true
35
+ end
36
+ end
37
+
38
+ describe '#services' do
39
+
40
+ it 'request to the correct path should be made' do
41
+ path = @base_path
42
+
43
+ stub_request(:get, path)
44
+ .to_return(body: fixture('./services.json'))
45
+
46
+ @client.services
47
+ expect(a_request(:get, path)).to have_been_made
48
+ end
49
+
50
+ it 'return correct attrs' do
51
+ path = @base_path
52
+
53
+ stub_request(:get, path)
54
+ .to_return(body: fixture('./services.json'))
55
+
56
+ s = @client.services
57
+ expect(s.is_a?(Array)).to be true
58
+ end
59
+ end
60
+
61
+ describe '#remove_service' do
12
62
 
13
63
  it 'should raise ArgumentError when name is not provided' do
14
64
  expect { @client.remove_service }.to raise_error(ArgumentError)
@@ -61,11 +111,11 @@ RSpec.describe Hyperb::Services do
61
111
  it 'request to the correct path should be made with name' do
62
112
  path = @base_path + '/create'
63
113
  body = {
64
- service_port: 80,
114
+ serviceport: 80,
65
115
  name: 'name1',
66
116
  image: 'nginx',
67
117
  replicas: 2,
68
- container_port: 80,
118
+ containerport: 80,
69
119
  labels: {}
70
120
  }
71
121
  stub_request(:post, path)
@@ -79,12 +129,12 @@ RSpec.describe Hyperb::Services do
79
129
  it 'correct request should be made with entrypoint' do
80
130
  path = @base_path + '/create'
81
131
  body = {
82
- service_port: 80,
132
+ serviceport: 80,
83
133
  name: 'name1',
84
134
  image: 'nginx',
85
135
  replicas: 2,
86
136
  entrypoint: 'entry.sh',
87
- container_port: 80,
137
+ containerport: 80,
88
138
  labels: {}
89
139
  }
90
140
  stub_request(:post, path)
@@ -98,12 +148,12 @@ RSpec.describe Hyperb::Services do
98
148
  it 'correct request should be made with cmd' do
99
149
  path = @base_path + '/create'
100
150
  body = {
101
- service_port: 80,
151
+ serviceport: 80,
102
152
  name: 'name1',
103
153
  image: 'nginx',
104
154
  replicas: 2,
105
155
  cmd: 'echo 1',
106
- container_port: 80,
156
+ containerport: 80,
107
157
  labels: {}
108
158
  }
109
159
  stub_request(:post, path)
@@ -117,12 +167,12 @@ RSpec.describe Hyperb::Services do
117
167
  it 'correct request should be made with env' do
118
168
  path = @base_path + '/create'
119
169
  body = {
120
- service_port: 80,
170
+ serviceport: 80,
121
171
  name: 'name1',
122
172
  image: 'nginx',
123
173
  replicas: 2,
124
174
  env: ['ENV=123'],
125
- container_port: 80,
175
+ containerport: 80,
126
176
  labels: {}
127
177
  }
128
178
  stub_request(:post, path)
@@ -136,12 +186,12 @@ RSpec.describe Hyperb::Services do
136
186
  it 'correct request should be made with protocol' do
137
187
  path = @base_path + '/create'
138
188
  body = {
139
- service_port: 80,
189
+ serviceport: 80,
140
190
  name: 'name1',
141
191
  image: 'nginx',
142
192
  replicas: 2,
143
193
  protocol: 'https',
144
- container_port: 80,
194
+ containerport: 80,
145
195
  labels: {}
146
196
  }
147
197
  stub_request(:post, path)
@@ -155,11 +205,11 @@ RSpec.describe Hyperb::Services do
155
205
  it 'correct request should be made with algorithm' do
156
206
  path = @base_path + '/create'
157
207
  body = {
158
- service_port: 80,
208
+ serviceport: 80,
159
209
  name: 'name1',
160
210
  image: 'nginx',
161
211
  replicas: 2,
162
- container_port: 80,
212
+ containerport: 80,
163
213
  algorithm: 'roundrobin',
164
214
  labels: {}
165
215
  }
@@ -174,12 +224,12 @@ RSpec.describe Hyperb::Services do
174
224
  it 'correct request should be made with workingdir' do
175
225
  path = @base_path + '/create'
176
226
  body = {
177
- service_port: 80,
227
+ serviceport: 80,
178
228
  name: 'name1',
179
229
  workingdir: '/path',
180
230
  image: 'nginx',
181
231
  replicas: 2,
182
- container_port: 80,
232
+ containerport: 80,
183
233
  labels: {}
184
234
  }
185
235
  stub_request(:post, path)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - drish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-14 00:00:00.000000000 Z
11
+ date: 2017-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -180,9 +180,11 @@ files:
180
180
  - spec/fixtures/images.json
181
181
  - spec/fixtures/inspect_container.json
182
182
  - spec/fixtures/inspect_image.json
183
+ - spec/fixtures/inspect_service.json
183
184
  - spec/fixtures/inspect_volume.json
184
185
  - spec/fixtures/remove_container.json
185
186
  - spec/fixtures/remove_image.json
187
+ - spec/fixtures/services.json
186
188
  - spec/fixtures/volumes.json
187
189
  - spec/helper.rb
188
190
  - spec/image_spec.rb