Unable to delete Xenserver VDI – This operation cannot be performed because this VDI is in use by some other operation

After having problems with one of my Xenservers in my lab, I decided to build a SAN to store my VMs. After building the SAN, I created an iSCSI target and added it to the Xenserver pool. Next, I started moving a Windows 7 VM to the new SR, but changed my mind while it was copying. After I got the copy to cancel, I still had the virtual disk showing in the repository, and it was eating up space. When I went to delete it, the delete button was greyed out. I tried restarting the toolstack, but no luck.

So I guess it’s time to go to the command line. First thing I do is get the UUID of the VDI using the “xe vdi-list sr-uuid=611441f9-20c7-6775-716a-37c78b6d672e”. I get a list of VDIs and quickly find the uuid of the disk I want to delete.

uuid ( RO) : 203137f6-d98b-4e8e-8940-263e26360559
name-label ( RW): Win7-Image 0
name-description ( RW): DELETE
sr-uuid ( RO): 611441f9-20c7-6775-716a-37c78b6d672e
virtual-size ( RO): 25769803776
sharable ( RO): false
read-only ( RO): false

Now let’s try deleting with “xe vdi-destory uuid=611441f9-20c7-6775-716a-37c78b6d672e”. Result: The uuid you supplied was invalid. Whoops. Entered the SR uuid. Ok, let’s try this again. “xe vdi-destory uuid=203137f6-d98b-4e8e-8940-263e26360559

This operation cannot be performed because this VDI is in use by some other operation
vdi: 203137f6-d98b-4e8e-8940-263e26360559 (Win7-Image 0)
operation: destroy

Eh boy. OK, so what is using it? When I’m looking at Xencenter, it shows the Virtual machine it is attached to is “Control domain on host xen1”, which is my first xenserver.

Next we need to look at the the virtual block devices that might be tying up this VDI by entering “xe vbd-list vdi-uuid=203137f6-d98b-4e8e-8940-263e26360559”. This should give you the result back similar to the following.

uuid ( RO) : fb58a7e8-6ad3-ed6b-05bb-817d6ff1e4f0
vm-uuid ( RO): 233c0fd0-1a4d-4746-8ae6-8d0bd642a145
vm-name-label ( RO): Control domain on host: xen1
vdi-uuid ( RO): 203137f6-d98b-4e8e-8940-263e26360559
empty ( RO): false
device ( RO): sm/backend/611441f9-20c7-6775-716a-37c78b6d672e/203137f6-d98b-4e8e-8940-263e26360559

Now, let’s delete that vbd so it releases the vdi by entering “xe vbd-unplug uuid=fb58a7e8-6ad3-ed6b-05bb-817d6ff1e4f0” followed by “xe vbd-destroy uuid=fb58a7e8-6ad3-ed6b-05bb-817d6ff1e4f0″.

You should now be able to delete the drive from Xencenter for from the command line.

Down and dirty way to determine average latency using Python, text files, and a batch file | Playing with Python

Here’s a post I put out on my python blog. I figured it would be helpful for sysadmins and the like, so I figured I’d post it here as well.

A client of mine is looking to give access to their ERP application to their office and plant in Shanghai. They are going to do this via Citrix, so I wanted to see what latency was like. To do this, I just setup a batch file that runs pings to both locations and outputs the results to a text file. I scheduled this to run every 4 hours. Here’s the batch file.

@echo off
set officefile="C:TempShanghaiPingsping_office_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%-%time:~3,2%.txt"
set plantfile="C:TempShanghaiPingsping_plant_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%-%time:~3,2%.txt"
ping -n 10 192.168.70.254 > %officefile%
ping -n 10 192.168.71.254 > %plantfile%

After running for about a week, I wrote a small python script to grab all the ping times out of the text files and give me the maximum, minimum, and average response times. You are prompted for the location of the text files and the beginning pattern, so you can get the results for each site.

import os
import re

pingfiles = []
filepath = input('Please enter where files are stored:(Ex: C:files)  :   ')
filepath = filepath + ''
beginning = input('Please enter what each file starts with: (Ex: ping_plant)  :  ')
for root, dirs, files in os.walk(filepath):
	for file in files:
		if file.startswith(beginning):
			pingfiles.append(file)

pingtimes = []

for file in pingfiles:
    filename = filepath + file
    openfile = open(filename, 'r')
    lines = openfile.readlines()
    responsetimes = re.findall(r'bytes=32 time=(d+)ms', str(lines))
    pingtimes = pingtimes + responsetimes
    openfile.close()

pingtimes = [int(i) for i in pingtimes]
print("Maximum ping time is", max(pingtimes))
print("Minimum ping time is", min(pingtimes))
print("Average ping time is", round(sum(pingtimes) / len(pingtimes)),)

Here’s the output for one location:

Maximum ping time is 307
Minimum ping time is 237
Average ping time is 254

I know this is nothing special, but I figured I’d throw it out there in case any other newbies or sys admins need to get this information quickly without software.

via Down and dirty way to determine average latency using Python, text files, and a batch file | Playing with Python.

WordPress 404 error on preview.. aka this is embarrassing error

I was having no luck finding a solution for this issue, so I figured I’d blog about it for posterity (so I can find it next time when I forget what I did). I recently setup a new blog about business continuity. I set everything up like this blog and my python blog, and everything seemed to work fine. I put my intro post out without a problem.

The next time I go to post, I put my first draft in and go to preview the post. This time, I get a message telling me the site is so embarrassed this happened but the page cannot be found. While this 404 error is kinda funny, I had no idea why I was getting it. Also, I could still post without issue. It was preview only that wasn’t working.

I must have played with the permalinks a hundred times including editing the .htaccess file directly. I searched on WordPress’s site and constantly came across the resolution of it’s your web browser. Clear your cache. Not so in my case. I tried it from several computers.

After this, I disabled all plugins, which didn’t help either. I changed the theme. No go. Finally, a week after this started, I just so happened to be looking at my settings and noticed I didn’t have the same URL in the site address and the WordPress address. One had http://www.playingwithdisaster.com and the other had http://playingwithdisaster.com. Unfortunately, I can’t remember which was which now, but that did the trick.

Wordpress and site URL