Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

[#607] Make OSP Instance Properties step compatible with Edit Plan and enable Edit Plan #674

Merged
merged 3 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class MigrationsNotStartedList extends React.Component {
if (!editPlanDisabled) showPlanWizardEditModeAction(plan.id);
}}
disabled={editPlanDisabled}
style={{ display: 'none' }} // Edit Plan is disabled until https://github.com/ManageIQ/manageiq/pull/17989 is ready
>
{__('Edit')}
</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class PlanWizardInstancePropertiesStep extends Component {
instancePropertiesRowsAction,
bestFitFlavorAction,
bestFitFlavorUrl,
recalculateBestFitFlavorAndSecurityGroup
recalculateBestFitFlavorAndSecurityGroup,
editingPlan
} = this.props;

const targetTenants =
Expand All @@ -39,7 +40,7 @@ class PlanWizardInstancePropertiesStep extends Component {
});
});

bestFitFlavorAction(bestFitFlavorUrl, sourceAndDestinationHrefSlugsForBestFit);
bestFitFlavorAction(bestFitFlavorUrl, sourceAndDestinationHrefSlugsForBestFit, editingPlan);
}
);

Expand Down Expand Up @@ -106,7 +107,8 @@ PlanWizardInstancePropertiesStep.propTypes = {
instancePropertiesRows: PropTypes.array,
bestFitFlavorUrl: PropTypes.string,
recalculateBestFitFlavorAndSecurityGroup: PropTypes.bool,
bestFitFlavors: PropTypes.array
bestFitFlavors: PropTypes.array,
editingPlan: PropTypes.object
};

PlanWizardInstancePropertiesStep.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const queryTenantsWithAttributesAction = (url, tenantIds, attributes) =>
return _getTenantWithAttributesActionCreator(uri.toString(), tenantIds);
};

export const setFlavorsAndSecurityGroups = (response, mappings, dispatch) => {
export const setFlavorsAndSecurityGroups = (response, mappings, editingPlan, dispatch) => {
const vmsSlugPrefix = 'vms/';
const flavorsSlugPrefix = 'flavors/';
const cloudTenantsSlugPrefix = 'cloud_tenants/';
Expand All @@ -41,11 +41,11 @@ export const setFlavorsAndSecurityGroups = (response, mappings, dispatch) => {

dispatch({
type: SET_V2V_BEST_FIT_FLAVORS_AND_DEFAULT_SECURITY_GROUPS,
payload: vmBestFitFlavors
payload: { vmBestFitFlavors, editingPlan }
});
};

export const _bestFitFlavorActionCreator = (url, flavor_mappings) => dispatch => {
export const _bestFitFlavorActionCreator = (url, flavor_mappings, editingPlan) => dispatch => {
const postBody = {
action: 'vm_flavor_fit',
mappings: flavor_mappings
Expand All @@ -56,7 +56,7 @@ export const _bestFitFlavorActionCreator = (url, flavor_mappings) => dispatch =>
API.post(url, postBody)
.then(response => {
resolve(response);
setFlavorsAndSecurityGroups(response, flavor_mappings, dispatch);
setFlavorsAndSecurityGroups(response, flavor_mappings, editingPlan, dispatch);
})
.catch(e => {
reject(e);
Expand All @@ -65,9 +65,9 @@ export const _bestFitFlavorActionCreator = (url, flavor_mappings) => dispatch =>
});
};

export const bestFitFlavorAction = (url, mappings) => {
export const bestFitFlavorAction = (url, mappings, editingPlan) => {
const uri = new URI(url);
return _bestFitFlavorActionCreator(uri.toString(), mappings);
return _bestFitFlavorActionCreator(uri.toString(), mappings, editingPlan);
};

export const instancePropertiesRowsAction = rows => dispatch =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ export default (state = initialState, action) => {
.set('isFetchingBestFitFlavor', false)
.set('isRejectedBestFitFlavor', true);
case SET_V2V_BEST_FIT_FLAVORS_AND_DEFAULT_SECURITY_GROUPS: {
const vmBestFitFlavors = action.payload;
const { vmBestFitFlavors, editingPlan } = action.payload;
const instancePropertiesRowsUpdatedWithBestFlavor = [];
vmBestFitFlavors.forEach(vmFlavor => {
const existingInstancePropertiesRow = state.instancePropertiesRows.find(row => row.id === vmFlavor.vm_id);
const tenant = state.tenantsWithAttributes.find(
tenantsWithAttribute => tenantsWithAttribute.id === vmFlavor.tenant_id
);
const tenantFlavors = tenant && tenant.flavors;
const tenantSecurityGroups = tenant && tenant.security_groups;

let bestFitFlavor;
let bestFitFlavorId = vmFlavor.flavor_id;
Expand All @@ -85,10 +86,29 @@ export default (state = initialState, action) => {
const defaultSecurityGroupId = defaultSecurityGroup && defaultSecurityGroup.id;
const defaultSecurityGroupName = defaultSecurityGroup && defaultSecurityGroup.name;

const bestFlavor = { name: bestFitFlavorName, id: bestFitFlavorId };
const bestGroup = { name: defaultSecurityGroupName, id: defaultSecurityGroupId };

let preselectedFlavor;
let preselectedGroup;

if (editingPlan) {
const existingVm = editingPlan.options.config_info.actions.find(
vm => vm.vm_id === existingInstancePropertiesRow.id
);
if (existingVm) {
const existingFlavor = tenantFlavors && tenantFlavors.find(flavor => flavor.id === existingVm.osp_flavor);
const existingGroup =
tenantSecurityGroups && tenantSecurityGroups.find(group => group.id === existingVm.osp_security_group);
preselectedFlavor = existingFlavor && { name: existingFlavor.name, id: existingFlavor.id };
preselectedGroup = existingGroup && { name: existingGroup.name, id: existingGroup.id };
}
}

const rowUpdatedWithBestFlavor = {
...existingInstancePropertiesRow,
osp_flavor: { name: bestFitFlavorName, id: bestFitFlavorId },
osp_security_group: { name: defaultSecurityGroupName, id: defaultSecurityGroupId },
osp_flavor: preselectedFlavor || bestFlavor,
osp_security_group: preselectedGroup || bestGroup,
target_cluster_name: tenant.name
};
instancePropertiesRowsUpdatedWithBestFlavor.push(rowUpdatedWithBestFlavor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import PlanWizardInstancePropertiesStep from './PlanWizardInstancePropertiesStep
import * as PlanWizardInstancePropertiesStepActions from './PlanWizardInstancePropertiesStepActions';
import reducer from './PlanWizardInstancePropertiesStepReducer';
import { getVMStepSelectedVms } from '../PlanWizardAdvancedOptionsStep/helpers';
import { findEditingPlan } from '../../PlanWizardSelectors';

export const reducers = { planWizardInstancePropertiesStep: reducer };

const mapStateToProps = (
{
overview: { transformationMappings },
overview: { transformationMappings, transformationPlans, editingPlanId },
planWizardInstancePropertiesStep,
planWizardVMStep,
form: {
Expand All @@ -24,10 +25,11 @@ const mapStateToProps = (
},
ownProps
) => {
const editingPlan = findEditingPlan(transformationPlans, editingPlanId);
const allVms =
vm_choice_radio === 'vms_via_csv'
? [...planWizardVMStep.valid_vms, ...planWizardVMStep.invalid_vms, ...planWizardVMStep.conflict_vms]
: planWizardVMStep.valid_vms;
: [...planWizardVMStep.preselected_vms, ...planWizardVMStep.valid_vms];
const selectedMapping =
transformationMappings &&
infrastructure_mapping &&
Expand All @@ -41,7 +43,8 @@ const mapStateToProps = (
osp_security_group: {},
osp_flavor: {}
})),
selectedMapping
selectedMapping,
editingPlan
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const _queryPreselectedVmsActionCreator = ids => dispatch => {
return dispatch({
type: QUERY_V2V_PLAN_VMS,
payload: API.post(
'/api/vms?expand=resources&attributes=name,ems_cluster.name,allocated_disk_storage,ext_management_system.name,v_parent_blue_folder_display_path',
'/api/vms?expand=resources&attributes=name,ems_cluster.name,ems_cluster.id,allocated_disk_storage,ext_management_system.name,v_parent_blue_folder_display_path',
{
action: 'query',
resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const _formatPreselectedVms = vmsQueryResults =>
id: result.id,
name: result.name,
cluster: result.ems_cluster ? result.ems_cluster.name : '',
ems_cluster_id: result.ems_cluster ? result.ems_cluster.id : '',
path: result.ext_management_system
? `${result.ext_management_system.name}/${result.v_parent_blue_folder_display_path}`
: '',
Expand Down