Skip to content

Commit

Permalink
version 3.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeevkallur committed May 25, 2022
1 parent 5f02b0b commit d4931ab
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ It must be placed in your working environment path.

Usage
----------
For 3.x and greater versions of the library see the documentation for usage: https://hewlettpackard.github.io/python-ilorest-library/
For 3.x and greater versions of the library see the documentation for usage: https://pages.github.hpe.com/intelligent-provisioning/python-redfish-library/

For 2.x versions of the library documentation is located at the `Wiki <https://github.com/HewlettPackard/python-ilorest-library/wiki>`_.
For 2.x versions of the library documentation is located at the `Wiki <https://github.hpe.com/intelligent-provisioning/python-redfish-library/wiki>`_.

Contributing
----------
Expand Down
3 changes: 3 additions & 0 deletions docs/Advanced-Usage.rest
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ The **body** property shows what body (if any) was passed along with the request
>>> response.request.body
'{"AssetTag": "new tag"}'

<<<<<<< HEAD
Certificate Based Authentication (HPE iLO Supported Authentication Only)
========================================================================

Expand Down Expand Up @@ -173,6 +174,8 @@ General steps to create the necessary steps include:
#. Generate user certificate.
#. Add user certificate mappings to iLO

=======
>>>>>>> parent of 6298e23... Updates to Certificate Based Authentication Login and Docs:
Multi-part Form Data
====================

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
# built documents.
#
# The short X.Y version.
version = u'3.3'
version = u'4.0'
# The full version, including alpha/beta/rc tags.
release = u'3.3.0.0'
release = u'4.0.0.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
103 changes: 103 additions & 0 deletions examples/Redfish/eject_virtual_media_iso.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Copyright 2016-2022 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

# -*- coding: utf-8 -*-
"""
An example of mounting virtual media for HPE iLO systems
"""

import sys
import json
from redfish import RedfishClient
from redfish.rest.v1 import ServerDownOrUnreachableError

from get_resource_directory import get_resource_directory

def mount_virtual_media_iso(_redfishobj, media_type,):

virtual_media_uri = None
virtual_media_response = []

resource_instances = get_resource_directory(_redfishobj)
if DISABLE_RESOURCE_DIR or not resource_instances:
#if we do not have a resource directory or want to force it's non use to find the
#relevant URI
managers_uri = _redfishobj.root.obj['Managers']['@odata.id']
managers_response = _redfishobj.get(managers_uri)
managers_members_uri = next(iter(managers_response.obj['Members']))['@odata.id']
managers_members_response = _redfishobj.get(managers_members_uri)
virtual_media_uri = managers_members_response.obj['VirtualMedia']['@odata.id']
else:
for instance in resource_instances:
#Use Resource directory to find the relevant URI
if '#VirtualMediaCollection.' in instance['@odata.type']:
virtual_media_uri = instance['@odata.id']

if virtual_media_uri:
virtual_media_response = _redfishobj.get(virtual_media_uri)
for virtual_media_slot in virtual_media_response.obj['Members']:
data = _redfishobj.get(virtual_media_slot['@odata.id'])
if media_type in data.dict['MediaTypes']:
virtual_media_mount_uri = data.obj['Actions']['#VirtualMedia.EjectMedia']['target']
post_body = {"Action": "HpeiLOVirtualMedia.EjectVirtualMedia"}
resp = _redfishobj.post(virtual_media_mount_uri, post_body)
if resp.status == 400:
try:
print(json.dumps(resp.obj['error']['@Message.ExtendedInfo'], indent=4, \
sort_keys=True))
except Exception as excp:
sys.stderr.write("A response error occurred, unable to access iLO"
"Extended Message Info...")
elif resp.status != 200:
sys.stderr.write("An http response of \'%s\' was returned.\n" % resp.status)
else:
print("Success!\n")
print(json.dumps(resp.dict, indent=4, sort_keys=True))
break

if __name__ == "__main__":
# When running on the server locally use the following commented values
#SYSTEM_URL = None
#LOGIN_ACCOUNT = None
#LOGIN_PASSWORD = None

# When running remotely connect using the secured (https://) address,
# account name, and password to send https requests
# SYSTEM_URL acceptable examples:
# "https://10.0.0.100"
# "https://ilo.hostname"
SYSTEM_URL = "https://10.0.0.100"
LOGIN_ACCOUNT = "admin"
LOGIN_PASSWORD = "password"

#specify the type of content the media represents
MEDIA_TYPE = "CD" #current possible options: Floppy, USBStick, CD, DVD

# flag to force disable resource directory. Resource directory and associated operations are
# intended for HPE servers.
DISABLE_RESOURCE_DIR = False

try:
# Create a Redfish client object
REDFISHOBJ = RedfishClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, \
password=LOGIN_PASSWORD)

# Login with the Redfish client
REDFISHOBJ.login()
except ServerDownOrUnreachableError as excp:
sys.stderr.write("ERROR: server not reachable or does not support RedFish.\n")
sys.exit()

mount_virtual_media_iso(REDFISHOBJ, MEDIA_TYPE)
REDFISHOBJ.logout()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
extras = {}

setup(name='python-ilorest-library',
version='3.3.0.0',
version='3.5.1.0',
description='iLO Rest Python Library',
author = 'Hewlett Packard Enterprise',
author_email = '[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion src/redfish/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Redfish restful library """

__all__ = ['rest', 'ris', 'hpilo']
__version__ = "3.5.0.0"
__version__ = "3.5.1.0"

import logging
from redfish.rest.v1 import AuthMethod, LegacyRestClient, RedfishClient
Expand Down
6 changes: 5 additions & 1 deletion src/redfish/rest/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def rest_request(self, path, method='GET', args=None, body=None, headers=None):
files = None
request_args = {}
if isinstance(path, bytes):
path = str(path).encode("utf-8")
path = str(path, "utf-8")
external_uri = True if 'redfish.dmtf.org' in path else False
else:
external_uri = True if 'redfish.dmtf.org' in path else False
Expand Down Expand Up @@ -327,7 +327,11 @@ def _init_connection(self, **kwargs):
"""Initiate blobstore connection"""
# mixed security modes require a password at all times
username = kwargs.pop('username', 'nousername')
if isinstance(username, bytes):
username = username.decode('utf-8')
password = kwargs.pop('password', 'nopassword')
if isinstance(password, bytes):
password = password.decode('utf-8')
try:
correctcreds = BlobStore2.initializecreds(username=username, password=password)
bs2 = BlobStore2()
Expand Down
3 changes: 2 additions & 1 deletion src/redfish/rest/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def default(self, obj):
jsondict['Content'] = obj.dict

return jsondict

if isinstance(obj, bytes):
obj = obj.decode('utf-8')
return json.JSONEncoder.default(self, obj)

class JSONDecoder(json.JSONDecoder):
Expand Down
4 changes: 4 additions & 0 deletions src/redfish/ris/rmc_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ def _uncache_client(self, cachefn, creds=None, enc=False):
creds['password'] = self._rmc._cm.decodefunct(creds['password'])
login_data['username'] = creds['username']
login_data['password'] = creds['password']
if isinstance(login_data['username'], bytes):
login_data['username'] = login_data['username'].decode('utf-8')
if isinstance(login_data['password'], bytes):
login_data['password'] = login_data['password'].decode('utf-8')

redfishinst = RestClient(
username=login_data.get('username', 'Administrator'),
Expand Down
4 changes: 1 addition & 3 deletions src/redfish/ris/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
if six.PY3:
from functools import reduce

if six.PY2:
from collections import Mapping
from collections.abc import Mapping
from collections import Mapping

import jsonpath_rw

Expand Down

0 comments on commit d4931ab

Please sign in to comment.