summaryrefslogtreecommitdiff
path: root/bz2041933-bz2041935-2-fence_openstack-clouds-openrc.patch
blob: 6daa2bb38442496c7971ea2fa0770c0859dc2e2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
From 7d9572ec947d23fa18ac530f07fe33ba148c9634 Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Mon, 17 Jan 2022 14:32:53 +0100
Subject: [PATCH] fence_openstack: fix issues with new clouds.yaml/openrc
 parameters - hardcoded clouds.yaml paths to work like the openstack cli
 client   (used by the resource agents)

---
 agents/openstack/fence_openstack.py     | 55 +++++++++++--------------
 tests/data/metadata/fence_openstack.xml | 10 -----
 2 files changed, 25 insertions(+), 40 deletions(-)

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