-
Notifications
You must be signed in to change notification settings - Fork 43
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
Feat/karbon clusters update #351
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5bd8107
create and delete node pools
dc1da36
separate node pools entity
a6c6868
update functionality for nodes count and labels
0dd32de
sanity fix
alaa-bish 927a7f9
functionality to get subnet by name
fd74be2
fix defaults
4249867
fix arguments
fb30a68
fix for etcd min disk size
a6eaeed
Add integration tests
alaa-bish 9a30aa3
fix bug#349
alaa-bish f9eeba4
sanity fix
alaa-bish 41697d6
Revert "fix for etcd min disk size"
beec356
Revert "fix bug#349"
5c02ff3
fixes
c839b16
fixes
4a21575
doc fix
alaa-bish 4e288b2
fixes to wait tasks completion
1937542
fix tests
alaa-bish f5da36f
fixes for update labels failure
0e9d6c8
fix for black issue
9ee456e
add tests
alaa-bish a73e381
fix
alaa-bish 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,176 @@ | ||
# This file is part of Ansible | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
from __future__ import absolute_import, division, print_function | ||
|
||
__metaclass__ = type | ||
|
||
from copy import deepcopy | ||
|
||
from ..prism.subnets import get_subnet_uuid | ||
from .clusters import Cluster | ||
|
||
|
||
class NodePool(Cluster): | ||
kind = "cluster" | ||
|
||
def __init__(self, module, resource_type="/v1-alpha.1/k8s/clusters"): | ||
super(NodePool, self).__init__(module, resource_type=resource_type) | ||
self.build_spec_methods = {} | ||
|
||
def _get_default_pool_spec(self): | ||
Gevorg-Khachatryan-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return deepcopy( | ||
{ | ||
"name": "", | ||
"num_instances": 0, | ||
"ahv_config": { | ||
"cpu": 0, | ||
"disk_mib": 0, | ||
"memory_mib": 0, | ||
"network_uuid": "", | ||
"iscsi_network_uuid": "", | ||
}, | ||
} | ||
) | ||
|
||
def _build_pool_spec(self, payload, config): | ||
payload["name"] = config["node_pool_name"] | ||
if config.get("pool_config"): | ||
payload["num_instances"] = config["pool_config"]["num_instances"] | ||
payload["ahv_config"]["cpu"] = config["pool_config"]["cpu"] | ||
payload["ahv_config"]["memory_mib"] = ( | ||
config["pool_config"]["memory_gb"] * 1024 | ||
) | ||
payload["ahv_config"]["disk_mib"] = config["pool_config"]["disk_gb"] * 1024 | ||
subnet_uuid, err = get_subnet_uuid(config["node_subnet"], self.module) | ||
if err: | ||
return None, err | ||
payload["ahv_config"]["network_uuid"] = subnet_uuid | ||
if config.get("node_iscsi_subnet"): | ||
iscsi_subnet_uuid, err = get_subnet_uuid( | ||
config["node_iscsi_subnet"], self.module | ||
) | ||
if err: | ||
return None, err | ||
payload["ahv_config"]["iscsi_network_uuid"] = iscsi_subnet_uuid | ||
|
||
return payload, None | ||
|
||
def get_pool_spec(self): | ||
default_pool_spec = self._get_default_pool_spec() | ||
error = self.validate_pool_resources() | ||
if error: | ||
return None, error | ||
spec, error = self._build_pool_spec(default_pool_spec, self.module.params) | ||
if error: | ||
return None, error | ||
return spec, None | ||
|
||
def get_labels_spec(self): | ||
Gevorg-Khachatryan-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return deepcopy( | ||
{ | ||
"add_labels": self.module.params.get("add_labels"), | ||
"remove_labels": self.module.params.get("remove_labels"), | ||
} | ||
) | ||
|
||
def add_node_pool(self, cluster_name, data=None): | ||
|
||
endpoint = "add-node-pool" | ||
resp = self.update( | ||
data=data, | ||
uuid=cluster_name, | ||
method="POST", | ||
endpoint=endpoint, | ||
) | ||
return resp | ||
|
||
def get_nodes_count(self, cluster_name, pool_name): | ||
nodes_count = 0 | ||
pool = self.get_node_pool(cluster_name, pool_name) | ||
if pool: | ||
nodes_count = len(pool.get("nodes")) | ||
return nodes_count | ||
|
||
def remove_pool_nodes(self, cluster_name, pool_name): | ||
nodes_count = self.get_nodes_count(cluster_name, pool_name) | ||
resp = {} | ||
if nodes_count: | ||
spec = {"count": nodes_count} | ||
endpoint = "node-pools/{0}/remove-nodes".format(pool_name) | ||
resp = self.update( | ||
data=spec, uuid=cluster_name, endpoint=endpoint, method="POST" | ||
) | ||
return resp | ||
|
||
def remove_node_pool(self, cluster_name, pool_name): | ||
|
||
endpoint = "node-pools/{0}".format(pool_name) | ||
resp = self.delete( | ||
uuid=cluster_name, | ||
endpoint=endpoint, | ||
) | ||
return resp | ||
|
||
def read_node_pools(self, cluster_name): | ||
|
||
endpoint = "node-pools" | ||
resp = self.read( | ||
uuid=cluster_name, | ||
endpoint=endpoint, | ||
) | ||
return resp | ||
|
||
def get_node_pool(self, cluster_name, pool_name): | ||
node_pools = self.read_node_pools(cluster_name) | ||
for pool in node_pools: | ||
if pool.get("name") == pool_name: | ||
return pool | ||
return None | ||
|
||
def update_nodes_count(self, cluster_name, pool_name, actual_count, expected_count): | ||
residual_count = expected_count - actual_count | ||
spec = {"count": abs(residual_count)} | ||
if residual_count > 0: | ||
resp = self.add_node(cluster_name, pool_name, spec) | ||
else: | ||
resp = self.remove_node(cluster_name, pool_name, spec) | ||
return resp | ||
|
||
def add_node(self, cluster_name, pool_name, data=None): | ||
|
||
endpoint = "node-pools/{0}/add-nodes".format(pool_name) | ||
resp = self.update( | ||
data=data, | ||
uuid=cluster_name, | ||
endpoint=endpoint, | ||
method="POST", | ||
) | ||
return resp | ||
|
||
def remove_node(self, cluster_name, pool_name, data=None): | ||
|
||
endpoint = "node-pools/{0}/remove-nodes".format(pool_name) | ||
resp = self.update( | ||
data=data, | ||
uuid=cluster_name, | ||
endpoint=endpoint, | ||
method="POST", | ||
) | ||
return resp | ||
|
||
def update_labels(self, cluster_name, pool_name, data=None, raise_error=True): | ||
|
||
endpoint = "node-pools/{0}/update-labels".format(pool_name) | ||
resp = self.update( | ||
data=data, | ||
uuid=cluster_name, | ||
endpoint=endpoint, | ||
method="POST", | ||
raise_error=raise_error, | ||
) | ||
return resp | ||
|
||
def validate_pool_resources(self): | ||
if not self.module.params.get("node_subnet"): | ||
return "missing required arguments: node_subnet" | ||
return None |
Oops, something went wrong.
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.
kind should be present in Cluster()