Merge "fix: remove interface number check of detach action"

This commit is contained in:
Zuul 2021-09-06 02:58:50 +00:00 committed by Gerrit Code Review
commit 2aef4e897c
2 changed files with 3 additions and 63 deletions

View File

@ -13,8 +13,7 @@
// limitations under the License. // limitations under the License.
import { ConfirmAction } from 'containers/Action'; import { ConfirmAction } from 'containers/Action';
import globalServerStore, { ServerStore } from 'stores/nova/instance'; import globalServerStore from 'stores/nova/instance';
// import { isActiveOrShutOff, isNotLocked } from 'resources/instance';
export default class Detach extends ConfirmAction { export default class Detach extends ConfirmAction {
get id() { get id() {
@ -39,50 +38,10 @@ export default class Detach extends ConfirmAction {
policy = 'os_compute_api:os-attach-interfaces:delete'; policy = 'os_compute_api:os-attach-interfaces:delete';
hasMoreInterfaces(instance) { allowedCheckFunc = (item) => !!item.device_id;
let count = 0;
const { addresses } = instance;
Object.keys(addresses).forEach((key) => {
const detail = addresses[key];
count += detail.length;
});
return count > 1;
}
allowedCheckFunc = (item) => {
const flag = !!item.device_id;
const { detail } = this.containerProps;
if (detail) {
return flag && this.hasMoreInterfaces(detail);
}
// && item.instance
// && isNotLocked(item.instance) && isActiveOrShutOff(item.instance)
// && this.hasMoreInterfaces(item.instance);
// console.log(flag, item);
return flag;
};
onSubmit = async () => { onSubmit = async () => {
const { id, device_id } = this.item; const { id, device_id } = this.item;
const { detail } = this.containerProps;
if (!detail) {
const store = new ServerStore();
await store.fetchDetail({ id: device_id });
if (!this.hasMoreInterfaces(store.detail)) {
this.onlyOne = true;
this.showConfirmErrorBeforeSubmit = true;
this.confirmErrorMessageBeforeSubmit = t(
'Unable to {action}, because : {reason}, instance: {name}.',
{
action: this.actionName || this.title,
name: this.item.name,
reason: t('the instance only has one virtual adapter'),
}
);
return Promise.reject();
}
}
this.showConfirmErrorBeforeSubmit = false;
return globalServerStore.detachInterface({ id: device_id, ports: [id] }); return globalServerStore.detachInterface({ id: device_id, ports: [id] });
}; };
} }

View File

@ -40,13 +40,6 @@ export class VirtualAdapterStore extends Base {
} }
}; };
get paramsFuncPage() {
return (params) => {
const { current, withPrice, instanceAddresses, ...rest } = params;
return rest;
};
}
@observable @observable
fixed_ips = new List(); fixed_ips = new List();
@ -114,19 +107,7 @@ export class VirtualAdapterStore extends Base {
if (items.length === 0) { if (items.length === 0) {
return items; return items;
} }
const { const { device_id, device_owner, addressAsIdKey, network_id } = filters;
device_id,
device_owner,
addressAsIdKey,
network_id,
instanceAddresses,
} = filters;
if (instanceAddresses) {
items = items.map((i) => ({
...i,
instanceAddresses,
}));
}
if (device_owner || device_id || network_id) { if (device_owner || device_id || network_id) {
// fetch fixed_ips details // fetch fixed_ips details
const details = await Promise.all( const details = await Promise.all(