3.9. NFS ISO ストレージの作成

仮想マシンを作成するには、ゲストオペレーティングシステム用のインストールメディアが必要です。インストールメディアは ISO ストレージドメインに保存されます。

注記

この例で提供されるコードは、リモート NFS 共有が Red Hat Virtualization で使用するために事前設定されていることを前提としています。NFS 共有の準備の詳細は、管理ガイド を参照してください。

例3.7 NFS ISO ストレージの作成

この例では、NFS ISO ドメインを storagedomains コレクションに追加します。

V4

V4 の場合、add メソッドを使用して新しいストレージドメインを追加し、types クラスを使用して次のパラメーターを渡します。

  • ストレージドメインの名前。
  • datacenters コレクションから取得したデータセンターオブジェクト。
  • host コレクションから取得したホストオブジェクト。
  • 追加されるストレージドメインのタイプ (dataiso、または export)。
  • 使用するストレージ形式 (v1v2、または 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).