|
|
d4ebfc |
From 7d9572ec947d23fa18ac530f07fe33ba148c9634 Mon Sep 17 00:00:00 2001
|
|
|
d4ebfc |
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
|
|
|
d4ebfc |
Date: Mon, 17 Jan 2022 14:32:53 +0100
|
|
|
d4ebfc |
Subject: [PATCH] fence_openstack: fix issues with new clouds.yaml/openrc
|
|
|
d4ebfc |
parameters - hardcoded clouds.yaml paths to work like the openstack cli
|
|
|
d4ebfc |
client (used by the resource agents)
|
|
|
d4ebfc |
|
|
|
d4ebfc |
---
|
|
|
d4ebfc |
agents/openstack/fence_openstack.py | 55 +++++++++++--------------
|
|
|
d4ebfc |
tests/data/metadata/fence_openstack.xml | 10 -----
|
|
|
d4ebfc |
2 files changed, 25 insertions(+), 40 deletions(-)
|
|
|
d4ebfc |
|
|
|
d4ebfc |
diff --git a/agents/openstack/fence_openstack.py b/agents/openstack/fence_openstack.py
|
|
|
d4ebfc |
index d3a4be3aa..666016d78 100644
|
|
|
d4ebfc |
--- a/agents/openstack/fence_openstack.py
|
|
|
d4ebfc |
+++ b/agents/openstack/fence_openstack.py
|
|
|
d4ebfc |
@@ -3,6 +3,7 @@
|
|
|
d4ebfc |
import atexit
|
|
|
d4ebfc |
import logging
|
|
|
d4ebfc |
import sys
|
|
|
d4ebfc |
+import os
|
|
|
d4ebfc |
|
|
|
d4ebfc |
import urllib3
|
|
|
d4ebfc |
|
|
|
d4ebfc |
@@ -27,9 +28,15 @@ def translate_status(instance_status):
|
|
|
d4ebfc |
return "unknown"
|
|
|
d4ebfc |
|
|
|
d4ebfc |
def get_cloud(options):
|
|
|
d4ebfc |
- import os, yaml
|
|
|
d4ebfc |
+ import yaml
|
|
|
d4ebfc |
|
|
|
d4ebfc |
- clouds_yaml = os.path.expanduser("~/.config/openstack/clouds.yaml")
|
|
|
d4ebfc |
+ clouds_yaml = "~/.config/openstack/clouds.yaml"
|
|
|
d4ebfc |
+ if not os.path.exists(os.path.expanduser(clouds_yaml)):
|
|
|
d4ebfc |
+ clouds_yaml = "/etc/openstack/clouds.yaml"
|
|
|
d4ebfc |
+ if not os.path.exists(os.path.expanduser(clouds_yaml)):
|
|
|
d4ebfc |
+ fail_usage("Failed: ~/.config/openstack/clouds.yaml and /etc/openstack/clouds.yaml does not exist")
|
|
|
d4ebfc |
+
|
|
|
d4ebfc |
+ clouds_yaml = os.path.expanduser(clouds_yaml)
|
|
|
d4ebfc |
if os.path.exists(clouds_yaml):
|
|
|
d4ebfc |
with open(clouds_yaml, "r") as yaml_stream:
|
|
|
d4ebfc |
try:
|
|
|
d4ebfc |
@@ -201,22 +208,13 @@ def define_new_opts():
|
|
|
d4ebfc |
"default": "Default",
|
|
|
d4ebfc |
"order": 5,
|
|
|
d4ebfc |
}
|
|
|
d4ebfc |
- all_opt["clouds-yaml"] = {
|
|
|
d4ebfc |
- "getopt": ":",
|
|
|
d4ebfc |
- "longopt": "clouds-yaml",
|
|
|
d4ebfc |
- "help": "--clouds-yaml=[clouds-yaml] Path to the clouds.yaml config file",
|
|
|
d4ebfc |
- "required": "0",
|
|
|
d4ebfc |
- "shortdesc": "clouds.yaml config file",
|
|
|
d4ebfc |
- "default": "~/.config/openstack/clouds.yaml",
|
|
|
d4ebfc |
- "order": 6,
|
|
|
d4ebfc |
- }
|
|
|
d4ebfc |
all_opt["cloud"] = {
|
|
|
d4ebfc |
"getopt": ":",
|
|
|
d4ebfc |
"longopt": "cloud",
|
|
|
d4ebfc |
- "help": "--cloud=[cloud] Openstack cloud (from clouds.yaml).",
|
|
|
d4ebfc |
+ "help": "--cloud=[cloud] Openstack cloud (from ~/.config/openstack/clouds.yaml or /etc/openstack/clouds.yaml).",
|
|
|
d4ebfc |
"required": "0",
|
|
|
d4ebfc |
"shortdesc": "Cloud from clouds.yaml",
|
|
|
d4ebfc |
- "order": 7,
|
|
|
d4ebfc |
+ "order": 6,
|
|
|
d4ebfc |
}
|
|
|
d4ebfc |
all_opt["openrc"] = {
|
|
|
d4ebfc |
"getopt": ":",
|
|
|
d4ebfc |
@@ -224,7 +222,7 @@ def define_new_opts():
|
|
|
d4ebfc |
"help": "--openrc=[openrc] Path to the openrc config file",
|
|
|
d4ebfc |
"required": "0",
|
|
|
d4ebfc |
"shortdesc": "openrc config file",
|
|
|
d4ebfc |
- "order": 8,
|
|
|
d4ebfc |
+ "order": 7,
|
|
|
d4ebfc |
}
|
|
|
d4ebfc |
all_opt["uuid"] = {
|
|
|
d4ebfc |
"getopt": ":",
|
|
|
d4ebfc |
@@ -232,7 +230,7 @@ def define_new_opts():
|
|
|
d4ebfc |
"help": "--uuid=[uuid] Replaced by -n, --plug",
|
|
|
d4ebfc |
"required": "0",
|
|
|
d4ebfc |
"shortdesc": "Replaced by port/-n/--plug",
|
|
|
d4ebfc |
- "order": 9,
|
|
|
d4ebfc |
+ "order": 8,
|
|
|
d4ebfc |
}
|
|
|
d4ebfc |
all_opt["cacert"] = {
|
|
|
d4ebfc |
"getopt": ":",
|
|
|
d4ebfc |
@@ -241,7 +239,7 @@ def define_new_opts():
|
|
|
d4ebfc |
"required": "0",
|
|
|
d4ebfc |
"shortdesc": "SSL X.509 certificates file",
|
|
|
d4ebfc |
"default": "",
|
|
|
d4ebfc |
- "order": 10,
|
|
|
d4ebfc |
+ "order": 9,
|
|
|
d4ebfc |
}
|
|
|
d4ebfc |
all_opt["apitimeout"] = {
|
|
|
d4ebfc |
"getopt": ":",
|
|
|
d4ebfc |
@@ -251,7 +249,7 @@ def define_new_opts():
|
|
|
d4ebfc |
"shortdesc": "Timeout in seconds to use for API calls, default is 60.",
|
|
|
d4ebfc |
"required": "0",
|
|
|
d4ebfc |
"default": 60,
|
|
|
d4ebfc |
- "order": 11,
|
|
|
d4ebfc |
+ "order": 10,
|
|
|
d4ebfc |
}
|
|
|
d4ebfc |
|
|
|
d4ebfc |
|
|
|
d4ebfc |
@@ -267,7 +265,6 @@ def main():
|
|
|
d4ebfc |
"project-name",
|
|
|
d4ebfc |
"user-domain-name",
|
|
|
d4ebfc |
"project-domain-name",
|
|
|
d4ebfc |
- "clouds-yaml",
|
|
|
d4ebfc |
"cloud",
|
|
|
d4ebfc |
"openrc",
|
|
|
d4ebfc |
"port",
|
|
|
d4ebfc |
@@ -312,28 +309,26 @@ def main():
|
|
|
d4ebfc |
|
|
|
d4ebfc |
run_delay(options)
|
|
|
d4ebfc |
|
|
|
d4ebfc |
- if options.get("--clouds-yaml"):
|
|
|
d4ebfc |
- if not os.path.exists(os.path.expanduser(options["--clouds-yaml"])):
|
|
|
d4ebfc |
- fail_usage("Failed: {} does not exist".format(options.get("--clouds-yaml")))
|
|
|
d4ebfc |
- if not options.get("--cloud"):
|
|
|
d4ebfc |
- fail_usage("Failed: \"cloud\" not specified")
|
|
|
d4ebfc |
+ if options.get("--cloud"):
|
|
|
d4ebfc |
cloud = get_cloud(options)
|
|
|
d4ebfc |
- username = cloud.get("username")
|
|
|
d4ebfc |
- password = cloud.get("password")
|
|
|
d4ebfc |
- projectname = cloud.get("project_name")
|
|
|
d4ebfc |
+ username = cloud.get("auth").get("username")
|
|
|
d4ebfc |
+ password = cloud.get("auth").get("password")
|
|
|
d4ebfc |
+ projectname = cloud.get("auth").get("project_name")
|
|
|
d4ebfc |
auth_url = None
|
|
|
d4ebfc |
try:
|
|
|
d4ebfc |
- auth_url = cloud.get("auth_url")
|
|
|
d4ebfc |
+ auth_url = cloud.get("auth").get("auth_url")
|
|
|
d4ebfc |
except KeyError:
|
|
|
d4ebfc |
fail_usage("Failed: You have to set the Keystone service endpoint for authorization")
|
|
|
d4ebfc |
- user_domain_name = cloud.get("user_domain_name")
|
|
|
d4ebfc |
- project_domain_name = cloud.get("project_domain_name")
|
|
|
d4ebfc |
+ user_domain_name = cloud.get("auth").get("user_domain_name")
|
|
|
d4ebfc |
+ project_domain_name = cloud.get("auth").get("project_domain_name")
|
|
|
d4ebfc |
caverify = cloud.get("verify")
|
|
|
d4ebfc |
if caverify in [True, False]:
|
|
|
d4ebfc |
options["--ssl-insecure"] = caverify
|
|
|
d4ebfc |
else:
|
|
|
d4ebfc |
options["--cacert"] = caverify
|
|
|
d4ebfc |
- if options.get("--openrc") and os.path.exists(os.path.expanduser(options["--openrc"])):
|
|
|
d4ebfc |
+ elif options.get("--openrc"):
|
|
|
d4ebfc |
+ if not os.path.exists(os.path.expanduser(options["--openrc"])):
|
|
|
d4ebfc |
+ fail_usage("Failed: {} does not exist".format(options.get("--openrc")))
|
|
|
d4ebfc |
source_env(options["--openrc"])
|
|
|
d4ebfc |
env = os.environ
|
|
|
d4ebfc |
username = env.get("OS_USERNAME")
|
|
|
d4ebfc |
diff --git a/tests/data/metadata/fence_openstack.xml b/tests/data/metadata/fence_openstack.xml
|
|
|
d4ebfc |
index 55a57b4d7..67b2191b7 100644
|
|
|
d4ebfc |
--- a/tests/data/metadata/fence_openstack.xml
|
|
|
d4ebfc |
+++ b/tests/data/metadata/fence_openstack.xml
|
|
|
d4ebfc |
@@ -93,16 +93,6 @@
|
|
|
d4ebfc |
<content type="string" default="Default" />
|
|
|
d4ebfc |
<shortdesc lang="en">Keystone Project Domain Name</shortdesc>
|
|
|
d4ebfc |
</parameter>
|
|
|
d4ebfc |
- <parameter name="clouds-yaml" unique="0" required="0" deprecated="1">
|
|
|
d4ebfc |
- <getopt mixed="--clouds-yaml=[clouds-yaml]" />
|
|
|
d4ebfc |
- <content type="string" default="~/.config/openstack/clouds.yaml" />
|
|
|
d4ebfc |
- <shortdesc lang="en">clouds.yaml config file</shortdesc>
|
|
|
d4ebfc |
- </parameter>
|
|
|
d4ebfc |
- <parameter name="clouds_yaml" unique="0" required="0" obsoletes="clouds-yaml">
|
|
|
d4ebfc |
- <getopt mixed="--clouds-yaml=[clouds-yaml]" />
|
|
|
d4ebfc |
- <content type="string" default="~/.config/openstack/clouds.yaml" />
|
|
|
d4ebfc |
- <shortdesc lang="en">clouds.yaml config file</shortdesc>
|
|
|
d4ebfc |
- </parameter>
|
|
|
d4ebfc |
<parameter name="cloud" unique="0" required="0">
|
|
|
d4ebfc |
<getopt mixed="--cloud=[cloud]" />
|
|
|
d4ebfc |
<content type="string" />
|