elecksee 1.0.22 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,50 +1,81 @@
1
- require 'elecksee/helpers/base'
1
+ require 'elecksee'
2
2
 
3
3
  class Lxc
4
- class OverlayDirectory
5
-
6
- attr_reader :name
7
- attr_reader :tmp_dir
8
-
9
- include Helpers
10
-
11
- def initialize(name, args={})
12
- @name = name
13
- @tmp_dir = args[:tmp_dir] || '/tmp/lxc/ephemerals'
14
- create
15
- end
4
+ module Storage
5
+ # Overlay directory backed storage
6
+ class OverlayDirectory
16
7
 
17
- def overlay_path
18
- File.join(tmp_dir, 'virt-overlays', name)
19
- end
20
- alias_method :target_path, :overlay_path
8
+ # @return [String] storage name (usually container name)
9
+ attr_reader :name
10
+ # @return [String] path to temporary directory
11
+ attr_reader :tmp_dir
21
12
 
22
- def create
23
- unless(File.directory?(overlay_path))
24
- FileUtils.mkdir_p(overlay_path)
13
+ include Helpers
14
+
15
+ # Create new instance
16
+ #
17
+ # @param name [String] storage name (usually container name)
18
+ # @param args [Hash]
19
+ # @option args [String] :tmp_dir path to temporary directory
20
+ def initialize(name, args={})
21
+ @name = name
22
+ @tmp_dir = args[:tmp_dir] || '/tmp/lxc/ephemerals'
23
+ create
25
24
  end
26
- end
27
25
 
28
- def destroy
29
- if(File.directory?(overlay_path))
30
- command("rm -rf #{overlay_path}", :sudo => true)
26
+ # @return [String] path to overlay directory
27
+ def overlay_path
28
+ File.join(tmp_dir, 'virt-overlays', name)
29
+ end
30
+ alias_method :target_path, :overlay_path
31
+
32
+ # Create the storage
33
+ #
34
+ # @return [TrueClass, FalseClass]
35
+ def create
36
+ unless(File.directory?(overlay_path))
37
+ FileUtils.mkdir_p(overlay_path)
38
+ true
39
+ else
40
+ false
41
+ end
42
+ end
43
+
44
+ # Destroy the storage
45
+ #
46
+ # @return [TrueClass, FalseClass]
47
+ def destroy
48
+ if(File.directory?(overlay_path))
49
+ command("rm -rf #{overlay_path}", :sudo => true)
50
+ true
51
+ else
52
+ false
53
+ end
31
54
  end
32
- end
33
-
34
- end
35
55
 
36
- # Clone directory does the same as the overlay, just in
37
- # a persistent place
38
- class CloneDirectory < OverlayDirectory
39
- def initialize(name, args={})
40
- args[:tmp_dir] = args[:dir] if args[:dir]
41
- args[:tmp_dir] || '/var/lib/lxc'
42
- super
43
56
  end
44
57
 
45
- def overlay_path
46
- File.join(tmp_dir, name)
58
+ # Clone directory does the same as the overlay, just in
59
+ # a persistent location
60
+ class CloneDirectory < OverlayDirectory
61
+
62
+ # Create new instance
63
+ #
64
+ # @param name [String] name of storage (usually container name)
65
+ # @param args [Hash]
66
+ # @option args [String] :dir persistent storage path
67
+ def initialize(name, args={})
68
+ args[:tmp_dir] = args[:dir] if args[:dir]
69
+ args[:tmp_dir] || '/var/lib/lxc'
70
+ super
71
+ end
72
+
73
+ # @return [String]
74
+ def overlay_path
75
+ File.join(tmp_dir, name)
76
+ end
77
+ alias_method :target_path, :overlay_path
47
78
  end
48
- alias_method :target_path, :overlay_path
79
+
49
80
  end
50
81
  end
@@ -1,60 +1,95 @@
1
- require 'elecksee/helpers/base'
1
+ require 'elecksee'
2
2
 
3
3
  class Lxc
4
- class OverlayMount
5
-
6
- include Helpers
7
-
8
- attr_reader :base
9
- attr_reader :overlay
10
- attr_reader :target
11
- attr_reader :overlay_type
12
-
13
- def initialize(args={})
14
- validate!(args)
15
- @base = args[:base]
16
- @overlay = args[:overlay]
17
- @target = args[:target]
18
- @overlay_type = args[:overlay_type] || 'overlayfs'
19
- end
4
+ module Storage
5
+ # Overlay mount backed storage
6
+ class OverlayMount
7
+
8
+ include Helpers
9
+
10
+ # @return [String] base path to overlay
11
+ attr_reader :base
12
+ # @return [String] path to overlay storage
13
+ attr_reader :overlay
14
+ # @return [String] path to mount overlay
15
+ attr_reader :target
16
+ # @return [String] type of overlay to implement
17
+ attr_reader :overlay_type
18
+
19
+ # Create new instance
20
+ #
21
+ # @param args [Hash]
22
+ # @option args [String] :base base path to overlay
23
+ # @option args [String] :overlay path to overlay storage
24
+ # @option args [String] :target path to mount overlay
25
+ # @option args [String] :overlay_type type of overlay to implement
26
+ # @note :overlay_type defaults to overlayfs
27
+ def initialize(args={})
28
+ validate!(args)
29
+ @base = args[:base]
30
+ @overlay = args[:overlay]
31
+ @target = args[:target]
32
+ @overlay_type = args[:overlay_type] || 'overlayfs'
33
+ end
20
34
 
21
- def mount
22
- unless(mounted?)
23
- case overlay_type
24
- when 'aufs'
25
- cmd = "mount -t aufs -o br=#{overlay}=rw:#{base}=ro,noplink none #{target}"
26
- when 'overlayfs'
27
- cmd = "mount -t overlayfs -oupperdir=#{overlay},lowerdir=#{base} none #{target}"
35
+ # Mount the overlay
36
+ #
37
+ # @return [TrueClass, FalseClass]
38
+ def mount
39
+ unless(mounted?)
40
+ case overlay_type
41
+ when 'aufs'
42
+ cmd = "mount -t aufs -o br=#{overlay}=rw:#{base}=ro,noplink none #{target}"
43
+ when 'overlayfs'
44
+ cmd = "mount -t overlayfs -oupperdir=#{overlay},lowerdir=#{base} none #{target}"
45
+ else
46
+ raise "Invalid overlay type provided: #{overlay_type}"
47
+ end
48
+ command(cmd, :sudo => true)
49
+ true
28
50
  else
29
- raise "Invalid overlay type provided: #{overlay_type}"
51
+ false
30
52
  end
31
- command(cmd, :sudo => true)
32
- true
33
53
  end
34
- end
35
54
 
36
- def mounted?
37
- command("mount").stdout.include?(target)
38
- end
39
-
40
- def unmount
41
- if(mounted?)
42
- command("umount #{target}", :sudo => true, :allow_failure => true)
43
- true
55
+ # @return [TrueClass, FalseClass]
56
+ def mounted?
57
+ command("mount").stdout.include?(target)
44
58
  end
45
- end
46
-
47
- private
48
59
 
49
- def validate!(args)
50
- [:base, :overlay, :target].each do |required|
51
- unless(args[required])
52
- raise ArgumentError.new "Missing required argument: #{required}"
60
+ # Unmount the overlay
61
+ #
62
+ # @return [TrueClass, FalseClass]
63
+ def unmount
64
+ if(mounted?)
65
+ command("umount #{target}", :sudo => true, :allow_failure => true)
66
+ true
67
+ else
68
+ false
53
69
  end
54
- unless(File.directory?(args[required]))
55
- raise TypeError.new "Provided argument is not a valid directory for #{required}: #{args[required]}"
70
+ end
71
+
72
+ private
73
+
74
+ # Validate the provide arguments
75
+ #
76
+ # @param args [Hash]
77
+ # @option args [String] :base
78
+ # @option args [String] :overlay
79
+ # @option args [String] :target
80
+ # @return [TrueClass]
81
+ def validate!(args)
82
+ [:base, :overlay, :target].each do |required|
83
+ unless(args[required])
84
+ raise ArgumentError.new "Missing required argument: #{required}"
85
+ end
86
+ unless(File.directory?(args[required]))
87
+ raise TypeError.new "Provided argument is not a valid directory for #{required}: #{args[required]}"
88
+ end
56
89
  end
90
+ true
57
91
  end
92
+
58
93
  end
59
94
  end
60
95
  end
@@ -1,84 +1,128 @@
1
- require 'elecksee/helpers/base'
1
+ require 'elecksee'
2
2
 
3
3
  class Lxc
4
+ module Storage
5
+ # Virtual device backed storage
6
+ class VirtualDevice
4
7
 
5
- class VirtualDevice
8
+ include Helpers
6
9
 
7
- include Helpers
10
+ # @return [String] storage name (usually container name)
11
+ attr_reader :name
12
+ # @return [String] path to temporary directory
13
+ attr_reader :tmp_dir
14
+ # @return [Integer] device size
15
+ attr_reader :size
16
+ # @return [TrueClass, FalseClass] use tmpfs
17
+ attr_reader :tmp_fs
18
+ # @return [String] file system to format (defaults ext4)
19
+ attr_reader :fs_type
8
20
 
9
- attr_reader :name
10
- attr_reader :tmp_dir
11
- attr_reader :size
12
- attr_reader :tmp_fs
13
- attr_reader :fs_type
14
-
15
- def initialize(name, args={})
16
- @name = name
17
- @tmp_dir = args[:tmp_dir] || '/tmp/lxc/ephemerals'
18
- @size = args[:size] || 2000
19
- @fs_type = args[:fs_type] || 'ext4'
20
- @tmp_fs = !!args[:tmp_fs]
21
- @fs_type = 'tmpfs' if @tmp_fs
22
- create
23
- end
21
+ # Create new instance
22
+ #
23
+ # @param name [String] generally container name
24
+ # @param args [Hash]
25
+ # @option args [String] :tmp_dir temporary directory
26
+ # @option args [Integer] :size size of device
27
+ # @option args [String] :fs_type file system to format
28
+ # @option args [TrueClass, FalseClass] :tmp_fs
29
+ def initialize(name, args={})
30
+ @name = name
31
+ @tmp_dir = args[:tmp_dir] || '/tmp/lxc/ephemerals'
32
+ @size = args[:size] || 2000
33
+ @fs_type = args[:fs_type] || 'ext4'
34
+ @tmp_fs = !!args[:tmp_fs]
35
+ @fs_type = 'tmpfs' if @tmp_fs
36
+ create
37
+ end
24
38
 
25
- def device_path
26
- tmp_fs ? :none : File.join(tmp_dir, 'virt-imgs', name)
27
- end
39
+ # @return [String] path to device
40
+ def device_path
41
+ tmp_fs ? :none : File.join(tmp_dir, 'virt-imgs', name)
42
+ end
28
43
 
29
- def mount_path
30
- File.join(tmp_dir, 'virt-mnts', name)
31
- end
32
- alias_method :target_path, :mount_path
44
+ # @return [String] path to mount
45
+ def mount_path
46
+ File.join(tmp_dir, 'virt-mnts', name)
47
+ end
48
+ alias_method :target_path, :mount_path
33
49
 
34
- def create
35
- make_directories!
36
- unless(tmp_fs)
37
- command("dd if=/dev/zero of=#{@device_path} bs=1k seek=#{sive}k count=1 > /dev/null")
38
- command("echo \"y\" | mkfs -t #{fs_type} #{size} > /dev/null")
50
+ # Create the storage
51
+ #
52
+ # @return [TrueClass, FalseClass]
53
+ def create
54
+ make_directories!
55
+ unless(tmp_fs)
56
+ command("dd if=/dev/zero of=#{@device_path} bs=1k seek=#{sive}k count=1 > /dev/null")
57
+ command("echo \"y\" | mkfs -t #{fs_type} #{size} > /dev/null")
58
+ true
59
+ else
60
+ false
61
+ end
39
62
  end
40
- end
41
63
 
42
- def mounted?
43
- command("mount").stdout.include?(mount_path)
44
- end
64
+ # @return [TrueClass, FalseClass] device currently mounted
65
+ def mounted?
66
+ command("mount").stdout.include?(mount_path)
67
+ end
45
68
 
46
- def mount
47
- unless(mounted?)
48
- command("mount -t #{fs_type}#{mount_options} #{device_path} #{mount_path}", :sudo => true)
49
- true
69
+ # @return [TrueClass, FalseClass] mount device
70
+ def mount
71
+ unless(mounted?)
72
+ command("mount -t #{fs_type}#{mount_options} #{device_path} #{mount_path}", :sudo => true)
73
+ true
74
+ else
75
+ false
76
+ end
50
77
  end
51
- end
52
78
 
53
- def unmount
54
- if(mounted?)
55
- command("umount #{mount_path}", :sudo => true)
56
- true
79
+ # @return [TrueClass, FalseClass] unmount device
80
+ def unmount
81
+ if(mounted?)
82
+ command("umount #{mount_path}", :sudo => true)
83
+ true
84
+ else
85
+ false
86
+ end
57
87
  end
58
- end
59
88
 
60
- def destroy
61
- unmount
62
- unless(device_path == :none)
63
- File.delete(device_path) if File.file?(device_path)
64
- FileUtils.rm_rf(device_path) if File.directory?(device_path)
89
+ # Destroy the storage device
90
+ #
91
+ # @return [TrueClass]
92
+ def destroy
93
+ unmount
94
+ unless(device_path == :none)
95
+ File.delete(device_path) if File.file?(device_path)
96
+ FileUtils.rm_rf(device_path) if File.directory?(device_path)
97
+ end
98
+ unless(mount_path == :none)
99
+ if(File.directory?(mount_path))
100
+ FileUtils.rmdir(mount_path)
101
+ end
102
+ end
103
+ true
65
104
  end
66
- FileUtils.rmdir(mount_path) if File.directory?(mount_path) unless mount_path == :none
67
- end
68
105
 
69
- private
106
+ private
70
107
 
71
- def mount_options
72
- ' -o loop' unless tmp_fs
73
- end
108
+ # @return [String] options for device mount
109
+ def mount_options
110
+ ' -o loop' unless tmp_fs
111
+ end
74
112
 
75
- def make_directories!
76
- [device_path, mount_path].each do |path|
77
- next if path == :none
78
- unless(File.directory?(path))
79
- FileUtils.mkdir_p(path)
113
+ # Create required directories
114
+ #
115
+ # @return [TrueClass]
116
+ def make_directories!
117
+ [device_path, mount_path].each do |path|
118
+ next if path == :none
119
+ unless(File.directory?(path))
120
+ FileUtils.mkdir_p(path)
121
+ end
80
122
  end
123
+ true
81
124
  end
125
+
82
126
  end
83
127
  end
84
128
  end
@@ -0,0 +1,13 @@
1
+ require 'elecksee'
2
+
3
+ class Lxc
4
+ # Container storage backers
5
+ module Storage
6
+
7
+ autoload :CloneDirectory, 'elecksee/storage/overlay_directory'
8
+ autoload :OverlayDirectory, 'elecksee/storage/overlay_directory'
9
+ autoload :OverlayMount, 'elecksee/storage/overlay_mount'
10
+ autoload :VirtualDevice, 'elecksee/storage/virtual_device'
11
+
12
+ end
13
+ end
@@ -1,3 +1,4 @@
1
1
  module Elecksee
2
- VERSION = Gem::Version.new('1.0.22')
2
+ # Current library version
3
+ VERSION = Gem::Version.new('1.1.0')
3
4
  end
data/lib/elecksee.rb CHANGED
@@ -1 +1,14 @@
1
1
  require 'elecksee/version'
2
+
3
+ # LXC interface
4
+ class Lxc
5
+ autoload :Clone, 'elecksee/clone'
6
+ autoload :Ephemeral, 'elecksee/ephemeral'
7
+ autoload :Helpers, 'elecksee/helpers'
8
+ autoload :CommandFailed, 'elecksee/helpers'
9
+ autoload :Timeout,'elecksee/helpers'
10
+ autoload :CommandResult, 'elecksee/helpers'
11
+ autoload :Storage, 'elecksee/storage'
12
+ end
13
+
14
+ require 'elecksee/lxc'
metadata CHANGED
@@ -1,46 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elecksee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.22
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Chris Roberts
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2015-01-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: mixlib-shellout
14
+ name: childprocess
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
- name: net-ssh
28
+ name: rye
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: LXC helpers
@@ -50,49 +45,47 @@ executables:
50
45
  extensions: []
51
46
  extra_rdoc_files: []
52
47
  files:
48
+ - CHANGELOG.md
49
+ - CONTRIBUTING.md
50
+ - LICENSE
51
+ - README.md
52
+ - bin/lxc-awesome-ephemeral
53
53
  - elecksee.gemspec
54
+ - lib/elecksee.rb
54
55
  - lib/elecksee/clone.rb
55
- - lib/elecksee/version.rb
56
- - lib/elecksee/lxc_file_config.rb
56
+ - lib/elecksee/ephemeral.rb
57
+ - lib/elecksee/helpers.rb
57
58
  - lib/elecksee/helpers/copies.rb
58
59
  - lib/elecksee/helpers/options.rb
59
- - lib/elecksee/helpers/base.rb
60
- - lib/elecksee/knife/config.rb
60
+ - lib/elecksee/lxc.rb
61
+ - lib/elecksee/lxc_file_config.rb
62
+ - lib/elecksee/storage.rb
63
+ - lib/elecksee/storage/overlay_directory.rb
61
64
  - lib/elecksee/storage/overlay_mount.rb
62
65
  - lib/elecksee/storage/virtual_device.rb
63
- - lib/elecksee/storage/overlay_directory.rb
64
- - lib/elecksee/ephemeral.rb
65
- - lib/elecksee/lxc.rb
66
- - lib/elecksee.rb
67
- - Gemfile
68
- - README.md
69
- - LICENSE
70
- - bin/lxc-awesome-ephemeral
71
- - CHANGELOG.md
72
- - Gemfile.lock
66
+ - lib/elecksee/version.rb
73
67
  homepage: http://github.com/chrisroberts/elecksee
74
68
  licenses: []
69
+ metadata: {}
75
70
  post_install_message:
76
71
  rdoc_options: []
77
72
  require_paths:
78
73
  - lib
79
74
  required_ruby_version: !ruby/object:Gem::Requirement
80
- none: false
81
75
  requirements:
82
- - - ! '>='
76
+ - - ">="
83
77
  - !ruby/object:Gem::Version
84
78
  version: '0'
85
79
  required_rubygems_version: !ruby/object:Gem::Requirement
86
- none: false
87
80
  requirements:
88
- - - ! '>='
81
+ - - ">="
89
82
  - !ruby/object:Gem::Version
90
83
  version: '0'
91
84
  requirements: []
92
85
  rubyforge_project:
93
- rubygems_version: 1.8.24
86
+ rubygems_version: 2.2.2
94
87
  signing_key:
95
- specification_version: 3
88
+ specification_version: 4
96
89
  summary: LXC helpers
97
90
  test_files: []
98
91
  has_rdoc:
data/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'childprocess'
4
-
5
- gemspec
data/Gemfile.lock DELETED
@@ -1,22 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- elecksee (1.0.21)
5
- mixlib-shellout
6
- net-ssh
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- childprocess (0.3.9)
12
- ffi (~> 1.0, >= 1.0.11)
13
- ffi (1.9.3)
14
- mixlib-shellout (1.3.0)
15
- net-ssh (2.7.0)
16
-
17
- PLATFORMS
18
- ruby
19
-
20
- DEPENDENCIES
21
- childprocess
22
- elecksee!
@@ -1,37 +0,0 @@
1
- require 'chef/mash'
2
- require 'chef/json_compat'
3
-
4
- class Lxc
5
- class Knife
6
- class Config
7
-
8
- attr_reader :base_path
9
- attr_reader :store
10
-
11
- def initialize(args={})
12
-
13
-
14
- def initialize(path='/etc/knife-lxc/config.json')
15
- if(File.exists?(path))
16
- @base_path = path
17
- @store = Chef::JSONCompat.from_json(File.read(path))
18
- else
19
- raise ArgumentError.new("Provided path is not valid: #{path}")
20
- end
21
- end
22
-
23
- def [](k)
24
- @store[k]
25
- end
26
-
27
- def
28
-
29
- def used_addresses
30
- end
31
-
32
- def available_addresses
33
- end
34
-
35
- end
36
- end
37
- end