forked from tkestack/tke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): support vm snapshot (tkestack#2289)
* fix(console): 修复判断是否可见缺少了children的问题 * feat(console): 创建虚拟机快照 * feat(console): 支持虚拟机快照恢复 * feat(console): 添加了统一的接口错误提示 * feat(console): 支持在快照列表中显示恢复状态 * feat(console): 新建快照成功之后跳转到快照列表
- Loading branch information
Showing
15 changed files
with
558 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { z } from 'zod'; | ||
|
||
export const nameRule = (key: string) => { | ||
return z | ||
.string() | ||
.min(1, { message: `${key}不能为空` }) | ||
.max(63, { message: `${key}长度不能超过63个字符` }) | ||
.regex(/^([A-Za-z0-9][-A-Za-z0-9_./]*)?[A-Za-z0-9]$/, { message: `${key}格式不正确` }); | ||
}; |
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
79 changes: 79 additions & 0 deletions
79
...c/modules/cluster/components/resource/virtual-machine/components/createSnapshotButton.tsx
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,79 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, Modal, Form, Input } from 'tea-component'; | ||
import { useForm, Controller } from 'react-hook-form'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { nameRule } from '@config/validateConfig'; | ||
import { z } from 'zod'; | ||
import { getReactHookFormStatusWithMessage } from '@helper'; | ||
import { virtualMachineAPI } from '@src/webApi'; | ||
|
||
export const CreateSnapshotButton = ({ clusterId, namespace, name, onSuccess = () => {}, disabled }) => { | ||
const [visible, setVisible] = useState(false); | ||
|
||
const { control, handleSubmit, reset } = useForm({ | ||
mode: 'onBlur', | ||
defaultValues: { | ||
snapshotName: '' | ||
}, | ||
resolver: zodResolver(z.object({ snapshotName: nameRule('快照名称') })) | ||
}); | ||
|
||
function onCancel() { | ||
setVisible(false); | ||
|
||
reset(); | ||
} | ||
|
||
async function onSubmit({ snapshotName }) { | ||
console.log('snapshot name', snapshotName); | ||
|
||
try { | ||
await virtualMachineAPI.createSnapshot({ | ||
clusterId, | ||
namespace, | ||
vmName: name, | ||
name: snapshotName | ||
}); | ||
|
||
onCancel(); | ||
onSuccess(); | ||
} catch (error) { | ||
console.log('create snapshot error:', error); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<Button type="link" onClick={() => setVisible(true)} disabled={disabled}> | ||
新建快照 | ||
</Button> | ||
|
||
<Modal caption="新建虚拟机快照" visible={visible} onClose={onCancel}> | ||
<Modal.Body> | ||
<Form> | ||
<Controller | ||
control={control} | ||
name="snapshotName" | ||
render={({ field, ...other }) => ( | ||
<Form.Item | ||
label="快照名称" | ||
extra="快照名称不能超过63个字符" | ||
{...getReactHookFormStatusWithMessage(other)} | ||
> | ||
<Input {...field} /> | ||
</Form.Item> | ||
)} | ||
/> | ||
</Form> | ||
</Modal.Body> | ||
|
||
<Modal.Footer> | ||
<Button type="primary" onClick={handleSubmit(onSubmit)}> | ||
确认 | ||
</Button> | ||
<Button onClick={onCancel}>取消</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
</> | ||
); | ||
}; |
15 changes: 15 additions & 0 deletions
15
.../src/modules/cluster/components/resource/virtual-machine/components/delSnapshotButton.tsx
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,15 @@ | ||
import React from 'react'; | ||
import { ActionButton } from './actionButton'; | ||
import { virtualMachineAPI } from '@src/webApi'; | ||
|
||
export const DelSnapshotButton = ({ type, clusterId, namespace, name, onSuccess = () => {} }) => { | ||
function del() { | ||
return virtualMachineAPI.delSnapshot({ clusterId, namespace, name }); | ||
} | ||
|
||
return ( | ||
<ActionButton type={type} title={`你确定要删除快照“${name}”吗?`} confirm={del} onSuccess={onSuccess}> | ||
删除 | ||
</ActionButton> | ||
); | ||
}; |
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
40 changes: 40 additions & 0 deletions
40
...modules/cluster/components/resource/virtual-machine/components/recoverySnapshotButton.tsx
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,40 @@ | ||
import React from 'react'; | ||
import { ActionButton } from './actionButton'; | ||
import { virtualMachineAPI } from '@src/webApi'; | ||
import { Text, Alert } from 'tea-component'; | ||
|
||
export const RecoverySnapshotButton = ({ | ||
type, | ||
clusterId, | ||
namespace, | ||
name, | ||
vmName, | ||
disabled, | ||
onSuccess = () => {} | ||
}) => { | ||
function recovery() { | ||
return virtualMachineAPI.recoverySnapshot({ clusterId, namespace, name, vmName }); | ||
} | ||
|
||
return ( | ||
<ActionButton | ||
type={type} | ||
title={`恢复快照`} | ||
confirm={recovery} | ||
onSuccess={onSuccess} | ||
disabled={disabled} | ||
body={ | ||
<> | ||
<Alert type="warning">请确保虚拟机处于关机状态!</Alert> | ||
<Text parent="p"> | ||
您将要对虚拟机<Text theme="warning">{vmName}</Text>恢复快照<Text theme="warning">{name}</Text>, | ||
恢复操作将会覆盖当前状态下虚拟机数据 | ||
</Text> | ||
<Text parent="p">您是否要继续执行?</Text> | ||
</> | ||
} | ||
> | ||
恢复 | ||
</ActionButton> | ||
); | ||
}; |
2 changes: 2 additions & 0 deletions
2
web/console/src/modules/cluster/components/resource/virtual-machine/index.tsx
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export { VMListPanel } from './pages/list'; | ||
export { VMCreatePanel } from './pages/create'; | ||
export { VMDetailPanel } from './pages/detail'; | ||
|
||
export { SnapshotTablePanel } from './pages//snapshotTablePanel/snapTablePanel'; |
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
Oops, something went wrong.