Monday, April 16, 2012

FUNC - Fedora Unified Network Controller Installation Script

FUNC is an open source automation tool developed by using Python programming language. We can use this tool for automating system admin tasks such as status check, configuration tweak, file transfer, rebooting the systems etc in multiple Linux-based systems. It uses the typical Client-Server model, where the server is called by the term "overlord" and the clients which are binded to the server are called as "minions".

Check out this link for more details with examples:
http://advanced-sysadmin-stuff.blogspot.in/2011/03/func-fedora-unified-network-controller.html

I have developed an Installation bundle which consists of Script for installing and configuring the FUNC client with all the required packages. URL to download the software bundle : http://dl.dropbox.com/u/50666315/blog/func_pack.tar

Just download it, extract and install the FUNC client by executing the 'install_func_client.sh' script.
http://dl.dropbox.com/u/50666315/scripts/install_func_client.sh

SAMPLE INSTALLATION:

[root func_pack]# bash install_func_client.sh

Enter the FQDN of FUNC Master Server : funcserver.domain.com

Starting RPM installation

Preparing...                ########################################### [100%]
   1:pyOpenSSL              ########################################### [100%]
Preparing...                ########################################### [100%]
   1:certmaster             ########################################### [100%]
Preparing...                ########################################### [100%]
   1:python-ctypes          ########################################### [100%]
Preparing...                ########################################### [100%]
   1:python-paste           ########################################### [100%]
Preparing...                ########################################### [100%]
   1:python-simplejson      ########################################### [100%]
Preparing...                ########################################### [100%]
   1:smolt                  ########################################### [100%]
Preparing...                ########################################### [100%]
   1:func                   ########################################### [100%]

 Proceeding with configuring the FUNC client
 PLEASE CONFIRM IF ALL THE LISTED BELOW RPMS ARE INSTALLED PROPERLY ?

pyOpenSSL-0.6-2.el5.i386.rpm
certmaster-0.27-1.el5.noarch.rpm
python-ctypes-1.0.2-2.el5.i386.rpm
python-paste-1.7.4-1.el5.noarch.rpm
python-simplejson-2.0.9-8.el5.i386.rpm
smolt-1.4-2.3.el5.noarch.rpm
func-0.27-1.el5.noarch.rpm

Type either 'yes' or 'no' : yes
Updating the config file
 Starting the FUNC Service

Starting func daemon

FUNC client service has been started successfully
Proceeding with registering to FUNC Master Server

The CSR(Certmaster Sign Request) has been successfully send to FUNC Master Server.
Please contact your FUNC Server Administrator to accept the CSR for this machine.

[root - func_pack]#

Saturday, April 14, 2012

PowerCLI: Start and Stop the VMs resides on a vCenter Folder

Starting all the VMs in the folder 'production1'

$vms = Get-VM -Location production1

ForEach($vm in $vms)                 # Start each VM in the folder 'production1'
{
start-vm -RunAsync -VM $vm -Confirm:$false
}

Stopping all the VMs in the folder 'production1'

$vms = Get-VM -Location production1
ForEach($vm in $vms)
# Try a graceful shutdown of VMGuest if vmware tools are installed, Otherwise just stop the VM
{
$vm_view = $vm | get-view
$vmtoolsstatus = $vm_view.summary.guest.toolsRunningStatus
Write-Host “VM $vm says tools status is $Vmtoolsstatus”
if ($vmtoolsstatus -eq “guestToolsRunning”)
{
Shutdown-VMGuest -VM $vm -Confirm:$false       # Shutting down VMGuest gracefully
}
else
{
Stop-VM -RunAsync -VM $vm -Confirm:$false      # Stopping the VM
}
}

Friday, April 13, 2012

PowerCLI script for listing VM partition information

This script will display the VM partition information of all the Virtual Machines (both Linux and Windows) in vCenter.

PS> ForEach ($VM in Get-VM ){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath, @{N="Capacity(MB)";E={[math]::Round($_.Capacity/ 1MB)}}, @{N="Free Space(MB)";E={[math]::Round($_.FreeSpace / 1MB)}}, @{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}

<output not shown>


-------------------------------------------------------------------------------------------------------------------------------------------------------

This modified version of above script will display the VM partition information of the Virtual Machines that are hosted on ESXi host : "iss-esxi-vm01.xxxx.com"

PS> ForEach ($VM in get-vmhost iss-esxi-vm01.xxxx.com | get-vm){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath, @{N="Capacity(MB)";E={[math]::Round($_.Capacity/ 1MB)}}, @{N="Free Space(MB)";E={[math]::Round($_.FreeSpace / 1MB)}}, @{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}

Name           : itc-esxi-dnx01.xxxx.com
DiskPath       : C:\
Capacity(MB)   : 51191
Free Space(MB) : 36503
Free Space %   : 71

Name           : iss-esxi-mail1.xxxx.com
DiskPath       : /
Capacity(MB)   : 1008
Free Space(MB) : 813
Free Space %   : 81

Name           : iss-esxi-mail1.xxxx.com
DiskPath       : /boot
Capacity(MB)   : 99
Free Space(MB) : 86
Free Space %   : 87

Name           : iss-esxi-mail1.xxxx.com
DiskPath       : /tmp
Capacity(MB)   : 1008
Free Space(MB) : 975
Free Space %   : 97

<output truncated>

Thursday, April 12, 2012

PowerCLI scripts for automating VMware vSphere - part 1

PS> get-vm iss-esx-scc1

Name                 PowerState Num CPUs Memory (MB)
----                 ---------- -------- -----------
iss-esx-scc1.itci... PoweredOn  2        8192

PS> get-vm iss-esx-scc1 | format-list

Name            : iss-esx-scc1.xxxx.com
PowerState      : PoweredOn
NumCpu          : 2
MemoryMB        : 8192
HardDisks       : {Hard disk 1, Hard disk 2}
CDDrives        : {CD/DVD drive 1}
FloppyDrives    : {Floppy drive 1}
NetworkAdapters : {Network adapter 1, Network adapter 2}
UsbDevices      : {}
Host            : iss-esx-vm01.xxxx.com
Id              : VirtualMachine-vm-178
Notes           :

PS> get-vm iss-esx-scc1 | format-list *

PowerState           : PoweredOn
Version                 : v7
Description            :
Notes                   :
Guest                   : iss-esx-scc1.xxxx.com:
NumCpu                  : 2
MemoryMB                : 8192
HardDisks               : {Hard disk 1, Hard disk 2}
NetworkAdapters         : {Network adapter 1, Network adapter 2}
UsbDevices              : {}
CDDrives                : {CD/DVD drive 1}
FloppyDrives            : {Floppy drive 1}
Host                    : iss-esx-vm01.xxxx.com
HostId                  : HostSystem-host-115
VMHostId                : HostSystem-host-115
VMHost                  : iss-esx-vm01.xxxx.com
VApp                    :
FolderId                : Folder-group-v22
Folder                  : vm
ResourcePoolId          : ResourcePool-resgroup-114
ResourcePool            : Resources
PersistentId            : 5256a506-9e03-ac9c-c997-b2b8936b1b0b
UsedSpaceGB             : 16.80688
ProvisionedSpaceGB      : 127.0002
DatastoreIdList         : {Datastore-datastore-148, Datastore-datastore-149}
HARestartPriority       :
HAIsolationResponse     :
DrsAutomationLevel      :
VMSwapfilePolicy        : Inherit
VMResourceConfiguration : CpuShares:Normal/2000 MemShares:Normal/81920
CustomFields            : {}
ExtensionData           : VMware.Vim.VirtualMachine
Id                      : VirtualMachine-vm-178
Name                    : iss-esx-scc1.xxxx.com
Uid                     : /VIServer=ardevaraju@iss-esx-vc02.xxxx.com:443/VirtualMachine=VirtualMachine-vm-178/

PS> get-vmhost | get-vm | where-object { $_ -like "*nim*" }

Name                 PowerState Num CPUs Memory (MB)
----                 ---------- -------- -----------
iss-esx-nimmonfp0... PoweredOn  2        4032
iss-esx-nim01.itc... PoweredOn  4        8192
iss-esx-nimsql1.i... PoweredOn  4        8192
iss-esx-nimthub01... PoweredOn  2        4096
iss-esx-nimfhub01... PoweredOn  2        4096

PS> get-vmhost | get-vm | where-object { $_.name -eq 'iss-esx-nim01' } | Get-NetworkAdapter

Name                 Type       NetworkName  MacAddress         WakeOnLan
                                                                  Enabled
----                 ----       -----------  ----------         ---------
Network adapter 1    e1000      ISS Network  00:50:56:b7:65:e3       True
Network adapter 2    e1000      VM Storag... 00:50:56:b7:3c:38       True

PS> get-vmhost | get-vm | where-object { $_.name -eq 'iss-esx-nim01' } | Get-Datastore

Name                               FreeSpaceMB      CapacityMB
----                               -----------      ----------
iss-esx-nim01:OSDISKn                    21704           81664
iss-esx-nim01:D_DISK                     19526           50944

PS > get-vmhost iss-esx-vm01 | get-vm | get-vmguest

State          IPAddress            OSFullName
-----          ---------            ----------
Running        {10.0.0.40, 10.15... Microsoft Windows Server 2008 R2 (64-bit)
Running        {172.17.1.200}       Microsoft Windows Server 2003 (32-bit)
NotRunning     {}
Running        {10.0.0.186, 10.1... Microsoft Windows Server 2008 R2 (64-bit)
NotRunning     {}
NotRunning     {}
NotRunning     {}
NotRunning     {}
NotRunning     {}
Running        {10.150.1.28, fe8... Red Hat Enterprise Linux 4 (32-bit)


Running        {10.150.4.157, fe... Red Hat Enterprise Linux 4 (32-bit)
Running        {10.150.1.35, fe8... Red Hat Enterprise Linux 5 (64-bit)
Running        {10.150.1.14}        Microsoft Windows Server 2008 (32-bit)
NotRunning     {}
Running        {10.0.0.180, 10.1... Microsoft Windows Server 2008 R2 (64-bit)
Running        {10.0.0.183, 10.1... Microsoft Windows Server 2008 R2 (64-bit)
Running        {10.150.1.16, 10.... Microsoft Windows Server 2008 R2 (64-bit)
Running        {169.254.9.208, 1... Microsoft Windows Server 2003 (32-bit)

PS> get-vmhost iss-esx-vm01 | get-vm | where {$_.Memorymb -lt 2048}

Name                 PowerState Num CPUs Memory (MB)
----                 ---------- -------- -----------
rfin-esx-mail1.it... PoweredOn  1        512
iss-esx-w2k3_32.h... PoweredOff 1        1024
iss-esx-w2k8_64.h... PoweredOff 2        1024
iss-esx-rhel5664-... PoweredOff 2        1024
hjbb-esx-ftp1.itc... PoweredOn  1        500
iss-esx-mman01.it... PoweredOn  2        512
iss-esx-sfm01.itc... PoweredOn  2        1024

PS> get-vmhost iss-esx-vm01 | get-vm | where {$_.Memorymb -gt 2048}

Name                 PowerState Num CPUs Memory (MB)
----                 ---------- -------- -----------
iss-esx-nimmonfp0... PoweredOn  2        4032
itc-esx-dnx01.itc... PoweredOn  2        4096
iss-esx-scc1.itci... PoweredOn  2        8192
iss-esx-mail1.itc... PoweredOn  2        4096
iss-esx-ad01.itci... PoweredOn  2        4096
iss-esx-mgr02.itc... PoweredOn  4        8192
iss-esx-nim01.itc... PoweredOn  4        8192
iss-esx-sdp01.itc... PoweredOn  4        4096
iss-esx-nimsql1.i... PoweredOn  4        8192

PS>

PowerCLI Banner: http://dl.dropbox.com/u/50666315/blog/Final-PowerCLI-4.1.1.pdf

Popular Posts

About Me

My photo
I have started this blog to share my work experience and spread some smart solutions on Linux to Internet community. I'm hoping more people will get benefited from this blog. Brief about me: I have 14+ years experience working as System Admin and currently work with VMware.