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 Instance.delete_tags() #459

Merged
merged 3 commits into from Feb 11, 2016
Merged

Conversation

JordonPhillips
Copy link
Contributor

The Tag resource was incorrectly modeled such that it is not a collection on an Instance. As a result, there is no way to batch delete tags from an Instance resource. This adds that functionality in, in a way that won't break on future EC2 resource changes.

In the long term there are plans to codify SDK specific customizations while maintaining a canonically correct resource model, but that will sometime in the future as part of a different story.

Fixes #381

cc @kyleknap @jamesls @mtdowling @rayluo

@JordonPhillips JordonPhillips added the pr/needs-review This PR needs a review from a member of the team. label Jan 26, 2016
@jonathanwcrane
Copy link
Contributor

Amazing.

from boto3.resources.model import Action


def inject_delete_tags(event_name, class_attributes, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if it is a good idea yet, but how about you generate a lazy-loaded docstring and attach it to the method something like this: https://github.com/boto/boto3/blob/develop/boto3/resources/factory.py#L464 in the inject_delete_tags.

I like the idea of modeling it as an actual action so that the documenter will pick it up and document it as a normal method, but I am not a big fan of having to add a new event and register two different handlers to complete the feature. It would be cool if the lazy-loaded docstrings can get flushed out in document_custom_method() so that we do not need to add a new event, we get docstrings for free, and we do not have to add two handlers everytime a resource model is incorrect and we have to add a customization to bridge some logic. Let me know what you think or if it is doable?

@kyleknap
Copy link
Member

kyleknap commented Feb 1, 2016

That is annoying that we cannot fix this. I wish the tags property was a reference to a collection of tags. Otherwise, fix looks appropriate. I did have a suggestion on how we add it though that I think would be good to explore.

@jamesls
Copy link
Member

jamesls commented Feb 2, 2016

Code wise, the actual delete_tags method added looks good. I would like to see a functional test added (possibly with the new stubbing stuff?). So pending:

  • adding tests
  • working with @kyleknap to work out how to best handle documentation for this

this gets a :shipit: from me.

@JordonPhillips JordonPhillips added incorporating-feedback and removed pr/needs-review This PR needs a review from a member of the team. labels Feb 3, 2016
@JordonPhillips JordonPhillips force-pushed the delete_tags branch 3 times, most recently from 712449d to cf3308f Compare February 3, 2016 18:22
The Tag resource was incorrectly modeled such that it is not a
collection on an Instance. As a result, there is no way to batch delete
tags from an Instance resource. This adds that functionality in, in a
way that won't break on future EC2 resource changes.

In the long term there are plans to codify SDK specific customizations
while maintaining a canonically correct resource model, but that will
sometime in the future as part of a different story.

Fixes boto#381
@@ -42,19 +42,19 @@ def test_document_interface_is_documented(self):
request_syntax_contents = self.get_request_syntax_document_block(
method_contents)
self.assert_contains_lines_in_order([
' response = table.put_item(',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the way our assertion / search works here is that it skips through whitespace to find the selected strings. Asserting whitespace is brittle because we may want to tweak formatting. In this case, the custom methods were being put in the wrong section of the generated docs, and moving them to the correct section changed the indentation somewhat.

@JordonPhillips JordonPhillips added pr/needs-review This PR needs a review from a member of the team. and removed incorporating-feedback labels Feb 3, 2016
@JordonPhillips
Copy link
Contributor Author

Changes: Added lots of tests, changed the docs to be lazy-loaded (thus removing the extra event), moved custom methods into the Action section as they should be, fixed some old tests

self._emitter.emit(
'creating-resource-class.%s' % cls_name,
class_attributes=attrs, base_classes=base_classes,
service_context=service_context, emitter=self._emitter)
Copy link
Member

Choose a reason for hiding this comment

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

I think I am fine with this change. Having the service_context is a quite informative bit of information that I could see used in helping create the action or base class and the emitter would seem useful to add extensibility logic when creating a method/class such that you could emit and register your own events on the creation of class/method.

@jamesls what are your thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

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

Service context I see makes sense. I think it's odd to include the emitter in an event emitted by the emitter.

Given you need the emitter to register a function, why not just give the emitter to the class/function on registration instead of at event emission time?

@kyleknap
Copy link
Member

kyleknap commented Feb 3, 2016

Looks good. 🚢 I like that the docstring idea worked out. It will be a lot easier to add custom methods that need to be added for compatibility reasons and can be represented in resource model terms.

I do want @jamesls opinion on adding extra arguments to the creating-resource-class event. I could see people using them so I am fine with them.

This provides a generalized class that can be used in the future to
inject more such actions that can be represented by a model, and then
refactors the delete tags injection to utilize it.
@JordonPhillips
Copy link
Contributor Author

Abstracted out a CustomModeledAction which allows me to pass in an emitter when registering the event, and makes it easier for such things to be added in the future.

self._emitter.emit(
'creating-resource-class.%s' % cls_name,
class_attributes=attrs, base_classes=base_classes,
service_context=service_context, resource_name=resource_name)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the resource_name? Can't we just add it to the constructor of CustomModeledAction and inject it as an argument to create_delete_tags_action or pull it off the event name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could potentially pull it off the event name. I didn't want to add it to CustomModeledAction since you would essentially be providing that info twice because it is part of the event name.

@kyleknap
Copy link
Member

Looks good. Just had those two comments to help cleanup the interface/speed.

@JordonPhillips
Copy link
Contributor Author

Updates:
Added the ability to inject kwargs into a lazy call so that it can be used.
Get the resource name from the event name, and remove it from the event.

@kyleknap
Copy link
Member

Thanks! 🚢 once test pass.

JordonPhillips added a commit that referenced this pull request Feb 11, 2016
@JordonPhillips JordonPhillips merged commit 04045f3 into boto:develop Feb 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/needs-review This PR needs a review from a member of the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants