summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-04-16 10:04:12 +0300
committerSaku Ytti <saku@ytti.fi>2014-04-16 10:04:12 +0300
commitd74a152bba73095a0c7090dc078a7023eeb9ad18 (patch)
tree43f0a47fc93bcdd22f5799d41989582fc57c1cc9
parent2af41e1769225ac42027f2f686763389296bab79 (diff)
remove web API
It is now separately in oxidized-web package
-rw-r--r--lib/oxidized/api/domain.rb48
-rw-r--r--lib/oxidized/api/rest.rb93
-rw-r--r--lib/oxidized/api/web.rb19
-rw-r--r--lib/oxidized/api/web/views/default.haml4
-rw-r--r--lib/oxidized/api/web/views/head.haml5
-rw-r--r--lib/oxidized/api/web/views/node.haml6
-rw-r--r--lib/oxidized/api/web/views/nodes.haml34
-rw-r--r--lib/oxidized/api/web/views/oxidized.sass51
-rw-r--r--lib/oxidized/api/web/webapp.rb104
-rw-r--r--lib/oxidized/cli.rb3
-rw-r--r--lib/oxidized/config.rb3
-rw-r--r--lib/oxidized/core.rb6
-rw-r--r--lib/oxidized/model/model.rb2
-rw-r--r--lib/oxidized/string.rb4
-rw-r--r--oxidized.gemspec7
15 files changed, 12 insertions, 377 deletions
diff --git a/lib/oxidized/api/domain.rb b/lib/oxidized/api/domain.rb
deleted file mode 100644
index fa6a1c7..0000000
--- a/lib/oxidized/api/domain.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# this is not used, just added here if I want to revive it
-
-module Oxidized
- require 'socket'
- require 'json'
- module API
- class Domain
- def initialize nodes, socket=CFG.api
- puts 'here'
- @nodes = nodes
- File.unlink socket rescue Errno::ENOENT
- @server = UNIXServer.new socket
- end
- def work
- io = select [@server], nil, nil, Config::Sleep
- process io.first.first.accept if io
- end
- def read
- @socket.recv 1024
- end
- def write data=''
- begin
- @socket.send JSON.dump(data), 0
- rescue Errno::EPIPE
- end
- end
- def process socket
- @socket = socket
- cmd = read
- cmd, data = cmd.split /\s+/, 2
- data = data.to_s.chomp
- case cmd
- when /next/i
- @nodes.next data
- write 'OK'
- when /reload/i
- @nodes.load if data.match /nodes/i
- write 'OK'
- when /list/i
- write @nodes.map{|e|e.name}
- when /node/i
- write @nodes.show(data)
- end
- @socket.close
- end
- end
- end
-end
diff --git a/lib/oxidized/api/rest.rb b/lib/oxidized/api/rest.rb
deleted file mode 100644
index cdf5c80..0000000
--- a/lib/oxidized/api/rest.rb
+++ /dev/null
@@ -1,93 +0,0 @@
-module Oxidized
- require 'webrick'
- require 'json'
- module API
- class Rest
- module Helpers
- def send res, msg='OK', ascii=false, status=200
- res.body = msg
- if not ascii
- msg = {:result => msg}
- res['Content-Type'] = 'application/json'
- res.status = status
- res.body = JSON.dump msg
- end
- end
- end
- include Oxidized::API::Rest::Helpers
- def initialize nodes, listen
- @nodes = nodes
- addr, port = listen.to_s.split ':'
- port, addr = addr, nil if not port
- @web = WEBrick::HTTPServer.new :BindAddress=>addr, :Port=>port, :Logger=>Log, :AccessLog=>[]
- maps
- end
- def work
- req = select @web.listeners, nil, nil, Config::Sleep
- while req
- @web.run req.first.first.accept
- req = select @web.listeners, nil, nil, 0
- end
- end
- def maps
- @web.mount '/nodes/next', Next, @nodes
- @web.mount_proc '/nodes' do |req, res|
- #script_name, #path_info
- case req.path_info[1..-1]
- # /nodes/reload - reloads list of nodes
- when 'reload'
- @nodes.load
- send res
- # /nodes/list - returns list of nodes
- when 'list'
- send res, @nodes.list
- # /nodes/show/node - returns data about node
- when /show\/(.*)/
- send res, @nodes.show($1)
- # /nodes/fetch/<node> or /nodes/fetch/group/<group>/<node> - returns json formatted configuration file for <node>
- when /fetch\/(.*)/
- begin
- if $1.include? '/'
- group, node = $1.split("/")[1..2]
- else
- group, node = nil, $1
- end
- ascii = if node[-4..-1] == '.txt'
- node = node[0..-5]
- end
- send res, @nodes.fetch(node, group), ascii
- rescue Oxidized::NotSupported => e
- send res, e
- end
- end
- end
- end
-
- # /nodes/next/node - moves node to head of queue
- class Next < WEBrick::HTTPServlet::AbstractServlet
- include Oxidized::API::Rest::Helpers
- def initialize server, nodes
- super server
- @nodes = nodes
- end
- def do_GET req, res
- @nodes.next req.path_info[1..-1]
- send res
- end
- def do_PUT req, res
- node = req.path_info[1..-1]
- begin
- opt = JSON.load req.body
- Log.debug "before: #{@nodes.list}"
- @nodes.next node, opt
- Log.debug "after: #{@nodes.list}"
- send res
- rescue JSON::ParserError
- send res, 'broken JSON', 400
- end
- end
- end
-
- end
- end
-end
diff --git a/lib/oxidized/api/web.rb b/lib/oxidized/api/web.rb
deleted file mode 100644
index 9a5a507..0000000
--- a/lib/oxidized/api/web.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-module Oxidized
- module API
- class Web
- attr_reader :thread
- def initialize nodes, listen
- require 'oxidized/api/web/webapp'
- addr, port = listen.to_s.split ':'
- port, addr = addr, nil if not port
- WebApp.set :server, %w(puma)
- WebApp.set :bind, addr if addr
- WebApp.set :port, port
- WebApp.set :nodes, nodes
- end
- def run
- @thread = Thread.new { WebApp.run! }
- end
- end
- end
-end
diff --git a/lib/oxidized/api/web/views/default.haml b/lib/oxidized/api/web/views/default.haml
deleted file mode 100644
index 1ff1f4b..0000000
--- a/lib/oxidized/api/web/views/default.haml
+++ /dev/null
@@ -1,4 +0,0 @@
-%html
- !=haml :head
- %body
- =@data
diff --git a/lib/oxidized/api/web/views/head.haml b/lib/oxidized/api/web/views/head.haml
deleted file mode 100644
index f8c41f8..0000000
--- a/lib/oxidized/api/web/views/head.haml
+++ /dev/null
@@ -1,5 +0,0 @@
-%head
- %title oxidized
- %script{:src=>'//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js'}
- %script{:src=>'//cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.13.3/jquery.tablesorter.min.js'}
- %link{:rel=>'stylesheet', :href=>'/stylesheets/oxidized.css'}
diff --git a/lib/oxidized/api/web/views/node.haml b/lib/oxidized/api/web/views/node.haml
deleted file mode 100644
index 6c68e07..0000000
--- a/lib/oxidized/api/web/views/node.haml
+++ /dev/null
@@ -1,6 +0,0 @@
-%html
- !=haml :head
- %body
- -out='';PP.pp(@data,out)
- %pre
- =out
diff --git a/lib/oxidized/api/web/views/nodes.haml b/lib/oxidized/api/web/views/nodes.haml
deleted file mode 100644
index 336a4c2..0000000
--- a/lib/oxidized/api/web/views/nodes.haml
+++ /dev/null
@@ -1,34 +0,0 @@
-%html
- !=haml :head
- %body
- %table{:id=>'nodesTable', :class=>'center tablesorter'}
- %thead
- %tr
- %th Name
- %th IP
- %th Group
- %th Last Status
- %th Last Time
- %th Config
- %th Update
- %tbody
- -trclass = %w(even odd)
- -@data.sort_by{|e|e[:name]}.each do |node|
- -klass = trclass.rotate!.first
- %tr{:class=>klass}
- %td
- %a(href="/node/show/#{node[:name]}") #{node[:name]}
- %td= node[:ip]
- %td= node[:group]
- %td= node[:status]
- %td= node[:time]
- %td
- %a(href="/node/fetch/#{node[:full_name]}") config
- %td
- %a(href="/node/next/#{node[:full_name]}") update
- %p{:class=>'center'}
- %a(href="/reload") reload list of nodes
- :javascript
- $(function(){
- $("#nodesTable").tablesorter();
- });
diff --git a/lib/oxidized/api/web/views/oxidized.sass b/lib/oxidized/api/web/views/oxidized.sass
deleted file mode 100644
index 39d090f..0000000
--- a/lib/oxidized/api/web/views/oxidized.sass
+++ /dev/null
@@ -1,51 +0,0 @@
-$font-stack: Helvetica, sans-serif
-$base03: #002b36
-$base02: #073642
-$base01: #586e75
-$base00: #657b83
-$base0: #839496
-$base1: #93a1a1
-$base2: #eee8d5
-$base3: #fdf6e3
-$yellow: #b58900
-$orange: #cb4b16
-$red: #dc322f
-$magenta: #d33682
-$violet: #6c71c4
-$blue: #268bd2
-$cyan: #2aa198
-$green: #859900
-
-body
- font: 100% $font-stack
- color: $base03
- background: $base3
-
-a:link
- color: $red
- text-decoration: none
-
-// a:visited
-// a:active
-
-a:hover
- color: $magenta
- text-decoration: underline
-
-.center
- margin-left: auto
- margin-right: auto
- text-align: center
-
-th
- color: $cyan
-
-tr.odd
- background: $base2
-
-tr.even
- background: $base3
-
-tr:hover
- background: $base01
- color: $base3
diff --git a/lib/oxidized/api/web/webapp.rb b/lib/oxidized/api/web/webapp.rb
deleted file mode 100644
index 751a4c7..0000000
--- a/lib/oxidized/api/web/webapp.rb
+++ /dev/null
@@ -1,104 +0,0 @@
-require 'sinatra/base'
-require 'sinatra/json'
-require 'haml'
-require 'sass'
-require 'pp'
-module Oxidized
- module API
- class WebApp < Sinatra::Base
-
- get '/' do
- redirect '/nodes'
- end
-
- get '/nodes.?:format?' do
- @data = nodes.list.map do |node|
- node[:status] = 'never'
- node[:time] = 'never'
- node[:group] = 'default' unless node[:group]
- if node[:last]
- node[:status] = node[:last][:status]
- node[:time] = node[:last][:end]
- end
- node
- end
- out :nodes
- end
-
- get '/reload.?:format?' do
- nodes.load
- @data = 'reloaded list of nodes'
- out
- end
-
-
- get '/node/fetch/:node' do
- node, @json = route_parse :node
- @data = nodes.fetch node, nil
- out :text
- end
-
- get '/node/fetch/:group/:node' do
- node, @json = route_parse :node
- @data = nodes.fetch node, params[:group]
- out :text
- end
-
-
- get '/node/next/:node' do
- node, @json = route_parse :node
- nodes.next node
- redirect '/nodes' unless @json
- @data = 'ok'
- out
- end
-
- # use this to attach author/email/message to commit
- put '/node/next/:node' do
- node, @json = route_parse :node
- opt = JSON.load request.body.read
- nodes.next node, opt
- redirect '/nodes' unless @json
- @data = 'ok'
- out
- end
-
- get '/node/show/:node' do
- node, @json = route_parse :node
- @data = nodes.show node
- out :node
- end
-
- get '/stylesheets/*.css' do
- sass params[:splat].first.to_sym
- end
-
- private
-
- def out template=:default
- if @json or params[:format] == 'json'
- json @data
- elsif template == :text
- content_type :text
- @data
- else
- haml template
- end
- end
-
- def nodes
- settings.nodes
- end
-
- def route_parse param
- json = false
- e = params[param].split '.'
- if e.last == 'json'
- e.pop
- json = true
- end
- [e.join('.'), json]
- end
- end
- end
-end
diff --git a/lib/oxidized/cli.rb b/lib/oxidized/cli.rb
index 1e6cf05..aa8c516 100644
--- a/lib/oxidized/cli.rb
+++ b/lib/oxidized/cli.rb
@@ -2,8 +2,6 @@ module Oxidized
class CLI
require 'oxidized'
require 'slop'
- class CLIError < OxidizedError; end
- class NoConfig < CLIError; end
def run
Process.daemon unless CFG.debug
@@ -18,7 +16,6 @@ module Oxidized
private
def initialize
- raise NoConfig, 'edit ~/.config/oxidized/config' if CFGS.create
_args, opts = parse_opts
CFG.debug = true if opts[:debug]
end
diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb
index 48a3879..cb5f81d 100644
--- a/lib/oxidized/config.rb
+++ b/lib/oxidized/config.rb
@@ -1,5 +1,6 @@
module Oxidized
require 'asetus'
+ class NoConfig < OxidizedError; end
class Config
Root = File.join ENV['HOME'], '.config', 'oxidized'
Crash = File.join Root, 'crash'
@@ -41,4 +42,6 @@ module Oxidized
Log.level = Logger::INFO unless CFG.debug
Log.file = CFG.log if CFG.log
+
+ raise NoConfig, 'edit ~/.config/oxidized/config' if CFGS.create
end
diff --git a/lib/oxidized/core.rb b/lib/oxidized/core.rb
index b4f5612..202cb94 100644
--- a/lib/oxidized/core.rb
+++ b/lib/oxidized/core.rb
@@ -5,7 +5,6 @@ module Oxidized
require 'oxidized/worker'
require 'oxidized/nodes'
require 'oxidized/manager'
- require 'oxidized/api/web'
class << self
def new *args
Core.new args
@@ -18,6 +17,11 @@ module Oxidized
nodes = Nodes.new
@worker = Worker.new nodes
if CFG.rest
+ begin
+ require 'oxidized/web'
+ rescue LoadError
+ raise LoadError, 'oxidized-web not found: sudo gem install oxidized-web'
+ end
@rest = API::Web.new nodes, CFG.rest
@rest.run
end
diff --git a/lib/oxidized/model/model.rb b/lib/oxidized/model/model.rb
index dc7d18a..d8f5fe2 100644
--- a/lib/oxidized/model/model.rb
+++ b/lib/oxidized/model/model.rb
@@ -76,7 +76,7 @@ module Oxidized
def cmd string, &block
out = @input.cmd string
return false unless out
- out = Oxidized::String out
+ out = Oxidized::String.new out
self.class.cmds[:all].each do |all_block|
out = instance_exec out, string, &all_block
end
diff --git a/lib/oxidized/string.rb b/lib/oxidized/string.rb
index b334eaa..bcc393a 100644
--- a/lib/oxidized/string.rb
+++ b/lib/oxidized/string.rb
@@ -2,11 +2,11 @@ module Oxidized
# Used in models, contains convenience methods
class String < String
# @return [Oxidized::String] copy of self with last line removed
- def pop
+ def cut_tail
Oxy::String.new each_line.to_a[0..-2].join
end
# @return [Oxidized::String] copy of self with first line removed
- def shift
+ def cut_head
Oxy::String.new each_line.to_a[1..-1].join
end
end
diff --git a/oxidized.gemspec b/oxidized.gemspec
index e72e1ef..34287c2 100644
--- a/oxidized.gemspec
+++ b/oxidized.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'oxidized'
- s.version = '0.0.52'
+ s.version = '0.0.53'
s.platform = Gem::Platform::RUBY
s.authors = [ 'Saku Ytti' ]
s.email = %w( saku@ytti.fi )
@@ -15,9 +15,4 @@ Gem::Specification.new do |s|
s.add_dependency 'asetus', '>= 0.0.7'
s.add_dependency 'slop'
s.add_dependency 'net-ssh'
- s.add_dependency 'sinatra'
- s.add_dependency 'sinatra-contrib'
- s.add_dependency 'puma'
- s.add_dependency 'haml'
- s.add_dependency 'sass'
end