foreman_acd 0.7.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +17 -2
  4. data/app/controllers/foreman_acd/app_definitions_controller.rb +104 -7
  5. data/app/controllers/foreman_acd/app_instances_controller.rb +15 -30
  6. data/app/controllers/foreman_acd/concerns/app_instance_mixins.rb +36 -0
  7. data/app/controllers/ui_acd_controller.rb +42 -3
  8. data/app/lib/actions/foreman_acd/run_configurator.rb +1 -0
  9. data/app/models/concerns/foreman_acd/host_managed_extensions.rb +40 -27
  10. data/app/models/foreman_acd/app_instance.rb +47 -2
  11. data/app/models/foreman_acd/foreman_host.rb +8 -0
  12. data/app/services/foreman_acd/app_deployer.rb +19 -2
  13. data/app/services/foreman_acd/inventory_creator.rb +11 -1
  14. data/app/views/foreman_acd/app_definitions/_form.html.erb +4 -0
  15. data/app/views/foreman_acd/app_definitions/import.html.erb +20 -1
  16. data/app/views/foreman_acd/app_definitions/index.html.erb +3 -6
  17. data/app/views/foreman_acd/app_instances/_form.html.erb +4 -0
  18. data/app/views/foreman_acd/app_instances/index.html.erb +15 -11
  19. data/app/views/foreman_acd/app_instances/report.html.erb +7 -2
  20. data/app/views/ui_acd/host_report.json.rabl +4 -0
  21. data/app/views/ui_acd/report_data.json.rabl +10 -0
  22. data/app/views/ui_acd/validate_hostname.json.rabl +6 -0
  23. data/config/routes.rb +3 -0
  24. data/db/migrate/20210818125913_add_is_existing_host_to_foreman_host.rb +8 -0
  25. data/db/migrate/20210902110645_add_initial_configure_task.rb +8 -0
  26. data/lib/foreman_acd/plugin.rb +9 -9
  27. data/lib/foreman_acd/version.rb +1 -1
  28. data/lib/foreman_acd.rb +27 -9
  29. data/package.json +8 -25
  30. data/test/controllers/ui_acd_controller_test.rb +4 -1
  31. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js +2 -0
  32. data/webpack/__snapshots__/helper.test.js.snap +1 -1
  33. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +34 -10
  34. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +12 -0
  35. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +1 -0
  36. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +30 -9
  37. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +4 -0
  38. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinition.test.js +1 -0
  39. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionSelectors.test.js +12 -0
  40. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinition.test.js.snap +31 -5
  41. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionSelectors.test.js.snap +8 -0
  42. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +1 -1
  43. data/webpack/components/ApplicationDefinition/components/__tests__/__snapshots__/AnsiblePlaybookSelector.test.js.snap +3 -3
  44. data/webpack/components/ApplicationDefinition/index.js +8 -0
  45. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImport.js +214 -0
  46. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImport.scss +1 -0
  47. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportActions.js +161 -0
  48. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportConstants.js +6 -0
  49. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportReducer.js +79 -0
  50. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportSelectors.js +8 -0
  51. data/webpack/components/ApplicationDefinitionImport/__fixtures__/applicationDefinitionImportConfData_1.fixtures.js +129 -0
  52. data/webpack/components/ApplicationDefinitionImport/__fixtures__/applicationDefinitionImportReducer.fixtures.js +29 -0
  53. data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImport.test.js +20 -0
  54. data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImportReducer.test.js +43 -0
  55. data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImportSelectors.test.js +29 -0
  56. data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImport.test.js.snap +62 -0
  57. data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImportReducer.test.js.snap +362 -0
  58. data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImportSelectors.test.js.snap +130 -0
  59. data/webpack/components/ApplicationDefinitionImport/index.js +32 -0
  60. data/webpack/components/ApplicationInstance/ApplicationInstance.js +102 -26
  61. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +118 -6
  62. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +4 -0
  63. data/webpack/components/ApplicationInstance/ApplicationInstanceHelper.js +15 -0
  64. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +71 -30
  65. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +4 -0
  66. data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceReducer.fixtures.js +2 -0
  67. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstance.test.js +1 -0
  68. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceReducer.test.js +12 -0
  69. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceSelectors.test.js +12 -0
  70. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstance.test.js.snap +98 -7
  71. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceReducer.test.js.snap +271 -0
  72. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceSelectors.test.js.snap +8 -0
  73. data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +1 -0
  74. data/webpack/components/ApplicationInstance/components/ServiceCounter.js +1 -1
  75. data/webpack/components/ApplicationInstance/helper.js +0 -0
  76. data/webpack/components/ApplicationInstance/index.js +8 -0
  77. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +81 -6
  78. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +35 -1
  79. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +3 -0
  80. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +19 -0
  81. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +4 -0
  82. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReport.test.js.snap +1 -124
  83. data/webpack/components/ApplicationInstanceReport/index.js +8 -1
  84. data/webpack/components/ExistingHostSelection/ExistingHostSelection.js +104 -0
  85. data/webpack/components/ExistingHostSelection/ExistingHostSelection.scss +15 -0
  86. data/webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js +71 -0
  87. data/webpack/components/ExistingHostSelection/ExistingHostSelectionConstants.js +4 -0
  88. data/webpack/components/ExistingHostSelection/ExistingHostSelectionHelper.js +0 -0
  89. data/webpack/components/ExistingHostSelection/ExistingHostSelectionReducer.js +90 -0
  90. data/webpack/components/ExistingHostSelection/ExistingHostSelectionSelectors.js +8 -0
  91. data/webpack/components/ExistingHostSelection/__fixtures__/existingHostSelectionConfData_1.fixtures.js +191 -0
  92. data/webpack/components/ExistingHostSelection/__fixtures__/existingHostSelectionReducer.fixtures.js +203 -0
  93. data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelection.test.js +19 -0
  94. data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelectionReducer.test.js +59 -0
  95. data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelectionSelectors.test.js +36 -0
  96. data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelection.test.js.snap +35 -0
  97. data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelectionReducer.test.js.snap +614 -0
  98. data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelectionSelectors.test.js.snap +27 -0
  99. data/webpack/components/ExistingHostSelection/components/ServiceSelector.js +48 -0
  100. data/webpack/components/ExistingHostSelection/components/__tests__/ServiceSelector.test.js +35 -0
  101. data/webpack/components/ExistingHostSelection/components/__tests__/__snapshots__/ServiceSelector.test.js.snap +77 -0
  102. data/webpack/components/ExistingHostSelection/index.js +26 -0
  103. data/webpack/components/ParameterSelection/ParameterSelection.js +103 -1
  104. data/webpack/components/ParameterSelection/ParameterSelection.scss +7 -0
  105. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +46 -4
  106. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +2 -0
  107. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +5 -1
  108. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +52 -11
  109. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +2 -0
  110. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +8 -0
  111. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +2 -0
  112. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -0
  113. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +96 -0
  114. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +117 -17
  115. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +13 -0
  116. data/webpack/components/ParameterSelection/index.js +4 -1
  117. data/webpack/components/SyncGitRepo/SyncGitRepo.js +2 -10
  118. data/webpack/components/SyncGitRepo/SyncGitRepoActions.js +2 -3
  119. data/webpack/components/SyncGitRepo/SyncGitRepoConstants.js +0 -1
  120. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepo.test.js.snap +1 -0
  121. data/webpack/components/SyncGitRepo/components/FormTextInput.js +1 -1
  122. data/webpack/components/SyncGitRepo/components/ScmTypeSelector.js +3 -2
  123. data/webpack/components/common/DeleteTableEntry.js +16 -2
  124. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +38 -0
  125. data/webpack/helper.js +21 -1
  126. data/webpack/helper.test.js +20 -1
  127. data/webpack/index.js +5 -0
  128. data/webpack/js-yaml.js +3874 -0
  129. data/webpack/reducer.js +13 -2
  130. data/webpack/test_setup.js +0 -2
  131. metadata +46 -2
@@ -2,129 +2,6 @@
2
2
 
3
3
  exports[`ApplicationInstanceReport should render application instance report 1`] = `
4
4
  <span>
5
- <div
6
- className="deploy_status"
7
- >
8
- <div>
9
- <div
10
- className="deploy_status_head"
11
- >
12
- Deployment task
13
- </div>
14
- <div
15
- className="deploy_status_content"
16
- >
17
- <a
18
- href="deploy/task/url"
19
- >
20
- Last deployment task
21
- </a>
22
- </div>
23
- </div>
24
- <div>
25
- <div
26
- className="deploy_status_head"
27
- >
28
- Configuration job
29
- </div>
30
- <div
31
- className="deploy_status_content"
32
- >
33
- <a
34
- href="configure/job/url"
35
- >
36
- Configuration jobs
37
- </a>
38
- </div>
39
- </div>
40
- </div>
41
- <div
42
- className="deploy_report_hosts"
43
- >
44
- Hosts
45
- <VerticalTabs
46
- activeTab={false}
47
- className=""
48
- id="vertical_tabs"
49
- restrictTabs={false}
50
- >
51
- <VerticalTabsTab
52
- active={true}
53
- className=""
54
- hasActiveDescendant={false}
55
- id={0}
56
- key="vt_tab_0"
57
- onActivate={[Function]}
58
- shown={false}
59
- title="great-web-app-db-1"
60
- wrapStyle="nowrap"
61
- />
62
- <VerticalTabsTab
63
- active={false}
64
- className=""
65
- hasActiveDescendant={false}
66
- id={1}
67
- key="vt_tab_1"
68
- onActivate={[Function]}
69
- shown={false}
70
- title="great-web-app-web-1"
71
- wrapStyle="nowrap"
72
- />
73
- <VerticalTabsTab
74
- active={false}
75
- className=""
76
- hasActiveDescendant={false}
77
- id={2}
78
- key="vt_tab_2"
79
- onActivate={[Function]}
80
- shown={false}
81
- title="great-web-app-web-2"
82
- wrapStyle="nowrap"
83
- />
84
- </VerticalTabs>
85
- </div>
86
- <div
87
- className="deploy_report_status"
88
- >
89
- <div>
90
- <span>
91
- Host:
92
- <a
93
- href="/hosts/great-web-app-db-1.deploy3.dev.atix"
94
- >
95
- great-web-app-db-1
96
- </a>
97
- </span>
98
- <span>
99
-  | 
100
- </span>
101
- <span>
102
- State:
103
- Deployed
104
- </span>
105
- <span>
106
-  | 
107
- </span>
108
- <span>
109
- Power Status:
110
- <Component
111
- data={
112
- Object {
113
- "id": 8,
114
- "url": "/api/v2/hosts/great-web-app-db-1.deploy3.dev.atix/power",
115
- }
116
- }
117
- key="power_status_8"
118
- />
119
- </span>
120
- </div>
121
- </div>
122
- <div
123
- className="deploy_report_tasks"
124
- >
125
- <ReportViewer
126
- report={Array []}
127
- />
128
- </div>
5
+ No host
129
6
  </span>
130
7
  `;
@@ -8,11 +8,19 @@ import * as ApplicationInstanceReportActions from './ApplicationInstanceReportAc
8
8
  import {
9
9
  selectHosts,
10
10
  selectActiveHostId,
11
+ selectDeploymentState,
12
+ selectInitialConfigureState,
13
+ selectInitialConfigureJobUrl,
14
+ selectShowInitialConfigureJob,
11
15
  } from './ApplicationInstanceReportSelectors';
12
16
 
13
17
  const mapStateToProps = state => ({
14
18
  hosts: selectHosts(state),
15
19
  activeHostId: selectActiveHostId(state),
20
+ deploymentState: selectDeploymentState(state),
21
+ initialConfigureState: selectInitialConfigureState(state),
22
+ initialConfigureJobUrl: selectInitialConfigureJobUrl(state),
23
+ showInitialConfigureJob: selectShowInitialConfigureJob(state),
16
24
  });
17
25
 
18
26
  const mapDispatchToProps = dispatch =>
@@ -22,4 +30,3 @@ export default connect(
22
30
  mapStateToProps,
23
31
  mapDispatchToProps
24
32
  )(ApplicationInstanceReport);
25
-
@@ -0,0 +1,104 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { orderBy } from 'lodash';
4
+ import ServiceSelector from './components/ServiceSelector';
5
+ import { arrayToObject } from '../../helper';
6
+
7
+ import {
8
+ cloneDeep,
9
+ } from 'lodash';
10
+
11
+ import {
12
+ Icon,
13
+ Button,
14
+ DualListControlled,
15
+ } from 'patternfly-react';
16
+
17
+ class ExistingHostSelection extends React.Component {
18
+
19
+ constructor(props) {
20
+ super(props);
21
+ }
22
+
23
+ componentDidMount() {
24
+ const {
25
+ location,
26
+ organization,
27
+ services,
28
+ initExistingHostSelection,
29
+ allHosts,
30
+ } = this.props;
31
+
32
+ initExistingHostSelection(allHosts);
33
+ }
34
+
35
+ render() {
36
+ const {
37
+ location,
38
+ organization,
39
+ services,
40
+ serviceId,
41
+ availableHosts,
42
+ alreadyUsedHosts,
43
+ loadHostsOfHostgroup,
44
+ hostSelectionChanged,
45
+ } = this.props;
46
+
47
+ const serviceList = arrayToObject(services, "id", "name");
48
+ const load_hostgroup_url = "/api/v2/hostgroups/__hostgroup_id__/hosts"
49
+
50
+ return(
51
+ <div>
52
+ <div className="row">
53
+ <ServiceSelector
54
+ label="Service"
55
+ hidden={ false }
56
+ selectValue={ this.props.serviceId ? this.props.serviceId.toString() : '0'}
57
+ options={ serviceList }
58
+ onChange={ loadHostsOfHostgroup }
59
+ additionalData={{ url: load_hostgroup_url, services: services }} />
60
+ </div>
61
+ <div className="row">
62
+ <label className="col-md-2 control-label">{ __("Hosts") }</label>
63
+ {this.props.serviceId != undefined ? (
64
+ <div className="col-md-6">
65
+ <DualListControlled
66
+ onChange={ hostSelectionChanged }
67
+ left={{
68
+ items: cloneDeep(availableHosts),
69
+ }}
70
+ right={{
71
+ items: cloneDeep(alreadyUsedHosts),
72
+ }}
73
+ allowHiddenInputs={false}
74
+ />
75
+ </div>) : (<span>{ __("Please select service first.") }</span>)}
76
+ </div>
77
+ </div>
78
+ );
79
+ }
80
+ }
81
+
82
+ ExistingHostSelection.defaultProps = {
83
+ serviceId: undefined,
84
+ hostsInHostgroup: {},
85
+ availableHosts: [],
86
+ alreadyUsedHosts: [],
87
+ selectedHosts: [],
88
+ };
89
+
90
+ ExistingHostSelection.propTypes = {
91
+ location: PropTypes.string.isRequired,
92
+ organization: PropTypes.string.isRequired,
93
+ services: PropTypes.array.isRequired,
94
+ initExistingHostSelection: PropTypes.func,
95
+ serviceId: PropTypes.number,
96
+ hostsInHostgroup: PropTypes.object,
97
+ availableHosts: PropTypes.array,
98
+ alreadyUsedHosts: PropTypes.array,
99
+ selectedHosts: PropTypes.array,
100
+ loadHostsOfHostgroup: PropTypes.func,
101
+ hostSelectionChanged: PropTypes.func,
102
+ };
103
+
104
+ export default ExistingHostSelection;
@@ -0,0 +1,15 @@
1
+ @import '~@theforeman/vendor/scss/variables';
2
+
3
+ .add_existing_hosts_modal {
4
+ margin-top: 0;
5
+ margin-bottom: 0;
6
+ height: 100%;
7
+ width: 80%;
8
+ max-width: none !important;
9
+ }
10
+
11
+ .row {
12
+ margin-left: 0;
13
+ margin-right: 0;
14
+ margin-bottom: 20px;
15
+ }
@@ -0,0 +1,71 @@
1
+ import React from 'react';
2
+ import * as sort from 'sortabular';
3
+ import { translate as __ } from 'foremanReact/common/I18n';
4
+
5
+ import api from 'foremanReact/API';
6
+
7
+ import {
8
+ propsToSnakeCase,
9
+ propsToCamelCase,
10
+ } from 'foremanReact/common/helpers';
11
+
12
+ import {
13
+ EXISTING_HOST_SELECTION_INIT,
14
+ EXISTING_HOST_SELECTION_LOAD_HOSTS_SUCCESS,
15
+ EXISTING_HOST_SELECTION_LOAD_HOSTS_FAILURE,
16
+ EXISTING_HOST_SELECTION_SELECTION_CHANGED,
17
+ } from './ExistingHostSelectionConstants';
18
+
19
+ export const initExistingHostSelection = (
20
+ allHosts,
21
+ ) => dispatch => {
22
+ const initialState = {};
23
+
24
+ initialState.alreadyUsedHosts = undefined;
25
+ initialState.serviceId = undefined;
26
+ initialState.selectedHosts = [];
27
+ initialState.hostsInHostgroup = {};
28
+ initialState.allHosts = allHosts;
29
+
30
+ dispatch({
31
+ type: EXISTING_HOST_SELECTION_INIT,
32
+ payload: initialState,
33
+ });
34
+ }
35
+
36
+ export const loadHostsOfHostgroup = (
37
+ serviceId,
38
+ additionalData
39
+ ) => dispatch => {
40
+
41
+ const selService = additionalData.services.filter(s => (s.id == serviceId))[0];
42
+ const realUrl = additionalData.url.replace("__hostgroup_id__", selService.hostgroup);
43
+
44
+ return api
45
+ .get(realUrl, {}, {})
46
+ .then(({ data }) =>
47
+ dispatch({
48
+ type: EXISTING_HOST_SELECTION_LOAD_HOSTS_SUCCESS,
49
+ payload: {
50
+ hosts: data.results,
51
+ serviceId: parseInt(serviceId),
52
+ }
53
+ })
54
+ )
55
+ .catch(error => dispatch(errorHandler(EXISTING_HOST_SELECTION_LOAD_HOSTS_FAILURE, error)));
56
+ };
57
+
58
+ export const hostSelectionChanged = ({ left, right }) => ({
59
+ type: EXISTING_HOST_SELECTION_SELECTION_CHANGED,
60
+ payload: {
61
+ selection: right.items,
62
+ }
63
+ });
64
+
65
+ const errorHandler = (msg, err) => {
66
+ const error = {
67
+ errorMsg: __('Failed to fetch data from server.'),
68
+ statusText: err,
69
+ };
70
+ return { type: msg, payload: { error } };
71
+ };
@@ -0,0 +1,4 @@
1
+ export const EXISTING_HOST_SELECTION_INIT = 'EXISTING_HOST_SELECTION_INIT';
2
+ export const EXISTING_HOST_SELECTION_LOAD_HOSTS_SUCCESS = 'EXISTING_HOST_SELECTION_LOAD_HOSTS_SUCCESS';
3
+ export const EXISTING_HOST_SELECTION_LOAD_HOSTS_FAILURE = 'EXISTING_HOST_SELECTION_LOAD_HOSTS_FAILURE';
4
+ export const EXISTING_HOST_SELECTION_SELECTION_CHANGED = 'EXISTING_HOST_SELECTION_SELECTION_CHANGED';
@@ -0,0 +1,90 @@
1
+ import Immutable from 'seamless-immutable';
2
+
3
+ import {
4
+ cloneDeep,
5
+ findIndex,
6
+ findLastIndex,
7
+ } from 'lodash';
8
+
9
+ import { shortHostname } from '../../helper';
10
+ import * as sort from 'sortabular';
11
+
12
+ import {
13
+ EXISTING_HOST_SELECTION_INIT,
14
+ EXISTING_HOST_SELECTION_LOAD_HOSTS_SUCCESS,
15
+ EXISTING_HOST_SELECTION_LOAD_HOSTS_FAILURE,
16
+ EXISTING_HOST_SELECTION_SELECTION_CHANGED,
17
+ } from './ExistingHostSelectionConstants';
18
+
19
+ export const initialState = Immutable({
20
+ serviceId: undefined,
21
+ error: { errorMsg: '', status: '', statusText: '' },
22
+ });
23
+
24
+ const existingHostSelectionConf = (state = initialState, action) => {
25
+ const { payload } = action;
26
+
27
+ switch (action.type) {
28
+ case EXISTING_HOST_SELECTION_INIT: {
29
+ return state.merge(payload);
30
+ }
31
+ case EXISTING_HOST_SELECTION_LOAD_HOSTS_SUCCESS: {
32
+ let alreadyUsedHosts = [];
33
+
34
+ state.allHosts.forEach(host => {
35
+ if ((host.service == payload.serviceId) && (host.isExistingHost == true)) {
36
+ alreadyUsedHosts.push({
37
+ value: host.hostname,
38
+ label: host.hostname,
39
+ disabled: true,
40
+ tooltipText: __('Host already used for this application instance'),
41
+ });
42
+ }
43
+ });
44
+
45
+ let availableHosts = [];
46
+ let hostsInHostgroup = {};
47
+ payload.hosts.forEach(host => {
48
+ let shortName = shortHostname(host.name);
49
+ if (state.allHosts.find(h => h.hostname == shortName) == undefined) {
50
+ availableHosts.push({
51
+ value: shortName,
52
+ label: shortName,
53
+ });
54
+ }
55
+ hostsInHostgroup[shortName] = host;
56
+ });
57
+
58
+ return state.merge({
59
+ hostsInHostgroup: hostsInHostgroup,
60
+ availableHosts: availableHosts,
61
+ alreadyUsedHosts: alreadyUsedHosts,
62
+ serviceId: payload.serviceId,
63
+ });
64
+ }
65
+ case EXISTING_HOST_SELECTION_LOAD_HOSTS_FAILURE: {
66
+ return state.merge({ error: payload.error });
67
+ }
68
+ case EXISTING_HOST_SELECTION_SELECTION_CHANGED: {
69
+ let selectedHosts = [];
70
+
71
+ payload.selection.forEach(selHost => {
72
+ let hostData = state.hostsInHostgroup[selHost.value];
73
+ selectedHosts.push({
74
+ fqdn: hostData.name,
75
+ hostname: shortHostname(hostData.name),
76
+ hostgroupId: hostData.hostgroup_id,
77
+ serviceId: state.serviceId,
78
+ });
79
+ });
80
+
81
+ return state.merge({
82
+ selectedHosts: selectedHosts,
83
+ });
84
+ }
85
+ default:
86
+ return state;
87
+ }
88
+ };
89
+
90
+ export default existingHostSelectionConf;
@@ -0,0 +1,8 @@
1
+ const existingHostState = state => state.foremanAcd.existingHostSelectionConf;
2
+
3
+ export const selectServiceId = state => existingHostState(state).serviceId;
4
+ export const selectAllHosts = state => existingHostState(state).allHosts;
5
+ export const selectHostsInHostgroup = state => existingHostState(state).selectHostsInHostgroup;
6
+ export const selectAvailableHosts = state => existingHostState(state).availableHosts;
7
+ export const selectAlreadyUsedHosts = state => existingHostState(state).alreadyUsedHosts;
8
+ export const selectSelectedHosts = state => existingHostState(state).selectedHosts;
@@ -0,0 +1,191 @@
1
+ export const existingHostSelectionConfData_1 = {
2
+ serviceId: 2,
3
+ error: {
4
+ errorMsg: '',
5
+ status: '',
6
+ statusText: ''
7
+ },
8
+ allHosts: [
9
+ {
10
+ id: 5,
11
+ hostname: 'isaac-anselm',
12
+ service: '1',
13
+ description: '',
14
+ foremanParameters: [],
15
+ ansibleParameters: [],
16
+ }
17
+ ],
18
+ alreadyUsedHosts: [
19
+ {
20
+ value: 'isaac-anselm',
21
+ label: 'isaac-anselm',
22
+ disabled: true,
23
+ tooltipText: 'Host already used for this application instance'
24
+ }
25
+ ],
26
+ selectedHosts: [],
27
+ hostsInHostgroup: {
28
+ '3': {
29
+ ip: null,
30
+ ip6: '',
31
+ environment_id: null,
32
+ environment_name: null,
33
+ last_report: null,
34
+ mac: '00:11:22:33:44:a1',
35
+ realm_id: null,
36
+ realm_name: null,
37
+ sp_mac: null,
38
+ sp_ip: null,
39
+ sp_name: null,
40
+ domain_id: 1,
41
+ domain_name: 'mylocal',
42
+ architecture_id: 1,
43
+ architecture_name: 'x86_64',
44
+ operatingsystem_id: 1,
45
+ operatingsystem_name: 'centos 7',
46
+ subnet_id: 1,
47
+ subnet_name: 'mylocal',
48
+ subnet6_id: null,
49
+ subnet6_name: null,
50
+ sp_subnet_id: null,
51
+ ptable_id: 118,
52
+ ptable_name: 'Kickstart default',
53
+ medium_id: 1,
54
+ medium_name: 'CentOS 7 mirror',
55
+ pxe_loader: 'PXELinux BIOS',
56
+ build: true,
57
+ comment: '',
58
+ disk: '',
59
+ installed_at: null,
60
+ model_id: null,
61
+ hostgroup_id: 1,
62
+ owner_id: 4,
63
+ owner_name: 'Admin User',
64
+ owner_type: 'User',
65
+ enabled: true,
66
+ managed: true,
67
+ use_image: null,
68
+ image_file: '',
69
+ uuid: null,
70
+ compute_resource_id: null,
71
+ compute_resource_name: null,
72
+ compute_profile_id: null,
73
+ compute_profile_name: null,
74
+ capabilities: [
75
+ 'build'
76
+ ],
77
+ provision_method: 'build',
78
+ certname: 'isaac-anselm.mylocal',
79
+ image_id: null,
80
+ image_name: null,
81
+ created_at: '2021-08-05 11:16:34 +0200',
82
+ updated_at: '2021-08-05 11:16:34 +0200',
83
+ last_compile: null,
84
+ global_status: 0,
85
+ global_status_label: 'Error',
86
+ uptime_seconds: null,
87
+ organization_id: 1,
88
+ organization_name: 'Default Organization',
89
+ location_id: 2,
90
+ location_name: 'Default Location',
91
+ puppet_status: 0,
92
+ model_name: null,
93
+ build_status: 2,
94
+ build_status_label: 'Token expired',
95
+ name: 'isaac-anselm.mylocal',
96
+ id: 3,
97
+ puppet_proxy_id: null,
98
+ puppet_proxy_name: null,
99
+ puppet_ca_proxy_id: null,
100
+ puppet_ca_proxy_name: null,
101
+ puppet_proxy: null,
102
+ puppet_ca_proxy: null,
103
+ hostgroup_name: 'base',
104
+ hostgroup_title: 'base'
105
+ },
106
+ '7': {
107
+ ip: null,
108
+ ip6: null,
109
+ environment_id: null,
110
+ environment_name: null,
111
+ last_report: null,
112
+ mac: '00:11:22:33:60:15',
113
+ realm_id: null,
114
+ realm_name: null,
115
+ sp_mac: null,
116
+ sp_ip: null,
117
+ sp_name: null,
118
+ domain_id: 1,
119
+ domain_name: 'mylocal',
120
+ architecture_id: 1,
121
+ architecture_name: 'x86_64',
122
+ operatingsystem_id: 1,
123
+ operatingsystem_name: 'centos 7',
124
+ subnet_id: 1,
125
+ subnet_name: 'mylocal',
126
+ subnet6_id: null,
127
+ subnet6_name: null,
128
+ sp_subnet_id: null,
129
+ ptable_id: 118,
130
+ ptable_name: 'Kickstart default',
131
+ medium_id: 1,
132
+ medium_name: 'CentOS 7 mirror',
133
+ pxe_loader: 'PXELinux BIOS',
134
+ build: true,
135
+ comment: null,
136
+ disk: null,
137
+ installed_at: null,
138
+ model_id: null,
139
+ hostgroup_id: 1,
140
+ owner_id: 4,
141
+ owner_name: 'Admin User',
142
+ owner_type: 'User',
143
+ enabled: true,
144
+ managed: true,
145
+ use_image: null,
146
+ image_file: '',
147
+ uuid: null,
148
+ compute_resource_id: null,
149
+ compute_resource_name: null,
150
+ compute_profile_id: null,
151
+ compute_profile_name: null,
152
+ capabilities: [
153
+ 'build'
154
+ ],
155
+ provision_method: 'build',
156
+ certname: 'lllllll.mylocal',
157
+ image_id: null,
158
+ image_name: null,
159
+ created_at: '2021-08-19 14:00:20 +0200',
160
+ updated_at: '2021-08-19 14:00:20 +0200',
161
+ last_compile: null,
162
+ global_status: 0,
163
+ global_status_label: 'Error',
164
+ uptime_seconds: null,
165
+ organization_id: 1,
166
+ organization_name: 'Default Organization',
167
+ location_id: 2,
168
+ location_name: 'Default Location',
169
+ puppet_status: 0,
170
+ model_name: null,
171
+ build_status: 2,
172
+ build_status_label: 'Token expired',
173
+ name: 'lllllll.mylocal',
174
+ id: 7,
175
+ puppet_proxy_id: null,
176
+ puppet_proxy_name: null,
177
+ puppet_ca_proxy_id: null,
178
+ puppet_ca_proxy_name: null,
179
+ puppet_proxy: null,
180
+ puppet_ca_proxy: null,
181
+ hostgroup_name: 'base',
182
+ hostgroup_title: 'base'
183
+ }
184
+ },
185
+ availableHosts: [
186
+ {
187
+ value: 'lllllll',
188
+ label: 'lllllll'
189
+ }
190
+ ]
191
+ }