kytoon 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ * Sun Mar 3 2013 Dan Prince <dprince@redhat.com> - 1.3.4
2
+ -Improve libvirt file injection so it works with or without LVM. (sthaha)
3
+ -Fix 'kytoon ssh' so it works with multiple args. (sthaha)
4
+ -Exits with a non-zero value (1) on task failure. (sthaha)
5
+ -Verbose output when image creation fails. (sthaha)
6
+
1
7
  * Tue Feb 12 2013 Dan Prince <dprince@redhat.com> - 1.3.3
2
8
  -Update SELinux to set correct context on /root/.ssh as well.
3
9
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.3
1
+ 1.3.4
@@ -100,18 +100,18 @@ class ServerGroup
100
100
 
101
101
  def server_names
102
102
 
103
- names=[]
103
+ names=[]
104
104
 
105
105
  servers.each do |server|
106
106
  if block_given? then
107
107
  yield server['hostname']
108
108
  else
109
109
  names << server['hostname']
110
- end
110
+ end
111
111
  end
112
112
 
113
113
  names
114
-
114
+
115
115
  end
116
116
 
117
117
  def cache_to_disk
@@ -297,8 +297,7 @@ fi
297
297
 
298
298
  def self.create_instance(group_id, inst_name, memory_gigs, original, original_xml, disk_path, create_cow, selinux_enabled, ssh_public_key, sudo)
299
299
 
300
- selinux_enabled = selinux_enabled =~ /(true|t|yes|y|1)$/i ? "true" : ""
301
-
300
+ selinux_enabled, guestfs_selinux_arg = selinux_enabled =~ /(true|t|yes|y|1)$/i ? ["true", '--selinux']: ["", '']
302
301
  puts "Creating instance: #{inst_name}"
303
302
  instance_memory = (KIB_PER_GIG * memory_gigs.to_f).to_i
304
303
  original_disk_path = source_disk_filename(original, original_xml) #cow only
@@ -326,7 +325,9 @@ if [ -n "#{create_cow}" ]; then
326
325
  --preserve-data \
327
326
  || { echo "failed to virt-clone"; exit 1; }
328
327
 
329
- #{sudo} qemu-img create -f qcow2 -o backing_file=#{original_disk_path} "#{disk_path}"
328
+ #{sudo} qemu-img create -f qcow2 -o backing_file=#{original_disk_path} "#{disk_path}" || { \
329
+ echo 'Failed to create a copy-on-write image of #{original_disk_path }'; exit 1;
330
+ }
330
331
 
331
332
  else
332
333
 
@@ -339,27 +340,24 @@ else
339
340
 
340
341
  fi
341
342
 
342
- LV_ROOT=$(#{sudo} virt-filesystems -a #{disk_path} --logical-volumes | grep root)
343
- # If using LVM we inject the ssh key this way
344
- if [ -n "$LV_ROOT" ]; then
345
- if [ -n "#{selinux_enabled}" ]; then
346
- #{sudo} guestfish --selinux add #{disk_path} : \
347
- run : \
348
- mount $LV_ROOT / : \
349
- sh "/bin/mkdir -p /root/.ssh" : \
350
- write-append /root/.ssh/authorized_keys "#{ssh_public_key}\n" : \
351
- sh "/bin/chmod -R 700 /root/.ssh" : \
352
- sh "load_policy -i" : \
353
- sh "chcon unconfined_u:object_r:user_home_t:s0 /root/.ssh" : \
354
- sh "chcon system_u:object_r:ssh_home_t /root/.ssh/authorized_keys"
355
- else
356
- #{sudo} guestfish add #{disk_path} : \
357
- run : \
358
- mount $LV_ROOT / : \
359
- sh "/bin/mkdir -p /root/.ssh" : \
360
- write-append /root/.ssh/authorized_keys "#{ssh_public_key}\n" : \
361
- sh "/bin/chmod -R 700 /root/.ssh"
362
- fi
343
+ #Copy the ssh-key
344
+ #{sudo} guestfish -a #{disk_path} -i <<- __EOF__
345
+ mkdir-p /root/.ssh
346
+ write-append /root/.ssh/authorized_keys "#{ssh_public_key}"
347
+ write-append /root/.ssh/authorized_keys \"\\n\"
348
+ chmod 0700 /root/.ssh
349
+ __EOF__
350
+
351
+ [ $? -eq 0 ] || { echo 'Error: unable to inject keys into the image #{disk_path}'; exit 1; }
352
+
353
+ #Extra magic if selinux is enabled
354
+ if [ -n "#{selinux_enabled}" ]; then
355
+ #{sudo} guestfish #{guestfs_selinux_arg} -a #{disk_path} -i <<- __EOF__
356
+ sh 'load_policy -i'
357
+ sh 'chcon unconfined_u:object_r:user_home_t:s0 /root/.ssh'
358
+ sh 'chcon system_u:object_r:ssh_home_t /root/.ssh/authorized_keys'
359
+ __EOF__
360
+ [ $? -eq 0 ] || { echo 'Error: unable to perform selinux operations on #{disk_path}'; exit 1; }
363
361
  fi
364
362
 
365
363
  #{sudo} virsh --connect=qemu:///system setmaxmem #{domain_name} #{instance_memory}
@@ -368,12 +366,12 @@ fi
368
366
 
369
367
  }
370
368
  retval=$?
371
- if not retval.success?
369
+ if not retval.success?
372
370
  puts out
373
371
  raise KytoonException, "Failed to create instance #{inst_name}."
374
372
  end
375
373
 
376
- # lookup server IP here...
374
+ # lookup server IP here...
377
375
  mac_addr = nil
378
376
  network_name = nil
379
377
  dom_xml = %x{#{sudo} virsh --connect=qemu:///system dumpxml #{domain_name}}
@@ -419,7 +417,7 @@ fi
419
417
  }
420
418
  puts out
421
419
  retval=$?
422
- if not retval.success?
420
+ if not retval.success?
423
421
  puts out
424
422
  raise KytoonException, "Failed to cleanup instances."
425
423
  end
@@ -7,6 +7,8 @@ class ThorTasks < Thor
7
7
  desc "create", "Create a new server group."
8
8
  method_options :group_type => :string
9
9
  method_options :group_config => :string
10
+
11
+
10
12
  def create(options=(options or {}))
11
13
  begin
12
14
  ServerGroup.init(options[:group_type])
@@ -14,9 +16,11 @@ class ThorTasks < Thor
14
16
  puts "Server group ID #{sg.id} created."
15
17
  rescue KytoonException => ke
16
18
  puts ke.message
19
+ exit 1
17
20
  end
18
21
  end
19
22
 
23
+
20
24
  desc "list", "List existing server groups."
21
25
  method_options :group_type => :string
22
26
  def list(options=(options or {}))
@@ -25,6 +29,7 @@ class ThorTasks < Thor
25
29
  ServerGroup.index()
26
30
  rescue KytoonException => ke
27
31
  puts ke.message
32
+ exit 1
28
33
  end
29
34
  end
30
35
 
@@ -38,6 +43,7 @@ class ThorTasks < Thor
38
43
  sg.pretty_print
39
44
  rescue KytoonException => ke
40
45
  puts ke.message
46
+ exit 1
41
47
  end
42
48
  end
43
49
 
@@ -52,6 +58,7 @@ class ThorTasks < Thor
52
58
  SshUtil.remove_known_hosts_ip(sg.gateway_ip)
53
59
  rescue KytoonException => ke
54
60
  puts ke.message
61
+ exit 1
55
62
  end
56
63
  end
57
64
 
@@ -65,13 +72,14 @@ class ThorTasks < Thor
65
72
  puts sg.gateway_ip
66
73
  rescue KytoonException => ke
67
74
  puts ke.message
75
+ exit 1
68
76
  end
69
77
  end
70
78
 
71
79
  desc "ssh", "SSH into a group."
72
80
  method_options :group_id => :string
73
81
  method_options :group_type => :string
74
- def ssh(options=(options or {}))
82
+ def ssh(*)
75
83
  begin
76
84
  ServerGroup.init(options[:group_type])
77
85
  args=ARGV[1, ARGV.length].join(" ")
@@ -84,6 +92,7 @@ class ThorTasks < Thor
84
92
  exec("ssh -o \"StrictHostKeyChecking no\" root@#{sg.gateway_ip} #{args}")
85
93
  rescue KytoonException => ke
86
94
  puts ke.message
95
+ exit 1
87
96
  end
88
97
  end
89
98
 
@@ -47,7 +47,7 @@ module Util
47
47
  elsif File.exists?(File.join(ssh_dir, "id_dsa.pub"))
48
48
  File.join(ssh_dir, "id_dsa.pub")
49
49
  else
50
- raise ConfigException, "Failed to load SSH key. Please create a SSH public key pair in your HOME directory."
50
+ raise ConfigException, "Failed to load SSH key. Please run 'ssh-keygen'."
51
51
  end
52
52
 
53
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kytoon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-13 00:00:00.000000000 Z
12
+ date: 2013-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -289,7 +289,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
289
289
  version: '0'
290
290
  segments:
291
291
  - 0
292
- hash: -1487060926017859322
292
+ hash: 3688137143086163860
293
293
  required_rubygems_version: !ruby/object:Gem::Requirement
294
294
  none: false
295
295
  requirements: