Guest User

Untitled

a guest
Mar 31st, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. module KIR
  2. module Validation
  3. class AttachedDevicePrimaryIPCheck
  4.  
  5. def self.make(validator)
  6. new(validator.device.network_environment)
  7. end
  8.  
  9. def initialize(environment)
  10. @environment = environment
  11. end
  12.  
  13. def run
  14. 'the following attached devices are missing primary ip #{attached_device_ids.map(&:number).join(",")}' unless attached_device_with_no_primary.present?
  15. end
  16.  
  17. # private
  18.  
  19. def attached_device_with_no_primary
  20. @environment.network_devices.reject do |d|
  21. d.ip_addresses.any? { |ip| ip.is_primary? }
  22. end
  23. end
  24.  
  25. def attached_device_ids
  26. attached_device_with_no_primary.map {|d| d.id} unless attached_device_with_no_primary.present?
  27. end
  28. end
  29. end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment