cangallo 0.0.1 → 0.0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5714dca973ec1755fc348bbef4494c7e1da8c41
4
- data.tar.gz: 4abacf5c9616cb358befa15117d1682b26236a1b
3
+ metadata.gz: 9b90c4e1c69b4114fbdc225c7d0af0b7d2ef6fdd
4
+ data.tar.gz: 0cd1c440f093931313e562a730a8fb51e48e718e
5
5
  SHA512:
6
- metadata.gz: f817d57b34e4758aa33886d34ca0e9d744385a47c497ca33764ffcf988658f2172085ca2f25c3f778a09e8ee74b74844571b86d65e0b4bc4f7e5c1e17fa3eaf4
7
- data.tar.gz: d2877b68c3ed720db1163dcb0c352a0d97fefcff866501d5f54375f223b1b57f02f08b5acafea0f59a907f16f447ac67d6bb623f6aaf427c2d7db62c05031b6a
6
+ metadata.gz: df8fbdcdfe22afed9e21af5200615213d58b7c77b93076dc3560f8d6a631afad502f34bbad7d45f48e0d5e2bb9923ed1f1ca98c477bfbe2eb1dc80efbb775abf
7
+ data.tar.gz: 3d36c90229f184f55bfaf6a0faa6c66e90d8d2e2916adaedb796def36475d2d517302dae72456e61a322c0739bb4c406a9e30b1cc9060404d71d5995e1c62c1e
@@ -19,20 +19,54 @@ require 'json'
19
19
  require 'systemu'
20
20
  require 'tempfile'
21
21
  require 'fileutils'
22
+ require 'shellwords'
23
+ require 'rubygems'
22
24
 
23
25
  class Cangallo
24
26
 
25
27
  class LibGuestfs
26
28
  def self.virt_customize(image, commands, params = "")
27
- cmd_file = Tempfile.new("canga")
29
+ version = self.version
28
30
 
29
- cmd_file.puts(commands)
30
- cmd_file.close
31
+ if !version
32
+ raise "Could not get virt-customize version"
33
+ end
31
34
 
32
- #rc = system("virt-customize -v -x -a #{image} --commands-from-file #{cmd_file.path}")
33
- rc = system("virt-customize -a #{image} #{params.join(" ")} " <<
34
- "--commands-from-file #{cmd_file.path}")
35
- cmd_file.unlink
35
+ target_version = Gem::Version.new('1.30')
36
+ current_version = Gem::Version.new(version)
37
+ good_version = false
38
+
39
+ customize_command = nil
40
+
41
+ good_version = true if current_version >= target_version
42
+
43
+ if good_version
44
+ cmd_file = Tempfile.new("canga")
45
+
46
+ cmd_file.puts(commands)
47
+ cmd_file.close
48
+
49
+ customize_command = "virt-customize -a #{image} #{params.join(" ")} " <<
50
+ "--commands-from-file #{cmd_file.path}"
51
+ else
52
+ cmd_params = commands.map do |line|
53
+ m = line.match(/^([^\s]+)\s+(.*)$/)
54
+ if m
55
+ "--" + m[1] + " " + Shellwords.escape(m[2].strip)
56
+ else
57
+ nil
58
+ end
59
+ end
60
+
61
+ cmd_params.compact!
62
+
63
+ customize_command = "virt-customize -a #{image} #{params.join(" ")} " <<
64
+ "#{cmd_params.join(" ")}"
65
+ end
66
+
67
+ rc = system(customize_command)
68
+
69
+ cmd_file.unlink if good_version
36
70
 
37
71
  return rc
38
72
  end
@@ -42,5 +76,17 @@ class Cangallo
42
76
 
43
77
  return rc
44
78
  end
79
+
80
+ def self.version
81
+ str = `virt-customize --version`
82
+
83
+ m = str.match(/^virt-customize (.*)$/)
84
+
85
+ if m
86
+ m[1]
87
+ else
88
+ nil
89
+ end
90
+ end
45
91
  end
46
92
  end
@@ -16,5 +16,5 @@
16
16
  # limitations under the License.
17
17
 
18
18
  class Cangallo
19
- VERSION = '0.0.1'
19
+ VERSION = '0.0.2'
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cangallo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Fontan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-28 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor