Permalink
Browse files

Add default and details formatter for describe processes

  • Loading branch information...
1 parent 74dc59b commit 43eb8f361075dfcb0aace8403405a5f35964e7e5 @oldpatricka oldpatricka committed Oct 23, 2012
Showing with 46 additions and 0 deletions.
  1. +3 −0 ceiclient/cli.py
  2. +43 −0 ceiclient/commands.py
View
3 ceiclient/cli.py
@@ -33,6 +33,7 @@ def using_pyon():
parser.add_argument('--timeout', '-t', action='store', dest='timeout', type=int, default=DEFAULT_TIMEOUT)
parser.add_argument('--yaml', '-Y', action='store_const', const=True)
parser.add_argument('--json', '-J', action='store_const', const=True)
+parser.add_argument('--details', '-D', action='store_const', const=True)
parser.add_argument('--run-name', '-n', action='store', dest='run_name')
parser.add_argument('--service-name', '-d', action='store', default=None)
parser.add_argument('--sysname', '-s', action='store', default=None)
@@ -112,6 +113,8 @@ def main():
print(yaml.safe_dump(result, default_flow_style=False)),
elif opts.json:
print(json.dumps(result, indent=4)),
+ elif opts.details:
+ command.details(result)
else:
command.output(result)
View
43 ceiclient/commands.py
@@ -1,6 +1,7 @@
import pprint
import re
import sys
+import yaml
import time
import uuid
@@ -24,13 +25,21 @@ def __init__(self, subparsers):
def output(result):
pprint.pprint(result)
+ @staticmethod
+ def details(result):
+ pprint.pprint(result)
+
class CeiCommandPrintOutput(CeiCommand):
@staticmethod
def output(result):
print(result)
+ @staticmethod
+ def details(result):
+ print(result)
+
class CeiCommandPrintListOutput(CeiCommand):
@@ -39,6 +48,11 @@ def output(result):
for element in result:
print element
+ @staticmethod
+ def details(result):
+ for element in result:
+ print element
+
class DTRSAddDT(CeiCommandPrintOutput):
@@ -618,6 +632,21 @@ def execute(client, opts):
class PDDescribeProcesses(CeiCommand):
name = 'list'
+ output_template = '''
+Process ID = {{ result.upid }}
+Process Name = {{ result.name }}
+Process State = {{ result.state }}
+Hostname = {{ result.hostname }}
+'''
+
+ details_template = '''
+Process ID = {{ result.upid }}
+Process Name = {{ result.name }}
+Process State = {{ result.state }}
+Hostname = {{ result.hostname }}
+Constraints = {{ result.constraints }}
+Configuration = {{ result.configuration }}
+'''
def __init__(self, subparsers):
parser = subparsers.add_parser(self.name)
@@ -626,6 +655,20 @@ def __init__(self, subparsers):
def execute(client, opts):
return client.describe_processes()
+ @staticmethod
+ def output(result):
+ template = Template(PDDescribeProcesses.output_template)
+ for raw_proc in result:
+ print template.render(result=raw_proc)
+
+ @staticmethod
+ def details(result):
+ template = Template(PDDescribeProcesses.details_template)
+ for raw_proc in result:
+ raw_proc['constraints'] = yaml.safe_dump(raw_proc['constraints']).rstrip('\n')
+ raw_proc['configuration'] = yaml.safe_dump(raw_proc['configuration']).rstrip('\n')
+ print template.render(result=raw_proc)
+
class PDTerminateProcess(CeiCommand):

0 comments on commit 43eb8f3

Please sign in to comment.