Ejemplo n.º 1
0
 def _boot_from_install_media(self):
     # Need to be done after firewall closeup for allowing the user to
     # connect from remote.
     os_installed = False
     self._create_vm()
     while not os_installed:
         try:
             os_installed = check_liveliness.manualSetupDispatcher(
                 self,
                 check_liveliness.MSD_OS_INSTALLED,
             )
         except socket.error as e:
             self.logger.debug(
                 'Error talking with VDSM (%s), reconnecting.' % str(e),
                 exc_info=True)
             cli = vdscli.connect(
                 timeout=ohostedcons.Const.VDSCLI_SSL_TIMEOUT)
             self.environment[ohostedcons.VDSMEnv.VDS_CLI] = cli
Ejemplo n.º 2
0
 def _boot_from_install_media(self):
     # Need to be done after firewall closeup for allowing the user to
     # connect from remote.
     os_installed = False
     self._create_vm()
     while not os_installed:
         try:
             os_installed = check_liveliness.manualSetupDispatcher(
                 self,
                 check_liveliness.MSD_OS_INSTALLED,
             )
         except socket.error as e:
             self.logger.debug(
                 'Error talking with VDSM (%s), reconnecting.' % str(e),
                 exc_info=True
             )
             cli = vdscli.connect(
                 timeout=ohostedcons.Const.VDSCLI_SSL_TIMEOUT
             )
             self.environment[ohostedcons.VDSMEnv.VDS_CLI] = cli
Ejemplo n.º 3
0
 def _boot_from_install_media(self):
     os_installed = False
     self._create_vm()
     while not os_installed:
         try:
             os_installed = check_liveliness.manualSetupDispatcher(
                 self,
                 check_liveliness.MSD_OS_INSTALLED,
             )
         except socket.error as e:
             self.logger.debug(
                 'Error talking with VDSM (%s), reconnecting.' % str(e),
                 exc_info=True
             )
             self.environment[
                 ohostedcons.VDSMEnv.VDS_CLI
             ] = ohautil.connect_vdsm_json_rpc(
                 logger=self.logger,
                 timeout=ohostedcons.Const.VDSCLI_SSL_TIMEOUT,
             )
Ejemplo n.º 4
0
    def _closeup(self):
        # TODO: refactor into shorter and simpler functions
        self._getSSH()
        self._configureHostDeploy()
        cluster_name = None
        default_cluster_name = 'Default'
        engine_api = engineapi.get_engine_api(self)
        added_to_cluster = False
        while not added_to_cluster:
            try:
                cluster_name = self.environment[
                    ohostedcons.EngineEnv.HOST_CLUSTER_NAME]
                if not self.environment[ohostedcons.EngineEnv.APP_HOST_NAME]:
                    self.environment[ohostedcons.EngineEnv.
                                     APP_HOST_NAME] = socket.gethostname()
                self.logger.debug(
                    "Getting the list of available clusters via engine's APIs")
                if cluster_name is not None:
                    if cluster_name not in [
                            c.get_name() for c in engine_api.clusters.list()
                    ]:
                        raise RuntimeError(
                            _('Specified cluster does not exist: {cluster}').
                            format(cluster=cluster_name, ))
                else:
                    cluster_l = [
                        c.get_name() for c in engine_api.clusters.list()
                    ]
                    cluster_name = (default_cluster_name
                                    if default_cluster_name in cluster_l else
                                    cluster_l[0])
                    if len(cluster_l) > 1:
                        cluster_name = self.dialog.queryString(
                            name='cluster_name',
                            note=_('Enter the name of the cluster to which '
                                   'you want to add the host (@VALUES@) '
                                   '[@DEFAULT@]: '),
                            prompt=True,
                            default=cluster_name,
                            validValues=cluster_l,
                        )
                    self.environment[
                        ohostedcons.EngineEnv.HOST_CLUSTER_NAME] = cluster_name
                cluster = engine_api.clusters.get(cluster_name)

                conn = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
                caps = vds_info.capabilities(conn)
                bridge_port = self.environment[
                    ohostedcons.NetworkEnv.BRIDGE_IF]
                if bridge_port in caps['vlans']:
                    self.logger.debug(
                        "Updating engine's management network to be vlanned")
                    vlan_id = caps['vlans'][bridge_port]['vlanid']
                    self.logger.debug(
                        "Getting engine's management network via engine's APIs"
                    )
                    cluster_mgmt_network = cluster.networks.get(
                        name=self.environment[
                            ohostedcons.NetworkEnv.BRIDGE_NAME])
                    mgmt_network_id = cluster_mgmt_network.get_id()
                    mgmt_network = engine_api.networks.get(id=mgmt_network_id)
                    mgmt_network.set_vlan(
                        self._ovirtsdk_xml.params.VLAN(id=vlan_id))
                    mgmt_network.update()
                    self._wait_network_vlan_ready(engine_api, mgmt_network_id,
                                                  vlan_id)

                self.logger.debug('Adding the host to the cluster')

                engine_api.hosts.add(
                    self._ovirtsdk_xml.params.Host(
                        name=self.environment[
                            ohostedcons.EngineEnv.APP_HOST_NAME],
                        # Note that the below is required for compatibility
                        # with vdsm-generated pki. See bz 1178535.
                        address=self.environment[
                            ohostedcons.NetworkEnv.HOST_NAME],
                        cluster=cluster,
                        ssh=self._ovirtsdk_xml.params.SSH(
                            authentication_method='publickey',
                            port=self.environment[
                                ohostedcons.NetworkEnv.SSHD_PORT],
                        ),
                        override_iptables=self.environment[
                            otopicons.NetEnv.IPTABLES_ENABLE],
                    ))
                added_to_cluster = True
            except ovirtsdk.infrastructure.errors.RequestError as e:
                self.logger.debug(
                    'Cannot add the host to cluster {cluster}'.format(
                        cluster=cluster_name, ),
                    exc_info=True,
                )
                self.logger.error(
                    _('Cannot automatically add the host '
                      'to cluster {cluster}:\n{details}\n').format(
                          cluster=cluster_name, details=e.detail))
                while not check_liveliness.manualSetupDispatcher(
                        self, check_liveliness.MSD_FURTHER_ACTIONS,
                        self.environment[
                            ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN]):
                    pass

        up = self._wait_host_ready(
            engine_api, self.environment[ohostedcons.EngineEnv.APP_HOST_NAME])
        # TODO: host-deploy restarted vdscli so we need to
        # connect again
        if not up:
            self.logger.error(
                _('Unable to add {host} to the manager').format(
                    host=self.environment[
                        ohostedcons.EngineEnv.APP_HOST_NAME], ))
        else:
            # This works only if the host is up.
            self.logger.debug('Setting CPU for the cluster')
            try:
                cluster, cpu = self._wait_cluster_cpu_ready(
                    engine_api, cluster_name)
                self.logger.debug(cpu.__dict__)
                cpu.set_id(self.environment[ohostedcons.VDSMEnv.ENGINE_CPU])
                cluster.set_cpu(cpu)
                cluster.update()
            except ovirtsdk.infrastructure.errors.RequestError as e:
                self.logger.debug(
                    'Cannot set CPU level of cluster {cluster}'.format(
                        cluster=cluster_name, ),
                    exc_info=True,
                )
                self.logger.error(
                    _('Cannot automatically set CPU level '
                      'of cluster {cluster}:\n{details}\n').format(
                          cluster=cluster_name, details=e.detail))
        engine_api.disconnect()
Ejemplo n.º 5
0
    def _closeup(self):
        # TODO: refactor into shorter and simpler functions
        self._getCA()
        self._getSSH()
        cluster_name = None
        default_cluster_name = 'Default'
        valid = False
        fqdn = self.environment[
            ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN]
        while not valid:
            try:
                self.logger.info(_('Connecting to the Engine'))
                insecure = False
                if self.environment[ohostedcons.EngineEnv.INSECURE_SSL]:
                    insecure = True
                engine_api = self._ovirtsdk_api.API(
                    url='https://{fqdn}/ovirt-engine/api'.format(fqdn=fqdn, ),
                    username='******',
                    password=self.environment[
                        ohostedcons.EngineEnv.ADMIN_PASSWORD],
                    ca_file=self.environment[
                        ohostedcons.EngineEnv.TEMPORARY_CERT_FILE],
                    insecure=insecure,
                )
                engine_api.clusters.list()
                valid = True
            except ovirtsdk.infrastructure.errors.RequestError as e:
                if e.status == 401:
                    if self._interactive_admin_pwd:
                        self.logger.error(
                            _('The engine API didn'
                              't accepted '
                              'the administrator password you provided\n'
                              'Please enter it again to retry.'))
                        self.environment[
                            ohostedcons.EngineEnv.
                            ADMIN_PASSWORD] = self.dialog.queryString(
                                name='ENGINE_ADMIN_PASSWORD',
                                note=_('Enter '
                                       'admin@internal'
                                       ' user password that '
                                       'will be used for accessing '
                                       'the Administrator Portal: '),
                                prompt=True,
                                hidden=True,
                            )
                    else:
                        raise RuntimeError(
                            _('The engine API didn'
                              't accepted '
                              'the administrator password you provided\n'))
                else:
                    self.logger.error(
                        _('Cannot connect to engine APIs on {fqdn}:\n'
                          '{details}\n').format(
                              fqdn=fqdn,
                              details=e.detail,
                          ))
                    raise RuntimeError(
                        _('Cannot connect to engine APIs on {fqdn}').format(
                            fqdn=fqdn, ))

        added_to_cluster = False
        while not added_to_cluster:
            try:
                cluster_name = self.environment[
                    ohostedcons.EngineEnv.HOST_CLUSTER_NAME]
                self.logger.debug(
                    "Getting the list of available clusters via engine's APIs")
                if cluster_name is not None:
                    if cluster_name not in [
                            c.get_name() for c in engine_api.clusters.list()
                    ]:
                        raise RuntimeError(
                            _('Specified cluster does not exist: {cluster}').
                            format(cluster=cluster_name, ))
                else:
                    cluster_l = [
                        c.get_name() for c in engine_api.clusters.list()
                    ]
                    cluster_name = (default_cluster_name
                                    if default_cluster_name in cluster_l else
                                    cluster_l[0])
                    cluster_name = self.dialog.queryString(
                        name='cluster_name',
                        note=_('Enter the name of the cluster to which '
                               'you want to add the host (@VALUES@) '
                               '[@DEFAULT@]: '),
                        prompt=True,
                        default=cluster_name,
                        validValues=cluster_l,
                    )
                    self.environment[
                        ohostedcons.EngineEnv.HOST_CLUSTER_NAME] = cluster_name
                cluster = engine_api.clusters.get(cluster_name)

                conn = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
                net_info = netinfo.NetInfo(vds_info.capabilities(conn))
                bridge_port = self.environment[
                    ohostedcons.NetworkEnv.BRIDGE_IF]
                if bridge_port in net_info.vlans:
                    self.logger.debug(
                        "Updating engine's management network to be vlanned")
                    vlan_id = net_info.vlans[bridge_port]['vlanid']
                    self.logger.debug(
                        "Getting engine's management network via engine's APIs"
                    )
                    mgmt_network = cluster.networks.get(name=self.environment[
                        ohostedcons.NetworkEnv.BRIDGE_NAME])
                    mgmt_network.set_vlan(
                        self._ovirtsdk_xml.params.VLAN(id=vlan_id))
                    mgmt_network.update()

                # Configuring the cluster for Hyper Converged support if
                # enabled
                if self.environment[
                        ohostedcons.StorageEnv.GLUSTER_PROVISIONING_ENABLED]:
                    cluster.set_gluster_service(True)
                    cluster.update()
                    cluster = engine_api.clusters.get(cluster_name)

                self.logger.debug('Adding the host to the cluster')

                engine_api.hosts.add(
                    self._ovirtsdk_xml.params.Host(
                        name=self.environment[
                            ohostedcons.EngineEnv.APP_HOST_NAME],
                        # Note that the below is required for compatibility
                        # with vdsm-generated pki. See bz 1178535.
                        # TODO: Make it configurable like engine fqdn.
                        address=socket.gethostname(),
                        reboot_after_installation=False,
                        cluster=cluster,
                        ssh=self._ovirtsdk_xml.params.SSH(
                            authentication_method='publickey',
                            port=self.environment[
                                ohostedcons.NetworkEnv.SSHD_PORT],
                        ),
                        override_iptables=self.environment[
                            otopicons.NetEnv.IPTABLES_ENABLE],
                    ))
                added_to_cluster = True
            except ovirtsdk.infrastructure.errors.RequestError as e:
                self.logger.debug(
                    'Cannot add the host to cluster {cluster}'.format(
                        cluster=cluster_name, ),
                    exc_info=True,
                )
                self.logger.error(
                    _('Cannot automatically add the host '
                      'to cluster {cluster}:\n{details}\n').format(
                          cluster=cluster_name, details=e.detail))
                while not check_liveliness.manualSetupDispatcher(
                        self, check_liveliness.MSD_FURTHER_ACTIONS, fqdn):
                    pass

        up = self._wait_host_ready(
            engine_api, self.environment[ohostedcons.EngineEnv.APP_HOST_NAME])
        # TODO: host-deploy restarted vdscli so we need to
        # connect again
        if not up:
            self.logger.error(
                _('Unable to add {host} to the manager').format(
                    host=self.environment[
                        ohostedcons.EngineEnv.APP_HOST_NAME], ))
        else:
            # This works only if the host is up.
            self.logger.debug('Setting CPU for the cluster')
            try:
                cluster, cpu = self._wait_cluster_cpu_ready(
                    engine_api, cluster_name)
                self.logger.debug(cpu.__dict__)
                cpu.set_id(self.environment[ohostedcons.VDSMEnv.ENGINE_CPU])
                cluster.set_cpu(cpu)
                cluster.update()
            except ovirtsdk.infrastructure.errors.RequestError as e:
                self.logger.debug(
                    'Cannot set CPU level of cluster {cluster}'.format(
                        cluster=cluster_name, ),
                    exc_info=True,
                )
                self.logger.error(
                    _('Cannot automatically set CPU level '
                      'of cluster {cluster}:\n{details}\n').format(
                          cluster=cluster_name, details=e.detail))
        engine_api.disconnect()
Ejemplo n.º 6
0
    def _closeup(self):
        esexecuting = self.environment[
            ohostedcons.CloudInit.EXECUTE_ESETUP
        ]
        fqdn = self.environment[
            ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN
        ]
        live_checker = check_liveliness.LivelinessChecker()
        # manual engine setup execution
        if not esexecuting:
            self.dialog.note(
                _('Please install and setup the engine in the VM.')
            )
            self.dialog.note(
                _(
                    'You may also be interested in '
                    'installing ovirt-guest-agent-common package '
                    'in the VM.'
                )
            )
            while not check_liveliness.manualSetupDispatcher(
                self,
                check_liveliness.MSD_ENGINE_INSTALLED,
                fqdn
            ):
                pass

        # automated engine setup execution on the appliance
        else:
            spath = (
                ohostedcons.Const.OVIRT_HE_CHANNEL_PATH +
                self.environment[
                    ohostedcons.VMEnv.VM_UUID
                ] + '.' +
                ohostedcons.Const.OVIRT_HE_CHANNEL_NAME
            )
            self.logger.debug(
                'Connecting to the appliance on {spath}'.format(spath=spath)
            )
            self._appliance_connect(spath)
            completed = False
            TIMEOUT = 5
            nTimeout5 = int(math.ceil(
                float(
                    self.environment[
                        ohostedcons.EngineEnv.ENGINE_SETUP_TIMEOUT
                    ]
                ) / TIMEOUT
            ))

            self.logger.info(_('Running engine-setup on the appliance'))
            rtimeouts = 0
            while not completed:
                line, timeout = self._appliance_readline_nb(TIMEOUT)
                if line:
                    self.dialog.note('|- ' + line + '\n')
                if timeout:
                    rtimeouts += 1
                else:
                    rtimeouts = 0
                if rtimeouts >= nTimeout5:
                    self.logger.error(
                        'Engine setup got stuck on the appliance'
                    )
                    raise RuntimeError(
                        _(
                            'Engine setup is stalled on the appliance '
                            'since {since} seconds ago.\n'
                            'Please check its log on the appliance.\n'
                        ).format(since=TIMEOUT*nTimeout5)
                    )
                if ohostedcons.Const.E_RESTORE_SUCCESS_STRING in line:
                    self.logger.info(
                        'Engine backup successfully restored'
                    )
                elif ohostedcons.Const.E_RESTORE_FAIL_STRING in line:
                    self.logger.error(
                        'Engine backup restore failed on the appliance'
                    )
                    raise RuntimeError(
                        _(
                            'engine-backup failed restoring the engine backup '
                            'on the appliance\n'
                            'Please check its log on the appliance.\n'
                        )
                    )
                elif ohostedcons.Const.E_SETUP_SUCCESS_STRING in line:
                    completed = True
                elif ohostedcons.Const.E_SETUP_FAIL_STRING in line:
                    self.logger.error(
                        'Engine setup failed on the appliance'
                    )
                    raise RuntimeError(
                        _(
                            'Engine setup failed on the appliance\n'
                            'Please check its log on the appliance.\n'
                        ).format(since=TIMEOUT*nTimeout5)
                    )
                # TODO: prefer machine dialog for more robust interaction
            self.logger.debug('Engine-setup successfully completed ')
            self.logger.info(_('Engine-setup successfully completed '))
            self._appliance_disconnect()
            cengineup = 0
            waitEngineUP = True
            while waitEngineUP:
                if live_checker.isEngineUp(fqdn):
                    waitEngineUP = False
                else:
                    cengineup += 1
                    if cengineup >= 20:
                        self.logger.error(_('Engine is still not reachable'))
                        raise RuntimeError(_('Engine is still not reachable'))
                    self.logger.info(
                        _('Engine is still not reachable, waiting...')
                    )
                    time.sleep(15)
    def _closeup(self):
        # TODO: refactor into shorter and simpler functions
        self._getCA()
        self._getSSH()
        cluster_name = None
        default_cluster_name = 'Default'
        valid = False
        fqdn = self.environment[
            ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN
        ]
        while not valid:
            try:
                self.logger.info(_('Connecting to the Engine'))
                insecure = False
                if self.environment[
                    ohostedcons.EngineEnv.INSECURE_SSL
                ]:
                    insecure = True
                engine_api = self._ovirtsdk_api.API(
                    url='https://{fqdn}/ovirt-engine/api'.format(
                        fqdn=fqdn,
                    ),
                    username='******',
                    password=self.environment[
                        ohostedcons.EngineEnv.ADMIN_PASSWORD
                    ],
                    ca_file=self.environment[
                        ohostedcons.EngineEnv.TEMPORARY_CERT_FILE
                    ],
                    insecure=insecure,
                )
                engine_api.clusters.list()
                valid = True
            except ovirtsdk.infrastructure.errors.RequestError as e:
                if e.status == 401:
                    if self._interactive_admin_pwd:
                        self.logger.error(
                            _(
                                'The engine API didn''t accepted '
                                'the administrator password you provided\n'
                                'Please enter it again to retry.'
                            )
                        )
                        self.environment[
                            ohostedcons.EngineEnv.ADMIN_PASSWORD
                        ] = self.dialog.queryString(
                            name='ENGINE_ADMIN_PASSWORD',
                            note=_(
                                'Enter ''admin@internal'' user password that '
                                'will be used for accessing '
                                'the Administrator Portal: '
                            ),
                            prompt=True,
                            hidden=True,
                        )
                    else:
                        raise RuntimeError(
                            _(
                                'The engine API didn''t accepted '
                                'the administrator password you provided\n'
                            )
                        )
                else:
                    self.logger.error(
                        _(
                            'Cannot connect to engine APIs on {fqdn}:\n'
                            '{details}\n'
                        ).format(
                            fqdn=fqdn,
                            details=e.detail,
                        )
                    )
                    raise RuntimeError(
                        _(
                            'Cannot connect to engine APIs on {fqdn}'
                        ).format(
                            fqdn=fqdn,
                        )
                    )

        added_to_cluster = False
        while not added_to_cluster:
            try:
                cluster_name = self.environment[
                    ohostedcons.EngineEnv.HOST_CLUSTER_NAME
                ]
                self.logger.debug(
                    "Getting the list of available clusters via engine's APIs"
                )
                if cluster_name is not None:
                    if cluster_name not in [
                        c.get_name()
                        for c in engine_api.clusters.list()
                    ]:
                        raise RuntimeError(
                            _(
                                'Specified cluster does not exist: {cluster}'
                            ).format(
                                cluster=cluster_name,
                            )
                        )
                else:
                    cluster_l = [
                        c.get_name()
                        for c in engine_api.clusters.list()
                    ]
                    cluster_name = (
                        default_cluster_name if default_cluster_name in
                        cluster_l else cluster_l[0]
                    )
                    cluster_name = self.dialog.queryString(
                        name='cluster_name',
                        note=_(
                            'Enter the name of the cluster to which '
                            'you want to add the host (@VALUES@) '
                            '[@DEFAULT@]: '
                        ),
                        prompt=True,
                        default=cluster_name,
                        validValues=cluster_l,
                    )
                    self.environment[
                        ohostedcons.EngineEnv.HOST_CLUSTER_NAME
                    ] = cluster_name
                cluster = engine_api.clusters.get(cluster_name)

                conn = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
                net_info = netinfo.NetInfo(vds_info.capabilities(conn))
                bridge_port = self.environment[
                    ohostedcons.NetworkEnv.BRIDGE_IF
                ]
                if bridge_port in net_info.vlans:
                    self.logger.debug(
                        "Updating engine's management network to be vlanned"
                    )
                    vlan_id = net_info.vlans[bridge_port]['vlanid']
                    self.logger.debug(
                        "Getting engine's management network via engine's APIs"
                    )
                    mgmt_network = cluster.networks.get(
                        name=self.environment[
                            ohostedcons.NetworkEnv.BRIDGE_NAME]
                    )
                    mgmt_network.set_vlan(
                        self._ovirtsdk_xml.params.VLAN(id=vlan_id)
                    )
                    mgmt_network.update()

                # Configuring the cluster for Hyper Converged support if
                # enabled
                if self.environment[
                    ohostedcons.StorageEnv.GLUSTER_PROVISIONING_ENABLED
                ]:
                    cluster.set_gluster_service(True)
                    cluster.update()
                    cluster = engine_api.clusters.get(cluster_name)

                self.logger.debug('Adding the host to the cluster')

                engine_api.hosts.add(
                    self._ovirtsdk_xml.params.Host(
                        name=self.environment[
                            ohostedcons.EngineEnv.APP_HOST_NAME
                        ],
                        # Note that the below is required for compatibility
                        # with vdsm-generated pki. See bz 1178535.
                        # TODO: Make it configurable like engine fqdn.
                        address=socket.gethostname(),
                        reboot_after_installation=False,
                        cluster=cluster,
                        ssh=self._ovirtsdk_xml.params.SSH(
                            authentication_method='publickey',
                            port=self.environment[
                                ohostedcons.NetworkEnv.SSHD_PORT
                            ],
                        ),
                        override_iptables=self.environment[
                            otopicons.NetEnv.IPTABLES_ENABLE
                        ],
                    )
                )
                added_to_cluster = True
            except ovirtsdk.infrastructure.errors.RequestError as e:
                self.logger.debug(
                    'Cannot add the host to cluster {cluster}'.format(
                        cluster=cluster_name,
                    ),
                    exc_info=True,
                )
                self.logger.error(
                    _(
                        'Cannot automatically add the host '
                        'to cluster {cluster}:\n{details}\n'
                    ).format(
                        cluster=cluster_name,
                        details=e.detail
                    )
                )
                while not check_liveliness.manualSetupDispatcher(
                    self,
                    check_liveliness.MSD_FURTHER_ACTIONS,
                    fqdn
                ):
                    pass

        up = self._wait_host_ready(
            engine_api,
            self.environment[ohostedcons.EngineEnv.APP_HOST_NAME]
        )
        # TODO: host-deploy restarted vdscli so we need to
        # connect again
        if not up:
            self.logger.error(
                _(
                    'Unable to add {host} to the manager'
                ).format(
                    host=self.environment[
                        ohostedcons.EngineEnv.APP_HOST_NAME
                    ],
                )
            )
        else:
            # This works only if the host is up.
            self.logger.debug('Setting CPU for the cluster')
            try:
                cluster, cpu = self._wait_cluster_cpu_ready(
                    engine_api,
                    cluster_name
                )
                self.logger.debug(cpu.__dict__)
                cpu.set_id(
                    self.environment[ohostedcons.VDSMEnv.ENGINE_CPU]
                )
                cluster.set_cpu(cpu)
                cluster.update()
            except ovirtsdk.infrastructure.errors.RequestError as e:
                self.logger.debug(
                    'Cannot set CPU level of cluster {cluster}'.format(
                        cluster=cluster_name,
                    ),
                    exc_info=True,
                )
                self.logger.error(
                    _(
                        'Cannot automatically set CPU level '
                        'of cluster {cluster}:\n{details}\n'
                    ).format(
                        cluster=cluster_name,
                        details=e.detail
                    )
                )
        engine_api.disconnect()
Ejemplo n.º 8
0
    def _closeup(self):
        # TODO: refactor into shorter and simpler functions
        self._getSSH()
        self._configureHostDeploy()
        cluster_name = None
        default_cluster_name = 'Default'
        engine_api = engineapi.get_engine_api(self)
        added_to_cluster = False
        while not added_to_cluster:
            try:
                cluster_name = self.environment[
                    ohostedcons.EngineEnv.HOST_CLUSTER_NAME
                ]
                self.logger.debug(
                    "Getting the list of available clusters via engine's APIs"
                )
                if cluster_name is not None:
                    if cluster_name not in [
                        c.get_name()
                        for c in engine_api.clusters.list()
                    ]:
                        raise RuntimeError(
                            _(
                                'Specified cluster does not exist: {cluster}'
                            ).format(
                                cluster=cluster_name,
                            )
                        )
                else:
                    cluster_l = [
                        c.get_name()
                        for c in engine_api.clusters.list()
                    ]
                    cluster_name = (
                        default_cluster_name if default_cluster_name in
                        cluster_l else cluster_l[0]
                    )
                    if len(cluster_l) > 1:
                        cluster_name = self.dialog.queryString(
                            name='cluster_name',
                            note=_(
                                'Enter the name of the cluster to which '
                                'you want to add the host (@VALUES@) '
                                '[@DEFAULT@]: '
                            ),
                            prompt=True,
                            default=cluster_name,
                            validValues=cluster_l,
                        )
                    self.environment[
                        ohostedcons.EngineEnv.HOST_CLUSTER_NAME
                    ] = cluster_name
                cluster = engine_api.clusters.get(cluster_name)

                conn = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
                net_info = CachingNetInfo(vds_info.capabilities(conn))
                bridge_port = self.environment[
                    ohostedcons.NetworkEnv.BRIDGE_IF
                ]
                if bridge_port in net_info.vlans:
                    self.logger.debug(
                        "Updating engine's management network to be vlanned"
                    )
                    vlan_id = net_info.vlans[bridge_port]['vlanid']
                    self.logger.debug(
                        "Getting engine's management network via engine's APIs"
                    )
                    cluster_mgmt_network = cluster.networks.get(
                        name=self.environment[
                            ohostedcons.NetworkEnv.BRIDGE_NAME]
                    )
                    mgmt_network_id = cluster_mgmt_network.get_id()
                    mgmt_network = engine_api.networks.get(
                        id=mgmt_network_id
                    )
                    mgmt_network.set_vlan(
                        self._ovirtsdk_xml.params.VLAN(id=vlan_id)
                    )
                    mgmt_network.update()
                    self._wait_network_vlan_ready(
                        engine_api,
                        mgmt_network_id,
                        vlan_id
                    )

                self.logger.debug('Adding the host to the cluster')

                engine_api.hosts.add(
                    self._ovirtsdk_xml.params.Host(
                        name=self.environment[
                            ohostedcons.EngineEnv.APP_HOST_NAME
                        ],
                        # Note that the below is required for compatibility
                        # with vdsm-generated pki. See bz 1178535.
                        address=self.environment[
                            ohostedcons.NetworkEnv.HOST_NAME
                        ],
                        cluster=cluster,
                        ssh=self._ovirtsdk_xml.params.SSH(
                            authentication_method='publickey',
                            port=self.environment[
                                ohostedcons.NetworkEnv.SSHD_PORT
                            ],
                        ),
                        override_iptables=self.environment[
                            otopicons.NetEnv.IPTABLES_ENABLE
                        ],
                    )
                )
                added_to_cluster = True
            except ovirtsdk.infrastructure.errors.RequestError as e:
                self.logger.debug(
                    'Cannot add the host to cluster {cluster}'.format(
                        cluster=cluster_name,
                    ),
                    exc_info=True,
                )
                self.logger.error(
                    _(
                        'Cannot automatically add the host '
                        'to cluster {cluster}:\n{details}\n'
                    ).format(
                        cluster=cluster_name,
                        details=e.detail
                    )
                )
                while not check_liveliness.manualSetupDispatcher(
                    self,
                    check_liveliness.MSD_FURTHER_ACTIONS,
                    self.environment[
                        ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN
                    ]
                ):
                    pass

        up = self._wait_host_ready(
            engine_api,
            self.environment[ohostedcons.EngineEnv.APP_HOST_NAME]
        )
        # TODO: host-deploy restarted vdscli so we need to
        # connect again
        if not up:
            self.logger.error(
                _(
                    'Unable to add {host} to the manager'
                ).format(
                    host=self.environment[
                        ohostedcons.EngineEnv.APP_HOST_NAME
                    ],
                )
            )
        else:
            # This works only if the host is up.
            self.logger.debug('Setting CPU for the cluster')
            try:
                cluster, cpu = self._wait_cluster_cpu_ready(
                    engine_api,
                    cluster_name
                )
                self.logger.debug(cpu.__dict__)
                cpu.set_id(
                    self.environment[ohostedcons.VDSMEnv.ENGINE_CPU]
                )
                cluster.set_cpu(cpu)
                cluster.update()
            except ovirtsdk.infrastructure.errors.RequestError as e:
                self.logger.debug(
                    'Cannot set CPU level of cluster {cluster}'.format(
                        cluster=cluster_name,
                    ),
                    exc_info=True,
                )
                self.logger.error(
                    _(
                        'Cannot automatically set CPU level '
                        'of cluster {cluster}:\n{details}\n'
                    ).format(
                        cluster=cluster_name,
                        details=e.detail
                    )
                )
        engine_api.disconnect()
    def _closeup(self):
        esexecuting = self.environment[ohostedcons.CloudInit.EXECUTE_ESETUP]
        fqdn = self.environment[
            ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN]
        live_checker = check_liveliness.LivelinessChecker()
        # manual engine setup execution
        if not esexecuting:
            self.dialog.note(
                _('Please install and setup the engine in the VM.'))
            self.dialog.note(
                _('You may also be interested in '
                  'installing ovirt-guest-agent-common package '
                  'in the VM.'))
            while not check_liveliness.manualSetupDispatcher(
                    self, check_liveliness.MSD_ENGINE_INSTALLED, fqdn):
                pass

        # automated engine setup execution on the appliance
        else:
            spath = (ohostedcons.Const.OVIRT_HE_CHANNEL_PATH +
                     self.environment[ohostedcons.VMEnv.VM_UUID] + '.' +
                     ohostedcons.Const.OVIRT_HE_CHANNEL_NAME)
            self.logger.debug(
                'Connecting to the appliance on {spath}'.format(spath=spath))
            self._appliance_connect(spath)
            completed = False
            TIMEOUT = 5
            nTimeout5 = int(
                math.ceil(
                    float(self.environment[
                        ohostedcons.EngineEnv.ENGINE_SETUP_TIMEOUT]) /
                    TIMEOUT))

            self.logger.info(_('Running engine-setup on the appliance'))
            rtimeouts = 0
            while not completed:
                line, timeout = self._appliance_readline_nb(TIMEOUT)
                if line:
                    self.dialog.note('|- ' + line + '\n')
                if timeout:
                    rtimeouts += 1
                else:
                    rtimeouts = 0
                if rtimeouts >= nTimeout5:
                    self.logger.error(
                        'Engine setup got stuck on the appliance')
                    raise RuntimeError(
                        _('Engine setup is stalled on the appliance '
                          'since {since} seconds ago.\n'
                          'Please check its log on the appliance.\n').format(
                              since=TIMEOUT * nTimeout5))
                if ohostedcons.Const.E_RESTORE_SUCCESS_STRING in line:
                    self.logger.info('Engine backup successfully restored')
                elif ohostedcons.Const.E_RESTORE_FAIL_STRING in line:
                    self.logger.error(
                        'Engine backup restore failed on the appliance')
                    raise RuntimeError(
                        _('engine-backup failed restoring the engine backup '
                          'on the appliance\n'
                          'Please check its log on the appliance.\n'))
                elif ohostedcons.Const.E_SETUP_SUCCESS_STRING in line:
                    completed = True
                elif ohostedcons.Const.E_SETUP_FAIL_STRING in line:
                    self.logger.error('Engine setup failed on the appliance')
                    raise RuntimeError(
                        _('Engine setup failed on the appliance\n'
                          'Please check its log on the appliance.\n').format(
                              since=TIMEOUT * nTimeout5))
                # TODO: prefer machine dialog for more robust interaction
            self.logger.debug('Engine-setup successfully completed ')
            self.logger.info(_('Engine-setup successfully completed '))
            self._appliance_disconnect()
            cengineup = 0
            waitEngineUP = True
            while waitEngineUP:
                if live_checker.isEngineUp(fqdn):
                    waitEngineUP = False
                else:
                    cengineup += 1
                    if cengineup >= 20:
                        self.logger.error(_('Engine is still not reachable'))
                        raise RuntimeError(_('Engine is still not reachable'))
                    self.logger.info(
                        _('Engine is still not reachable, waiting...'))
                    time.sleep(15)