Skip to content

Instantly share code, notes, and snippets.

@xlcommunity
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xlcommunity/9781c58d99cb11db9257 to your computer and use it in GitHub Desktop.
Save xlcommunity/9781c58d99cb11db9257 to your computer and use it in GitHub Desktop.
Configuring the XL Release Windows Remote Script task to use WINRM_NATIVE (i.e. winrs)
<!--
THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS.
-->
<type-modification type="remoteScript.Windows">
<property name="connectionType" default="WINRM_NATIVE" category="input" />
<property name="enableHttps" category="input" kind="boolean" required="false" default="false" label="Enable HTTPS for WinRM" />
<!-- WINRM_INTERNAL only -->
<property name="winrmTimeout" default="PT60.000S" category="input" label="Timeout (WINRM_INTERNAL only)" />
<!-- WINRM_NATIVE only -->
<property name="winrsAllowDelegate" kind="boolean" required="false" default="false" category="input" label="Allow Delegate (WINRM_NATIVE only)" />
<property name="winrsCompression" kind="boolean" required="false" default="false" category="input" label="Compression (WINRM_NATIVE only)" />
<property name="winrsNoecho" kind="boolean" required="false" default="false" category="input" label="No Echo (WINRM_NATIVE only)" />
<property name="winrsNoprofile" kind="boolean" default="false" required="false" category="input" label="No Profile (WINRM_NATIVE only)" />
<property name="winrsUnencrypted" kind="boolean" required="false" default="false" category="input" label="Unencrypted (WINRM_NATIVE only)" />
</type-modification>
# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
# FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS.
import sys
from com.xebialabs.xlrelease.plugin.overthere import WinrmRemoteScript
# adding these imports
from com.xebialabs.overthere.cifs import CifsConnectionBuilder
from com.xebialabs.overthere.cifs import CifsConnectionType
# this subclass of WinrmRemoteScript stores the two new properties -
# 'sudoUsername' and 'interactiveSudo', and uses them in the overridden
# 'customize' method
class WinrmRemoteScript2(WinrmRemoteScript):
def __init__(self, username, password, address, remotePath, script, timeout, connectionType, enableHttps, winrsAllowDelegate, winrsCompression, winrsNoecho, winrsNoprofile, winrsUnencrypted):
WinrmRemoteScript.__init__(self, username, password, address, remotePath, script, timeout)
self.connectionType = connectionType
self.enableHttps = enableHttps
self.winrsAllowDelegate = winrsAllowDelegate
self.winrsCompression = winrsCompression
self.winrsNoecho = winrsNoecho
self.winrsNoprofile = winrsNoprofile
self.winrsUnencrypted = winrsUnencrypted
def customize(self, options):
# call the out-of-the-box implementation - assumes WINRM_INTERNAL
self.super__customize(options)
options.set(CifsConnectionBuilder.WINRM_ENABLE_HTTPS, enableHttps)
if self.connectionType == 'WINRM_NATIVE':
options.set(CifsConnectionBuilder.CONNECTION_TYPE, CifsConnectionType.WINRM_NATIVE)
options.set(CifsConnectionBuilder.WINRS_ALLOW_DELEGATE, winrsAllowDelegate)
options.set(CifsConnectionBuilder.WINRS_COMPRESSION, winrsCompression)
options.set(CifsConnectionBuilder.WINRS_NOECHO, winrsNoecho)
options.set(CifsConnectionBuilder.WINRS_NOPROFILE, winrsNoprofile)
options.set(CifsConnectionBuilder.WINRS_UNENCRYPTED, winrsUnencrypted)
#print 'DEBUG: Options:', options
# using our subclass 'WinrmRemoteScript2' here in place of 'WinrmRemoteScript'
script = WinrmRemoteScript2(username, password, address, remotePath, script, timeout, connectionType, enableHttps, winrsAllowDelegate, winrsCompression, winrsNoecho, winrsNoprofile, winrsUnencrypted)
exitCode = script.execute()
output = script.getStdout()
err = script.getStderr()
if (exitCode == 0):
print output
else:
print "Exit code "
print exitCode
print
print "#### Output:"
print output
print "#### Error stream:"
print err
print
print "----"
sys.exit(exitCode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment