Exemple #1
0
def main():
    opts = parse_arguments()

    level = logging.INFO
    if opts.debug:
        level = logging.DEBUG
    logging.basicConfig(level=level)

    if opts.config_path:
        ConfigLoader.set_config_location(opts.config_path)

    if not opts.document_root:
        logging.error('Document root not provided')
        raise SystemExit(1)

    logging.debug('configuration at: %s', ConfigLoader.CONFIG_PATH)

    if opts.helpers_dir:
        ServiceReloader.set_helpers_dir(opts.helpers_dir)

    if opts.ia:
        logging.error('Image Analyzer mode')
        app = Application(opts.document_root, mode=Application.MODE_AO)
    else:
        app = Application(opts.document_root)

    logging.debug('listening on port %d', opts.http_port)
    app.listen(opts.http_port)

    logging.debug('starting...')
    IOLoop.instance().start()
Exemple #2
0
    def get(self):
        ldr = self.app.get_template_loader()
        tmpl = ldr.load('system_settings.html')

        config = ConfigLoader()
        rig = config.get_system()
        if not rig:
            rig = None
        system_entries = [
            dict(name='Assigned Rig',
                 value=rig,
                 type='input',
                 id='assigned_rig')
        ]
        if self.app.mode == self.app.MODE_KR:
            aladin = config.get_aladin()
            system_entries.append(
                dict(name='Aladin control mode',
                     value=SystemSettingsHandler.aladin_modes_get[aladin],
                     type='dropdown',
                     id='controll_aladin',
                     options=list(
                         SystemSettingsHandler.aladin_modes_get.values())))

        self.write(
            tmpl.generate(system_entries=system_entries,
                          configuration_active=True,
                          widget_render=partial(widget_render, ldr)))
Exemple #3
0
def main():
    opts = parse_arguments()

    level = logging.INFO
    if opts.debug:
        level = logging.DEBUG
    logging.basicConfig(level=level)

    if opts.config_path:
        ConfigLoader.set_config_location(opts.config_path)

    if not opts.document_root:
        logging.error('Document root not provided')
        raise SystemExit(1)

    logging.debug('configuration at: %s', ConfigLoader.CONFIG_PATH)

    if opts.helpers_dir:
        ServiceReloader.set_helpers_dir(opts.helpers_dir)

    if opts.ia:
        logging.error('Image Analyzer mode')
        app = Application(opts.document_root, mode=Application.MODE_AO)
    else:
        app = Application(opts.document_root)

    logging.debug('listening on port %d', opts.http_port)
    app.listen(opts.http_port)

    logging.debug('starting...')
    IOLoop.instance().start()
Exemple #4
0
    def get(self):
        _log.debug("get: %r", self.request)

        config_applied = self.get_argument('config_applied', False)
        if config_applied == '1':
            config_applied = True

        reboot_applied = self.get_argument('reboot_applied', False)
        if reboot_applied == '1':
            reboot_applied = True

        ldr = self.app.get_template_loader()
        tmpl = ldr.load('status.html')

        config = ConfigLoader()
        rig = config.get_system()
        if not rig:
            rig = 'None'

        hostname = get_hostname()
        if not hostname:
            hostname = 'ros3d'

        system_entries = [
            dict(name='Hostname', value=hostname),
            dict(name='Assigned Rig', value=rig)
        ]

        if self.app.mode == Application.MODE_KR:
            aladin = config.get_aladin()
            system_entries.append(
                dict(name='Aladin Control Mode',
                     value=SystemSettingsHandler.aladin_modes_get[aladin]))

        system_entries.append(dict(name='Uptime', value=self._uptime()))
        network_entries = self._net()
        camera_entries = [
            dict(name='Cam 1', value='Inactive'),
            dict(name='Cam 2', value='Active')
        ]
        camera_entries = self._cam()
        self.write(
            tmpl.generate(system_entries=system_entries,
                          network_entries=network_entries,
                          camera_entries=camera_entries,
                          config_applied=config_applied,
                          reboot_applied=reboot_applied,
                          system_active=True,
                          widget_render=partial(widget_render, ldr)))
Exemple #5
0
    def post(self):
        _log.debug('configuration set: %s', self.request)
        _log.debug('body: %s', self.request.body)

        # parse request
        arguments = parse_qs_bytes(self.request.body, keep_blank_values=False)
        _log.debug('arguments: %s', arguments)

        if arguments.has_key('assigned_rig') and arguments['assigned_rig'][0]:
            rig = arguments['assigned_rig'][0]
            _log.debug('set assigned rig to: %s', rig)
        else:
            rig = None

        if (self.app.mode
                == self.app.MODE_KR) and arguments['controll_aladin'][0]:
            aladin = self.aladin_modes_post[arguments['controll_aladin'][0]]

        def get_arg(arg):
            if arguments.has_key(arg):
                return arguments[arg][0]
            else:
                return None

        # services in need of reload
        need_reload = []

        config = ConfigLoader()
        if rig != config.get_system():
            config.set_system(rig)
            # reload controller service
            need_reload.append(ServiceReloader.SERVICE_CONTROLLER)

        if self.app.mode == self.app.MODE_KR:
            if aladin != config.get_aladin():
                config.set_aladin(aladin)
                need_reload.append(ServiceReloader.SERVICE_SERVO)

        # update configuration file
        config.write()

        if need_reload:
            _log.info('services needing reload: %s', need_reload)
            ServiceReloader.reload(need_reload)
            _log.info('reload complete')

        self.redirect('/?config_applied=1')
Exemple #6
0
    def get(self):
        _log.debug("get: %r", self.request)

        config_applied = self.get_argument('config_applied', False)
        if config_applied == '1':
            config_applied = True

        reboot_applied = self.get_argument('reboot_applied', False)
        if reboot_applied == '1':
            reboot_applied = True

        ldr = self.app.get_template_loader()
        tmpl = ldr.load('status.html')

        config = ConfigLoader()
        rig = config.get_system()
        if not rig:
            rig = 'None'

        hostname = get_hostname()
        if not hostname:
            hostname = 'ros3d'

        system_entries= [
            dict(name='Hostname', value=hostname),
            dict(name='Assigned Rig', value=rig)
        ]

        if self.app.mode == Application.MODE_KR:
            aladin = config.get_aladin()
            system_entries.append(dict(name='Aladin Control Mode',
                                       value=SystemSettingsHandler.aladin_modes_get[aladin]))

        system_entries.append(dict(name='Uptime', value=self._uptime()))
        network_entries = self._net()
        camera_entries = [
                dict(name='Cam 1', value='Inactive'),
                dict(name='Cam 2', value='Active')
                ]
        camera_entries = self._cam()
        self.write(tmpl.generate(system_entries=system_entries,
                                 network_entries=network_entries,
                                 camera_entries=camera_entries,
                                 config_applied=config_applied,
                                 reboot_applied=reboot_applied,
                                 system_active=True,
                                 widget_render=partial(widget_render, ldr)))
Exemple #7
0
    def post(self):
        _log.debug('configuration set: %s' , self.request)
        _log.debug('body: %s', self.request.body)

        # parse request
        arguments = parse_qs_bytes(self.request.body, keep_blank_values=False)
        _log.debug('arguments: %s', arguments)

        if arguments.has_key('assigned_rig') and arguments['assigned_rig'][0]:
            rig = arguments['assigned_rig'][0]
            _log.debug('set assigned rig to: %s', rig)
        else:
            rig = None

        if (self.app.mode == self.app.MODE_KR) and arguments['controll_aladin'][0]:
            aladin = self.aladin_modes_post[arguments['controll_aladin'][0]]

        def get_arg(arg):
            if arguments.has_key(arg):
                return arguments[arg][0]
            else:
                return None

        # services in need of reload
        need_reload = []

        config = ConfigLoader()
        if rig != config.get_system():
            config.set_system(rig)
            # reload controller service
            need_reload.append(ServiceReloader.SERVICE_CONTROLLER)

        if self.app.mode == self.app.MODE_KR:
            if aladin != config.get_aladin():
                config.set_aladin(aladin)
                need_reload.append(ServiceReloader.SERVICE_SERVO)

        # update configuration file
        config.write()

        if need_reload:
            _log.info('services needing reload: %s', need_reload)
            ServiceReloader.reload(need_reload)
            _log.info('reload complete')

        self.redirect('/?config_applied=1')
Exemple #8
0
    def get(self):
        ldr = self.app.get_template_loader()
        tmpl = ldr.load('system_settings.html')

        config = ConfigLoader()
        rig = config.get_system()
        if not rig:
            rig = None
        system_entries = [
            dict(name='Assigned Rig', value=rig, type='input', id='assigned_rig')
        ]
        if self.app.mode == self.app.MODE_KR:
            aladin = config.get_aladin()
            system_entries.append(dict(name='Aladin control mode',
                                       value=SystemSettingsHandler.aladin_modes_get[aladin],
                                       type='dropdown',
                                       id='controll_aladin',
                                       options=list(SystemSettingsHandler.aladin_modes_get.values())))

        self.write(tmpl.generate(system_entries=system_entries,
                                 configuration_active=True,
                                 widget_render=partial(widget_render, ldr)))
Exemple #9
0
    def __init__(self):
        super(DevControllerRestClient, self).__init__()

        config = ConfigLoader()
        self.rest_url = config.get_rest_url()
        LOG.debug('rest client created')
Exemple #10
0
    def post(self):
        _log.debug('configuration set: %s', self.request)
        _log.debug('body: %s', self.request.body)

        # parse request
        arguments = parse_qs_bytes(self.request.body, keep_blank_values=False)
        _log.debug('arguments: %s', arguments)

        wired_config = {}
        wireless_config = {}

        def get_ip_config(prefix):
            if arguments.has_key(prefix + '_ipv4_method'):
                method = arguments[prefix + '_ipv4_method'][0].lower()
                if method not in ['dhcp', 'static']:
                    # incorrect method
                    # TODO: raise exception
                    _log.error('incorrect method: %s', method)

                ipv4_config = {'method': method}

                static_method_keys = [
                    prefix + '_ipv4_address', prefix + '_ipv4_netmask',
                    prefix + '_ipv4_gateway'
                ]
                if method == 'static':
                    if all([arguments.has_key(k)
                            for k in static_method_keys]) == False:
                        # missing confgiuration
                        # TODO: raise exception
                        _log.error('incorrect network configuration: %s',
                                   arguments)
                    else:
                        ipv4_config['address'] = arguments[prefix +
                                                           '_ipv4_address'][0]
                        ipv4_config['netmask'] = arguments[prefix +
                                                           '_ipv4_netmask'][0]
                        ipv4_config['gateway'] = arguments[prefix +
                                                           '_ipv4_gateway'][0]
                return ipv4_config
            else:
                # TODO: raise exception
                _log.error('IPv4 method not specified in arguments: %s',
                           arguments)
            return None

        wired_config['ipv4'] = get_ip_config('eth')
        wireless_config['ipv4'] = get_ip_config('wifi')

        def get_arg(arg):
            if arguments.has_key(arg):
                return arguments[arg][0]
            else:
                return None

        wireless_config['name'] = get_arg('wifi_ap_name')
        wireless_config['password'] = get_arg('wifi_psk_pass')

        net = network_provider()
        net_config = {
            'wired': [wired_config],
        }
        if self.app.mode == self.app.MODE_KR:
            net_config['wireless'] = [wireless_config]

        net.set_config(net_config)

        config = ConfigLoader()
        config.write()

        self.redirect('/?config_applied=1')
Exemple #11
0
    def get(self):
        ldr = self.app.get_template_loader()
        tmpl = ldr.load('network_settings.html')

        config = ConfigLoader()
        net = network_provider().list_interfaces()
        wired = net['wired'][0]
        if bool(net.get('wireless', [])):
            wireless = net['wireless'][0]
        else:
            wireless = None

        # format IP address assignment method properly
        def _convert_ip_method(in_method):
            """Convert passed IP method to a value that is suitable for presentation"""
            conv_method = {'dhcp': 'DHCP', 'static': 'Static'}
            return conv_method.get(in_method, 'Unknown')

        _log.debug('first wired interface: %s', wired)

        if wired['online']:
            src = 'ipv4'
        else:
            src = 'ipv4conf'
        eth_address = wired[src].get('address', None)
        eth_netmask = wired[src].get('netmask', None)
        eth_gateway = wired[src].get('gateway', None)
        eth_method = _convert_ip_method(wired[src].get('method', 'dhcp'))

        # setup wired interface
        network_entries = {
            'wired': [
                dict(name='IPv4 Address',
                     value=eth_address,
                     type='input',
                     id='eth_ipv4_address'),
                dict(name='IPv4 Mask',
                     value=eth_netmask,
                     type='input',
                     id='eth_ipv4_netmask'),
                dict(name='IPv4 Gateway',
                     value=eth_gateway,
                     type='input',
                     id='eth_ipv4_gateway'),
                dict(name='IPv4 Method',
                     value=eth_method,
                     type='dropdown',
                     id='eth_ipv4_method',
                     options=['DHCP', 'Static'])
            ],
            'wireless': []
        }

        if wireless:
            if wireless['online']:
                src = 'ipv4'
            else:
                src = 'ipv4conf'
            wifi_address = wireless[src].get('address', None)
            wifi_netmask = wireless[src].get('netmask', None)
            wifi_gateway = wireless[src].get('gateway', None)
            wifi_method = _convert_ip_method(wireless[src].get(
                'method', 'dhcp'))

            if wireless['wificonf']:
                wifi_ap = wireless['wificonf'].get('name', None)
                wifi_psk = wireless['wificonf'].get('wpa-psk', None)
            else:
                wifi_ap = None
                wifi_psk = None

            wireless_entry = [
                dict(name='Access Point',
                     value=wifi_ap,
                     type='input',
                     id='wifi_ap_name'),
                dict(name='WPA Password',
                     value=wifi_psk,
                     type='password',
                     id='wifi_psk_pass'),
                dict(name='IPv4 Address',
                     value=wifi_address,
                     type='input',
                     id='wifi_ipv4_address'),
                dict(name='IPv4 Mask',
                     value=wifi_netmask,
                     type='input',
                     id='wifi_ipv4_netmask'),
                dict(name='IPv4 Gateway',
                     value=wifi_gateway,
                     type='input',
                     id='wifi_ipv4_gateway'),
                dict(name='IPv4 Method',
                     value=wifi_method,
                     type='dropdown',
                     id='wifi_ipv4_method',
                     options=['DHCP', 'Static'])
            ]
        else:
            wireless_entry = [dict(name='Status', value='No device')]
        if self.app.mode == self.app.MODE_KR:
            network_entries['wireless'] = wireless_entry

        self.write(
            tmpl.generate(network_entries=network_entries,
                          configuration_active=True,
                          widget_render=partial(widget_render, ldr)))
Exemple #12
0
    def post(self):
        _log.debug('configuration set: %s' , self.request)
        _log.debug('body: %s', self.request.body)

        # parse request
        arguments = parse_qs_bytes(self.request.body, keep_blank_values=False)
        _log.debug('arguments: %s', arguments)

        wired_config = {}
        wireless_config = {}

        def get_ip_config(prefix):
            if arguments.has_key(prefix + '_ipv4_method'):
                method = arguments[prefix + '_ipv4_method'][0].lower()
                if method not in ['dhcp', 'static']:
                    # incorrect method
                    # TODO: raise exception
                    _log.error('incorrect method: %s', method)

                ipv4_config = {
                    'method': method
                }

                static_method_keys = [prefix + '_ipv4_address',
                                      prefix + '_ipv4_netmask',
                                      prefix + '_ipv4_gateway']
                if method == 'static':
                    if all([arguments.has_key(k) for k in static_method_keys]) == False:
                        # missing confgiuration
                        # TODO: raise exception
                        _log.error('incorrect network configuration: %s', arguments)
                    else:
                        ipv4_config['address'] = arguments[prefix + '_ipv4_address'][0]
                        ipv4_config['netmask'] = arguments[prefix + '_ipv4_netmask'][0]
                        ipv4_config['gateway'] = arguments[prefix + '_ipv4_gateway'][0]
                return ipv4_config
            else:
                # TODO: raise exception
                _log.error('IPv4 method not specified in arguments: %s', arguments)
            return None

        wired_config['ipv4'] = get_ip_config('eth')
        wireless_config['ipv4'] = get_ip_config('wifi')

        def get_arg(arg):
            if arguments.has_key(arg):
                return arguments[arg][0]
            else:
                return None

        wireless_config['name'] = get_arg('wifi_ap_name')
        wireless_config['password'] = get_arg('wifi_psk_pass')

        net = network_provider()
        net_config = {
            'wired': [wired_config],
        }
        if self.app.mode == self.app.MODE_KR:
            net_config['wireless'] = [wireless_config]

        net.set_config(net_config)

        config = ConfigLoader()
        config.write()

        self.redirect('/?config_applied=1')
Exemple #13
0
    def __init__(self):
        super(DevControllerRestClient, self).__init__()

        config = ConfigLoader()
        self.rest_url = config.get_rest_url()
        LOG.debug("rest client created")