高晓庄
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 详细设计文档 ## 一、总体设计 ### 1.1 总体说明 #### 1.1.1 需求概述 #### 1.1.2 运行环境简介 #### 1.1.3 设计分工说明 ### 1.2 核心流程设计 ## 二、数据库设计 ### 1、ER图 ![api_web_er.drawio](https://gitlab.bingosoft.net/bcc-knowledge-image-public/bcc-knowledge-image-public/raw/master/1658366171.png) ### 2、sql脚本 [初始化数据库sql脚本](./sql/api_web.sql) ## 三、镜像 ### 1、列表 - **请求路径** ```/api/v1/images/list``` - **请求类型** GET - **请求参数** | 名称 | 参数类型 | 是否必填 | 描述 | | ----------- | -------- | -------- | ------------ | | filter_name | string | 否 | 模糊过滤名称 | | page_num | int | 否 | 页码 | | page_size | int | 否 | 页码 | - **返回参数** | 名称 | 参数类型 | 描述 | | ----------- | -------- | -------- | | image_id | string | 镜像ID | | image_name | string | 镜像名称 | | image_size | uint64 | 镜像大小 | | create_time | uint64 | 创建时间 | - **数据库操作** ```sql SELECT image_id, image_name, image_size describe, create_time FROM api_web.image; ``` ### 2、详情 - **请求路径** ```/api/v1/images/inspect``` - **请求类型** GET - **请求参数** | 名称 | 参数类型 | 是否必填 | 描述 | | -------- | -------- | -------- | ------ | | image_id | string | 是 | 镜像ID | - **返回参数** | 名称 | 参数类型 | 描述 | | ----------- | -------- | -------- | | image_id | string | 镜像ID | | image_name | string | 镜像名称 | | image_size | uint64 | 镜像大小 | | create_time | uint64 | 创建时间 | | os_type | string | 操作系统 | | describe | string | 镜像描述 | - **数据库操作** ```sql SELECT image_id, image_name, image_size,os_type, describe, create_time FROM api_web.image Where image_id=【image_id】; ``` ### 3、创建 - **请求路径** ```/api/v1/images/create``` - **请求类型** POST - **请求参数** | 名称 | 参数类型 | 是否必填 | 描述 | | ---------- | -------- | -------- | ------------------------- | | image_name | string | 是 | 镜像名称 | | image_size | uint64 | 是 | 镜像大小(B) | | os_type | string | 是 | 操作系统(Linux或者Window) | | describe | string | 否 | 镜像描述 | - **后端命令** ```qemu-img create -f rbd rbd:images/ami-AB112345 2G ``` - **数据库操作** ```sql SELECT image_id, image_name, image_size,os_type, describe, create_time FROM api_web.image Where image_id=【image_id】; ``` ![image-20220721155825727](/home/zhangqi/.config/Typora/typora-user-images/image-20220721155825727.png) ### 4、注册 - **请求路径** ```/api/v1/images/register``` - **请求类型** POST - **请求参数** | 名称 | 参数类型 | 是否必填 | 描述 | | ---------- | -------- | -------- | --------------------------------------------------------- | | image_name | string | 是 | 镜像名称 | | image_size | uint64 | 是 | 镜像大小(B) | | os_type | string | 是 | 操作系统(Linux或者Window) | | image_id | string | 是 | 镜像ID, 通过```/api/v1/unregister_images/list```接口获取 | | describe | string | 否 | 镜像描述 | `将ceph镜像池中未注册的镜像,注册到云平台端的数据库中。` ### 5、未注册镜像列表 - **请求路径** ```/api/v1/unregister_images/list``` - **请求类型** GET - **后端命令** ```rbd ls images ``` - **数据库操作** ``` SELECT image_id FROM api_web.image;``` ```bash 获取ceph镜像池中镜像,然后过滤出为注册到平台端数据库中的镜像数据,返回image_id给前端 ``` ### 6、修改 - **请求路径** ```/api/v1/images/update``` - **请求类型** POST - **请求参数** | 名称 | 参数类型 | 是否必填 | 描述 | | ---------- | -------- | -------- | ----------------------------- | | image_id | string | 是 | 镜像ID | | describe | string | 否 | 修改描述 | | os_type | string | 否 | 修改操作系统(Linux或者Window) | | image_name | string | 否 | 修改名称 | - **数据库操作** ```sql UPDATE api_web.image SET image_name='',`describe`='',`os_type`='' WHERE image_id='0'; ``` ### 7、反注册 - **请求路径** ```/api/v1/images/delete``` - **请求类型** POST - **请求参数** | 名称 | 参数类型 | 是否必填 | 描述 | | -------- | -------- | -------- | ---------------- | | image_id | string | 是 | 镜像ID | | del_file | bool | 否 | 是否删除镜像文件 | - **删除镜像文件** ```bash rbd remove --pool images --image [镜像名称] ``` - **数据库操作** ```sql DELETE FROM api_web.image WHERE image_id='0'; ``` ![image-20220721163213463](/home/zhangqi/.config/Typora/typora-user-images/image-20220721163213463.png) ## 四、存储卷 ### 1、查询 - **请求路径** ```/api/v1/volume/list``` - **请求类型** GET - **请求参数** | 名称 | 参数类型 | 是否必填 | 描述 | | ----------- | -------- | -------- | ------------ | | filter_name | string | 否 | 模糊过滤名称 | | page_num | int | 否 | 页码 | | page_size | int | 否 | 页码 | - **返回参数** | 名称 | 参数类型 | 描述 | | ----------- | -------- | ---------- | | volume_id | string | 存储卷ID | | volume_name | string | 存储卷名称 | | volume_size | uint64 | 存储卷大小 | | create_time | uint64 | 创建时间 | | instance_id | string | 挂接实例id | | status | string | 存储卷状态 | | describe | string | 描述信息 | - **数据库操作** ```sql SELECT volume_id, volume_name, volume_size, instance_id, describe, create_time ,status FROM api_web.volume; ``` ### 2、创建 - **请求路径** ```/api/v1/volume/create ``` - **请求类型** POST - **请求参数** | 名称 | 参数类型 | 是否必填 | 描述 | | ----------- | -------- | -------- | ---------- | | volume_name | string | 是 | 存储卷名称 | | volume_size | int | 是 | 存储卷大小 | | describe | string | 否 | 描述信息 | - **返回参数** - **数据库操作** ```sql INSERT INTO api_web.volume (volume_id, volume_name, volume_size, `describe`, create_time) VALUES('0', '', 0, '0', '', CURRENT_TIMESTAMP); ``` - **初始化操作** > ```bash > ceph osd pool create volumes 64 64 > ceph osd pool create images 64 64 > rbd pool init volumes > rbd pool init images > ``` - **命令操作** ```bash qemu-img create -f rbd rbd:volumes/vol-123456 2G ``` ![image-20220721091230285](https://gitlab.bingosoft.net/bcc-knowledge-image-public/bcc-knowledge-image-public/raw/master/1658367301.png) ### 3、挂载/卸载 - **请求路径** ```/api/v1/volume/mount``` ```/api/v1/volume/unmount``` - **请求类型** POST - **请求参数** | 名称 | 参数类型 | 是否必填 | 描述 | | ----------- | -------- | -------- | -------- | | volume_id | string | 是 | 存储卷ID | | instance_id | string | 是 | 实例ID | - **返回参数** - **数据库操作** ```sql UPDATE api_web.volume SET status='', instance_id='' WHERE volume_id='0'; ``` - **命令操作** ```bash vim vol-123456.xml ``` ```xml <disk type='network' device='disk'> <driver name='qemu' type='raw' cache='none' io='native'/> <source protocol='rbd' name='volumes/vol-123456'> <host name='192.168.51.133' port='6789'/> </source> <target dev='vdb' bus='virtio'/> <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/> </disk> ``` ```bash # 挂载 virsh attach-device --domain i-123456 vol-123456.xml --live --config # 成功验证 # Disk attached successfully # 卸载 virsh detach-device --domain i-123456 vol-123456.xml --live --config # 成功验证 # Disk detached successfully ``` - **挂载流程** ![image-20220720111415558](https://gitlab.bingosoft.net/bcc-knowledge-image-public/bcc-knowledge-image-public/raw/master/1658287848.png) - **卸载流程** ![image-20220720111631517](https://gitlab.bingosoft.net/bcc-knowledge-image-public/bcc-knowledge-image-public/raw/master/1658287856.png) ### 4、删除 - **请求路径** ```/api/v1/volume/delete``` - **请求类型** GET - **请求参数** | 名称 | 参数类型 | 是否必填 | 描述 | | --------- | -------- | -------- | -------- | | volume_id | string | 是 | 存储卷ID | - **返回参数** - **数据库操作** ```sql DELETE FROM api_web.volume WHERE volume_id='0'; ``` - **命令操作** ```bash rbd rm pool_name/volume_name ``` - **删除卷流程** ![image-20220720113134691](https://gitlab.bingosoft.net/bcc-knowledge-image-public/bcc-knowledge-image-public/raw/master/1658287898.png) ## 五、网卡 ### 1、查询 ```/api/v1/network/list``` ```/api/v1/network/search``` 分页查询数据库记录(ID,名称,mac,挂接状态,挂接实例id,挂接实例名称,挂接时间,创建时间,描述信息) ```sql SELECT network_interface_id, network_interface_name, instance_id, ip, mac, status, create_time FROM api_web.network_interface; ``` ### 2、创建 ```/api/v1/network/create``` 执行命令,创建数据库记录 ```sql INSERT INTO api_web.network_interface (network_interface_id, network_interface_name, instance_id, ip, mac, status, create_time) VALUES('0', '', '0', '', '', '', CURRENT_TIMESTAMP); ``` ![image-20220720145807375](https://gitlab.bingosoft.net/bcc-knowledge-image-public/bcc-knowledge-image-public/raw/master/1658370875.png) ### 3、挂载/卸载 ```/api/v1/network/attach``` ```/api/v1/network/detach``` 执行命令,修改数据库记录(挂接状态,挂接实例id,挂接实例名称,挂接时间) ```sql UPDATE api_web.network_interface SET status='' WHERE network_interface_id='0'; ``` 挂载: ```bash # virsh attach-interface 实例名 --type bridge --source 网卡名 --mac 指定mac地址 --live 验证 # virsh domiflist 实例名 ``` ![image-20220721133027782](https://gitlab.bingosoft.net/bcc-knowledge-image-public/bcc-knowledge-image-public/raw/master/1658381430.png) 卸载: ```bash  # virsh detach-interface 实例名 --mac mac地址 --type bridge --live 验证 # virsh domiflist 实例名 ``` ![image-20220721133044769](https://gitlab.bingosoft.net/bcc-knowledge-image-public/bcc-knowledge-image-public/raw/master/1658381446.png) ### 4、删除 ```/api/v1/network/delete``` 状态闲置可删除,执行命令,删除数据库记录 ```sql DELETE FROM api_web.volume WHERE volume_id='0'; ``` ## 六、实例 ### 1、查询 ```/api/v1/instance/list``` ```/api/v1/instance/search``` 查询数据库记录(ID,名称,状态,IP,HostIP,CPU,内存,网卡,存储卷,描述信息,创建时间) ```sql SELECT instance_id, instance_name, status, ip, host_ip, cpu, memory, `describe`, create_time, image_id FROM api_web.`instance`; ``` ### 2、详情 ```/api/v1/instance/detail``` 查询数据库记录 ```sql SELECT instance_name, status, ip, host_ip, cpu, memory, describe, create_time, image_id FROM api_web.instance WHERE instance_id='0'; SELECT image_name, image_location, image_size, `describe`, create_time FROM api_web.image WHERE image_id='0'; SELECT volume_name, volume_size, instance_id, `describe`, create_time FROM api_web.volume WHERE volume_id='0'; SELECT network_interface_name, instance_id, ip, mac, status, create_time FROM api_web.network_interface WHERE volume_id='0'; ``` ### 3、创建 ```/api/v1/instance/create``` ```/api/v1/instance/progress``` 存储卷(创建,选择)、cpu、内存 创建数据库记录 ```sql INSERT INTO api_web.`instance` (instance_id, instance_name, status, ip, host_ip, cpu, memory, `describe`, create_time, image_id) VALUES('0', '', '', '', '', 0, 0, '', CURRENT_TIMESTAMP, ''); ``` ![image-20220720170255547](https://gitlab.bingosoft.net/bcc-knowledge-image-public/bcc-knowledge-image-public/raw/master/1658307775.png) >xmerl XML解析器: *https://cloud.tencent.com/developer/chapter/12415* ### 4、开机/关机 ```/api/v1/instance/turnon``` ```/api/v1/instance/turnoff``` 执行命令,修改数据库记录(状态) ```ba virsh start i-123456 vrish shutdown i-123456 ``` ```sql UPDATE api_web.`instance` SET status='开机/关机' WHERE instance_id='0'; ``` ### 5、销毁 ```/api/v1/instance/destory``` 执行命令,删除数据库记录 ```bash virsh undefine i-123456 ##删除存储卷、网卡 ``` ```sql UPDATE api_web.`instance` SET status='销毁中' WHERE instance_id='0'; DELETE FROM api_web.`instance` WHERE instance_id='0'; ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully