onering-client 0.0.61 → 0.0.62
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/onering.rb +10 -9
- data/lib/onering/api.rb +17 -1
- data/lib/onering/cli/config.rb +55 -0
- metadata +2 -1
data/lib/onering.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
$: << File.expand_path(File.dirname(__FILE__))
|
2
2
|
require 'onering/util'
|
3
3
|
require 'onering/api'
|
4
|
-
require 'onering/plugins/devices'
|
5
|
-
require 'onering/plugins/authentication'
|
6
|
-
require 'onering/plugins/automation'
|
7
|
-
require 'onering/plugins/reporter'
|
8
4
|
require 'onering/cli'
|
9
|
-
|
10
|
-
require
|
11
|
-
|
12
|
-
require
|
13
|
-
|
5
|
+
|
6
|
+
# require plugins
|
7
|
+
Dir[File.join(File.expand_path(File.dirname(__FILE__)),"onering","plugins","*.rb")].each do |i|
|
8
|
+
require i
|
9
|
+
end
|
10
|
+
|
11
|
+
# require cli submodules
|
12
|
+
Dir[File.join(File.expand_path(File.dirname(__FILE__)),"onering","cli","*.rb")].each do |i|
|
13
|
+
require i
|
14
|
+
end
|
data/lib/onering/api.rb
CHANGED
@@ -25,7 +25,12 @@ module Onering
|
|
25
25
|
module Errors
|
26
26
|
class Exception < ::Exception; end
|
27
27
|
class NotConnected < Exception; end
|
28
|
+
|
28
29
|
class ClientError < Exception; end
|
30
|
+
class Unauthorized < ClientError; end
|
31
|
+
class Forbidden < ClientError; end
|
32
|
+
class NotFound < ClientError; end
|
33
|
+
|
29
34
|
class ServerError < Exception; end
|
30
35
|
class ConnectionTimeout < Exception; end
|
31
36
|
class AuthenticationMissing < Exception; end
|
@@ -93,7 +98,18 @@ module Onering
|
|
93
98
|
if rv.code >= 500
|
94
99
|
raise Errors::ServerError.new("HTTP #{rv.code} - #{Onering::Util.http_status(rv.code)} #{rv.parsed_response.get('error.message','') rescue ''}")
|
95
100
|
elsif rv.code >= 400
|
96
|
-
|
101
|
+
message = "HTTP #{rv.code} - #{Onering::Util.http_status(rv.code)} #{rv.parsed_response.get('error.message', '') rescue ''}"
|
102
|
+
|
103
|
+
case rv.code
|
104
|
+
when 401
|
105
|
+
raise Errors::Unauthorized.new(message)
|
106
|
+
when 403
|
107
|
+
raise Errors::Forbidden.new(message)
|
108
|
+
when 404
|
109
|
+
raise Errors::NotFound.new(message)
|
110
|
+
else
|
111
|
+
raise Errors::ClientError.new(message)
|
112
|
+
end
|
97
113
|
else
|
98
114
|
rv
|
99
115
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Onering
|
2
|
+
module CLI
|
3
|
+
module Config
|
4
|
+
def self.configure(global={})
|
5
|
+
Onering::Reporter.setup()
|
6
|
+
@api = Onering::CLI.connect(global)
|
7
|
+
|
8
|
+
@opts = ::Trollop::options do
|
9
|
+
banner <<-EOS
|
10
|
+
Options:
|
11
|
+
EOS
|
12
|
+
|
13
|
+
opt :id, "The node ID of the device to operate on", :short => '-i', :type => :string, :default => Onering::Util.fact('hardwareid')
|
14
|
+
|
15
|
+
# subcommands
|
16
|
+
stop_on %w{get set test}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.run(args)
|
21
|
+
sc = args.shift
|
22
|
+
|
23
|
+
case (sc.downcase.to_sym rescue nil)
|
24
|
+
# -----------------------------------------------------------------------------
|
25
|
+
when :get
|
26
|
+
raise "Expected 1 parameter, got #{args.length}" unless args.length >= 1
|
27
|
+
|
28
|
+
begin
|
29
|
+
rv = @api.request(@opts[:method], "devices/#{@opts[:id]}/config/#{args[0].gsub('.','/')}")
|
30
|
+
return (rv.parsed_response rescue rv.response.body)
|
31
|
+
rescue Onering::API::Errors::NotFound
|
32
|
+
if args[1].nil? and not STDIN.tty?
|
33
|
+
args[1] = STDIN.read()
|
34
|
+
end
|
35
|
+
|
36
|
+
return (MultiJson.load(args[1]) rescue args[1])
|
37
|
+
end
|
38
|
+
|
39
|
+
# -----------------------------------------------------------------------------
|
40
|
+
when :set
|
41
|
+
raise "Expected 2 parameters, got #{args.length}" unless args.length == 2
|
42
|
+
|
43
|
+
return @api.set_field(@opts[:id], "config.#{args[0]}", args[1])
|
44
|
+
|
45
|
+
# -----------------------------------------------------------------------------
|
46
|
+
when :test
|
47
|
+
raise "Expected 1 parameter, got #{args.length}" unless args.length >= 1
|
48
|
+
|
49
|
+
else
|
50
|
+
raise "Unknown subcommand #{sc.inspect}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onering-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.62
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- lib/onering/cli.rb
|
153
153
|
- lib/onering/cli/fact.rb
|
154
154
|
- lib/onering/cli/call.rb
|
155
|
+
- lib/onering/cli/config.rb
|
155
156
|
- lib/onering/cli/devices.rb
|
156
157
|
- lib/onering/cli/automation.rb
|
157
158
|
- lib/onering/cli/reporter.rb
|