chef-partners/train

Name: train

Owner: Chef Partners

Description: Transport Interface to unify communication over SSH, WinRM, and friends.

Created: 2018-04-12 14:24:06.0

Updated: 2018-04-12 14:24:08.0

Pushed: 2018-04-25 08:13:40.0

Homepage: null

Size: 700

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

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:

Train supports:

Examples

Setup

Local

ire 'train'
n = Train.create('local')

SSH

ire 'train'
n = Train.create('ssh',
st: '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:

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

WinRM

ire 'train'
n = Train.create('winrm',
st: '1.2.3.4', user: 'Administrator', password: '...', ssl: true, self_signed: true)

Docker

ire 'train'
n = 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.

ire 'train'
n = 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.

ire 'train'
n = Train.create('aws')
Configuration

To get a list of available options for a plugin:

 Train.options('ssh')

This will provide all configuration options:


ost     => { :required => true},
ort     => { :default  => 22, :required => true},
ser     => { :default  => "root", :required => true},
eys     => { :default  => nil},
assword => { :default  => nil},
.
Usage
art or reuse a connection
 = train.connection

n a command on Linux/Unix/Mac
 conn.run_command('whoami').stdout

t OS info
 conn.os[:family]
 conn.os[:release]

cess files
 conn.file('/proc/version').content

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

ose the connection
.close

Testing

We perform unit, integration and windows tests.

Mac/Linux
le exec ruby -W -Ilib:test/unit test/unit/extras/stat_test.rb
Windows
n windows tests
le exec rake test:windows

n single tests
le 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 (drichter@chef.io)

| Author: | Christoph Hartmann (chartmann@chef.io)

| Copyright: | Copyright (c) 2015 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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.