mcorpc 0.0.1

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.
Files changed (2) hide show
  1. data/lib/mcorpc.rb +104 -0
  2. metadata +62 -0
data/lib/mcorpc.rb ADDED
@@ -0,0 +1,104 @@
1
+ require 'rubygems'
2
+ require 'mcollective'
3
+
4
+ include MCollective::RPC
5
+
6
+ class MCORPC
7
+ attr_reader :mco
8
+
9
+ def conn(agent)
10
+ # Initialize rpcclient connection for agent
11
+ mc = rpcclient(agent)
12
+ mc.reset_filter
13
+ mc.timeout = 60
14
+ # Set -T global
15
+ mc.collective = 'global'
16
+ # Disable Progress bar
17
+ mc.progress = false
18
+ mc.verbose = false
19
+ @mco = mc
20
+ end
21
+
22
+ def close
23
+ # Close rpcclient connection
24
+ @mco.disconnect
25
+ end
26
+
27
+ def reset_filter
28
+ # Reset Filters
29
+ @mco.reset_filter
30
+ end
31
+
32
+ def mcocmd(host,cmd)
33
+ # shellcmd agent to execute commands
34
+ conn("shellcmd")
35
+ value = nil
36
+ # MCO filter for -F hostname='hostname'
37
+ mco.fact_filter "hostname",host
38
+ mco.discover :verbose => false
39
+ response = mco.runcmd(:cmd => cmd)
40
+ response.each { |a| value = a.results[:data][:stdout]}
41
+ return value
42
+ end
43
+
44
+ def mcohostfact(host,fact)
45
+ # facts agent to get fact value for a host
46
+ conn("rpcutil")
47
+ value = nil
48
+ mco.fact_filter "hostname", host
49
+ mco.discover :verbose => false
50
+ response = mco.get_fact(:fact => fact)
51
+ response.each { |a| value = a.results[:data][:value]}
52
+ return value
53
+ end
54
+
55
+ def mcodiscovernode(facts,classes=nil)
56
+ # find agent to discover hosts
57
+ conn("rpcutil")
58
+ value = nil
59
+ facts = facts.split(",")
60
+ # Set fact discovery
61
+ facts.each { |f|
62
+ factName,factValue = f.split("=")
63
+ mco.fact_filter factName, factValue
64
+ }
65
+ #Set class discovery
66
+ if classes
67
+ classes = classes.split(",")
68
+ classes.each {|classname|
69
+ mco.class_filter classname
70
+ }
71
+ end
72
+ mco.discover :verbose => false
73
+ value = mco.discover
74
+ return value
75
+ end
76
+
77
+ def mcodiscoverfact(fact,facts,classes=nil)
78
+ # facts agent to search fact value
79
+ conn("rpcutil")
80
+ value = nil
81
+ facts = facts.split(",")
82
+ # Set fact discovery
83
+ facts.each { |f|
84
+ factName,factValue = f.split("=")
85
+ mco.fact_filter factName, factValue
86
+ }
87
+ #Set class discovery
88
+ if classes
89
+ classes = classes.split(",")
90
+ classes.each {|classname|
91
+ mco.class_filter classname
92
+ }
93
+ end
94
+ mco.discover :verbose => false
95
+ response = mco.get_fact(:fact => fact)
96
+ response.each { |a|
97
+ value = []
98
+ value.push a.results[:data][:value]
99
+ value = value.uniq
100
+ }
101
+ return value
102
+ end
103
+
104
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mcorpc
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - tujwww (Virender Khatri)
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2013-09-05 00:00:00 +05:30
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: MCO Client for agents - shellcmd facts etc.
22
+ email: vir.khatri@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/mcorpc.rb
31
+ has_rdoc: true
32
+ homepage: ""
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.3.6
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: MCO RPC Client
61
+ test_files: []
62
+