CloudyScripts 1.5.16 → 1.5.17

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ require 'rake/testtask'
12
12
 
13
13
  spec = Gem::Specification.new do |s|
14
14
  s.name = 'CloudyScripts'
15
- s.version = '1.5.16'
15
+ s.version = '1.5.17'
16
16
  s.has_rdoc = true
17
17
  s.extra_rdoc_files = ['README.rdoc', 'LICENSE']
18
18
  s.summary = 'Scripts to facilitate programming for infrastructure clouds.'
@@ -118,4 +118,43 @@ class Ec2Helper
118
118
  end
119
119
  end
120
120
 
121
+ # Checks if all ports are opened for the security group on range "0.0.0.0/0".
122
+ # If an additional range is specified in the parameter, a check returns
123
+ # true if a port is opened for either range 0.0.0.0/0 or the additional
124
+ # range specified.
125
+ # Returns true or false.
126
+ def check_open_port(security_group, port, range = "0.0.0.0/0")
127
+ res = @ec2_api.describe_security_groups(:group_name => security_group)
128
+ #puts "res = #{res.inspect}"
129
+ groups = res['securityGroupInfo']['item']
130
+ if groups.size == 0
131
+ raise Exception.new("security group '#{security_group}' not found")
132
+ end
133
+ permissions = groups[0]['ipPermissions']['item']
134
+ if permissions.size == 0
135
+ # no permissions at all
136
+ return false
137
+ end
138
+ permissions.each() {|permission|
139
+ #puts "permission: #{permission.inspect}"
140
+ if permission['ipRanges'] == nil
141
+ #no IP-Ranges defined (group based mode): ignore
142
+ next
143
+ end
144
+ from_port = permission['fromPort'].to_i
145
+ to_port = permission['toPort'].to_i
146
+ prot = permission['ipProtocol']
147
+ if port >= from_port && port <= to_port && prot == "tcp"
148
+ permission['ipRanges']['item'].each() {|ipRange|
149
+ if ipRange['cidrIp'] != "0.0.0.0/0" && ipRange['cidrIp'] != range
150
+ next
151
+ else
152
+ return true
153
+ end
154
+ }
155
+ end
156
+ }
157
+ false
158
+ end
159
+
121
160
  end
@@ -122,10 +122,13 @@ class RemoteCommandHandler
122
122
  end
123
123
 
124
124
  # Zip the complete contents of the source path into the destination file.
125
+ # Returns the an array with stderr output messages.
125
126
  def zip(source_path, destination_file)
126
127
  begin
127
- exec = "cd #{source_path}; zip -ry #{destination_file} *"
128
- remote_execute(exec, nil, true)
128
+ exec = "cd #{source_path}; zip -ryq #{destination_file} *"
129
+ stderr = []
130
+ get_output(exec, nil, nil, stderr)
131
+ return stderr
129
132
  rescue Exception => e
130
133
  raise Exception.new("zip failed due to #{e.message}")
131
134
  end
@@ -417,7 +417,11 @@ module StateTransitionHelper
417
417
  # # zip_file_name => name of the zip file (without .zip suffix)
418
418
  def zip_volume(source_dir, zip_file_dest, zip_file_name)
419
419
  post_message("going to zip the EBS volume")
420
- remote_handler().zip(source_dir, zip_file_dest+"/"+zip_file_name)
420
+ stderr = remote_handler().zip(source_dir, zip_file_dest+"/"+zip_file_name)
421
+ if stderr.size > 0
422
+ @logger.info("zip operation generated error and might not be complete. output: #{stderr.join("\n")}")
423
+ post_message("zip operation generated error and might not be complete. output: #{stderr.join("\n")}")
424
+ end
421
425
  post_message("EBS volume successfully zipped")
422
426
  end
423
427
 
@@ -28,6 +28,13 @@ class Ami2EbsConversion < Ec2Script
28
28
  end
29
29
 
30
30
  def check_input_parameters()
31
+ if @input_params[:security_group_name] == nil
32
+ @input_params[:security_group_name] = "default"
33
+ end
34
+ ec2_helper = Ec2Helper.new(@input_params[:ec2_api_handler])
35
+ if !ec2_helper.check_open_port(@input_params[:security_group_name], 22)
36
+ raise Exception.new("Port 22 must be opened for security group #{@input_params[:security_group_name]} to connect via SSH")
37
+ end
31
38
  if @input_params[:name] == nil
32
39
  @input_params[:name] = "Boot EBS (for AMI #{@input_params[:ami_id]}) at #{Time.now.strftime('%d/%m/%Y %H.%M.%S')}"
33
40
  else
@@ -42,6 +42,14 @@ class CopyAmi < Ec2Script
42
42
  if ec2_helper.ami_prop(@input_params[:ami_id], 'rootDeviceType') != "ebs"
43
43
  raise Exception.new("must be an EBS type image")
44
44
  end
45
+ local_ec2_helper = ec2_helper
46
+ if !local_ec2_helper.check_open_port('default', 22)
47
+ raise Exception.new("Port 22 must be opened for security group 'default' to connect via SSH in source-region")
48
+ end
49
+ remote_ec2_helper = Ec2Helper.new(@input_params[:target_ec2_handler])
50
+ if !remote_ec2_helper.check_open_port('default', 22)
51
+ raise Exception.new("Port 22 must be opened for security group 'default' to connect via SSH in target-region")
52
+ end
45
53
  if @input_params[:root_device_name] == nil
46
54
  @input_params[:root_device_name] = "/dev/sda1"
47
55
  end
@@ -35,6 +35,14 @@ class CopySnapshot< Ec2Script
35
35
  end
36
36
 
37
37
  def check_input_parameters()
38
+ local_ec2_helper = Ec2Helper.new(@input_params[:ec2_api_handler])
39
+ if !local_ec2_helper.check_open_port('default', 22)
40
+ raise Exception.new("Port 22 must be opened for security group 'default' to connect via SSH in source-region")
41
+ end
42
+ remote_ec2_helper = Ec2Helper.new(@input_params[:target_ec2_handler])
43
+ if !remote_ec2_helper.check_open_port('default', 22)
44
+ raise Exception.new("Port 22 must be opened for security group 'default' to connect via SSH in target-region")
45
+ end
38
46
  if @input_params[:source_ssh_username] == nil
39
47
  @input_params[:source_ssh_username] = "root"
40
48
  end
@@ -34,6 +34,13 @@ class DownloadSnapshot < Ec2Script
34
34
  end
35
35
 
36
36
  def check_input_parameters()
37
+ if @input_params[:security_group_name] == nil
38
+ @input_params[:security_group_name] = "default"
39
+ end
40
+ ec2_helper = Ec2Helper.new(@input_params[:ec2_api_handler])
41
+ if !ec2_helper.check_open_port(@input_params[:security_group_name], 22)
42
+ raise Exception.new("Port 22 must be opened for security group #{@input_params[:security_group_name]} to connect via SSH")
43
+ end
37
44
  if @input_params[:source_device] == nil
38
45
  @input_params[:source_device] = "/dev/sdj1"
39
46
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 5
8
- - 16
9
- version: 1.5.16
8
+ - 17
9
+ version: 1.5.17
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matthias Jung
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-18 00:00:00 +02:00
17
+ date: 2010-05-19 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency