yetis_node 0.0.2 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/yetis_cmd_list.rb +12 -12
- data/lib/yetis_node.rb +4 -1
- data/lib/yetis_node/base_transport.rb +12 -0
- data/lib/yetis_node/client.rb +18 -8
- data/lib/yetis_node/cmd/base.rb +2 -11
- data/lib/yetis_node/cmd/show.rb +1 -1
- data/lib/yetis_node/error.rb +8 -1
- data/lib/yetis_node/json_rpc_transport.rb +23 -0
- data/lib/yetis_node/version.rb +1 -1
- data/lib/yetis_node/xml_rpc_transport.rb +17 -0
- data/yetis_node.gemspec +9 -8
- metadata +26 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73cc4c5a4c2931c35f55b526115b79619ccc596d
|
4
|
+
data.tar.gz: ba9ebf51cc5f23ad6f632c3339bf6cc83c281377
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dc1ebfe06f54f42d22eac5379bf2e05bdbc29ac23856658f53d7642f1aa4cdf1aab82fb6998ea87947e33b6b36d4e800588741104647e16382ed878608cc290
|
7
|
+
data.tar.gz: 294dd20cfbebec68d4b28ab19693fb82589ca97104788b5cd6ba881c7626a0c065a5859aa75049d39607b6f43a283ae7e1d61e0a98c39f92f960dc8ae34b6096
|
data/bin/yetis_cmd_list.rb
CHANGED
@@ -2,23 +2,23 @@
|
|
2
2
|
|
3
3
|
require "xmlrpc/client"
|
4
4
|
|
5
|
-
if(ARGV.empty?)
|
6
|
-
|
7
|
-
|
5
|
+
if (ARGV.empty?)
|
6
|
+
puts "usage: #{$0} host:port"
|
7
|
+
exit
|
8
8
|
end
|
9
9
|
|
10
|
-
(host,port) = ARGV[0].split(':')
|
10
|
+
(host, port) = ARGV[0].split(':')
|
11
11
|
$s = XMLRPC::Client.new(host, "/", port)
|
12
12
|
|
13
13
|
def f(*args)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
puts args.take(args.size-1).join(' ')
|
15
|
+
r = $s.call("di", "yeti", *args)
|
16
|
+
return if !r.kind_of?(Array)
|
17
|
+
r.each do |e|
|
18
|
+
if e.kind_of?(Array)
|
19
|
+
f(*args.first(args.size - 1), e[0], '_list')
|
20
|
+
end
|
21
|
+
end
|
22
22
|
end
|
23
23
|
|
24
24
|
begin
|
data/lib/yetis_node.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'yetis_node/version'
|
2
2
|
require 'yetis_node/cmd/base'
|
3
3
|
require 'yetis_node/cmd/show'
|
4
4
|
require 'yetis_node/cmd/set'
|
5
5
|
require 'yetis_node/cmd/request'
|
6
6
|
require 'yetis_node/error'
|
7
|
+
require 'yetis_node/base_transport'
|
8
|
+
require 'yetis_node/xml_rpc_transport'
|
9
|
+
require 'yetis_node/json_rpc_transport'
|
7
10
|
require 'yetis_node/client'
|
8
11
|
|
9
12
|
module YetisNode
|
data/lib/yetis_node/client.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'forwardable'
|
2
2
|
module YetisNode
|
3
3
|
|
4
4
|
|
@@ -7,13 +7,16 @@ module YetisNode
|
|
7
7
|
# node.calls_count
|
8
8
|
# => "10"
|
9
9
|
class Client
|
10
|
-
|
10
|
+
extend Forwardable
|
11
11
|
|
12
|
-
|
12
|
+
attr_reader :uri, :options, :transport
|
13
|
+
|
14
|
+
def_delegators :@transport, :rpc_send
|
13
15
|
|
14
16
|
def initialize(uri, options = {})
|
15
17
|
@uri = uri
|
16
18
|
@options = options
|
19
|
+
select_transport!
|
17
20
|
end
|
18
21
|
|
19
22
|
include Cmd::Base
|
@@ -21,15 +24,22 @@ module YetisNode
|
|
21
24
|
include Cmd::Request
|
22
25
|
include Cmd::Set
|
23
26
|
|
24
|
-
|
25
27
|
protected :invoke_show, :invoke_request, :invoke_set
|
26
28
|
|
27
|
-
|
29
|
+
private
|
28
30
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
31
|
+
def select_transport!
|
32
|
+
transport_klass = case @options.fetch(:transport, :xml_rpc)
|
33
|
+
when :xml_rpc
|
34
|
+
XmlRpcTransport
|
35
|
+
when :json_rpc
|
36
|
+
JsonRpcTransport
|
37
|
+
else
|
38
|
+
raise Error.new('invalid transport')
|
39
|
+
end
|
32
40
|
|
41
|
+
@transport = transport_klass.new(@uri, @options)
|
42
|
+
end
|
33
43
|
|
34
44
|
end
|
35
45
|
end
|
data/lib/yetis_node/cmd/base.rb
CHANGED
@@ -2,19 +2,10 @@ module YetisNode
|
|
2
2
|
module Cmd
|
3
3
|
module Base
|
4
4
|
|
5
|
-
|
6
5
|
def invoke(method, prefix, args = [])
|
7
|
-
rpc_send(*([prefix] + method.to_s.split(
|
8
|
-
end
|
9
|
-
|
10
|
-
def rpc_send(*args)
|
11
|
-
begin
|
12
|
-
xml_rpc.call_async('di', 'yeti', *args)
|
13
|
-
rescue XMLRPC::FaultException => e
|
14
|
-
raise Error.new(e.message)
|
15
|
-
end
|
6
|
+
rpc_send(*([prefix] + method.to_s.split('_') + args.compact))
|
16
7
|
end
|
17
8
|
|
18
9
|
end
|
19
10
|
end
|
20
|
-
end
|
11
|
+
end
|
data/lib/yetis_node/cmd/show.rb
CHANGED
data/lib/yetis_node/error.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'jrpc'
|
2
|
+
module YetisNode
|
3
|
+
class JsonRpcTransport < BaseTransport
|
4
|
+
|
5
|
+
def rpc_send(*args)
|
6
|
+
begin
|
7
|
+
json_rpc.connect if json_rpc.closed?
|
8
|
+
result = json_rpc.invoke_request(*args)
|
9
|
+
json_rpc.close
|
10
|
+
result
|
11
|
+
rescue ::JRPC::Error => e
|
12
|
+
raise Error.new("JSON RPC Error: #{"(#{e.code}) " if e.respond_to?(:code)}#{e.message}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def json_rpc
|
17
|
+
@json_rpc ||= ::JRPC::TcpClient.new uri,
|
18
|
+
namespace: 'yeti.',
|
19
|
+
timeout: options.fetch(:timeout, BaseTransport::DEFAULT_TIMEOUT)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/yetis_node/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'xmlrpc/client'
|
2
|
+
module YetisNode
|
3
|
+
class XmlRpcTransport < BaseTransport
|
4
|
+
|
5
|
+
|
6
|
+
def rpc_send(*args)
|
7
|
+
xml_rpc.call_async('di', 'yeti', *args)
|
8
|
+
rescue XMLRPC::FaultException => e
|
9
|
+
raise Error.new(e.message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def xml_rpc
|
13
|
+
@xml_rpc ||= XMLRPC::Client.new2 uri, options.fetch(:timeout, BaseTransport::DEFAULT_TIMEOUT)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/yetis_node.gemspec
CHANGED
@@ -4,20 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'yetis_node/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'yetis_node'
|
8
8
|
spec.version = YetisNode::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Igor Fedoronchuk']
|
10
|
+
spec.email = ['igor.f@didww.com']
|
11
11
|
spec.summary = %q{XMLRPC client for YETI switch.}
|
12
12
|
spec.description = %q{XMLRPC client for YETI switch. http://yeti-switch.org }
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'http://yeti-switch.org'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
spec.add_development_dependency
|
21
|
+
spec.add_runtime_dependency 'jrpc', '~> 0.4', '>= 0.4.6'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
24
|
end
|
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yetis_node
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Fedoronchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jrpc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.4.6
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.4'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.4.6
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: bundler
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,13 +73,16 @@ files:
|
|
53
73
|
- Rakefile
|
54
74
|
- bin/yetis_cmd_list.rb
|
55
75
|
- lib/yetis_node.rb
|
76
|
+
- lib/yetis_node/base_transport.rb
|
56
77
|
- lib/yetis_node/client.rb
|
57
78
|
- lib/yetis_node/cmd/base.rb
|
58
79
|
- lib/yetis_node/cmd/request.rb
|
59
80
|
- lib/yetis_node/cmd/set.rb
|
60
81
|
- lib/yetis_node/cmd/show.rb
|
61
82
|
- lib/yetis_node/error.rb
|
83
|
+
- lib/yetis_node/json_rpc_transport.rb
|
62
84
|
- lib/yetis_node/version.rb
|
85
|
+
- lib/yetis_node/xml_rpc_transport.rb
|
63
86
|
- yetis_node.gemspec
|
64
87
|
homepage: http://yeti-switch.org
|
65
88
|
licenses:
|
@@ -81,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
104
|
version: '0'
|
82
105
|
requirements: []
|
83
106
|
rubyforge_project:
|
84
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.5.0
|
85
108
|
signing_key:
|
86
109
|
specification_version: 4
|
87
110
|
summary: XMLRPC client for YETI switch.
|