Esempio n. 1
0
    def _customizationNetwork(self):
        osetuphostname.Hostname(plugin=self).getHostname(
            envkey=ovmpcons.EngineConfigEnv.ENGINE_FQDN, whichhost=_("the engine"), supply_default=True
        )

        while self.environment[ovmpcons.ConfigEnv.VMCONSOLE_PROXY_PORT] is None:
            try:
                port = osetuputil.parsePort(
                    self.dialog.queryString(
                        name="VMCONSOLE_PROXY_HOST",
                        note=_("Engine vmconsole port [@DEFAULT@]: "),
                        prompt=True,
                        default=(ovmpcons.Defaults.DEFAULT_VMCONSOLE_PROXY_PORT),
                    )
                )
                self.environment[ovmpcons.ConfigEnv.VMCONSOLE_PROXY_PORT] = port
            except ValueError:
                self.logger.warning(_("Unable to parse the given port."))
Esempio n. 2
0
    def getCredentials(
        self,
        name,
        queryprefix,
        defaultdbenvkeys,
        show_create_msg=False,
        note=None,
        credsfile=None,
    ):
        interactive = None in (
            self.environment[self._dbenvkeys['host']],
            self.environment[self._dbenvkeys['port']],
            self.environment[self._dbenvkeys['database']],
            self.environment[self._dbenvkeys['user']],
            self.environment[self._dbenvkeys['password']],
        )

        if interactive:
            if note is None and credsfile:
                note = _(
                    "\nPlease provide the following credentials for the "
                    "{name} database.\nThey should be found on the {name} "
                    "server in '{credsfile}'.\n\n"
                ).format(
                    name=name,
                    credsfile=credsfile,
                )

            if note:
                self.dialog.note(text=note)

            if show_create_msg:
                self.dialog.note(
                    text=_(
                        "\n"
                        "ATTENTION\n"
                        "\n"
                        "Manual action required.\n"
                        "Please create database for ovirt-engine use. "
                        "Use the following commands as an example:\n"
                        "\n"
                        "create role {user} with login encrypted password "
                        "'{user}';\n"
                        "create database {database} owner {user}\n"
                        " template template0\n"
                        " encoding 'UTF8' lc_collate 'en_US.UTF-8'\n"
                        " lc_ctype 'en_US.UTF-8';\n"
                        "\n"
                        "Make sure that database can be accessed remotely.\n"
                        "\n"
                    ).format(
                        user=defaultdbenvkeys['user'],
                        database=defaultdbenvkeys['database'],
                    ),
                )

        connectionValid = False
        while not connectionValid:
            host = self.environment[self._dbenvkeys['host']]
            port = self.environment[self._dbenvkeys['port']]
            secured = self.environment[self._dbenvkeys['secured']]
            securedHostValidation = self.environment[
                self._dbenvkeys['hostValidation']
            ]
            db = self.environment[self._dbenvkeys['database']]
            user = self.environment[self._dbenvkeys['user']]
            password = self.environment[self._dbenvkeys['password']]

            if host is None:
                while True:
                    host = self.dialog.queryString(
                        name='{qpref}HOST'.format(qpref=queryprefix),
                        note=_(
                            '{name} database host [@DEFAULT@]: '
                        ).format(
                            name=name,
                        ),
                        prompt=True,
                        default=defaultdbenvkeys['host'],
                    )
                    try:
                        socket.getaddrinfo(host, None)
                        break  # do while missing in python
                    except socket.error as e:
                        self.logger.error(
                            _('Host is invalid: {error}').format(
                                error=e.strerror
                            )
                        )

            if port is None:
                while True:
                    try:
                        port = osetuputil.parsePort(
                            self.dialog.queryString(
                                name='{qpref}PORT'.format(qpref=queryprefix),
                                note=_(
                                    '{name} database port [@DEFAULT@]: '
                                ).format(
                                    name=name,
                                ),
                                prompt=True,
                                default=defaultdbenvkeys['port'],
                            )
                        )
                        break  # do while missing in python
                    except ValueError:
                        pass

            if secured is None:
                secured = dialog.queryBoolean(
                    dialog=self.dialog,
                    name='{qpref}SECURED'.format(qpref=queryprefix),
                    note=_(
                        '{name} database secured connection (@VALUES@) '
                        '[@DEFAULT@]: '
                    ).format(
                        name=name,
                    ),
                    prompt=True,
                    default=defaultdbenvkeys['secured'],
                )

            if not secured:
                securedHostValidation = False

            if securedHostValidation is None:
                securedHostValidation = dialog.queryBoolean(
                    dialog=self.dialog,
                    name='{qpref}SECURED_HOST_VALIDATION'.format(
                        qpref=queryprefix
                    ),
                    note=_(
                        '{name} database host name validation in secured '
                        'connection (@VALUES@) [@DEFAULT@]: '
                    ).format(
                        name=name,
                    ),
                    prompt=True,
                    default=True,
                ) == 'yes'

            if db is None:
                db = self.dialog.queryString(
                    name='{qpref}DATABASE'.format(qpref=queryprefix),
                    note=_(
                        '{name} database name [@DEFAULT@]: '
                    ).format(
                        name=name,
                    ),
                    prompt=True,
                    default=defaultdbenvkeys['database'],
                )

            if user is None:
                user = self.dialog.queryString(
                    name='{qpref}USER'.format(qpref=queryprefix),
                    note=_(
                        '{name} database user [@DEFAULT@]: '
                    ).format(
                        name=name,
                    ),
                    prompt=True,
                    default=defaultdbenvkeys['user'],
                )

            if password is None:
                password = self.dialog.queryString(
                    name='{qpref}PASSWORD'.format(qpref=queryprefix),
                    note=_(
                        '{name} database password: '******'host']: host,
                self._dbenvkeys['port']: port,
                self._dbenvkeys['secured']: secured,
                self._dbenvkeys['hostValidation']: securedHostValidation,
                self._dbenvkeys['user']: user,
                self._dbenvkeys['password']: password,
                self._dbenvkeys['database']: db,
            }

            if interactive:
                try:
                    self.tryDatabaseConnect(dbenv)
                    self._checkDbEncoding(environment=dbenv, name=name)
                    self.environment.update(dbenv)
                    connectionValid = True
                except RuntimeError as e:
                    self.logger.error(
                        _('Cannot connect to {name} database: {error}').format(
                            name=name,
                            error=e,
                        )
                    )
            else:
                # this is usally reached in provisioning
                # or if full ansewr file
                self.environment.update(dbenv)
                connectionValid = True

        try:
            self.environment[
                self._dbenvkeys['newDatabase']
            ] = self.isNewDatabase()
        except:
            self.logger.debug('database connection failed', exc_info=True)
Esempio n. 3
0
    def getCredentials(
        self,
        name,
        queryprefix,
        defaultdbenvkeys,
        show_create_msg=False,
        note=None,
        credsfile=None,
    ):
        interactive = None in (
            _ind_env(self, DEK.HOST),
            _ind_env(self, DEK.PORT),
            _ind_env(self, DEK.DATABASE),
            _ind_env(self, DEK.USER),
            _ind_env(self, DEK.PASSWORD),
        )

        if interactive:
            if note is None and credsfile:
                note = _(
                    "\nPlease provide the following credentials for the "
                    "{name} database.\nThey should be found on the {name} "
                    "server in '{credsfile}'.\n\n"
                ).format(
                    name=name,
                    credsfile=credsfile,
                )

            if note:
                self.dialog.note(text=note)

            if show_create_msg:
                self.dialog.note(
                    text=_(
                        "\n"
                        "ATTENTION\n"
                        "\n"
                        "Manual action required.\n"
                        "Please create database for ovirt-engine use. "
                        "Use the following commands as an example:\n"
                        "\n"
                        "create role {user} with login encrypted password "
                        "'{user}';\n"
                        "create database {database} owner {user}\n"
                        " template template0\n"
                        " encoding 'UTF8' lc_collate 'en_US.UTF-8'\n"
                        " lc_ctype 'en_US.UTF-8';\n"
                        "\n"
                        "Make sure that database can be accessed remotely.\n"
                        "\n"
                    ).format(
                        user=defaultdbenvkeys[DEK.USER],
                        database=defaultdbenvkeys[DEK.DATABASE],
                    ),
                )

        connectionValid = False
        while not connectionValid:
            host = _ind_env(self, DEK.HOST)
            port = _ind_env(self, DEK.PORT)
            secured = _ind_env(self, DEK.SECURED)
            securedHostValidation = _ind_env(self, DEK.HOST_VALIDATION)
            db = _ind_env(self, DEK.DATABASE)
            user = _ind_env(self, DEK.USER)
            password = _ind_env(self, DEK.PASSWORD)

            if host is None:
                while True:
                    host = self.dialog.queryString(
                        name='{qpref}HOST'.format(qpref=queryprefix),
                        note=_(
                            '{name} database host [@DEFAULT@]: '
                        ).format(
                            name=name,
                        ),
                        prompt=True,
                        default=defaultdbenvkeys[DEK.HOST],
                    )
                    try:
                        socket.getaddrinfo(host, None)
                        break  # do while missing in python
                    except socket.error as e:
                        self.logger.error(
                            _('Host is invalid: {error}').format(
                                error=e.strerror
                            )
                        )

            if port is None:
                while True:
                    try:
                        port = osetuputil.parsePort(
                            self.dialog.queryString(
                                name='{qpref}PORT'.format(qpref=queryprefix),
                                note=_(
                                    '{name} database port [@DEFAULT@]: '
                                ).format(
                                    name=name,
                                ),
                                prompt=True,
                                default=defaultdbenvkeys[DEK.PORT],
                            )
                        )
                        break  # do while missing in python
                    except ValueError:
                        pass

            if secured is None:
                secured = dialog.queryBoolean(
                    dialog=self.dialog,
                    name='{qpref}SECURED'.format(qpref=queryprefix),
                    note=_(
                        '{name} database secured connection (@VALUES@) '
                        '[@DEFAULT@]: '
                    ).format(
                        name=name,
                    ),
                    prompt=True,
                    default=defaultdbenvkeys[DEK.SECURED],
                )

            if not secured:
                securedHostValidation = False

            if securedHostValidation is None:
                securedHostValidation = dialog.queryBoolean(
                    dialog=self.dialog,
                    name='{qpref}SECURED_HOST_VALIDATION'.format(
                        qpref=queryprefix
                    ),
                    note=_(
                        '{name} database host name validation in secured '
                        'connection (@VALUES@) [@DEFAULT@]: '
                    ).format(
                        name=name,
                    ),
                    prompt=True,
                    default=True,
                ) == 'yes'

            if db is None:
                db = self.dialog.queryString(
                    name='{qpref}DATABASE'.format(qpref=queryprefix),
                    note=_(
                        '{name} database name [@DEFAULT@]: '
                    ).format(
                        name=name,
                    ),
                    prompt=True,
                    default=defaultdbenvkeys[DEK.DATABASE],
                )

            if user is None:
                user = self.dialog.queryString(
                    name='{qpref}USER'.format(qpref=queryprefix),
                    note=_(
                        '{name} database user [@DEFAULT@]: '
                    ).format(
                        name=name,
                    ),
                    prompt=True,
                    default=defaultdbenvkeys[DEK.USER],
                )

            if password is None:
                password = self.dialog.queryString(
                    name='{qpref}PASSWORD'.format(qpref=queryprefix),
                    note=_(
                        '{name} database password: '******'Cannot connect to {name} database: {error}').format(
                            name=name,
                            error=e,
                        )
                    )
            else:
                # this is usally reached in provisioning
                # or if full ansewr file
                self.environment.update(dbenv)
                connectionValid = True

        try:
            self.environment[
                self._dbenvkeys[DEK.NEW_DATABASE]
            ] = self.isNewDatabase()
        except:
            self.logger.debug('database connection failed', exc_info=True)

        if not _ind_env(self, DEK.NEW_DATABASE):
            self._checkDbConf(environment=dbenv, name=name)
Esempio n. 4
0
    def _customization(self):
        dbovirtutils = database.OvirtUtils(plugin=self)

        interactive = None in (
            self.environment[osetupcons.DBEnv.HOST],
            self.environment[osetupcons.DBEnv.PORT],
            self.environment[osetupcons.DBEnv.DATABASE],
            self.environment[osetupcons.DBEnv.USER],
            self.environment[osetupcons.DBEnv.PASSWORD],
        )

        if interactive:
            self.dialog.note(
                text=_(
                    "\n"
                    "ATTENTION\n"
                    "\n"
                    "Manual action required.\n"
                    "Please create database for ovirt-engine use. "
                    "Use the following commands as an example:\n"
                    "\n"
                    "create user engine password 'engine';\n"
                    "create database engine owner engine template template0\n"
                    "encoding 'UTF8' lc_collate 'en_US.UTF-8'\n"
                    "lc_ctype 'en_US.UTF-8';\n"
                    "\n"
                    "Make sure that database can be accessed remotely.\n"
                    "\n"
                ),
            )

        connectionValid = False
        while not connectionValid:
            host = self.environment[osetupcons.DBEnv.HOST]
            port = self.environment[osetupcons.DBEnv.PORT]
            secured = self.environment[osetupcons.DBEnv.SECURED]
            securedHostValidation = self.environment[
                osetupcons.DBEnv.SECURED_HOST_VALIDATION
            ]
            db = self.environment[osetupcons.DBEnv.DATABASE]
            user = self.environment[osetupcons.DBEnv.USER]
            password = self.environment[osetupcons.DBEnv.PASSWORD]

            if host is None:
                while True:
                    host = self.dialog.queryString(
                        name='OVESETUP_DB_HOST',
                        note=_('Database host [@DEFAULT@]: '),
                        prompt=True,
                        default=osetupcons.Defaults.DEFAULT_DB_HOST,
                    )
                    try:
                        socket.getaddrinfo(host, None)
                        break  # do while missing in python
                    except socket.error as e:
                        self.logger.error(
                            _('Host is invalid: {error}').format(
                                error=e.strerror
                            )
                        )

            if port is None:
                while True:
                    try:
                        port = osetuputil.parsePort(
                            self.dialog.queryString(
                                name='OVESETUP_DB_PORT',
                                note=_('Database port [@DEFAULT@]: '),
                                prompt=True,
                                default=osetupcons.Defaults.DEFAULT_DB_PORT,
                            )
                        )
                        break  # do while missing in python
                    except ValueError:
                        pass

            if secured is None:
                secured = dialog.queryBoolean(
                    dialog=self.dialog,
                    name='OVESETUP_DB_SECURED',
                    note=_(
                        'Database secured connection (@VALUES@) '
                        '[@DEFAULT@]: '
                    ),
                    prompt=True,
                    default=osetupcons.Defaults.DEFAULT_DB_SECURED,
                )

            if not secured:
                securedHostValidation = False

            if securedHostValidation is None:
                securedHostValidation = dialog.queryBoolean(
                    dialog=self.dialog,
                    name='OVESETUP_DB_SECURED_HOST_VALIDATION',
                    note=_(
                        'Validate host name in secured connection (@VALUES@) '
                        '[@DEFAULT@]: '
                    ),
                    prompt=True,
                    default=True,
                ) == 'yes'

            if db is None:
                db = self.dialog.queryString(
                    name='OVESETUP_DB_DATABASE',
                    note=_('Database name [@DEFAULT@]: '),
                    prompt=True,
                    default=osetupcons.Defaults.DEFAULT_DB_DATABASE,
                )

            if user is None:
                user = self.dialog.queryString(
                    name='OVESETUP_DB_USER',
                    note=_('Database user [@DEFAULT@]: '),
                    prompt=True,
                    default=osetupcons.Defaults.DEFAULT_DB_USER,
                )

            if password is None:
                password = self.dialog.queryString(
                    name='OVESETUP_DB_PASSWORD',
                    note=_('Database password: '******'Cannot connect to database: {error}').format(
                            error=e,
                        )
                    )
            else:
                # this is usally reached in provisioning
                # or if full ansewr file
                self.environment.update(dbenv)
                connectionValid = True

        try:
            self.environment[
                osetupcons.DBEnv.NEW_DATABASE
            ] = dbovirtutils.isNewDatabase()
        except:
            self.logger.debug('database connection failed', exc_info=True)
Esempio n. 5
0
    def _customization(self):
        dbovirtutils = database.OvirtUtils(plugin=self)

        interactive = None in (
            self.environment[osetupcons.DBEnv.HOST],
            self.environment[osetupcons.DBEnv.PORT],
            self.environment[osetupcons.DBEnv.DATABASE],
            self.environment[osetupcons.DBEnv.USER],
            self.environment[osetupcons.DBEnv.PASSWORD],
        )

        if interactive:
            self.dialog.note(text=_(
                "\n"
                "ATTENTION\n"
                "\n"
                "Manual action required.\n"
                "Please create database for ovirt-engine use. "
                "Use the following commands as an example:\n"
                "\n"
                "create user engine password 'engine';\n"
                "create database engine owner engine template template0\n"
                "encoding 'UTF8' lc_collate 'en_US.UTF-8'\n"
                "lc_ctype 'en_US.UTF-8';\n"
                "\n"
                "Make sure that database can be accessed remotely.\n"
                "\n"), )
        else:
            self.dialog.note(text=_('Using existing credentials'), )

        connectionValid = False
        while not connectionValid:
            host = self.environment[osetupcons.DBEnv.HOST]
            port = self.environment[osetupcons.DBEnv.PORT]
            secured = self.environment[osetupcons.DBEnv.SECURED]
            securedHostValidation = self.environment[
                osetupcons.DBEnv.SECURED_HOST_VALIDATION]
            db = self.environment[osetupcons.DBEnv.DATABASE]
            user = self.environment[osetupcons.DBEnv.USER]
            password = self.environment[osetupcons.DBEnv.PASSWORD]

            if host is None:
                while True:
                    host = self.dialog.queryString(
                        name='OVESETUP_DB_HOST',
                        note=_('Database host [@DEFAULT@]: '),
                        prompt=True,
                        default=osetupcons.Defaults.DEFAULT_DB_HOST,
                    )
                    try:
                        socket.getaddrinfo(host, None)
                        break  # do while missing in python
                    except socket.error as e:
                        self.logger.error(
                            _('Host is invalid: {error}').format(
                                error=e.strerror))

            if port is None:
                while True:
                    try:
                        port = osetuputil.parsePort(
                            self.dialog.queryString(
                                name='OVESETUP_DB_PORT',
                                note=_('Database port [@DEFAULT@]: '),
                                prompt=True,
                                default=osetupcons.Defaults.DEFAULT_DB_PORT,
                            ))
                        break  # do while missing in python
                    except ValueError:
                        pass

            if secured is None:
                secured = dialog.queryBoolean(
                    dialog=self.dialog,
                    name='OVESETUP_DB_SECURED',
                    note=_('Database secured connection (@VALUES@) '
                           '[@DEFAULT@]: '),
                    prompt=True,
                    default=osetupcons.Defaults.DEFAULT_DB_SECURED,
                )

            if not secured:
                securedHostValidation = False

            if securedHostValidation is None:
                securedHostValidation = dialog.queryBoolean(
                    dialog=self.dialog,
                    name='OVESETUP_DB_SECURED_HOST_VALIDATION',
                    note=_(
                        'Validate host name in secured connection (@VALUES@) '
                        '[@DEFAULT@]: '),
                    prompt=True,
                    default=True,
                ) == 'yes'

            if db is None:
                db = self.dialog.queryString(
                    name='OVESETUP_DB_DATABASE',
                    note=_('Database name [@DEFAULT@]: '),
                    prompt=True,
                    default=osetupcons.Defaults.DEFAULT_DB_DATABASE,
                )

            if user is None:
                user = self.dialog.queryString(
                    name='OVESETUP_DB_USER',
                    note=_('Database user [@DEFAULT@]: '),
                    prompt=True,
                    default=osetupcons.Defaults.DEFAULT_DB_USER,
                )

            if password is None:
                password = self.dialog.queryString(
                    name='OVESETUP_DB_PASSWORD',
                    note=_('Database password: '******'Cannot connect to database: {error}').format(
                            error=e, ))
            else:
                # this is usally reached in provisioning
                # or if full ansewr file
                self.environment.update(dbenv)
                connectionValid = True

        try:
            self.environment[
                osetupcons.DBEnv.NEW_DATABASE] = dbovirtutils.isNewDatabase()
        except:
            self.logger.debug('database connection failed', exc_info=True)