class WinRM::WSMV::InitRunspacePool

WSMV message to create a remote shell

Attributes

shell_id[RW]

Public Class Methods

new(session_opts, shell_id, payload) click to toggle source
# File lib/winrm/wsmv/init_runspace_pool.rb, line 23
def initialize(session_opts, shell_id, payload)
  @session_opts = session_opts
  @shell_id = shell_id
  @payload = payload
end

Protected Instance Methods

create_body(body) click to toggle source
# File lib/winrm/wsmv/init_runspace_pool.rb, line 35
def create_body(body)
  # OMI server requires a Name for the Shell
  body.tag!("#{NS_WIN_SHELL}:Shell", 'ShellId' => shell_id, 'Name' => 'Runspace') do |s|
    s << Gyoku.xml(shell_body)
  end
end
create_header(header) click to toggle source
# File lib/winrm/wsmv/init_runspace_pool.rb, line 31
def create_header(header)
  header << Gyoku.xml(shell_headers)
end

Private Instance Methods

action_create() click to toggle source
# File lib/winrm/wsmv/init_runspace_pool.rb, line 65
def action_create
  {
    "#{NS_ADDRESSING}:Action" => 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Create',
    :attributes! => {
      "#{NS_ADDRESSING}:Action" => {
        'mustUnderstand' => true
      }
    }
  }
end
header_opts() click to toggle source
# File lib/winrm/wsmv/init_runspace_pool.rb, line 76
def header_opts
  {
    "#{NS_WSMAN_DMTF}:OptionSet" => {
      "#{NS_WSMAN_DMTF}:Option" => 2.3,
      :attributes! => {
        "#{NS_WSMAN_DMTF}:Option" => {
          'Name' => 'protocolversion',
          'MustComply' => 'true'
        }
      }
    },
    :attributes! => {
      "#{NS_WSMAN_DMTF}:OptionSet" => {
        'env:mustUnderstand' => 'true'
      }
    }
  }
end
shell_body() click to toggle source
# File lib/winrm/wsmv/init_runspace_pool.rb, line 44
def shell_body
  body = {
    "#{NS_WIN_SHELL}:InputStreams" => 'stdin pr',
    "#{NS_WIN_SHELL}:OutputStreams" => 'stdout'
  }
  body['creationXml'] = encode_bytes(@payload)
  body[:attributes!] = {
    'creationXml' => {
      'xmlns' => 'http://schemas.microsoft.com/powershell'
    }
  }
  body
end
shell_headers() click to toggle source
# File lib/winrm/wsmv/init_runspace_pool.rb, line 58
def shell_headers
  merge_headers(shared_headers(@session_opts),
                resource_uri_shell(RESOURCE_URI_POWERSHELL),
                action_create,
                header_opts)
end