vagrant_rbapi 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 613a6f3a5fb6388e59119cbcc5c4dcccde428166
4
- data.tar.gz: 9f836f29dd33f7d686f9d14607c11e103bb1864b
3
+ metadata.gz: dd2e51f525f75f7feeb91545e982c873f06f0022
4
+ data.tar.gz: dc6c4a5415ded21a75f4ed05cf07d9ae1e35425d
5
5
  SHA512:
6
- metadata.gz: c5e22232d7978caeb19e6d8c58f7d19ef43da77df3c8e249958a718152e47e39adc8e92f24ead57a4714eedcc114ac093a6d7f1c4aaa6294adc7bc14dc1690de
7
- data.tar.gz: 65ef5907ae41010ef1f50f76fa3121c06122a99a0d93e93f4c577de7d9aba7ea13e85ea86f9be1f2b03e7161526dfe122845ffd1134fc3d5cd69682b2247bd4a
6
+ metadata.gz: c4397c3870dd4a3fa01084d61923a0f7a0b297355911b5672aca73cf13320625178dd3f549ec63a880c5b70c2cce56605ad860b40a7a68982f67651c4d86d735
7
+ data.tar.gz: 8e0324a0c28f7dbb674289fee1d56990f4a52e08910769662cff40fddd7671c598a0529d370cafcf32d37dfb3283fbbb49f6861b14c9d348545e9f3df34888ea
data/README.md CHANGED
@@ -15,16 +15,13 @@ Usage
15
15
  irb(main):003:0> vagrant.status
16
16
  => "not created"
17
17
  irb(main):004:0> vagrant.up
18
- => "0"
19
18
  irb(main):005:0> vagrant.status
20
19
  => "running"
21
20
  irb(main):006:0> vagrant.ssh('uname -a')
22
21
  => "Linux precise64 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux"
23
22
  irb(main):007:0> vagrant.halt
24
- => "0"
25
23
  irb(main):008:0> vagrant.status
26
24
  => "poweroff"
27
25
  irb(main):009:0> vagrant.destroy
28
- => "0"
29
26
  irb(main):010:0> vagrant.status
30
27
  => "not created"
data/lib/vagrant_rbapi.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'vagrant_rbapi/version'
2
2
  require 'vagrant_rbapi/exceptions'
3
3
 
4
+ require 'net/scp'
4
5
  require 'net/ssh'
5
6
  require 'open3'
6
7
 
@@ -23,26 +24,36 @@ class Vagrant_Rbapi
23
24
  Open3.popen3(ENV, cmd) do |stdin, stdout, stderr, wait_thr|
24
25
  out = stdout.read.to_s
25
26
  err = stderr.read.to_s
26
- val = wait_thr.value.to_s.split.last
27
+ val = wait_thr.value.to_s.split.last.to_i
27
28
  end
28
- return out, err, val
29
+ raise VagrantRbapi::CommandReturnedNonZero unless val == 0
30
+ return out
29
31
  end
30
32
 
31
33
  def status
32
- out, err, val = vagrant_cmd(['status'])
34
+ out = vagrant_cmd(['status'])
33
35
  status = out[/default(.*)\(/, 1].strip
34
36
  return status
35
37
  end
36
38
 
37
- def up
39
+ def up(provider = 'virtualbox')
38
40
  raise VagrantRbapi::BoxAlreadyRunning if self.status == 'running'
39
- out, err, val = vagrant_cmd(['up'])
40
- return val
41
+ vagrant_cmd(['up', "--provider=#{provider}"])
42
+ end
43
+
44
+ def halt
45
+ raise VagrantRbapi::BoxNotRunning if self.status != 'running'
46
+ vagrant_cmd(['halt', '--force'])
47
+ end
48
+
49
+ def destroy
50
+ raise VagrantRbapi::BoxNotCreated if self.status == 'not created'
51
+ vagrant_cmd(['destroy', '--force'])
41
52
  end
42
53
 
43
54
  def ssh_config
44
55
  raise VagrantRbapi::BoxNotRunning if self.status != 'running'
45
- out, err, val = vagrant_cmd(['ssh-config'])
56
+ out = vagrant_cmd(['ssh-config'])
46
57
  hostname = out[/HostName (.*)$/, 1].strip
47
58
  user = out[/User (.*)$/, 1].strip
48
59
  port = out[/Port (.*)$/, 1].strip
@@ -60,15 +71,17 @@ class Vagrant_Rbapi
60
71
  return out
61
72
  end
62
73
 
63
- def halt
74
+ def scp(direction, recursive, source, destination)
64
75
  raise VagrantRbapi::BoxNotRunning if self.status != 'running'
65
- out, err, val = vagrant_cmd(['halt', '--force'])
66
- return val
67
- end
68
-
69
- def destroy
70
- raise VagrantRbapi::BoxNotCreated if self.status == 'not created'
71
- out, err, val = vagrant_cmd(['destroy', '--force'])
72
- return val
76
+ config = ssh_config
77
+ if direction == :upload
78
+ Net::SCP.start(config[0], config[1], port: config[2], key_data: [File.read(config[3])]) do |scp|
79
+ scp.upload!(source, destination, recursive: recursive)
80
+ end
81
+ elsif direction == :download
82
+ Net::SCP.start(config[0], config[1], port: config[2], key_data: [File.read(config[3])]) do |scp|
83
+ scp.download!(source, destination, recursive: recursive)
84
+ end
85
+ end
73
86
  end
74
87
  end
@@ -1,4 +1,5 @@
1
1
  module VagrantRbapi
2
+ class CommandReturnedNonZero < StandardError; end
2
3
  class BoxNotCreated < StandardError; end
3
4
  class BoxNotRunning < StandardError; end
4
5
  class BoxAlreadyRunning < StandardError; end
@@ -1,3 +1,3 @@
1
1
  module VagrantRbapi
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
Binary file
@@ -0,0 +1,6 @@
1
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
2
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
3
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
4
+ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
5
+ cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
6
+ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -1,2 +1,3 @@
1
+ require 'fileutils'
1
2
  require 'minitest/autorun'
2
3
  require_relative '../lib/vagrant_rbapi'
data/test/test_destroy.rb CHANGED
@@ -11,23 +11,23 @@ class TestDestroy < MiniTest::Unit::TestCase
11
11
  Dir.chdir('../..')
12
12
  end
13
13
 
14
- def test_up_destroy
14
+ def test_destroy
15
15
  assert_equal('not created', @vagrant.status)
16
16
 
17
- assert_equal("0", @vagrant.up)
17
+ @vagrant.up
18
18
  assert_equal('running', @vagrant.status)
19
19
 
20
- assert_equal("0", @vagrant.destroy)
20
+ @vagrant.destroy
21
21
  assert_equal('not created', @vagrant.status)
22
22
  end
23
23
 
24
- def test_up_destroy_destroy
24
+ def test_destroy_destroy
25
25
  assert_equal('not created', @vagrant.status)
26
26
 
27
- assert_equal("0", @vagrant.up)
27
+ @vagrant.up
28
28
  assert_equal('running', @vagrant.status)
29
29
 
30
- assert_equal("0", @vagrant.destroy)
30
+ @vagrant.destroy
31
31
  assert_equal('not created', @vagrant.status)
32
32
 
33
33
  assert_raises(VagrantRbapi::BoxNotCreated) { @vagrant.destroy }
data/test/test_halt.rb CHANGED
@@ -11,32 +11,32 @@ class TestHalt < MiniTest::Unit::TestCase
11
11
  Dir.chdir('../..')
12
12
  end
13
13
 
14
- def test_up_halt_destroy
14
+ def test_halt
15
15
  assert_equal('not created', @vagrant.status)
16
16
 
17
- assert_equal("0", @vagrant.up)
17
+ @vagrant.up
18
18
  assert_equal('running', @vagrant.status)
19
19
 
20
- assert_equal("0", @vagrant.halt)
20
+ @vagrant.halt
21
21
  assert_equal('poweroff', @vagrant.status)
22
22
 
23
- assert_equal("0", @vagrant.destroy)
23
+ @vagrant.destroy
24
24
  assert_equal('not created', @vagrant.status)
25
25
  end
26
26
 
27
- def test_up_halt_halt_destroy
27
+ def test_halt_halt
28
28
  assert_equal('not created', @vagrant.status)
29
29
 
30
- assert_equal("0", @vagrant.up)
30
+ @vagrant.up
31
31
  assert_equal('running', @vagrant.status)
32
32
 
33
- assert_equal("0", @vagrant.halt)
33
+ @vagrant.halt
34
34
  assert_equal('poweroff', @vagrant.status)
35
35
 
36
36
  assert_raises(VagrantRbapi::BoxNotRunning) { @vagrant.halt }
37
37
  assert_equal('poweroff', @vagrant.status)
38
38
 
39
- assert_equal("0", @vagrant.destroy)
39
+ @vagrant.destroy
40
40
  assert_equal('not created', @vagrant.status)
41
41
  end
42
42
  end
data/test/test_scp.rb ADDED
@@ -0,0 +1,62 @@
1
+ require_relative 'minitest_helper'
2
+
3
+ class TestSSH < MiniTest::Unit::TestCase
4
+ def setup
5
+ precise64 = File.join(File.expand_path(File.dirname(File.dirname(__FILE__))), 'test/precise64')
6
+ @vagrant = Vagrant_Rbapi.new(precise64)
7
+ end
8
+
9
+ def teardown
10
+ @vagrant.destroy if @vagrant.status != 'not created'
11
+ Dir.chdir('../..')
12
+ end
13
+
14
+ def test_scp
15
+ assert_equal('not created', @vagrant.status)
16
+
17
+ @vagrant.up
18
+ assert_equal('running', @vagrant.status)
19
+
20
+ @vagrant.scp(:upload, false, File.expand_path('../files/Lorem.txt'), '/home/vagrant/Lorem.txt')
21
+ assert_equal('/home/vagrant/Lorem.txt: ASCII text', @vagrant.ssh('file ~/Lorem.txt'))
22
+
23
+ @vagrant.scp(:upload, false, File.expand_path('../files/Lorem.gif'), '/home/vagrant/Lorem.gif')
24
+ assert_equal('/home/vagrant/Lorem.gif: GIF image data, version 89a, 125 x 125', @vagrant.ssh('file ~/Lorem.gif'))
25
+
26
+ @vagrant.scp(:download, false, '/home/vagrant/Lorem.txt', File.expand_path('../files/Lorem2.txt'))
27
+ assert_equal('../files/Lorem2.txt: ASCII text', `file ../files/Lorem2.txt`.strip)
28
+
29
+ @vagrant.scp(:download, false, '/home/vagrant/Lorem.gif', File.expand_path('../files/Lorem2.gif'))
30
+ assert_equal('../files/Lorem2.gif: GIF image data, version 89a, 125 x 125', `file ../files/Lorem2.gif`.strip)
31
+
32
+ @vagrant.scp(:upload, true, File.expand_path('../files'), '/home/vagrant/')
33
+ assert_equal('/home/vagrant/files/Lorem.txt: ASCII text', @vagrant.ssh('file ~/files/Lorem.txt'))
34
+ assert_equal('/home/vagrant/files/Lorem.gif: GIF image data, version 89a, 125 x 125', @vagrant.ssh('file ~/files/Lorem.gif'))
35
+
36
+ FileUtils.rm('../files/Lorem2.txt') if File.file?('../files/Lorem2.txt')
37
+ FileUtils.rm('../files/Lorem2.gif') if File.file?('../files/Lorem2.gif')
38
+
39
+ @vagrant.destroy
40
+ assert_equal('not created', @vagrant.status)
41
+ end
42
+
43
+ def test_scp_recursive
44
+ assert_equal('not created', @vagrant.status)
45
+
46
+ @vagrant.up
47
+ assert_equal('running', @vagrant.status)
48
+
49
+ @vagrant.scp(:upload, true, File.expand_path('../files'), '/home/vagrant/')
50
+ assert_equal('/home/vagrant/files/Lorem.txt: ASCII text', @vagrant.ssh('file ~/files/Lorem.txt'))
51
+ assert_equal('/home/vagrant/files/Lorem.gif: GIF image data, version 89a, 125 x 125', @vagrant.ssh('file ~/files/Lorem.gif'))
52
+
53
+ @vagrant.scp(:download, true, '/home/vagrant/files', File.expand_path('../files'))
54
+ assert_equal('../files/files/Lorem.txt: ASCII text', `file ../files/files/Lorem.txt`.strip)
55
+ assert_equal('../files/files/Lorem.gif: GIF image data, version 89a, 125 x 125', `file ../files/files/Lorem.gif`.strip)
56
+
57
+ FileUtils.rm_r('../files/files') if File.directory?('../files/files')
58
+
59
+ @vagrant.destroy
60
+ assert_equal('not created', @vagrant.status)
61
+ end
62
+ end
data/test/test_ssh.rb CHANGED
@@ -11,20 +11,30 @@ class TestSSH < MiniTest::Unit::TestCase
11
11
  Dir.chdir('../..')
12
12
  end
13
13
 
14
- def test_up_ssh_destroy
14
+ def test_ssh
15
15
  assert_equal('not created', @vagrant.status)
16
16
 
17
- assert_equal("0", @vagrant.up)
17
+ @vagrant.up
18
18
  assert_equal('running', @vagrant.status)
19
19
 
20
20
  assert_includes(@vagrant.ssh('cat /etc/lsb-release'), 'Ubuntu 12.04 LTS')
21
21
  assert_equal('I am a Box', @vagrant.ssh('echo "I am a Box"'))
22
- assert_nil(@vagrant.ssh('sudo shutdown -h now'))
23
22
 
23
+ @vagrant.destroy
24
+ assert_equal('not created', @vagrant.status)
25
+ end
26
+
27
+ def test_ssh_shutdown
28
+ assert_equal('not created', @vagrant.status)
29
+
30
+ @vagrant.up
31
+ assert_equal('running', @vagrant.status)
32
+
33
+ @vagrant.ssh('sudo shutdown -h now')
24
34
  sleep 5 while @vagrant.status == 'running'
25
35
  assert_equal('poweroff', @vagrant.status)
26
36
 
27
- assert_equal("0", @vagrant.destroy)
37
+ @vagrant.destroy
28
38
  assert_equal('not created', @vagrant.status)
29
39
  end
30
40
  end
@@ -11,10 +11,10 @@ class TestSSHConfig < MiniTest::Unit::TestCase
11
11
  Dir.chdir('../..')
12
12
  end
13
13
 
14
- def test_up_ssh_config_destroy
14
+ def test_ssh_config
15
15
  assert_equal('not created', @vagrant.status)
16
16
 
17
- assert_equal("0", @vagrant.up)
17
+ @vagrant.up
18
18
  assert_equal('running', @vagrant.status)
19
19
 
20
20
  assert_equal('127.0.0.1', @vagrant.ssh_config[0])
@@ -22,7 +22,7 @@ class TestSSHConfig < MiniTest::Unit::TestCase
22
22
  assert_equal('2222', @vagrant.ssh_config[2])
23
23
  assert_equal(File.join(File.expand_path('~/'), '.vagrant.d/insecure_private_key'), @vagrant.ssh_config[3])
24
24
 
25
- assert_equal("0", @vagrant.destroy)
25
+ @vagrant.destroy
26
26
  assert_equal('not created', @vagrant.status)
27
27
  end
28
28
  end
data/test/test_up.rb CHANGED
@@ -11,26 +11,43 @@ class TestUp < MiniTest::Unit::TestCase
11
11
  Dir.chdir('../..')
12
12
  end
13
13
 
14
- def test_up_destroy
14
+ def test_up
15
15
  assert_equal('not created', @vagrant.status)
16
16
 
17
- assert_equal("0", @vagrant.up)
17
+ @vagrant.up
18
18
  assert_equal('running', @vagrant.status)
19
19
 
20
- assert_equal("0", @vagrant.destroy)
20
+ @vagrant.destroy
21
21
  assert_equal('not created', @vagrant.status)
22
22
  end
23
23
 
24
- def test_up_up_destroy
24
+ def test_up_up
25
25
  assert_equal('not created', @vagrant.status)
26
26
 
27
- assert_equal("0", @vagrant.up)
27
+ @vagrant.up
28
28
  assert_equal('running', @vagrant.status)
29
29
 
30
30
  assert_raises(VagrantRbapi::BoxAlreadyRunning) { @vagrant.up }
31
31
  assert_equal('running', @vagrant.status)
32
32
 
33
- assert_equal("0", @vagrant.destroy)
33
+ @vagrant.destroy
34
+ assert_equal('not created', @vagrant.status)
35
+ end
36
+
37
+ def test_up_vbox
38
+ assert_equal('not created', @vagrant.status)
39
+
40
+ @vagrant.up('virtualbox')
41
+ assert_equal('running', @vagrant.status)
42
+
43
+ @vagrant.destroy
44
+ assert_equal('not created', @vagrant.status)
45
+ end
46
+
47
+ def test_up_foobar
48
+ assert_equal('not created', @vagrant.status)
49
+
50
+ assert_raises(VagrantRbapi::CommandReturnedNonZero) { @vagrant.up('foobar') }
34
51
  assert_equal('not created', @vagrant.status)
35
52
  end
36
53
  end
data/test/test_which.rb CHANGED
@@ -11,7 +11,7 @@ class TestWhich < MiniTest::Unit::TestCase
11
11
  Dir.chdir('../..')
12
12
  end
13
13
 
14
- def test_which_with_vagrant_in_path
14
+ def test_which
15
15
  assert_equal `which vagrant`.strip, @vagrant.vagrant_bin
16
16
  end
17
17
  end
@@ -3,20 +3,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'vagrant_rbapi/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "vagrant_rbapi"
6
+ spec.name = 'vagrant_rbapi'
7
7
  spec.version = VagrantRbapi::VERSION
8
- spec.authors = ["Peter Wilmott"]
9
- spec.email = ["p@p8952.info"]
10
- spec.summary = %q{vagrant_rbapi}
11
- spec.description = %q{vagrant_rbapi}
12
- spec.homepage = ""
13
- spec.license = "GPL3"
8
+ spec.authors = ['Peter Wilmott']
9
+ spec.email = ['p@p8952.info']
10
+ spec.summary = %q{Ruby bindings for interacting with Vagrant boxes}
11
+ spec.description = %q{Ruby bindings for interacting with Vagrant boxes}
12
+ spec.homepage = ''
13
+ spec.license = 'GPL3'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
19
19
 
20
- spec.add_runtime_dependency 'rake'
20
+ spec.add_runtime_dependency 'net-scp'
21
21
  spec.add_runtime_dependency 'net-ssh'
22
+ spec.add_runtime_dependency 'rake'
22
23
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant_rbapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Wilmott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-09 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: net-scp
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '>='
@@ -38,7 +38,21 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: vagrant_rbapi
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Ruby bindings for interacting with Vagrant boxes
42
56
  email:
43
57
  - p@p8952.info
44
58
  executables: []
@@ -53,10 +67,13 @@ files:
53
67
  - lib/vagrant_rbapi.rb
54
68
  - lib/vagrant_rbapi/exceptions.rb
55
69
  - lib/vagrant_rbapi/version.rb
70
+ - test/files/Lorem.gif
71
+ - test/files/Lorem.txt
56
72
  - test/minitest_helper.rb
57
73
  - test/precise64/Vagrantfile
58
74
  - test/test_destroy.rb
59
75
  - test/test_halt.rb
76
+ - test/test_scp.rb
60
77
  - test/test_ssh.rb
61
78
  - test/test_ssh_config.rb
62
79
  - test/test_up.rb
@@ -85,12 +102,15 @@ rubyforge_project:
85
102
  rubygems_version: 2.2.2
86
103
  signing_key:
87
104
  specification_version: 4
88
- summary: vagrant_rbapi
105
+ summary: Ruby bindings for interacting with Vagrant boxes
89
106
  test_files:
107
+ - test/files/Lorem.gif
108
+ - test/files/Lorem.txt
90
109
  - test/minitest_helper.rb
91
110
  - test/precise64/Vagrantfile
92
111
  - test/test_destroy.rb
93
112
  - test/test_halt.rb
113
+ - test/test_scp.rb
94
114
  - test/test_ssh.rb
95
115
  - test/test_ssh_config.rb
96
116
  - test/test_up.rb