Giter Site home page Giter Site logo

train's Introduction

Train - Transport Interface

Build Status Build Status Master Gem Version

Train lets you talk to your local or remote operating systems and APIs with a unified interface.

It allows you to:

  • execute commands via run_command
  • interact with files via file
  • identify the target operating system via os
  • authenticate to API-based services and treat them like a platform

Train supports:

  • Local execution
  • SSH
  • WinRM
  • Docker
  • Mock (for testing and debugging)
  • AWS as an API
  • Azure as an API
  • VMware via PowerCLI

Examples

Setup

Local

require 'train'
train = Train.create('local')

SSH

require 'train'
train = Train.create('ssh',
  host: '1.2.3.4', port: 22, user: 'root', key_files: '/vagrant')

If you don't specify the key_files and password options, SSH agent authentication will be attempted. For example:

require 'train'
train = Train.create('ssh', host: '1.2.3.4', port: 22, user: 'root')

WinRM

require 'train'
train = Train.create('winrm',
  host: '1.2.3.4', user: 'Administrator', password: '...', ssl: true, self_signed: true)

Docker

require 'train'
train = Train.create('docker', host: 'container_id...')

AWS

To use AWS API authentication, setup an AWS client profile to store the Access Key ID and Secret Access Key.

require 'train'
train = Train.create('aws', region: 'us-east-2', profile: 'my-profile')

You may also use the standard AWS CLI environment variables, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION.

require 'train'
train = Train.create('aws')

VMware

require 'train'
Train.create('vmware', viserver: '10.0.0.10', user: 'demouser', password: 'securepassword')

You may also use environment variables by setting VISERVER, VISERVER__USERNAME, and VISERVER_PASSWORD

require 'train'
Train.create('vmware')

Configuration

To get a list of available options for a plugin:

puts Train.options('ssh')

This will provide all configuration options:

{
  :host     => { :required => true},
  :port     => { :default  => 22, :required => true},
  :user     => { :default  => "root", :required => true},
  :keys     => { :default  => nil},
  :password => { :default  => nil},
  ...

Usage

# start or reuse a connection
conn = train.connection

# run a command on Linux/Unix/Mac
puts conn.run_command('whoami').stdout

# get OS info
puts conn.os[:family]
puts conn.os[:release]

# access files
puts conn.file('/proc/version').content

# access specific API client functionality
ec2_client = train.connection.aws_client(Aws::EC2::Client)
puts ec2_client.describe_instances

# close the connection
conn.close

Testing

We perform unit, integration and windows tests.

  • unit tests ensure the intended behaviour of the implementation
  • integration tests run against VMs and docker containers
  • windows tests that run on appveyor for windows integration tests

Mac/Linux

bundle exec ruby -W -Ilib:test/unit test/unit/extras/stat_test.rb

Windows

# run windows tests
bundle exec rake test:windows

# run single tests
bundle exec ruby -I .\test\windows\ .\test\windows\local_test.rb

Kudos and Contributors

Train is heavily based on the work of:

We also want to thank halo who did a great contribution by handing over the train gem name.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

| Author: | Dominik Richter ([email protected])

| Author: | Christoph Hartmann ([email protected])

| Copyright: | Copyright (c) 2015-2018 Chef Software Inc.

| Copyright: | Copyright (c) 2015 Vulcano Security GmbH.

| 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.

train's People

Contributors

arlimus avatar chris-rock avatar jquick avatar adamleff avatar chef-ci avatar srenatus avatar jerryaldrichiii avatar tas50 avatar alexpop avatar jonathanmorley avatar chef-delivery avatar briandoodyie avatar stevendanna avatar marcparadise avatar anirudh-gupta avatar dmccown avatar mwrock avatar clintoncwolfe avatar jerearista avatar tyler-ball avatar frezbo avatar tduffield avatar thommay avatar miah avatar justindossey avatar jkeiser avatar jeremymv2 avatar schrd avatar srb3 avatar zealws avatar

Watchers

James Cloos 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.