python-redfish/redfish/old/functions.py
Bruno Cornec f844afc49b First working 0.1 version
- Uses tortilla lib to wrap the REST API (dep)
- Uses python requests to manage login/logout (dep)
- Provides 2 functional working examples with Redfish simulator and
  ProLiant server or Moonshot Server
- Remove OpenStack deps as this code has to be usable outside of
  OpenStack
- Provides a configuration file to handle credentials and connection
  URL
- Provides a mapping class to handle multiple versions of Redfish
  (in this version, 0.95.0 for ProLiant and 1.0.0 for mockup)
- Provides a first action reset_server to ... reset system
  The action is commented into simple-proliant.py to not do
  unexpected reset.
- Provides a first retrieving function get_bios_version to get the
  BIOS version of a system.
- Add basic logging capability
- Clean up to meet pep8 and doc strings (in progress).
2015-12-02 20:33:03 +01:00

50 lines
1.7 KiB
Python

# Copyright 2014 Hewlett-Packard Development Company, L.P.
#
# 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.
"""
Provides functions for using the Redfish RESTful API.
"""
import collections
import json
import sys
from redfish import connection
class RedfishOperation(connection.RedfishConnection):
def reset_server(self):
(status, headers, system) = self.rest_get('/redfish/v1/Systems', None)
memberuri = system['links']['Member'][0]['href']
# verify expected type
# hint: don't limit to version 0 here as we will rev to 1.0 at some point hopefully with minimal changes
# assert(connection.get_type(system) == 'ComputerSystem.0' or connection.get_type(system) == 'ComputerSystem.1')
# verify it supports POST
# assert(connection.operation_allowed(headers, 'POST'))
action = dict()
action['Action'] = 'Reset'
action['ResetType'] = 'ForceRestart'
# perform the POST action
print('POST ' + json.dumps(action) + ' to ' + memberuri)
(status, headers, response) = self.rest_post(memberuri, None, action)
print('POST response = ' + str(status))
connection.print_extended_error(response)