resource_in 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +2 -0
- data/Rakefile +6 -0
- data/bin/r-in +40 -0
- data/lib/resource_in/command.rb +35 -0
- data/lib/resource_in/driver.rb +18 -0
- data/lib/resource_in/machine.rb +16 -0
- data/lib/resource_in/machine_impl.rb +80 -0
- data/lib/resource_in/racktables_driver.rb +14 -0
- data/lib/resource_in/resource.rb +32 -0
- data/lib/resource_in/ucs_driver.rb +27 -0
- data/lib/resource_in/version.rb +3 -0
- data/lib/resource_in/vmware_driver.rb +21 -0
- data/lib/resource_in.rb +11 -0
- data/resource-in.gemspec +27 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f8c4c14f7b4880004d746b81563a92fef6cfdb1f
|
4
|
+
data.tar.gz: 3b02b6126dff78fe353c863215e53d26b761e67d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f59e34ca17f34645cda020faba37777daa2d2b04aa6cfb1904637782ae657e4329dda3b9723afa0519bcc536f6d0d90abfc097aa965faa4d39c9f0712b9e944
|
7
|
+
data.tar.gz: 4da6b34a1e1f97920a113aadce829995937f1c26b7c87459f06e1ac6dc3c62d587f2ef6a36c295743395438b80b30f4942e167cc0183df4b819739ee20e7fc10
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/r-in
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__)
|
4
|
+
|
5
|
+
require "optparse"
|
6
|
+
require "resource_in"
|
7
|
+
require "colorize"
|
8
|
+
|
9
|
+
# here is default definition of commandline-options
|
10
|
+
options = {
|
11
|
+
:type => 'all',
|
12
|
+
}
|
13
|
+
parser = OptionParser.new do |opt|
|
14
|
+
opt.banner = <<-EOS
|
15
|
+
Usage: #{"r-in <subcommands>".bold}
|
16
|
+
|
17
|
+
#{"Command Overview".bold}
|
18
|
+
#{"r-in list [condition]".bold}
|
19
|
+
list all resource information overview. When you specify a condition, you can filter results.
|
20
|
+
#{"r-in get [server-name]".bold}
|
21
|
+
get a server information which is specified in argument.
|
22
|
+
EOS
|
23
|
+
end
|
24
|
+
|
25
|
+
subparsers = Hash.new {|h,k|
|
26
|
+
puts "No such subcommand: #{k}"
|
27
|
+
exit 1
|
28
|
+
}
|
29
|
+
subparsers['list'] = OptionParser.new.on('-t [ computing | all(DEFAULT) ] ') \
|
30
|
+
{|type| options[:type] = type}
|
31
|
+
subparsers['get'] = OptionParser.new.on()
|
32
|
+
|
33
|
+
command = parser.order!(ARGV).first
|
34
|
+
subparsers[ARGV.shift].parse!(ARGV) unless ARGV.empty?
|
35
|
+
|
36
|
+
if ResourceIn::Command.respond_to?(command)
|
37
|
+
ResourceIn::Command.send(command, options, ARGV)
|
38
|
+
else
|
39
|
+
puts parser.banner()
|
40
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'ucs_driver'
|
2
|
+
require_relative 'vmware_driver'
|
3
|
+
|
4
|
+
require 'terminal-table/import'
|
5
|
+
|
6
|
+
module ResourceIn
|
7
|
+
class Command
|
8
|
+
def self.list(opts, argv)
|
9
|
+
resource_kls = case opts[:type]
|
10
|
+
when 'all'
|
11
|
+
Machine
|
12
|
+
when 'machine'
|
13
|
+
Machine
|
14
|
+
else
|
15
|
+
raise 'unknown type is detected'
|
16
|
+
end
|
17
|
+
|
18
|
+
resource = resource_kls.new
|
19
|
+
|
20
|
+
resource.output(resource.filter(argv.first, resource.list))
|
21
|
+
end
|
22
|
+
def self.get(opts, argv)
|
23
|
+
machine = Machine.new
|
24
|
+
|
25
|
+
data = machine.get(argv.first)
|
26
|
+
|
27
|
+
if data != [nil]
|
28
|
+
machine.output_detail(data)
|
29
|
+
else
|
30
|
+
puts "warning: no such resource '#{argv.first}' in this environment."
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module ResourceIn
|
4
|
+
class Driver
|
5
|
+
FORMAT = ['name', 'address', 'status', 'location', 'boottime', 'created_by']
|
6
|
+
DETAIL_FORMAT = ['name', 'address', 'status', 'location', 'boottime', 'created_by', 'cores', 'RAM', 'OS', 'Alarm']
|
7
|
+
|
8
|
+
def invoke(command, cachepath = '/dev/null')
|
9
|
+
cachepath.gsub!(' ', '_')
|
10
|
+
|
11
|
+
if !!cachepath and FileTest.exists?(cachepath) and not FileTest.zero?(cachepath)
|
12
|
+
JSON.parse(File.read(cachepath))
|
13
|
+
else
|
14
|
+
JSON.parse(`#{command} 2> /dev/null | tee #{cachepath}`)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative "machine_impl"
|
2
|
+
require_relative "resource"
|
3
|
+
|
4
|
+
module ResourceIn
|
5
|
+
|
6
|
+
class Machine < Resource
|
7
|
+
attr_reader :location, :manager
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
@drivers = [UCSDriver, VMwareDriver]
|
12
|
+
end
|
13
|
+
|
14
|
+
include MachineResourceImpl
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module ResourceIn
|
2
|
+
module MachineResourceImpl
|
3
|
+
def list
|
4
|
+
@drivers.map do |klass|
|
5
|
+
driver_racktables = RacktablesDriver.new
|
6
|
+
obj = klass.new
|
7
|
+
|
8
|
+
case [klass]
|
9
|
+
when [ResourceIn::VMwareDriver]
|
10
|
+
obj.list.map do |each|
|
11
|
+
last_update = driver_racktables.get_lastupdate(each['name'])
|
12
|
+
if !!last_update and last_update['status'] != 'error'
|
13
|
+
each['created_by'] = "#{last_update['person']}"
|
14
|
+
end
|
15
|
+
|
16
|
+
each
|
17
|
+
end
|
18
|
+
else
|
19
|
+
obj.list
|
20
|
+
end
|
21
|
+
end.flatten
|
22
|
+
end
|
23
|
+
def get(condition)
|
24
|
+
@drivers.map do |klass|
|
25
|
+
obj = klass.new
|
26
|
+
|
27
|
+
obj.get(condition)
|
28
|
+
end.flatten
|
29
|
+
end
|
30
|
+
def filter(condition, data)
|
31
|
+
data.select do |d|
|
32
|
+
cond = false
|
33
|
+
cond |= d['name'] =~ /^#{condition}/
|
34
|
+
cond |= d['address'].any? {|x| x =~ /^#{condition}/}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
def output(data)
|
38
|
+
format = Driver::FORMAT
|
39
|
+
|
40
|
+
table_output = table do |t|
|
41
|
+
t.headings = format
|
42
|
+
data.each do |each|
|
43
|
+
line = []
|
44
|
+
format.each_with_index do |k, i|
|
45
|
+
case k
|
46
|
+
when 'address'
|
47
|
+
line[i] = each[k].join("\n")
|
48
|
+
else
|
49
|
+
line[i] = each[k]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
t << line
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
puts table_output
|
57
|
+
end
|
58
|
+
def output_detail(data)
|
59
|
+
table = Terminal::Table.new do |t|
|
60
|
+
format = Driver::DETAIL_FORMAT
|
61
|
+
|
62
|
+
t << [key = format.shift, data.first[key]]
|
63
|
+
t << :separator
|
64
|
+
|
65
|
+
format.each do |k|
|
66
|
+
t << [k, data.first[k]]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
puts table
|
71
|
+
end
|
72
|
+
def do_create(options)
|
73
|
+
@drivers.each do |klass|
|
74
|
+
obj = klass.new
|
75
|
+
|
76
|
+
obj.create(options)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "driver"
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
module ResourceIn
|
5
|
+
class RacktablesDriver < Driver
|
6
|
+
def initialize
|
7
|
+
@cmd_lastupdate = 'get_vm_lastupdate'
|
8
|
+
@cachepath = '/tmp/cache.racktables'
|
9
|
+
end
|
10
|
+
def get_lastupdate(vm)
|
11
|
+
invoke("#{@cmd_lastupdate} '#{vm}'", @cachepath + ".last_update.#{vm}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ResourceIn
|
2
|
+
class Resource
|
3
|
+
attr_reader :name, :type, :drivers
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@drivers = []
|
7
|
+
end
|
8
|
+
|
9
|
+
### These methods are assumed to be override by each Resource SubClass
|
10
|
+
def list
|
11
|
+
# This methods list data from each drivers
|
12
|
+
# @output: Array
|
13
|
+
end
|
14
|
+
|
15
|
+
def filter(data, condition)
|
16
|
+
# This implement filters of input data
|
17
|
+
# @input:
|
18
|
+
# - data : Array
|
19
|
+
# - condition : String
|
20
|
+
# @output : Array
|
21
|
+
end
|
22
|
+
|
23
|
+
def output(data)
|
24
|
+
# This outputs data to STDOUT
|
25
|
+
# @input : Array
|
26
|
+
end
|
27
|
+
|
28
|
+
def do_create(options)
|
29
|
+
# This create resoruce
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative "driver"
|
2
|
+
|
3
|
+
module ResourceIn
|
4
|
+
class UCSDriver < Driver
|
5
|
+
def initialize
|
6
|
+
@cmd_list = '/usr/local/bin/ucs_list_servers'
|
7
|
+
@cachepath = '/tmp/ucs_servers.cache'
|
8
|
+
end
|
9
|
+
def list
|
10
|
+
invoke(@cmd_list, @cachepath).each do |d|
|
11
|
+
d['status'] = case d['status']
|
12
|
+
when 'ok'
|
13
|
+
'ok'
|
14
|
+
else
|
15
|
+
'warning'
|
16
|
+
end
|
17
|
+
d['address'] = []
|
18
|
+
d['boottime'] = ''
|
19
|
+
d['created_by'] = ''
|
20
|
+
end
|
21
|
+
end
|
22
|
+
def get(_)
|
23
|
+
# Not implemented yet
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "driver"
|
2
|
+
require_relative "racktables_driver"
|
3
|
+
|
4
|
+
module ResourceIn
|
5
|
+
class VMwareDriver < Driver
|
6
|
+
def initialize
|
7
|
+
@cmd_list = '/usr/local/bin/vmware_list_servers'
|
8
|
+
@cmd_get = '/usr/local/bin/vmware_get_server'
|
9
|
+
|
10
|
+
@cachepath = '/tmp/vmware_servers.cache'
|
11
|
+
end
|
12
|
+
def list
|
13
|
+
invoke(@cmd_list, @cachepath).each do |d|
|
14
|
+
d['status'] = d['status'] == 'green' ? 'ok' : 'warning'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
def get(condition)
|
18
|
+
invoke("#{@cmd_get} #{condition}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/resource_in.rb
ADDED
data/resource-in.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'resource_in/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "resource_in"
|
8
|
+
spec.version = ResourceIn::VERSION
|
9
|
+
spec.authors = ["Hiroyasu OHYAMA"]
|
10
|
+
spec.email = ["user.localhost2000@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This integrates IT resources.}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = "https://github.com/userlocalhost2000/resource-in"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "bin"
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "terminal-table", "1.5.2"
|
22
|
+
spec.add_runtime_dependency "colorize", "0.7.7"
|
23
|
+
spec.add_runtime_dependency "dl_racktables", "~> 0.0.1"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resource_in
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiroyasu OHYAMA
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: terminal-table
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.5.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.7.7
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dl_racktables
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.11'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.11'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: ''
|
98
|
+
email:
|
99
|
+
- user.localhost2000@gmail.com
|
100
|
+
executables:
|
101
|
+
- r-in
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- .rspec
|
107
|
+
- .travis.yml
|
108
|
+
- Gemfile
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/r-in
|
112
|
+
- lib/resource_in.rb
|
113
|
+
- lib/resource_in/command.rb
|
114
|
+
- lib/resource_in/driver.rb
|
115
|
+
- lib/resource_in/machine.rb
|
116
|
+
- lib/resource_in/machine_impl.rb
|
117
|
+
- lib/resource_in/racktables_driver.rb
|
118
|
+
- lib/resource_in/resource.rb
|
119
|
+
- lib/resource_in/ucs_driver.rb
|
120
|
+
- lib/resource_in/version.rb
|
121
|
+
- lib/resource_in/vmware_driver.rb
|
122
|
+
- resource-in.gemspec
|
123
|
+
homepage: https://github.com/userlocalhost2000/resource-in
|
124
|
+
licenses: []
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.0.14.1
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: This integrates IT resources.
|
146
|
+
test_files: []
|
147
|
+
has_rdoc:
|