def add_defaultservice_to_host(host_name): """ Given a specific hostname, add default service to it """ # Get our host try: my_host = Model.Host.objects.get_by_shortname(host_name) except ValueError: raise okconfig.OKConfigError("Host %s not found." % host_name) # Dont do anything if file already exists service = Model.Service.objects.filter(name=host_name) if len(service) != 0: return False # Make sure that host belongs to a okconfig-compatible group hostgroup_name = my_host['hostgroups'] or "default" hostgroup_name = hostgroup_name.strip('+') if hostgroup_name in okconfig.get_groups(): GROUP=hostgroup_name else: GROUP='default' template = default_service_template template = re.sub("HOSTNAME", host_name, template) template = re.sub("GROUP", GROUP, template) file = open( my_host['filename'], 'a') file.write(template) file.close() return True
def add_defaultservice_to_host(host_name): """ Given a specific hostname, add default service to it """ # Get our host try: my_host = Model.Host.objects.get_by_shortname(host_name) except ValueError: raise okconfig.OKConfigError("Host %s not found." % host_name) # Dont do anything if file already exists service = Model.Service.objects.filter(name=host_name) if len(service) != 0: return False # Make sure that host belongs to a okconfig-compatible group hostgroup_name = my_host['hostgroups'] or "default" hostgroup_name = hostgroup_name.strip('+') if hostgroup_name in okconfig.get_groups(): GROUP = hostgroup_name else: GROUP = 'default' template = default_service_template template = re.sub("HOSTNAME", host_name, template) template = re.sub("GROUP", GROUP, template) fh = open(my_host['filename'], 'a') fh.write(template) fh.close() return True
def get_all_groups(): return map(lambda x: (x, x), okconfig.get_groups())
def get_all_groups(): return [(x, x) for x in okconfig.get_groups()]