-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37395 - New Hosts page perform build actions
Refs #37395 - Made the hosts controller handle both json and html Refs #37395 - Fails correctly with url Refs #37395 - Moved error notifications to a separate file
- Loading branch information
Showing
11 changed files
with
388 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class BulkHostsManager | ||
def initialize(hosts:) | ||
@hosts = hosts | ||
end | ||
|
||
def build(reboot: false) | ||
# returns missed hosts | ||
@hosts.select do |host| | ||
success = true | ||
begin | ||
host.built(false) if host.build? && host.token_expired? | ||
host.setBuild | ||
host.power.reset if reboot && host.supports_power_and_running? | ||
rescue => error | ||
Foreman::Logging.exception("Failed to redeploy #{host}.", error) | ||
success = false | ||
end | ||
!success | ||
end | ||
end | ||
|
||
def rebuild_configuration | ||
# returns a hash with a key/value configuration | ||
all_fails = {} | ||
@hosts.each do |host| | ||
result = host.recreate_config | ||
result.each_pair do |k, v| | ||
all_fails[k] ||= [] | ||
all_fails[k] << host unless v | ||
end | ||
end | ||
all_fails | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
node :message do | ||
locals[:message] | ||
end | ||
|
||
node :failed_host_ids do | ||
locals[:failed_host_ids] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
.../javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/BulkBuildHostModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { | ||
Modal, | ||
Button, | ||
TextContent, | ||
Text, | ||
Checkbox, | ||
Radio, | ||
} from '@patternfly/react-core'; | ||
import { addToast } from '../../../ToastsList/slice'; | ||
import { translate as __ } from '../../../../common/I18n'; | ||
import { failedHostsToastParams } from '../helpers'; | ||
import { STATUS } from '../../../../constants'; | ||
import { selectAPIStatus } from '../../../../redux/API/APISelectors'; | ||
import { bulkBuildHosts, HOST_BUILD_KEY } from './actions'; | ||
|
||
const BulkBuildHostModal = ({ | ||
isOpen, | ||
closeModal, | ||
selectedCount, | ||
orgId, | ||
fetchBulkParams, | ||
}) => { | ||
const dispatch = useDispatch(); | ||
const [buildRadioChecked, setBuildRadioChecked] = useState(true); | ||
const [rebootChecked, setRebootChecked] = useState(false); | ||
const hostUpdateStatus = useSelector(state => | ||
selectAPIStatus(state, HOST_BUILD_KEY) | ||
); | ||
const handleModalClose = () => { | ||
setRebootChecked(false); | ||
setBuildRadioChecked(true); | ||
closeModal(); | ||
}; | ||
|
||
const handleError = ({ response }) => { | ||
handleModalClose(); | ||
dispatch( | ||
addToast( | ||
failedHostsToastParams({ ...response.data.error, key: HOST_BUILD_KEY }) | ||
) | ||
); | ||
}; | ||
const handleSave = () => { | ||
const requestBody = { | ||
included: { | ||
search: fetchBulkParams(), | ||
}, | ||
reboot: rebootChecked, | ||
rebuild_configuration: !buildRadioChecked, | ||
}; | ||
|
||
dispatch(bulkBuildHosts(requestBody, handleModalClose, handleError)); | ||
}; | ||
|
||
const handleBuildRadioSelected = selected => { | ||
setBuildRadioChecked(selected); | ||
if (!selected) { | ||
setRebootChecked(false); | ||
} | ||
}; | ||
const modalActions = [ | ||
<Button | ||
key="add" | ||
ouiaId="bulk-build-hosts-modal-add-button" | ||
variant="primary" | ||
onClick={handleSave} | ||
isDisabled={hostUpdateStatus === STATUS.PENDING} | ||
isLoading={hostUpdateStatus === STATUS.PENDING} | ||
> | ||
{__('Confirm')} | ||
</Button>, | ||
<Button | ||
key="cancel" | ||
ouiaId="bulk-build-hosts-modal-cancel-button" | ||
variant="link" | ||
onClick={handleModalClose} | ||
> | ||
Cancel | ||
</Button>, | ||
]; | ||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
onClose={handleModalClose} | ||
onEscapePress={handleModalClose} | ||
title={__('Build management')} | ||
width="50%" | ||
position="top" | ||
actions={modalActions} | ||
id="bulk-build-hosts-modal" | ||
key="bulk-build-hosts-modal" | ||
ouiaId="bulk-build-hosts-modal" | ||
> | ||
<TextContent> | ||
<Text ouiaId="bulk-set-build-options"> | ||
<FormattedMessage | ||
defaultMessage={__( | ||
'Choose an action that will be performed on {hosts}.' | ||
)} | ||
values={{ | ||
hosts: ( | ||
<strong> | ||
<FormattedMessage | ||
defaultMessage="{count, plural, one {# {singular}} other {# {plural}}}" | ||
values={{ | ||
count: selectedCount, | ||
singular: __('selected host'), | ||
plural: __('selected hosts'), | ||
}} | ||
id="ccs-options-i18n" | ||
Check warning on line 114 in webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/BulkBuildHostModal.js
|
||
/> | ||
</strong> | ||
), | ||
}} | ||
id="bulk-build-host-description" | ||
/> | ||
</Text> | ||
</TextContent> | ||
<hr /> | ||
<Radio | ||
isChecked={buildRadioChecked} | ||
name="buildHostRadioGroup" | ||
onChange={checked => handleBuildRadioSelected(checked)} | ||
label={__('Build')} | ||
id="build-host-radio" | ||
ouiaId="build-host-radio" | ||
body={ | ||
<Checkbox | ||
label={__('Reboot now')} | ||
id="reboot-now-checkbox-id" | ||
name="reboot-now" | ||
isChecked={rebootChecked} | ||
isDisabled={!buildRadioChecked} | ||
onChange={setRebootChecked} | ||
ouiaId="build-reboot-checkbox" | ||
/> | ||
} | ||
/> | ||
<hr /> | ||
<Radio | ||
name="buildHostRadioGroup" | ||
onChange={checked => handleBuildRadioSelected(!checked)} | ||
label={__('Rebuild provisioning configuration only')} | ||
id="rebuild-host-radio" | ||
ouiaId="rebuild-host-radio" | ||
/> | ||
</Modal> | ||
); | ||
}; | ||
|
||
BulkBuildHostModal.propTypes = { | ||
isOpen: PropTypes.bool, | ||
closeModal: PropTypes.func, | ||
selectedCount: PropTypes.number.isRequired, | ||
fetchBulkParams: PropTypes.func.isRequired, | ||
orgId: PropTypes.number.isRequired, | ||
}; | ||
|
||
BulkBuildHostModal.defaultProps = { | ||
isOpen: false, | ||
closeModal: () => {}, | ||
}; | ||
|
||
export default BulkBuildHostModal; |
17 changes: 17 additions & 0 deletions
17
webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/actions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { APIActions } from '../../../../redux/API'; | ||
import { foremanUrl } from '../../../../common/helpers'; | ||
|
||
export const HOST_BUILD_KEY = 'HOST_BUILD_KEY'; | ||
export const bulkBuildHosts = (params, handleSuccess, handleError) => { | ||
const url = foremanUrl(`/api/v2/hosts/bulk/build`); | ||
return APIActions.put({ | ||
key: HOST_BUILD_KEY, | ||
url, | ||
successToast: response => response.data.message, | ||
handleSuccess, | ||
handleError, | ||
params, | ||
}); | ||
}; | ||
|
||
export default bulkBuildHosts; |
Oops, something went wrong.