Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add signal which send data with old and new value of address and host… (
#2776) Add signal which send data with old and new value of address and hostname
- Loading branch information
Showing
5 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default_app_config = 'ralph.networks.apps.Networks' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.conf import settings | ||
from django.db.models.signals import post_delete, post_save | ||
|
||
from ralph.apps import RalphAppConfig | ||
|
||
|
||
class Networks(RalphAppConfig): | ||
name = 'ralph.networks' | ||
|
||
def ready(self): | ||
if not settings.ENABLE_DNSAAS_INTEGRATION: | ||
return | ||
from ralph.networks.receivers import ( | ||
delete_dns_record, | ||
update_dns_record | ||
) | ||
ip_model = self.get_model('IPAddress') | ||
post_save.connect( | ||
receiver=update_dns_record, | ||
sender=ip_model | ||
) | ||
post_delete.connect( | ||
receiver=delete_dns_record, | ||
sender=ip_model, | ||
) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from ralph.dns.dnsaas import DNSaaS | ||
|
||
|
||
def update_dns_record(instance, created, *args, **kwargs): | ||
keys = ['address', 'hostname'] | ||
data_to_send = { | ||
'old': { | ||
key: instance._previous_state[key] for key in keys | ||
}, | ||
'new': { | ||
key: instance.__dict__[key] for key in keys | ||
} | ||
} | ||
data_to_send['action'] = 'add' if created else 'update' | ||
if data_to_send['old']['hostname'] is not None: | ||
DNSaaS().send_ipaddress_data(data_to_send) | ||
|
||
|
||
def delete_dns_record(instance, *args, **kwargs): | ||
DNSaaS().send_ipaddress_data({ | ||
'address': instance.address, | ||
'hostname': instance.hostname, | ||
'action': 'delete' | ||
}) |