Show Table of Contents
2.10. Example: Creating NFS ISO Storage using Python
To create a virtual machine you must be able to provide installation media for the guest operating system. In a Red Hat Virtualization environment you store the installation media on an ISO storage domain.
Note
The code provided in this example assumes that the remote NFS share has been pre-configured for use with Red Hat Virtualization. Refer to the Red Hat Virtualization Administration Guide for more information on preparing NFS shares for use.
Example 2.9. Creating NFS ISO storage using Python
This Python example adds an NFS ISO domain to the
storagedomains collection. Adding an NFS storage domain in Python can be broken down into several steps:
- Identify the data center to which the storage must be attached, using the
getmethod of thedatacenterscollection.dc = api.datacenters.get( name="Default" )
- Identify the host that must be used to attach the storage, using the
getmethod of thehostscollection.h = api.hosts.get(name="Atlantic")
- Define the
Storageparameters for the NFS storage domain. In this example the NFS location192.0.43.10/storage/isois being used.s = params.Storage(address="192.0.43.10", path="/storage/iso", type_="nfs")
- Request creation of the storage domain, using the
addmethod of thestoragedomainscollection. In addition to theStorageparameters it is necessary to pass:- A name for the storage domain.
- The data center object that was retrieved from the
datacenterscollection. - The host object that was retrieved from the
hostscollection. - The type of storage domain being added (
data,iso, orexport). - The storage format to use (
v1,v2, orv3).
Once these steps are combined, the completed script is:
from ovirtsdk.api import API
from ovirtsdk.xml import params
try:
api = API (url="https://HOST",
username="USER@DOMAIN",
password="PASS",
ca_file="ca.crt")
dc = api.datacenters.get(name="Default")
h = api.hosts.get(name="Atlantic")
s = params.Storage(address="192.0.43.10", path="/storage/iso", type_="nfs")
sd_params = params.StorageDomain(name="iso1", data_center=dc, host=h, type_="iso", storage_format="v3", storage=s)
try:
sd = api.storagedomains.add(sd_params)
print "Storage Domain '%s' added (%s)." % (sd.get_name())
except Exception as ex:
print "Adding storage domain failed: %s" % ex
api.disconnect()
except Exception as ex:
print "Unexpected error: %s" % ex
If the
add method call is successful then the script will output:
Storage Domain 'iso1' added (789814a7-7b90-4a39-a1fd-f6a98cc915d8).

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.