acos_client 0.1.0.pre.alpha

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.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +3 -0
  3. data/Gemfile +4 -0
  4. data/README.md +39 -0
  5. data/Rakefile +1 -0
  6. data/acos_client.gemspec +29 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +7 -0
  9. data/lib/acos_client/application.rb +91 -0
  10. data/lib/acos_client/client.rb +58 -0
  11. data/lib/acos_client/errors.rb +56 -0
  12. data/lib/acos_client/tools.rb +12 -0
  13. data/lib/acos_client/v21/action.rb +36 -0
  14. data/lib/acos_client/v21/axapi_http.rb +142 -0
  15. data/lib/acos_client/v21/base.rb +63 -0
  16. data/lib/acos_client/v21/config_file.rb +26 -0
  17. data/lib/acos_client/v21/device_info.rb +22 -0
  18. data/lib/acos_client/v21/ha.rb +29 -0
  19. data/lib/acos_client/v21/log.rb +117 -0
  20. data/lib/acos_client/v21/monkey_patch_ssl.rb +22 -0
  21. data/lib/acos_client/v21/nat.rb +53 -0
  22. data/lib/acos_client/v21/network.rb +167 -0
  23. data/lib/acos_client/v21/partition.rb +53 -0
  24. data/lib/acos_client/v21/responses.rb +170 -0
  25. data/lib/acos_client/v21/session.rb +61 -0
  26. data/lib/acos_client/v21/slb/aflex.rb +89 -0
  27. data/lib/acos_client/v21/slb/class_list.rb +67 -0
  28. data/lib/acos_client/v21/slb/hm.rb +122 -0
  29. data/lib/acos_client/v21/slb/init.rb +53 -0
  30. data/lib/acos_client/v21/slb/member.rb +36 -0
  31. data/lib/acos_client/v21/slb/port.rb +52 -0
  32. data/lib/acos_client/v21/slb/server.rb +65 -0
  33. data/lib/acos_client/v21/slb/service_group.rb +75 -0
  34. data/lib/acos_client/v21/slb/template/init.rb +28 -0
  35. data/lib/acos_client/v21/slb/template/persistence.rb +79 -0
  36. data/lib/acos_client/v21/slb/template/template_ssl.rb +56 -0
  37. data/lib/acos_client/v21/slb/virtual_port.rb +87 -0
  38. data/lib/acos_client/v21/slb/virtual_server.rb +62 -0
  39. data/lib/acos_client/v21/slb/virtual_service.rb +61 -0
  40. data/lib/acos_client/v21/system.rb +84 -0
  41. data/lib/acos_client/version.rb +3 -0
  42. data/lib/acos_client.rb +13 -0
  43. metadata +154 -0
@@ -0,0 +1,117 @@
1
+ require 'acos_client/v21/base'
2
+
3
+ module AcosClient
4
+ module V21
5
+
6
+ class Log < AcosClient::V21::BaseV21
7
+
8
+ def set(sys_log, **opts)
9
+ params = {:sys_log => sys_log}
10
+ self._post('system.log.set', params: params, **opts)
11
+ end
12
+
13
+
14
+ def get(**opts)
15
+ self._get('system.log.get', **opts)
16
+ end
17
+
18
+
19
+ def clear(sys_log, **opts)
20
+ self._post('system.log.clear', **opts)
21
+ end
22
+
23
+
24
+ def download(**opts)
25
+ self._get('system.log.download', **opts)
26
+ end
27
+
28
+
29
+ def backup(**opts)
30
+ self._post('system.log.backup', **opts)
31
+ end
32
+
33
+
34
+ def level
35
+ Level.new(self.client)
36
+ end
37
+
38
+ class Level < AcosClient::V21::BaseV21
39
+ def get(**opts)
40
+ self._get('system.log.level.get', **opts)
41
+ end
42
+
43
+ def set(log_level, **opts)
44
+ params = {:log_level => log_level}
45
+ self._post('system.log.level.set', params: params, **opts)
46
+ end
47
+ end
48
+
49
+
50
+ def server
51
+ Server.new(self.client)
52
+ end
53
+
54
+ class Server < AcosClient::V21::BaseV21
55
+ def get(**opts)
56
+ self._get('system.log.server.get', **opts)
57
+ end
58
+
59
+ def set(log_server, **opts)
60
+ params = {:log_server => log_server}
61
+ self._post('system.log.server.set', params: params, **opts)
62
+ end
63
+ end
64
+
65
+
66
+ def buffer
67
+ Buffer.new(self.client)
68
+ end
69
+
70
+ class Buffer < AcosClient::V21::BaseV21
71
+ def get(**opts)
72
+ self._get('system.log.buffer.get', **opts)
73
+ end
74
+
75
+ def set(buff_size, **opts)
76
+ params = {:buffer_size => buff_size}
77
+ self._post('system.log.buffer.set', params: params, **opts)
78
+ end
79
+ end
80
+
81
+
82
+ def smtp
83
+ Smtp.new(self.client)
84
+ end
85
+
86
+ class Smtp < AcosClient::V21::BaseV21
87
+ def get(**opts)
88
+ self._get('system.log.smtp.get', **opts)
89
+ end
90
+
91
+ def set(smtp, **opts)
92
+ params = {:smtp => smtp}
93
+ self._post('system.log.smtp.set', params: params, **opts)
94
+ end
95
+ end
96
+
97
+
98
+ def audit
99
+ Audit.new(self.client)
100
+ end
101
+
102
+ class Audit < AcosClient::V21::BaseV21
103
+ def get(**opts)
104
+ self._get('system.log.audit.get', **opts)
105
+ end
106
+
107
+ def set(audit, **opts)
108
+ params = {:audit => audit}
109
+ self._post('system.log.audit.set', params: params, **opts)
110
+ end
111
+
112
+ end
113
+
114
+ end
115
+
116
+ end
117
+ end
@@ -0,0 +1,22 @@
1
+ module OpenSSL
2
+ module SSL
3
+ class SSLContext
4
+ remove_const(:DEFAULT_PARAMS)
5
+ DEFAULT_PARAMS = {
6
+ :ssl_version => "TLSv1",
7
+ :verify_mode => OpenSSL::SSL::VERIFY_PEER,
8
+ :ciphers => %w{
9
+ DES-CBC3-SHA
10
+ }.join(":"),
11
+ :options => -> {
12
+ opts = OpenSSL::SSL::OP_ALL
13
+ opts &= ~OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS if defined?(OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS)
14
+ opts |= OpenSSL::SSL::OP_NO_COMPRESSION if defined?(OpenSSL::SSL::OP_NO_COMPRESSION)
15
+ opts |= OpenSSL::SSL::OP_NO_SSLv2 if defined?(OpenSSL::SSL::OP_NO_SSLv2)
16
+ opts |= OpenSSL::SSL::OP_NO_SSLv3 if defined?(OpenSSL::SSL::OP_NO_SSLv3)
17
+ opts
18
+ }.call
19
+ }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,53 @@
1
+ require 'acos_client/v21/base'
2
+
3
+ module AcosClient
4
+ module V21
5
+ class Nat < AcosClient::V21::BaseV21
6
+
7
+ def pool
8
+ Pool.new(self.client)
9
+ end
10
+
11
+ class Pool < AcosClient::V21::BaseV21
12
+
13
+ def _set(action, name, start_ip, end_ip, mask, **opts)
14
+
15
+ params = {
16
+ :name => name,
17
+ :start_ip_addr => start_ip,
18
+ :end_ip_addr => end_ip,
19
+ :netmask => mask,
20
+ }
21
+
22
+ self._post(action, params: params, **opts)
23
+ end
24
+
25
+ def all(**opts)
26
+ self._get('nat.pool.getAll', **opts)
27
+ end
28
+
29
+ def create(name, start_ip, end_ip, mask, **opts)
30
+ self._set('nat.pool.create', name, start_ip, end_ip, mask, **opts)
31
+ end
32
+
33
+ def update(name, start_ip, end_ip, mask, **opts)
34
+ self._set('nat.pool.create', name, start_ip, end_ip, mask, **opts)
35
+ end
36
+
37
+ def delete(name, **opts)
38
+ self._post('nat.pool.delete', params: {:name => name}, **opts)
39
+ end
40
+
41
+ def stats(name, **opts)
42
+ self._post('nat.pool.fetchStatistics', params: {:name => name}, **opts)
43
+ end
44
+
45
+ def all_stats(**opts)
46
+ self._get('nat.pool.fetchALLStatistics', **opts)
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,167 @@
1
+ require 'acos_client/v21/base'
2
+
3
+
4
+ module AcosClient
5
+ module V21
6
+
7
+ class Network < AcosClient::V21::BaseV21
8
+
9
+ def interface
10
+ Interface.new(self.client)
11
+ end
12
+
13
+ class Interface < AcosClient::V21::BaseV21
14
+
15
+ def all
16
+ self._get('network.interface.getAll')
17
+ end
18
+
19
+ def get(port_num)
20
+ # FIXME Broken ?
21
+ self._get('network.interface.get', params: {:port_num => port_num})
22
+ end
23
+
24
+ def set(port_num, **otps)
25
+
26
+ params = {
27
+ :interface => {
28
+ :port_num => port_num
29
+ }
30
+ }
31
+ self._post('network.interface.set', params: params, **opts)
32
+ end
33
+
34
+ def ipv4
35
+ IPV4.new(self.client)
36
+ end
37
+
38
+ class IPV4 < AcosClient::V21::BaseV21
39
+
40
+ def _set(action, port_num, ipv4_address, ipv4_mask, **opts)
41
+
42
+ params = {
43
+ :interface => {
44
+ :ipv4 => {
45
+ :ipv4_address => ipv4_address,
46
+ :ipv4_mask => ipv4_mask
47
+ },
48
+ :port_num => port_num
49
+ }
50
+ }
51
+
52
+ self._post(action, params: params, **opts)
53
+ end
54
+
55
+ def all_delete(port_num, **opts)
56
+ self._post('network.interface.ipv4.deleteAll', params: {:port_num => port_num}, **opts)
57
+ end
58
+
59
+ def add(port_num, ipv4_address, ipv4_mask, **opts)
60
+ self._set('network.interface.ipv4.add', port_num, ipv4_address, ipv4_mask, **opts)
61
+ end
62
+
63
+ def delete(port_num, ipv4_address, ipv4_mask, **opts)
64
+ self._set('network.interface.ipv4.delete', port_num, ipv4_address, ipv4_mask, **opts)
65
+ end
66
+ end
67
+ end
68
+
69
+ def acl
70
+ ACL.new(self.client)
71
+ end
72
+
73
+ class ACL < AcosClient::V21::BaseV21
74
+
75
+ def ext
76
+ Ext.new(self.client)
77
+ end
78
+
79
+ class Ext < AcosClient::V21::BaseV21
80
+
81
+ # Protocols
82
+ ICMP = 0
83
+ IP = 1
84
+ TCP = 2
85
+ UDP = 3
86
+
87
+ def _set(action, id, acl_item_list, **opts)
88
+
89
+ params = {
90
+ :ext_acl => {
91
+ :id => id,
92
+ :acl_item_list => acl_item_list
93
+ }
94
+ }
95
+
96
+ # silently fails if 'acl_item_list' is empty
97
+ self._post(action, params: params, **opts)
98
+ end
99
+
100
+ def all
101
+ self._get('network.acl.ext.getAll')
102
+ end
103
+
104
+ def search(id)
105
+ # FIXME not working
106
+ self._get('network.acl.ext.search', params: {:id => id})
107
+ end
108
+
109
+ def create(id, acl_item_list, **opts)
110
+ self._set('network.acl.ext.create', id, acl_item_list, **opts)
111
+ end
112
+
113
+ def update(id, acl_item_list, **opts)
114
+ self._set('network.acl.ext.update', id, acl_item_list,
115
+ **opts) # FIXME NOT WORKING
116
+ end
117
+
118
+ def delete(id)
119
+ # FIXME NOT WORKING
120
+ self._post('network.acl.ext.delete', params: {:id => id})
121
+ end
122
+
123
+ def all_delete(**opts)
124
+ self._get('network.acl.ext.deleteAll', **opts)
125
+ end
126
+ end
127
+ end
128
+
129
+ def route
130
+ Route.new(self.client)
131
+ end
132
+
133
+ class Route < AcosClient::V21::BaseV21
134
+
135
+ def _set(action, address, mask, gateway, distance, **opts)
136
+ params = {
137
+ :address => address,
138
+ :mask => mask,
139
+ :gateway => gateway,
140
+ :distance => distance
141
+ }
142
+ self._post(action, params: params, **opts)
143
+ end
144
+
145
+ def ipv4_all(**opts)
146
+ self._get('network.route.ipv4static.getAll', **opts)
147
+ end
148
+
149
+ def ipv4_create(address, mask, gateway, distance, **opts)
150
+ self._set('network.route.ipv4static.create', address, mask, gateway, distance, **opts)
151
+ end
152
+
153
+ def ipv4_update(address, mask, gateway, distance, **opts)
154
+ # FIXME NOT WORKING
155
+ self._set('network.route.ipv4static.update', address, mask, gateway, distance, **opts)
156
+ end
157
+
158
+ def ipv4_delete(address, mask, gateway, distance, **opts)
159
+ # FIXME NOT WORKING
160
+ self._set('network.route.ipv4static.delete', address, mask, gateway, distance, **opts)
161
+ end
162
+ end
163
+
164
+ end
165
+
166
+ end
167
+ end
@@ -0,0 +1,53 @@
1
+ require 'acos_client/errors'
2
+ require 'acos_client/v21/base'
3
+
4
+
5
+ module AcosClient
6
+ module V21
7
+
8
+ class Partition < AcosClient::V21::BaseV21
9
+
10
+ def exists(name)
11
+
12
+ if name == 'shared'
13
+ return true
14
+ end
15
+
16
+ begin
17
+ self._post('system.partition.search', params: {:name => name})
18
+ return true
19
+ rescue AcosClient::Error::NotFound
20
+ return false
21
+ end
22
+ end
23
+
24
+ def active(name='shared')
25
+ if self.client.current_partition != name
26
+ self._post('system.partition.active', params: {:name => name})
27
+ self.client.current_partition = name
28
+ end
29
+ end
30
+
31
+ def create(name)
32
+ params = {
33
+ :partition => {
34
+ :max_aflex_file => 32,
35
+ :network_partition => 0,
36
+ :name => name
37
+ }
38
+ }
39
+ if name != 'shared'
40
+ self._post('system.partition.create', params: params)
41
+ end
42
+ end
43
+
44
+ def delete(name)
45
+ if name != 'shared'
46
+ self.client.session.close
47
+ self._post('system.partition.delete', params: {:name => name})
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,170 @@
1
+ require 'acos_client/errors'
2
+
3
+
4
+ module AcosClient
5
+ module V21
6
+ module Responses
7
+
8
+ RESPONSE_CODES = {
9
+ 999 => {
10
+ ('*') => AcosClient::Error::NotFound
11
+ },
12
+ 1002 => {
13
+ ('*') => AcosClient::Error::MemoryFault
14
+ },
15
+ 1009 => {
16
+ ('session.close') => nil,
17
+ ('*') => AcosClient::Error::InvalidSessionID
18
+ },
19
+ 1023 => {
20
+ ('slb.service_group.member.delete') => nil,
21
+ ('*') => AcosClient::Error::NotFound
22
+ },
23
+ 1043 => {
24
+ ('slb.virtual_server.vport.delete') => nil,
25
+ ('*') => AcosClient::Error::NotFound
26
+ },
27
+ 1076 => {
28
+ ('session.close') => nil,
29
+ ('*') => AcosClient::Error::InvalidPartitionParameter
30
+ },
31
+ 1163 => {
32
+ ('*') => AcosClient::Error::InvalidParameter
33
+ },
34
+ 1165 => {
35
+ ('*') => AcosClient::Error::HMMissingHttpPassive
36
+ },
37
+ 1405 => {
38
+ ('*') => AcosClient::Error::Exists
39
+ },
40
+ 1406 => {
41
+ ('*') => AcosClient::Error::Exists
42
+ },
43
+ 1982 => {
44
+ ('*') => AcosClient::Error::Exists
45
+ },
46
+ 2941 => {
47
+ ('*') => AcosClient::Error::Exists
48
+ },
49
+ 3602 => {
50
+ ('slb.class_list.update') => AcosClient::Error::NotFound,
51
+ ('*') => AcosClient::Error::NotFound
52
+ },
53
+ 17039361 => {
54
+ ('slb.aflex.delete') => nil,
55
+ ('*') => AcosClient::Error::NotFound
56
+ },
57
+ 17039364 => {
58
+ ('slb.aflex.upload') => AcosClient::Error::InUse,
59
+ ('slb.aflex.delete') => AcosClient::Error::InUse,
60
+ ('*') => AcosClient::Error::InUse
61
+ },
62
+ 33619968 => {
63
+ ('slb.hm.delete') => nil,
64
+ ('*') => AcosClient::Error::NotFound
65
+ },
66
+ 33619969 => {
67
+ ('*') => AcosClient::Error::InUse,
68
+ },
69
+ 67174402 => {
70
+ ('slb.server.delete') => nil,
71
+ ('slb.server.port.delete') => nil,
72
+ ('*') => AcosClient::Error::NotFound
73
+ },
74
+ 67239937 => {
75
+ ('slb.virtual_server.delete') => nil,
76
+ ('slb.virtual_service.delete') => nil,
77
+ ('slb.virtual_service.update') => AcosClient::Error::NotFound,
78
+ ('*') => AcosClient::Error::NotFound
79
+ },
80
+ 67239947 => {
81
+ ('*') => AcosClient::Error::Exists
82
+ },
83
+ 67305473 => {
84
+ ('slb.service_group.delete') => nil,
85
+ ('slb.service_group.member.delete') => nil,
86
+ ('slb.service_group.member.create') => AcosClient::Error::NotFound,
87
+ ('slb.service_group.member.update') => AcosClient::Error::NotFound,
88
+ ('*') => AcosClient::Error::NotFound
89
+ },
90
+ 67371009 => {
91
+ ('slb.template.cookie_persistence.delete') => nil,
92
+ ('slb.template.src_ip_persistence.delete') => nil,
93
+ ('slb.template.client_ssl.delete') => nil,
94
+ ('slb.template.server_ssl.delete') => nil,
95
+ ('*') => AcosClient::Error::NotFound
96
+ },
97
+ 67371049 => {
98
+ ('slb.class_list.delete') => nil,
99
+ ('*') => AcosClient::Error::NotFound
100
+ },
101
+ 402653200 => {
102
+ ('*') => AcosClient::Error::Exists
103
+ },
104
+ 402653201 => {
105
+ ('*') => AcosClient::Error::Exists
106
+ },
107
+ 402653202 => {
108
+ ('*') => AcosClient::Error::Exists
109
+ },
110
+ 402653206 => {
111
+ ('*') => AcosClient::Error::Exists
112
+ },
113
+ 402718800 => {
114
+ ('*') => AcosClient::Error::NotFound
115
+ },
116
+ 520486915 => {
117
+ ('*') => AcosClient::Error::AuthenticationFailure
118
+ },
119
+ 520749062 => {
120
+ ('*') => AcosClient::Error::NotFound
121
+ },
122
+ 654311465 => {
123
+ ('*') => AcosClient::Error::AddressSpecifiedIsInUse
124
+ },
125
+ 654311495 => {
126
+ ('*') => AcosClient::Error::InUse,
127
+ },
128
+ 654311496 => {
129
+ ('*') => AcosClient::Error::AddressSpecifiedIsInUse
130
+ },
131
+ 654376968 => {
132
+ ('nat.pool.delete') => nil,
133
+ ('*') => AcosClient::Error::NotFound
134
+ },
135
+ 654573574 => {
136
+ ('network.acl.ext.delete') => nil,
137
+ ('*') => AcosClient::Error::NotFound
138
+ }
139
+ }
140
+
141
+
142
+ def self.raise_axapi_error(response, action: nil)
143
+
144
+ if response.key?(:response) and response[:response].key?(:err)
145
+ code = response[:response][:err][:code]
146
+
147
+ if RESPONSE_CODES.key?(code)
148
+ error_dict = RESPONSE_CODES[code]
149
+
150
+ if !action.nil? and error_dict.key?(action)
151
+ error = error_dict[action]
152
+ else
153
+ error = error_dict['*']
154
+ end
155
+
156
+ if !error.nil?
157
+ raise error, 'Err: ' + code.to_s + ' ' + response[:response][:err][:msg]
158
+ else
159
+ return
160
+ end
161
+ end
162
+ raise RuntimeError, 'Err: ' + code.to_s + ' ' + response[:response][:err][:msg]
163
+ end
164
+
165
+ raise RuntimeError
166
+
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,61 @@
1
+ require 'acos_client/errors'
2
+
3
+ module AcosClient
4
+ module V21
5
+
6
+ class Session
7
+
8
+ def initialize(client, username, password)
9
+ @client = client
10
+ @http = client.http
11
+ @username = username
12
+ @password = password
13
+ @session_id = nil
14
+ end
15
+
16
+ def id
17
+ if @session_id.nil?
18
+ self.authenticate(@username, @password)
19
+ end
20
+ @session_id
21
+ end
22
+
23
+ def authenticate(username, password)
24
+ url = '/services/rest/V2.1/?format=json&method=authenticate'
25
+
26
+ options = {
27
+ :username => username,
28
+ :password => password
29
+ }
30
+
31
+ if @session_id.nil?
32
+ self.close
33
+ end
34
+
35
+ r = @http.post(url, params: options)
36
+ @session_id = r[:session_id]
37
+ r
38
+ end
39
+
40
+ def close
41
+ begin
42
+ @client.partition.active
43
+ rescue Exception
44
+ #pass
45
+ end
46
+
47
+ begin
48
+ url = "/services/rest/v2.1/?format=json&method=session.close&session_id=#{@session_id}"
49
+ r = @http.post(url, params: {:session_id => @session_id})
50
+
51
+ rescue AcosClient::Error::InvalidPartitionParameter
52
+ #pass
53
+ ensure
54
+ @session_id = nil
55
+ end
56
+
57
+ r
58
+ end
59
+ end
60
+ end
61
+ end