Merge extended host information into services

        :param services: services list, to look for a specific one
        :type services: alignak.objects.service.Services
        :return: None
434094
def merge(self, services):
        
        for extinfo in self:
            if hasattr(extinfo, 'register') and not getattr(extinfo, 'register'):
                # We don't have to merge template
                continue
            hosts_names = extinfo.get_name().split(",")
            for host_name in hosts_names:
                serv = services.find_srv_by_name_and_hostname(host_name,
                                                              extinfo.service_description)
                if serv is not None:
                    # Fusion
                    self.merge_extinfo(serv, extinfo)
527488
def _add_services(self, this_service, other_services):
        
        if this_service['name'] != os.path.basename(os.getcwd()):
            s = this_service['name']
            msg = "The charm's root directory name needs to be {}".format(s)
            amulet.raise_status(amulet.FAIL, msg=msg)

        if 'units' not in this_service:
            this_service['units'] = 1

        self.d.add(this_service['name'], units=this_service['units'],
                   constraints=this_service.get('constraints'),
                   storage=this_service.get('storage'))

        for svc in other_services:
            if 'location' in svc:
                branch_location = svc['location']
            elif self.series:
                branch_location = 'cs:{}/{}'.format(self.series, svc['name']),
            else:
                branch_location = None

            if 'units' not in svc:
                svc['units'] = 1

            self.d.add(svc['name'], charm=branch_location, units=svc['units'],
                       constraints=svc.get('constraints'),
                       storage=svc.get('storage'))
1268329
def service_description_for_host(host)
      response = self.class.get(@base_uri + "config/host/#{host}?format=json",
                                basic_auth: @auth, verify: false)
      raise ApiError unless response.code == 200
      host_config = JSON.parse!(response.body)
      if host_config['services'].nil?
        services = []
      else
        services = host_config['services'].map { |s| s['service_description'] }
      end
      host_config['hostgroups'].each do |hg|
        services += hostgroup_services(hg)
      end
      services.nil? ? [] : services
    end
1156963
def _interface_to_service(iface):
    '''
    
    '''
    for _service in _get_services():
        service_info = pyconnman.ConnService(os.path.join(SERVICE_PATH, _service))
        if service_info.get_property('Ethernet')['Interface'] == iface:
            return _service
    return None
1189975
def register_service_dependencies(service, servicedependencies):
        
        # We explode service_dependencies into Servicedependency
        # We just create serviceDep with goods values (as STRING!),
        # the link pass will be done after
        sdeps = [d.strip() for d in getattr(service, "service_dependencies", [])]
        # %2=0 are for hosts, !=0 are for service_description
        i = 0
        hname = ''
        for elt in sdeps:
            if i % 2 == 0:  # host
                hname = elt
            else:  # description
                desc = elt
                # we can register it (service) (depend on) -> (hname, desc)
                # If we do not have enough data for service, it'service no use
                if hasattr(service, 'service_description') and hasattr(service, 'host_name'):
                    if hname == '':
                        hname = service.host_name
                    servicedependencies.add_service_dependency(
                        service.host_name, service.service_description, hname, desc)
            i += 1
843446
def services(self):
        """"""
        ids = [ref['id'] for ref in self['services']]
        return [Service.fetch(id) for id in ids]
461633
def services(self):
        """"""
        services = []
        if self._services is None:
            self.__init()
        for service in self._services:
            url = "%s/%s/%s" % (self.root, service['name'], service['type'])
            if service['type'] == "GPServer":
                services.append(GPService(url=url,
                                          securityHandler=self._securityHandler,
                                          proxy_url=self._proxy_url,
                                          proxy_port=self._proxy_port))
            elif service['type'] == "MapServer":
                services.append(MapService(url=url,
                                           securityHandler=self._securityHandler,
                                           proxy_url=self._proxy_url,
                                           proxy_port=self._proxy_port))
            elif service['type'] == "ImageServer":
                services.append(ImageService(url=url,
                                             securityHandler=self._securityHandler,
                                             proxy_url=self._proxy_url,
                                             proxy_port=self._proxy_port))
            elif service['type'] == "FeatureServer":
                if self.currentFolder == 'root':
                    serviceName = service['name']
                else:
                    serviceName = service['name'].split('/')[1]
                url = "%s/%s/%s" % (self.location, serviceName, service['type'])
                services.append(FeatureService(url=url,
                                               securityHandler=self._securityHandler,
                                               proxy_url=self._proxy_url,
                                               proxy_port=self._proxy_port))
            elif service['type'] == "GeometryServer":
                url = "%s/%s/%s" % (self.root, service['name'], service['type'])
                services.append(GeometryService(url=url,
                                               securityHandler=self._securityHandler,
                                               proxy_url=self._proxy_url,
                                               proxy_port=self._proxy_port))
            elif service['type'] == "MobileServer":
                services.append(MobileService(url=url,
                                              securityHandler=self._securityHandler,
                                              proxy_url=self._proxy_url,
                                              proxy_port=self._proxy_port))
            elif service['type'] == "NAServer":
                services.append(NetworkService(url=url,
                                               securityHandler=self._securityHandler,
                                               proxy_port=self._proxy_port,
                                               proxy_url=self._proxy_url))
            elif service['type'] == "GeocodeServer":
                services.append(GeocodeService(url=url,
                                               securityHandler=self._securityHandler,
                                               proxy_port=self._proxy_port,
                                               proxy_url=self._proxy_url))
            elif service['type'] == "GeoDataServer":
                services.append(GeoDataService(url=url,
                                               securityHandler=self._securityHandler,
                                               proxy_port=self._proxy_port,
                                               proxy_url=self._proxy_url))
            elif service['type'] == "GlobeServer":
                services.append(GlobeService(url=url,
                                               securityHandler=self._securityHandler,
                                               proxy_port=self._proxy_port,
                                               proxy_url=self._proxy_url))
            elif service['type'] == "StreamServer":
                services.append(StreamService(url=url,
                                             securityHandler=self._securityHandler,
                                             proxy_port=self._proxy_port,
                                             proxy_url=self._proxy_url))                
            elif service['type'] in ("IndexGenerator", "IndexingLauncher", "SearchServer"):
                pass
            else:
                print (service['type'], service['name'])
        return services
943901
def service_per_endpoint(self, context=None):
        
        endps = self.getattr("endpoints", context)
        res = {}
        for service, specs in endps.items():
            for endp, binding in specs:
                res[endp] = (service, binding)
        return res
483870
def merged(self):
        ''''''
        stats = {}
        for topic in self.client.topics()['topics']:
            for producer in self.client.lookup(topic)['producers']:
                hostname = producer['broadcast_address']
                port = producer['http_port']
                host = '%s_%s' % (hostname, port)
                stats[host] = nsqd.Client(
                    'http://%s:%s/' % (hostname, port)).clean_stats()
        return stats
272704
def attach_http_service(cls, http_service: HTTPService):
        
        if cls._http_service is None:
            cls._http_service = http_service
            cls._set_bus(http_service)
        else:
            warnings.warn('HTTP service is already attached')
1173379
def services(self):
        ""
        return [self._get_subfolder("%s/%s/" % 
                (s['name'].rstrip('/').split('/')[-1], s['type']), 
                self._service_type_mapping.get(s['type'], Service)) for s
                in self._json_struct.get('services', [])]
1079051
def add_service(self, service):
        
        if (self.service is None):
            self.service = service
        elif (isinstance(self.service, dict)):
            self.service = [self.service, service]
        else:
            self.service.append(service)
1005089
def _sysv_services():
    '''
    
    '''
    _services = []
    output = __salt__['cmd.run'](['chkconfig', '--list'], python_shell=False)
    for line in output.splitlines():
        comps = line.split()
        try:
            if comps[1].startswith('0:'):
                _services.append(comps[0])
        except IndexError:
            continue
    # Return only the services that have an initscript present
    return [x for x in _services if _service_is_sysv(x)]
510375
def removeService(self, service):
        
        for name, wrapper in self.services.iteritems():
            if service in (name, wrapper.service):
                del self.services[name]
                return

        raise NameError("Service %r not found" % (service,))
836690
def get_services(self):
        
        services = []
        for resource in self._get_services()['resources']:
            services.append(resource['entity']['label'])

        return services
933095
def linkify_templates(self):
        
        self.hosts.linkify_templates()
        self.contacts.linkify_templates()
        self.services.linkify_templates()
        self.servicedependencies.linkify_templates()
        self.hostdependencies.linkify_templates()
        self.timeperiods.linkify_templates()
        self.hostsextinfo.linkify_templates()
        self.servicesextinfo.linkify_templates()
        self.escalations.linkify_templates()
        # But also old srv and host escalations
        self.serviceescalations.linkify_templates()
        self.hostescalations.linkify_templates()
212509
def _loadServices(self):
        
        servicesPath = os.path.join(self.path, "service")
        if not os.path.isdir(servicesPath):
            return

        self._scanDirectoryForServices(servicesPath)