cangallo 0.0.2.1 → 0.0.3

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: 9b90c4e1c69b4114fbdc225c7d0af0b7d2ef6fdd
4
- data.tar.gz: 0cd1c440f093931313e562a730a8fb51e48e718e
3
+ metadata.gz: c21b6ff98e9fcbbf383de70f0f06f9863e45a84b
4
+ data.tar.gz: c383ca0b87759da70f78a982f52b899c3b22e0a8
5
5
  SHA512:
6
- metadata.gz: df8fbdcdfe22afed9e21af5200615213d58b7c77b93076dc3560f8d6a631afad502f34bbad7d45f48e0d5e2bb9923ed1f1ca98c477bfbe2eb1dc80efbb775abf
7
- data.tar.gz: 3d36c90229f184f55bfaf6a0faa6c66e90d8d2e2916adaedb796def36475d2d517302dae72456e61a322c0739bb4c406a9e30b1cc9060404d71d5995e1c62c1e
6
+ metadata.gz: a58a2b3f477cf582c334b6920a3dc4b22991f901a111fa78818862830f83296e15510b113457fc2502e237fdc30511234fe50478a554ff5f2fe2d6c80c8df87e
7
+ data.tar.gz: 0c4ad7d347a66d809cf748d76f0392e1db07f92ed49438e0a23b04fb1ab6ae6d3f645b7136e7cd4830bc3cd97abee5f5185f5474bd8af4395ea0d346236c4da9
@@ -25,6 +25,8 @@ require 'rubygems'
25
25
  class Cangallo
26
26
 
27
27
  class LibGuestfs
28
+ CUSTOMIZE_CMD = /^([^\s]+)\s+(.*)$/
29
+
28
30
  def self.virt_customize(image, commands, params = "")
29
31
  version = self.version
30
32
 
@@ -50,14 +52,28 @@ class Cangallo
50
52
  "--commands-from-file #{cmd_file.path}"
51
53
  else
52
54
  cmd_params = commands.map do |line|
53
- m = line.match(/^([^\s]+)\s+(.*)$/)
55
+ m = line.match(CUSTOMIZE_CMD)
54
56
  if m
55
- "--" + m[1] + " " + Shellwords.escape(m[2].strip)
57
+ command = m[1]
58
+ parms = m[2].strip
59
+
60
+ if command == 'copy-in'
61
+ command = 'upload'
62
+ parms, new_command = copy_in(parms)
63
+
64
+ [
65
+ "--" + command + " " + Shellwords.escape(parms),
66
+ "--run-command " + Shellwords.escape(new_command)
67
+ ]
68
+ else
69
+ "--" + command + " " + Shellwords.escape(parms)
70
+ end
56
71
  else
57
72
  nil
58
73
  end
59
74
  end
60
75
 
76
+ cmd_params.flatten!
61
77
  cmd_params.compact!
62
78
 
63
79
  customize_command = "virt-customize -a #{image} #{params.join(" ")} " <<
@@ -88,5 +104,36 @@ class Cangallo
88
104
  nil
89
105
  end
90
106
  end
107
+
108
+ def self.copy_in(str)
109
+ local, remote = str.split(':')
110
+
111
+ raise "Source '#{local}' does not exist" if !File.exist?(local)
112
+
113
+ upload_local = local
114
+ upload_remote = remote
115
+ run_command = nil
116
+
117
+ if File.directory?(local)
118
+ upload_local_tmp = Tempfile.new("canga")
119
+ upload_local_tmp.close
120
+
121
+ upload_local = upload_local_tmp.path
122
+ upload_remote = "/tmp/#{File.basename(upload_local)}"
123
+
124
+
125
+ local_parent_dir = File.dirname(local)
126
+ local_name = File.basename(local)
127
+ rc = system("tar czf #{upload_local} -C #{local_parent_dir} #{local_name}")
128
+
129
+ raise "Error creating tar archive for '#{local_name}'" if !rc
130
+
131
+ run_command = "tar xf #{upload_remote} -C #{remote}"
132
+ end
133
+
134
+ upload_param = "#{upload_local}:#{upload_remote}"
135
+
136
+ return upload_param, run_command
137
+ end
91
138
  end
92
139
  end
@@ -16,5 +16,5 @@
16
16
  # limitations under the License.
17
17
 
18
18
  class Cangallo
19
- VERSION = '0.0.2'
19
+ VERSION = '0.0.3'
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.2.1
4
+ version: 0.0.3
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-10-14 00:00:00.000000000 Z
11
+ date: 2016-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -54,7 +54,7 @@ files:
54
54
  - lib/cangallo/qcow2.rb
55
55
  - lib/cangallo/repo.rb
56
56
  - lib/cangallo/version.rb
57
- homepage: http://canga.io
57
+ homepage: https://canga.io
58
58
  licenses:
59
59
  - Apache-2.0
60
60
  metadata: {}