Mar 312009
 

This is the 3rd and I think final revision of this script. I added the –list function, which before had to be combined with the –vm_name function. The main reason for creating this script was so that there can be an easy way to manage snapshots, especially automating the deletion, creation, reverting, and listing of snapshots. If you find this script or any of my scripts useful, please let me know.

 

perl vm_snapshot.pl --list
Platinum
name: test1
description:
state: poweredOff
vm type: VirtualMachine
time created: 2009-03-17T10:26:34.605171-04:00

Gold
name: test2
description:
state: poweredOff
vm type: VirtualMachine
time created: 2009-03-17T13:32:05Z

Silver
name: test3
description:
state: poweredOff
vm type: VirtualMachine
time created: 2009-03-17T13:32:22Z 

Remember!!! That in order to use this script you will need the Perl VI SDK installed on your linux box as well as $home/.visdkrc setup correctly

Here is an example .visdkrc…

VI_SERVER = Virtual Console Server
VI_USERNAME = login
VI_PASSWORD = passwd
VI_PROTOCOL = https
VI_PORTNUMBER = 443

Continue reading “VMware ESX SDK SnapShot Perl Script Part 3” »

Mar 312009
 

Welcome to part 2 of the “HowTo List Virtual Machines using Python and CIM“. In this part, I modified the original script so that you can pass the Virtual Machine name as well as run it with out the Virtual Machine name. In the first part of this HowTO I created the listVMsInfo.py script witch just listed all the Virtual Machines. So please enjoy the script and hopefully it will make your life just a bit easier.

python listVMsInfo.py -u "http://esxhost" -a "login passwd" -n "testVM"
VM Name 		 testVM
Operating System 	 Suse Linux Enterprise Server 10 (32-bit)
Host Name 		 None
IP Address 		 None
DataStore Used 		 [Esxtestvol] testVM.vmxRequested
State 	 Not ApplicableOperational
Status 	 Enabled
Enabled by Default 	 Enabled
Enabled State 		 Not Applicable

Download this script here!
Download

Mar 252009
 

Good Afternoon guys, here I created another Python Script. This script will check your DataStores aka VMFS. I built this script so that it can be used with Nagios and or Zenoss. The purpose of this script is so that you can monitor thresholds on a per DataStore/VMFS. You will need to download and install Pywbem in order to use this script. You can get it here
Example below…

        example below...
python check_datastore.py -u "http://esxhost" -a "login passwd" --d "Esxtestvol2" -w 60 -c 73 -m GB
Warning Esxtestvol2 189GB Avail 62% used |avail=189

python check_datastore.py -u "http://esxhost" -a "login passwd" --d "Esxtestvol2" -w 70 -c 85 -m MB
OK Esxtestvol2 194558MB Avail 61% used |avail=194558

python check_datastore.py -u "http://esxhost" -a "login passwd" --d "ISO" -w 10 -c 21 -m KB
Critical ISO 41867542528KB Avail 21% used |avail=41867542528

python check_datastore.py -u "http://esxhost" -a "login passwd" --d "Esxtestvol2" -w 70 -c 85
OK Esxtestvol2 204008849408bytes Avail 61% used |avail=204008849408

-u, --url This is the URL you will use to connect to the ESX server, "http://esxhost"
-a, --auth This is the Login and Passwd you will use, "login passwd"
-d, --dstore This is the DataStore aka VMFS to check, "Esxtestvol2"
-w, --warn This is the warning threshold that you will set, 70
-c, --crit This is the critical threshold that you will set, 85
-m, --metric This is the metric that you will use, "KB", "MB", "GB", The default is Bytes

You can download this script here check_datastore.py

Mar 242009
 

Here I created another Python script using Pywbem to get the Storage Pools from ESX.
In this script you can get the disk utilisation statistics from each datastore or from a particular datastore.
Script Updated to include the .VMX files that belong to each DataStore..


example below…
python VMdataStorePool.py -u “http://esxhost” -a “login passwd”
Available DataStores on http://esxhost

DataStore Name                   Esxtestvol2
Total Disk Space                 499G
Remaining Disk Space             189G
Used Disk Space                  310G
Percentage Used                  62%
VMX files that belong to this DataStore::
[Esxtestvol2] Win2003test3/Win2003test3.vmx
[Esxtestvol2] netwaretest/netwaretest.vmx
[Esxtestvol2] RHEL 4 NFS test/RHEL 4 NFS test.vmx
[Esxtestvol2] RHEL 5 NFS test/RHEL 5 NFS test.vmx
[Esxtestvol2] RHEL 3 NFS test/RHEL 3 NFS test.vmx
[Esxtestvol2] vicfg/vicfg.vmx

DataStore Name                   ISO
Total Disk Space                 49G
Remaining Disk Space             38G
Used Disk Space                  11G
Percentage Used                  22%
VMX files that belong to this DataStore::
None Exist

python VMdataStorePool.py -u “http://esxhost” -a “login passwd” –dstore=”KodakVol1″
Available DataStores on http://esxhost

DataStore Name                   KodakVol1
Total Disk Space                 499G
Remaining Disk Space             379G
Used Disk Space                  120G
Percentage Used                  24%
VMX files that belong to this DataStore::
[KodakVol1] Kojak/Kojak.vmx
[KodakVol1] Sakai/Sakai.vmx
[KodakVol1] bbtest2.vmx
[KodakVol1] bbtest.vmx

-u, –url       This is the URL you will use to connect to the ESX server, “http://esxhost”
-a, –auth      This is the Login and Passwd you will use, “login passwd”
-d, –dstore    This is the DataStore aka VMFS to check, “Esxtestvol2″

 

Mar 242009
 

Good morning my fellow Admins, Engineers, Scripters, Programmers, etc….. YOU GET THE IDEA :) . For the past week, I have been learning all about the CIM and WBEM API. Since I am working alot more then I have ever have with VMware. I am trying to automate as much as possible with out using Perl. Now please do not think I am hating on Perl, it is not that at all, it is just the fact that I love Python, thats all! That being said here is the 1st part in a 2 part series on Listing Virtual Machines using Pywbem in Python. I the 1st part I will show you how to list Virtual Machines and data related to those VMs. Example Below…

Update, here is the link for part 2 of this article.

    python listVMsInfo.py -u "http://esxhost" -a "login passwd"

    VM Name                  Linux DP1 Client     Operating System         Red Hat Enterprise Linux 5 (32-bit)    Host Name                dpclient.linuxdynasty    IP Address               192.168.101.124    DataStore Used           [Esxlinuxvol2] Linux Data Protector Install Ser/Linux Data Protector Install Ser.vmx    Requested State          Not Applicable    Operational Status       Enabled    Enabled by Default       Enabled    Enabled State            Not Applicable

Continue reading “HowTo List Virtual Machines using Python and CIM Part 1” »

Mar 222009
 

Apache, among many other httpds, can be configured to log to an executable’s STDIN instead of a file. But older Apaches, again like other httpds, won’t let you pipe that programme’s output to another’s input, so you’re limited to whatever the one was made to do.*

httpd error logs often contain error conditions one wants to be alerted about, but for most people that means either monitoring it with some variant of tailf running on the host, or sshing to the host to run tail (or tail -f) on the log, piped to egrep, etcetera. This kind of set-up can work fine for one or two web servers, but gets cumbersome when you have more than just a few, and can become impracticable when dealing with many or when the error logs are being written to frequently.

Well, I sometimes have to deal with six hundred or more. Screw ssh 'tailf | egrep' ...

Continue reading “Apache Logs: Multiple Pipeline” »

Mar 172009
 

Not long ago I was mutually baited into an argument with one of our developers, in which he challenged me on why I had chosen Python for my most recent project. His claim that I didn’t "know Python" he backed up with a few questions:

  1. What is Python’s method resolution order?
  2. How does it bind variables on its stack?
  3. Does Python implement closures, and if so, how?

Now, I’ll be the first to admit that I don’t "know Python". I can express my logic in the Pythonic vernacular, but there’s much about it that I don’t yet know about or understand. In much the same way as a person unfamiliar with English will use the imperative mood where the subjunctive is called for, it still works, but it’s not done in the clearest and most accurate way.

I jokingly retorted that I didn’t even know those things about Perl, not because it’s true but to make a point. I know Perl (and I know the answers in Python, too). But I don’t need to know its MRO, how it "binds variables on its stack", or how to write a closure in it, in order to write good Perl code.

"Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it." — Alan J. Perlis, "Epigrams in Programming", 1982.

Do you really have to know everything about X in order to "know X"? Do I need to know Python’s opcodes and when they’re invoked? Do I need to know Perl’s SV, HV, and other such structs and the hints maintained therein? Really, half the point of using these interpretted languages is so that you don’t need to know their guts.

Continue reading “You don’t know Python” »

Mar 082009
 

Well, I want to start this off, by saying that I am not leaving Python or Perl behind for Ruby, but that is the order in which I learned these 3 languages.  I learned Perl first and I used it strictly for about 3 years, then I learned Python and I have been using Python mainly since then and Perl when needed. Now since I am playing with Puppet, I figured I should go ahead and learn Ruby as well.

So far I am pretty impressed with Ruby as it reminds me of Python and Perl put together. Everything in Ruby is a Object just like it is in Python. Also you do not require a semicolon at the end of every line in Ruby like you do in Perl. You do not require a $ for a Scalar variable or a @ for an array or a % for a hash in Ruby, which you do require in Perl but not in Python. There are a lot more similarities then that, and I will post some of the commands that are similar and ones that are a bit different. Now this will not be a complete list of differences but enough so that you get the idea.

python	print "hello world" 			#This will print hello world but with a New Line at the End
ruby puts "hello world" #This will print hello world but with a New Line at the End
perl print "hello worldn"; #This will print hello world but with a New Line at the End

python x = 8 #x is equal to 8 which is an integer
ruby x = 8 #x is equal to 8 which is an integer
perl $x = 8; #x is equal to 8 which is an integer

python type(x) #x is what type.... Integer, String, Class... etc
ruby x.class #x is of what class.... FixNum, String, Class.. etc

python x, y, z = 1, 2, 3 #multiple assignments on one line
ruby x, y, z = 1, 2, 3 #multiple assignments on one line
perl ($x, $y, $z) = (1, 2, 3); #multiple assignments on one line

python se = "foil" #Assign a string to se
ruby se = "foil" #Assign a string to se
perl $se = "foil" #Assign a string to se

python se[0:4] #Access a slice of a string
ruby se[0..4] #Access a slice of a string

Warning: fopen(/home/dynasty/linuxdynasty.org/wp-content/plugins/wp-google-plus-one/lib/standard.txt) [function.fopen]: failed to open stream: No such file or directory in /home/dynasty/linuxdynasty.org/wp-content/plugins/wp-google-plus-one/plusone.php on line 104

Warning: fread(): supplied argument is not a valid stream resource in /home/dynasty/linuxdynasty.org/wp-content/plugins/wp-google-plus-one/plusone.php on line 105

Warning: fclose(): supplied argument is not a valid stream resource in /home/dynasty/linuxdynasty.org/wp-content/plugins/wp-google-plus-one/plusone.php on line 106
.