idcf-ilb 0.0.1
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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +93 -0
- data/.travis.yml +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +111 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/idcf-ilb.gemspec +29 -0
- data/lib/idcf/ilb.rb +13 -0
- data/lib/idcf/ilb/client.rb +180 -0
- data/lib/idcf/ilb/client_extensions.rb +24 -0
- data/lib/idcf/ilb/client_extensions/config.rb +97 -0
- data/lib/idcf/ilb/client_extensions/fwgroup.rb +57 -0
- data/lib/idcf/ilb/client_extensions/job.rb +75 -0
- data/lib/idcf/ilb/client_extensions/limit.rb +24 -0
- data/lib/idcf/ilb/client_extensions/loadbalancer.rb +79 -0
- data/lib/idcf/ilb/client_extensions/log.rb +30 -0
- data/lib/idcf/ilb/client_extensions/network.rb +26 -0
- data/lib/idcf/ilb/client_extensions/server.rb +46 -0
- data/lib/idcf/ilb/client_extensions/sslalgorithm.rb +43 -0
- data/lib/idcf/ilb/client_extensions/sslcert.rb +79 -0
- data/lib/idcf/ilb/client_extensions/sslpolicy.rb +58 -0
- data/lib/idcf/ilb/client_extensions/traffic.rb +35 -0
- data/lib/idcf/ilb/client_extensions/virtualmachine.rb +29 -0
- data/lib/idcf/ilb/errors.rb +10 -0
- data/lib/idcf/ilb/request.rb +97 -0
- data/lib/idcf/ilb/resources.rb +22 -0
- data/lib/idcf/ilb/resources/base.rb +60 -0
- data/lib/idcf/ilb/resources/config.rb +21 -0
- data/lib/idcf/ilb/resources/fwgroup.rb +16 -0
- data/lib/idcf/ilb/resources/job.rb +16 -0
- data/lib/idcf/ilb/resources/limit.rb +13 -0
- data/lib/idcf/ilb/resources/loadbalancer.rb +16 -0
- data/lib/idcf/ilb/resources/log.rb +13 -0
- data/lib/idcf/ilb/resources/network.rb +9 -0
- data/lib/idcf/ilb/resources/nic.rb +13 -0
- data/lib/idcf/ilb/resources/server.rb +9 -0
- data/lib/idcf/ilb/resources/sslalgorithm.rb +21 -0
- data/lib/idcf/ilb/resources/sslcert.rb +16 -0
- data/lib/idcf/ilb/resources/sslpolicy.rb +23 -0
- data/lib/idcf/ilb/resources/traffic.rb +9 -0
- data/lib/idcf/ilb/resources/virtualmachine.rb +13 -0
- data/lib/idcf/ilb/response.rb +84 -0
- data/lib/idcf/ilb/validators.rb +22 -0
- data/lib/idcf/ilb/validators/base.rb +105 -0
- data/lib/idcf/ilb/validators/config.rb +27 -0
- data/lib/idcf/ilb/validators/fwgroup.rb +17 -0
- data/lib/idcf/ilb/validators/job.rb +18 -0
- data/lib/idcf/ilb/validators/limit.rb +17 -0
- data/lib/idcf/ilb/validators/loadbalancer.rb +26 -0
- data/lib/idcf/ilb/validators/log.rb +22 -0
- data/lib/idcf/ilb/validators/network.rb +25 -0
- data/lib/idcf/ilb/validators/server.rb +13 -0
- data/lib/idcf/ilb/validators/sslalgorithm.rb +14 -0
- data/lib/idcf/ilb/validators/sslcert.rb +24 -0
- data/lib/idcf/ilb/validators/sslpolicy.rb +17 -0
- data/lib/idcf/ilb/validators/traffic.rb +14 -0
- data/lib/idcf/ilb/validators/virtualmachine.rb +26 -0
- data/lib/idcf/ilb/version.rb +5 -0
- metadata +232 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Ilb
|
3
|
+
module Resources
|
4
|
+
# Fwgroup resource class
|
5
|
+
class Fwgroup < Base
|
6
|
+
# Refresh this fwgroup
|
7
|
+
#
|
8
|
+
# @return [Fwgroup] self object
|
9
|
+
def refresh
|
10
|
+
self.attributes = client.get_fwgroup(id).body
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Ilb
|
3
|
+
module Resources
|
4
|
+
# Loadbalancer resource class
|
5
|
+
class Loadbalancer < Base
|
6
|
+
# Refresh this loadbalancer
|
7
|
+
#
|
8
|
+
# @return [Loadbalancer] self object
|
9
|
+
def refresh
|
10
|
+
self.attributes = client.get_loadbalancer(id).body
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Ilb
|
3
|
+
module Resources
|
4
|
+
# Sslalgorithm resource class
|
5
|
+
class Sslalgorithm < Base
|
6
|
+
# Refresh this sslalgorithm
|
7
|
+
#
|
8
|
+
# @return [Sslalgorithm] self object
|
9
|
+
def refresh
|
10
|
+
self.attributes = client.get_sslalgorithm(id).body
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
# Inspect this class
|
15
|
+
def inspect
|
16
|
+
"#<#{self.class}:0x%014x @protocol=#{protocol} @cipher=#{cipher} @id=#{id}>" % [object_id]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Ilb
|
3
|
+
module Resources
|
4
|
+
# Sslcert resource class
|
5
|
+
class Sslcert < Base
|
6
|
+
# Refresh this sslcert
|
7
|
+
#
|
8
|
+
# @return [Sslcert] self object
|
9
|
+
def refresh
|
10
|
+
self.attributes = client.get_sslcert(id).body
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Ilb
|
3
|
+
module Resources
|
4
|
+
# Sslpolicy resource class
|
5
|
+
class Sslpolicy < Base
|
6
|
+
# @return [Array<Sslpolicy>] an array of sslpolicies
|
7
|
+
def algorithms
|
8
|
+
return @algorithm_objects if @algorithm_objects
|
9
|
+
refresh
|
10
|
+
@algorithm_objects = @algorithms.map { |algo| Sslalgorithm.new(client, algo) }
|
11
|
+
end
|
12
|
+
|
13
|
+
# Refresh this sslpolicy
|
14
|
+
#
|
15
|
+
# @return [Sslpolicy] self object
|
16
|
+
def refresh
|
17
|
+
self.attributes = client.get_sslpolicy(id).body
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Ilb
|
3
|
+
module Resources
|
4
|
+
# Virtualmachine resource class
|
5
|
+
class Virtualmachine < Base
|
6
|
+
# Inspect this class
|
7
|
+
def inspect
|
8
|
+
"#<#{self.class}:0x%014x @id=#{id} @name=#{name} @zone_name=#{zone_name}>" % [object_id]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
module Idcf
|
4
|
+
module Ilb
|
5
|
+
# HTTP response
|
6
|
+
class Response
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
# @!attribute [r] body
|
10
|
+
# @return [Hash, Array, nil] response body as a hash,
|
11
|
+
# an array of hashes or nil.
|
12
|
+
# @!attribute [r] headers
|
13
|
+
# @return [Hash] HTTP response headers
|
14
|
+
# @!attribute [r] status
|
15
|
+
# @return [Integer] HTTP status code
|
16
|
+
attr_reader :body, :headers, :status
|
17
|
+
|
18
|
+
# @param faraday_response [Faraday::Response]
|
19
|
+
def initialize(faraday_response)
|
20
|
+
@body = faraday_response.body
|
21
|
+
@headers = faraday_response.headers
|
22
|
+
@status = faraday_response.status
|
23
|
+
end
|
24
|
+
|
25
|
+
def_delegator :@body, :[]
|
26
|
+
|
27
|
+
# Returns the number of resources.
|
28
|
+
#
|
29
|
+
# @return [Fixnum] count of resources.
|
30
|
+
def count
|
31
|
+
case body
|
32
|
+
when Array
|
33
|
+
body.size
|
34
|
+
when Hash
|
35
|
+
body.key?("uuid") ? 1 : 0
|
36
|
+
else
|
37
|
+
0
|
38
|
+
end
|
39
|
+
end
|
40
|
+
alias size count
|
41
|
+
|
42
|
+
# Returns error message.
|
43
|
+
# When request succeed, this returns nil.
|
44
|
+
#
|
45
|
+
# @return [String] API error message
|
46
|
+
def message
|
47
|
+
if success?
|
48
|
+
nil
|
49
|
+
else
|
50
|
+
body ? self["message"] : "Resource not found."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns error reference.
|
55
|
+
# When request succeed, this returns nil.
|
56
|
+
#
|
57
|
+
# @return [String] API error reference
|
58
|
+
def reference
|
59
|
+
if success?
|
60
|
+
nil
|
61
|
+
else
|
62
|
+
body ? self["reference"] : "No reference"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns an array of resource hashes.
|
67
|
+
#
|
68
|
+
# @return [Array<Hash>] an array of resource hashes
|
69
|
+
def resources
|
70
|
+
body && [*body]
|
71
|
+
end
|
72
|
+
|
73
|
+
# @return [Boolean] request success?
|
74
|
+
def success?
|
75
|
+
status < 400
|
76
|
+
end
|
77
|
+
|
78
|
+
# @return [String] ID of a resource
|
79
|
+
def id
|
80
|
+
body.is_a?(Hash) && body.key?("id") ? self["id"] : nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Ilb
|
3
|
+
# Validators for request attributes.
|
4
|
+
module Validators
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require "idcf/ilb/validators/base"
|
10
|
+
require "idcf/ilb/validators/loadbalancer"
|
11
|
+
require "idcf/ilb/validators/config"
|
12
|
+
require "idcf/ilb/validators/server"
|
13
|
+
require "idcf/ilb/validators/job"
|
14
|
+
require "idcf/ilb/validators/sslcert"
|
15
|
+
require "idcf/ilb/validators/sslalgorithm"
|
16
|
+
require "idcf/ilb/validators/sslpolicy"
|
17
|
+
require "idcf/ilb/validators/fwgroup"
|
18
|
+
require "idcf/ilb/validators/network"
|
19
|
+
require "idcf/ilb/validators/virtualmachine"
|
20
|
+
require "idcf/ilb/validators/limit"
|
21
|
+
require "idcf/ilb/validators/log"
|
22
|
+
require "idcf/ilb/validators/traffic"
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require "active_support/core_ext/class/attribute"
|
2
|
+
|
3
|
+
module Idcf
|
4
|
+
module Ilb
|
5
|
+
module Validators
|
6
|
+
# Base validator class
|
7
|
+
class Base
|
8
|
+
class_attribute :valid_attributes
|
9
|
+
|
10
|
+
class << self
|
11
|
+
# Validate requeste attributes.
|
12
|
+
# If there are invalid attributes, error occurs.
|
13
|
+
#
|
14
|
+
# @param attributes [Hash] request attributes
|
15
|
+
# @param action [Symbol] request method
|
16
|
+
def validate_attributes!(attributes, action = nil)
|
17
|
+
validate_presence!(attributes, action)
|
18
|
+
validate_absence!(attributes, action)
|
19
|
+
validate_any!(attributes, action)
|
20
|
+
attributes.each do |name, value|
|
21
|
+
validate_attribute!(name, value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def required_attributes(action)
|
28
|
+
return [] unless action
|
29
|
+
valid_attributes.select do |_, validator|
|
30
|
+
validator[action] == :required
|
31
|
+
end.keys
|
32
|
+
end
|
33
|
+
|
34
|
+
def any_attributes(action)
|
35
|
+
return [] unless action
|
36
|
+
valid_attributes.select do |_, validator|
|
37
|
+
validator[action].to_s =~ /any_+/
|
38
|
+
end.keys
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid_attribute?(value, valid_type)
|
42
|
+
case valid_type
|
43
|
+
when Array
|
44
|
+
valid_type.any? { |t| valid_attribute?(value, t) }
|
45
|
+
when Regexp
|
46
|
+
if value.is_a?(String)
|
47
|
+
valid_type =~ value
|
48
|
+
else
|
49
|
+
false
|
50
|
+
end
|
51
|
+
else
|
52
|
+
value.is_a?(valid_type)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def validate_absence!(attributes, action)
|
57
|
+
if action
|
58
|
+
attributes.each do |name, value|
|
59
|
+
next unless !valid_attributes[name] || !valid_attributes[name][action]
|
60
|
+
raise(UnnecessaryAttribute, "`#{name}` is unnecessary in #{action} action")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def validate_attribute!(name, value)
|
66
|
+
validate_attribute_name!(name)
|
67
|
+
validate_attribute_type!(name, value)
|
68
|
+
end
|
69
|
+
|
70
|
+
def validate_attribute_name!(name)
|
71
|
+
return true if valid_attributes.key?(name.to_sym)
|
72
|
+
raise(InvalidAttributeName, "`#{name}` is invalid attribute name")
|
73
|
+
end
|
74
|
+
|
75
|
+
def validate_attribute_type!(name, value)
|
76
|
+
valid_type = valid_attributes[name.to_sym][:type]
|
77
|
+
return true if valid_attribute?(value, valid_type)
|
78
|
+
raise(InvalidAttributeType, "`#{name}` is required to be a #{valid_type}")
|
79
|
+
end
|
80
|
+
|
81
|
+
def validate_presence!(attributes, action)
|
82
|
+
required_attributes(action).each do |name|
|
83
|
+
unless attributes.key?(name)
|
84
|
+
raise(MissingAttribute, "`#{name}` is required in #{action} action")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def validate_any!(attributes, action)
|
90
|
+
check_keys = any_attributes(action)
|
91
|
+
if check_keys.empty?
|
92
|
+
else
|
93
|
+
unless attributes.values_at(*check_keys).flatten!.any?
|
94
|
+
raise(
|
95
|
+
MissingAttribute,
|
96
|
+
"[`#{check_keys.join(', ')}`], any attribute required in #{action} action"
|
97
|
+
)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Ilb
|
3
|
+
module Validators
|
4
|
+
# Config validator class
|
5
|
+
class Config < Base
|
6
|
+
self.valid_attributes = {
|
7
|
+
id: { type: String },
|
8
|
+
loadbalancer_id: { type: String },
|
9
|
+
frontend_protocol: { type: String, create: :required, patch: :optional },
|
10
|
+
port: { type: Integer, create: :required, patch: :optional },
|
11
|
+
servers: { type: Array, create: :required, patch: :optional },
|
12
|
+
backend_protocol: { type: String, create: :required, patch: :optional },
|
13
|
+
sslcert_id: { type: String, create: :optional, patch: :optional },
|
14
|
+
sslpolicy_id: { type: String, create: :optional, patch: :optional },
|
15
|
+
connection_timeout: { type: Integer, create: :required, patch: :optional },
|
16
|
+
stickiness_policy: { type: String, create: :optional, patch: :optional },
|
17
|
+
algorithm: { type: String, create: :required, patch: :optional },
|
18
|
+
healthcheck: { type: Hash, create: :required, patch: :optional },
|
19
|
+
backupserver: { type: Hash, create: :optional, patch: :optional },
|
20
|
+
state: { type: String },
|
21
|
+
created_at: { type: String },
|
22
|
+
updated_at: { type: String }
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|