Class: Sgupdater::Updater
- Inherits:
-
Object
- Object
- Sgupdater::Updater
- Defined in:
- lib/sgupdater/updater.rb
Instance Method Summary collapse
- #add(from, to) ⇒ Object
-
#initialize(options = {}) ⇒ Updater
constructor
A new instance of Updater.
- #replace(from, to) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Updater
Returns a new instance of Updater.
8 9 10 11 12 13 14 15 |
# File 'lib/sgupdater/updater.rb', line 8 def initialize( = {}) = .dup [:without_convert] = true [:format] = :json AWS.config() @client = Piculet::Client.new() @exported = @client.export(without_convert: true) end |
Instance Method Details
#add(from, to) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sgupdater/updater.rb', line 32 def add(from, to) @exported.each do |vpc, sgs| sgs.each do |sg, props| props[:ingress].each do |ing| ing[:ip_ranges].each do |cidr| if cidr == from ing[:ip_ranges] << to puts [vpc ? vpc : '(classic)', sg, props[:name], ing[:protocol], ing[:port_range], ing[:ip_ranges], ing[:groups]].join("\t") end end end end end end |
#replace(from, to) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sgupdater/updater.rb', line 17 def replace(from, to) @exported.each do |vpc, sgs| sgs.each do |sg, props| props[:ingress].each do |ing| ing[:ip_ranges].each_with_index do |cidr, i| if cidr == from ing[:ip_ranges][i] = to puts [vpc ? vpc : 'classic', sg, props[:name], ing[:protocol], ing[:port_range], ing[:ip_rages], ing[:groups], cidr].join("\t") end end end end end end |
#update ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sgupdater/updater.rb', line 47 def update exported = JSON.pretty_generate(@exported) file = Tempfile.new('exported') begin file.puts exported file.rewind file.rewind updated = @client.apply(file) ensure file.close file.unlink end updated end |