Class: VagrantPlugins::CommandDns::Action::Route53::Destroy
- Inherits:
-
Object
- Object
- VagrantPlugins::CommandDns::Action::Route53::Destroy
- Defined in:
- lib/vagrant-command-dns/action/route53/destroy.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ Destroy
constructor
A new instance of Destroy.
Constructor Details
#initialize(app, env) ⇒ Destroy
Returns a new instance of Destroy.
10 11 12 13 |
# File 'lib/vagrant-command-dns/action/route53/destroy.rb', line 10 def initialize(app, env) @app = app @logger = Log4r::Logger.new('vagrant_command_dns::action::route53::destroy') end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vagrant-command-dns/action/route53/destroy.rb', line 15 def call(env) unless env[:machine].config.dns.__skip if env[:machine].state.id != :running raise Errors::MachineStateError, state: 'running' end end env[:record_map].each do |hostname, ip| @logger.info("Checking for existing '#{hostname}' Route53 record...") record_name = hostname + '.' unless hostname.end_with?('.') begin zone = env[:route53].zones.get(env[:machine].config.dns.route53_zone_id) record = zone.records.get(record_name) rescue Fog::DNS::AWS::Error => err env[:ui].error(I18n.t('vagrant_command_dns.command.route53.fog_error', message: err.)) end if !record.nil? && record.attributes[:name] == record_name if env[:machine].config.dns.__skip == true || record.attributes[:value][0] == ip @logger.info("Deleting Route53 record for '#{hostname}'...") begin record.destroy rescue Fog::DNS::AWS::Error => err env[:ui].error(I18n.t('vagrant_command_dns.command.route53.fog_error', message: err.)) end env[:ui].info(I18n.t('vagrant_command_dns.command.route53.destroy_success', ip: ip, hostname: hostname)) elsif record.attributes[:value][0] != ip env[:ui].warn(I18n.t('vagrant_command_dns.command.route53.destroy_conflict', hostname: hostname, expected: ip, got: record.attributes[:value][0])) else raise Errors::VagrantCommandDnsError end else env[:ui].info(I18n.t('vagrant_command_dns.command.route53.destroy_not_found', hostname: hostname)) end end @app.call(env) end |