Este contenido no está disponible en el idioma seleccionado.

2.10. Example: Creating NFS Data Storage using Python


When a Red Hat Enterprise Virtualization environment is first being created it is necessary to define at least a data storage domain, and an ISO storage domain. The data storage domain will be used to store virtual machine disk images while the ISO storage domain will be used to store installation media for guest operating systems.
The API class provides access to a storage domains collection, named storagedomains. This collection contains all the storage domains in the environment. The storagedomains collection can also be used to add and remove storage domains.

Note

The code provided in this example assumes that the remote NFS share has been pre-configured for use with Red Hat Enterprise Virtualization. Refer to the Red Hat Enterprise Virtualization Administration Guide for more information on preparing NFS shares for use.

Example 2.9. Creating NFS data storage using Python

This Python example adds an NFS data domain to the storagedomains collection. Adding an NFS storage domain in Python can be broken down into several steps:
  1. Identify the data center to which the storage must be attached, using the get method of the datacenters collection.
    dc = api.datacenters.get(name="Default")
    Copy to Clipboard Toggle word wrap
  2. Identify the host that must be used to attach the storage, using the get method of the hosts collection.
    h = api.hosts.get(name="Atlantic")
    Copy to Clipboard Toggle word wrap
  3. Define the Storage parameters for the NFS storage domain. In this example the NFS location 192.0.43.10/storage/data is being used.
    s = params.Storage(address="192.0.43.10", path="/storage/data", type_="nfs")
    Copy to Clipboard Toggle word wrap
  4. Request creation of the storage domain, using the add method of the storagedomains collection. In addition to the Storage parameters it is necessary to pass:
    • A name for the storage domain.
    • The data center object that was retrieved from the datacenters collection.
    • The host object that was retrieved from the hosts collection.
    • The type of storage domain being added (data, iso, or export).
    • The storage format to use (v1, v2, or v3).
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/data", type_="nfs")
    sd_params = params.StorageDomain(name="data1", data_center=dc, host=h, type_="data", 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
Copy to Clipboard Toggle word wrap
If the add method call is successful then the script will output:
Storage Domain 'data1' added (bd954c03-d180-4d16-878c-2aedbdede566).
Copy to Clipboard Toggle word wrap
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat