Description ----------
This project includes a set of sample Python scripts and Ansible playbooks that utilize the Redfish API to manage Lenovo ThinkSystem servers. The scripts use the DMTF python-redfish-library (https://github.com/DMTF/python-redfish-library).
For more information on the Redfish API, visit http://redfish.dmtf.org/
- To install the python-redfish-library, get the code from https://github.com/DMTF/python-redfish-library , then:
python setup.py dist –formats=zip
cd dist
pip install redfish-2.0.0.zip
- To install Ansible:
sudo apt install ansible
sudo yum install ansible
Requirements ----------* python-redfish-library need to be installed
A set of python examples is provided under the examples directory of this project. In addition to the examples, there are sample ansible playbook implementations that can be used as a reference to build on the python examples.
Simply run the python script to print out the values form the HTTP GET operation.
This example prints the current system power state (such as On or Off)
cd examples
python lenovo_get_power_state.py
This example prints the system reset types that are supported by this server, then passes one of the values (ForceOff) to force the server to shutdown:
Python lenovo_set_reset_types.py ForceOff
A simple ansible playbook defined in the ansible_playbooks directory can be used as reference to create similar playbooks.
- hosts: 127.0.0.1
tasks:
- name: run scripts based on script_name
command: python ../examples/{{script_name}}
register: script_output
- debug: var=script_output.stdout
Run the ansible playbooks from the ansible_playbooks directory. The way to run get_values and set_values playbooks is shown below:
ansible-playbook lenovo_set_values.yml --extra-vars "script_name=<script_name>.py parameter=<parameter>"
ansible-playbook lenovo_get_values.yml --extra-vars "script_name=<script_name>.py"
Contributing ----------
- Fork it!
- Create your feature branch: git checkout -b my-new-feature
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request :D
- 10/12/2017 : Initial version
Copyright 2017 Lenovo Corporation
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.