Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a -j/--json option for euca-describe-* commands #82

Closed
wants to merge 8 commits into from

Conversation

minnus
Copy link

@minnus minnus commented Jul 28, 2016

Outputs json format instead of the standard text formatting
for these tools.

Addresses some of : TOOLS-626

Not sure if the arg parsing should go in init but it was the easiest way to get this going instead of adding it to each subcommand.

@gholms
Copy link
Member

gholms commented Jul 28, 2016

This is an interesting idea! If the option is going to go into __init__ then it would probably make more sense to put format selection there, too, which would eliminate nearly all of the code duplication in this patch. One way of doing that would be to rename print_result to something else in the affected commands and then add a new print_result method to EC2Request that decides whether to output JSON or call the renamed methods. That's a bit more work, but it would get us a bit closer to having pluggable output formats while not having to hack up or override the run method.

I guess I should ask, though: what do you want to accomplish with JSON-formatted output? If we're going to be adding alternative output formats then we might want a more extensible way of invoking them than a dedicated option for each one. The --pretty=yaml option in the euserv-describe-events tool that recently hit mainline eucalyptus would be a good example of that.

One other thing: all euca2ools changes that affect the command line interface must come with documentation. Would you please update the relevant man pages to reflect your changes?

Arg('-j', '--json',
action='store_const', const='true', route_to=None,
help='''Output in json format''')
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this project the first Arg in the list appears immediately after the opening square brace and closing braces appear immediately after whatever precedes them. Please remove the whitespace after the [ and before the ].

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, Done

@minnus
Copy link
Author

minnus commented Jul 29, 2016

Thanks for the prompt review! Yeah, your suggestion worked out well and seems cleaner.

The rational is to allow easier parsing of the euca commands. We have a variety of tools for accounting and monitoring and it was pretty tedious to parse the formatted output. Since the euca commands already have the data stored internally in a nice format, it was straightforward to output as json. We only needed 2 or 3 of the commands but I figured I might as well do them all.

Sure will do docs once you confirm the changes are ok and implementation is stable.

@@ -72,9 +73,19 @@ class EC2Request(AWSQueryRequest, TabifyingMixin):
AUTH_CLASS = requestbuilder.auth.aws.HmacV4Auth
METHOD = 'POST'

ARGS = [Arg('-j', '--json',
action='store_const', const='true', route_to=None,
help='''Output in json format''')]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this more extensible by making it an option that takes an arg, like --pretty=json, so we don't have to clutter the namespace as we add new output formats in the future.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed. Added pretty=json that accepts a list of choices (only json is supported for now).

@gholms
Copy link
Member

gholms commented Aug 3, 2016

As expected, that makes this much cleaner. :-) See the comments above.

I will be out of town for the next week, so I apologize in advance if it takes a while before you get another response.

@gholms
Copy link
Member

gholms commented Aug 23, 2016

How go things, @minnus?

Outputs json format instead of the standard text formatting
for these tools.
Make the code simpler by moving configuration to __init__ and
renaming the subclass print_result method.
Per gholms, json may not always appear in self.args since
requests can invoke others by passing args directly to their
initializers.
@aebruno
Copy link

aebruno commented Dec 9, 2016

@gholms Sorry for the delay on this PR. I'm continuing @minnus work and would be happy to make any additional fixes necessary to get this accepted. We have several tools for accounting and monitoring our euca cloud that makes use of the pretty=json format. Would be great to see this incorporated into the upstream euca2ools. I attempted to tidy things up according to your previous comments above. Let us know how things look. Thanks!

@plessbd
Copy link

plessbd commented May 2, 2017

@gholms any update on what we would need for this. I would also find this useful

@plessbd
Copy link

plessbd commented May 30, 2017

@gholms any updates on this? I have been useing the patch to update my local copy and it seems to work, would be awesome if this was standard.

@minnus minnus closed this Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants