Skip to content

Instantly share code, notes, and snippets.

@openstacker
Created April 6, 2019 21:57
Show Gist options
  • Save openstacker/d0fd1d1cefccb40e109008e59d020baf to your computer and use it in GitHub Desktop.
Save openstacker/d0fd1d1cefccb40e109008e59d020baf to your computer and use it in GitHub Desktop.
+def enforce_cluster_auto_scaling_healing_node_count():
+ @decorator.decorator
+ def wrapper(func, *args, **kwargs):
+ cluster = args[1]
+ cluster_template = objects.ClusterTemplate.get_by_uuid(
+ pecan.request.context, cluster.cluster_template_id)
+ cluster_labels = cluster.get("labels")
+ template_labels = cluster_template.get("labels")
+
+ node_count = cluster.get("node_count")
+ min_node_count = cluster_labels.get("min_node_count", template_labels.get("min_node_count")) or or 1
+ max_node_count = cluster_labels.get("min_node_count", template_labels.get("min_node_count")) or node_count
+
+ healing_enabled = cluster_labels.get("auto_healing_enabled", template_labels.get("auto_healing_enabled")) or Flase
+ scaling_enabled = cluster_labels.get("auto_scaling_enabled", template_labels.get("auto_scaling_enabled")) or False
+
+ if healing_enabled or scaling_enabled:
+ if node_count - min_node_count < 1:
+ raise exception.Invalid("Cluster node_count must be greater than min_node_count at least 1.")
+ if max_node_count - node_count < 1:
+ raise exception.Invalid("Cluster node_count must be lesser than max_node_count at least 1.")
+ return func(*args, **kwargs)
+
+ return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment