API/SDK: List files in ISO domain

Latest response

I recently started messing with the Python SDK and was wondering if someone could help me figure out how to list the files in the ISO domain.  Using cURL I can achieve the desired result with the following command:

curl --cacert rhevm.crt -u "$credentials" -H "Content-Type: application/xml" -X GET https://$host/api/storagedomains/$domain_id/files

What is the equivalent to this in the Python SDK?

Responses

Hey Anthony, this is literally my second attempt at doing anything with python .. and it doesn't do what you need, but it might point you in the right direction... (I'm hoping that I will be able to figure this out and update the thread).

UPDATE: Found it..

https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Virtualization/3.1/html/Developer_Guide/Example_Attaching_an_ISO_Image_to_a_Virtual_Machine_using_Python.html

The only thing I am not happy with in this script is having to hard code the ISO_DOMAIN value in

if SD.name == "ISO_DOMAIN":

I'd like it if I was able to do a case-insensitve compare and search for 'iso' - which is rather assuming as not everyone would name their ISOS storage domain with ISO in the name.  Either way.. I think this should get you what you need.

 

#!/usr/bin/env python

# You should "import" cert from your RHEV Manager
# wget -O /etc/pki/ovirt-engine/ca.pem --no-check-certificate https://rhevmgr.company.com/ca.crt

import os

from ovirtsdk.api import API

URL='https://XXXX.YYYYY.com'
USER='admin@internal'
PASS='ZZZZ'

myapi = API ( url=URL,
  username=USER,
  password=PASS,
  ca_file="/etc/pki/ovirt-engine/ca.pem")

print "List of Storage Domains"
for sd in myapi.storagedomains.list():
    print sd.name

print

print "List of Files in"
for SD in myapi.storagedomains.list():
  if SD.name == "ISO_DOMAIN":
    FILES = myapi.storagedomains.get(name = SD.name)
    FILENAME = SD.files.list()
    for i in FILENAME:
      print "%s" % i.get_name()

That is exactly what I was looking for, Thanks James.