lxc-extra 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +9 -0
- data/lib/lxc/extra.rb +33 -0
- data/lib/lxc/extra/version.rb +5 -0
- data/lxc-extra.gemspec +25 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/unit/lxc_extra_spec.rb +33 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2UzYTQzMzdlNGFhN2ViZDZmYTk0OWFmMDM2MjQ4MjBhZDdlN2VmMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZmRjMzk0NWVmMTZjOWZkMWY5NWI2MjZiNmNkZWU3NGNkYWUwMjg1ZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODBmYTZkZjIwOWQ5Njc2OThiYzAyYWE0NGJmNDY1MmM2ODU0NmI0Nzc2ZTdk
|
10
|
+
ODNjYjdjMWY3YzNkYjVmMGZjNTQ3MDk4NTliZDk3OTUwNWQzOGZlZWY2MGM0
|
11
|
+
MDhiOGZhYzZmNGQ3YWIxOThiYjVmMGZkMjVlNDY1MTVmMDQyM2Y=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTcyZTFlMGE0MDc2ODhlM2M1YzZmZmZiOWI3MjIwNmNmMTk1MWQ0ZGNkOGFj
|
14
|
+
ZmRkMjQ2M2Q5NjBmYjIxMGI4MTJkMTJiMDNjMzAwMjVmODU1ZGY5MjlhYzc5
|
15
|
+
MTdjNzkyM2IxYmJmZGIzZmExYmU1N2YyZDA5NjBhZDBkYzU1NmY=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ranjib Dey
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# LXC::Extra
|
2
|
+
Helper methods for ruby lxc binding
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
gem 'lxc-extra', github: 'ranjib/lxc-extra'
|
9
|
+
|
10
|
+
And then execute:
|
11
|
+
|
12
|
+
$ bundle
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
Core [LXC ruby bindings](https://github.com/lxc/ruby-lxc) exposes liblxc api. LXC::Extra provides few additional methods. For example, the `attach` method
|
16
|
+
from core lxc allows executing arbitrary ruby code inside a container. Since the `attach` method does so via spawning a child process
|
17
|
+
inside the container, getting any data back from the attach block requires IPC. LXC::Extra provides `execute` method that wraps the `attach` method
|
18
|
+
and does the IPC magic for you, using `IO.pipe`.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require 'lxc/extra'
|
22
|
+
ct = LXC::Container.new('test')
|
23
|
+
data = ct.execute do
|
24
|
+
# run some code
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/lxc/extra.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'lxc'
|
2
|
+
require 'lxc/extra/version'
|
3
|
+
require 'io/wait'
|
4
|
+
|
5
|
+
module LXC
|
6
|
+
module Extra
|
7
|
+
def execute(&block)
|
8
|
+
r,w = IO.pipe
|
9
|
+
ret = attach(wait:true) do
|
10
|
+
ENV.clear
|
11
|
+
ENV['PATH']='/usr/bin:/bin:/usr/sbin'
|
12
|
+
r.close
|
13
|
+
begin
|
14
|
+
out = block.call
|
15
|
+
w.write(Marshal.dump(out))
|
16
|
+
rescue Exception => e
|
17
|
+
w.write(Marshal.dump(e))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
w.close
|
21
|
+
o = nil
|
22
|
+
if r.ready?
|
23
|
+
o = Marshal.load(r.read)
|
24
|
+
end
|
25
|
+
r.close
|
26
|
+
raise o if o.is_a?(Exception)
|
27
|
+
o
|
28
|
+
end
|
29
|
+
end
|
30
|
+
class Container
|
31
|
+
include Extra
|
32
|
+
end
|
33
|
+
end
|
data/lxc-extra.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lxc/extra/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lxc-extra"
|
8
|
+
spec.version = LXC::Extra::VERSION
|
9
|
+
spec.authors = ["Ranjib Dey"]
|
10
|
+
spec.email = ["ranjib@linux.com"]
|
11
|
+
spec.description = %q{Additional helper methods for ruby lxc binding}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = "https://github.com/ranjib/lxc-extra"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "ruby-lxc"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LXC::Extra do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
c = LXC::Container.new('test')
|
7
|
+
c.create('ubuntu') unless c.defined?
|
8
|
+
c.start unless c.running?
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:all) do
|
12
|
+
c = LXC::Container.new('test')
|
13
|
+
c.stop if c.running?
|
14
|
+
end
|
15
|
+
|
16
|
+
context '#execute' do
|
17
|
+
let(:ct) do
|
18
|
+
LXC::Container.new('test')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should return apropriate object' do
|
22
|
+
o = ct.execute{ 'FooBar' }
|
23
|
+
expect(o).to eq('FooBar')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should raise legitimate exceptions' do
|
27
|
+
class TestError < RuntimeError; end
|
28
|
+
expect do
|
29
|
+
ct.execute {raise TestError}
|
30
|
+
end.to raise_error(TestError)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lxc-extra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ranjib Dey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-lxc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
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: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Additional helper methods for ruby lxc binding
|
70
|
+
email:
|
71
|
+
- ranjib@linux.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/lxc/extra.rb
|
82
|
+
- lib/lxc/extra/version.rb
|
83
|
+
- lxc-extra.gemspec
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
- spec/unit/lxc_extra_spec.rb
|
86
|
+
homepage: https://github.com/ranjib/lxc-extra
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.1.11
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Additional helper methods for ruby lxc binding
|
110
|
+
test_files:
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
- spec/unit/lxc_extra_spec.rb
|