This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
/
PlanWizardInstancePropertiesStep.js
134 lines (121 loc) · 4.83 KB
/
PlanWizardInstancePropertiesStep.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { reduxForm, Field } from 'redux-form';
import PlanWizardInstancePropertiesStepTable from './components/PlanWizardInstancePropertiesStepTable';
import { OSP_TENANT } from '../../../../OverviewConstants';
import { getTenantsById, getDestinationTenantIdsBySourceClusterId } from './helpers';
class PlanWizardInstancePropertiesStep extends Component {
componentDidMount() {
const {
selectedMapping,
fetchOpenstackTenantUrl,
queryOpenstackTenantAttributes,
queryTenantsWithAttributesAction,
vmStepSelectedVms,
instancePropertiesRowsAction,
bestFitFlavorAction,
bestFitFlavorUrl,
recalculateBestFitFlavorAndSecurityGroup,
editingPlan,
shouldPrefillForEditing
} = this.props;
const targetTenants =
selectedMapping &&
selectedMapping.transformation_mapping_items &&
selectedMapping.transformation_mapping_items.filter(item => item.destination_type === OSP_TENANT);
if (targetTenants && recalculateBestFitFlavorAndSecurityGroup) {
const targetTenantIds = targetTenants.map(tenant => tenant.destination_id);
queryTenantsWithAttributesAction(fetchOpenstackTenantUrl, targetTenantIds, queryOpenstackTenantAttributes).then(
() => {
const sourceAndDestinationHrefSlugsForBestFit = [];
vmStepSelectedVms.forEach(vm => {
const destinationTenantId = targetTenants.filter(tenant => tenant.source_id === vm.ems_cluster_id)[0]
.destination_id;
sourceAndDestinationHrefSlugsForBestFit.push({
source_href_slug: `vms/${vm.id}`,
destination_href_slug: `cloud_tenants/${destinationTenantId}`
});
});
bestFitFlavorAction(
bestFitFlavorUrl,
sourceAndDestinationHrefSlugsForBestFit,
shouldPrefillForEditing && editingPlan
);
}
);
instancePropertiesRowsAction(vmStepSelectedVms);
}
}
render() {
const {
isFetchingTenantsWithAttributes,
tenantsWithAttributes,
selectedMapping,
instancePropertiesRows,
isSettingSecurityGroupsAndBestFitFlavors,
updatedInstancePropertiesRowOnStandby,
instancePropertiesRowsAction,
bestFitFlavors
} = this.props;
if (isFetchingTenantsWithAttributes || isSettingSecurityGroupsAndBestFitFlavors) {
return (
<div className="blank-slate-pf">
<div className="spinner spinner-lg blank-slate-pf-icon" />
<h3 className="blank-slate-pf-main-action">{__('Loading OpenStack Properties...')}</h3>
</div>
);
}
const tenantsWithAttributesById = getTenantsById(tenantsWithAttributes);
const destinationTenantIdsBySourceClusterId = getDestinationTenantIdsBySourceClusterId(
selectedMapping.transformation_mapping_items
);
return (
<Field
name="instancePropertiesVms"
component={PlanWizardInstancePropertiesStepTable}
rows={instancePropertiesRows}
tenantsWithAttributesById={tenantsWithAttributesById}
destinationTenantIdsBySourceClusterId={destinationTenantIdsBySourceClusterId}
updatedInstancePropertiesRowOnStandby={updatedInstancePropertiesRowOnStandby}
instancePropertiesRowsAction={instancePropertiesRowsAction}
bestFitFlavors={bestFitFlavors}
validate={value =>
value.updatedInstancePropertiesRowOnStandby && value.updatedInstancePropertiesRowOnStandby.id
}
/>
);
}
}
PlanWizardInstancePropertiesStep.propTypes = {
vmStepSelectedVms: PropTypes.array,
selectedMapping: PropTypes.object,
fetchOpenstackTenantUrl: PropTypes.string,
queryOpenstackTenantAttributes: PropTypes.arrayOf(PropTypes.string),
queryTenantsWithAttributesAction: PropTypes.func,
tenantsWithAttributes: PropTypes.array,
isFetchingTenantsWithAttributes: PropTypes.bool,
instancePropertiesRowsAction: PropTypes.func,
bestFitFlavorAction: PropTypes.func,
isSettingSecurityGroupsAndBestFitFlavors: PropTypes.bool,
updatedInstancePropertiesRowOnStandby: PropTypes.object,
instancePropertiesRows: PropTypes.array,
bestFitFlavorUrl: PropTypes.string,
recalculateBestFitFlavorAndSecurityGroup: PropTypes.bool,
bestFitFlavors: PropTypes.array,
editingPlan: PropTypes.object,
shouldPrefillForEditing: PropTypes.bool
};
PlanWizardInstancePropertiesStep.defaultProps = {
fetchOpenstackTenantUrl: '/api/cloud_tenants',
bestFitFlavorUrl: '/api/transformation_mappings',
queryOpenstackTenantAttributes: ['flavors', 'security_groups', 'default_security_group']
};
export default reduxForm({
form: 'planWizardInstancePropertiesStep',
initialValues: {
instancePropertiesVms: {
updatedInstancePropertiesRowOnStandby: {}
}
},
destroyOnUnmount: false
})(PlanWizardInstancePropertiesStep);