-
Notifications
You must be signed in to change notification settings - Fork 134
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 support for the instances and virtual-machines endpoints. #387
Conversation
Codecov Report
@@ Coverage Diff @@
## master #387 +/- ##
==========================================
+ Coverage 96.48% 96.54% +0.06%
==========================================
Files 12 14 +2
Lines 1053 1072 +19
Branches 123 127 +4
==========================================
+ Hits 1016 1035 +19
Misses 16 16
Partials 21 21
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the large patch; I had some concerns (see inline), but I'm totally sure they are valid. Otherwise, looks great.
pylxd/models/container.py
Outdated
@@ -1,4 +1,4 @@ | |||
# Copyright (c) 2016 Canonical Ltd | |||
# Copyright (c) 2020 Canonical Ltd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep the copyright at 2016 as that's when this file was started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happened because I did git mv container.py instance.py and then created a new container.py. In MAAS we always update the copyright year to the last time it was touched so I've changed this to 2016-2020. Let me know if it should just be 2016.
pylxd/models/instance.py
Outdated
|
||
@property | ||
def api(self): | ||
return getattr(self.client.api, self._endpoint)[self.name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this be:
self.client.api[self._endpoint][self.name]
It took me a while to wrap my head around what the code was doing.
pylxd/models/instance.py
Outdated
self._endpoint = getattr( | ||
instance.client.api, instance._endpoint)[instance.name].files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, is the following possible:?
self.endpoint=instance.client.api[instance._endpoint][instance.name].files
response = self._endpoint.post( | ||
params={'path': filepath}, | ||
data=data, | ||
headers=headers or None) | ||
if response.status_code == 200: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be:
response = self._client.api[self._endpoint][self.instance.name].files.post(...)
I thought self._endpoint
was either containers
or instance
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instace._endpoint is either instance, containers, or virutal-machines. This code is in the subclass FilesManage. FilesManager._endpoint is a reference to the actual object that should be used.
I ended up reusing the name since I couldn't think of a better one :\
|
||
def delete(self, filepath): | ||
self._instance.client.assert_has_api_extension('file_delete') | ||
response = self._endpoint.delete(params={'path': filepath}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This again doesn't seem right? Don't we need to access the self._client.api
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in FilesManager.
response = self._endpoint.get( | ||
params={'path': filepath}, is_api=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
response = self._endpoint.post( | ||
params={'path': filepath}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
def exists(cls, client, name): | ||
"""Determine whether a instance exists.""" | ||
try: | ||
getattr(client, cls._endpoint).get(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this might be nicer as:
client[cls._endpoint].get(name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get TypeError: 'Client' object is not subscriptable if I try that
pylxd/models/instance.py
Outdated
@classmethod | ||
def get(cls, client, name): | ||
"""Get a instance by name.""" | ||
response = getattr(client.api, cls._endpoint)[name].get() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client.api is subscritable but client isn't. I removed getattr here as suggested.
pylxd/models/instance.py
Outdated
information is needed, `Instance.sync` is the method call | ||
that should be used. | ||
""" | ||
response = getattr(client.api, cls._endpoint).get() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here, and in all subsequent locations.
Thanks for the review! I've updated things as suggested. I do still need to use getattr when operating on the client object, and not client.api. |
There was supposed to be a NOT in there. :( Sorry, I sounded like a prat; It meant to say "I'm not totally sure they are valid". (so easy to miss a word). Anyway, I'll try to do the review now, again. |
Signed-off-by: Lee Trager <lee.trager@canonical.com>
Signed-off-by: Lee Trager <lee.trager@canonical.com>
Signed-off-by: Lee Trager <lee.trager@canonical.com>
Signed-off-by: Lee Trager <lee.trager@canonical.com>
It's still failing a couple of integration tests that the master branch isn't (the master branch is failing the broken pipe one: #387): On xenial:
On bionic it's the same:
Bionic passes on master. The first fail is on master, but I think the other two need resolving before we can land this please? |
Signed-off-by: Lee Trager <lee.trager@canonical.com>
Thanks for looking into that. I updated #379 with the three tests that are failing for me with master on xenial. I've updated this pull request to fix the failing integration tests on Bionic. |
Great work in sorting out those issues. I've tested both in LXD on bionic and it's just the original xenial failure that's also on master. So I reckon this is ready to land. Thanks for all the work on it. |
Signed-off-by: Lee Trager lee.trager@canonical.com