[Users] Related to python script for Attach Cd (.iso) to a vm
Romil Gupta
romilgupta19 at gmail.com
Fri Nov 2 07:56:18 UTC 2012
Hello ,
*I want to write a script to attach a '.iso' image to a vm *
so ,can you please help me or tell me some api so that i can continue my
work !!!
I have some '.iso ' file in my storage .
script *rhevm_test.py*
from ovirtsdk.api import API
from ovirtsdk.xml import params
import time
rhevm_uri = "https://rhevm301.xxx.xx.com:8443/api"
rhevm_username = "admin at rhevm301.xxx.xx.com"
rhevm_password = "iso*help"
api = API(url=rhevm_uri, username=rhevm_username, password=rhevm_password)
print "Connected to RHEVM Successful"
MB = 1024*1024
GB = 1024*MB
VM_NAME = 'test_vm'
DESCRIP = 'testing vm'
CLUSTER_NAME = 'Default'
STORAGE_NAME = 'rhevmVMdata'
domain_name= 'rhevmiso'
domain_type = 'ISO'
try:
api.vms.add(params.VM(name=VM_NAME,description=DESCRIP,
memory=2*GB,cluster=api.clusters.get(CLUSTER_NAME),
template=api.templates.get('Blank') , cdroms =
'CentOS-6.2-x86_64-LiveCD.iso '))
print 'VM created'
api.vms.get(VM_NAME).nics.add(params.NIC(name='nic1',
network=params.Network(name='rhevm'), interface='Red Hat VirtIO'))
print 'NIC added to VM'
api.vms.get(VM_NAME).disks.add(params.Disk(storage_domains=params.StorageDomains(storage_domain=[api.storagedomains.get(STORAGE_NAME)]),size=512*MB,status=None,interface='VirtIO',format='Preallocated',sparse=True,bootable=True))
print 'Disk added to VM'
print 'Waiting for VM to reach Down status'
while api.vms.get(VM_NAME).status.state != 'down':
time.sleep(1)
except Exception as e:
print 'Failed to create VM with disk and NIC\n%s' % str(e)
time.sleep(10)
try:
if api.vms.get(VM_NAME).status.state != 'up':
print 'Starting VM'
api.vms.get(VM_NAME).start()
print 'Waiting for VM to reach Up status'
while api.vms.get(VM_NAME).status.state != 'up':
time.sleep(1)
else:
print 'VM already up'
except Exception as e:
print 'Failed to Start VM:\n%s' % str(e)
and got some exceptions
Connected to RHEVM Successful
Failed to create VM with disk and NIC
'str' object has no attribute 'export'
Failed to Start VM:
'NoneType' object has no attribute 'status'
if i remove this cdroms = 'CentOS-6.2-x86_64-LiveCD.iso ' the code will
works fine and it will create a vm with blank template w/o any '.iso'
attached !!
*
*
*
*
*
*
*
*
*With Regards,*
*Romil*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/users/attachments/20121102/900243c7/attachment-0001.html>
More information about the Users
mailing list