def run(self, props): if 'hostname' in props: netif.set_hostname(props['hostname']) if 'language' in props: self.configstore.set('system.language', props['language']) if 'timezone' in props: self.configstore.set('system.timezone', props['timezone']) if 'console_keymap' in props: self.configstore.set( 'system.console.keymap', props['console_keymap'], ) syslog_changed = False if 'syslog_server' in props: self.configstore.set('system.syslog_server', props['syslog_server']) syslog_changed = True try: self.dispatcher.call_sync('etcd.generation.generate_group', 'localtime') if syslog_changed: self.dispatcher.call_sync('etcd.generation.generate_group', 'syslog') self.dispatcher.call_sync('services.reload', 'syslog') except RpcException, e: raise TaskException( errno.ENXIO, 'Cannot reconfigure system: {0}'.format(str(e),) )
def run(self, props): if 'hostname' in props: netif.set_hostname(props['hostname']) if 'language' in props: self.configstore.set('system.language', props['language']) if 'timezone' in props: self.configstore.set('system.timezone', props['timezone']) if 'console_keymap' in props: self.configstore.set( 'system.console.keymap', props['console_keymap'], ) syslog_changed = False if 'syslog_server' in props: self.configstore.set('system.syslog_server', props['syslog_server']) syslog_changed = True try: self.dispatcher.call_sync('etcd.generation.generate_group', 'localtime') if syslog_changed: self.dispatcher.call_sync('etcd.generation.generate_group', 'syslog') self.dispatcher.call_sync('services.reload', 'syslog') except RpcException as e: raise TaskException( errno.ENXIO, 'Cannot reconfigure system: {0}'.format(str(e),) ) self.dispatcher.dispatch_event('system.general.changed', { 'operation': 'update', })
def run(self, props): if 'hostname' in props: netif.set_hostname(props['hostname']) if 'description' in props: self.configstore.set('system.description', props['description']) if 'tags' in props: self.configstore.set('system.tags', props['tags']) if 'language' in props: self.configstore.set('system.language', props['language']) if 'timezone' in props: new = props['timezone'] old = self.configstore.get('system.timezone') if new != old: count = self.run_subtask_sync('calendar_task.change_timezone', new) self.add_warning( TaskWarning( errno.ENXIO, "{0} calendar tasks rescheduled from timezone '{1}' to '{2}'" .format(count, old, new))) self.configstore.set('system.timezone', new) os.environ['TZ'] = new if 'console_keymap' in props: new = props['console_keymap'] old = self.configstore.get('system.console.keymap') if new != old: with open('/dev/console') as fd: system('/usr/sbin/kbdcontrol', '-l', props['console_keymap'], file_obj_stdin=fd) self.configstore.set('system.console.keymap', new) syslog_changed = False if 'syslog_server' in props: self.configstore.set('system.syslog_server', props['syslog_server']) syslog_changed = True try: self.dispatcher.call_sync('etcd.generation.generate_group', 'localtime') if syslog_changed: self.dispatcher.call_sync('serviced.job.send_signal', 'org.freenas.logd', signal.SIGHUP) except RpcException as e: raise TaskException( errno.ENXIO, 'Cannot reconfigure system: {0}'.format(str(e), )) self.dispatcher.dispatch_event('system.general.changed', { 'operation': 'update', })
def run(self, props): if 'hostname' in props: netif.set_hostname(props['hostname']) if 'description' in props: self.configstore.set('system.description', props['description']) if 'tags' in props: self.configstore.set('system.tags', props['tags']) if 'language' in props: self.configstore.set('system.language', props['language']) if 'timezone' in props: new = props['timezone'] old = self.configstore.get('system.timezone') if new != old: count = self.run_subtask_sync('calendar_task.change_timezone', new) self.add_warning(TaskWarning( errno.ENXIO, "{0} calendar tasks rescheduled from timezone '{1}' to '{2}'".format(count, old, new))) self.configstore.set('system.timezone', new) os.environ['TZ'] = new if 'console_keymap' in props: new = props['console_keymap'] old = self.configstore.get('system.console.keymap') if new != old: with open ('/dev/console') as fd: system('/usr/sbin/kbdcontrol', '-l', props['console_keymap'], file_obj_stdin=fd) self.configstore.set('system.console.keymap', new) syslog_changed = False if 'syslog_server' in props: self.configstore.set('system.syslog_server', props['syslog_server']) syslog_changed = True try: self.dispatcher.call_sync('etcd.generation.generate_group', 'localtime') if syslog_changed: self.dispatcher.call_sync('serviced.job.send_signal', 'org.freenas.logd', signal.SIGHUP) except RpcException as e: raise TaskException( errno.ENXIO, 'Cannot reconfigure system: {0}'.format(str(e),) ) self.dispatcher.dispatch_event('system.general.changed', { 'operation': 'update', })
def run(self, props): if 'hostname' in props: netif.set_hostname(props['hostname']) if 'description' in props: self.configstore.set('system.description', props['description']) if 'tags' in props: self.configstore.set('system.tags', props['tags']) if 'language' in props: self.configstore.set('system.language', props['language']) if 'timezone' in props: new = props['timezone'] old = self.configstore.get('system.timezone') if new != old: count = self.join_subtasks(self.run_subtask('calendar_task.change_timezone', new))[0] self.add_warning(TaskWarning( errno.ENXIO, "{0} calendar tasks rescheduled from timezone '{1}' to '{2}'".format(count, old, new))) self.configstore.set('system.timezone', new) os.environ['TZ'] = new if 'console_keymap' in props: self.configstore.set( 'system.console.keymap', props['console_keymap'], ) syslog_changed = False if 'syslog_server' in props: self.configstore.set('system.syslog_server', props['syslog_server']) syslog_changed = True try: self.dispatcher.call_sync('etcd.generation.generate_group', 'localtime') if syslog_changed: self.dispatcher.call_sync('etcd.generation.generate_group', 'syslog') self.dispatcher.call_sync('service.reload', 'syslog') except RpcException as e: raise TaskException( errno.ENXIO, 'Cannot reconfigure system: {0}'.format(str(e),) ) self.dispatcher.dispatch_event('system.general.changed', { 'operation': 'update', })
def run(self, props): if 'hostname' in props: netif.set_hostname(props['hostname']) if 'description' in props: self.configstore.set('system.description', props['description']) if 'tags' in props: self.configstore.set('system.tags', props['tags']) if 'language' in props: self.configstore.set('system.language', props['language']) if 'timezone' in props: self.configstore.set('system.timezone', props['timezone']) os.environ['TZ'] = props['timezone'] if 'console_keymap' in props: self.configstore.set( 'system.console.keymap', props['console_keymap'], ) syslog_changed = False if 'syslog_server' in props: self.configstore.set('system.syslog_server', props['syslog_server']) syslog_changed = True try: self.dispatcher.call_sync('etcd.generation.generate_group', 'localtime') if syslog_changed: self.dispatcher.call_sync('etcd.generation.generate_group', 'syslog') self.dispatcher.call_sync('service.reload', 'syslog') except RpcException as e: raise TaskException( errno.ENXIO, 'Cannot reconfigure system: {0}'.format(str(e), )) self.dispatcher.dispatch_event('system.general.changed', { 'operation': 'update', })
def _init(dispatcher, plugin): def on_hostname_change(args): if 'hostname' not in args: return dispatcher.configstore.set('system.hostname', args['hostname']) dispatcher.call_sync('services.restart', 'mdns') dispatcher.dispatch_event('system.general.changed', { 'operation': 'update', }) # Register schemas plugin.register_schema_definition('system-advanced', { 'type': 'object', 'properties': { 'console_cli': {'type': 'boolean'}, 'console_screensaver': {'type': 'boolean'}, 'serial_console': {'type': 'boolean'}, 'serial_port': {'type': 'string'}, 'serial_speed': {'type': 'integer'}, 'powerd': {'type': 'boolean'}, 'swapondrive': {'type': 'integer'}, 'debugkernel': {'type': 'boolean'}, 'uploadcrash': {'type': 'boolean'}, 'motd': {'type': 'string'}, 'boot_scrub_internal': {'type': 'integer'}, 'periodic_notify_user': {'type': 'integer'}, }, 'additionalProperties': False, }) plugin.register_schema_definition('system-general', { 'type': 'object', 'properties': { 'hostname': {'type': 'string'}, 'language': {'type': 'string'}, 'timezone': {'type': 'string'}, 'console_keymap': {'type': 'string'}, 'syslog_server': {'type': ['string', 'null']}, }, 'additionalProperties': False, }) plugin.register_schema_definition('system-ui', { 'type': 'object', 'properties': { 'webui_protocol': { 'type': ['array'], 'items': { 'type': 'string', 'enum': ['HTTP', 'HTTPS'], }, }, 'webui_listen': { 'type': ['array'], 'items': {'type': 'string'}, }, 'webui_http_redirect_https': {'type': 'boolean'}, 'webui_http_port': {'type': 'integer'}, 'webui_https_certificate': {'type': ['string', 'null']}, 'webui_https_port': {'type': 'integer'}, }, 'additionalProperties': False, }) plugin.register_schema_definition('system-time', { 'type': 'object', 'additionalProperties': False, 'properties': { 'system_time': {'type': 'string'}, 'boot_time': {'type': 'string'}, 'uptime': {'type': 'string'}, 'timezone': {'type': 'string'} } }) # Register event handler plugin.register_event_handler('system.hostname.change', on_hostname_change) # Register providers plugin.register_provider("system.advanced", SystemAdvancedProvider) plugin.register_provider("system.general", SystemGeneralProvider) plugin.register_provider("system.info", SystemInfoProvider) plugin.register_provider("system.ui", SystemUIProvider) # Register task handlers plugin.register_task_handler("system.advanced.configure", SystemAdvancedConfigureTask) plugin.register_task_handler("system.general.configure", SystemGeneralConfigureTask) plugin.register_task_handler("system.ui.configure", SystemUIConfigureTask) plugin.register_task_handler("system.time.configure", SystemTimeConfigureTask) plugin.register_task_handler("system.shutdown", SystemHaltTask) plugin.register_task_handler("system.reboot", SystemRebootTask) # Set initial hostname netif.set_hostname(dispatcher.configstore.get('system.hostname'))
def _init(dispatcher, plugin): def on_hostname_change(args): if 'hostname' not in args: return if args.get('jid') != 0: return dispatcher.configstore.set('system.hostname', args['hostname']) dispatcher.call_sync('service.restart', 'mdns') dispatcher.dispatch_event('system.general.changed', { 'operation': 'update', }) def on_system_timezone_change(args): logger.warning('Setting time zone to {0}'.format(args.get('timezone'))) os.environ['TZ'] = args.get('timezone') time.tzset() def on_certificate_change(args): if args.get('operation') != 'delete': return webui_certid = dispatcher.configstore.get( 'service.nginx.https.certificate') if not webui_certid: return for id in args.get('ids', []): if id == webui_certid: logger.warning( 'Clearing the WebUI Certificate field and switching to HTTP only' ) dispatcher.call_task_sync('system.ui.update', { 'webui_https_certificate': None, 'webui_protocol': ['HTTP'] }) return try: with open('/dev/console') as fd: system('/usr/sbin/kbdcontrol', '-l', dispatcher.configstore.get('system.console.keymap'), file_obj_stdin=fd) except SubprocessException as e: logger.error('Setting console keymap failed: {}'.format(str(e))) # Register schemas plugin.register_schema_definition( 'SystemAdvanced', { 'type': 'object', 'properties': { 'console_cli': { 'type': 'boolean' }, 'console_screensaver': { 'type': 'boolean' }, 'serial_console': { 'type': 'boolean' }, 'serial_port': { 'type': 'string' }, 'serial_speed': { '$ref': 'SystemAdvancedSerialspeed' }, 'powerd': { 'type': 'boolean' }, 'swapondrive': { 'type': 'integer' }, 'debugkernel': { 'type': 'boolean' }, 'debugui': { 'type': 'boolean' }, 'uploadcrash': { 'type': 'boolean' }, 'home_directory_root': { 'type': ['string', 'null'] }, 'motd': { 'type': 'string' }, 'boot_scrub_internal': { 'type': 'integer' }, 'periodic_notify_user': { 'type': 'integer' }, 'graphite_servers': { 'type': 'array', 'items': { 'type': 'string' } }, 'freenas_token_lifetime': { 'type': 'integer' } }, 'additionalProperties': False, }) plugin.register_schema_definition( 'SystemAdvancedSerialspeed', { 'type': 'integer', 'enum': [ 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200 ] }) plugin.register_schema_definition( 'SystemGeneral', { 'type': 'object', 'properties': { 'hostname': { 'type': 'string' }, 'description': { 'type': 'string' }, 'tags': { 'type': 'array', 'items': { 'type': 'string' } }, 'language': { 'type': 'string' }, 'timezone': { 'type': 'string' }, 'console_keymap': { 'type': 'string' }, 'syslog_server': { 'type': ['string', 'null'] }, }, 'additionalProperties': False, }) plugin.register_schema_definition( 'SystemUi', { 'type': 'object', 'properties': { 'webui_protocol': { 'type': ['array'], 'items': { '$ref': 'SystemUiWebuiprotocolItems' } }, 'webui_listen': { 'type': ['array'], 'items': { '$ref': 'IpAddress' }, }, 'webui_http_redirect_https': { 'type': 'boolean' }, 'webui_http_port': { 'type': 'integer' }, 'webui_https_certificate': { 'type': ['string', 'null'] }, 'webui_https_port': { 'type': 'integer' }, }, 'additionalProperties': False, }) plugin.register_schema_definition('SystemUiWebuiprotocolItems', { 'type': 'string', 'enum': ['HTTP', 'HTTPS'], }) plugin.register_schema_definition( 'SystemTime', { 'type': 'object', 'additionalProperties': False, 'properties': { 'system_time': { 'type': 'datetime' }, 'boot_time': { 'type': 'datetime' }, 'uptime': { 'type': 'number' }, 'timezone': { 'type': 'string' } } }) plugin.register_schema_definition( 'PowerChanged', { 'type': 'object', 'additionalProperties': False, 'properties': { 'operation': { '$ref': 'PowerChangedOperation' }, } }) plugin.register_schema_definition('PowerChangedOperation', { 'type': 'string', 'enum': ['SHUTDOWN', 'REBOOT'] }) # Register event handlers plugin.register_event_handler('system.hostname.change', on_hostname_change) plugin.register_event_handler('system.timezone.change', on_system_timezone_change) plugin.register_event_handler('crypto.certificate.changed', on_certificate_change) # Register Event Types plugin.register_event_type('system.general.changed') plugin.register_event_type('system.advanced.changed') plugin.register_event_type('system.ui.changed') plugin.register_event_type('power.changed', schema=h.ref('PowerChanged')) # Register providers plugin.register_provider("system.advanced", SystemAdvancedProvider) plugin.register_provider("system.general", SystemGeneralProvider) plugin.register_provider("system.info", SystemInfoProvider) plugin.register_provider("system.time", SystemTimeProvider) plugin.register_provider("system.ui", SystemUIProvider) # Register task handlers plugin.register_task_handler("system.advanced.update", SystemAdvancedConfigureTask) plugin.register_task_handler("system.general.update", SystemGeneralConfigureTask) plugin.register_task_handler("system.ui.update", SystemUIConfigureTask) plugin.register_task_handler("system.time.update", SystemTimeConfigureTask) plugin.register_task_handler("system.shutdown", SystemHaltTask) plugin.register_task_handler("system.reboot", SystemRebootTask) # Register debug hook plugin.register_debug_hook(collect_debug) # Set initial hostname netif.set_hostname(dispatcher.configstore.get('system.hostname'))
def _init(dispatcher, plugin): def on_hostname_change(args): if 'hostname' not in args: return if args.get('jid') != 0: return dispatcher.configstore.set('system.hostname', args['hostname']) dispatcher.call_sync('service.restart', 'mdns') dispatcher.dispatch_event('system.general.changed', { 'operation': 'update', }) def on_system_timezone_change(args): logger.warning('Setting time zone to {0}'.format(args.get('timezone'))) os.environ['TZ'] = args.get('timezone') time.tzset() # Register schemas plugin.register_schema_definition( 'system-advanced', { 'type': 'object', 'properties': { 'console_cli': { 'type': 'boolean' }, 'console_screensaver': { 'type': 'boolean' }, 'serial_console': { 'type': 'boolean' }, 'serial_port': { 'type': 'string' }, 'serial_speed': { '$ref': 'system-advanced-serialspeed' }, 'powerd': { 'type': 'boolean' }, 'swapondrive': { 'type': 'integer' }, 'debugkernel': { 'type': 'boolean' }, 'uploadcrash': { 'type': 'boolean' }, 'home_directory_root': { 'type': ['string', 'null'] }, 'motd': { 'type': 'string' }, 'boot_scrub_internal': { 'type': 'integer' }, 'periodic_notify_user': { 'type': 'integer' }, 'graphite_servers': { 'type': 'array', 'items': { 'type': 'string' } }, 'freenas_token_lifetime': { 'type': 'integer' } }, 'additionalProperties': False, }) plugin.register_schema_definition( 'system-advanced-serialspeed', { 'type': 'integer', 'enum': [ 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200 ] }) plugin.register_schema_definition( 'system-general', { 'type': 'object', 'properties': { 'hostname': { 'type': 'string' }, 'description': { 'type': 'string' }, 'tags': { 'type': 'array', 'items': { 'type': 'string' } }, 'language': { 'type': 'string' }, 'timezone': { 'type': 'string' }, 'console_keymap': { 'type': 'string' }, 'syslog_server': { 'type': ['string', 'null'] }, }, 'additionalProperties': False, }) plugin.register_schema_definition( 'system-ui', { 'type': 'object', 'properties': { 'webui_protocol': { 'type': ['array'], 'items': { '$ref': 'system-ui-webuiprotocol-items' } }, 'webui_listen': { 'type': ['array'], 'items': { '$ref': 'ip-address' }, }, 'webui_http_redirect_https': { 'type': 'boolean' }, 'webui_http_port': { 'type': 'integer' }, 'webui_https_certificate': { 'type': ['string', 'null'] }, 'webui_https_port': { 'type': 'integer' }, }, 'additionalProperties': False, }) plugin.register_schema_definition('system-ui-webuiprotocol-items', { 'type': 'string', 'enum': ['HTTP', 'HTTPS'], }) plugin.register_schema_definition( 'system-time', { 'type': 'object', 'additionalProperties': False, 'properties': { 'system_time': { 'type': 'datetime' }, 'boot_time': { 'type': 'datetime' }, 'uptime': { 'type': 'number' }, 'timezone': { 'type': 'string' } } }) plugin.register_schema_definition( 'power-changed', { 'type': 'object', 'additionalProperties': False, 'properties': { 'operation': { '$ref': 'power-changed-operation' }, } }) plugin.register_schema_definition('power-changed-operation', { 'type': 'string', 'enum': ['SHUTDOWN', 'REBOOT'] }) # Register event handlers plugin.register_event_handler('system.hostname.change', on_hostname_change) plugin.register_event_handler('system.timezone.change', on_system_timezone_change) # Register Event Types plugin.register_event_type('system.general.changed') plugin.register_event_type('system.advanced.changed') plugin.register_event_type('system.ui.changed') plugin.register_event_type('power.changed', schema=h.ref('power-changed')) # Register providers plugin.register_provider("system.advanced", SystemAdvancedProvider) plugin.register_provider("system.general", SystemGeneralProvider) plugin.register_provider("system.info", SystemInfoProvider) plugin.register_provider("system.time", SystemTimeProvider) plugin.register_provider("system.ui", SystemUIProvider) # Register task handlers plugin.register_task_handler("system.advanced.update", SystemAdvancedConfigureTask) plugin.register_task_handler("system.general.update", SystemGeneralConfigureTask) plugin.register_task_handler("system.ui.update", SystemUIConfigureTask) plugin.register_task_handler("system.time.update", SystemTimeConfigureTask) plugin.register_task_handler("system.shutdown", SystemHaltTask) plugin.register_task_handler("system.reboot", SystemRebootTask) # Register debug hook plugin.register_debug_hook(collect_debug) # Set initial hostname netif.set_hostname(dispatcher.configstore.get('system.hostname'))
def _init(dispatcher, plugin): def on_hostname_change(args): if 'hostname' not in args: return if args.get('jid') != 0: return dispatcher.configstore.set('system.hostname', args['hostname']) dispatcher.call_sync('service.restart', 'mdns') dispatcher.dispatch_event('system.general.changed', { 'operation': 'update', }) def on_system_timezone_change(args): logger.warning('Setting time zone to {0}'.format(args.get('timezone'))) os.environ['TZ'] = args.get('timezone') time.tzset() # Register schemas plugin.register_schema_definition('system-advanced', { 'type': 'object', 'properties': { 'console_cli': {'type': 'boolean'}, 'console_screensaver': {'type': 'boolean'}, 'serial_console': {'type': 'boolean'}, 'serial_port': {'type': 'string'}, 'serial_speed': {'$ref': 'system-advanced-serialspeed'}, 'powerd': {'type': 'boolean'}, 'swapondrive': {'type': 'integer'}, 'debugkernel': {'type': 'boolean'}, 'uploadcrash': {'type': 'boolean'}, 'home_directory_root': {'type': ['string', 'null']}, 'motd': {'type': 'string'}, 'boot_scrub_internal': {'type': 'integer'}, 'periodic_notify_user': {'type': 'integer'}, 'graphite_servers': { 'type': 'array', 'items': {'type': 'string'} }, 'freenas_token_lifetime': {'type': 'integer'} }, 'additionalProperties': False, }) plugin.register_schema_definition('system-advanced-serialspeed', { 'type': 'integer', 'enum': [110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200] }) plugin.register_schema_definition('system-general', { 'type': 'object', 'properties': { 'hostname': {'type': 'string'}, 'description': {'type': 'string'}, 'tags': { 'type': 'array', 'items': {'type': 'string'} }, 'language': {'type': 'string'}, 'timezone': {'type': 'string'}, 'console_keymap': {'type': 'string'}, 'syslog_server': {'type': ['string', 'null']}, }, 'additionalProperties': False, }) plugin.register_schema_definition('system-ui', { 'type': 'object', 'properties': { 'webui_protocol': { 'type': ['array'], 'items': {'$ref': 'system-ui-webuiprotocol-items'} }, 'webui_listen': { 'type': ['array'], 'items': {'$ref': 'ip-address'}, }, 'webui_http_redirect_https': {'type': 'boolean'}, 'webui_http_port': {'type': 'integer'}, 'webui_https_certificate': {'type': ['string', 'null']}, 'webui_https_port': {'type': 'integer'}, }, 'additionalProperties': False, }) plugin.register_schema_definition('system-ui-webuiprotocol-items', { 'type': 'string', 'enum': ['HTTP', 'HTTPS'], }) plugin.register_schema_definition('system-time', { 'type': 'object', 'additionalProperties': False, 'properties': { 'system_time': {'type': 'datetime'}, 'boot_time': {'type': 'datetime'}, 'uptime': {'type': 'number'}, 'timezone': {'type': 'string'} } }) plugin.register_schema_definition('power-changed', { 'type': 'object', 'additionalProperties': False, 'properties': { 'operation': {'$ref': 'power-changed-operation'}, } }) plugin.register_schema_definition('power-changed-operation', { 'type': 'string', 'enum': ['SHUTDOWN', 'REBOOT'] }) # Register event handlers plugin.register_event_handler('system.hostname.change', on_hostname_change) plugin.register_event_handler('system.timezone.change', on_system_timezone_change) # Register Event Types plugin.register_event_type('system.general.changed') plugin.register_event_type('system.advanced.changed') plugin.register_event_type('system.ui.changed') plugin.register_event_type('power.changed', schema=h.ref('power-changed')) # Register providers plugin.register_provider("system.advanced", SystemAdvancedProvider) plugin.register_provider("system.general", SystemGeneralProvider) plugin.register_provider("system.info", SystemInfoProvider) plugin.register_provider("system.time", SystemTimeProvider) plugin.register_provider("system.ui", SystemUIProvider) # Register task handlers plugin.register_task_handler("system.advanced.update", SystemAdvancedConfigureTask) plugin.register_task_handler("system.general.update", SystemGeneralConfigureTask) plugin.register_task_handler("system.ui.update", SystemUIConfigureTask) plugin.register_task_handler("system.time.update", SystemTimeConfigureTask) plugin.register_task_handler("system.shutdown", SystemHaltTask) plugin.register_task_handler("system.reboot", SystemRebootTask) # Register debug hook plugin.register_debug_hook(collect_debug) # Set initial hostname netif.set_hostname(dispatcher.configstore.get('system.hostname'))
def _init(dispatcher, plugin): def on_hostname_change(args): if 'hostname' not in args: return if args.get('jid') != 0: return dispatcher.configstore.set('system.hostname', args['hostname']) dispatcher.call_sync('service.restart', 'mdns') dispatcher.dispatch_event('system.general.changed', { 'operation': 'update', }) def on_system_timezone_change(args): logger.warning('Setting time zone to {0}'.format(args.get('timezone'))) os.environ['TZ'] = args.get('timezone') time.tzset() def on_certificate_change(args): if args.get('operation') != 'delete': return webui_certid = dispatcher.configstore.get('service.nginx.https.certificate') if not webui_certid: return for id in args.get('ids', []): if id == webui_certid: logger.warning('Clearing the WebUI Certificate field and switching to HTTP only') dispatcher.call_task_sync( 'system.ui.update', {'webui_https_certificate': None, 'webui_protocol': ['HTTP']} ) return try: with open('/dev/console') as fd: system('/usr/sbin/kbdcontrol', '-l', dispatcher.configstore.get('system.console.keymap'), file_obj_stdin=fd) except SubprocessException as e: logger.error('Setting console keymap failed: {}'.format(str(e))) # Register schemas plugin.register_schema_definition('SystemAdvanced', { 'type': 'object', 'properties': { 'console_cli': {'type': 'boolean'}, 'console_screensaver': {'type': 'boolean'}, 'serial_console': {'type': 'boolean'}, 'serial_port': {'type': 'string'}, 'serial_speed': {'$ref': 'SystemAdvancedSerialspeed'}, 'powerd': {'type': 'boolean'}, 'swapondrive': {'type': 'integer'}, 'debugkernel': {'type': 'boolean'}, 'uploadcrash': {'type': 'boolean'}, 'home_directory_root': {'type': ['string', 'null']}, 'motd': {'type': 'string'}, 'boot_scrub_internal': {'type': 'integer'}, 'periodic_notify_user': {'type': 'integer'}, 'graphite_servers': { 'type': 'array', 'items': {'type': 'string'} }, 'freenas_token_lifetime': {'type': 'integer'} }, 'additionalProperties': False, }) plugin.register_schema_definition('SystemAdvancedSerialspeed', { 'type': 'integer', 'enum': [110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200] }) plugin.register_schema_definition('SystemGeneral', { 'type': 'object', 'properties': { 'hostname': {'type': 'string'}, 'description': {'type': 'string'}, 'tags': { 'type': 'array', 'items': {'type': 'string'} }, 'language': {'type': 'string'}, 'timezone': {'type': 'string'}, 'console_keymap': {'type': 'string'}, 'syslog_server': {'type': ['string', 'null']}, }, 'additionalProperties': False, }) plugin.register_schema_definition('SystemUi', { 'type': 'object', 'properties': { 'webui_protocol': { 'type': ['array'], 'items': {'$ref': 'SystemUiWebuiprotocolItems'} }, 'webui_listen': { 'type': ['array'], 'items': {'$ref': 'IpAddress'}, }, 'webui_http_redirect_https': {'type': 'boolean'}, 'webui_http_port': {'type': 'integer'}, 'webui_https_certificate': {'type': ['string', 'null']}, 'webui_https_port': {'type': 'integer'}, }, 'additionalProperties': False, }) plugin.register_schema_definition('SystemUiWebuiprotocolItems', { 'type': 'string', 'enum': ['HTTP', 'HTTPS'], }) plugin.register_schema_definition('SystemTime', { 'type': 'object', 'additionalProperties': False, 'properties': { 'system_time': {'type': 'datetime'}, 'boot_time': {'type': 'datetime'}, 'uptime': {'type': 'number'}, 'timezone': {'type': 'string'} } }) plugin.register_schema_definition('PowerChanged', { 'type': 'object', 'additionalProperties': False, 'properties': { 'operation': {'$ref': 'PowerChangedOperation'}, } }) plugin.register_schema_definition('PowerChangedOperation', { 'type': 'string', 'enum': ['SHUTDOWN', 'REBOOT'] }) # Register event handlers plugin.register_event_handler('system.hostname.change', on_hostname_change) plugin.register_event_handler('system.timezone.change', on_system_timezone_change) plugin.register_event_handler('crypto.certificate.changed', on_certificate_change) # Register Event Types plugin.register_event_type('system.general.changed') plugin.register_event_type('system.advanced.changed') plugin.register_event_type('system.ui.changed') plugin.register_event_type('power.changed', schema=h.ref('PowerChanged')) # Register providers plugin.register_provider("system.advanced", SystemAdvancedProvider) plugin.register_provider("system.general", SystemGeneralProvider) plugin.register_provider("system.info", SystemInfoProvider) plugin.register_provider("system.time", SystemTimeProvider) plugin.register_provider("system.ui", SystemUIProvider) # Register task handlers plugin.register_task_handler("system.advanced.update", SystemAdvancedConfigureTask) plugin.register_task_handler("system.general.update", SystemGeneralConfigureTask) plugin.register_task_handler("system.ui.update", SystemUIConfigureTask) plugin.register_task_handler("system.time.update", SystemTimeConfigureTask) plugin.register_task_handler("system.shutdown", SystemHaltTask) plugin.register_task_handler("system.reboot", SystemRebootTask) # Register debug hook plugin.register_debug_hook(collect_debug) # Set initial hostname netif.set_hostname(dispatcher.configstore.get('system.hostname'))
def _init(dispatcher, plugin): def on_hostname_change(args): if 'hostname' not in args: return dispatcher.configstore.set('system.hostname', args['hostname']) dispatcher.dispatch_event('system.general.changed', { 'operation': 'update', }) # Register schemas plugin.register_schema_definition('system-advanced', { 'type': 'object', 'properties': { 'console_cli': {'type': 'boolean'}, 'console_screensaver': {'type': 'boolean'}, 'serial_console': {'type': 'boolean'}, 'serial_port': {'type': 'string'}, 'serial_speed': {'type': 'integer'}, 'powerd': {'type': 'boolean'}, 'swapondrive': {'type': 'integer'}, 'autotune': {'type': 'boolean'}, 'debugkernel': {'type': 'boolean'}, 'uploadcrash': {'type': 'boolean'}, 'motd': {'type': 'string'}, 'boot_scrub_internal': {'type': 'integer'}, 'periodic_notify_user': {'type': 'integer'}, }, 'additionalProperties': False, }) plugin.register_schema_definition('system-general', { 'type': 'object', 'properties': { 'hostname': {'type': 'string'}, 'language': {'type': 'string'}, 'timezone': {'type': 'string'}, 'console_keymap': {'type': 'string'}, 'syslog_server': {'type': ['string', 'null']}, }, 'additionalProperties': False, }) plugin.register_schema_definition('system-ui', { 'type': 'object', 'properties': { 'webui_protocol': { 'type': ['array'], 'items': { 'type': 'string', 'enum': ['HTTP', 'HTTPS'], }, }, 'webui_listen': { 'type': ['array'], 'items': {'type': 'string'}, }, 'webui_http_redirect_https': {'type': 'boolean'}, 'webui_http_port': {'type': 'integer'}, 'webui_https_certificate': {'type': ['string', 'null']}, 'webui_https_port': {'type': 'integer'}, }, 'additionalProperties': False, }) # Register event handler plugin.register_event_handler('system.hostname.change', on_hostname_change) # Register providers plugin.register_provider("system.advanced", SystemAdvancedProvider) plugin.register_provider("system.general", SystemGeneralProvider) plugin.register_provider("system.info", SystemInfoProvider) plugin.register_provider("system.ui", SystemUIProvider) # Register task handlers plugin.register_task_handler("system.advanced.configure", SystemAdvancedConfigureTask) plugin.register_task_handler("system.general.configure", SystemGeneralConfigureTask) plugin.register_task_handler("system.ui.configure", SystemUIConfigureTask) plugin.register_task_handler("system.shutdown", SystemHaltTask) plugin.register_task_handler("system.reboot", SystemRebootTask) # Set initial hostname netif.set_hostname(dispatcher.configstore.get('system.hostname'))