Programmatic scripting with WSMAN This Dell Technical White Paper provides information about programming scripts with WSMAN. Author(s) Thirumalaa Srinivas Jon Hass This white paper is for informational purposes only, and may contain typographical errors and technical inaccuracies. The content is provided as is, without express or implied warranties of any kind.
This document is for informational purposes only and may contain typographical errors and technical inaccuracies. The content is provided as is, without express or implied warranties of any kind. © 2012 Dell Inc. All rights reserved. Dell and its affiliates cannot be responsible for errors or omissions in typography or photography. Dell, the Dell logo, and PowerEdge are trademarks of Dell Inc. Intel and Xeon are registered trademarks of Intel Corporation in the U.S. and other countries.
Contents Executive Summary................................................................................ 3 Introduction......................................................................................... 3 WSMAN clients...................................................................................... 3 WinRM CLI ........................................................................................ 3 OpenWSMAN CLI .................................................................................
Executive Summary This white paper is for systems administrators looking to program scripts with WSMAN clients and to harness the power of the secure and standards-based WSMAN service. Introduction Dell PowerEdge servers equipped with Integrated Dell Remote Access Controller (iDRAC) provide secure, simple, scriptable and standards-based remote management capability through Web Services for Management (WSMAN).
Windows Remote Management (WinRM) is the Microsoft implementation of the WS-Management protocol which provides a secure way to communicate with local and remote computers using web services. Usage: winrm OPERATION RESOURCE_URI [-SWITCH:VALUE [-SWITCH:VALUE] ...] [@{KEY=VALUE[;KEY=VALUE]...}] For help on a specific operation: winrm g[et] -? Retrieving management information. winrm s[et] -? Modifying management information. winrm c[reate] -? Creating new instances of management resources.
--help-event Application Options -d, --debug=1-6 output. -j, --encoding -c, --cacert= peer -A, --cert= must be in PEM format.
Pictorial View of the Environment 1 Management Station with WSMAN scripts 2 Target System WSMAN over SSL Figure 1 - Environment Diagram Figure 1 shows the pictorial view of the environment. It starts with administrator (1) using the management station to run scripts to send WSMAN commands through an SSL connection. The target system in this case (2) is a Dell PowerEdge 11G or later server equipped with the iDRAC service processor.
In the following sections, this white paper explains these APIs and details their use. These APIs are used in the common files that come with the script packages posted at the Dell Tech Center. The link is available in the Where to Find More Information section. All the API examples are written using the Python programming language. Detect Host Operating System The host operating system must be detected as a pre-step to constructing the applicable WSMAN CLI command.
namespace, username, password, ipaddress and the SSL certificate. The certificate is defaulted to dummy. The constructed command can be directly launched on the command line or shell of the host OS, using the API detailed in the Launch WSMAN CLI command section. # Enumerate def wsman_enumerate_command(classname, namespace, username, password, ipaddress, cert = "dummy"): """ Constructs the WSMan Enumerate Operation command based on the OS and returns the command to be used.
""" if detect_host_os() == 1: wsman_command = 'winrm e "http://schemas.dmtf.org/wbem/wscim/1/cimschema/2/%s?__cimnamespace=%s" -u:%s -p:%s -r:https://%s/wsman -encoding:utf-8 a:basic -SkipCNcheck -SkipCAcheck -format:pretty -returntype:epr' wsman_command = wsman_command % (classname, namespace, username, password, ipaddress) else: wsman_command = 'wsman enumerate http://schemas.dmtf.
wsman_command = 'wsman get http://schemas.dell.com/wbem/wscim/1/cimschema/2/%s?%s -N %s -u %s -p %s -h %s -P 443 -v -j utf-8 -y basic -o -m 256 -c %s -V' wsman_command = wsman_command % (classname, key_str, namespace, username, password, ipaddress, cert) return wsman_command Set This API detects the host operating system and constructs the relevant WSMAN set CLI command, using the input parameters provided.
return wsman_command Invoke This API detects the host operating system and constructs the relevant WSMAN invoke CLI command, using the input parameters provided. The input parameters for the API are classname, namespace, methodname, keys of the class instance in python dictionary format, name-value pairs to be set on the instance in python dictionary format, username, password, ipaddress, the SSL certificate and a filename if name-value pairs are passed through a file.
else: wsman_command = 'wsman invoke -a "%s" http://schemas.dell.com/wbem/wscim/1/cim-schema/2/%s?%s -N %s -u %s -p %s -h %s -P 443 -v -j utf-8 -y basic -o -m 256 -c %s -V -J "%s"' wsman_command = wsman_command % (methodname, classname, key_str, namespace, username, password, ipaddress, cert, filename) return wsman_command Launch WSMAN CLI command After the relevant WSMAN CLI command is constructed, it must be launched on the command line or shell.
""" Ping the IP Address of the Target to make sure the network is up and responsive. """ import sys import re from sys import stdout if(detect_host_os() == 1): cmd = "ping -n 2 " + ipaddress resp = "\(0%" else: cmd = "ping -c 2 " + ipaddress resp = " 0%" print 'Pinging %s. Waiting for response.' % (ipaddress), stdout.flush() stdout_value,stderr_value = wsman_command_launch(cmd) if(re.search(resp,stdout_value)== None): print "\nThe iDRAC is not responding. Check system and try again." sys.
text_file = open(filename, "w") text_file.writelines(cert) text_file.close() print "Response received." return filename Important Notes Make sure your environment is configured well with WSMAN CLI tools, along with the appropriate version of Python. The target system that the scripts communicate with need to have WSMAN service running in the software stack. Dell’s iDRACs are configured with WSMAN service in the firmware image.
Summary Using the tools readily available to Windows and with some work in Linux, this whitepaper provides information on how to (A) get started on programmatically scripting with WSMAN using Python and (B) create a set of functions or APIs for common operations to leverage in creating custom server management scripts. The ability to create custom scripts for remote and secure systems management enables you to be more productive and efficient. Learn more Visit Dell.