Skip to content

Instantly share code, notes, and snippets.

@domcleal
Created December 3, 2013 20:50
Show Gist options
  • Save domcleal/7777250 to your computer and use it in GitHub Desktop.
Save domcleal/7777250 to your computer and use it in GitHub Desktop.
def require_ip_validation?
# if it's not managed there's nowhere to specify an IP anyway
return false unless managed?
# if the CR will provide an IP, then don't validate yet
return false if compute? && compute_resource.provided_attributes.keys.include?(:ip)
ip_for_dns = (subnet.present? && subnet.dns_id.present?) || (domain.present? && domain.dns_id.present?)
ip_for_dhcp = subnet.present? && subnet.dhcp_id.present?
ip_for_token = Setting[:token_duration] == 0 && !capabilities.include?(:image)
# Any of these conditions will require an IP, so chain with OR
ip_for_dns or ip_for_dhcp or ip_for_token
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment