<div dir="ltr"><div><br></div><div>We are working on a script so that we can create an ISCSI LUN on our SAN and then directly assign it to a vm.</div><div><br></div><div>We have been able to get it to work but with one small annoyance. I can't figure out how to populate size,serial,vendor_id and product_id via the api. Would anyone be able to point me in the right direction ? code (see def add_disk):</div>
<div><br></div><div><div>def get_clusterid(cluster_name):</div><div> cluster = ovirt_api.clusters.get(cluster_name)</div><div> try:</div><div> return <a href="http://cluster.id">cluster.id</a></div><div> except:</div>
<div> logging.error('the cluster: %s does not appear to exist' % cluster_name )</div><div> sys.exit(1)</div><div> </div><div>def nominate_host(cluster_id):</div><div> for host in ovirt_api.hosts.list():</div>
<div> if <a href="http://host.cluster.id">host.cluster.id</a> == cluster_id and host.status.state == 'up':</div><div> host.iscsidiscover</div><div> return host</div><div> logging.error('could not find a suitable host to nominate in cluster:')</div>
<div> sys.exit(1)</div><div><br></div><div><br></div><div>def iscsi_discover_and_login(cluster,target,portal,chap_user,chap_pass):</div><div> clusterid=get_clusterid(cluster)</div><div> host=nominate_host(clusterid)</div>
<div> </div><div> iscsidet = params.IscsiDetails()</div><div> iscsidet.address=portal</div><div> iscsidet.username=chap_user</div><div> iscsidet.password=chap_pass</div><div> iscsidet.target=target</div>
<div> </div><div> host.iscsidiscover(params.Action(iscsi=iscsidet))</div><div> result = host.iscsilogin(params.Action(iscsi=iscsidet))</div><div> </div><div> if result.status.state == 'complete':</div>
<div> </div><div> storecon = params.StorageConnection()</div><div> storecon.address=portal</div><div> storecon.type_='iscsi'</div><div> storecon.port=3260</div><div> storecon.target=target</div>
<div> storecon.username=chap_user</div><div> storecon.password=chap_pass</div><div> </div><div> ovirt_api.storageconnections.add(storecon)</div><div><br></div><div> return result</div><div> # error checking code needs to be added to this function</div>
<div> </div><div>def add_disk(vm_name,wwid,target,size,portal):</div><div> </div><div> logunit = params.LogicalUnit()</div><div> <a href="http://logunit.id">logunit.id</a>=wwid</div><div> logunit.vendor_id='EQLOGIC'</div>
<div> logunit.product_id='100E-00'</div><div> logunit.port=3260</div><div> logunit.lun_mapping=0</div><div> logunit.address=portal</div><div> logunit.target=target</div><div> logunit.size=size * 1073741824</div>
<div> </div><div> stor = params.Storage(logical_unit=[logunit])</div><div> stor.type_='iscsi'</div><div> </div><div> </div><div> disk = params.Disk()</div><div> disk.alias = 'vm-' + vm_name</div>
<div> <a href="http://disk.name">disk.name</a> = disk.alias</div><div> disk.interface = 'virtio'</div><div> disk.bootable = True</div><div> disk.type_ = 'iscsi'</div><div> disk.format='raw'</div>
<div> disk.set_size(size * 1073741824)</div><div> #disk.size=size * 1073741824</div><div> #disk.active=True</div><div> </div><div> disk.lun_storage=stor</div><div> </div><div> try:</div><div> result = ovirt_api.disks.add(disk)</div>
<div> except:</div><div> logging.error('Could not add disk')</div><div> sys.exit(1)</div><div> </div><div> attachdisk=ovirt_api.disks.get(disk.alias)</div><div> attachdisk.active = True</div>
<div> </div><div> try:</div><div> ovirt_api.vms.get(vm_name).disks.add(attachdisk)</div><div> except:</div><div> logging.error('Could attach disk to vm')</div><div> sys.exit(1)</div>
<div> </div><div> return result</div></div><div><br></div><div><br></div><div><br></div><div>If we could just get the size to show correctly that would be enough, the others don't really matter to me.</div><div>
<br></div><div><br></div><div>Thanks</div><div><br></div><div><i>Gary Lloyd</i><div>----------------------------------<br><div>IT Services</div><div>Keele University</div></div><div>-----------------------------------</div>
</div>
</div>