From 583e73b1abb8caf0465ce394fefeb6ba92830f14 Mon Sep 17 00:00:00 2001 From: Devananda van der Veen Date: Wed, 25 Mar 2015 15:58:07 -0700 Subject: [PATCH] fix issues found while testing --- redfish/connection.py | 2 +- redfish/functions.py | 57 ++++++++++++++++++++++++++++++++++ redfish/redfish-functions.py | 59 ------------------------------------ 3 files changed, 58 insertions(+), 60 deletions(-) create mode 100644 redfish/functions.py delete mode 100644 redfish/redfish-functions.py diff --git a/redfish/connection.py b/redfish/connection.py index 862812d..4613442 100644 --- a/redfish/connection.py +++ b/redfish/connection.py @@ -136,7 +136,7 @@ class RedfishConnection(object): self.user_name = user_name self.password = password authen = {'Password': self.password, 'UserName': self.user_name} - self.rest_post(self.host, '/rest/v1/sessions', None, json.dump(authen), + self.rest_post(self.host, '/rest/v1/sessions', None, json.dumps(authen), self.user_name, self.password) # XXX add members, we're going to have to cache diff --git a/redfish/functions.py b/redfish/functions.py new file mode 100644 index 0000000..a7c158b --- /dev/null +++ b/redfish/functions.py @@ -0,0 +1,57 @@ + + # 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 __init__(self, host, user_name, password): + super(RedfishOperation, self).__init__(host, + user_name, password) + # XXX add members, we're going to have to cache + + # noinspection PyPep8Naming + def reset_server(self): + (status, headers, system) = self.rest_get(self.host, + '/rest/v1/Systems', None, self.user_name, self.password) + + 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(self.host, memberuri, None, + action, self.user_name, self.password) + print('POST response = ' + str(status)) + connection.print_extended_error(response) diff --git a/redfish/redfish-functions.py b/redfish/redfish-functions.py deleted file mode 100644 index 4285e5e..0000000 --- a/redfish/redfish-functions.py +++ /dev/null @@ -1,59 +0,0 @@ - - # 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 json -import sys -from redfish import connection - -class RedfishOperation(object): - - def __init__(self, host, user_name, password): - super(RedFishOperation, self).__init__() - # XXX add members, we're going to have to cache - conn = RedfishConnection(host, user_name, password) - - # noinspection PyPep8Naming - def reset_server(): - print('Reset a server') - - # for each system in the systems collection at /rest/v1/Systems - for status, headers, system, memberuri in collection(host, '/rest/v1/Systems', None, user_name, password): - - # 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(conn.get_type(system) == 'ComputerSystem.0' or conn.get_type(system) == 'ComputerSystem.1') - - # verify it supports POST - assert(conn.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 = conn.rest_post(host, memberuri, None, action, user_name, password) - print('POST response = ' + str(status)) - conn.print_extended_error(response) - - # point made...quit - break