idcf-ilb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +93 -0
  5. data/.travis.yml +9 -0
  6. data/CODE_OF_CONDUCT.md +49 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +111 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/idcf-ilb.gemspec +29 -0
  14. data/lib/idcf/ilb.rb +13 -0
  15. data/lib/idcf/ilb/client.rb +180 -0
  16. data/lib/idcf/ilb/client_extensions.rb +24 -0
  17. data/lib/idcf/ilb/client_extensions/config.rb +97 -0
  18. data/lib/idcf/ilb/client_extensions/fwgroup.rb +57 -0
  19. data/lib/idcf/ilb/client_extensions/job.rb +75 -0
  20. data/lib/idcf/ilb/client_extensions/limit.rb +24 -0
  21. data/lib/idcf/ilb/client_extensions/loadbalancer.rb +79 -0
  22. data/lib/idcf/ilb/client_extensions/log.rb +30 -0
  23. data/lib/idcf/ilb/client_extensions/network.rb +26 -0
  24. data/lib/idcf/ilb/client_extensions/server.rb +46 -0
  25. data/lib/idcf/ilb/client_extensions/sslalgorithm.rb +43 -0
  26. data/lib/idcf/ilb/client_extensions/sslcert.rb +79 -0
  27. data/lib/idcf/ilb/client_extensions/sslpolicy.rb +58 -0
  28. data/lib/idcf/ilb/client_extensions/traffic.rb +35 -0
  29. data/lib/idcf/ilb/client_extensions/virtualmachine.rb +29 -0
  30. data/lib/idcf/ilb/errors.rb +10 -0
  31. data/lib/idcf/ilb/request.rb +97 -0
  32. data/lib/idcf/ilb/resources.rb +22 -0
  33. data/lib/idcf/ilb/resources/base.rb +60 -0
  34. data/lib/idcf/ilb/resources/config.rb +21 -0
  35. data/lib/idcf/ilb/resources/fwgroup.rb +16 -0
  36. data/lib/idcf/ilb/resources/job.rb +16 -0
  37. data/lib/idcf/ilb/resources/limit.rb +13 -0
  38. data/lib/idcf/ilb/resources/loadbalancer.rb +16 -0
  39. data/lib/idcf/ilb/resources/log.rb +13 -0
  40. data/lib/idcf/ilb/resources/network.rb +9 -0
  41. data/lib/idcf/ilb/resources/nic.rb +13 -0
  42. data/lib/idcf/ilb/resources/server.rb +9 -0
  43. data/lib/idcf/ilb/resources/sslalgorithm.rb +21 -0
  44. data/lib/idcf/ilb/resources/sslcert.rb +16 -0
  45. data/lib/idcf/ilb/resources/sslpolicy.rb +23 -0
  46. data/lib/idcf/ilb/resources/traffic.rb +9 -0
  47. data/lib/idcf/ilb/resources/virtualmachine.rb +13 -0
  48. data/lib/idcf/ilb/response.rb +84 -0
  49. data/lib/idcf/ilb/validators.rb +22 -0
  50. data/lib/idcf/ilb/validators/base.rb +105 -0
  51. data/lib/idcf/ilb/validators/config.rb +27 -0
  52. data/lib/idcf/ilb/validators/fwgroup.rb +17 -0
  53. data/lib/idcf/ilb/validators/job.rb +18 -0
  54. data/lib/idcf/ilb/validators/limit.rb +17 -0
  55. data/lib/idcf/ilb/validators/loadbalancer.rb +26 -0
  56. data/lib/idcf/ilb/validators/log.rb +22 -0
  57. data/lib/idcf/ilb/validators/network.rb +25 -0
  58. data/lib/idcf/ilb/validators/server.rb +13 -0
  59. data/lib/idcf/ilb/validators/sslalgorithm.rb +14 -0
  60. data/lib/idcf/ilb/validators/sslcert.rb +24 -0
  61. data/lib/idcf/ilb/validators/sslpolicy.rb +17 -0
  62. data/lib/idcf/ilb/validators/traffic.rb +14 -0
  63. data/lib/idcf/ilb/validators/virtualmachine.rb +26 -0
  64. data/lib/idcf/ilb/version.rb +5 -0
  65. metadata +232 -0
@@ -0,0 +1,24 @@
1
+ module Idcf
2
+ module Ilb
3
+ # This module includes SDK API methods for Client.
4
+ module ClientExtensions
5
+ def self.symbolize_keys(hash)
6
+ hash.map { |k, v| [k.to_sym, v] }.to_h
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ require "idcf/ilb/client_extensions/loadbalancer"
13
+ require "idcf/ilb/client_extensions/config"
14
+ require "idcf/ilb/client_extensions/server"
15
+ require "idcf/ilb/client_extensions/job"
16
+ require "idcf/ilb/client_extensions/sslcert"
17
+ require "idcf/ilb/client_extensions/sslalgorithm"
18
+ require "idcf/ilb/client_extensions/sslpolicy"
19
+ require "idcf/ilb/client_extensions/fwgroup"
20
+ require "idcf/ilb/client_extensions/network"
21
+ require "idcf/ilb/client_extensions/virtualmachine"
22
+ require "idcf/ilb/client_extensions/limit"
23
+ require "idcf/ilb/client_extensions/log"
24
+ require "idcf/ilb/client_extensions/traffic"
@@ -0,0 +1,97 @@
1
+ module Idcf
2
+ module Ilb
3
+ module ClientExtensions
4
+ # SDK APIs for config resource
5
+ module Config
6
+ # Create a new loadbalancer config.
7
+ #
8
+ # @param attributes [Hash] request attributes
9
+ # @option attributes [String] :frontend_protocol (required)
10
+ # @option attributes [String] :port (required)
11
+ # @option attributes [String] :servers (required)
12
+ # @option attributes [String] :backend_protocol (required)
13
+ # @option attributes [String] :sslcert_id (optional)
14
+ # @option attributes [String] :sslpolicy_id (optional)
15
+ # @option attributes [String] :connection_timeout (required)
16
+ # @option attributes [String] :stickiness_policy (optional)
17
+ # @option attributes [String] :servers (required)
18
+ # @option attributes [String] :algorithm (required)
19
+ # @option attributes [String] :healthcheck (required)
20
+ # @option attributes [String] :backupserver (optional)
21
+ # @param headers [Hash] HTTP request headers
22
+ # @return [Response] HTTP response object
23
+ def create_config(lb_id, attributes, headers = {})
24
+ Validators::Config.validate_attributes!(attributes, :create)
25
+ res = post!("loadbalancers/#{lb_id}/configs", attributes, headers)
26
+ check_job(res.body["job_id"], headers, ["get_config", lb_id])
27
+ end
28
+
29
+ # Get list of existing configs
30
+ #
31
+ # @param lb_id [String] ID of loadbalancer
32
+ # @param headers [Hash] HTTP request headers
33
+ # @return [Response] HTTP response object
34
+ def list_configs(lb_id, headers = {})
35
+ get!("loadbalancers/#{lb_id}/configs", {}, headers)
36
+ end
37
+
38
+ # Get a config
39
+ #
40
+ # @param lb_id [String] ID of loadbalancer
41
+ # @param id [String] ID of target config
42
+ # @param headers [Hash] HTTP request headers
43
+ # @return [Response] HTTP response object
44
+ def get_config(lb_id, id, headers = {})
45
+ get!("loadbalancers/#{lb_id}/configs/#{id}", {}, headers)
46
+ end
47
+
48
+ # Patch a config
49
+ #
50
+ # @param lb_id [String] ID of loadbalancer
51
+ # @param id [String] ID of target config
52
+ # @param attributes [Hash] request attributes
53
+ # @option attributes [String] :frontend_protocol (optional)
54
+ # @option attributes [String] :port (optional)
55
+ # @option attributes [String] :servers (optional)
56
+ # @option attributes [String] :backend_protocol (optional)
57
+ # @option attributes [String] :sslcert_id (optional)
58
+ # @option attributes [String] :sslpolicy_id (optional)
59
+ # @option attributes [String] :connection_timeout (optional)
60
+ # @option attributes [String] :stickiness_policy (optional)
61
+ # @option attributes [String] :servers (optional)
62
+ # @option attributes [String] :algorithm (optional)
63
+ # @option attributes [String] :healthcheck (optional)
64
+ # @option attributes [String] :backupserver (optional)
65
+ # @param headers [Hash] HTTP request headers
66
+ # @return [Response] HTTP response object
67
+ def patch_config(lb_id, id, attributes, headers = {})
68
+ Validators::Config.validate_attributes!(attributes, :patch)
69
+ res = patch!("loadbalancers/#{lb_id}/configs/#{id}", attributes, headers)
70
+ check_job(res.body["job_id"], headers, ["get_config", lb_id])
71
+ end
72
+
73
+ # Delete a config
74
+ #
75
+ # @param lb_id [String] ID of loadbalancer
76
+ # @param id [String] ID of target config
77
+ # @param headers [Hash] HTTP request headers
78
+ # @return [Boolean] delete success = true
79
+ def delete_config(lb_id, id, headers = {})
80
+ res = delete!("loadbalancers/#{lb_id}/configs/#{id}", {}, headers)
81
+ check_job(res.body["job_id"], headers)
82
+ end
83
+
84
+ # Get an array of existing config objects.
85
+ #
86
+ # @param lb_id [String] ID of loadbalancer
87
+ # @param headers [Hash] HTTP request headers
88
+ # @return [Array<Resources::Config>] An array of config objects
89
+ def configs(lb_id, headers = {})
90
+ list_configs(lb_id, headers).resources.map do |config|
91
+ Resources::Config.new(self, config)
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,57 @@
1
+ module Idcf
2
+ module Ilb
3
+ module ClientExtensions
4
+ # SDK APIs for fwgroup resource
5
+ module Fwgroup
6
+ # Create a new fwgroup.
7
+ #
8
+ # @param attributes [Hash] request attributes
9
+ # @option attributes [String] :name unique name of fwgroup (required)
10
+ # @param headers [Hash] HTTP request headers
11
+ # @return [Response] HTTP response object
12
+ def create_fwgroup(attributes, headers = {})
13
+ Validators::Fwgroup.validate_attributes!(attributes, :create)
14
+ res = post!("fwgroups", attributes, headers)
15
+ check_job(res.body["job_id"], headers, ["get_fwgroup"])
16
+ end
17
+
18
+ # Get list of existing fwgroups
19
+ #
20
+ # @param headers [Hash] HTTP request headers
21
+ # @return [Response] HTTP response object
22
+ def list_fwgroups(headers = {})
23
+ get!("fwgroups", {}, headers)
24
+ end
25
+
26
+ # Get a fwgroup
27
+ #
28
+ # @param id [String] ID of target fwgroup
29
+ # @param headers [Hash] HTTP request headers
30
+ # @return [Response] HTTP response object
31
+ def get_fwgroup(id, headers = {})
32
+ get!("fwgroups/#{id}", {}, headers)
33
+ end
34
+
35
+ # Delete a fwgroup
36
+ #
37
+ # @param id [String] ID of target fwgroup
38
+ # @param headers [Hash] HTTP request headers
39
+ # @return [Boolean] delete success = true
40
+ def delete_fwgroup(id, headers = {})
41
+ res = delete!("fwgroups/#{id}", {}, headers)
42
+ check_job(res.body["job_id"], headers)
43
+ end
44
+
45
+ # Get an array of existing fwgroup objects.
46
+ #
47
+ # @param headers [Hash] HTTP request headers
48
+ # @return [Array<Resources::Fwgroup>] An array of fwgroup objects
49
+ def fwgroups(headers = {})
50
+ list_fwgroups(headers).resources.map do |fwgroup|
51
+ Resources::Fwgroup.new(self, fwgroup)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,75 @@
1
+ module Idcf
2
+ module Ilb
3
+ module ClientExtensions
4
+ # SDK APIs for job resource
5
+ module Job
6
+ # Get list of existing jobs
7
+ #
8
+ # @param attributes [Hash] request attributes
9
+ # @option attributes [String] :resource name of resource (optional)
10
+ # @option attributes [String] :method name of http method (optional)
11
+ # @param headers [Hash] HTTP request headers
12
+ # @return [Response] HTTP response object
13
+ def list_jobs(attributes = {}, headers = {})
14
+ Validators::Job.validate_attributes!(attributes, :list)
15
+ get!("jobs", attributes, headers)
16
+ end
17
+
18
+ # Get a job
19
+ #
20
+ # @param id [String] ID of target job
21
+ # @param headers [Hash] HTTP request headers
22
+ # @return [Response] HTTP response object
23
+ def get_job(id, headers = {})
24
+ get!("jobs/#{id}", {}, headers)
25
+ end
26
+
27
+ # Check job result
28
+ # Get a resource data
29
+ #
30
+ # @param id [String] ID of target job
31
+ # @return [Response] HTTP response object
32
+ def check_job(id, headers = {}, callback_and_args = [], specify_res_id = true)
33
+ flag = false
34
+ 1.upto(20) do |n|
35
+ @res = get_job(id, headers)
36
+ if @res.body["job_status"] == "Success"
37
+ flag = true
38
+ break
39
+ elsif @res.body["job_status"] == "Failed"
40
+ raise(
41
+ ApiError,
42
+ "API Failed."
43
+ )
44
+ else
45
+ sleep 2 * n
46
+ end
47
+ end
48
+
49
+ if flag == true
50
+ if specify_res_id == true
51
+ res_id = @res.body["resource_id"]
52
+ callback_and_args << res_id
53
+ end
54
+ callback_and_args.empty? ? true : __send__(*callback_and_args, headers)
55
+ else
56
+ raise(
57
+ ApiError,
58
+ "JOB Timeout."
59
+ )
60
+ end
61
+ end
62
+
63
+ # Get an array of existing job objects.
64
+ #
65
+ # @param headers [Hash] HTTP request headers
66
+ # @return [Array<Resources::Job>] An array of job objects
67
+ def jobs(headers = {})
68
+ list_jobs(headers).resources.map do |job|
69
+ Resources::Job.new(self, job)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,24 @@
1
+ module Idcf
2
+ module Ilb
3
+ module ClientExtensions
4
+ # SDK APIs for limit resource
5
+ module Limit
6
+ # Get limit
7
+ #
8
+ # @param headers [Hash] HTTP request headers
9
+ # @return [Response] HTTP response object
10
+ def get_limit(headers = {})
11
+ get!("limits", {}, headers)
12
+ end
13
+
14
+ # Get a limit object.
15
+ #
16
+ # @param headers [Hash] HTTP request headers
17
+ # @return <Resources::Limit> a limit objects
18
+ def limit(headers = {})
19
+ Resources::Limit.new(self, get_limit(headers).body)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,79 @@
1
+ module Idcf
2
+ module Ilb
3
+ module ClientExtensions
4
+ # SDK APIs for loadbalancer resource
5
+ module Loadbalancer
6
+ # Create a new loadbalancer.
7
+ #
8
+ # @param attributes [Hash] request attributes
9
+ # @option attributes [String] :name unique name of loadbalancer (required)
10
+ # @option attributes [String] :network_id network_id of active network (required)
11
+ # @option attributes [Array] :configs configs of loadbalancer (required)
12
+ # @option attributes [Hash] :mackerel mackerel (optional)
13
+ # @option attributes [String] :fwgroup_id (optional)
14
+ # @param headers [Hash] HTTP request headers
15
+ # @return [Response] HTTP response object
16
+ def create_loadbalancer(attributes, headers = {})
17
+ Validators::Loadbalancer.validate_attributes!(attributes, :create)
18
+ res = post!("loadbalancers", attributes, headers)
19
+ check_job(res.body["job_id"], headers, ["get_loadbalancer"])
20
+ end
21
+
22
+ # Update a loadbalancer.
23
+ #
24
+ # @param attributes [Hash] request attributes
25
+ # @option attributes [String] :name unique name of loadbalancer (required)
26
+ # @option attributes [String] :certificate of loadbalancer (required)
27
+ # @option attributes [String] :private_key of loadbalancer (required)
28
+ # @option attributes [String] :certificate_chain of loadbalancer (optional)
29
+ # @param headers [Hash] HTTP request headers
30
+ # @return [Response] HTTP response object
31
+ def update_loadbalancer(id, attributes, headers = {})
32
+ Validators::Loadbalancer.validate_attributes!(attributes, :update)
33
+ res = put!("loadbalancers/#{id}", attributes, headers)
34
+ check_job(res.body["job_id"], headers, ["get_loadbalancer"])
35
+ end
36
+
37
+ # Get list of existing loadbalancers
38
+ #
39
+ # @param attributes [Hash] request attributes
40
+ # @option attributes [String] :name unique name of loadbalancer (optional)
41
+ # @param headers [Hash] HTTP request headers
42
+ # @return [Response] HTTP response object
43
+ def list_loadbalancers(attributes = {}, headers = {})
44
+ Validators::Loadbalancer.validate_attributes!(attributes, :list)
45
+ get!("loadbalancers", attributes, headers)
46
+ end
47
+
48
+ # Get a loadbalancer
49
+ #
50
+ # @param id [String] ID of target loadbalancer
51
+ # @param headers [Hash] HTTP request headers
52
+ # @return [Response] HTTP response object
53
+ def get_loadbalancer(id, headers = {})
54
+ get!("loadbalancers/#{id}", {}, headers)
55
+ end
56
+
57
+ # Delete a loadbalancer
58
+ #
59
+ # @param id [String] ID of target loadbalancer
60
+ # @param headers [Hash] HTTP request headers
61
+ # @return [Boolean] delete success = true
62
+ def delete_loadbalancer(id, headers = {})
63
+ res = delete!("loadbalancers/#{id}", {}, headers)
64
+ check_job(res.body["job_id"], headers)
65
+ end
66
+
67
+ # Get an array of existing loadbalancer objects.
68
+ #
69
+ # @param headers [Hash] HTTP request headers
70
+ # @return [Array<Resources::Loadbalancer>] An array of loadbalancer objects
71
+ def loadbalancers(headers = {})
72
+ list_loadbalancers(headers).resources.map do |loadbalancer|
73
+ Resources::Loadbalancer.new(self, loadbalancer)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,30 @@
1
+ module Idcf
2
+ module Ilb
3
+ module ClientExtensions
4
+ # SDK APIs for log resource
5
+ module Log
6
+ # Get list of logs
7
+ #
8
+ # @param attributes [Hash] request attributes
9
+ # @option attributes [Integer] :page (optional)
10
+ # @option attributes [Integer] :per_page (optional)
11
+ # @param headers [Hash] HTTP request headers
12
+ # @return [Response] HTTP response object
13
+ def list_logs(attributes = {}, headers = {})
14
+ Validators::Log.validate_attributes!(attributes, :list)
15
+ get!("logs", attributes, headers)
16
+ end
17
+
18
+ # Get an array of existing log objects.
19
+ #
20
+ # @param headers [Hash] HTTP request headers
21
+ # @return [Array<Resources::Log>] An array of log objects
22
+ def logs(headers = {})
23
+ list_logs(headers).resources.map do |log|
24
+ Resources::Log.new(self, log)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ module Idcf
2
+ module Ilb
3
+ module ClientExtensions
4
+ # SDK APIs for network resource
5
+ module Network
6
+ # Get list of networks
7
+ #
8
+ # @param headers [Hash] HTTP request headers
9
+ # @return [Response] HTTP response object
10
+ def list_networks(headers = {})
11
+ get!("networks", {}, headers)
12
+ end
13
+
14
+ # Get an array of existing network objects.
15
+ #
16
+ # @param headers [Hash] HTTP request headers
17
+ # @return [Array<Resources::Network>] An array of network objects
18
+ def networks(headers = {})
19
+ list_networks(headers).resources.map do |network|
20
+ Resources::Network.new(self, network)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ module Idcf
2
+ module Ilb
3
+ module ClientExtensions
4
+ # SDK APIs for server resource
5
+ module Server
6
+ # Add a loadbalancer config's server.
7
+ #
8
+ # @param lb_id [String] ID of loadbalancer
9
+ # @param config_id [String] ID of loadbalancer's config
10
+ # @param data [Hash] add server hash
11
+ # @option data [String] :ipaddress (required)
12
+ # @option data [Integer] :port (required)
13
+ # @param headers [Hash] HTTP request headers
14
+ # @return [Array<Hash>] An array of [loadbalancer's config server] hash
15
+ def add_server(lb_id, config_id, data, headers = {})
16
+ Validators::Server.validate_attributes!(data, :add)
17
+ res = post!("loadbalancers/#{lb_id}/configs/#{config_id}/servers", data, headers)
18
+ check_job(res.body["job_id"], headers, ["list_servers", lb_id, config_id], false)
19
+ end
20
+
21
+ # Get list of existing [loadbalancer's config servers]
22
+ #
23
+ # @param lb_id [String] ID of loadbalancer
24
+ # @param config_id [String] ID of loadbalancer's config
25
+ # @param headers [Hash] HTTP request headers
26
+ # @return [Array<Hash>] An array of [loadbalancer's config server] hash
27
+ def list_servers(lb_id, config_id, headers = {})
28
+ res = get!("loadbalancers/#{lb_id}/configs/#{config_id}/servers", {}, headers)
29
+ res.body
30
+ end
31
+
32
+ # Delete a [loadbalancer's config server]
33
+ #
34
+ # @param lb_id [String] ID of loadbalancer
35
+ # @param config_id [String] ID of loadbalancer's config
36
+ # @param id [String] ID of loadbalancer's config server
37
+ # @param headers [Hash] HTTP request headers
38
+ # @return [Array<Hash>] An array of [loadbalancer's config server] hash
39
+ def delete_server(lb_id, config_id, id, headers = {})
40
+ res = delete!("loadbalancers/#{lb_id}/configs/#{config_id}/servers/#{id}", {}, headers)
41
+ check_job(res.body["job_id"], headers, ["list_servers", lb_id, config_id], false)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end