def main():
    service.setupLogger()

    logger = logging.getLogger(_LOGGER_NAME)

    try:
        args = parse_args()

        cfg_file = configfile.ConfigFile([
            config.VMCONSOLE_PROXY_HELPER_DEFAULTS,
            config.VMCONSOLE_PROXY_HELPER_VARS,
        ])

        if cfg_file.getboolean('DEBUG') or args.debug:
            logger.setLevel(logging.DEBUG)

        base_url = (
            # debug, emergency override
            os.getenv('OVIRT_VMCONSOLE_ENGINE_BASE_URL') or
            cfg_file.get('ENGINE_BASE_URL')
        )

        logger.debug('using engine base url: %s', base_url)

        enc = make_ticket_encoder(cfg_file)
        data = enc.encode(json.dumps(make_request(args)))
        req = urllib2.Request(
            urlparse.urljoin(base_url, 'services/vmconsole-proxy'),
            data=data,
            headers={
                'Content-Type': 'text/plain',
                'Content-Length': len(data),
            },
        )

        ca_certs = cfg_file.get('ENGINE_CA')
        if not ca_certs:
            logger.warn('Engine CA not configured, '
                        'connecting in insecure mode')
            ca_certs = None

        with urlopen(
            url=req,
            ca_certs=ca_certs,
            verify_host=cfg_file.getboolean('ENGINE_VERIFY_HOST')
        ) as res:
            if res.getcode() != _HTTP_STATUS_CODE_SUCCESS:
                raise RuntimeError(
                    'Engine call failed: code=%d' % res.getcode()
                )
            print(handle_response(res.read()))

    except Exception as ex:
        logger.error('Error: %s', ex)
        logger.debug('Exception', exc_info=True)
        return 1
    else:
        return 0
Exemple #2
0
                ],
                env=self._engineEnv,
                stopTime=self._config.getinteger(
                    'ENGINE_STOP_TIME'
                ),
                stopInterval=self._config.getinteger(
                    'ENGINE_STOP_INTERVAL'
                ),
            )

            raise self.TerminateException()

        except self.TerminateException:
            if os.path.exists(self._config.get('ENGINE_UP_MARK')):
                os.remove(self._config.get('ENGINE_UP_MARK'))

    def daemonCleanup(self):
        if self._tempDir:
            self._tempDir.destroy()
        if self._jbossRuntime:
            self._jbossRuntime.destroy()


if __name__ == '__main__':
    service.setupLogger()
    d = Daemon()
    d.run()


# vim: expandtab tabstop=4 shiftwidth=4