Browse code

Expose timeout option to Redfish modules

(cherry picked from commit d8536e47d3fe1d31412f192ce567a9780ae0d521)

Bill Dodd authored on 2019/03/27 02:19:24
Showing 5 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+bugfixes:
1
+  - redfish_utils - expose timeout option for redfish implementations that exceed the 10 second default
... ...
@@ -19,9 +19,10 @@ DELETE_HEADERS = {'accept': 'application/json', 'OData-Version': '4.0'}
19 19
 
20 20
 class RedfishUtils(object):
21 21
 
22
-    def __init__(self, creds, root_uri):
22
+    def __init__(self, creds, root_uri, timeout):
23 23
         self.root_uri = root_uri
24 24
         self.creds = creds
25
+        self.timeout = timeout
25 26
         self._init_session()
26 27
         return
27 28
 
... ...
@@ -33,7 +34,7 @@ class RedfishUtils(object):
33 33
                             url_password=self.creds['pswd'],
34 34
                             force_basic_auth=True, validate_certs=False,
35 35
                             follow_redirects='all',
36
-                            use_proxy=False)
36
+                            use_proxy=False, timeout=self.timeout)
37 37
             data = json.loads(resp.read())
38 38
         except HTTPError as e:
39 39
             return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
... ...
@@ -52,7 +53,7 @@ class RedfishUtils(object):
52 52
                             url_password=self.creds['pswd'],
53 53
                             force_basic_auth=True, validate_certs=False,
54 54
                             follow_redirects='all',
55
-                            use_proxy=False)
55
+                            use_proxy=False, timeout=self.timeout)
56 56
         except HTTPError as e:
57 57
             return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
58 58
         except URLError as e:
... ...
@@ -70,7 +71,7 @@ class RedfishUtils(object):
70 70
                             url_password=self.creds['pswd'],
71 71
                             force_basic_auth=True, validate_certs=False,
72 72
                             follow_redirects='all',
73
-                            use_proxy=False)
73
+                            use_proxy=False, timeout=self.timeout)
74 74
         except HTTPError as e:
75 75
             return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
76 76
         except URLError as e:
... ...
@@ -88,7 +89,7 @@ class RedfishUtils(object):
88 88
                             url_password=self.creds['pswd'],
89 89
                             force_basic_auth=True, validate_certs=False,
90 90
                             follow_redirects='all',
91
-                            use_proxy=False)
91
+                            use_proxy=False, timeout=self.timeout)
92 92
         except HTTPError as e:
93 93
             return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
94 94
         except URLError as e:
... ...
@@ -63,6 +63,12 @@ options:
63 63
     required: false
64 64
     description:
65 65
       - bootdevice when setting boot configuration
66
+  timeout:
67
+    description:
68
+      - Timeout in seconds for URL requests to OOB controller
69
+    default: 10
70
+    type: int
71
+    version_added: '2.7.11'
66 72
 
67 73
 author: "Jose Delarosa (github: jose-delarosa)"
68 74
 '''
... ...
@@ -116,13 +122,14 @@ EXAMPLES = '''
116 116
       userid: "{{ userid }}"
117 117
       userpswd: "{{ userpswd }}"
118 118
 
119
-  - name: Clear Manager Logs
119
+  - name: Clear Manager Logs with a timeout of 20 seconds
120 120
     redfish_command:
121 121
       category: Manager
122 122
       command: ClearLogs
123 123
       baseuri: "{{ baseuri }}"
124 124
       user: "{{ user }}"
125 125
       password: "{{ password }}"
126
+      timeout: 20
126 127
 '''
127 128
 
128 129
 RETURN = '''
... ...
@@ -163,6 +170,7 @@ def main():
163 163
             userpswd=dict(no_log=True),
164 164
             userrole=dict(),
165 165
             bootdevice=dict(),
166
+            timeout=dict(type='int', default=10)
166 167
         ),
167 168
         supports_check_mode=False
168 169
     )
... ...
@@ -180,10 +188,13 @@ def main():
180 180
             'userpswd': module.params['userpswd'],
181 181
             'userrole': module.params['userrole']}
182 182
 
183
+    # timeout
184
+    timeout = module.params['timeout']
185
+
183 186
     # Build root URI
184 187
     root_uri = "https://" + module.params['baseuri']
185 188
     rf_uri = "/redfish/v1/"
186
-    rf_utils = RedfishUtils(creds, root_uri)
189
+    rf_utils = RedfishUtils(creds, root_uri, timeout)
187 190
 
188 191
     # Check that Category is valid
189 192
     if category not in CATEGORY_COMMANDS_ALL:
... ...
@@ -62,6 +62,12 @@ options:
62 62
     description:
63 63
       - value of Manager attribute to update
64 64
     default: 'null'
65
+  timeout:
66
+    description:
67
+      - Timeout in seconds for URL requests to OOB controller
68
+    default: 10
69
+    type: int
70
+    version_added: "2.7.11"
65 71
 
66 72
 author: "Jose Delarosa (github: jose-delarosa)"
67 73
 '''
... ...
@@ -97,7 +103,7 @@ EXAMPLES = '''
97 97
       user: "{{ user }}"
98 98
       password: "{{ password }}"
99 99
 
100
-  - name: Set BIOS default settings
100
+  - name: Set BIOS default settings with a timeout of 20 seconds
101 101
     redfish_config:
102 102
       category: Systems
103 103
       command: SetBiosDefaultSettings
... ...
@@ -134,6 +140,7 @@ EXAMPLES = '''
134 134
       baseuri: "{{ baseuri }}"
135 135
       user: "{{ user}}"
136 136
       password: "{{ password }}"
137
+      timeout: 20
137 138
 '''
138 139
 
139 140
 RETURN = '''
... ...
@@ -169,6 +176,7 @@ def main():
169 169
             mgr_attr_value=dict(default='null'),
170 170
             bios_attr_name=dict(default='null'),
171 171
             bios_attr_value=dict(default='null'),
172
+            timeout=dict(type='int', default=10)
172 173
         ),
173 174
         supports_check_mode=False
174 175
     )
... ...
@@ -183,6 +191,10 @@ def main():
183 183
     # Manager attributes to update
184 184
     mgr_attributes = {'mgr_attr_name': module.params['mgr_attr_name'],
185 185
                       'mgr_attr_value': module.params['mgr_attr_value']}
186
+
187
+    # timeout
188
+    timeout = module.params['timeout']
189
+
186 190
     # BIOS attributes to update
187 191
     bios_attributes = {'bios_attr_name': module.params['bios_attr_name'],
188 192
                        'bios_attr_value': module.params['bios_attr_value']}
... ...
@@ -190,7 +202,7 @@ def main():
190 190
     # Build root URI
191 191
     root_uri = "https://" + module.params['baseuri']
192 192
     rf_uri = "/redfish/v1/"
193
-    rf_utils = RedfishUtils(creds, root_uri)
193
+    rf_utils = RedfishUtils(creds, root_uri, timeout)
194 194
 
195 195
     # Check that Category is valid
196 196
     if category not in CATEGORY_COMMANDS_ALL:
... ...
@@ -42,6 +42,12 @@ options:
42 42
     required: true
43 43
     description:
44 44
       - Password for authentication with OOB controller
45
+  timeout:
46
+    description:
47
+      - Timeout in seconds for URL requests to OOB controller
48
+    default: 10
49
+    type: int
50
+    version_added: '2.7.11'
45 51
 
46 52
 author: "Jose Delarosa (github: jose-delarosa)"
47 53
 '''
... ...
@@ -55,13 +61,14 @@ EXAMPLES = '''
55 55
       user: "{{ user }}"
56 56
       password: "{{ password }}"
57 57
 
58
-  - name: Get fan inventory
58
+  - name: Get fan inventory with a timeout of 20 seconds
59 59
     redfish_facts:
60 60
       category: Chassis
61 61
       command: GetFanInventory
62 62
       baseuri: "{{ baseuri }}"
63 63
       user: "{{ user }}"
64 64
       password: "{{ password }}"
65
+      timeout: 20
65 66
 
66 67
   - name: Get default inventory information
67 68
     redfish_facts:
... ...
@@ -149,6 +156,7 @@ def main():
149 149
             baseuri=dict(required=True),
150 150
             user=dict(required=True),
151 151
             password=dict(required=True, no_log=True),
152
+            timeout=dict(type='int', default=10)
152 153
         ),
153 154
         supports_check_mode=False
154 155
     )
... ...
@@ -157,10 +165,13 @@ def main():
157 157
     creds = {'user': module.params['user'],
158 158
              'pswd': module.params['password']}
159 159
 
160
+    # timeout
161
+    timeout = module.params['timeout']
162
+
160 163
     # Build root URI
161 164
     root_uri = "https://" + module.params['baseuri']
162 165
     rf_uri = "/redfish/v1"
163
-    rf_utils = RedfishUtils(creds, root_uri)
166
+    rf_utils = RedfishUtils(creds, root_uri, timeout)
164 167
 
165 168
     # Build Category list
166 169
     if "all" in module.params['category']: