Skip to content
This repository has been archived by the owner on Nov 28, 2017. It is now read-only.

Add a new instance action: Resize #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add a new instance action: Resize #29

wants to merge 3 commits into from

Conversation

xuhang57
Copy link
Collaborator

@xuhang57 xuhang57 commented Mar 9, 2017

Description

API change for allowing a new instance action: Resize.

Checklist before merging Pull Requests

  • Polling instance more often so the user doesn't have to refresh to see the size change
  • Unit test for testing this new action
  • Reviewed and approved by at least one other contributor.

Related PR(s)

The front-end change PR: 11

Potential Problem

We may don't want to allow any user to resize from a larger flavor to a smaller one. OpenStack Horizon allows the user to do that and it might cause problems.
Will discuss this in more details.

Thanks
Lucas

@xuhang57 xuhang57 requested review from knikolla, kamfonik and rob-baron and removed request for knikolla, kamfonik and rob-baron March 14, 2017 19:05
Copy link

@kamfonik kamfonik left a comment

Choose a reason for hiding this comment

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

I'm not familiar enough with the code base to 100% follow these, but I approve of removing that goofy exception...

@@ -51,6 +52,14 @@ def __init__(self, *args, **kwargs):
self.request_user = user
super(InstanceSerializer, self).__init__(*args, **kwargs)

def get_size(self, obj):
from api.v2.serializers.summaries import (

Choose a reason for hiding this comment

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

Should this be imported at the top?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kamfonik hmm, I will ask you on this then. Since this is only used by this function. Sometimes I see people import them within only the functions. But we could also put them on top. What do you think, Laura?

Choose a reason for hiding this comment

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

PEP8 recommends imports only at the top of the file, but I can see that there are already function-level imports elsewhere in this code.

From what I have read there may be a slight performance cost to importing inside the function, but probably only on the first call to the function (after that the module should be cached).

In discussions about this on StackOverflow there were a few notes that some people do import within the function while developing, until they have some stable code and know what they need and where it is used, then they move all the imports to the top to comply with PEP8.

Mostly my thought is that if we are going to violate PEP8 there should be a reason, although the reason could be simple like "consistency with existing code" etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kamfonik Thanks for researching on this. I could clean up the functions that I have modified/created. As for other elsewhere in code base. We either need to have a new PR for cleaning all the code, or keep ignoring them, but make sure we do it properly for the furture PRs.

Choose a reason for hiding this comment

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

@xuhang57 sure, cleaning up is probably not urgent, but deciding now what you want for new code will save a lot of work later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it should be moved to the top

esh_driver.__class__, esh_driver.provider,
esh_driver.identity, esh_instance.id,
core_identity.provider.id, core_identity.id, core_identity.created_by)
task_four = deploy_init_to.si(

Choose a reason for hiding this comment

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

since you are removing task_four, can we remove tthe import of deploy_init_to above in line 361?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, done.

@@ -51,6 +52,14 @@ def __init__(self, *args, **kwargs):
self.request_user = user
super(InstanceSerializer, self).__init__(*args, **kwargs)

def get_size(self, obj):

Choose a reason for hiding this comment

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

I can't find where this new function comes into play. Does it get called in some way by your frontend code?

Copy link
Collaborator Author

@xuhang57 xuhang57 Mar 15, 2017

Choose a reason for hiding this comment

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

@kamfonik Yes, so get_size gets called when we havesize = SerializerMethodField (Line 26) it will call def get_<field-name>

@xuhang57 xuhang57 added the WIP label Mar 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants