From 8ba310e7c5977de7a93a6d7b76c0910e06302b55 Mon Sep 17 00:00:00 2001 From: Paul Stone Date: Wed, 3 Jul 2013 08:18:43 +0100 Subject: [PATCH 1/2] Added ability to execute native powershell scripts by specifying "#ps1_native", powershell will be launched from the sysnative file system redirected folder. useful when trying to import modules that only reside in 64bit powershell (ServerManager for example) --- cloudbaseinit/plugins/windows/userdata.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cloudbaseinit/plugins/windows/userdata.py b/cloudbaseinit/plugins/windows/userdata.py index b85850ef..a69144a5 100644 --- a/cloudbaseinit/plugins/windows/userdata.py +++ b/cloudbaseinit/plugins/windows/userdata.py @@ -55,6 +55,11 @@ class UserDataPlugin(base.BasePlugin): args = ['powershell.exe', '-ExecutionPolicy', 'RemoteSigned', '-NonInteractive', target_path] shell = False + elif re.search(r'^#ps1_native\s', user_data, re.I): + target_path += '.ps1' + args = ['%windir%\sysnative\WindowsPowerShell\v1.0\powershell.exe', '-ExecutionPolicy', 'RemoteSigned', + '-NonInteractive', target_path] + shell = False else: # Unsupported LOG.warning('Unsupported user_data format') From 3e4d629fbb98c04c8fbe3c48b0ca3e0821a0ac30 Mon Sep 17 00:00:00 2001 From: Paul Stone Date: Wed, 3 Jul 2013 11:14:35 +0100 Subject: [PATCH 2/2] Changes as requested for pep8 + others. Modified code to be pep8 compliant. Added check for sysnative folder presence. --- cloudbaseinit/plugins/windows/userdata.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cloudbaseinit/plugins/windows/userdata.py b/cloudbaseinit/plugins/windows/userdata.py index a69144a5..8c274232 100644 --- a/cloudbaseinit/plugins/windows/userdata.py +++ b/cloudbaseinit/plugins/windows/userdata.py @@ -55,11 +55,22 @@ class UserDataPlugin(base.BasePlugin): args = ['powershell.exe', '-ExecutionPolicy', 'RemoteSigned', '-NonInteractive', target_path] shell = False - elif re.search(r'^#ps1_native\s', user_data, re.I): - target_path += '.ps1' - args = ['%windir%\sysnative\WindowsPowerShell\v1.0\powershell.exe', '-ExecutionPolicy', 'RemoteSigned', - '-NonInteractive', target_path] - shell = False + elif re.search(r'^#ps1_sysnative\s', user_data, re.I): + if os.path.isdir(os.path.expandvars("%windir%") + + "\\sysnative\\WindowsPowerShell\\v1.0\\"): + target_path += '.ps1' + args = [os.path.expandvars("%windir%") + + '\\sysnative\\WindowsPowerShell\ + \\v1.0\\powershell.exe', + '-ExecutionPolicy', + 'RemoteSigned', '-NonInteractive', target_path] + shell = False + else: + # Unable to validate sysnative presence + LOG.warning('Unable to validate sysnative folder presence.\ + If Target OS is Server 2003, please ensure you have\ + KB942589 installed') + return (base.PLUGIN_EXECUTION_DONE, False) else: # Unsupported LOG.warning('Unsupported user_data format')