网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
企业连接 EC
云原生应用网络 ANC
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 CTC
边缘安全 EdgeSec
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
Haydn解决方案工厂
数字化诊断治理专家服务
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts 盘古助手
华为云Astro大屏应用
计算
弹性云服务器 ECS
Flexus云服务
裸金属服务器 BMS
云手机服务器 CPH
专属主机 DeH
弹性伸缩 AS
镜像服务 IMS
函数工作流 FunctionGraph
云耀云服务器(旧版)
VR云渲游平台 CVR
Huawei Cloud EulerOS
云化数据中心 CloudDC
网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
企业连接 EC
云原生应用网络 ANC
CDN与智能边缘
内容分发网络 CDN
智能边缘云 IEC
智能边缘平台 IEF
CloudPond云服务
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 CTC
边缘安全 EdgeSec
大数据
MapReduce服务 MRS
数据湖探索 DLI
表格存储服务 CloudTable
可信智能计算服务 TICS
推荐系统 RES
云搜索服务 CSS
数据可视化 DLV
数据接入服务 DIS
数据仓库服务 GaussDB(DWS)
数据治理中心 DataArts Studio
湖仓构建 LakeFormation
智能数据洞察 DataArts Insight
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
开天aPaaS
应用平台 AppStage
开天企业工作台 MSSE
开天集成工作台 MSSI
API中心 API Hub
云消息服务 KooMessage
交换数据空间 EDS
云地图服务 KooMap
云手机服务 KooPhone
组织成员账号 OrgID
云空间服务 KooDrive
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
区块链
区块链服务 BCS
数字资产链 DAC
华为云区块链引擎服务 HBS
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
Haydn解决方案工厂
数字化诊断治理专家服务
价格
成本优化最佳实践
专属云商业逻辑
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
其他
管理控制台
消息中心
产品价格详情
系统权限
客户关联华为云合作伙伴须知
公共问题
宽限期保留期
奖励推广计划
活动
云服务信任体系能力说明
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts 盘古助手
华为云Astro大屏应用
存储
对象存储服务 OBS
云硬盘 EVS
云备份 CBR
高性能弹性文件服务 SFS Turbo
弹性文件服务 SFS
存储容灾服务 SDRS
云硬盘备份 VBS
云服务器备份 CSBS
数据快递服务 DES
云存储网关 CSG
专属分布式存储服务 DSS
数据工坊 DWR
地图数据 MapDS
键值存储服务 KVS
容器
云容器引擎 CCE
云容器实例 CCI
容器镜像服务 SWR
云原生服务中心 OSC
应用服务网格 ASM
华为云UCS
数据库
云数据库 RDS
数据复制服务 DRS
文档数据库服务 DDS
分布式数据库中间件 DDM
云数据库 GaussDB
云数据库 GeminiDB
数据管理服务 DAS
数据库和应用迁移 UGO
云数据库 TaurusDB
人工智能
AI开发平台ModelArts
华为HiLens
图引擎服务 GES
图像识别 Image
文字识别 OCR
自然语言处理 NLP
内容审核 Moderation
图像搜索 ImageSearch
医疗智能体 EIHealth
企业级AI应用开发专业套件 ModelArts Pro
人脸识别服务 FRS
对话机器人服务 CBS
语音交互服务 SIS
人证核身服务 IVS
视频智能分析服务 VIAS
城市智能体
自动驾驶云服务 Octopus
盘古大模型 PanguLargeModels
IoT物联网
设备接入 IoTDA
全球SIM联接 GSL
IoT数据分析 IoTA
路网数字化服务 DRIS
IoT边缘 IoTEdge
设备发放 IoTDP
企业应用
域名注册服务 Domains
云解析服务 DNS
企业门户 EWP
ICP备案
商标注册
华为云WeLink
华为云会议 Meeting
隐私保护通话 PrivateNumber
语音通话 VoiceCall
消息&短信 MSGSMS
云管理网络
SD-WAN 云服务
边缘数据中心管理 EDCM
云桌面 Workspace
应用与数据集成平台 ROMA Connect
ROMA资产中心 ROMA Exchange
API全生命周期管理 ROMA API
政企自服务管理 ESM
视频
实时音视频 SparkRTC
视频直播 Live
视频点播 VOD
媒体处理 MPC
视频接入服务 VIS
数字内容生产线 MetaStudio
迁移
主机迁移服务 SMS
对象存储迁移服务 OMS
云数据迁移 CDM
迁移中心 MGC
专属云
专属计算集群 DCC
开发者工具
SDK开发指南
API签名指南
DevStar
华为云命令行工具服务 KooCLI
Huawei Cloud Toolkit
CodeArts API
云化转型
云架构中心
云采用框架
用户服务
账号中心
费用中心
成本中心
资源中心
企业管理
工单管理
客户运营能力
国际站常见问题
支持计划
专业服务
合作伙伴支持计划
我的凭证
华为云公共事业服务云平台
工业软件
工业数字模型驱动引擎
硬件开发工具链平台云服务
工业数据转换引擎云服务

更新磁盘信息

更新时间:2025-01-21 GMT+08:00
分享

功能介绍

更新服务器的磁盘信息,此接口会把服务器原有磁盘信息清空,然后更新成新磁盘信息。

调用方法

请参见如何调用API

URI

PUT /v3/sources/{source_id}/diskinfo

表1 路径参数

参数

是否必选

参数类型

描述

source_id

String

源端服务器ID

最小长度:0

最大长度:255

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

最小长度:1

最大长度:16384

表3 请求Body参数

参数

是否必选

参数类型

描述

disks

Array of ServerDisk objects

更新的磁盘信息

数组长度:0 - 65535

volumegroups

Array of VolumeGroups objects

更新的卷信息

数组长度:0 - 65535

btrfs_list

Array of BtrfsFileSystem objects

更新的btrfs信息

数组长度:0 - 65535

表4 ServerDisk

参数

是否必选

参数类型

描述

name

String

磁盘名称

最小长度:0

最大长度:255

partition_style

String

磁盘的分区类型,添加源端时源端磁盘必选

MBR:mbr格式

GPT:gpt格式

枚举值:

  • MBR

  • GPT

device_use

String

磁盘类型

BOOT:BOOT设备

OS:系统设备

枚举值:

  • BOOT

  • OS

size

Long

磁盘总大小,以字节为单位

最小值:0

最大值:9223372036854775807

used_size

Long

磁盘已使用大小,以字节为单位

最小值:0

最大值:9223372036854775807

physical_volumes

Array of PhysicalVolume objects

磁盘上的物理分区信息

数组长度:0 - 65535

os_disk

Boolean

是否为系统盘

relation_name

String

Linux系统 目的端ECS中与源端关联的磁盘名称

最小长度:0

最大长度:255

inode_size

Integer

inode数量

最小值:0

最大值:2147483647

表5 PhysicalVolume

参数

是否必选

参数类型

描述

device_use

String

分区类型,普通分区,启动分区,系统分区

最小长度:0

最大长度:255

file_system

String

文件系统类型

最小长度:0

最大长度:255

index

Integer

顺序

最小值:0

最大值:2147483647

mount_point

String

挂载点

最小长度:0

最大长度:255

name

String

名称,windows表示盘符,Linux表示设备号

最小长度:0

最大长度:255

size

Long

大小

最小值:0

最大值:9223372036854775807

used_size

Long

使用大小

最小值:0

最大值:9223372036854775807

inode_size

Integer

inode数量

最小值:0

最大值:2147483647

inode_nums

Long

inode节点数量

最小值:0

最大值:9223372036854775807

uuid

String

GUID,可从源端查询

最小长度:0

最大长度:255

size_per_cluster

Integer

每个cluster大小

最小值:0

最大值:2147483647

表6 VolumeGroups

参数

是否必选

参数类型

描述

components

String

Pv信息

最小长度:0

最大长度:255

free_size

Long

剩余空间

最小值:0

最大值:9223372036854775807

logical_volumes

Array of LogicalVolumes objects

lv信息

数组长度:0 - 255

name

String

名称

最小长度:0

最大长度:255

size

Long

大小

最小值:0

最大值:9223372036854775807

表7 LogicalVolumes

参数

是否必选

参数类型

描述

block_count

Integer

块数量

最小值:0

最大值:2147483647

缺省值:0

block_size

Long

块大小

最小值:0

最大值:1048576

缺省值:0

file_system

String

文件系统

最小长度:0

最大长度:255

inode_size

Integer

inode数量

最小值:0

最大值:2147483647

inode_nums

Long

inode节点数量

最小值:0

最大值:9223372036854775807

device_use

String

分区类型,普通分区,启动分区,系统分区

最小长度:0

最大长度:255

mount_point

String

挂载点

最小长度:0

最大长度:256

name

String

名称

最小长度:0

最大长度:1024

size

Long

大小

最小值:0

最大值:9223372036854775807

used_size

Long

使用大小

最小值:0

最大值:9223372036854775807

free_size

Long

剩余空间

最小值:0

最大值:9223372036854775807

表8 BtrfsFileSystem

参数

是否必选

参数类型

描述

name

String

文件系统名称

最小长度:0

最大长度:255

label

String

文件系统标签,若无标签为空字符串

最小长度:0

最大长度:255

uuid

String

文件系统的uuid

最小长度:0

最大长度:255

device

String

btrfs包含的设备名称

最小长度:0

最大长度:255

size

Long

文件系统数据占用大小

最小值:0

最大值:9223372036854775807

nodesize

Long

btrfs节点大小

最小值:0

最大值:9223372036854775807

sectorsize

Integer

扇区大小

最小值:0

最大值:2147483647

data_profile

String

数据配置(RAD)

最小长度:0

最大长度:255

system_profile

String

文件系统配置(RAD)

最小长度:0

最大长度:255

metadata_profile

String

元数据配置(RAD)

最小长度:0

最大长度:255

global_reserve1

String

Btrfs文件系统信息

最小长度:0

最大长度:255

g_vol_used_size

Long

Btrfs卷已使用空间大小

最小值:0

最大值:9223372036854775807

default_subvolid

String

默认子卷ID

最小长度:0

最大长度:255

default_subvol_name

String

默认子卷名称

最小长度:0

最大长度:255

default_subvol_mountpath

String

默认子卷挂载路径/BTRFS文件系统的挂载路径

最小长度:0

最大长度:255

subvolumn

Array of BtrfsSubvolumn objects

子卷信息

数组长度:0 - 65535

表9 BtrfsSubvolumn

参数

是否必选

参数类型

描述

uuid

String

父卷的uuid

最小长度:0

最大长度:255

is_snapshot

String

子卷是否为快照

最小长度:0

最大长度:255

subvol_id

String

子卷的ID

最小长度:0

最大长度:255

parent_id

String

父卷ID

最小长度:0

最大长度:255

subvol_name

String

子卷的名称

最小长度:0

最大长度:255

subvol_mount_path

String

子卷的挂载路径

最小长度:0

最大长度:255

响应参数

状态码: 200

表10 响应Body参数

参数

参数类型

描述

-

String

更新磁盘信息成功

状态码: 403

表11 响应Body参数

参数

参数类型

描述

error_code

String

错误代码

最小长度:0

最大长度:255

error_msg

String

错误信息

最小长度:0

最大长度:255

encoded_authorization_message

String

加密授权信息

最小长度:0

最大长度:65535

error_param

Array of strings

错误参数

最小长度:0

最大长度:65535

数组长度:1 - 20

details

Array of details objects

详细错误信息

数组长度:1 - 20

表12 details

参数

参数类型

描述

error_code

String

SMS错误代码

最小长度:0

最大长度:65535

error_msg

String

SMS错误信息

最小长度:0

最大长度:65535

请求示例

更新服务器的磁盘信息,此接口会把服务器原有磁盘信息清空,然后更新成新磁盘信息,新的磁盘名称是/dev/vda,磁盘类型是BOOT,磁盘大小是42949672960字节。

PUT https://{endpoint}/v3/sources/{source_id}/diskinfo

{
  "disks" : [ {
    "name" : "/dev/vda",
    "device_use" : "BOOT",
    "size" : 42949672960,
    "partition_style" : "MBR",
    "used_size" : 42948624384,
    "physical_volumes" : [ {
      "name" : "/dev/vda1",
      "size" : 2153775104,
      "device_use" : "NORMAL",
      "used_size" : 2153775104,
      "inode_size" : 0,
      "file_system" : "swap",
      "mount_point" : ""
    }, {
      "name" : "/dev/vda2",
      "size" : 16862150656,
      "device_use" : "BTRFS",
      "used_size" : 16862150656,
      "inode_size" : 0,
      "file_system" : "btrfs",
      "mount_point" : ""
    }, {
      "name" : "/dev/vda3",
      "size" : 23932698624,
      "device_use" : "NORMAL",
      "used_size" : 33988608,
      "inode_size" : 0,
      "file_system" : "xfs",
      "mount_point" : "/home"
    } ]
  }, {
    "name" : "/dev/vdb",
    "device_use" : "NORMAL",
    "size" : 21474836480,
    "partition_style" : "MBR",
    "used_size" : 21473787904,
    "physical_volumes" : [ {
      "name" : "/dev/vdb1",
      "size" : 21473787904,
      "device_use" : "VOLUME_GROUP",
      "used_size" : 21473787904,
      "inode_size" : 0,
      "file_system" : "LVM2_member",
      "mount_point" : ""
    } ]
  }, {
    "name" : "/dev/vdc",
    "device_use" : "VOLUME_GROUP",
    "size" : 21474836480,
    "partition_style" : "MBR",
    "used_size" : 0,
    "physical_volumes" : [ ]
  } ],
  "volumegroups" : [ {
    "name" : "vg1",
    "size" : 42948624384,
    "components" : "/dev/vdb1;/dev/vdc",
    "logical_volumes" : [ {
      "name" : "/dev/mapper/vg1-lv1",
      "device_use" : "NORMAL",
      "size" : 10737418240,
      "free_size" : 10713837568,
      "used_size" : 23580672,
      "file_system" : "ext4",
      "mount_point" : "/mnt/lv1",
      "inode_size" : 256
    } ]
  } ],
  "btrfs_list" : [ {
    "name" : "/dev/vda2",
    "label" : "none",
    "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
    "device" : "/dev/vda2",
    "size" : "3.30GiB",
    "nodesize" : 16384,
    "sectorsize" : 4096,
    "data_profile" : "single",
    "system_profile" : "single",
    "metadata_profile" : "single",
    "global_reserve1" : "single",
    "g_vol_used_size" : 3894038528,
    "default_subvolid" : 259,
    "default_subvol_name" : "@/.snapshots/1/snapshot",
    "default_subvol_mountpath" : "/",
    "subvolumn" : [ {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 257,
      "parent_id" : 5,
      "subvol_name" : "@",
      "subvol_mount_path" : null
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 258,
      "parent_id" : 257,
      "subvol_name" : "@/.snapshots",
      "subvol_mount_path" : "/.snapshots"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : true,
      "subvol_id" : 259,
      "parent_id" : 258,
      "subvol_name" : "@/.snapshots/1/snapshot",
      "subvol_mount_path" : "/"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 260,
      "parent_id" : 257,
      "subvol_name" : "@/boot/grub2/i386-pc",
      "subvol_mount_path" : "/boot/grub2/i386-pc"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 261,
      "parent_id" : 257,
      "subvol_name" : "@/boot/grub2/x86_64-efi",
      "subvol_mount_path" : "/boot/grub2/x86_64-efi"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 262,
      "parent_id" : 257,
      "subvol_name" : "@/opt",
      "subvol_mount_path" : "/opt"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 263,
      "parent_id" : 257,
      "subvol_name" : "@/srv",
      "subvol_mount_path" : "/srv"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 264,
      "parent_id" : 257,
      "subvol_name" : "@/tmp",
      "subvol_mount_path" : "/tmp"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 265,
      "parent_id" : 257,
      "subvol_name" : "@/usr/local",
      "subvol_mount_path" : "/usr/local"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 266,
      "parent_id" : 257,
      "subvol_name" : "@/var/cache",
      "subvol_mount_path" : "/var/cache"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 267,
      "parent_id" : 257,
      "subvol_name" : "@/var/crash",
      "subvol_mount_path" : "/var/crash"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 268,
      "parent_id" : 257,
      "subvol_name" : "@/var/lib/libvirt/images",
      "subvol_mount_path" : "/var/lib/libvirt/images"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 269,
      "parent_id" : 257,
      "subvol_name" : "@/var/lib/machines",
      "subvol_mount_path" : "/var/lib/machines"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 270,
      "parent_id" : 257,
      "subvol_name" : "@/var/lib/mailman",
      "subvol_mount_path" : "/var/lib/mailman"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 271,
      "parent_id" : 257,
      "subvol_name" : "@/var/lib/mariadb",
      "subvol_mount_path" : "/var/lib/mariadb"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 272,
      "parent_id" : 257,
      "subvol_name" : "@/var/lib/mysql",
      "subvol_mount_path" : "/var/lib/mysql"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 273,
      "parent_id" : 257,
      "subvol_name" : "@/var/lib/named",
      "subvol_mount_path" : "/var/lib/named"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 274,
      "parent_id" : 257,
      "subvol_name" : "@/var/lib/pgsql",
      "subvol_mount_path" : "/var/lib/pgsql"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 275,
      "parent_id" : 257,
      "subvol_name" : "@/var/log",
      "subvol_mount_path" : "/var/log"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 276,
      "parent_id" : 257,
      "subvol_name" : "@/var/opt",
      "subvol_mount_path" : "/var/opt"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 277,
      "parent_id" : 257,
      "subvol_name" : "@/var/spool",
      "subvol_mount_path" : "/var/spool"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : false,
      "subvol_id" : 278,
      "parent_id" : 257,
      "subvol_name" : "@/var/tmp",
      "subvol_mount_path" : "/var/tmp"
    }, {
      "uuid" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
      "is_snapshot" : true,
      "subvol_id" : 282,
      "parent_id" : 258,
      "subvol_name" : "@/.snapshots/2/snapshot",
      "subvol_mount_path" : null
    } ]
  } ]
}

响应示例

状态码: 403

鉴权失败

{
  "error_code" : "SMS.9004",
  "error_msg" : "The current account does not have the permission to execute policy You do not have permission to perform action XXX on resource XXX.",
  "encoded_authorization_message" : "XXXXXX",
  "error_param" : [ "You do not have permission to perform action XXX on resource XXX." ],
  "details" : [ {
    "error_code" : "SMS.9004",
    "error_msg" : "You do not have permission to perform action XXX on resource XXX."
  } ]
}

SDK代码示例

SDK代码示例如下。

更新服务器的磁盘信息,此接口会把服务器原有磁盘信息清空,然后更新成新磁盘信息,新的磁盘名称是/dev/vda,磁盘类型是BOOT,磁盘大小是42949672960字节。

  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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.sms.v3.region.SmsRegion;
import com.huaweicloud.sdk.sms.v3.*;
import com.huaweicloud.sdk.sms.v3.model.*;

import java.util.List;
import java.util.ArrayList;

public class UpdateDiskInfoSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new GlobalCredentials()
                .withAk(ak)
                .withSk(sk);

        SmsClient client = SmsClient.newBuilder()
                .withCredential(auth)
                .withRegion(SmsRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateDiskInfoRequest request = new UpdateDiskInfoRequest();
        request.withSourceId("{source_id}");
        PutDiskInfoReq body = new PutDiskInfoReq();
        List<BtrfsSubvolumn> listBtrfsListSubvolumn = new ArrayList<>();
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("257")
                .withParentId("5")
                .withSubvolName("@")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("258")
                .withParentId("257")
                .withSubvolName("@/.snapshots")
                .withSubvolMountPath("/.snapshots")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("true")
                .withSubvolId("259")
                .withParentId("258")
                .withSubvolName("@/.snapshots/1/snapshot")
                .withSubvolMountPath("/")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("260")
                .withParentId("257")
                .withSubvolName("@/boot/grub2/i386-pc")
                .withSubvolMountPath("/boot/grub2/i386-pc")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("261")
                .withParentId("257")
                .withSubvolName("@/boot/grub2/x86_64-efi")
                .withSubvolMountPath("/boot/grub2/x86_64-efi")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("262")
                .withParentId("257")
                .withSubvolName("@/opt")
                .withSubvolMountPath("/opt")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("263")
                .withParentId("257")
                .withSubvolName("@/srv")
                .withSubvolMountPath("/srv")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("264")
                .withParentId("257")
                .withSubvolName("@/tmp")
                .withSubvolMountPath("/tmp")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("265")
                .withParentId("257")
                .withSubvolName("@/usr/local")
                .withSubvolMountPath("/usr/local")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("266")
                .withParentId("257")
                .withSubvolName("@/var/cache")
                .withSubvolMountPath("/var/cache")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("267")
                .withParentId("257")
                .withSubvolName("@/var/crash")
                .withSubvolMountPath("/var/crash")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("268")
                .withParentId("257")
                .withSubvolName("@/var/lib/libvirt/images")
                .withSubvolMountPath("/var/lib/libvirt/images")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("269")
                .withParentId("257")
                .withSubvolName("@/var/lib/machines")
                .withSubvolMountPath("/var/lib/machines")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("270")
                .withParentId("257")
                .withSubvolName("@/var/lib/mailman")
                .withSubvolMountPath("/var/lib/mailman")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("271")
                .withParentId("257")
                .withSubvolName("@/var/lib/mariadb")
                .withSubvolMountPath("/var/lib/mariadb")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("272")
                .withParentId("257")
                .withSubvolName("@/var/lib/mysql")
                .withSubvolMountPath("/var/lib/mysql")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("273")
                .withParentId("257")
                .withSubvolName("@/var/lib/named")
                .withSubvolMountPath("/var/lib/named")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("274")
                .withParentId("257")
                .withSubvolName("@/var/lib/pgsql")
                .withSubvolMountPath("/var/lib/pgsql")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("275")
                .withParentId("257")
                .withSubvolName("@/var/log")
                .withSubvolMountPath("/var/log")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("276")
                .withParentId("257")
                .withSubvolName("@/var/opt")
                .withSubvolMountPath("/var/opt")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("277")
                .withParentId("257")
                .withSubvolName("@/var/spool")
                .withSubvolMountPath("/var/spool")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("278")
                .withParentId("257")
                .withSubvolName("@/var/tmp")
                .withSubvolMountPath("/var/tmp")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("true")
                .withSubvolId("282")
                .withParentId("258")
                .withSubvolName("@/.snapshots/2/snapshot")
        );
        List<BtrfsFileSystem> listbodyBtrfsList = new ArrayList<>();
        listbodyBtrfsList.add(
            new BtrfsFileSystem()
                .withName("/dev/vda2")
                .withLabel("none")
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withDevice("/dev/vda2")
                .withSize(3.30GiBL)
                .withNodesize(16384L)
                .withSectorsize(4096)
                .withDataProfile("single")
                .withSystemProfile("single")
                .withMetadataProfile("single")
                .withGlobalReserve1("single")
                .withGVolUsedSize(3894038528L)
                .withDefaultSubvolid("259")
                .withDefaultSubvolName("@/.snapshots/1/snapshot")
                .withDefaultSubvolMountpath("/")
                .withSubvolumn(listBtrfsListSubvolumn)
        );
        List<LogicalVolumes> listVolumegroupsLogicalVolumes = new ArrayList<>();
        listVolumegroupsLogicalVolumes.add(
            new LogicalVolumes()
                .withFileSystem("ext4")
                .withInodeSize(256)
                .withDeviceUse("NORMAL")
                .withMountPoint("/mnt/lv1")
                .withName("/dev/mapper/vg1-lv1")
                .withSize(10737418240L)
                .withUsedSize(23580672L)
                .withFreeSize(10713837568L)
        );
        List<VolumeGroups> listbodyVolumegroups = new ArrayList<>();
        listbodyVolumegroups.add(
            new VolumeGroups()
                .withComponents("/dev/vdb1;/dev/vdc")
                .withLogicalVolumes(listVolumegroupsLogicalVolumes)
                .withName("vg1")
                .withSize(42948624384L)
        );
        List<PhysicalVolume> listDisksPhysicalVolumes = new ArrayList<>();
        listDisksPhysicalVolumes.add(
            new PhysicalVolume()
                .withDeviceUse("VOLUME_GROUP")
                .withFileSystem("LVM2_member")
                .withMountPoint("")
                .withName("/dev/vdb1")
                .withSize(21473787904L)
                .withUsedSize(21473787904L)
                .withInodeSize(0)
        );
        List<PhysicalVolume> listDisksPhysicalVolumes1 = new ArrayList<>();
        listDisksPhysicalVolumes1.add(
            new PhysicalVolume()
                .withDeviceUse("NORMAL")
                .withFileSystem("swap")
                .withMountPoint("")
                .withName("/dev/vda1")
                .withSize(2153775104L)
                .withUsedSize(2153775104L)
                .withInodeSize(0)
        );
        listDisksPhysicalVolumes1.add(
            new PhysicalVolume()
                .withDeviceUse("BTRFS")
                .withFileSystem("btrfs")
                .withMountPoint("")
                .withName("/dev/vda2")
                .withSize(16862150656L)
                .withUsedSize(16862150656L)
                .withInodeSize(0)
        );
        listDisksPhysicalVolumes1.add(
            new PhysicalVolume()
                .withDeviceUse("NORMAL")
                .withFileSystem("xfs")
                .withMountPoint("/home")
                .withName("/dev/vda3")
                .withSize(23932698624L)
                .withUsedSize(33988608L)
                .withInodeSize(0)
        );
        List<ServerDisk> listbodyDisks = new ArrayList<>();
        listbodyDisks.add(
            new ServerDisk()
                .withName("/dev/vda")
                .withPartitionStyle(ServerDisk.PartitionStyleEnum.fromValue("MBR"))
                .withDeviceUse(ServerDisk.DeviceUseEnum.fromValue("BOOT"))
                .withSize(42949672960L)
                .withUsedSize(42948624384L)
                .withPhysicalVolumes(listDisksPhysicalVolumes1)
        );
        listbodyDisks.add(
            new ServerDisk()
                .withName("/dev/vdb")
                .withPartitionStyle(ServerDisk.PartitionStyleEnum.fromValue("MBR"))
                .withDeviceUse(ServerDisk.DeviceUseEnum.fromValue("NORMAL"))
                .withSize(21474836480L)
                .withUsedSize(21473787904L)
                .withPhysicalVolumes(listDisksPhysicalVolumes)
        );
        listbodyDisks.add(
            new ServerDisk()
                .withName("/dev/vdc")
                .withPartitionStyle(ServerDisk.PartitionStyleEnum.fromValue("MBR"))
                .withDeviceUse(ServerDisk.DeviceUseEnum.fromValue("VOLUME_GROUP"))
                .withSize(21474836480L)
                .withUsedSize(0L)
                .withPhysicalVolumes()
        );
        body.withBtrfsList(listbodyBtrfsList);
        body.withVolumegroups(listbodyVolumegroups);
        body.withDisks(listbodyDisks);
        request.withBody(body);
        try {
            UpdateDiskInfoResponse response = client.updateDiskInfo(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

更新服务器的磁盘信息,此接口会把服务器原有磁盘信息清空,然后更新成新磁盘信息,新的磁盘名称是/dev/vda,磁盘类型是BOOT,磁盘大小是42949672960字节。

  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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdksms.v3.region.sms_region import SmsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdksms.v3 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]

    credentials = GlobalCredentials(ak, sk)

    client = SmsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(SmsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateDiskInfoRequest()
        request.source_id = "{source_id}"
        listSubvolumnBtrfsList = [
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="257",
                parent_id="5",
                subvol_name="@"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="258",
                parent_id="257",
                subvol_name="@/.snapshots",
                subvol_mount_path="/.snapshots"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="true",
                subvol_id="259",
                parent_id="258",
                subvol_name="@/.snapshots/1/snapshot",
                subvol_mount_path="/"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="260",
                parent_id="257",
                subvol_name="@/boot/grub2/i386-pc",
                subvol_mount_path="/boot/grub2/i386-pc"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="261",
                parent_id="257",
                subvol_name="@/boot/grub2/x86_64-efi",
                subvol_mount_path="/boot/grub2/x86_64-efi"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="262",
                parent_id="257",
                subvol_name="@/opt",
                subvol_mount_path="/opt"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="263",
                parent_id="257",
                subvol_name="@/srv",
                subvol_mount_path="/srv"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="264",
                parent_id="257",
                subvol_name="@/tmp",
                subvol_mount_path="/tmp"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="265",
                parent_id="257",
                subvol_name="@/usr/local",
                subvol_mount_path="/usr/local"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="266",
                parent_id="257",
                subvol_name="@/var/cache",
                subvol_mount_path="/var/cache"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="267",
                parent_id="257",
                subvol_name="@/var/crash",
                subvol_mount_path="/var/crash"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="268",
                parent_id="257",
                subvol_name="@/var/lib/libvirt/images",
                subvol_mount_path="/var/lib/libvirt/images"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="269",
                parent_id="257",
                subvol_name="@/var/lib/machines",
                subvol_mount_path="/var/lib/machines"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="270",
                parent_id="257",
                subvol_name="@/var/lib/mailman",
                subvol_mount_path="/var/lib/mailman"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="271",
                parent_id="257",
                subvol_name="@/var/lib/mariadb",
                subvol_mount_path="/var/lib/mariadb"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="272",
                parent_id="257",
                subvol_name="@/var/lib/mysql",
                subvol_mount_path="/var/lib/mysql"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="273",
                parent_id="257",
                subvol_name="@/var/lib/named",
                subvol_mount_path="/var/lib/named"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="274",
                parent_id="257",
                subvol_name="@/var/lib/pgsql",
                subvol_mount_path="/var/lib/pgsql"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="275",
                parent_id="257",
                subvol_name="@/var/log",
                subvol_mount_path="/var/log"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="276",
                parent_id="257",
                subvol_name="@/var/opt",
                subvol_mount_path="/var/opt"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="277",
                parent_id="257",
                subvol_name="@/var/spool",
                subvol_mount_path="/var/spool"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="278",
                parent_id="257",
                subvol_name="@/var/tmp",
                subvol_mount_path="/var/tmp"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="true",
                subvol_id="282",
                parent_id="258",
                subvol_name="@/.snapshots/2/snapshot"
            )
        ]
        listBtrfsListbody = [
            BtrfsFileSystem(
                name="/dev/vda2",
                label="none",
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                device="/dev/vda2",
                size=3.30GiB,
                nodesize=16384,
                sectorsize=4096,
                data_profile="single",
                system_profile="single",
                metadata_profile="single",
                global_reserve1="single",
                g_vol_used_size=3894038528,
                default_subvolid="259",
                default_subvol_name="@/.snapshots/1/snapshot",
                default_subvol_mountpath="/",
                subvolumn=listSubvolumnBtrfsList
            )
        ]
        listLogicalVolumesVolumegroups = [
            LogicalVolumes(
                file_system="ext4",
                inode_size=256,
                device_use="NORMAL",
                mount_point="/mnt/lv1",
                name="/dev/mapper/vg1-lv1",
                size=10737418240,
                used_size=23580672,
                free_size=10713837568
            )
        ]
        listVolumegroupsbody = [
            VolumeGroups(
                components="/dev/vdb1;/dev/vdc",
                logical_volumes=listLogicalVolumesVolumegroups,
                name="vg1",
                size=42948624384
            )
        ]
        listPhysicalVolumesDisks = [
            PhysicalVolume(
                device_use="VOLUME_GROUP",
                file_system="LVM2_member",
                mount_point="",
                name="/dev/vdb1",
                size=21473787904,
                used_size=21473787904,
                inode_size=0
            )
        ]
        listPhysicalVolumesDisks1 = [
            PhysicalVolume(
                device_use="NORMAL",
                file_system="swap",
                mount_point="",
                name="/dev/vda1",
                size=2153775104,
                used_size=2153775104,
                inode_size=0
            ),
            PhysicalVolume(
                device_use="BTRFS",
                file_system="btrfs",
                mount_point="",
                name="/dev/vda2",
                size=16862150656,
                used_size=16862150656,
                inode_size=0
            ),
            PhysicalVolume(
                device_use="NORMAL",
                file_system="xfs",
                mount_point="/home",
                name="/dev/vda3",
                size=23932698624,
                used_size=33988608,
                inode_size=0
            )
        ]
        listDisksbody = [
            ServerDisk(
                name="/dev/vda",
                partition_style="MBR",
                device_use="BOOT",
                size=42949672960,
                used_size=42948624384,
                physical_volumes=listPhysicalVolumesDisks1
            ),
            ServerDisk(
                name="/dev/vdb",
                partition_style="MBR",
                device_use="NORMAL",
                size=21474836480,
                used_size=21473787904,
                physical_volumes=listPhysicalVolumesDisks
            ),
            ServerDisk(
                name="/dev/vdc",
                partition_style="MBR",
                device_use="VOLUME_GROUP",
                size=21474836480,
                used_size=0,
            )
        ]
        request.body = PutDiskInfoReq(
            btrfs_list=listBtrfsListbody,
            volumegroups=listVolumegroupsbody,
            disks=listDisksbody
        )
        response = client.update_disk_info(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

更新服务器的磁盘信息,此接口会把服务器原有磁盘信息清空,然后更新成新磁盘信息,新的磁盘名称是/dev/vda,磁盘类型是BOOT,磁盘大小是42949672960字节。

  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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    sms "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := global.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := sms.NewSmsClient(
        sms.SmsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateDiskInfoRequest{}
	request.SourceId = "{source_id}"
	var listSubvolumnBtrfsList = []model.BtrfsSubvolumn{
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "257",
            ParentId: "5",
            SubvolName: "@",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "258",
            ParentId: "257",
            SubvolName: "@/.snapshots",
            SubvolMountPath: "/.snapshots",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "true",
            SubvolId: "259",
            ParentId: "258",
            SubvolName: "@/.snapshots/1/snapshot",
            SubvolMountPath: "/",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "260",
            ParentId: "257",
            SubvolName: "@/boot/grub2/i386-pc",
            SubvolMountPath: "/boot/grub2/i386-pc",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "261",
            ParentId: "257",
            SubvolName: "@/boot/grub2/x86_64-efi",
            SubvolMountPath: "/boot/grub2/x86_64-efi",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "262",
            ParentId: "257",
            SubvolName: "@/opt",
            SubvolMountPath: "/opt",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "263",
            ParentId: "257",
            SubvolName: "@/srv",
            SubvolMountPath: "/srv",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "264",
            ParentId: "257",
            SubvolName: "@/tmp",
            SubvolMountPath: "/tmp",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "265",
            ParentId: "257",
            SubvolName: "@/usr/local",
            SubvolMountPath: "/usr/local",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "266",
            ParentId: "257",
            SubvolName: "@/var/cache",
            SubvolMountPath: "/var/cache",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "267",
            ParentId: "257",
            SubvolName: "@/var/crash",
            SubvolMountPath: "/var/crash",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "268",
            ParentId: "257",
            SubvolName: "@/var/lib/libvirt/images",
            SubvolMountPath: "/var/lib/libvirt/images",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "269",
            ParentId: "257",
            SubvolName: "@/var/lib/machines",
            SubvolMountPath: "/var/lib/machines",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "270",
            ParentId: "257",
            SubvolName: "@/var/lib/mailman",
            SubvolMountPath: "/var/lib/mailman",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "271",
            ParentId: "257",
            SubvolName: "@/var/lib/mariadb",
            SubvolMountPath: "/var/lib/mariadb",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "272",
            ParentId: "257",
            SubvolName: "@/var/lib/mysql",
            SubvolMountPath: "/var/lib/mysql",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "273",
            ParentId: "257",
            SubvolName: "@/var/lib/named",
            SubvolMountPath: "/var/lib/named",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "274",
            ParentId: "257",
            SubvolName: "@/var/lib/pgsql",
            SubvolMountPath: "/var/lib/pgsql",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "275",
            ParentId: "257",
            SubvolName: "@/var/log",
            SubvolMountPath: "/var/log",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "276",
            ParentId: "257",
            SubvolName: "@/var/opt",
            SubvolMountPath: "/var/opt",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "277",
            ParentId: "257",
            SubvolName: "@/var/spool",
            SubvolMountPath: "/var/spool",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "278",
            ParentId: "257",
            SubvolName: "@/var/tmp",
            SubvolMountPath: "/var/tmp",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "true",
            SubvolId: "282",
            ParentId: "258",
            SubvolName: "@/.snapshots/2/snapshot",
        },
    }
	var listBtrfsListbody = []model.BtrfsFileSystem{
        {
            Name: "/dev/vda2",
            Label: "none",
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            Device: "/dev/vda2",
            Size: int64(3.30GiB),
            Nodesize: int64(16384),
            Sectorsize: int32(4096),
            DataProfile: "single",
            SystemProfile: "single",
            MetadataProfile: "single",
            GlobalReserve1: "single",
            GVolUsedSize: int64(3894038528),
            DefaultSubvolid: "259",
            DefaultSubvolName: "@/.snapshots/1/snapshot",
            DefaultSubvolMountpath: "/",
            Subvolumn: listSubvolumnBtrfsList,
        },
    }
	deviceUseLogicalVolumes:= "NORMAL"
	var listLogicalVolumesVolumegroups = []model.LogicalVolumes{
        {
            FileSystem: "ext4",
            InodeSize: int32(256),
            DeviceUse: &deviceUseLogicalVolumes,
            MountPoint: "/mnt/lv1",
            Name: "/dev/mapper/vg1-lv1",
            Size: int64(10737418240),
            UsedSize: int64(23580672),
            FreeSize: int64(10713837568),
        },
    }
	componentsVolumegroups:= "/dev/vdb1;/dev/vdc"
	nameVolumegroups:= "vg1"
	sizeVolumegroups:= int64(42948624384)
	var listVolumegroupsbody = []model.VolumeGroups{
        {
            Components: &componentsVolumegroups,
            LogicalVolumes: &listLogicalVolumesVolumegroups,
            Name: &nameVolumegroups,
            Size: &sizeVolumegroups,
        },
    }
	deviceUsePhysicalVolumes:= "VOLUME_GROUP"
	fileSystemPhysicalVolumes:= "LVM2_member"
	mountPointPhysicalVolumes:= ""
	namePhysicalVolumes:= "/dev/vdb1"
	sizePhysicalVolumes:= int64(21473787904)
	usedSizePhysicalVolumes:= int64(21473787904)
	inodeSizePhysicalVolumes:= int32(0)
	var listPhysicalVolumesDisks = []model.PhysicalVolume{
        {
            DeviceUse: &deviceUsePhysicalVolumes,
            FileSystem: &fileSystemPhysicalVolumes,
            MountPoint: &mountPointPhysicalVolumes,
            Name: &namePhysicalVolumes,
            Size: &sizePhysicalVolumes,
            UsedSize: &usedSizePhysicalVolumes,
            InodeSize: &inodeSizePhysicalVolumes,
        },
    }
	deviceUsePhysicalVolumes1:= "NORMAL"
	fileSystemPhysicalVolumes1:= "swap"
	mountPointPhysicalVolumes1:= ""
	namePhysicalVolumes1:= "/dev/vda1"
	sizePhysicalVolumes1:= int64(2153775104)
	usedSizePhysicalVolumes1:= int64(2153775104)
	inodeSizePhysicalVolumes1:= int32(0)
	deviceUsePhysicalVolumes2:= "BTRFS"
	fileSystemPhysicalVolumes2:= "btrfs"
	mountPointPhysicalVolumes2:= ""
	namePhysicalVolumes2:= "/dev/vda2"
	sizePhysicalVolumes2:= int64(16862150656)
	usedSizePhysicalVolumes2:= int64(16862150656)
	inodeSizePhysicalVolumes2:= int32(0)
	deviceUsePhysicalVolumes3:= "NORMAL"
	fileSystemPhysicalVolumes3:= "xfs"
	mountPointPhysicalVolumes3:= "/home"
	namePhysicalVolumes3:= "/dev/vda3"
	sizePhysicalVolumes3:= int64(23932698624)
	usedSizePhysicalVolumes3:= int64(33988608)
	inodeSizePhysicalVolumes3:= int32(0)
	var listPhysicalVolumesDisks1 = []model.PhysicalVolume{
        {
            DeviceUse: &deviceUsePhysicalVolumes1,
            FileSystem: &fileSystemPhysicalVolumes1,
            MountPoint: &mountPointPhysicalVolumes1,
            Name: &namePhysicalVolumes1,
            Size: &sizePhysicalVolumes1,
            UsedSize: &usedSizePhysicalVolumes1,
            InodeSize: &inodeSizePhysicalVolumes1,
        },
        {
            DeviceUse: &deviceUsePhysicalVolumes2,
            FileSystem: &fileSystemPhysicalVolumes2,
            MountPoint: &mountPointPhysicalVolumes2,
            Name: &namePhysicalVolumes2,
            Size: &sizePhysicalVolumes2,
            UsedSize: &usedSizePhysicalVolumes2,
            InodeSize: &inodeSizePhysicalVolumes2,
        },
        {
            DeviceUse: &deviceUsePhysicalVolumes3,
            FileSystem: &fileSystemPhysicalVolumes3,
            MountPoint: &mountPointPhysicalVolumes3,
            Name: &namePhysicalVolumes3,
            Size: &sizePhysicalVolumes3,
            UsedSize: &usedSizePhysicalVolumes3,
            InodeSize: &inodeSizePhysicalVolumes3,
        },
    }
	partitionStyleDisks:= model.GetServerDiskPartitionStyleEnum().MBR
	partitionStyleDisks1:= model.GetServerDiskPartitionStyleEnum().MBR
	partitionStyleDisks2:= model.GetServerDiskPartitionStyleEnum().MBR
	var listDisksbody = []model.ServerDisk{
        {
            Name: "/dev/vda",
            PartitionStyle: &partitionStyleDisks,
            DeviceUse: model.GetServerDiskDeviceUseEnum().BOOT,
            Size: int64(42949672960),
            UsedSize: int64(42948624384),
            PhysicalVolumes: listPhysicalVolumesDisks1,
        },
        {
            Name: "/dev/vdb",
            PartitionStyle: &partitionStyleDisks1,
            DeviceUse: model.GetServerDiskDeviceUseEnum().NORMAL,
            Size: int64(21474836480),
            UsedSize: int64(21473787904),
            PhysicalVolumes: listPhysicalVolumesDisks,
        },
        {
            Name: "/dev/vdc",
            PartitionStyle: &partitionStyleDisks2,
            DeviceUse: model.GetServerDiskDeviceUseEnum().VOLUME_GROUP,
            Size: int64(21474836480),
            UsedSize: int64(0),
        },
    }
	request.Body = &model.PutDiskInfoReq{
		BtrfsList: &listBtrfsListbody,
		Volumegroups: &listVolumegroupsbody,
		Disks: &listDisksbody,
	}
	response, err := client.UpdateDiskInfo(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

更新服务器的磁盘信息,此接口会把服务器原有磁盘信息清空,然后更新成新磁盘信息,新的磁盘名称是/dev/vda,磁盘类型是BOOT,磁盘大小是42949672960字节。

  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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.sms.v3.region.SmsRegion;
import com.huaweicloud.sdk.sms.v3.*;
import com.huaweicloud.sdk.sms.v3.model.*;

import java.util.List;
import java.util.ArrayList;

public class UpdateDiskInfoSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new GlobalCredentials()
                .withAk(ak)
                .withSk(sk);

        SmsClient client = SmsClient.newBuilder()
                .withCredential(auth)
                .withRegion(SmsRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateDiskInfoRequest request = new UpdateDiskInfoRequest();
        request.withSourceId("{source_id}");
        PutDiskInfoReq body = new PutDiskInfoReq();
        List<BtrfsSubvolumn> listBtrfsListSubvolumn = new ArrayList<>();
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("257")
                .withParentId("5")
                .withSubvolName("@")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("258")
                .withParentId("257")
                .withSubvolName("@/.snapshots")
                .withSubvolMountPath("/.snapshots")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("true")
                .withSubvolId("259")
                .withParentId("258")
                .withSubvolName("@/.snapshots/1/snapshot")
                .withSubvolMountPath("/")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("260")
                .withParentId("257")
                .withSubvolName("@/boot/grub2/i386-pc")
                .withSubvolMountPath("/boot/grub2/i386-pc")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("261")
                .withParentId("257")
                .withSubvolName("@/boot/grub2/x86_64-efi")
                .withSubvolMountPath("/boot/grub2/x86_64-efi")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("262")
                .withParentId("257")
                .withSubvolName("@/opt")
                .withSubvolMountPath("/opt")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("263")
                .withParentId("257")
                .withSubvolName("@/srv")
                .withSubvolMountPath("/srv")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("264")
                .withParentId("257")
                .withSubvolName("@/tmp")
                .withSubvolMountPath("/tmp")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("265")
                .withParentId("257")
                .withSubvolName("@/usr/local")
                .withSubvolMountPath("/usr/local")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("266")
                .withParentId("257")
                .withSubvolName("@/var/cache")
                .withSubvolMountPath("/var/cache")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("267")
                .withParentId("257")
                .withSubvolName("@/var/crash")
                .withSubvolMountPath("/var/crash")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("268")
                .withParentId("257")
                .withSubvolName("@/var/lib/libvirt/images")
                .withSubvolMountPath("/var/lib/libvirt/images")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("269")
                .withParentId("257")
                .withSubvolName("@/var/lib/machines")
                .withSubvolMountPath("/var/lib/machines")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("270")
                .withParentId("257")
                .withSubvolName("@/var/lib/mailman")
                .withSubvolMountPath("/var/lib/mailman")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("271")
                .withParentId("257")
                .withSubvolName("@/var/lib/mariadb")
                .withSubvolMountPath("/var/lib/mariadb")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("272")
                .withParentId("257")
                .withSubvolName("@/var/lib/mysql")
                .withSubvolMountPath("/var/lib/mysql")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("273")
                .withParentId("257")
                .withSubvolName("@/var/lib/named")
                .withSubvolMountPath("/var/lib/named")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("274")
                .withParentId("257")
                .withSubvolName("@/var/lib/pgsql")
                .withSubvolMountPath("/var/lib/pgsql")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("275")
                .withParentId("257")
                .withSubvolName("@/var/log")
                .withSubvolMountPath("/var/log")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("276")
                .withParentId("257")
                .withSubvolName("@/var/opt")
                .withSubvolMountPath("/var/opt")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("277")
                .withParentId("257")
                .withSubvolName("@/var/spool")
                .withSubvolMountPath("/var/spool")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("false")
                .withSubvolId("278")
                .withParentId("257")
                .withSubvolName("@/var/tmp")
                .withSubvolMountPath("/var/tmp")
        );
        listBtrfsListSubvolumn.add(
            new BtrfsSubvolumn()
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withIsSnapshot("true")
                .withSubvolId("282")
                .withParentId("258")
                .withSubvolName("@/.snapshots/2/snapshot")
        );
        List<BtrfsFileSystem> listbodyBtrfsList = new ArrayList<>();
        listbodyBtrfsList.add(
            new BtrfsFileSystem()
                .withName("/dev/vda2")
                .withLabel("none")
                .withUuid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001")
                .withDevice("/dev/vda2")
                .withSize(3.30GiBL)
                .withNodesize(16384L)
                .withSectorsize(4096)
                .withDataProfile("single")
                .withSystemProfile("single")
                .withMetadataProfile("single")
                .withGlobalReserve1("single")
                .withGVolUsedSize(3894038528L)
                .withDefaultSubvolid("259")
                .withDefaultSubvolName("@/.snapshots/1/snapshot")
                .withDefaultSubvolMountpath("/")
                .withSubvolumn(listBtrfsListSubvolumn)
        );
        List<LogicalVolumes> listVolumegroupsLogicalVolumes = new ArrayList<>();
        listVolumegroupsLogicalVolumes.add(
            new LogicalVolumes()
                .withFileSystem("ext4")
                .withInodeSize(256)
                .withDeviceUse("NORMAL")
                .withMountPoint("/mnt/lv1")
                .withName("/dev/mapper/vg1-lv1")
                .withSize(10737418240L)
                .withUsedSize(23580672L)
                .withFreeSize(10713837568L)
        );
        List<VolumeGroups> listbodyVolumegroups = new ArrayList<>();
        listbodyVolumegroups.add(
            new VolumeGroups()
                .withComponents("/dev/vdb1;/dev/vdc")
                .withLogicalVolumes(listVolumegroupsLogicalVolumes)
                .withName("vg1")
                .withSize(42948624384L)
        );
        List<PhysicalVolume> listDisksPhysicalVolumes = new ArrayList<>();
        listDisksPhysicalVolumes.add(
            new PhysicalVolume()
                .withDeviceUse("VOLUME_GROUP")
                .withFileSystem("LVM2_member")
                .withMountPoint("")
                .withName("/dev/vdb1")
                .withSize(21473787904L)
                .withUsedSize(21473787904L)
                .withInodeSize(0)
        );
        List<PhysicalVolume> listDisksPhysicalVolumes1 = new ArrayList<>();
        listDisksPhysicalVolumes1.add(
            new PhysicalVolume()
                .withDeviceUse("NORMAL")
                .withFileSystem("swap")
                .withMountPoint("")
                .withName("/dev/vda1")
                .withSize(2153775104L)
                .withUsedSize(2153775104L)
                .withInodeSize(0)
        );
        listDisksPhysicalVolumes1.add(
            new PhysicalVolume()
                .withDeviceUse("BTRFS")
                .withFileSystem("btrfs")
                .withMountPoint("")
                .withName("/dev/vda2")
                .withSize(16862150656L)
                .withUsedSize(16862150656L)
                .withInodeSize(0)
        );
        listDisksPhysicalVolumes1.add(
            new PhysicalVolume()
                .withDeviceUse("NORMAL")
                .withFileSystem("xfs")
                .withMountPoint("/home")
                .withName("/dev/vda3")
                .withSize(23932698624L)
                .withUsedSize(33988608L)
                .withInodeSize(0)
        );
        List<ServerDisk> listbodyDisks = new ArrayList<>();
        listbodyDisks.add(
            new ServerDisk()
                .withName("/dev/vda")
                .withPartitionStyle(ServerDisk.PartitionStyleEnum.fromValue("MBR"))
                .withDeviceUse(ServerDisk.DeviceUseEnum.fromValue("BOOT"))
                .withSize(42949672960L)
                .withUsedSize(42948624384L)
                .withPhysicalVolumes(listDisksPhysicalVolumes1)
        );
        listbodyDisks.add(
            new ServerDisk()
                .withName("/dev/vdb")
                .withPartitionStyle(ServerDisk.PartitionStyleEnum.fromValue("MBR"))
                .withDeviceUse(ServerDisk.DeviceUseEnum.fromValue("NORMAL"))
                .withSize(21474836480L)
                .withUsedSize(21473787904L)
                .withPhysicalVolumes(listDisksPhysicalVolumes)
        );
        listbodyDisks.add(
            new ServerDisk()
                .withName("/dev/vdc")
                .withPartitionStyle(ServerDisk.PartitionStyleEnum.fromValue("MBR"))
                .withDeviceUse(ServerDisk.DeviceUseEnum.fromValue("VOLUME_GROUP"))
                .withSize(21474836480L)
                .withUsedSize(0L)
                .withPhysicalVolumes()
        );
        body.withBtrfsList(listbodyBtrfsList);
        body.withVolumegroups(listbodyVolumegroups);
        body.withDisks(listbodyDisks);
        request.withBody(body);
        try {
            UpdateDiskInfoResponse response = client.updateDiskInfo(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

更新服务器的磁盘信息,此接口会把服务器原有磁盘信息清空,然后更新成新磁盘信息,新的磁盘名称是/dev/vda,磁盘类型是BOOT,磁盘大小是42949672960字节。

  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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdksms.v3.region.sms_region import SmsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdksms.v3 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]

    credentials = GlobalCredentials(ak, sk)

    client = SmsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(SmsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateDiskInfoRequest()
        request.source_id = "{source_id}"
        listSubvolumnBtrfsList = [
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="257",
                parent_id="5",
                subvol_name="@"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="258",
                parent_id="257",
                subvol_name="@/.snapshots",
                subvol_mount_path="/.snapshots"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="true",
                subvol_id="259",
                parent_id="258",
                subvol_name="@/.snapshots/1/snapshot",
                subvol_mount_path="/"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="260",
                parent_id="257",
                subvol_name="@/boot/grub2/i386-pc",
                subvol_mount_path="/boot/grub2/i386-pc"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="261",
                parent_id="257",
                subvol_name="@/boot/grub2/x86_64-efi",
                subvol_mount_path="/boot/grub2/x86_64-efi"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="262",
                parent_id="257",
                subvol_name="@/opt",
                subvol_mount_path="/opt"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="263",
                parent_id="257",
                subvol_name="@/srv",
                subvol_mount_path="/srv"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="264",
                parent_id="257",
                subvol_name="@/tmp",
                subvol_mount_path="/tmp"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="265",
                parent_id="257",
                subvol_name="@/usr/local",
                subvol_mount_path="/usr/local"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="266",
                parent_id="257",
                subvol_name="@/var/cache",
                subvol_mount_path="/var/cache"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="267",
                parent_id="257",
                subvol_name="@/var/crash",
                subvol_mount_path="/var/crash"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="268",
                parent_id="257",
                subvol_name="@/var/lib/libvirt/images",
                subvol_mount_path="/var/lib/libvirt/images"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="269",
                parent_id="257",
                subvol_name="@/var/lib/machines",
                subvol_mount_path="/var/lib/machines"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="270",
                parent_id="257",
                subvol_name="@/var/lib/mailman",
                subvol_mount_path="/var/lib/mailman"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="271",
                parent_id="257",
                subvol_name="@/var/lib/mariadb",
                subvol_mount_path="/var/lib/mariadb"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="272",
                parent_id="257",
                subvol_name="@/var/lib/mysql",
                subvol_mount_path="/var/lib/mysql"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="273",
                parent_id="257",
                subvol_name="@/var/lib/named",
                subvol_mount_path="/var/lib/named"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="274",
                parent_id="257",
                subvol_name="@/var/lib/pgsql",
                subvol_mount_path="/var/lib/pgsql"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="275",
                parent_id="257",
                subvol_name="@/var/log",
                subvol_mount_path="/var/log"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="276",
                parent_id="257",
                subvol_name="@/var/opt",
                subvol_mount_path="/var/opt"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="277",
                parent_id="257",
                subvol_name="@/var/spool",
                subvol_mount_path="/var/spool"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="false",
                subvol_id="278",
                parent_id="257",
                subvol_name="@/var/tmp",
                subvol_mount_path="/var/tmp"
            ),
            BtrfsSubvolumn(
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                is_snapshot="true",
                subvol_id="282",
                parent_id="258",
                subvol_name="@/.snapshots/2/snapshot"
            )
        ]
        listBtrfsListbody = [
            BtrfsFileSystem(
                name="/dev/vda2",
                label="none",
                uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
                device="/dev/vda2",
                size=3.30GiB,
                nodesize=16384,
                sectorsize=4096,
                data_profile="single",
                system_profile="single",
                metadata_profile="single",
                global_reserve1="single",
                g_vol_used_size=3894038528,
                default_subvolid="259",
                default_subvol_name="@/.snapshots/1/snapshot",
                default_subvol_mountpath="/",
                subvolumn=listSubvolumnBtrfsList
            )
        ]
        listLogicalVolumesVolumegroups = [
            LogicalVolumes(
                file_system="ext4",
                inode_size=256,
                device_use="NORMAL",
                mount_point="/mnt/lv1",
                name="/dev/mapper/vg1-lv1",
                size=10737418240,
                used_size=23580672,
                free_size=10713837568
            )
        ]
        listVolumegroupsbody = [
            VolumeGroups(
                components="/dev/vdb1;/dev/vdc",
                logical_volumes=listLogicalVolumesVolumegroups,
                name="vg1",
                size=42948624384
            )
        ]
        listPhysicalVolumesDisks = [
            PhysicalVolume(
                device_use="VOLUME_GROUP",
                file_system="LVM2_member",
                mount_point="",
                name="/dev/vdb1",
                size=21473787904,
                used_size=21473787904,
                inode_size=0
            )
        ]
        listPhysicalVolumesDisks1 = [
            PhysicalVolume(
                device_use="NORMAL",
                file_system="swap",
                mount_point="",
                name="/dev/vda1",
                size=2153775104,
                used_size=2153775104,
                inode_size=0
            ),
            PhysicalVolume(
                device_use="BTRFS",
                file_system="btrfs",
                mount_point="",
                name="/dev/vda2",
                size=16862150656,
                used_size=16862150656,
                inode_size=0
            ),
            PhysicalVolume(
                device_use="NORMAL",
                file_system="xfs",
                mount_point="/home",
                name="/dev/vda3",
                size=23932698624,
                used_size=33988608,
                inode_size=0
            )
        ]
        listDisksbody = [
            ServerDisk(
                name="/dev/vda",
                partition_style="MBR",
                device_use="BOOT",
                size=42949672960,
                used_size=42948624384,
                physical_volumes=listPhysicalVolumesDisks1
            ),
            ServerDisk(
                name="/dev/vdb",
                partition_style="MBR",
                device_use="NORMAL",
                size=21474836480,
                used_size=21473787904,
                physical_volumes=listPhysicalVolumesDisks
            ),
            ServerDisk(
                name="/dev/vdc",
                partition_style="MBR",
                device_use="VOLUME_GROUP",
                size=21474836480,
                used_size=0,
            )
        ]
        request.body = PutDiskInfoReq(
            btrfs_list=listBtrfsListbody,
            volumegroups=listVolumegroupsbody,
            disks=listDisksbody
        )
        response = client.update_disk_info(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

更新服务器的磁盘信息,此接口会把服务器原有磁盘信息清空,然后更新成新磁盘信息,新的磁盘名称是/dev/vda,磁盘类型是BOOT,磁盘大小是42949672960字节。

  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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    sms "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := global.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := sms.NewSmsClient(
        sms.SmsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateDiskInfoRequest{}
	request.SourceId = "{source_id}"
	var listSubvolumnBtrfsList = []model.BtrfsSubvolumn{
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "257",
            ParentId: "5",
            SubvolName: "@",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "258",
            ParentId: "257",
            SubvolName: "@/.snapshots",
            SubvolMountPath: "/.snapshots",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "true",
            SubvolId: "259",
            ParentId: "258",
            SubvolName: "@/.snapshots/1/snapshot",
            SubvolMountPath: "/",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "260",
            ParentId: "257",
            SubvolName: "@/boot/grub2/i386-pc",
            SubvolMountPath: "/boot/grub2/i386-pc",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "261",
            ParentId: "257",
            SubvolName: "@/boot/grub2/x86_64-efi",
            SubvolMountPath: "/boot/grub2/x86_64-efi",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "262",
            ParentId: "257",
            SubvolName: "@/opt",
            SubvolMountPath: "/opt",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "263",
            ParentId: "257",
            SubvolName: "@/srv",
            SubvolMountPath: "/srv",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "264",
            ParentId: "257",
            SubvolName: "@/tmp",
            SubvolMountPath: "/tmp",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "265",
            ParentId: "257",
            SubvolName: "@/usr/local",
            SubvolMountPath: "/usr/local",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "266",
            ParentId: "257",
            SubvolName: "@/var/cache",
            SubvolMountPath: "/var/cache",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "267",
            ParentId: "257",
            SubvolName: "@/var/crash",
            SubvolMountPath: "/var/crash",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "268",
            ParentId: "257",
            SubvolName: "@/var/lib/libvirt/images",
            SubvolMountPath: "/var/lib/libvirt/images",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "269",
            ParentId: "257",
            SubvolName: "@/var/lib/machines",
            SubvolMountPath: "/var/lib/machines",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "270",
            ParentId: "257",
            SubvolName: "@/var/lib/mailman",
            SubvolMountPath: "/var/lib/mailman",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "271",
            ParentId: "257",
            SubvolName: "@/var/lib/mariadb",
            SubvolMountPath: "/var/lib/mariadb",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "272",
            ParentId: "257",
            SubvolName: "@/var/lib/mysql",
            SubvolMountPath: "/var/lib/mysql",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "273",
            ParentId: "257",
            SubvolName: "@/var/lib/named",
            SubvolMountPath: "/var/lib/named",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "274",
            ParentId: "257",
            SubvolName: "@/var/lib/pgsql",
            SubvolMountPath: "/var/lib/pgsql",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "275",
            ParentId: "257",
            SubvolName: "@/var/log",
            SubvolMountPath: "/var/log",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "276",
            ParentId: "257",
            SubvolName: "@/var/opt",
            SubvolMountPath: "/var/opt",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "277",
            ParentId: "257",
            SubvolName: "@/var/spool",
            SubvolMountPath: "/var/spool",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "false",
            SubvolId: "278",
            ParentId: "257",
            SubvolName: "@/var/tmp",
            SubvolMountPath: "/var/tmp",
        },
        {
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            IsSnapshot: "true",
            SubvolId: "282",
            ParentId: "258",
            SubvolName: "@/.snapshots/2/snapshot",
        },
    }
	var listBtrfsListbody = []model.BtrfsFileSystem{
        {
            Name: "/dev/vda2",
            Label: "none",
            Uuid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
            Device: "/dev/vda2",
            Size: int64(3.30GiB),
            Nodesize: int64(16384),
            Sectorsize: int32(4096),
            DataProfile: "single",
            SystemProfile: "single",
            MetadataProfile: "single",
            GlobalReserve1: "single",
            GVolUsedSize: int64(3894038528),
            DefaultSubvolid: "259",
            DefaultSubvolName: "@/.snapshots/1/snapshot",
            DefaultSubvolMountpath: "/",
            Subvolumn: listSubvolumnBtrfsList,
        },
    }
	deviceUseLogicalVolumes:= "NORMAL"
	var listLogicalVolumesVolumegroups = []model.LogicalVolumes{
        {
            FileSystem: "ext4",
            InodeSize: int32(256),
            DeviceUse: &deviceUseLogicalVolumes,
            MountPoint: "/mnt/lv1",
            Name: "/dev/mapper/vg1-lv1",
            Size: int64(10737418240),
            UsedSize: int64(23580672),
            FreeSize: int64(10713837568),
        },
    }
	componentsVolumegroups:= "/dev/vdb1;/dev/vdc"
	nameVolumegroups:= "vg1"
	sizeVolumegroups:= int64(42948624384)
	var listVolumegroupsbody = []model.VolumeGroups{
        {
            Components: &componentsVolumegroups,
            LogicalVolumes: &listLogicalVolumesVolumegroups,
            Name: &nameVolumegroups,
            Size: &sizeVolumegroups,
        },
    }
	deviceUsePhysicalVolumes:= "VOLUME_GROUP"
	fileSystemPhysicalVolumes:= "LVM2_member"
	mountPointPhysicalVolumes:= ""
	namePhysicalVolumes:= "/dev/vdb1"
	sizePhysicalVolumes:= int64(21473787904)
	usedSizePhysicalVolumes:= int64(21473787904)
	inodeSizePhysicalVolumes:= int32(0)
	var listPhysicalVolumesDisks = []model.PhysicalVolume{
        {
            DeviceUse: &deviceUsePhysicalVolumes,
            FileSystem: &fileSystemPhysicalVolumes,
            MountPoint: &mountPointPhysicalVolumes,
            Name: &namePhysicalVolumes,
            Size: &sizePhysicalVolumes,
            UsedSize: &usedSizePhysicalVolumes,
            InodeSize: &inodeSizePhysicalVolumes,
        },
    }
	deviceUsePhysicalVolumes1:= "NORMAL"
	fileSystemPhysicalVolumes1:= "swap"
	mountPointPhysicalVolumes1:= ""
	namePhysicalVolumes1:= "/dev/vda1"
	sizePhysicalVolumes1:= int64(2153775104)
	usedSizePhysicalVolumes1:= int64(2153775104)
	inodeSizePhysicalVolumes1:= int32(0)
	deviceUsePhysicalVolumes2:= "BTRFS"
	fileSystemPhysicalVolumes2:= "btrfs"
	mountPointPhysicalVolumes2:= ""
	namePhysicalVolumes2:= "/dev/vda2"
	sizePhysicalVolumes2:= int64(16862150656)
	usedSizePhysicalVolumes2:= int64(16862150656)
	inodeSizePhysicalVolumes2:= int32(0)
	deviceUsePhysicalVolumes3:= "NORMAL"
	fileSystemPhysicalVolumes3:= "xfs"
	mountPointPhysicalVolumes3:= "/home"
	namePhysicalVolumes3:= "/dev/vda3"
	sizePhysicalVolumes3:= int64(23932698624)
	usedSizePhysicalVolumes3:= int64(33988608)
	inodeSizePhysicalVolumes3:= int32(0)
	var listPhysicalVolumesDisks1 = []model.PhysicalVolume{
        {
            DeviceUse: &deviceUsePhysicalVolumes1,
            FileSystem: &fileSystemPhysicalVolumes1,
            MountPoint: &mountPointPhysicalVolumes1,
            Name: &namePhysicalVolumes1,
            Size: &sizePhysicalVolumes1,
            UsedSize: &usedSizePhysicalVolumes1,
            InodeSize: &inodeSizePhysicalVolumes1,
        },
        {
            DeviceUse: &deviceUsePhysicalVolumes2,
            FileSystem: &fileSystemPhysicalVolumes2,
            MountPoint: &mountPointPhysicalVolumes2,
            Name: &namePhysicalVolumes2,
            Size: &sizePhysicalVolumes2,
            UsedSize: &usedSizePhysicalVolumes2,
            InodeSize: &inodeSizePhysicalVolumes2,
        },
        {
            DeviceUse: &deviceUsePhysicalVolumes3,
            FileSystem: &fileSystemPhysicalVolumes3,
            MountPoint: &mountPointPhysicalVolumes3,
            Name: &namePhysicalVolumes3,
            Size: &sizePhysicalVolumes3,
            UsedSize: &usedSizePhysicalVolumes3,
            InodeSize: &inodeSizePhysicalVolumes3,
        },
    }
	partitionStyleDisks:= model.GetServerDiskPartitionStyleEnum().MBR
	partitionStyleDisks1:= model.GetServerDiskPartitionStyleEnum().MBR
	partitionStyleDisks2:= model.GetServerDiskPartitionStyleEnum().MBR
	var listDisksbody = []model.ServerDisk{
        {
            Name: "/dev/vda",
            PartitionStyle: &partitionStyleDisks,
            DeviceUse: model.GetServerDiskDeviceUseEnum().BOOT,
            Size: int64(42949672960),
            UsedSize: int64(42948624384),
            PhysicalVolumes: listPhysicalVolumesDisks1,
        },
        {
            Name: "/dev/vdb",
            PartitionStyle: &partitionStyleDisks1,
            DeviceUse: model.GetServerDiskDeviceUseEnum().NORMAL,
            Size: int64(21474836480),
            UsedSize: int64(21473787904),
            PhysicalVolumes: listPhysicalVolumesDisks,
        },
        {
            Name: "/dev/vdc",
            PartitionStyle: &partitionStyleDisks2,
            DeviceUse: model.GetServerDiskDeviceUseEnum().VOLUME_GROUP,
            Size: int64(21474836480),
            UsedSize: int64(0),
        },
    }
	request.Body = &model.PutDiskInfoReq{
		BtrfsList: &listBtrfsListbody,
		Volumegroups: &listVolumegroupsbody,
		Disks: &listDisksbody,
	}
	response, err := client.UpdateDiskInfo(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

更新磁盘信息成功

403

鉴权失败

错误码

请参见错误码

提示

您即将访问非华为云网站,请注意账号财产安全

文档反馈

文档反馈

意见反馈

0/500

标记内容

同时提交标记内容