def _register_a_service(self, name, interfaces=None, port=0, comments=None): '''Method: _register_a_service, private to class Description: Register a single service on the interfaces Args interfaces - the interfaces to register the service on instance - the SMF service instance handle name - the service name to be registered port - the port that the service is listening on, if port is 0 then registering a service listed in the AI SMF service instance. comments - comments for the ad hoc registered service Returns list_sdrefs - list of service references Raises AImDNSError - if SMF status property does not exist, OR if SMF txt_record property does not exist, OR if SMF port property does not exist. ''' if not self.register_initialized: self.exclude = libaimdns.getboolean_property(common.SRVINST, common.EXCLPROP) self.networks = libaimdns.getstrings_property(common.SRVINST, common.NETSPROP) self.register_initialized = True smf_port = None # if port is 0 then processing an AI service if port == 0: serv = config.get_service_props(name) if not serv: raise AIMDNSError(cw(_('error: aiMDNSError: no such ' 'installation service "%s"') % name)) # ensure the service is enabled if config.PROP_STATUS not in serv: raise AIMDNSError(cw(_('error: aiMDNSError: installation ' 'service key "status" property does ' 'not exist'))) if serv[config.PROP_STATUS] != config.STATUS_ON: print(cw(_('warning: Installation service "%s" is not enabled ' % name))) return None smf_port = config.get_service_port(name) if not smf_port: try: smf_port = libaimdns.getinteger_property(common.SRVINST, common.PORTPROP) smf_port = str(smf_port) except libaimdns.aiMDNSError, err: raise AIMDNSError(cw(_('error: aiMDNSError: port property ' 'failure (%s)') % err))
def test_getinteger(self): '''test libaimdns.getinteger_property interface ''' prop = 'test/anint' value = 1 setprop = 'setprop %s = integer: %d' % (prop, value) newvalues = self.SetSCFValue([setprop]) assert getinteger_property(self.svc, prop) == value, \ 'integer property does not match' del(newvalues) try: assert getinteger_property(self.bogus_svc, prop), \ 'integer returned for bogus_svc' except aiMDNSError: pass try: assert getinteger_property(self.svc, self.bogus_prop), \ 'integer returned for bogus_prop' except aiMDNSError: pass
for service_name in config.get_all_service_names(): # assume new service setup port = config.get_service_port(service_name) sys.stdout.write( '<a href="http://%s:%d/cgi-bin/' 'cgi_get_manifest.py?version=%s&service=%s">%s</a><br>\n' % (host, port, VERSION, service_name, service_name)) sys.stdout.write('</i></ol>%s' % _('Please select a service ' 'from the above list.')) print '</body></html>' if __name__ == '__main__': gettext.install("ai", "/usr/lib/locale") DEFAULT_PORT = libaimdns.getinteger_property(com.SRVINST, com.PORTPROP) (PARAM_VERSION, SERVICE, NO_DEFAULT, FORM_DATA) = \ get_parameters(cgi.FieldStorage()) print >> sys.stderr, PARAM_VERSION, SERVICE, NO_DEFAULT, FORM_DATA if PARAM_VERSION == COMPATIBILITY_VERSION or SERVICE is None: # Old client (REQUEST_METHOD, REQUEST_PORT) = get_environment_information() if REQUEST_PORT == DEFAULT_PORT: # only new clients use default port HOST = socket.gethostname() print 'Content-Type: text/html' # HTML is following print # blank line, end of headers print '<pre>' sys.stdout.write(_('error:must supply a service name\n')) sys.stdout.write(_('The request should look like:\n')) sys.stdout.write('<ol>http://%s:%d/cgi_get_manifest.py?' 'version=%s&service=<i>servicename</i></ol>' %
def _register_a_service(self, name, interfaces=None, port=0, comments=None): '''Method: _register_a_service, private to class Description: Register a single service on the interfaces Args interfaces - the interfaces to register the service on instance - the SMF service instance handle name - the service name to be registered port - the port that the service is listening on, if port is 0 then registering a service listed in the AI SMF service instance. comments - comments for the ad hoc registered service Returns list_sdrefs - list of service references Raises AImDNSError - if SMF status property does not exist, OR if SMF txt_record property does not exist, OR if SMF port property does not exist. ''' if not self.register_initialized: self.exclude = libaimdns.getboolean_property( common.SRVINST, common.EXCLPROP) self.networks = libaimdns.getstrings_property( common.SRVINST, common.NETSPROP) self.register_initialized = True smf_port = None # if port is 0 then processing an AI service if port == 0: serv = config.get_service_props(name) if not serv: raise AIMDNSError( cw( _('error: aiMDNSError: no such ' 'installation service "%s"') % name)) # ensure the service is enabled if config.PROP_STATUS not in serv: raise AIMDNSError( cw( _('error: aiMDNSError: installation ' 'service key "status" property does ' 'not exist'))) if serv[config.PROP_STATUS] != config.STATUS_ON: print( cw( _('warning: Installation service "%s" is not enabled ' % name))) return None smf_port = config.get_service_port(name) if not smf_port: try: smf_port = libaimdns.getinteger_property( common.SRVINST, common.PORTPROP) smf_port = str(smf_port) except libaimdns.aiMDNSError, err: raise AIMDNSError( cw( _('error: aiMDNSError: port property ' 'failure (%s)') % err))
sys.stdout.write(_('Available services are:<p><ol><i>')) host = socket.gethostname() for service_name in config.get_all_service_names(): # assume new service setup port = config.get_service_port(service_name) sys.stdout.write('<a href="http://%s:%d/cgi-bin/' 'cgi_get_manifest.py?version=%s&service=%s">%s</a><br>\n' % (host, port, VERSION, service_name, service_name)) sys.stdout.write('</i></ol>%s' % _('Please select a service ' 'from the above list.')) print '</body></html>' if __name__ == '__main__': gettext.install("ai", "/usr/lib/locale") DEFAULT_PORT = libaimdns.getinteger_property(com.SRVINST, com.PORTPROP) (PARAM_VERSION, SERVICE, NO_DEFAULT, FORM_DATA) = \ get_parameters(cgi.FieldStorage()) print >> sys.stderr, PARAM_VERSION, SERVICE, NO_DEFAULT, FORM_DATA if PARAM_VERSION == COMPATIBILITY_VERSION or SERVICE is None: # Old client (REQUEST_METHOD, REQUEST_PORT) = get_environment_information() if REQUEST_PORT == DEFAULT_PORT: # only new clients use default port HOST = socket.gethostname() print 'Content-Type: text/html' # HTML is following print # blank line, end of headers print '<pre>' sys.stdout.write(_('error:must supply a service name\n')) sys.stdout.write(_('The request should look like:\n')) sys.stdout.write('<ol>http://%s:%d/cgi_get_manifest.py?' 'version=%s&service=<i>servicename</i></ol>' %