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