Esempio n. 1
0
# -*- coding: utf-8 -*-
# vim: set expandtab tabstop=4 shiftwidth=4 :
__license__ = 'GPL v3'
import os.path
import _utils

services_store_dir = _utils.Config().services_store_dir
services_live_dir = _utils.Config().services_live_dir


def _mksname(name):
    return name.lower().replace(' ','_')


def add(name,port,host = '',domain = '',stype = '_http._tcp',subtype = None,protocol = None,text = []):
    ''' Adds service file to storage dir
        @param  name    service name
        @param  port    integer port number. (udp: 0-65535, tcp: 1-65535)
        @param  host    hostname. multicast or unicast DNS findable host name.
        @param  domain  FQDN eg: myname.local or google.com
        @param  stype   see http://www.dns-sd.org/ServiceTypes.html (default: '_http._ftp')
        @param  subtype service subtype
        @param  protocol    [any|ipv4|ipv6] (default: any; as per spec in "man avahi.service")
        @param  text    list/tuple of <text-record/> values
        USAGE: add('service name',9007) all other parameters are optional
    '''
    ## notes for haxwithaxe
    # See http://www.dns-sd.org/ServiceTypes.html
    # name: <name>1
    # stype: <service>+
    #   protocol: <service ?protocol="ipv4|ipv6|any">
Esempio n. 2
0
# -*- coding: utf-8 -*-
# vim: set expandtab tabstop=4 shiftwidth=4 :

'''
services.py
A module that reads the database of services running on the node and those found via avahi (mdns) and spits them out for use elsewhere.
'''

__author__ = 'haxwithaxe (me at haxwithaxe dot net)'

import _utils
import os
import re

# grab shared config
conf = _utils.Config()
logging = _utils.get_logging()

def service_states():
    services = conf.list_services()
    for s in services:
        if not s['state']:
            if not s['init']:
                s['state'] = False
            s['state'] = ask_init(s['name'])
    return services

def get_local_services_list():
    '''Get the list of services running on this node from the databases.'''
    # Pull a list of running web apps on the node.
    service_list = service_states()