Merge lp:~harlowja/cloud-init/no-prettytable into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Joshua Harlow
Status: Rejected
Rejected by: Scott Moser
Proposed branch: lp:~harlowja/cloud-init/no-prettytable
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 232 lines (+47/-34)
9 files modified
cloudinit/config/cc_debug.py (+3/-2)
cloudinit/config/cc_salt_minion.py (+2/-1)
cloudinit/handlers/cloud_config.py (+2/-1)
cloudinit/netinfo.py (+29/-15)
cloudinit/safeyaml.py (+7/-0)
cloudinit/util.py (+0/-10)
requirements.txt (+0/-3)
tests/unittests/test_runs/test_merge_run.py (+2/-1)
tests/unittests/test_runs/test_simple_run.py (+2/-1)
To merge this branch: bzr merge lp:~harlowja/cloud-init/no-prettytable
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Needs Fixing
cloud-init Commiters Pending
Review via email: mp+238491@code.launchpad.net

Description of the change

Remove prettytable

Output the network and route information using yaml
instead so that it can be easily parsed by applications
looking at the console (if they so desire to do this).

To post a comment you must log in.
1027. By Joshua Harlow

Remove the route number since its not useful when in a list format

1028. By Joshua Harlow

Remove the leftover enumerate() call

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

Hello,
Thank you for taking the time to contribute to cloud-init. Cloud-init has moved its revision control system to git. As a result, we are marking all bzr merge proposals as 'rejected'. If you would like to re-submit this proposal for review, please do so by following the current HACKING documentation at http://cloudinit.readthedocs.io/en/latest/topics/hacking.html .

I would definitely like to see the option of different output style.

Unmerged revisions

1028. By Joshua Harlow

Remove the leftover enumerate() call

1027. By Joshua Harlow

Remove the route number since its not useful when in a list format

1026. By Joshua Harlow

Remove prettytable

Output the network and route information using yaml
instead so that it can be easily parsed by applications
looking at the console (if they so desire to do this).

An example of what this looks like:

http://paste.ubuntu.com/8566656/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cloudinit/config/cc_debug.py'
2--- cloudinit/config/cc_debug.py 2014-01-23 19:28:59 +0000
3+++ cloudinit/config/cc_debug.py 2014-10-15 19:38:21 +0000
4@@ -15,6 +15,7 @@
5 # along with this program. If not, see <http://www.gnu.org/licenses/>.
6
7 from cloudinit import type_utils
8+from cloudinit import safeyaml
9 from cloudinit import util
10 import copy
11 from StringIO import StringIO
12@@ -55,10 +56,10 @@
13 # Now dump it...
14 to_print = StringIO()
15 to_print.write(_make_header("Config"))
16- to_print.write(util.yaml_dumps(dump_cfg))
17+ to_print.write(safeyaml.dumps(dump_cfg))
18 to_print.write("\n")
19 to_print.write(_make_header("MetaData"))
20- to_print.write(util.yaml_dumps(cloud.datasource.metadata))
21+ to_print.write(safeyaml.dumps(cloud.datasource.metadata))
22 to_print.write("\n")
23 to_print.write(_make_header("Misc"))
24 to_print.write("Datasource: %s\n" %
25
26=== modified file 'cloudinit/config/cc_salt_minion.py'
27--- cloudinit/config/cc_salt_minion.py 2014-02-05 15:36:47 +0000
28+++ cloudinit/config/cc_salt_minion.py 2014-10-15 19:38:21 +0000
29@@ -16,6 +16,7 @@
30
31 import os
32
33+from cloudinit import safeyaml
34 from cloudinit import util
35
36 # Note: see http://saltstack.org/topics/installation/
37@@ -41,7 +42,7 @@
38 if 'conf' in salt_cfg:
39 # Add all sections from the conf object to /etc/salt/minion
40 minion_config = os.path.join(config_dir, 'minion')
41- minion_data = util.yaml_dumps(salt_cfg.get('conf'))
42+ minion_data = safeyaml.dumps(salt_cfg.get('conf'))
43 util.write_file(minion_config, minion_data)
44
45 # ... copy the key pair if specified
46
47=== modified file 'cloudinit/handlers/cloud_config.py'
48--- cloudinit/handlers/cloud_config.py 2014-08-26 19:53:41 +0000
49+++ cloudinit/handlers/cloud_config.py 2014-10-15 19:38:21 +0000
50@@ -25,6 +25,7 @@
51 from cloudinit import handlers
52 from cloudinit import log as logging
53 from cloudinit import mergers
54+from cloudinit import safeyaml
55 from cloudinit import util
56
57 from cloudinit.settings import (PER_ALWAYS)
58@@ -92,7 +93,7 @@
59 '',
60 ]
61 lines.extend(file_lines)
62- lines.append(util.yaml_dumps(self.cloud_buf))
63+ lines.append(safeyaml.dumps(self.cloud_buf))
64 else:
65 lines = []
66 util.write_file(self.cloud_fn, "\n".join(lines), 0600)
67
68=== modified file 'cloudinit/netinfo.py'
69--- cloudinit/netinfo.py 2014-09-12 21:22:29 +0000
70+++ cloudinit/netinfo.py 2014-10-15 19:38:21 +0000
71@@ -20,12 +20,11 @@
72 # You should have received a copy of the GNU General Public License
73 # along with this program. If not, see <http://www.gnu.org/licenses/>.
74
75+from cloudinit import safeyaml
76 import cloudinit.util as util
77 from cloudinit.log import logging
78 import re
79
80-from prettytable import PrettyTable
81-
82 LOG = logging.getLogger()
83
84
85@@ -156,11 +155,21 @@
86 lines.append(util.center("Net device info failed", '!', 80))
87 netdev = None
88 if netdev is not None:
89- fields = ['Device', 'Up', 'Address', 'Mask', 'Hw-Address']
90- tbl = PrettyTable(fields)
91+ fields = {
92+ 'up': 'Up',
93+ 'addr': 'Address',
94+ 'mask': 'Mask',
95+ 'hwaddr': 'Hw-Address',
96+ }
97+ rows = []
98 for (dev, d) in netdev.iteritems():
99- tbl.add_row([dev, d["up"], d["addr"], d["mask"], d["hwaddr"]])
100- netdev_s = tbl.get_string()
101+ row = {
102+ 'Device': dev,
103+ }
104+ for (from_key, to_key) in fields.items():
105+ row[to_key] = d[from_key]
106+ rows.append(row)
107+ netdev_s = safeyaml.dumps(rows, explicit_start=False)
108 max_len = len(max(netdev_s.splitlines(), key=len))
109 header = util.center("Net device info", "+", max_len)
110 lines.extend([header, netdev_s])
111@@ -176,15 +185,20 @@
112 util.logexc(LOG, "Route info failed: %s" % e)
113 routes = None
114 if routes is not None:
115- fields = ['Route', 'Destination', 'Gateway',
116- 'Genmask', 'Interface', 'Flags']
117- tbl = PrettyTable(fields)
118- for (n, r) in enumerate(routes):
119- route_id = str(n)
120- tbl.add_row([route_id, r['destination'],
121- r['gateway'], r['genmask'],
122- r['iface'], r['flags']])
123- route_s = tbl.get_string()
124+ fields = {
125+ 'destination': 'Destination',
126+ 'gateway': 'Gateway',
127+ 'genmask': 'Genmask',
128+ 'iface': 'Interface',
129+ 'flags': 'Flags',
130+ }
131+ rows = []
132+ for r in routes:
133+ row = {}
134+ for (from_key, to_key) in fields.items():
135+ row[to_key] = r[from_key]
136+ rows.append(row)
137+ route_s = safeyaml.dumps(rows, explicit_start=False)
138 max_len = len(max(route_s.splitlines(), key=len))
139 header = util.center("Route info", "+", max_len)
140 lines.extend([header, route_s])
141
142=== modified file 'cloudinit/safeyaml.py'
143--- cloudinit/safeyaml.py 2012-09-28 20:35:53 +0000
144+++ cloudinit/safeyaml.py 2014-10-15 19:38:21 +0000
145@@ -30,3 +30,10 @@
146
147 def load(blob):
148 return(yaml.load(blob, Loader=_CustomSafeLoader))
149+
150+
151+def dumps(obj, explicit_start=True):
152+ formatted = yaml.dump(obj, line_break="\n",
153+ indent=4, explicit_start=explicit_start,
154+ explicit_end=True, default_flow_style=False)
155+ return formatted
156
157=== modified file 'cloudinit/util.py'
158--- cloudinit/util.py 2014-09-30 20:24:54 +0000
159+++ cloudinit/util.py 2014-10-15 19:38:21 +0000
160@@ -1270,16 +1270,6 @@
161 logexc(LOG, "Failed writing url content to %s", target_fn)
162
163
164-def yaml_dumps(obj):
165- formatted = yaml.dump(obj,
166- line_break="\n",
167- indent=4,
168- explicit_start=True,
169- explicit_end=True,
170- default_flow_style=False)
171- return formatted
172-
173-
174 def ensure_dir(path, mode=None):
175 if not os.path.isdir(path):
176 # Make the dir and adjust the mode
177
178=== modified file 'requirements.txt'
179--- requirements.txt 2014-03-05 23:05:59 +0000
180+++ requirements.txt 2014-10-15 19:38:21 +0000
181@@ -4,9 +4,6 @@
182 cheetah
183 jinja2
184
185-# This is used for any pretty printing of tabular data.
186-PrettyTable
187-
188 # This one is currently only used by the MAAS datasource. If that
189 # datasource is removed, this is no longer needed
190 oauth
191
192=== modified file 'tests/unittests/test_runs/test_merge_run.py'
193--- tests/unittests/test_runs/test_merge_run.py 2014-09-10 18:32:37 +0000
194+++ tests/unittests/test_runs/test_merge_run.py 2014-10-15 19:38:21 +0000
195@@ -2,6 +2,7 @@
196
197 from .. import helpers
198
199+from cloudinit import safeyaml
200 from cloudinit.settings import (PER_INSTANCE)
201 from cloudinit import stages
202 from cloudinit import util
203@@ -21,7 +22,7 @@
204 'cloud_init_modules': ['write-files'],
205 }
206 ud = self.readResource('user_data.1.txt')
207- cloud_cfg = util.yaml_dumps(cfg)
208+ cloud_cfg = safeyaml.dumps(cfg)
209 util.ensure_dir(os.path.join(new_root, 'etc', 'cloud'))
210 util.write_file(os.path.join(new_root, 'etc',
211 'cloud', 'cloud.cfg'), cloud_cfg)
212
213=== modified file 'tests/unittests/test_runs/test_simple_run.py'
214--- tests/unittests/test_runs/test_simple_run.py 2014-07-23 16:25:35 +0000
215+++ tests/unittests/test_runs/test_simple_run.py 2014-10-15 19:38:21 +0000
216@@ -2,6 +2,7 @@
217
218 from .. import helpers
219
220+from cloudinit import safeyaml
221 from cloudinit.settings import (PER_INSTANCE)
222 from cloudinit import stages
223 from cloudinit import util
224@@ -46,7 +47,7 @@
225 ],
226 'cloud_init_modules': ['write-files'],
227 }
228- cloud_cfg = util.yaml_dumps(cfg)
229+ cloud_cfg = safeyaml.dumps(cfg)
230 util.ensure_dir(os.path.join(new_root, 'etc', 'cloud'))
231 util.write_file(os.path.join(new_root, 'etc',
232 'cloud', 'cloud.cfg'), cloud_cfg)