GithubHelp home page GithubHelp logo

isabella232 / em-winrm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chef-boneyard/em-winrm

0.0 0.0 0.0 268 KB

DEPRECATED: EventMachine based, asynchronous parallel client for Windows Remote Management (WinRM).

License: Apache License 2.0

Ruby 100.00%

em-winrm's Introduction

EM-WinRM

An EventMachine client for Windows Remote Management (WinRM). This allows you to invoke commands on Windows machines from any machine that can run Ruby. This client leverages the EventMachine reactor to run the same command across multiple machines in parallel (think net-ssh-multi).

WinRM allows you to call native objects in Windows. This includes, but is not limited to, running batch scripts, powershell scripts and fetching WMI variables. For more information on WinRM, please visit Microsoft’s WinRM site.

Deprecation Notice

The functionality provided by this library has been merged into knife-windows. Following the release of knife-windows v1.0.0, this library will no longer be used and thus no longer be maintained.

Example Usage

servers = {
  'ec2-75-xxx-xxx-127.compute-1.amazonaws.com' => {:port => 80, :user => 'Administrator', :password => 'super_secret_passowrd'},
  'ec2-50-xxx-xxx-141.compute-1.amazonaws.com' => {:port => 80, :user => 'Administrator', :password => 'super_secret_passowrd'},
  'ec2-75-xxx-xxx-192.compute-1.amazonaws.com' => {:port => 80, :user => 'Administrator', :password => 'super_secret_passowrd'}
}

def h
  @highline ||= HighLine.new
end

def print_data(host, data, color = :cyan)
  if data =~ /\n/
      data.split(/\n/).each { |d| print_data(host, d, color) }
  else
    puts "#{h.color(host, color)} #{data.chomp}"
  end
end

# create a session
session = EventMachine::WinRM::Session.new(:log_level => :info)

# add some servers
servers.each do |host,options|
  session.use(host,options)
end

# create some callbacks
session.on_output do |host, data|
  print_data(host, data)
end
session.on_error do |host, err|
  print_data(host, data, :red)
end
session.on_finish do |host|
  host = host == :done ? 'All Servers' : host
  print_data(host, 'done.')
end

# run a command
session.relay_command('dir')

Gives the following output:

ec2-75-xxx-xxx-192.compute-1.amazonaws.com  Volume in drive C has no label.
ec2-75-xxx-xxx-192.compute-1.amazonaws.com  Volume Serial Number is 9415-4101
ec2-75-xxx-xxx-192.compute-1.amazonaws.com
ec2-75-xxx-xxx-192.compute-1.amazonaws.com  Directory of C:\Users\Administrator
ec2-75-xxx-xxx-192.compute-1.amazonaws.com
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          .
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          ..
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          Contacts
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          Desktop
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          Documents
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          Downloads
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          Favorites
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          Links
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          Music
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          Pictures
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          Saved Games
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          Searches
ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011  03:30 AM    <DIR>          Videos
ec2-75-xxx-xxx-192.compute-1.amazonaws.com                0 File(s)              0 bytes
ec2-75-xxx-xxx-192.compute-1.amazonaws.com               13 Dir(s)  21,553,827,840 bytes free
ec2-75-xxx-xxx-127.compute-1.amazonaws.com  Volume in drive C has no label.
ec2-75-xxx-xxx-127.compute-1.amazonaws.com  Volume Serial Number is 9415-4101
ec2-75-xxx-xxx-127.compute-1.amazonaws.com
ec2-75-xxx-xxx-127.compute-1.amazonaws.com  Directory of C:\Users\Administrator
ec2-75-xxx-xxx-127.compute-1.amazonaws.com
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          .
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          ..
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          Contacts
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          Desktop
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          Documents
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          Downloads
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          Favorites
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          Links
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          Music
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          Pictures
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          Saved Games
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          Searches
ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011  06:13 PM    <DIR>          Videos
ec2-75-xxx-xxx-127.compute-1.amazonaws.com                0 File(s)              0 bytes
ec2-75-xxx-xxx-127.compute-1.amazonaws.com               13 Dir(s)  21,535,481,856 bytes free
ec2-50-xxx-xxx-141.compute-1.amazonaws.com  Volume in drive C has no label.
ec2-50-xxx-xxx-141.compute-1.amazonaws.com  Volume Serial Number is 9415-4101
ec2-50-xxx-xxx-141.compute-1.amazonaws.com
ec2-50-xxx-xxx-141.compute-1.amazonaws.com  Directory of C:\Users\Administrator
ec2-50-xxx-xxx-141.compute-1.amazonaws.com
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          .
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          ..
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          Contacts
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          Desktop
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          Documents
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          Downloads
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          Favorites
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          Links
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          Music
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          Pictures
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          Saved Games
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          Searches
ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011  01:17 AM    <DIR>          Videos
ec2-50-xxx-xxx-141.compute-1.amazonaws.com                0 File(s)              0 bytes
ec2-50-xxx-xxx-141.compute-1.amazonaws.com               13 Dir(s)  21,555,576,832 bytes free
ec2-75-xxx-xxx-192.compute-1.amazonaws.com done.
ec2-75-xxx-xxx-127.compute-1.amazonaws.com done.
ec2-50-xxx-xxx-141.compute-1.amazonaws.com done.
All Servers done.

Credit

Thanks to Dan Wanek who wrote the WinRM Ruby client gem that is used heavily by this gem.

Also big thanks to Paul Morton and Chris McClimans (aka Hippie Hacker) for lots of real world testing and features!

Contact

License

Author

Seth Chisamore (<[email protected]>)

Copyright

Copyright © 2011 Seth Chisamore

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

em-winrm's People

Contributors

btm avatar fbehrens avatar gswallow avatar hh avatar jaym avatar mclark1129 avatar mrogg avatar mwrock avatar pmorton avatar schisamo avatar thommay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.