-
Notifications
You must be signed in to change notification settings - Fork 135
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
Added minimal cluster support #331
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
676d011
cluster endpoint read support
felix-engelmann 420c0d9
renamed node to more close cluster_member
felix-engelmann 5e79bae
Added functionality to specify target cluster member in containers.cr…
felix-engelmann 4423a1a
Added tests for Cluster Members and Targeted create container
felix-engelmann 34d1601
Added to contributors
felix-engelmann 997d473
pep8 compliance
felix-engelmann fab37f5
Added integration test for cluster member info and all attributes
felix-engelmann e6304b8
more efficient pop and params post parameter
felix-engelmann 676badf
Copied approach of a singleton manager from ajkavanagh
felix-engelmann afd3575
Merge branch 'master' of github.com:felix-engelmann/pylxd
felix-engelmann f1f6e94
Adapted tests for ClusterMembers at client.members
felix-engelmann 5cd8799
pep8 compliance
felix-engelmann 76cda97
removed attributes name and state, as they are not returned
felix-engelmann b9162a2
Removed debug print outputs and Integration tests working
felix-engelmann a22c401
Added tests for cluster endpoint
felix-engelmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (c) 2016 Canonical Ltd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from integration.testing import IntegrationTestCase | ||
|
||
|
||
class ClusterMemberTestCase(IntegrationTestCase): | ||
|
||
def setUp(self): | ||
super(ClusterMemberTestCase, self).setUp() | ||
|
||
if not self.client.has_api_extension('clustering'): | ||
self.skipTest('Required LXD API extension not available!') | ||
|
||
|
||
class TestClusterMembers(ClusterMemberTestCase): | ||
"""Tests for `Client.cluster_members.`""" | ||
|
||
def test_get(self): | ||
"""A cluster member is fetched by its name.""" | ||
|
||
members = self.client.cluster_members.all() | ||
|
||
random_member_name = "%s" % members[0].name | ||
random_member_url = "%s" % members[0].url | ||
|
||
member = self.client.cluster_members.get(random_member_name) | ||
|
||
new_url = "%s" % member.url | ||
self.assertEqual(random_member_url, new_url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright (c) 2016 Canonical Ltd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
from pylxd.models import _model as model | ||
|
||
|
||
class ClusterMember(model.Model): | ||
"""A LXD certificate.""" | ||
|
||
name = model.Attribute(readonly=True) | ||
url = model.Attribute(readonly=True) | ||
database = model.Attribute(readonly=True) | ||
state = model.Attribute(readonly=True) | ||
server_name = model.Attribute(readonly=True) | ||
status = model.Attribute(readonly=True) | ||
message = model.Attribute(readonly=True) | ||
|
||
@classmethod | ||
def get(cls, client, name): | ||
"""Get a certificate by fingerprint.""" | ||
response = client.api.cluster_members[name].get() | ||
|
||
return cls(client, **response.json()['metadata']) | ||
|
||
@classmethod | ||
def all(cls, client): | ||
"""Get all certificates.""" | ||
response = client.api.cluster_members.get() | ||
|
||
nodes = [] | ||
for node in response.json()['metadata']: | ||
name = node.split('/')[-1] | ||
nodes.append(cls(client, name=name)) | ||
return nodes | ||
|
||
@property | ||
def api(self): | ||
return self.client.api.cluster_members[self.name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) 2016 Canonical Ltd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from pylxd.tests import testing | ||
|
||
|
||
class TestClusterMember(testing.PyLXDTestCase): | ||
"""Tests for pylxd.models.ClusterMember.""" | ||
|
||
def test_get(self): | ||
"""A cluster member is retrieved.""" | ||
member = self.client.cluster_members.get('an-member') | ||
|
||
self.assertEqual('https://10.1.1.101:8443', member.url) | ||
|
||
def test_all(self): | ||
"""All cluster members are returned.""" | ||
members = self.client.cluster_members.all() | ||
|
||
self.assertIn('an-member', [m.name for m in members]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 confused me when I first looked at it, and then I realised that the
ClusterMemberManager
is straddling thecluster
segment of the endpoint.This means there is no
ClusterManager
forcluster
? I feel there should be aClusterManager
and then aClusterMemberManager
that hangs off that for members.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.
Thank you for your comments. I tried a lot to have a
ClusterManager
and then a hierarchicalClusterMemberManager
, but as there are no multiple cluster elements and/cluster/members
is a more or less independent endpoint from/cluster
I argue against such a hierarchy. It would take quite some tweaking to get theClusterMemberManager
below theClusterManager
, because unlike with the nestedStoragePoolManagers
, there is no such thing as a/cluster/0/members
endpoint.What is your opinion on it?
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.
So a
ClusterMemberManager
and aClusterManager
can coexist as top level managers. There is also little semantic relation.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.
It feels wrong. My rationale is to help people who are reading the REST API documents; i.e. it's the difference between
At the moment we have a "rule" that is effectively 'replace a
/
with a.
in python code and addall()
,get()
etc to the end.TBH, I'm not a big fan of the current API format (I didn't design it, so take my criticism with a grain of salt, as it might be NIH!!), but I'm holding out to keep it consistent.
However, if it's a lot of work to make the change, then let me know here. I'm just thinking of an empty manager that can then have another manager hung off of it.
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 agree that
client.cluster.members.all()
feels better. However I did not manage to write such a nested Manager, where there exists only one object.Here is how I tried to build it with a
ClusterManager
:and it's child the
ClusterMemberManager
:As you see there is quite a lot of debug outputs inside. I screwed up the api references somehow, because the
Cluster.api
should return sth likeself.client.api.cluster[0]
but that would query/1.0/cluster/0
which is wrong.Do you have a quick idea on how to fix this?
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.
Hmm, interesting; it's sort of been done before with the snapshots manager, but those were on a container (obviously a list of containers). But I'm not sure how to do it ... I'll have a think and get back to you. I'll grab your master and see what I can see.
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 not pushed, just an idea. You find my WIP at: https://github.com/felix-engelmann/pylxd/tree/nested-cluster-manager
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 kind of know what we're trying to do; "basically, create an object to hang
.members
off that does-the-right-thing; I'll have a ponder at the code.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.
Hi @felix-engelmann -- so I've had a go; not sure if I like it! What are your thoughts? It's here: https://github.com/ajkavanagh/pylxd/tree/felix-ajk-alternative, commit: ajkavanagh@755185a
I ended up hacking up a custom ClusterManager to be able to have the singleton and also access members; it looks like the code architecture wasn't designed to do it!
Also, it needs a bit of work (e.g. tests, etc.) -- is it heading in a direction that you'd be happy with?
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.
Thx, cool! I was forcing it too much into the existing structure, what failed. But your solution looks as it is going in the right direction. I'll pick it up from there and adapt the tests etc.