Remove special handling of common services and refactor getting service attributes
This commit is contained in:
parent
0347efcb38
commit
ff92241ddb
13 changed files with 92 additions and 49 deletions
playbooks/filter_plugins
|
@ -1,29 +1,25 @@
|
|||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'my_service_attributes': self.my_service_attributes,
|
||||
'services_for_host': self.services_for_host,
|
||||
'services_to_dnscontrol': self.services_to_dnscontrol,
|
||||
'services_get_backups': self.services_get_backups,
|
||||
'service_get_backups': self.service_get_backups,
|
||||
'service_get_domain': self.service_get_domain,
|
||||
}
|
||||
|
||||
def my_service_attributes(self, services, host, attribute="name"):
|
||||
def services_for_host(self, services, host):
|
||||
result = []
|
||||
for service in services:
|
||||
# only compare the host if it is set
|
||||
if host and service["host"] != host:
|
||||
if not host:
|
||||
result.append(service)
|
||||
continue
|
||||
|
||||
attribute_value = service.get(attribute)
|
||||
if not attribute_value:
|
||||
if service["host"] == host:
|
||||
result.append(service)
|
||||
continue
|
||||
if service["host"] == "*":
|
||||
result.append(service)
|
||||
continue
|
||||
|
||||
if type(attribute_value) == list:
|
||||
result.extend(attribute_value)
|
||||
else:
|
||||
result.append(attribute_value)
|
||||
|
||||
return result
|
||||
|
||||
def find_service(self, services, name):
|
||||
|
@ -34,10 +30,8 @@ class FilterModule(object):
|
|||
|
||||
def services_get_backups(self, all_services, wanted_services):
|
||||
result = []
|
||||
for service in all_services:
|
||||
if service.get("name") in wanted_services:
|
||||
for backup in service.get("backup") or []:
|
||||
result.append(backup["name"])
|
||||
for wanted_service in wanted_services:
|
||||
result.extend(self.service_get_backups(all_services, wanted_service))
|
||||
return result
|
||||
|
||||
def service_get_backups(self, all_services, wanted_service):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue