PowerShell, XenServer Paul Fulbright PowerShell, XenServer Paul Fulbright

PowerShell: XenServer Get VM IP Address

This like all of these PowerShell XenServer examples requires you load the snapin and an active connection to a XenServer.

First you need to get a reference to your VM of choice, in this case I know the exact VM by name so I do this:

$vms = Get-XenServer:VM | Where-Object {$_.name_label -eq "<nameofVM>"}

Now I want to read the guest metrics on this VM to find the IP Address, note that this requires XSTools to be installed and the IP address wont be available right away, typically it seems to only be available after the machine has both booted, and had time for the XSTools to report it's IP to guest metrics, but once it's available you can get it by doing this:

Get-XenServer:VM_guest_metrics.Networks -VMGuestMetrics $vms.guest_metrics

Be aware that if you want to get a list of IP's for more than one VM you will need to foreach through $vms and run the command for each one.

One potential use of this is to, say, clone a new VM from a template, start it, wait for it to establish a network connection then Test-Connection until you get a result, at which time you can proceed to do whatever else you need to do (via WinRM for instance, if you have it enabled in the template).

Read More
PowerShell, XenServer Paul Fulbright PowerShell, XenServer Paul Fulbright

PowerShell: XenServer Messages (Since)

If you are expecting a message to occur after an action you are taking the following may be of use to you.

$messages = Get-XenServer:Message.Since -Since [System.DateTime]::Now
foreach($i in $messages.Values) { $i }

Obviously this doesn't do anything intelligent like look for the specific event, but once you see the output you can customize it to do whatever you want.

Read More
PowerShell, XenServer Paul Fulbright PowerShell, XenServer Paul Fulbright

PowerShell: XenServer Recreate ISO Store

A little too much code to past directly on SquareSpace (haven't had time to figure out a way around that) but here it is.

Read More
PowerShell, XenServer Paul Fulbright PowerShell, XenServer Paul Fulbright

PowerShell: Destroy CIFS ISO Library

This is step one of two in destroying (and then re-creating) a CIFS ISO library in XenServer, the reasons you may need to do this are varied, this is personally useful to me in a lab environment when the repo location or user credentials may change often. Everythign below requires the XenServer PSSnapin.

First thing we want to do is snag the info for the SR we want to delete:

$sr = Get-XenServer:SR | Where-Object {$_.content_type -eq "iso" -and $_.type -ne "udev" -and $_.name_label -ne "XenServer Tools"}

This filters out the CD-ROM (udev) and XS Tools and just returns us SR's whose content type is ISO, so it shouldn't matter what you name your repo (um, as long as you don't name it XenServer Tools I guess).

Now we need to unplug it:

foreach($i in $sr.PBDs){Invoke-XenServer:PBD.Unplug -SR $i}

Do you need to foreach this? Probably not. But if you DO happen to set it up with multiple PBD's then it will still fail on the next step because you only unplugged some of the PBD's, when in doubt, be thorough.

Now lets remove the SR:

Invoke-XenServer:SR.Forget -SR $sr.name_label

There you go, the next step will be to ask for a path, user and password to create a new ISO Library, which I'll cover next time.

 

Read More
XenServer Paul Fulbright XenServer Paul Fulbright

XenServer Appliance Import Fails

If you find your import sitting at "Connecting..." with a reference to the specific VDI it is trying to create at the end, 99% chance it failed to get an IP. At the last phase of the import just specify a static IP, in my case for whatever reason DHCP wasn't responding fast enough so even though it LOOKED like it was getting an IP it just wasn't making the connection. Manually setting an IP solved it.

Read More
XenServer Paul Fulbright XenServer Paul Fulbright

XenServer: Manually Set Memory Range.

xe vm-list

Grab the uuid for the VM you wish to modify.

xe vm-param-set -uuid=<uuid> -memory-static-min=1024MiB

xe vm-param-set -uuid=<uuid> -memory-dynamic-min=1024MiB

xe vm-param-set -uuid=<uuid> -memory-static-max=1024MiB

xe vm-param-set -uuid=<uuid> -memory-dynamic-max=1024MiB

You will most commonly use MiB to specify the memory size.

My most common reason for setting this is the Windows 7 template sets the minimum RAM to 2GB, which IS the recommended minimum, but obviously not needed, especially if the VM is doing primarily lightweight testing (testing an install, etc.).

 

Read More
XenServer Paul Fulbright XenServer Paul Fulbright

XenServer: Add search domain to DNS.

xe pif-list host-name-label=<hostname> management=true

xe pif-param-set uuid=<uuid> other-config:domain=domain.com

reboot

hostname -d -v

Should show the search domains at the bottom.

Alternatively:

cat /etc/resolv.conf

Read More
XenServer Paul Fulbright XenServer Paul Fulbright

XenServer: PXE Boot failure/solution.

So trying to boot off PXE on a XenServer VM seems to VERY frequently cause problems. I finally figured out how to work around the issue.

When booting from network (you probably need to bump network boot up above the "will not boot" line) hit Ctrl+B when it says to bring up the gPXE command line. Then do the following.

  • dhcp net0 (or whatever adapter you want to use)
  • config
  • set "next-server" to the tftp server location (this is where all your boot images are) use the IP ot hostname.
  • set "filename" to the path to the correct .com file. In my case I had to bypass the OSChooser and set the path to Boot/x64/wdsnbp.com
  • Ctrl+X
  • autoboot
  • You should see it load the image and continue.

Note that you NEED to know the location where the images are stored and be able to see them so you know what file to point it to. If you can't figure it out, start pointing it to every .com you can find lol.

Also beware that on reboot these settings are NOT saved. Which is annoying. But hey, it beats flat out not being able to RIS.

Read More
Paul Fulbright Paul Fulbright

XenServer: Create RAID SR.

A quick How-To: on adding a RAID array as an SR in XenServer, the version I personally used was 5.6 but 5.5 and 5.0 should be identical.

Steps to create an SR in a Xenserver.

Locate the RAID array partition.

cat /proc/partitions

This returns a list of all partitions, find the RAID array and make note of it's name (sda, sdb, sdx, etc.).

Now locate the disk-id.

ll /dev/disk/by-id

This lists disk ID's, look for the ID that matches the partition name from the previous step.

Obtain the XenServer host-uuid, we need this because we need to specify the XenServer as the host to attach the SR to in the next step.

xe host-list

Create the SR.

xe sr-create content-type=user device-config:device=/dev/<sdx> host-uuid=<host-uuid> name-label=”RAID Array” shared=false type=lvm

You should now be able to see (and use) your RAID array in XenCenter.

Read More