resource_in 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8c4c14f7b4880004d746b81563a92fef6cfdb1f
4
- data.tar.gz: 3b02b6126dff78fe353c863215e53d26b761e67d
3
+ metadata.gz: 50c53656ed2eb245432807330e68350588076db3
4
+ data.tar.gz: fbe5aa998daff838fbb1dbeded3ef37a427a0bf8
5
5
  SHA512:
6
- metadata.gz: 0f59e34ca17f34645cda020faba37777daa2d2b04aa6cfb1904637782ae657e4329dda3b9723afa0519bcc536f6d0d90abfc097aa965faa4d39c9f0712b9e944
7
- data.tar.gz: 4da6b34a1e1f97920a113aadce829995937f1c26b7c87459f06e1ac6dc3c62d587f2ef6a36c295743395438b80b30f4942e167cc0183df4b819739ee20e7fc10
6
+ metadata.gz: 85ad60cfc628cac8a5ca8f5c581896988d1cbc2c4cbeaa3867f88b7a8c81bec827c4c1e4ee5d2baf1731c4eaba24455e0d9df9369c8dd3e2d8c3b69f1ff1e75b
7
+ data.tar.gz: 27364307f50be33cdd2ec8fe2a58c4719ff45a286b97ad56ff6b96461b584a19a9e6685aca79aac9a449d0c848bbf1883c239b8d78561df369481e0124092840
data/build.mk ADDED
@@ -0,0 +1,20 @@
1
+ ## This makes CiscoUCS SDK and VMware SDK development environment
2
+
3
+ all: clean init ucs-build vmware-build
4
+
5
+ init:
6
+ [ -d ./build ] || mkdir build
7
+
8
+ clean:
9
+ [ -d ./build ] && sudo rm -fR ./build || true
10
+
11
+ ucs-build:
12
+ sudo apt-get install python2.7
13
+ wget https://communities.cisco.com/servlet/JiveServlet/download/36899-13-76835/UcsSdk-0.8.3.tar.gz -O build/UcsSdk-0.8.3.tar.gz
14
+ tar xzf build/UcsSdk-0.8.3.tar.gz -C build
15
+ cd build/UcsSdk-0.8.3/; /usr/bin/python setup.py build && sudo /usr/bin/python setup.py install
16
+
17
+ vmware-build:
18
+ sudo apt-get install python3 python3-pip git
19
+ git clone https://github.com/vmware/pyvmomi.git build/pyvmomi
20
+ cd build/pyvmomi/; /usr/bin/python3 setup.py build && sudo bash -lc "/usr/bin/python3 setup.py install"
@@ -0,0 +1,25 @@
1
+ module ResourceIn
2
+ class Authorization
3
+ MSG_PERMISSION_ERROR = 'Permission denied for this operation'
4
+
5
+ CMD_WBINFO='/usr/bin/wbinfo'
6
+
7
+ class << self
8
+ def is_viewer?
9
+ self.is_user? or Process.groups.any? {|x| x == self._get_gid('resourcein viewer')}
10
+ end
11
+ def is_user?
12
+ self.is_admin? or Process.groups.any? {|x| x == self._get_gid('resourcein user')}
13
+ end
14
+ def is_admin?
15
+ Process.groups.any? {|x| x == self._get_gid('resourcein admin')}
16
+ end
17
+
18
+ # XXX: Now using 'wbinfo' command to get group information from krb5 cache.
19
+ # It's preferred to get it directly from winbind without 'wbinfo' command.
20
+ def _get_gid(name)
21
+ `#{CMD_WBINFO} --group-info='#{name}'`.split(':')[2].to_i
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,11 +1,16 @@
1
- require_relative 'ucs_driver'
2
- require_relative 'vmware_driver'
1
+ require_relative 'driver_ucs'
2
+ require_relative 'driver_vmware'
3
3
 
4
4
  require 'terminal-table/import'
5
5
 
6
6
  module ResourceIn
7
7
  class Command
8
8
  def self.list(opts, argv)
9
+ unless Authorization.is_viewer?
10
+ puts "[Warning] User '#{ENV['USER']}' needs 'Viewer' permission to execute command 'list'"
11
+ return
12
+ end
13
+
9
14
  resource_kls = case opts[:type]
10
15
  when 'all'
11
16
  Machine
@@ -17,18 +22,30 @@ module ResourceIn
17
22
 
18
23
  resource = resource_kls.new
19
24
 
20
- resource.output(resource.filter(argv.first, resource.list))
25
+ begin
26
+ resource.output(resource.filter(argv.first, resource.list))
27
+ rescue InvalidArgument => e
28
+ puts "[warning] #{e.message}"
29
+ end
21
30
  end
22
31
  def self.get(opts, argv)
23
- machine = Machine.new
32
+ unless Authorization.is_user?
33
+ puts "[Warning] User '#{ENV['USER']}' needs 'User' permission to execute command 'get'"
34
+ return
35
+ end
24
36
 
25
- data = machine.get(argv.first)
37
+ machine = Machine.new
26
38
 
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
39
+ begin
40
+ data = machine.get(argv.first)
41
+ if data != [nil]
42
+ machine.output_detail(data)
43
+ else
44
+ puts "warning: no such resource '#{argv.first}' in this environment."
45
+ exit 1
46
+ end
47
+ rescue InvalidArgument => e
48
+ puts "[warning] #{e.message}"
32
49
  end
33
50
  end
34
51
  end
@@ -0,0 +1,26 @@
1
+ require 'yaml'
2
+
3
+ module ResourceIn
4
+ class Config
5
+ CONFIG_PATH = '/usr/local/etc/rin.yml'
6
+
7
+ class << self
8
+ def [](param)
9
+ (@config_data ||= load_config)['resource-in'][param]
10
+ end
11
+
12
+ private
13
+ def load_config
14
+ unless FileTest.exists?(config_path)
15
+ raise RuntimeError "invalid configuration file (#{config_path})"
16
+ end
17
+
18
+ YAML.load_file(config_path)
19
+ end
20
+
21
+ def config_path
22
+ ENV['RIN_CONFIG'] == nil ? CONFIG_PATH : ENV['RIN_CONFIG']
23
+ end
24
+ end
25
+ end
26
+ end
@@ -4,12 +4,17 @@ module ResourceIn
4
4
  class Driver
5
5
  FORMAT = ['name', 'address', 'status', 'location', 'boottime', 'created_by']
6
6
  DETAIL_FORMAT = ['name', 'address', 'status', 'location', 'boottime', 'created_by', 'cores', 'RAM', 'OS', 'Alarm']
7
+ VALID_PATTERN = /^[0-9A-Za-z[:space:]_\-\.]+$/
8
+
9
+ def validate_condition(argument)
10
+ raise InvalidArgument.new("Invalid Argument: #{argument}") unless !!(argument =~ VALID_PATTERN)
11
+ end
7
12
 
8
13
  def invoke(command, cachepath = '/dev/null')
9
14
  cachepath.gsub!(' ', '_')
10
15
 
11
16
  if !!cachepath and FileTest.exists?(cachepath) and not FileTest.zero?(cachepath)
12
- JSON.parse(File.read(cachepath))
17
+ JSON.parse(File.read(cachepath)) unless FileTest.zero? cachepath
13
18
  else
14
19
  JSON.parse(`#{command} 2> /dev/null | tee #{cachepath}`)
15
20
  end
@@ -8,6 +8,8 @@ module ResourceIn
8
8
  @cachepath = '/tmp/cache.racktables'
9
9
  end
10
10
  def get_lastupdate(vm)
11
+ validate_condition(vm)
12
+
11
13
  invoke("#{@cmd_lastupdate} '#{vm}'", @cachepath + ".last_update.#{vm}")
12
14
  end
13
15
  end
File without changes
@@ -1,5 +1,5 @@
1
1
  require_relative "driver"
2
- require_relative "racktables_driver"
2
+ require_relative "driver_racktables"
3
3
 
4
4
  module ResourceIn
5
5
  class VMwareDriver < Driver
@@ -15,6 +15,8 @@ module ResourceIn
15
15
  end
16
16
  end
17
17
  def get(condition)
18
+ validate_condition(condition)
19
+
18
20
  invoke("#{@cmd_get} #{condition}")
19
21
  end
20
22
  end
@@ -0,0 +1,5 @@
1
+ module ResourceIn
2
+ class PermissionError < RuntimeError; end
3
+ class InvalidConfig < RuntimeError; end
4
+ class InvalidArgument < RuntimeError; end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module ResourceIn
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/resource_in.rb CHANGED
@@ -3,8 +3,11 @@ require "resource_in/command"
3
3
  require "resource_in/machine"
4
4
  require "resource_in/resource"
5
5
  require "resource_in/version"
6
+ require "resource_in/authorization"
7
+ require "resource_in/exception"
8
+ require "resource_in/config"
6
9
 
7
- module ResourceIntegrator
10
+ module ResourceIn
8
11
  def self.version
9
12
  VERSION
10
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resource_in
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyasu OHYAMA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: terminal-table
@@ -42,56 +42,56 @@ dependencies:
42
42
  name: dl_racktables
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.0.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.0.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.11'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.11'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '10.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '3.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.0'
97
97
  description: ''
@@ -102,23 +102,27 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - .gitignore
106
- - .rspec
107
- - .travis.yml
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
108
  - Gemfile
109
109
  - README.md
110
110
  - Rakefile
111
111
  - bin/r-in
112
+ - build.mk
112
113
  - lib/resource_in.rb
114
+ - lib/resource_in/authorization.rb
113
115
  - lib/resource_in/command.rb
116
+ - lib/resource_in/config.rb
114
117
  - lib/resource_in/driver.rb
118
+ - lib/resource_in/driver_racktables.rb
119
+ - lib/resource_in/driver_ucs.rb
120
+ - lib/resource_in/driver_vmware.rb
121
+ - lib/resource_in/exception.rb
115
122
  - lib/resource_in/machine.rb
116
123
  - lib/resource_in/machine_impl.rb
117
- - lib/resource_in/racktables_driver.rb
118
124
  - lib/resource_in/resource.rb
119
- - lib/resource_in/ucs_driver.rb
120
125
  - lib/resource_in/version.rb
121
- - lib/resource_in/vmware_driver.rb
122
126
  - resource-in.gemspec
123
127
  homepage: https://github.com/userlocalhost2000/resource-in
124
128
  licenses: []
@@ -129,19 +133,18 @@ require_paths:
129
133
  - lib
130
134
  required_ruby_version: !ruby/object:Gem::Requirement
131
135
  requirements:
132
- - - '>='
136
+ - - ">="
133
137
  - !ruby/object:Gem::Version
134
138
  version: '0'
135
139
  required_rubygems_version: !ruby/object:Gem::Requirement
136
140
  requirements:
137
- - - '>='
141
+ - - ">="
138
142
  - !ruby/object:Gem::Version
139
143
  version: '0'
140
144
  requirements: []
141
145
  rubyforge_project:
142
- rubygems_version: 2.0.14.1
146
+ rubygems_version: 2.4.5
143
147
  signing_key:
144
148
  specification_version: 4
145
149
  summary: This integrates IT resources.
146
150
  test_files: []
147
- has_rdoc: