Hello,

I am creating a script that spins up VMs, including the creation of VDIs and 
VBDs, respectively. But I have came across an issue with it and have been 
following along the documentation, found here: 
http://xapi-project.github.io/xen-api/overview.html 
<http://xapi-project.github.io/xen-api/overview.html>

When I go to create a disk image, it constantly fails:

Collecting info on the VM Specs.....
Connection Successful!
Checking for template: CentOS 7
Server has 75 VM objects (this includes templates):
Found: OpaqueRef:858d7cdb-6882-7055-74d1-2e6162533d59 CentOS 7
('Selected template: ', 'CentOS 7')
Installing new VM from the template
Adding non-interactive to the kernel commandline
Choosing an SR to instantiate the VM's disks
Choosing SR: NFS VM disks (uuid 95a58c17-6a0d-1d61-33e2-e445a5e147b3)
Rewriting the disk provisioning XML
Creating Disk for VM..... Test
Connection Successful!
Caught ['UUID_INVALID', 'VDI', '95a58c17-6a0d-1d61-33e2-e445a5e147b3']:
Traceback (most recent call last):
  File "/Users/ryankahil/Xen-Builder/bsdxenbuilder.py", line 148, in create_vdi
    src_vdi = session.xenapi.VDI.get_by_uuid(vdi_uuid)
  File "/Library/Python/2.7/site-packages/XenAPI.py", line 229, in __call__
    return self.__send(self.__name, args)
  File "/Library/Python/2.7/site-packages/XenAPI.py", line 133, in 
xenapi_request
    result = _parse_result(getattr(self, methodname)(*full_params))
  File "/Library/Python/2.7/site-packages/XenAPI.py", line 203, in _parse_result
    raise Failure(result['ErrorDescription'])
Failure: ['UUID_INVALID', 'VDI', '95a58c17-6a0d-1d61-33e2-e445a5e147b3’]

I am following the documentation as best as possible and can’t seem to find out 
why the UUID is invalid. The SR I am using is NFS if that helps. And have taken 
some code snippets for VDI and VBD creations in your GitHub repo to see if 
there is something I am doing wrong but again, the same issue. Here is a 
snippet of my code:

def create_vdi(ctx,name,sr,readonly,hdspace,diskimage,vdi_uuid):
    click.echo("Creating Disk for VM..... " + name)
    session = xen_session()
    vdi = None
    try:
        src_vdi = session.xenapi.VDI.get_by_uuid(vdi_uuid)
       # sr = session.xenapi.VDI.get_SR(src_vdi)
        vdi_args = session.xenapi.VDI.get_record(src_vdi)
        vdi = session.xenapi.VDI.create(vdi_args)
        create_vbd(name,vdi,readonly,userdevice)
    except Exception, e:
        print("Caught %s: " % str(e))
        traceback.print_exc()

The vdi_uuid is provided in another method:

        sr_pool = session.xenapi.pool.get_all()[0]
        default_sr = session.xenapi.pool.get_default_SR(sr_pool)
        default_sr = session.xenapi.SR.get_record(default_sr)
        print("Choosing SR: %s (uuid %s)" % (default_sr['name_label'], 
default_sr['uuid']))
        print("Rewriting the disk provisioning XML")
        spec = provision.getProvisionSpec(session, vm)
        spec.setSR(default_sr['uuid'])
        provision.setProvisionSpec(session, vm, spec)


        create = session.xenapi.VM.provision(vm)
        session.xenapi.VM.start(vm,False, True)
        vdi_uuid = default_sr['uuid’]

I have noticed that once the VM is created (in a stopped state due to having no 
boot disk), simply attaching a DVD drive allows me to install CentOS. But is 
there a way to programmatically do this with XenAPI (I thought creating the 
VDI/VBD does this for me)?

Thanks,
Ryan
_______________________________________________
Xen-api mailing list
Xen-api@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-api

Reply via email to