Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 2fcbf2c

Browse files
committed
Enable usage of a certificate file when connecting to OneView Appliance
- Bumped up SDK versions to prepare for release - Enabled usage of ssl_certificate as ENV variable and inside Dict - Added certificate files to ignored list
1 parent 99dbd76 commit 2fcbf2c

File tree

10 files changed

+75
-35
lines changed

10 files changed

+75
-35
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@ docs/source/*
6464
!docs/source/conf.py
6565
!docs/source/index.rst
6666
.vscode
67+
68+
#certificate files
69+
*.crt

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# 4.4.0(Unreleased)
1+
# 4.4.0
2+
#### Notes
3+
Enabled usage of a CA Certificate file for establishing a SSL connection to the HPE OneView Appliance.
4+
25
#### New Resources:
36
- Version
47

58
#### Bug fixes & Enhancements
69
- [#332](https://github.com/HewlettPackard/python-hpOneView/issues/332) example scmb.py is broken with v4.x libray
10+
- [#339](https://github.com/HewlettPackard/python-hpOneView/issues/339) Validate secure connection to OneView using a certificate file
711

812
# 4.3.0
913
#### Notes

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export ONEVIEWSDK_SESSIONID='123'
9696
# Optional
9797
export ONEVIEWSDK_API_VERSION='300'
9898
export ONEVIEWSDK_AUTH_LOGIN_DOMAIN='authdomain'
99+
export ONEVIEWSDK_SSL_CERTIFICATE='<path_to_cert.crt_file>'
99100
export ONEVIEWSDK_PROXY='<proxy_host>:<proxy_port>'
100101
```
101102

@@ -140,6 +141,33 @@ oneview_client = OneViewClient(config)
140141

141142
:lock: Tip: Check the file permissions because the password is stored in clear-text.
142143

144+
### SSL Server Certificate
145+
146+
To enable the SDK to establish a SSL connection to the HPE OneView server, it is necessary to generate a CA Cert file containing the server credentials.
147+
148+
1. Fetch the HPE OneView Appliance CA certificate
149+
150+
Example:
151+
152+
```bash
153+
$ openssl s_client -showcerts -host <host> -port 443
154+
```
155+
156+
Copy the server certificate content from `-----BEGIN CERTIFICATE-----` to `-----END CERTIFICATE-----` (inclusive) into a `<file_name>.crt` file.
157+
158+
2. Declare the CA Certificate location when creating a `config` dictionary
159+
160+
```python
161+
config = {
162+
"ip": "172.16.102.82",
163+
"credentials": {
164+
"userName": "Administrator",
165+
"password": "secret123"
166+
},
167+
"ssl_certificate": "/home/python-hpOneView/my_ov_certificate.crt"
168+
}
169+
```
170+
143171
### Proxy
144172

145173
If your environment requires a proxy, define the proxy properties in the JSON file using the following syntax:

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
# built documents.
7272
#
7373
# The short X.Y version.
74-
version = u'4.3.0'
74+
version = u'4.4.0'
7575
# The full version, including alpha/beta/rc tags.
76-
release = u'4.3.0'
76+
release = u'4.4.0'
7777

7878
# The language for content autogenerated by Sphinx. Refer to documentation
7979
# for a list of supported languages.

hpOneView/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
standard_library.install_aliases()
1515

1616
__title__ = 'hpOneView'
17-
__version__ = '4.3.0'
17+
__version__ = '4.4.0'
1818
__copyright__ = '(C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP'
1919
__license__ = 'MIT'
2020

hpOneView/connection.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
# -*- coding: utf-8 -*
22

3-
"""
4-
connection.py
5-
~~~~~~~~~~~~~~
6-
7-
This module maintains communication with the appliance.
8-
"""
9-
from __future__ import absolute_import
10-
from __future__ import division
11-
from __future__ import print_function
12-
from __future__ import unicode_literals
13-
14-
from builtins import open
15-
from builtins import str
16-
from future import standard_library
17-
from future.utils import raise_from
18-
19-
standard_library.install_aliases()
20-
21-
223
###
234
# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP
245
#
@@ -41,6 +22,23 @@
4122
# THE SOFTWARE.
4223
###
4324

25+
"""
26+
connection.py
27+
~~~~~~~~~~~~~~
28+
29+
This module maintains communication with the appliance.
30+
"""
31+
from __future__ import absolute_import
32+
from __future__ import division
33+
from __future__ import print_function
34+
from __future__ import unicode_literals
35+
36+
from builtins import open
37+
from builtins import str
38+
from future import standard_library
39+
40+
standard_library.install_aliases()
41+
4442
import http.client
4543
import json
4644
import logging
@@ -49,14 +47,15 @@
4947
import os
5048
import ssl
5149
import time
50+
import traceback
5251

5352
from hpOneView.exceptions import HPOneViewException
5453

5554
logger = logging.getLogger(__name__)
5655

5756

5857
class connection(object):
59-
def __init__(self, applianceIp, api_version=300):
58+
def __init__(self, applianceIp, api_version=300, sslBundle=False):
6059
self._session = None
6160
self._host = applianceIp
6261
self._cred = None
@@ -68,8 +67,8 @@ def __init__(self, applianceIp, api_version=300):
6867
self._proxyHost = None
6968
self._proxyPort = None
7069
self._doProxy = False
71-
self._sslTrustedBundle = None
7270
self._sslTrustAll = True
71+
self._sslTrustedBundle = self.set_trusted_ssl_bundle(sslBundle)
7372
self._nextPage = None
7473
self._prevPage = None
7574
self._numTotalRecords = 0
@@ -92,8 +91,9 @@ def set_proxy(self, proxyHost, proxyPort):
9291
self._doProxy = True
9392

9493
def set_trusted_ssl_bundle(self, sslBundle):
95-
self._sslTrustAll = False
96-
self._sslTrustedBundle = sslBundle
94+
if sslBundle is not False:
95+
self._sslTrustAll = False
96+
return sslBundle
9797

9898
def get_session(self):
9999
return self._session
@@ -434,8 +434,8 @@ def login(self, cred, verbose=False):
434434
try:
435435
if self._validateVersion is False:
436436
self.validateVersion()
437-
except Exception as e:
438-
raise_from(HPOneViewException('Failure during login attempt.'), e)
437+
except Exception:
438+
raise(HPOneViewException('Failure during login attempt.\n %s' % traceback.format_exc()))
439439

440440
self._cred = cred
441441
try:

hpOneView/oneview_client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class OneViewClient(object):
116116
DEFAULT_API_VERSION = 300
117117

118118
def __init__(self, config):
119-
self.__connection = connection(config["ip"], config.get('api_version', self.DEFAULT_API_VERSION))
119+
self.__connection = connection(config["ip"], config.get('api_version', self.DEFAULT_API_VERSION), config.get('ssl_certificate', False))
120120
self.__image_streamer_ip = config.get("image_streamer_ip")
121121
self.__set_proxy(config)
122122
self.__connection.login(config["credentials"])
@@ -193,7 +193,6 @@ def __init__(self, config):
193193
self.__versions = None
194194
self.__backups = None
195195
self.__login_details = None
196-
# TODO: Implement: con.set_trusted_ssl_bundle(args.cert)
197196

198197
@classmethod
199198
def from_json_file(cls, file_name):
@@ -217,14 +216,16 @@ def from_environment_variables(cls):
217216
Construct OneViewClient using environment variables.
218217
219218
Allowed variables: ONEVIEWSDK_IP (required), ONEVIEWSDK_USERNAME (required), ONEVIEWSDK_PASSWORD (required),
220-
ONEVIEWSDK_AUTH_LOGIN_DOMAIN, ONEVIEWSDK_API_VERSION, ONEVIEWSDK_IMAGE_STREAMER_IP, ONEVIEWSDK_SESSIONID and ONEVIEWSDK_PROXY.
219+
ONEVIEWSDK_AUTH_LOGIN_DOMAIN, ONEVIEWSDK_API_VERSION, ONEVIEWSDK_IMAGE_STREAMER_IP, ONEVIEWSDK_SESSIONID, ONEVIEWSDK_SSL_CERTIFICATE
220+
and ONEVIEWSDK_PROXY.
221221
222222
Returns:
223223
OneViewClient:
224224
"""
225225
ip = os.environ.get('ONEVIEWSDK_IP', '')
226226
image_streamer_ip = os.environ.get('ONEVIEWSDK_IMAGE_STREAMER_IP', '')
227227
api_version = int(os.environ.get('ONEVIEWSDK_API_VERSION', OneViewClient.DEFAULT_API_VERSION))
228+
ssl_certificate = os.environ.get('ONEVIEWSDK_SSL_CERTIFICATE', '')
228229
username = os.environ.get('ONEVIEWSDK_USERNAME', '')
229230
auth_login_domain = os.environ.get('ONEVIEWSDK_AUTH_LOGIN_DOMAIN', '')
230231
password = os.environ.get('ONEVIEWSDK_PASSWORD', '')
@@ -234,6 +235,7 @@ def from_environment_variables(cls):
234235
config = dict(ip=ip,
235236
image_streamer_ip=image_streamer_ip,
236237
api_version=api_version,
238+
ssl_certificate=ssl_certificate,
237239
credentials=dict(userName=username, authLoginDomain=auth_login_domain, password=password, sessionID=sessionID),
238240
proxy=proxy)
239241

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
from setuptools import setup
2727

2828
setup(name='hpOneView',
29-
version='4.3.0',
29+
version='4.4.0',
3030
description='HPE OneView Python Library',
3131
url='https://github.com/HewlettPackard/python-hpOneView',
32-
download_url="https://github.com/HewlettPackard/python-hpOneView/tarball/v4.3.0",
32+
download_url="https://github.com/HewlettPackard/python-hpOneView/tarball/v4.4.0",
3333
author='Hewlett Packard Enterprise Development LP',
3434
author_email='[email protected]',
3535
license='MIT',

tests/unit/test_oneview_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ def test_from_environment_variables_is_passing_right_arguments_to_the_constructo
297297
mock_cls.assert_called_once_with({'api_version': 201,
298298
'proxy': '172.16.100.195:9999',
299299
'ip': '172.16.100.199',
300+
'ssl_certificate': '',
300301
'image_streamer_ip': '172.172.172.172',
301302
'credentials':
302303
{'userName': 'admin',
@@ -313,6 +314,7 @@ def test_from_environment_variables_is_passing_right_arguments_to_the_constructo
313314
'proxy': '172.16.100.195:9999',
314315
'ip': '172.16.100.199',
315316
'image_streamer_ip': '172.172.172.172',
317+
'ssl_certificate': '',
316318
'credentials':
317319
{'userName': 'admin',
318320
'password': 'secret123',
@@ -328,6 +330,7 @@ def test_from_environment_variables_is_passing_right_arguments_to_the_constructo
328330
'proxy': '',
329331
'ip': '172.16.100.199',
330332
'image_streamer_ip': '',
333+
'ssl_certificate': '',
331334
'credentials':
332335
{'userName': '',
333336
'password': '',

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ skip_missing_interpreters = true
1010

1111
[flake8]
1212
ignore = E402
13-
max-line-length = 140
13+
max-line-length = 160
1414
exclude = hpOneView/__init__.py
1515
max-complexity = 14
1616

0 commit comments

Comments
 (0)