lmcadm 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,135 @@
1
+ require 'gli'
2
+ module LMCAdm
3
+ include GLI::App
4
+ extend self
5
+ subcommand_option_handling :normal
6
+ desc 'Work on devices'
7
+
8
+ command :device do |c|
9
+ c.desc 'List devices'
10
+ c.command :list do |device_list|
11
+ device_list.desc 'Account UUID|Name'
12
+ device_list.flag :A, :account, :required => true
13
+
14
+ device_list.desc 'Include config information'
15
+ device_list.switch :c, :config
16
+
17
+ device_list.action do |global_options, options|
18
+ account = LMC::Account.get_by_uuid_or_name options[:account]
19
+ t=ProgressVisualizer.new "Getting devices"
20
+ devices = LMC::Device.get_for_account(account)
21
+ t.done
22
+ cols = [{:id => {width: 36}}, :name, :model, :serial, :heartbeatstate]
23
+ if options[:config]
24
+ cols << {"config_state.updateState" => {display_name: "config state"}}
25
+ t = ProgressVisualizer.new "Getting config states"
26
+ devices.each do |device|
27
+ device.config_state
28
+ t.dot
29
+ end
30
+ t.done
31
+ end
32
+ tp devices, cols
33
+ end
34
+ end
35
+
36
+ c.arg_name "device uuid", [:multiple]
37
+ c.desc 'Show device config'
38
+ c.command :config do |device_config|
39
+ device_config.desc 'Account UUID|Name'
40
+ device_config.flag :A, :account
41
+
42
+ device_config.desc 'Write to files'
43
+ device_config.switch :w
44
+ device_config.desc 'Prefix for files'
45
+ device_config.default_value 'config'
46
+ device_config.flag :p, :prefix
47
+
48
+ device_config.desc "Filter OID"
49
+ device_config.flag :filter_oid, "filter-oid"
50
+
51
+ device_config.action do |global_options, options, args|
52
+ account = LMC::Account.get_by_uuid_or_name options[:account]
53
+ all_devices = LMC::Device.get_for_account(account)
54
+ devices = all_devices.select do |device|
55
+ args.include? device.id
56
+ end
57
+ devices.each do |device|
58
+ full_config = device.get_config_for_account(account)
59
+ result_config = full_config
60
+ if options[:filter_oid]
61
+ result_config = full_config["items"].select do |item|
62
+ item == options[:filter_oid]
63
+ end
64
+ end
65
+ puts "result_config class: " + result_config.class.to_s if global_options[:debug]
66
+ puts "result_config class: " + result_config.body_object.class.to_s if global_options[:debug]
67
+ pretty = JSON.pretty_generate(result_config)
68
+ if options[:w]
69
+ IO.write(options[:prefix] + "-" + device.name + '-' + device.id + ".json",pretty)
70
+ else
71
+ puts pretty
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+
79
+ c.arg_name "device uuid"
80
+ c.desc 'Change device config'
81
+ c.command :setconfig do |device_config|
82
+ device_config.desc 'Account UUID|Name'
83
+ device_config.flag :A, :account
84
+
85
+ device_config.desc 'oid'
86
+ device_config.flag :oid
87
+
88
+ device_config.desc 'value'
89
+ device_config.flag :value
90
+
91
+ device_config.desc "json file with new settings\n same as output format but just keep items key on first level"
92
+ device_config.flag :jsonfile
93
+
94
+ device_config.action do |global_options, options, args|
95
+ account = LMC::Account.get_by_uuid_or_name options[:account]
96
+ t = ProgressVisualizer.new "Getting device..."
97
+ all_devices = LMC::Device.get_for_account(account)
98
+ devices = all_devices.select do |device|
99
+ args.include? device.id
100
+ end
101
+ device = devices.first
102
+ if !device.nil?
103
+ t.finished "Done".green
104
+ else
105
+ t.finished "Failed".red
106
+ raise "Device not found"
107
+ end
108
+
109
+ t=ProgressVisualizer.new "Getting current config..."
110
+ config = device.get_config_for_account(account)
111
+ t.finished " Done".green
112
+
113
+ t=ProgressVisualizer.new "Applying changes..."
114
+ if options[:jsonfile]
115
+ jsoncontent = IO.read(options[:jsonfile])
116
+ configchange = JSON.parse jsoncontent
117
+ config.merge! configchange
118
+ end
119
+ if options[:oid] && options[:value]
120
+ config['items'][options[:oid]] = options[:value]
121
+ end
122
+ config.delete "state" # should not send this back
123
+ t.finished " Done".green
124
+
125
+ puts JSON.pretty_generate(config) if global_options[:debug]
126
+ t=ProgressVisualizer.new "Submitting new config..."
127
+ result = device.set_config_for_account(config, account)
128
+ if result.code == 200
129
+ print " " + result["id"].to_s + "..."
130
+ end
131
+ t.finished " " + LMCADMResultInterpreter.interpret_with_color(result)
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,10 @@
1
+ require 'io/console'
2
+
3
+ module LMCAdm
4
+ module Helpers
5
+ def self.read_pw(promptstring=nil)
6
+ puts promptstring unless promptstring.nil?
7
+ STDIN.noecho(&:gets).strip
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module LMCAdm
2
+ module Helpers
3
+ def self.longest_in_collection(coll)
4
+ max = coll.reduce(0) do |memo, str|
5
+ memo > str.length ? memo : str.length
6
+
7
+ end
8
+ return max
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require 'gli'
2
+ module LMCAdm
3
+ include ::GLI::App
4
+ extend self
5
+ #command :cloudiadirect do |c|
6
+ # c.action do
7
+ # puts 'direkt!!!!!'
8
+ # end
9
+ #end
10
+ class TestCommandContainer
11
+
12
+
13
+ #desc 'Check cloud connectivity'
14
+ #command :cloud do |c|
15
+ # c.action do |global_options|
16
+ # lmcen = LMC::Cloud.new(global_options[:cloud_host], global_options[:user], global_options[:password])
17
+ # puts "Base URL: #{lmcen.build_url}"
18
+ # puts "Cloud connection OK" if lmcen.auth_ok
19
+ # if global_options[:v]
20
+ # puts "authentication token: " + lmcen.session_token
21
+ # end
22
+ # end
23
+ #end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module LMCAdm
2
+ VERSION = "0.5.0"
3
+ end
data/lib/lmcadm.rb ADDED
@@ -0,0 +1,13 @@
1
+ #require "lmcadm/version"
2
+ #require 'lmcadm/account_commands'
3
+ #require 'lmcadm/test_command_container'
4
+
5
+ Dir.glob(File.expand_path("../lmcadm/*.rb", __FILE__)).each do |file|
6
+ require file
7
+ end
8
+ Dir.glob(File.expand_path("../lmcadm/helpers/*.rb", __FILE__)).each do |file|
9
+ require file
10
+ end
11
+ module LMCAdm
12
+ # Your code goes here...
13
+ end
data/lmcadm ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ #wrapper script
3
+ #set -x
4
+ GLI_DEBUG=true bundle exec exe/lmcadm "$@"
data/lmcadm.gemspec ADDED
@@ -0,0 +1,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "lmcadm/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lmcadm"
8
+ spec.version = LMCAdm::VERSION
9
+ spec.authors = ["erpel"]
10
+ spec.email = ["philipp@copythat.de"]
11
+
12
+ spec.summary = %q{lmcadm is a command line client for LMC}
13
+ spec.license = "BSD-3-Clause"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against " \
21
+ "public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
+ f.match(%r{^(test|spec|features)/})
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.16"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "minitest", "~> 5.0"
34
+ spec.add_development_dependency "pry-nav", "0.2.4"
35
+
36
+ spec.add_runtime_dependency 'lmc', '~> 0.4.0'
37
+ spec.add_runtime_dependency 'gli', '~> 2.17'
38
+ spec.add_runtime_dependency 'table_print', '~> 1.5'
39
+ spec.add_runtime_dependency 'colorize'
40
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lmcadm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - erpel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-nav
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: lmc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.4.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.4.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: gli
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.17'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.17'
97
+ - !ruby/object:Gem::Dependency
98
+ name: table_print
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.5'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.5'
111
+ - !ruby/object:Gem::Dependency
112
+ name: colorize
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - philipp@copythat.de
128
+ executables:
129
+ - lmcadm
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".idea/lmcadm.iml"
135
+ - ".idea/misc.xml"
136
+ - ".idea/modules.xml"
137
+ - ".idea/vcs.xml"
138
+ - ".ruby-version"
139
+ - ".travis.yml"
140
+ - Gemfile
141
+ - LICENSE.txt
142
+ - README.md
143
+ - Rakefile
144
+ - bin/console
145
+ - bin/setup
146
+ - exe/lmcadm
147
+ - lib/lmcadm.rb
148
+ - lib/lmcadm/ColoredProgressVisualizer.rb
149
+ - lib/lmcadm/Log.rb
150
+ - lib/lmcadm/ProgressVisualizer.rb
151
+ - lib/lmcadm/ResultInterpreter.rb
152
+ - lib/lmcadm/UUID.rb
153
+ - lib/lmcadm/account_commands.rb
154
+ - lib/lmcadm/cloud_commands.rb
155
+ - lib/lmcadm/commands/maintenance.rb
156
+ - lib/lmcadm/commands/principal.rb
157
+ - lib/lmcadm/commands/privatecloud.rb
158
+ - lib/lmcadm/config_commands.rb
159
+ - lib/lmcadm/device_commands.rb
160
+ - lib/lmcadm/helpers/password_helper.rb
161
+ - lib/lmcadm/helpers/string_helpers.rb
162
+ - lib/lmcadm/test_command_container.rb
163
+ - lib/lmcadm/version.rb
164
+ - lmcadm
165
+ - lmcadm.gemspec
166
+ homepage:
167
+ licenses:
168
+ - BSD-3-Clause
169
+ metadata: {}
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 2.6.11
187
+ signing_key:
188
+ specification_version: 4
189
+ summary: lmcadm is a command line client for LMC
190
+ test_files: []