3.9. 创建 NFS ISO 存储
要创建虚拟机,您需要用于客户端操作系统的安装介质。安装介质保存在 ISO 存储域中。
注意
本例中提供的代码假定远程 NFS 共享已预先配置,可与 Red Hat Virtualization 一起使用。有关准备 NFS 共享的更多信息,请参阅 管理指南。
例 3.7. 创建 NFS ISO 存储
这个示例在 storagedomains 集合中添加 NFS ISO 域。
V4
对于 V4,可使用 add 方法添加新的存储域,并使用 类型 类传递以下参数:
- 存储域的名称。
-
从数据中心集合检索
的数据中心对象。 -
从主机集合检索
的主机对象。 -
正在添加的存储域的类型(
数据、iso或导出)。 -
要使用的存储格式(
v1、v2或v3)。
import ovirtsdk4 as sdk
import ovirtsdk4.types as types
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()
# Use the "add" method to create a new NFS storage domain:
sd = sds_service.add(
types.StorageDomain(
name='myiso',
description='My ISO',
type=types.StorageDomainType.ISO,
host=types.Host(
name='myhost',
),
storage=types.HostStorage(
type=types.StorageType.NFS,
address='FQDN',
path='/nfs/ovirt/path/to/myiso',
),
),
)
# 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()))
# Close the connection to the server:
connection.close()
如果 add 方法调用成功,则示例输出文本:
Storage Domain 'myiso' added (00000000-0000-0000-0000-000000000000).