e1df55452b0538769a475a1be633a55d818ecae6
[certmaster.git] / certmaster / overlord / cmd_modules / show.py
1 """
2 show introspection commandline
3
4 Copyright 2007, Red Hat, Inc
5 see AUTHORS
6
7 This software may be freely redistributed under the terms of the GNU
8 general public license.
9
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software
12 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
13 """
14
15
16 import optparse
17 import pprint
18 import xmlrpclib
19
20 from func.overlord import command
21 from func.overlord import client
22
23 DEFAULT_PORT = 51234
24
25
26 class ShowHardware(client.command.Command):
27 name = "hardware"
28 usage = "show hardware details"
29
30 # FIXME: we might as well make verbose be in the subclass
31 # and probably an inc variable while we are at it
32 def addOptions(self):
33 self.parser.add_option("-v", "--verbose", dest="verbose",
34 action="store_true")
35 self.parser.add_option("-p", "--port", dest="port")
36
37
38 def handleOptions(self, options):
39 self.port = DEFAULT_PORT
40 if self.options.port:
41 self.port = self.options.port
42
43 def parse(self, argv):
44 self.argv = argv
45 return command.Command.parse(self,argv)
46
47 def do(self,args):
48
49 self.server_spec = self.parentCommand.parentCommand.server_spec
50
51 client_obj = client.Client(self.server_spec,
52 port=self.port,
53 interactive=False,
54 verbose=self.options.verbose,
55 config=self.config)
56
57 results = client_obj.run("hardware", "info", [])
58
59 # if the user
60 top_options = ["port","verbose"]
61
62 for minion in results:
63 print "%s:" % minion
64 minion_data = results[minion]
65 # if user set no args
66 if not args:
67 pprint.pprint(minion_data)
68 continue
69
70 for arg in args:
71 if arg in minion_data:
72 print minion_data[arg]
73
74
75 class Show(client.command.Command):
76 name = "show"
77 usage = "various simple report stuff"
78 subCommandClasses = [ShowHardware]
79 def addOptions(self):
80 self.parser.add_option("-v", "--verbose", dest="verbose",
81 action="store_true")
82 self.parser.add_option("-p", "--port", dest="port",
83 default=DEFAULT_PORT)
84
85 def handleOptions(self, options):
86 self.options = options
87
88 self.verbose = options.verbose
89 self.port = options.port
90
91
92 def parse(self, argv):
93 self.argv = argv
94
95 return command.Command.parse(self, argv)
96
97
98 def do(self, args):
99 pass