MuranoCLI 2.0.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.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.rspec +2 -0
- data/.travis.yml +21 -0
- data/Gemfile +27 -0
- data/LICENSE.txt +19 -0
- data/MuranoCLI.gemspec +50 -0
- data/MuranoCLI.iss +50 -0
- data/README.markdown +208 -0
- data/Rakefile +188 -0
- data/TODO.taskpaper +122 -0
- data/bin/mr +8 -0
- data/bin/murano +84 -0
- data/docs/demo.md +109 -0
- data/lib/MrMurano/Account.rb +211 -0
- data/lib/MrMurano/Config-Migrate.rb +47 -0
- data/lib/MrMurano/Config.rb +286 -0
- data/lib/MrMurano/Mock.rb +63 -0
- data/lib/MrMurano/Product-1P-Device.rb +145 -0
- data/lib/MrMurano/Product-Resources.rb +195 -0
- data/lib/MrMurano/Product.rb +358 -0
- data/lib/MrMurano/ProjectFile.rb +349 -0
- data/lib/MrMurano/Solution-Cors.rb +46 -0
- data/lib/MrMurano/Solution-Endpoint.rb +177 -0
- data/lib/MrMurano/Solution-File.rb +150 -0
- data/lib/MrMurano/Solution-ServiceConfig.rb +140 -0
- data/lib/MrMurano/Solution-Services.rb +326 -0
- data/lib/MrMurano/Solution-Users.rb +129 -0
- data/lib/MrMurano/Solution.rb +59 -0
- data/lib/MrMurano/SubCmdGroupContext.rb +49 -0
- data/lib/MrMurano/SyncUpDown.rb +565 -0
- data/lib/MrMurano/commands/assign.rb +57 -0
- data/lib/MrMurano/commands/businessList.rb +45 -0
- data/lib/MrMurano/commands/completion.rb +152 -0
- data/lib/MrMurano/commands/config.rb +67 -0
- data/lib/MrMurano/commands/content.rb +130 -0
- data/lib/MrMurano/commands/cors.rb +30 -0
- data/lib/MrMurano/commands/domain.rb +17 -0
- data/lib/MrMurano/commands/gb.rb +33 -0
- data/lib/MrMurano/commands/init.rb +138 -0
- data/lib/MrMurano/commands/keystore.rb +157 -0
- data/lib/MrMurano/commands/logs.rb +78 -0
- data/lib/MrMurano/commands/mock.rb +63 -0
- data/lib/MrMurano/commands/password.rb +88 -0
- data/lib/MrMurano/commands/postgresql.rb +41 -0
- data/lib/MrMurano/commands/product.rb +14 -0
- data/lib/MrMurano/commands/productCreate.rb +39 -0
- data/lib/MrMurano/commands/productDelete.rb +33 -0
- data/lib/MrMurano/commands/productDevice.rb +84 -0
- data/lib/MrMurano/commands/productDeviceIdCmds.rb +86 -0
- data/lib/MrMurano/commands/productList.rb +45 -0
- data/lib/MrMurano/commands/productWrite.rb +27 -0
- data/lib/MrMurano/commands/show.rb +80 -0
- data/lib/MrMurano/commands/solution.rb +14 -0
- data/lib/MrMurano/commands/solutionCreate.rb +39 -0
- data/lib/MrMurano/commands/solutionDelete.rb +34 -0
- data/lib/MrMurano/commands/solutionList.rb +45 -0
- data/lib/MrMurano/commands/status.rb +92 -0
- data/lib/MrMurano/commands/sync.rb +60 -0
- data/lib/MrMurano/commands/timeseries.rb +115 -0
- data/lib/MrMurano/commands/tsdb.rb +271 -0
- data/lib/MrMurano/commands/usage.rb +23 -0
- data/lib/MrMurano/commands/zshcomplete.erb +112 -0
- data/lib/MrMurano/commands.rb +32 -0
- data/lib/MrMurano/hash.rb +20 -0
- data/lib/MrMurano/http.rb +153 -0
- data/lib/MrMurano/makePretty.rb +75 -0
- data/lib/MrMurano/schema/pf-v1.0.0.yaml +114 -0
- data/lib/MrMurano/schema/sf-v0.2.0.yaml +77 -0
- data/lib/MrMurano/schema/sf-v0.3.0.yaml +78 -0
- data/lib/MrMurano/template/mock.erb +9 -0
- data/lib/MrMurano/template/projectFile.murano.erb +81 -0
- data/lib/MrMurano/verbosing.rb +99 -0
- data/lib/MrMurano/version.rb +4 -0
- data/lib/MrMurano.rb +20 -0
- data/spec/Account-Passwords_spec.rb +242 -0
- data/spec/Account_spec.rb +272 -0
- data/spec/ConfigFile_spec.rb +50 -0
- data/spec/ConfigMigrate_spec.rb +89 -0
- data/spec/Config_spec.rb +409 -0
- data/spec/Http_spec.rb +204 -0
- data/spec/MakePretties_spec.rb +118 -0
- data/spec/Mock_spec.rb +53 -0
- data/spec/ProductBase_spec.rb +113 -0
- data/spec/ProductContent_spec.rb +162 -0
- data/spec/ProductResources_spec.rb +329 -0
- data/spec/Product_1P_Device_spec.rb +202 -0
- data/spec/Product_1P_RPC_spec.rb +175 -0
- data/spec/Product_spec.rb +153 -0
- data/spec/ProjectFile_spec.rb +324 -0
- data/spec/Solution-Cors_spec.rb +164 -0
- data/spec/Solution-Endpoint_spec.rb +581 -0
- data/spec/Solution-File_spec.rb +212 -0
- data/spec/Solution-ServiceConfig_spec.rb +202 -0
- data/spec/Solution-ServiceDevice_spec.rb +176 -0
- data/spec/Solution-ServiceEventHandler_spec.rb +385 -0
- data/spec/Solution-ServiceModules_spec.rb +465 -0
- data/spec/Solution-UsersRoles_spec.rb +207 -0
- data/spec/Solution_spec.rb +92 -0
- data/spec/SyncRoot_spec.rb +83 -0
- data/spec/SyncUpDown_spec.rb +495 -0
- data/spec/Verbosing_spec.rb +279 -0
- data/spec/_workspace.rb +27 -0
- data/spec/cmd_assign_spec.rb +51 -0
- data/spec/cmd_business_spec.rb +59 -0
- data/spec/cmd_common.rb +72 -0
- data/spec/cmd_config_spec.rb +68 -0
- data/spec/cmd_content_spec.rb +71 -0
- data/spec/cmd_cors_spec.rb +50 -0
- data/spec/cmd_device_spec.rb +96 -0
- data/spec/cmd_domain_spec.rb +32 -0
- data/spec/cmd_init_spec.rb +30 -0
- data/spec/cmd_keystore_spec.rb +97 -0
- data/spec/cmd_password_spec.rb +62 -0
- data/spec/cmd_status_spec.rb +239 -0
- data/spec/cmd_syncdown_spec.rb +86 -0
- data/spec/cmd_syncup_spec.rb +62 -0
- data/spec/cmd_usage_spec.rb +36 -0
- data/spec/fixtures/.mrmuranorc +9 -0
- data/spec/fixtures/ProjectFiles/invalid.yaml +9 -0
- data/spec/fixtures/ProjectFiles/only_meta.yaml +24 -0
- data/spec/fixtures/ProjectFiles/with_routes.yaml +27 -0
- data/spec/fixtures/SolutionFiles/0.2.0.json +20 -0
- data/spec/fixtures/SolutionFiles/0.2.0_invalid.json +18 -0
- data/spec/fixtures/SolutionFiles/0.2.json +21 -0
- data/spec/fixtures/SolutionFiles/0.3.0.json +20 -0
- data/spec/fixtures/SolutionFiles/0.3.0_invalid.json +19 -0
- data/spec/fixtures/SolutionFiles/0.3.json +20 -0
- data/spec/fixtures/SolutionFiles/basic.json +20 -0
- data/spec/fixtures/SolutionFiles/secret.json +6 -0
- data/spec/fixtures/configfile +9 -0
- data/spec/fixtures/dumped_config +42 -0
- data/spec/fixtures/mrmuranorc_deleted_bob +8 -0
- data/spec/fixtures/mrmuranorc_tool_bob +3 -0
- data/spec/fixtures/product_spec_files/example.exoline.spec.yaml +116 -0
- data/spec/fixtures/product_spec_files/example.murano.spec.yaml +14 -0
- data/spec/fixtures/product_spec_files/gwe.exoline.spec.yaml +21 -0
- data/spec/fixtures/product_spec_files/gwe.murano.spec.yaml +16 -0
- data/spec/fixtures/product_spec_files/lightbulb-no-state.yaml +11 -0
- data/spec/fixtures/product_spec_files/lightbulb.yaml +14 -0
- data/spec/fixtures/roles-three.yaml +11 -0
- data/spec/fixtures/syncable_content/assets/icon.png +0 -0
- data/spec/fixtures/syncable_content/assets/index.html +0 -0
- data/spec/fixtures/syncable_content/assets/js/script.js +0 -0
- data/spec/fixtures/syncable_content/modules/table_util.lua +58 -0
- data/spec/fixtures/syncable_content/routes/manyRoutes.lua +11 -0
- data/spec/fixtures/syncable_content/routes/singleRoute.lua +5 -0
- data/spec/fixtures/syncable_content/services/devdata.lua +18 -0
- data/spec/fixtures/syncable_content/services/timers.lua +4 -0
- data/spec/spec_helper.rb +119 -0
- metadata +498 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'MrMurano/Mock'
|
|
2
|
+
|
|
3
|
+
command 'mock' do |c|
|
|
4
|
+
c.syntax = %{murano mock}
|
|
5
|
+
c.summary = %{Enable or disable testpoint. Show current UUID.}
|
|
6
|
+
c.description = %{mock lets you enable testpoints to do local lua development}
|
|
7
|
+
|
|
8
|
+
c.action do |args, options|
|
|
9
|
+
::Commander::UI.enable_paging
|
|
10
|
+
say MrMurano::SubCmdGroupHelp.new(c).get_help
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
command 'mock enable' do |c|
|
|
15
|
+
c.syntax = %{murano mock enable}
|
|
16
|
+
c.summary = %{Create a testpoint file.}
|
|
17
|
+
c.description = %{Run syncup after running this to carry the change through to Murano.
|
|
18
|
+
Returns the UUID to be used for authenticating.
|
|
19
|
+
}
|
|
20
|
+
c.option '--raw', %{print raw uuid}
|
|
21
|
+
c.action do |args, options|
|
|
22
|
+
mock = MrMurano::Mock.new
|
|
23
|
+
uuid = mock.create_testpoint()
|
|
24
|
+
if options.raw then
|
|
25
|
+
say uuid
|
|
26
|
+
else
|
|
27
|
+
say %{Created testpoint file. Run `murano syncup` to activate. The following is the authorization token:}
|
|
28
|
+
say %{$ export AUTHORIZATION="#{uuid}"}
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
command 'mock disable' do |c|
|
|
34
|
+
c.syntax = %{murano mock disable}
|
|
35
|
+
c.summary = %{Remove the testpoint file.}
|
|
36
|
+
c.description = %{Run syncup after running this to carry the change through to Murano.}
|
|
37
|
+
|
|
38
|
+
c.action do |args, options|
|
|
39
|
+
mock = MrMurano::Mock.new
|
|
40
|
+
removed = mock.remove_testpoint()
|
|
41
|
+
if removed then
|
|
42
|
+
say %{Deleted testpoint file. Run `murano syncup` to remove the testpoint.}
|
|
43
|
+
else
|
|
44
|
+
say %{No testpoint file to remove.}
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
command 'mock show' do |c|
|
|
50
|
+
c.syntax = %{murano mock disable}
|
|
51
|
+
c.summary = %{Remove the testpoint file.}
|
|
52
|
+
c.description = %{Run syncup after running this to carry the change through to Murano.}
|
|
53
|
+
|
|
54
|
+
c.action do |args, options|
|
|
55
|
+
mock = MrMurano::Mock.new
|
|
56
|
+
uuid = mock.show()
|
|
57
|
+
if uuid then
|
|
58
|
+
say uuid
|
|
59
|
+
else
|
|
60
|
+
say %{Could not find testpoint file or UUID in testpoint file.}
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
|
|
2
|
+
command :password do |c|
|
|
3
|
+
c.syntax = %{murano password}
|
|
4
|
+
c.summary = %{About password commands}
|
|
5
|
+
c.description = %{Sub-commands for working with usernames and passwords}
|
|
6
|
+
c.action do |args, options|
|
|
7
|
+
::Commander::UI.enable_paging
|
|
8
|
+
say MrMurano::SubCmdGroupHelp.new(c).get_help
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
alias_command 'password current', :config, 'user.name'
|
|
13
|
+
|
|
14
|
+
class Outter
|
|
15
|
+
include MrMurano::Verbose
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
command 'password list' do |c|
|
|
19
|
+
c.syntax = %{murano password list}
|
|
20
|
+
c.summary = %{List the usernames with saved passwords}
|
|
21
|
+
c.description = %{List the usernames and hosts that have been saved}
|
|
22
|
+
c.action do |args, options|
|
|
23
|
+
psd = MrMurano::Passwords.new
|
|
24
|
+
psd.load
|
|
25
|
+
|
|
26
|
+
ret = psd.list
|
|
27
|
+
outter = Outter.new
|
|
28
|
+
outter.outf(ret) do |dd, ios|
|
|
29
|
+
rows=[]
|
|
30
|
+
dd.each_pair do |key, value|
|
|
31
|
+
value.each{|v| rows << [key, v] }
|
|
32
|
+
end
|
|
33
|
+
outter.tabularize({
|
|
34
|
+
:rows=>rows, :headers => [:Host, :Username]
|
|
35
|
+
}, ios)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
command 'password set' do |c|
|
|
43
|
+
c.syntax = %{murano password set <username> [<host>]}
|
|
44
|
+
c.summary = %{Set password for username}
|
|
45
|
+
|
|
46
|
+
c.option '--password PASSWORD', String, %{The password to use}
|
|
47
|
+
c.option '--from_env', %{Use password in MURANO_PASSWORD}
|
|
48
|
+
|
|
49
|
+
c.action do |args, options|
|
|
50
|
+
psd = MrMurano::Passwords.new
|
|
51
|
+
psd.load
|
|
52
|
+
|
|
53
|
+
username = args.shift
|
|
54
|
+
host = args.shift
|
|
55
|
+
host = $cfg['net.host'] if host.nil?
|
|
56
|
+
|
|
57
|
+
if options.password then
|
|
58
|
+
pws = options.password
|
|
59
|
+
elsif options.from_env then
|
|
60
|
+
pws = ENV['MURANO_PASSWORD']
|
|
61
|
+
else
|
|
62
|
+
pws = ask("Password: ") { |q| q.echo = "*" }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
psd.set(host, username, pws)
|
|
66
|
+
psd.save
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
command 'password delete' do |c|
|
|
72
|
+
c.syntax = %{murano password delete <username> [<host>]}
|
|
73
|
+
c.summary = %{Delete password for username}
|
|
74
|
+
|
|
75
|
+
c.action do |args, options|
|
|
76
|
+
psd = MrMurano::Passwords.new
|
|
77
|
+
psd.load
|
|
78
|
+
|
|
79
|
+
username = args.shift
|
|
80
|
+
host = args.shift
|
|
81
|
+
host = $cfg['net.host'] if host.nil?
|
|
82
|
+
|
|
83
|
+
psd.remove(host, username)
|
|
84
|
+
psd.save
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# vim: set ai et sw=2 ts=2 :
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'MrMurano/Solution-ServiceConfig'
|
|
2
|
+
|
|
3
|
+
module MrMurano
|
|
4
|
+
class Postgresql < ServiceConfig
|
|
5
|
+
def initialize
|
|
6
|
+
super
|
|
7
|
+
@serviceName = 'postgresql'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def query(query)
|
|
11
|
+
call(:query, :post, {:sql=>query})
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
command :postgresql do |c|
|
|
17
|
+
c.syntax = %{murano postgresql <SQL Commands>}
|
|
18
|
+
c.summary = %{Query the relational database}
|
|
19
|
+
|
|
20
|
+
c.option '-o', '--output FILE', %{Download to file instead of STDOUT}
|
|
21
|
+
|
|
22
|
+
c.action do |args,options|
|
|
23
|
+
pg = MrMurano::Postgresql.new
|
|
24
|
+
ret = pg.query args.join(' ')
|
|
25
|
+
|
|
26
|
+
io=nil
|
|
27
|
+
if options.output then
|
|
28
|
+
io = File.open(options.output, 'w')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
pg.outf(ret, io) do |dd, ios|
|
|
32
|
+
pg.tabularize({
|
|
33
|
+
:headers=>dd[:columns],
|
|
34
|
+
:rows=>dd[:rows]
|
|
35
|
+
}, ios)
|
|
36
|
+
end
|
|
37
|
+
io.close unless io.nil?
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
# vim: set ai et sw=2 ts=2 :
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'MrMurano/SubCmdGroupContext'
|
|
2
|
+
|
|
3
|
+
command :product do |c|
|
|
4
|
+
c.syntax = %{murano product}
|
|
5
|
+
c.summary = %{About Product}
|
|
6
|
+
c.description = %{Sub-commands for working with Products}
|
|
7
|
+
|
|
8
|
+
c.action do |args, options|
|
|
9
|
+
::Commander::UI.enable_paging
|
|
10
|
+
say MrMurano::SubCmdGroupHelp.new(c).get_help
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# vim: set ai et sw=2 ts=2 :
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
command 'product create' do |c|
|
|
3
|
+
c.syntax = %{murano product create <name>}
|
|
4
|
+
c.summary = %{Create a new product}
|
|
5
|
+
c.option '--save', %{Save new product id to config}
|
|
6
|
+
|
|
7
|
+
c.action do |args, options|
|
|
8
|
+
acc = MrMurano::Account.new
|
|
9
|
+
if args.count < 1 then
|
|
10
|
+
acc.error "Name of product missing"
|
|
11
|
+
exit 1
|
|
12
|
+
end
|
|
13
|
+
name = args[0]
|
|
14
|
+
|
|
15
|
+
ret = acc.new_product(name)
|
|
16
|
+
if ret.nil? then
|
|
17
|
+
acc.error "Create failed"
|
|
18
|
+
exit 5
|
|
19
|
+
end
|
|
20
|
+
if not ret.kind_of?(Hash) and not ret.empty? then
|
|
21
|
+
acc.error "Create failed: #{ret.to_s}"
|
|
22
|
+
exit 2
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# create doesn't return anything, so we need to go look for it.
|
|
26
|
+
ret = acc.products.select{|i| i[:label] == name}
|
|
27
|
+
pid = ret.first[:modelId]
|
|
28
|
+
if pid.nil? or pid.empty? then
|
|
29
|
+
acc.error "Didn't find an apiId!!!! #{ret}"
|
|
30
|
+
exit 3
|
|
31
|
+
end
|
|
32
|
+
if options.save then
|
|
33
|
+
$cfg.set('product.id', pid)
|
|
34
|
+
end
|
|
35
|
+
acc.outf pid
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
# vim: set ai et sw=2 ts=2 :
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'MrMurano/Account'
|
|
2
|
+
|
|
3
|
+
command 'product delete' do |c|
|
|
4
|
+
c.syntax = %{murano product delete <product>}
|
|
5
|
+
c.summary = %{Delete a product}
|
|
6
|
+
c.description = %{Delete a product}
|
|
7
|
+
|
|
8
|
+
c.action do |args, options|
|
|
9
|
+
acc = MrMurano::Account.new
|
|
10
|
+
if args.count < 1 then
|
|
11
|
+
acc.error "Product id or name missing"
|
|
12
|
+
return
|
|
13
|
+
end
|
|
14
|
+
name = args[0]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Need to convert what we got into the internal PID.
|
|
18
|
+
ret = (acc.products or []).select{|i| i.has_value? name }
|
|
19
|
+
|
|
20
|
+
acc.debug "Matches found:"
|
|
21
|
+
acc.outf(ret) if $cfg['tool.debug']
|
|
22
|
+
|
|
23
|
+
if ret.empty? then
|
|
24
|
+
acc.error "No product matching '#{name}' found. Nothing to delete."
|
|
25
|
+
else
|
|
26
|
+
ret = acc.delete_product(ret.first[:pid])
|
|
27
|
+
if not ret.kind_of?(Hash) and not ret.empty? then
|
|
28
|
+
acc.error "Delete failed: #{ret.to_s}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
# vim: set ai et sw=2 ts=2 :
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require 'MrMurano/Product-1P-Device'
|
|
2
|
+
|
|
3
|
+
command 'product device' do |c|
|
|
4
|
+
c.syntax = %{murano product device}
|
|
5
|
+
c.summary = %{Interact with a device in a product}
|
|
6
|
+
c.description = %{Interact with a device in a product}
|
|
7
|
+
|
|
8
|
+
c.action do |a,o|
|
|
9
|
+
::Commander::UI.enable_paging
|
|
10
|
+
say MrMurano::SubCmdGroupHelp.new(c).get_help
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
command 'product device read' do |c|
|
|
15
|
+
c.syntax = %{murano product device read <identifier> (<resources>)}
|
|
16
|
+
c.summary = %{Read recources on a device}
|
|
17
|
+
c.option '-o', '--output FILE', %{Download to file instead of STDOUT}
|
|
18
|
+
|
|
19
|
+
c.action do |args,options|
|
|
20
|
+
snid = args.shift
|
|
21
|
+
prd = MrMurano::Product1PDevice.new
|
|
22
|
+
|
|
23
|
+
if args.count == 0 then
|
|
24
|
+
# fetch list and read all
|
|
25
|
+
args = prd.list(snid).keys
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
io=nil
|
|
29
|
+
io = File.open(options.output, 'w') if options.output
|
|
30
|
+
data = prd.read(snid, args)
|
|
31
|
+
prd.outf(data, io)
|
|
32
|
+
io.close unless io.nil?
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
command 'product device twee' do |c|
|
|
38
|
+
c.syntax = %{murano product device twee <identifier>}
|
|
39
|
+
c.summary = %{Show info about a device}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
c.action do |args,options|
|
|
43
|
+
options.default :width=>HighLine::SystemExtensions.terminal_size[0]
|
|
44
|
+
snid = args.shift
|
|
45
|
+
prd = MrMurano::Product1PDevice.new
|
|
46
|
+
data = prd.twee(snid)
|
|
47
|
+
exit 2 if data.empty?
|
|
48
|
+
|
|
49
|
+
io=nil
|
|
50
|
+
io = File.open(options.output, 'w') if options.output
|
|
51
|
+
prd.outf(data, io) do |dd,ios|
|
|
52
|
+
data={}
|
|
53
|
+
data[:title] = "#{snid} #{dd[:description][:name]} #{dd[:basic][:status]}"
|
|
54
|
+
data[:headers] = [:Resource, :Format, :Modified, :Value]
|
|
55
|
+
data[:rows] = dd[:children].map do |child|
|
|
56
|
+
[ (child[:description][:name] or child[:alias]),
|
|
57
|
+
child[:description][:format],
|
|
58
|
+
child[:basic][:modified],
|
|
59
|
+
(child[:value] or "").to_s[0..22] # TODO adjust based on terminal width
|
|
60
|
+
]
|
|
61
|
+
end
|
|
62
|
+
prd.tabularize(data, ios)
|
|
63
|
+
end
|
|
64
|
+
io.close unless io.nil?
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
command 'product device delete' do |c|
|
|
69
|
+
c.syntax = %{murano product device delete <identifier>}
|
|
70
|
+
c.summary = %{Delete a device}
|
|
71
|
+
|
|
72
|
+
c.action do |args,options|
|
|
73
|
+
snid = args.shift
|
|
74
|
+
prd = MrMurano::Product1PDevice.new
|
|
75
|
+
|
|
76
|
+
ret = prd.remove(snid)
|
|
77
|
+
prd.outf ret unless ret.empty?
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# XXX cannot call this here, since 'sn list' doesn't exist yet.
|
|
82
|
+
#alias_command 'product device list', 'sn list'
|
|
83
|
+
|
|
84
|
+
# vim: set ai et sw=2 ts=2 :
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require 'MrMurano/Product'
|
|
2
|
+
require 'terminal-table'
|
|
3
|
+
|
|
4
|
+
command 'product device list' do |c|
|
|
5
|
+
c.syntax = %{murano product device list [options]}
|
|
6
|
+
c.summary = %{List serial numbers for a product}
|
|
7
|
+
|
|
8
|
+
c.option '--offset NUMBER', Integer, %{Offset to start listing at}
|
|
9
|
+
c.option '--limit NUMBER', Integer, %{How many devices to return}
|
|
10
|
+
c.option '-o', '--output FILE', %{Download to file instead of STDOUT}
|
|
11
|
+
|
|
12
|
+
c.action do |args,options|
|
|
13
|
+
options.default :offset=>0, :limit=>50
|
|
14
|
+
|
|
15
|
+
prd = MrMurano::Product.new
|
|
16
|
+
io=nil
|
|
17
|
+
io = File.open(options.output, 'w') if options.output
|
|
18
|
+
data = prd.list(options.offset, options.limit)
|
|
19
|
+
prd.outf(data, nil) do |dd,ios|
|
|
20
|
+
dt={}
|
|
21
|
+
dt[:headers] = [:SN, :Status, :RID]
|
|
22
|
+
dt[:rows] = data.map{|row| [row[:sn], row[:status], row[:rid]]}
|
|
23
|
+
prd.tabularize(dt, ios)
|
|
24
|
+
end
|
|
25
|
+
io.close unless io.nil?
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
command 'product device enable' do |c|
|
|
30
|
+
c.syntax = %{murano product device enable [<sn>|--file <sns>]}
|
|
31
|
+
c.summary = %{Enable a serial number; Creates device in Murano}
|
|
32
|
+
c.description = %{Enables serial numbers, creating the digial shadow in Murano.
|
|
33
|
+
|
|
34
|
+
NOTE: This opens the 24 hour activation window. If the device does not make
|
|
35
|
+
the activation call within this time, it will need to be enabled again.
|
|
36
|
+
}
|
|
37
|
+
c.option '-f', '--file FILE', %{A file of serial numbers, one per line}
|
|
38
|
+
|
|
39
|
+
c.action do |args,options|
|
|
40
|
+
prd = MrMurano::Product.new
|
|
41
|
+
if options.file then
|
|
42
|
+
File.open(options.file) do |io|
|
|
43
|
+
io.each_line do |line|
|
|
44
|
+
line.strip!
|
|
45
|
+
prd.enable(line) unless line.empty?
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
elsif args.count > 0 then
|
|
49
|
+
prd.enable(args[0])
|
|
50
|
+
else
|
|
51
|
+
prd.error "Missing a serial number to enable"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
command 'product device activate' do |c|
|
|
57
|
+
c.syntax = %{murano product device activate <sn>}
|
|
58
|
+
c.summary = %{Activate a serial number, retriving its CIK}
|
|
59
|
+
c.description = %{Activates a serial number.
|
|
60
|
+
|
|
61
|
+
Generally you should not use this. Instead the device should make the activation
|
|
62
|
+
call itself and save the CIK token. Its just that sometimes when building a
|
|
63
|
+
proof-of-concept it is just easier to hardcode the CIK.
|
|
64
|
+
|
|
65
|
+
Note that you can only activate a device once. After that you cannot retrive the
|
|
66
|
+
CIK again.
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
c.action do |args,options|
|
|
70
|
+
prd = MrMurano::ProductSerialNumber.new
|
|
71
|
+
if args.count < 1 then
|
|
72
|
+
prd.error "Serial number missing"
|
|
73
|
+
return
|
|
74
|
+
end
|
|
75
|
+
sn = args.first
|
|
76
|
+
|
|
77
|
+
prd.outf prd.activate(sn)
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
alias_command 'sn list', 'product device list'
|
|
83
|
+
alias_command 'sn enable', 'product device enable'
|
|
84
|
+
alias_command 'sn activate', 'product device activate'
|
|
85
|
+
|
|
86
|
+
# vim: set ai et sw=2 ts=2 :
|