[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-API] [xs-devel] "Eject ISO Image" Mechanism Proposal



On 07/01/2014 23:41, Jesse Benedict wrote:

I am setting up my own dev environment, but in the mean-time I would like to propose the following:

 

PROPOSAL

Auto Ejection of All Mounted CDs

 

PURPOSE

To make application of patches/hotfixes easier in large environments where ISO images may be mounted to VMs

 

TARGET COMPONENTS

XE command line, ie:

xe eject-all-isos

 

XenCenter (API call to eject-all-isos)

 

OR in our XSxxxxx.upadate package format as a pre-req script.


Looks very sensible and useful.

However, when scripting xe calls, "params=some,list,of,parameter,you,are,interested,in" and "--minimal" are your friends.  See inline below.

 

EXAMPLE CODE

An example is a file I wrote, xe-eject-all-isos (using Bash for simplicity):

 

#!/bin/bash

 

echo "CHECKING"

 

# Get list of VMs from xe vm-list -- specifically UUID

VMLIST=`xe vm-list is-control-domain=false | grep uuid | awk '{print $5}'`


VMLIST=$(xe vm-list is-control-domain=false params=uuid --minimal | tr ',' ' ')

should do that without grep or awk, (but sadly still using tr)

(Note for Ring3: It would be lovely for shell scripts to get a space-delimited list from --minimal rather than comma-delimited, but I cant see a convenient option for that)

 

# Loop through list and see if a DVD/CDROM is present

for VMUUID in $VMLIST

do

     VMNAME=`xe vm-list uuid=$VMUUID | grep "name-label" | awk '{print $4}'`


VMNAME="$(xe vm-list uuid=$VMUUID params=name-label --minimal)"

You need to quote in case the VM name has spaces in.

    ISOMOUNTED=`xe vm-cd-list uuid=$VMUUID | grep "empty" | awk '{print $4}'`


vm-cd-list doesn't take a uuid parameter, but then again doesn't appear to function correctly.

Note for Ring3: This appears to be a bug (tested on XS 6.2 SP1).  `xe vm-cd-list uuid=` tab completes to VM uuids, but rejects them, and the help description doesn't mention uuid= as a valid parameter.  The help text indicates that it accepts the meta-option "vm=", which works for vm names, but not for vm uuids.  Running a bare `xe vm-cd-list` insists on having the '--multiple' option, and (when provided) hands back a list of vbd uuids of cds for each vm.

Also, unlike some of the other $FOO-list options, vm-cd-list doesn't appear to like "params=".

Jesse:

Best as I can tell, you probably want:

ISOMOUNTED=$(xe vm-cd-list vm=$VMNAME | grep "empty" | awk '{print $4})

 

     if [ "$ISOMOUNTED" = "false" ] ; then

           xe vm-cd-eject uuid=$VMUUID


xe vm-cd-eject also tab completes uuid= to VM uuids but rejects them, and yet accepts vm=$VMNAME

           echo "UNMOUNTED DVD/CD IMAGE FROM $VMNAME"

     fi     

done

 

# END

echo "DONE"

 

 

 

Sincerely,


I occurs to me that all of this can be achieved with the single call

xe vm-cd-eject --multiple

So long as you are happy to accept

"operation failed on $VMUUID: Operation could not be performed because the drive is empty"

for PV guests, and

"operation failed on $VMUUID: INTERNAL_ERROR: [ Cli_util.Cli_failure("No CDs found") ]"

for HVM guests, when CDs are not actually present in the first place.  (Again, tested on XS 6.2 SP1)


~Andrew
_______________________________________________
Xen-api mailing list
Xen-api@xxxxxxxxxxxxx
http://lists.xen.org/cgi-bin/mailman/listinfo/xen-api

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.