3.8. 创建 NFS 数据存储
首次创建 Red Hat Virtualization 环境时,需要至少定义数据存储域和 ISO 存储域。数据存储域存储虚拟磁盘,而 ISO 存储域存储 guest 操作系统的安装介质。
storagedomains 集合包含环境中的所有存储域,并可用于添加和删除存储域。
注意
本例中提供的代码假定远程 NFS 共享已预先配置,可与 Red Hat Virtualization 一起使用。有关准备 NFS 共享的更多信息,请参阅 管理指南。
例 3.6. 创建 NFS 数据存储
这个示例在 storagedomains 集合中添加 NFS 数据域。
V4
对于 V4,可使用 add 方法添加新的存储域,并使用 类型 类传递以下参数:
- 存储域的名称。
-
从数据中心集合检索
的数据中心对象。 -
从主机集合检索
的主机对象。 -
正在添加的存储域的类型(
数据、iso或导出)。 -
要使用的存储格式(
v1、v2或v3)。
import ovirtsdk4 as sdk
import ovirtsdk4.types as types
# Create the connection to the server:
connection = sdk.Connection(
url='https://engine.example.com/ovirt-engine/api',
username='admin@internal',
password='password',
ca_file='ca.pem',
)
# Get the reference to the storage domains service:
sds_service = connection.system_service().storage_domains_service()
# Create a new NFS storage domain:
sd = sds_service.add(
types.StorageDomain(
name='mydata',
description='My data',
type=types.StorageDomainType.DATA,
host=types.Host(
name='myhost',
),
storage=types.HostStorage(
type=types.StorageType.NFS,
address='_FQDN_',
path='/nfs/ovirt/path/to/mydata',
),
),
)
# Wait until the storage domain is unattached:
sd_service = sds_service.storage_domain_service(sd.id)
while True:
time.sleep(5)
sd = sd_service.get()
if sd.status == types.StorageDomainStatus.UNATTACHED:
break
print("Storage Domain '%s' added (%s)." % (sd.name(), sd.id()))
connection.close()
如果 add 方法调用成功,则示例输出文本:
Storage Domain 'mydata' added (00000000-0000-0000-0000-000000000000).