|
|
09283b |
From 33e63ce9959199bdfdf8167d2f64a85776d30141 Mon Sep 17 00:00:00 2001
|
|
|
09283b |
From: Andrew Beekhof <andrew@beekhof.net>
|
|
|
09283b |
Date: Fri, 22 Apr 2016 12:27:10 +1000
|
|
|
09283b |
Subject: [PATCH] fence_compute: improved handling of compute nodes
|
|
|
09283b |
with/without FQDNs
|
|
|
09283b |
|
|
|
09283b |
---
|
|
|
09283b |
fence/agents/compute/fence_compute.py | 94 +++++++++++++++++++++++++++++++----
|
|
|
09283b |
1 file changed, 84 insertions(+), 10 deletions(-)
|
|
|
09283b |
|
|
|
09283b |
diff --git a/fence/agents/compute/fence_compute.py b/fence/agents/compute/fence_compute.py
|
|
|
09283b |
index b93580b..be7fc22 100644
|
|
|
09283b |
--- a/fence/agents/compute/fence_compute.py
|
|
|
09283b |
+++ b/fence/agents/compute/fence_compute.py
|
|
|
09283b |
@@ -202,6 +202,86 @@ def set_power_status(_, options):
|
|
|
09283b |
|
|
|
09283b |
return
|
|
|
09283b |
|
|
|
09283b |
+
|
|
|
09283b |
+def fix_domain(options):
|
|
|
09283b |
+ domains = {}
|
|
|
09283b |
+ last_domain = None
|
|
|
09283b |
+
|
|
|
09283b |
+ if nova:
|
|
|
09283b |
+ # Find it in nova
|
|
|
09283b |
+
|
|
|
09283b |
+ hypervisors = nova.hypervisors.list()
|
|
|
09283b |
+ for hypervisor in hypervisors:
|
|
|
09283b |
+ shorthost = hypervisor.hypervisor_hostname.split('.')[0]
|
|
|
09283b |
+
|
|
|
09283b |
+ if shorthost == hypervisor.hypervisor_hostname:
|
|
|
09283b |
+ # Nova is not using FQDN
|
|
|
09283b |
+ calculated = ""
|
|
|
09283b |
+ else:
|
|
|
09283b |
+ # Compute nodes are named as FQDN, strip off the hostname
|
|
|
09283b |
+ calculated = hypervisor.hypervisor_hostname.replace(shorthost+".", "")
|
|
|
09283b |
+
|
|
|
09283b |
+ domains[calculated] = shorthost
|
|
|
09283b |
+
|
|
|
09283b |
+ if calculated == last_domain:
|
|
|
09283b |
+ # Avoid complaining for each compute node with the same name
|
|
|
09283b |
+ # One hopes they don't appear interleaved as A.com B.com A.com B.com
|
|
|
09283b |
+ logging.debug("Calculated the same domain from: %s" % hypervisor.hypervisor_hostname)
|
|
|
09283b |
+
|
|
|
09283b |
+ elif options.has_key("--domain") and options["--domain"] == calculated:
|
|
|
09283b |
+ # Supplied domain name is valid
|
|
|
09283b |
+ return
|
|
|
09283b |
+
|
|
|
09283b |
+ elif options.has_key("--domain"):
|
|
|
09283b |
+ # Warn in case nova isn't available at some point
|
|
|
09283b |
+ logging.warning("Supplied domain '%s' does not match the one calculated from: %s"
|
|
|
09283b |
+ % (options["--domain"], hypervisor.hypervisor_hostname))
|
|
|
09283b |
+
|
|
|
09283b |
+ last_domain = calculated
|
|
|
09283b |
+
|
|
|
09283b |
+ if len(domains) == 0 and not options.has_key("--domain"):
|
|
|
09283b |
+ logging.error("Could not calculate the domain names used by compute nodes in nova")
|
|
|
09283b |
+
|
|
|
09283b |
+ elif len(domains) == 1 and not options.has_key("--domain"):
|
|
|
09283b |
+ options["--domain"] = last_domain
|
|
|
09283b |
+
|
|
|
09283b |
+ elif len(domains) == 1:
|
|
|
09283b |
+ logging.error("Overriding supplied domain '%s' does not match the one calculated from: %s"
|
|
|
09283b |
+ % (options["--domain"], hypervisor.hypervisor_hostname))
|
|
|
09283b |
+ options["--domain"] = last_domain
|
|
|
09283b |
+
|
|
|
09283b |
+ elif len(domains) > 1:
|
|
|
09283b |
+ logging.error("The supplied domain '%s' did not match any used inside nova: %s"
|
|
|
09283b |
+ % (options["--domain"], repr(domains)))
|
|
|
09283b |
+ sys.exit(1)
|
|
|
09283b |
+
|
|
|
09283b |
+def fix_plug_name(options):
|
|
|
09283b |
+ if options["--action"] == "list":
|
|
|
09283b |
+ return
|
|
|
09283b |
+
|
|
|
09283b |
+ if not options.has_key("--plug"):
|
|
|
09283b |
+ return
|
|
|
09283b |
+
|
|
|
09283b |
+ fix_domain(options)
|
|
|
09283b |
+ short_plug = options["--plug"].split('.')[0]
|
|
|
09283b |
+ logging.debug("Checking target '%s' against calculated domain '%s'"% (options["--plug"], calculated))
|
|
|
09283b |
+
|
|
|
09283b |
+ if not options.has_key("--domain"):
|
|
|
09283b |
+ # Nothing supplied and nova not available... what to do... nothing
|
|
|
09283b |
+ return
|
|
|
09283b |
+
|
|
|
09283b |
+ elif options["--domain"] == "":
|
|
|
09283b |
+ # Ensure any domain is stripped off since nova isn't using FQDN
|
|
|
09283b |
+ options["--plug"] = short_plug
|
|
|
09283b |
+
|
|
|
09283b |
+ elif options["--plug"].find(options["--domain"]):
|
|
|
09283b |
+ # Plug already contains the domain, don't re-add
|
|
|
09283b |
+ return
|
|
|
09283b |
+
|
|
|
09283b |
+ else:
|
|
|
09283b |
+ # Add the domain to the plug
|
|
|
09283b |
+ options["--plug"] = short_plug + "." + options["--domain"]
|
|
|
09283b |
+
|
|
|
09283b |
def get_plugs_list(_, options):
|
|
|
09283b |
result = {}
|
|
|
09283b |
|
|
|
09283b |
@@ -209,12 +289,9 @@ def get_plugs_list(_, options):
|
|
|
09283b |
hypervisors = nova.hypervisors.list()
|
|
|
09283b |
for hypervisor in hypervisors:
|
|
|
09283b |
longhost = hypervisor.hypervisor_hostname
|
|
|
09283b |
- if options["--domain"] != "":
|
|
|
09283b |
- shorthost = longhost.replace("." + options["--domain"], "")
|
|
|
09283b |
- result[longhost] = ("", None)
|
|
|
09283b |
- result[shorthost] = ("", None)
|
|
|
09283b |
- else:
|
|
|
09283b |
- result[longhost] = ("", None)
|
|
|
09283b |
+ shorthost = longhost.split('.')[0]
|
|
|
09283b |
+ result[longhost] = ("", None)
|
|
|
09283b |
+ result[shorthost] = ("", None)
|
|
|
09283b |
return result
|
|
|
09283b |
|
|
|
09283b |
|
|
|
09283b |
@@ -270,7 +347,6 @@ def define_new_opts():
|
|
|
09283b |
"help" : "-d, --domain=[string] DNS domain in which hosts live, useful when the cluster uses short names and nova uses FQDN",
|
|
|
09283b |
"required" : "0",
|
|
|
09283b |
"shortdesc" : "DNS domain in which hosts live",
|
|
|
09283b |
- "default" : "",
|
|
|
09283b |
"order": 5,
|
|
|
09283b |
}
|
|
|
09283b |
all_opt["record-only"] = {
|
|
|
09283b |
@@ -328,9 +404,7 @@ def main():
|
|
|
09283b |
except ImportError:
|
|
|
09283b |
fail_usage("nova not found or not accessible")
|
|
|
09283b |
|
|
|
09283b |
- # Potentially we should make this a pacemaker feature
|
|
|
09283b |
- if options["--action"] != "list" and options["--domain"] != "" and options.has_key("--plug"):
|
|
|
09283b |
- options["--plug"] = options["--plug"] + "." + options["--domain"]
|
|
|
09283b |
+ fix_plug_name(options)
|
|
|
09283b |
|
|
|
09283b |
if options["--record-only"] in [ "2", "Disabled", "disabled" ]:
|
|
|
09283b |
sys.exit(0)
|