示例#1
0
 def _customization(self):
     if self.environment[
         osetupcons.RenameEnv.FQDN
     ] is None:
         osetuphostname.Hostname(
             plugin=self,
         ).getHostname(
             envkey=osetupcons.RenameEnv.FQDN,
             whichhost=_('New'),
             supply_default=False,
             prompttext=_('New fully qualified server name: '),
             validate_syntax=True,
             system=True,
             dns=True,
             local_non_loopback=self.environment[
                 osetupcons.ConfigEnv.FQDN_NON_LOOPBACK_VALIDATION
             ],
             reverse_dns=self.environment[
                 osetupcons.ConfigEnv.FQDN_REVERSE_VALIDATION
             ],
         )
     self.environment[
         osetupcons.ConfigEnv.FQDN
     ] = self.environment[
         osetupcons.RenameEnv.FQDN
     ]
     self.environment[
         oenginecons.ConfigEnv.ENGINE_FQDN
     ] = self.environment[
         osetupcons.RenameEnv.FQDN
     ]
示例#2
0
 def _customizationNetwork(self):
     osetuphostname.Hostname(
         plugin=self,
     ).getHostname(
         envkey=oenginecons.ConfigEnv.ENGINE_FQDN,
         whichhost=_('the engine'),
         supply_default=False,
         validate_syntax=True,
         system=True,
         dns=False,
         local_non_loopback=self.environment[
             osetupcons.ConfigEnv.FQDN_NON_LOOPBACK_VALIDATION
         ],
         reverse_dns=self.environment[
             osetupcons.ConfigEnv.FQDN_REVERSE_VALIDATION
         ],
     )
     self.environment[osetupcons.NetEnv.FIREWALLD_SERVICES].extend([
         {
             'name': 'ovirt-vmconsole-proxy',
             'directory': 'vmconsole-proxy'
         },
     ])
     self.environment[
         osetupcons.NetEnv.FIREWALLD_SUBST
     ].update({
         '@VMCONSOLE_PROXY_PORT@': self.environment[
             ovmpcons.ConfigEnv.VMCONSOLE_PROXY_PORT
         ],
     })
示例#3
0
 def _customization(self):
     osetuphostname.Hostname(plugin=self, ).getHostname(
         envkey=osetupcons.ConfigEnv.FQDN,
         whichhost=_('this'),
         supply_default=True,
         validate_syntax=True,
         system=True,
         dns=True,
         local_non_loopback=self.environment[
             osetupcons.ConfigEnv.FQDN_NON_LOOPBACK_VALIDATION],
         reverse_dns=self.environment[
             osetupcons.ConfigEnv.FQDN_REVERSE_VALIDATION],
     )
示例#4
0
    def _remote_engine_customization(self):
        self._enabled = True
        osetuphostname.Hostname(
            plugin=self,
        ).getHostname(
            envkey=oenginecons.ConfigEnv.ENGINE_FQDN,
            whichhost=_('the engine'),
            supply_default=False,
        )
        self._remote_engine = self.environment[
            osetupcons.CoreEnv.REMOTE_ENGINE
        ]
        self._remote_engine.configure(
            fqdn=self.environment[
                oenginecons.ConfigEnv.ENGINE_FQDN
            ],
        )

        # It's actually configured only at closeup, but postinstall is
        # written at misc, so set here, earlier.
        self.environment[odwhcons.ConfigEnv.REMOTE_ENGINE_CONFIGURED] = True
示例#5
0
 def _setup(self):
     self._hostname_helper = osetuphostname.Hostname(plugin=self)
示例#6
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:
            dbenv = {}
            for k in (
                    DEK.HOST,
                    DEK.PORT,
                    DEK.SECURED,
                    DEK.HOST_VALIDATION,
                    DEK.DATABASE,
                    DEK.USER,
                    DEK.PASSWORD,
            ):
                dbenv[self._dbenvkeys[k]] = _ind_env(self, k)

            def query_dbenv(what, note, tests=None, **kwargs):
                dialog.queryEnvKey(name='{qpref}{what}'.format(
                    qpref=queryprefix,
                    what=string.upper(what),
                ),
                                   dialog=self.dialog,
                                   logger=self.logger,
                                   env=dbenv,
                                   key=self._dbenvkeys[what],
                                   note=note.format(name=name, ),
                                   prompt=True,
                                   default=defaultdbenvkeys[what],
                                   tests=tests,
                                   **kwargs)

            query_dbenv(
                what=DEK.HOST,
                note=_('{name} database host [@DEFAULT@]: '),
                tests=({
                    'test':
                    osetuphostname.Hostname(
                        self._plugin, ).getHostnameTester(),
                }, ),
            )

            query_dbenv(
                what=DEK.PORT,
                note=_('{name} database port [@DEFAULT@]: '),
                tests=({
                    'test': osetuputil.getPortTester()
                }, ),
            )

            if dbenv[self._dbenvkeys[DEK.SECURED]] is None:
                dbenv[self._dbenvkeys[DEK.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 dbenv[self._dbenvkeys[DEK.SECURED]]:
                dbenv[self._dbenvkeys[DEK.HOST_VALIDATION]] = False

            if dbenv[self._dbenvkeys[DEK.HOST_VALIDATION]] is None:
                dbenv[self._dbenvkeys[
                    DEK.HOST_VALIDATION]] = 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'

            query_dbenv(
                what=DEK.DATABASE,
                note=_('{name} database name [@DEFAULT@]: '),
            )

            query_dbenv(
                what=DEK.USER,
                note=_('{name} database user [@DEFAULT@]: '),
            )

            query_dbenv(
                what=DEK.PASSWORD,
                note=_('{name} database password: '******'dbenv: %s', dbenv)
            if interactive:
                try:
                    self.tryDatabaseConnect(dbenv)
                    self._checkDbConf(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[
                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)
示例#7
0
    def _misc_deploy(self):
        import docker
        fqdn = self.environment[osetupcons.ConfigEnv.FQDN]

        envdict = {
            'ADMIN_USER_PASSWORD': odockerccons.Const.ADMIN_USER_PASSWORD,
            'ADMIN_TENANT_NAME': odockerccons.Const.ADMIN_TENANT_NAME,
            # TODO: use randomly generated passwords
            'DB_ROOT_PASSWORD': odockerccons.Const.MARIADB_ROOT_PASSWORD,
            'CINDER_DB_NAME': odockerccons.Const.CINDER_DB_NAME,
            'CINDER_DB_USER': odockerccons.Const.CINDER_DB_USER,
            'CINDER_DB_PASSWORD': odockerccons.Const.CINDER_DB_PASSWORD,
            'CINDER_KEYSTONE_USER': odockerccons.Const.CINDER_KEYSTONE_USER,
            'CINDER_ADMIN_PASSWORD': odockerccons.Const.CINDER_ADMIN_PASSWORD,
            'GLANCE_API_SERVICE_HOST': fqdn,
            'GLANCE_DB_NAME': odockerccons.Const.GLANCE_DB_NAME,
            'GLANCE_DB_PASSWORD': odockerccons.Const.GLANCE_DB_PASSWORD,
            'GLANCE_DB_USER': odockerccons.Const.GLANCE_DB_USER,
            'GLANCE_KEYSTONE_PASSWORD':
            odockerccons.Const.GLANCE_KEYSTONE_PASSWORD,
            'GLANCE_KEYSTONE_USER': odockerccons.Const.GLANCE_KEYSTONE_USER,
            'GLANCE_REGISTRY_SERVICE_HOST': fqdn,
            'KEYSTONE_ADMIN_PASSWORD':
            odockerccons.Const.KEYSTONE_ADMIN_PASSWORD,
            'KEYSTONE_ADMIN_SERVICE_HOST': fqdn,
            'KEYSTONE_ADMIN_SERVICE_PORT':
            odockerccons.Const.KEYSTONE_ADMIN_SERVICE_PORT,
            'KEYSTONE_ADMIN_TOKEN': odockerccons.Const.KEYSTONE_ADMIN_TOKEN,
            'KEYSTONE_AUTH_PROTOCOL':
            odockerccons.Const.KEYSTONE_AUTH_PROTOCOL,
            'KEYSTONE_DB_PASSWORD': odockerccons.Const.KEYSTONE_DB_PASSWORD,
            'KEYSTONE_PUBLIC_SERVICE_HOST': fqdn,
            'MARIADB_SERVICE_HOST': fqdn,
            'MARIADB_ROOT_PASSWORD': odockerccons.Const.MARIADB_ROOT_PASSWORD,
            'RABBITMQ_PASS': odockerccons.Const.RABBIT_PASSWORD,
            'RABBITMQ_SERVICE_HOST': fqdn,
            'RABBITMQ_USER': odockerccons.Const.RABBIT_USER,
            'RABBIT_PASSWORD': odockerccons.Const.RABBIT_PASSWORD,
            'RABBIT_USERID': odockerccons.Const.RABBIT_USER,
        }

        hostname = osetuphostname.Hostname(plugin=self)
        dnsresolved = hostname.isResolvedByDNS(fqdn)
        # TODO: check if we also need to force container DNS
        for cont in self._dimages:
            self.logger.info(_('Pulling {cname}').format(cname=cont['name']))
            for line in self._dcli.pull(cont['image'], stream=True):
                jline = json.loads(line)
                self.logger.debug(json.dumps(jline, indent=4))
                if 'error' in jline:
                    raise RuntimeError(
                        _("Unable to pull image {cname}: {message}").format(
                            cname=cont['image'],
                            message=jline['errorDetail']['message'],
                        ))
        for cont in self._dimages:
            self.logger.info(_('Creating {cname}').format(cname=cont['name']))
            try:
                container = self._dcli.create_container(
                    image=cont['image'],
                    name=cont['name'],
                    environment=envdict,
                )
            except docker.errors.APIError as ex:
                if ex.response.status_code == 404:
                    raise RuntimeError(
                        _('Unable to find image {image}: {explanation}'
                          ).format(image=cont['image'],
                                   explanation=ex.explanation))
                elif ex.response.status_code == 409:
                    raise RuntimeError(
                        _('Name conflict creating container {cname}: '
                          '{explanation}').format(cname=cont['name'],
                                                  explanation=ex.explanation))
                elif ex.response.status_code == 500:
                    raise RuntimeError(
                        _('docker server error creating container {cname}: '
                          '{explanation}').format(cname=cont['name'],
                                                  explanation=ex.explanation))
                else:
                    raise ex

            self.logger.info(_('Starting {cname}').format(cname=cont['name']))
            cid = container.get('Id')
            self.logger.debug('Container {cname}: {cid}'.format(
                cname=cont['name'],
                cid=cid,
            ))
            try:
                self._dcli.start(
                    container=cid,
                    restart_policy={"Name": "always"},
                    volumes_from=(
                        odockerccons.Const.C_NAME_MARIADBDATA if cont['name']
                        == odockerccons.Const.C_NAME_MARIADBAPP else None),
                    network_mode='host',
                    extra_hosts=({
                        fqdn:
                        hostname.getResolvedAddresses(fqdn).pop()
                    } if not dnsresolved else None))
            except docker.errors.APIError as ex:
                if ex.response.status_code == 404:
                    raise RuntimeError(
                        _('Unable to start container {cname}: {explanation}').
                        format(cname=cont['name'], explanation=ex.explanation))
                else:
                    raise ex

        dlist = [d['name'] for d in self._dimages]
        dlist.extend(self._already_deployed_by_me)
        self.environment[odockerccons.RemoveEnv.REMOVE_DCLIST] = ', '.join(
            set(dlist))
示例#8
0
 def _setup(self):
     self.command.detect('genisoimage')
     self._hostname_helper = osetuphostname.Hostname(plugin=self)
     self.command.detect('ping')
示例#9
0
 def _setup(self):
     self.command.detect('ssh-keygen')
     self._hostname_helper = osetuphostname.Hostname(plugin=self)
     self.command.detect('ping')