Dell PG Validation group is releasing their Python WSMan API to the public under the LGPLv2.1 open source license.
This library used extensively by the Validation Organization, and is a key component of the scripts that we use to perform automated WSMan testing prior to releasing our products.
Download
Git repository (GitHub):
https://github.com/jtallieu/dell-wsman-client-api-python.git/
Releases
WSMan API v 0.9.18 - Added WSMan identify command
WSMan API v 0.9.19 - Fixed buffer overrun issue for laorge property values. Associators and References command work properly for winrm
Requirements
- wsmancli in the PATH for linux or winrm in the PATH for Windows clients.
- python 2.6 or greater
Why We Developed This Library
If you’ve ever worked with the wsmancli /winrm command lines, you are familiar with the complexity of the command syntax. Commands easily go beyond 100 characters. And the output, to the uninitiated, is a bit intimidating. To develop scripts that leverage wsmancli or winrm requires complete understanding of how to form these commands and parse the output. The script developer must also be familiar with how to execute the command in the python environment and capture the output.
Our Python WSMan API provides that expertise allowing the script developer to only be concerned with the business logic. Also, you can get some really nice logs with no added cost. The library is designed to work with both Linux (wsmancli) and Windows (winrm). The library accounts for the differences between both Linux’s wsmancli and Windows’ winrm utility.
Extensible Architecture
The library is simply a series of transformations. Transform information into a command and transform command output into python data structures. The receptiveness of the library lies in its modular and extensible architecture.
- Providers
- The provider module is responsible for forming the correct wsman command and parsing the output into python objects. There is a provider for both wsmancli and winrm to account for the slight differences in the syntax and output between the two.
- Transport
- The transport module carries out the execution of the command (from the provider) and is responsible for providing the command’s output to the proper provider module. You may write and employ your own specialized Transport when invoking the API.
- Response
- Data classes that represent the types of responses that are generated by the wsman commands. These data classes (Association, Reference, Instance, Fault) provide dictionary-like access to the CIM Properties of the object they represent.
- Logging
- Provide formatters that understand how to represent wsman commands and output in various log formats (text, html)
Sample Usage In a Script
Get the full example here
from wsman import WSMan wsman= WSMan(transport=Subprocess()) remote = Remote("172.26.4.55", 'root', 'rootpw') refs = wsman.enumerate_keys("DCIM_NICView", "root/dcim", remote=remote)
# Find the reference we want a full GET on forreference inrefs: ifreference.get("InstanceID")[0] == "NIC.Slot.2-2-4": break
my_nic= wsman.get(reference, "", remote=remote) for key in my_nic.keys: print key, ":", my_nic.get(key) |
Configure Logging
import logging
wsman= WSMan(transport=Subprocess()) remote = Remote("172.26.4.55", 'root', 'rootpw') |
Generated HTML Log with pretty formatting
The generated HTML file is self contained.