<br clear="all"><div>Hello ,</div><div><br></div><div><font color="#000000"><b>I want to write a script to attach a '.iso' image to a vm </b></font></div><div>so ,can you please help me or tell me some api so that i can continue my work !!!</div>
<div>I have some '.iso ' file in my storage .</div><div><br></div><div><div>script <b>rhevm_test.py</b></div></div><div><br></div><div><font color="#0000ff">from ovirtsdk.api import API</font></div><div><font color="#0000ff">from ovirtsdk.xml import params</font></div>
<div><font color="#0000ff">import time</font></div><div><font color="#0000ff"><br></font></div><div><font color="#0000ff">rhevm_uri = "<a href="https://rhevm301.xxx.xx.com:8443/api">https://rhevm301.xxx.xx.com:8443/api</a>"</font></div>
<div><font color="#0000ff">rhevm_username = "<a href="mailto:admin@rhevm301.xxx.xx.com">admin@rhevm301.xxx.xx.com</a>"</font></div><div><font color="#0000ff">rhevm_password = "iso*help"</font></div><div>
<font color="#0000ff"><br></font></div><div><font color="#0000ff">api = API(url=rhevm_uri, username=rhevm_username, password=rhevm_password)</font></div><div><font color="#0000ff">print "Connected to RHEVM Successful"</font></div>
<div><font color="#0000ff"><br></font></div><div><font color="#0000ff">MB = 1024*1024</font></div><div><font color="#0000ff">GB = 1024*MB</font></div><div><font color="#0000ff">VM_NAME = 'test_vm'</font></div><div>
<font color="#0000ff">DESCRIP = 'testing vm'</font></div><div><font color="#0000ff">CLUSTER_NAME = 'Default'<br></font></div><div><font color="#0000ff">STORAGE_NAME = 'rhevmVMdata'</font></div><div>
<div><font color="#0000ff"><br></font></div><div><font color="#0000ff">domain_name= 'rhevmiso' </font></div><div><font color="#0000ff">domain_type = 'ISO'</font></div></div><div><font color="#0000ff"><br>
</font></div><div><font color="#0000ff"><br></font></div><div><font color="#0000ff">try:</font></div><div><font color="#0000ff"> api.vms.add(params.VM(name=VM_NAME,description=DESCRIP, memory=2*GB,cluster=api.clusters.get(CLUSTER_NAME), template=api.templates.get('Blank') , </font><font color="#ff0000">cdroms = 'CentOS-6.2-x86_64-LiveCD.iso </font><span style="color:rgb(0,0,255)">'))</span></div>
<div><font color="#0000ff"> </font></div><div><font color="#0000ff"> print 'VM created'</font></div><div><font color="#0000ff"><br></font></div><div><font color="#0000ff"> api.vms.get(VM_NAME).nics.add(params.NIC(name='nic1', network=params.Network(name='rhevm'), interface='Red Hat VirtIO'))</font></div>
<div><font color="#0000ff"> print 'NIC added to VM'</font></div><div><font color="#0000ff"><br></font></div><div><font color="#0000ff"> 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))</font></div>
<div><font color="#0000ff"><br></font></div><div><font color="#0000ff"> print 'Disk added to VM'</font></div><div><font color="#0000ff"> print 'Waiting for VM to reach Down status'</font></div><div><font color="#0000ff"> while api.vms.get(VM_NAME).status.state != 'down':</font></div>
<div><font color="#0000ff"> time.sleep(1)</font></div><div><font color="#0000ff">except Exception as e:</font></div><div><font color="#0000ff"> print 'Failed to create VM with disk and NIC\n%s' % str(e)</font></div>
<div><font color="#0000ff"><br></font></div><div><font color="#0000ff">time.sleep(10)</font></div><div><font color="#0000ff"><br></font></div><div><font color="#0000ff">try:</font></div><div><font color="#0000ff"> if api.vms.get(VM_NAME).status.state != 'up':</font></div>
<div><font color="#0000ff"> print 'Starting VM'</font></div><div><font color="#0000ff"> api.vms.get(VM_NAME).start()</font></div><div><font color="#0000ff"> print 'Waiting for VM to reach Up status'</font></div>
<div><font color="#0000ff"> while api.vms.get(VM_NAME).status.state != 'up':</font></div><div><font color="#0000ff"> time.sleep(1)</font></div><div><font color="#0000ff"> else:</font></div><div>
<font color="#0000ff"> print 'VM already up'</font></div><div><font color="#0000ff">except Exception as e:</font></div><div><font color="#0000ff"> print 'Failed to Start VM:\n%s' % str(e)</font></div>
<div><br></div><div> </div><div>and got some exceptions</div><div><br></div><div><div>Connected to RHEVM Successful</div><div>Failed to create VM with disk and NIC</div><div>'str' object has no attribute 'export'</div>
<div>Failed to Start VM:</div><div>'NoneType' object has no attribute 'status'</div></div><div><br></div><div>if i remove this <font color="#ff0000">cdroms = 'CentOS-6.2-x86_64-LiveCD.iso </font><span style="color:rgb(0,0,255)">' </span><font color="#000000">the code will works fine and it will create a vm with blank template w/o any '.iso' attached !!</font></div>
<br>
<div><br></div><div><b><font color="#9900ff"><br></font></b></div><div><b><font color="#9900ff"><br></font></b></div><div><b><font color="#9900ff"><br></font></b></div><div><b><font color="#9900ff"><br></font></b></div><div>
<b><font color="#9900ff">With Regards,</font></b></div><div><b><font color="#9900ff">Romil</font></b></div><div><br></div><div><br></div><div><br></div>