Created
February 21, 2019 14:17
-
-
Save sbskas/b13e702cee2592d28b864f603d5b76c4 to your computer and use it in GitHub Desktop.
Proposal #2 for 26104
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/models/concerns/orchestration/dhcp.rb b/app/models/concerns/orchestration/dhcp.rb | |
index b74d90e47..2b1332290 100644 | |
--- a/app/models/concerns/orchestration/dhcp.rb | |
+++ b/app/models/concerns/orchestration/dhcp.rb | |
@@ -140,18 +140,21 @@ module Orchestration::DHCP | |
new_record? ? queue_dhcp_create : queue_dhcp_update | |
end | |
+ def generate_id(interface,action) | |
+ return "dhcp_#{action}_#{interface.unique_id}" | |
+ end | |
+ | |
def queue_dhcp_create | |
logger.debug "Scheduling new DHCP reservations for #{self}" | |
- queue.create(id: "dhcp_create_#{self.mac}", name: _("Create DHCP Settings for %s") % self, priority: 10, action: [self, :set_dhcp]) if dhcp? | |
+ queue.create(id: generate_id(self,"create"), name: _("Create DHCP Settings for %s") % self, priority: 10, action: [self, :set_dhcp]) if dhcp? | |
end | |
def queue_dhcp_update | |
return unless dhcp_update_required? | |
logger.debug("Detected a changed required for DHCP record") | |
- queue.create(id: "dhcp_remove_#{old.mac}", name: _("Remove DHCP Settings for %s") % old, priority: 5, action: [old, :del_dhcp]) if old.dhcp? | |
- queue.create(id: "dhcp_create_#{self.mac}", name: _("Create DHCP Settings for %s") % self, priority: 9, action: [self, :set_dhcp]) if dhcp? | |
+ queue.create(id: generate_id(old,"remove"), name: _("Remove DHCP Settings for %s") % old, priority: 5, action: [old, :del_dhcp]) if old.dhcp? | |
+ queue.create(id: generate_id(self,"create"), name: _("Create DHCP Settings for %s") % self, priority: 9, action: [self, :set_dhcp]) if dhcp? | |
end | |
- | |
# do we need to update our dhcp reservations | |
def dhcp_update_required? | |
# IP Address / name changed, or 'rebuild' action is triggered and DHCP record on the smart proxy is not present/identical. | |
@@ -174,7 +177,7 @@ module Orchestration::DHCP | |
def queue_dhcp_destroy | |
return unless dhcp? && errors.empty? | |
- queue.create(id: "dhcp_remove_#{self.mac}", name: _("Remove DHCP Settings for %s") % self, priority: 5, action: [self, :del_dhcp]) | |
+ queue.create(id: generate_id(self,"remove"), name: _("Remove DHCP Settings for %s") % self, priority: 5, action: [self, :del_dhcp]) | |
true | |
end | |
@@ -182,7 +185,7 @@ module Orchestration::DHCP | |
return if !dhcp? || !overwrite? | |
logger.debug "Scheduling DHCP conflicts removal" | |
- queue.create(id: "dhcp_conflicts_remove_#{self.mac}", name: _("DHCP conflicts removal for %s") % self, priority: 5, action: [self, :del_dhcp_conflicts]) | |
+ queue.create(id: generate_id(self,"conflicts_remove"), name: _("DHCP conflicts removal for %s") % self, priority: 5, action: [self, :del_dhcp_conflicts]) | |
end | |
def dhcp_conflict_detected? | |
diff --git a/app/models/nic/managed.rb b/app/models/nic/managed.rb | |
index 0e8197ddb..d7951b87d 100644 | |
--- a/app/models/nic/managed.rb | |
+++ b/app/models/nic/managed.rb | |
@@ -78,6 +78,10 @@ module Nic | |
mac_addresses_for_provisioning.any? || (host.present? && host.compute_provides?(:mac)) | |
end | |
+ def unique_id | |
+ [self.mac, self.ip, self.identifier, self.id].find{|x| x&.present?} | |
+ end | |
+ | |
protected | |
def copy_hostname_from_host |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment