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

Commit c47cb42

Browse files
authored
Merge pull request #340 from HewlettPackard/enhancement/enable-ssl-certificate
Fixed #339
2 parents 99dbd76 + ed79be8 commit c47cb42

File tree

13 files changed

+94
-42
lines changed

13 files changed

+94
-42
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: 38 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,43 @@ 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+
```bash
150+
$ openssl s_client -showcerts -host <host> -port 443
151+
```
152+
153+
2. Copy the server certificate wrapped with a header line and a footer line into a `<file_name>.crt` file.
154+
```
155+
-----BEGIN CERTIFICATE-----
156+
... (HPE OneView Appliance certificate in base64 PEM encoding) ...
157+
-----END CERTIFICATE-----
158+
```
159+
When using HPE Image Streamer, the server certificate for the HPE Image Streamer should also be added to the certificates file. Example:
160+
```
161+
-----BEGIN CERTIFICATE-----
162+
... (HPE OneView Appliance certificate in base64 PEM encoding) ...
163+
-----END CERTIFICATE-----
164+
-----BEGIN CERTIFICATE-----
165+
... (HPE Image Streamer Appliance certificate in base64 PEM encoding) ...
166+
-----END CERTIFICATE-----
167+
```
168+
169+
3. Declare the CA Certificate location when creating a `config` dictionary.
170+
```python
171+
config = {
172+
"ip": "172.16.102.82",
173+
"credentials": {
174+
"userName": "Administrator",
175+
"password": "secret123"
176+
},
177+
"ssl_certificate": "/home/python-hpOneView/my_ov_certificate.crt"
178+
}
179+
```
180+
143181
### Proxy
144182

145183
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.

examples/config-rename.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"ip": "172.16.102.59",
33
"image_streamer_ip": "172.16.102.60",
4-
"api_version": 300,
4+
"api_version": 500,
5+
"ssl_certificate": "",
56
"credentials": {
67
"userName": "administrator",
78
"authLoginDomain": "",

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: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
11
# -*- coding: utf-8 -*
2-
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-
222
###
233
# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP
244
#
@@ -41,6 +21,23 @@
4121
# THE SOFTWARE.
4222
###
4323

24+
"""
25+
connection.py
26+
~~~~~~~~~~~~~~
27+
28+
This module maintains communication with the appliance.
29+
"""
30+
from __future__ import absolute_import
31+
from __future__ import division
32+
from __future__ import print_function
33+
from __future__ import unicode_literals
34+
35+
from builtins import open
36+
from builtins import str
37+
from future import standard_library
38+
39+
standard_library.install_aliases()
40+
4441
import http.client
4542
import json
4643
import logging
@@ -49,14 +46,15 @@
4946
import os
5047
import ssl
5148
import time
49+
import traceback
5250

5351
from hpOneView.exceptions import HPOneViewException
5452

5553
logger = logging.getLogger(__name__)
5654

5755

5856
class connection(object):
59-
def __init__(self, applianceIp, api_version=300):
57+
def __init__(self, applianceIp, api_version=300, sslBundle=False):
6058
self._session = None
6159
self._host = applianceIp
6260
self._cred = None
@@ -68,8 +66,9 @@ def __init__(self, applianceIp, api_version=300):
6866
self._proxyHost = None
6967
self._proxyPort = None
7068
self._doProxy = False
71-
self._sslTrustedBundle = None
7269
self._sslTrustAll = True
70+
self._sslBundle = sslBundle
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:
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/image_streamer/image_streamer_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444

4545

4646
class ImageStreamerClient(object):
47-
def __init__(self, ip, session_id, api_version):
48-
self.__connection = connection(ip, api_version)
47+
def __init__(self, ip, session_id, api_version, sslBundle=False):
48+
self.__connection = connection(ip, api_version, sslBundle)
4949
self.__connection.set_session_id(session_id)
5050
self.__golden_images = None
5151
self.__plan_scripts = None

hpOneView/oneview_client.py

Lines changed: 7 additions & 4 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

@@ -284,7 +286,8 @@ def create_image_streamer_client(self):
284286
"""
285287
image_streamer = ImageStreamerClient(self.__image_streamer_ip,
286288
self.__connection.get_session_id(),
287-
self.__connection._apiVersion)
289+
self.__connection._apiVersion,
290+
self.__connection._sslBundle)
288291

289292
return image_streamer
290293

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',

0 commit comments

Comments
 (0)