mercoledì 31 luglio 2013

VMware: Deploy VMs from Template using PowerCLI

After yesterday's introductive post, today I would like to share a simple, yet powerful, PowerCLI script that allows you to deploy VMs from a Template.

This is the script structure:

 1..<N> | Foreach {  
 New-VM -vmhost <ESX_HOST> -Name <VM_NAME> -Template <TEMPLATE> -Datastore <DATASTORE> [-OtherOptions]  
 }  

Where:

<N> is the number of VMs you need to deploy.
<ESX_HOST> is the host where you will deploy your VMs
<TEMPLATE> is the template from which your VMs will be created
<DATASTORE> is the datastore that will contain your VMs
[-OtherOptions] are additional options that can be used in conjunction with New-VM command.

As you can see it's really basic, but New-VM cmdlet is really powerful and it has a lot of options. To go through all on New-VM options:


Get-Help New-VM -Detailed


Here's how I used it today for deploying 6 VMs that will be Oracle RAC nodes.


Open a text editor and paste this code in it saving file with .ps1 extension.

 1..2 | Foreach {  
 New-VM -vmhost esx1.testdomain.com -Name RAC$_ -Template OL6 -Datastore datastore1  
 }  
 3..4 | Foreach {  
 New-VM -vmhost esx2.testdomain.com -Name RAC$_ -Template OL6 -Datastore datastore2 -ResourcePool TestResourcePool  
 }  
 5..6 | Foreach {  
 New-VM -vmhost esx3.testdomain.com -Name RAC$_ -Template OL6 -Datastore datastore3 | Start-VM  
 }  



As you can see we are deploying 6 VMs, named RAC1 to RAC6 from a template called OL6.
RAC1 and RAC2 will be deployed on host esx1.testdomain.com, RAC3 and RAC4 on host esx2.testdomain.com and RAC5 and RAC6 on host esx3.testdomain.com.
RAC3 and RAC4 will be placed in a resource pool called TestResourcePool.
RAC5 and RAC6 will be powered on after deployment due to Start-VM cmdlet.


To run this simple script just open VMware vSphere PowerCLI, connect to your vCenter (or host) using Connect-VIServer cmdlet as stated in VMware: vSphere PowerCLI 101 post.


A progress bar will appear in your PowerCLI console


That's all!!Happy VMware Automation!!

martedì 30 luglio 2013

VMware: vSphere PowerCLI 101

These days I'm speding some time learning VMware vSphere PowerCLI. I think vSphere PowerCLI is a great tool for automating tasks among vSphere environments. It's so useful to automate repetitive tasks, it allows IT admins to save huge amounts of time performing common tasks using scripts.

To start using VMware vSphere PowerCLI simply go here:

vSphere PowerCLI: Windows PowerShell interface for managing vSphere

You need to download and install VMware vSphere PowerCLI on your Windows machine in order to start scripting.

Here is the official vSphere PowerCLI Documentation

Another really useful PowerCLI document to read is Getting Started with PowerCLI 4.1 – Automating Your vSphere Environment  which contains a lot of useful commands to perform basic tasks.

Last link I would like to share is the VMware PowerCLI 5.1 Poster which presents all PowerCLI cmdlets in a single panel grouping them by function (Network Operations, Logs/Reporting, etc.)

So, let's start with PowerCLI 101 post...

Connecting/Disconnecting to vCenter Server:

To start using PowerCLI you need to connect to a vCenter Server or to an ESXi host

Connect-VIServer -Server <VCENTER_IP_ADDRESS> -User <USERNAME> -Password <PASSWORD>


Example: Connect-VIServer -Server 192.168.116.155 -User root -Password vmware

To disconnect:

Disconnect-VIServer


Available Commands:

To list all available commands:

Get-Command

Example: Get-Command *VM*  -> To list all commands containing word "VM" in their name.

To get more infos on a command

Get-Help <COMMAND_NAME> -Detailed


Selecting Columns:

<cmdlet> | Select-Object <COLUMNS_TO_SHOW>

Example: Get-VM | Select-Object Name, PowerState -> To display only name and power state of every VM


Prevent truncated columns:

If a column contains many data it could happen that output it's truncated. To prevent this:

<cmdlet> | Select-Object <COLUMNS_TO_SHOW> | Ft -autosize


Redirecting Output:

<cmdlet> > <OUTPUT_FILE>

Example: Get-VM > C:\List_of_VMs.txt -> To create a file named "List_of_VMs.txt" which contains the list of all our VMs


Exporting CSVs:

<cmdlet> | Export-Csv <OUTPUT_FILE>

Example: Get-VM | Export-Csv C:\List_of_VMs.csv -> To export to CSV infos about VMs


Combining Cmdlets:

<cmdlet> | <cmdlet>

Example:  Get-VMHost esx1.testdomain.com | Get-VM -> To show all VMs running on esx1.testdomain.com host


Nested Expressions:

<cmdlet> | Select-Object @{N="<COLUMN_NAME>"; E={<EXPRESSION>}}

Example:  Get-VM | Select-Object Name, @{N="Datastore"; E={$_ | Get-Datastore}} -> Display VM name and datastore on which each VM resides

In the next post I will provide some PowerCLI useful scripts.

That's all!!

lunedì 29 luglio 2013

ESXi: The operation is not allowed in the current state

Today I stepped into this issue while trying to vMotion a VM to another host. When validating destination host this error is displayed:

The operation is not allowed in the current state

After a brief search I found KB 1003829 which states:

1)Cancel the Enter maintenance mode
My host was not entering maintenance mode

2)Restart the ESX host's management agents
Done but still got error

3)Wait until any pending tasks for the ESX host are complete
No running tasks reported from vSphere Client. Logged into my host using SSH to see if there are pending tasks using this command:

vim-cmd vimsvc/task_list

# vim-cmd vimsvc/task_list
(ManagedObjectReference) [
   'vim.Task:haTask-5-vim...'
]

There was a task still running due to the command above (if there are no ongoing tasks the brackets "[]" are empty), waited until completion but vMotion host validation still failed with message "The operation is not allowed in the current state".

4.a)Disconnect and then reconnect the ESX host to VirtualCenter
Done but still got error

4.b)Restart the VMware VirtualCenter Server service
Finally here is how I solved my issue!

To restart vCenter Server go to:

https://YOUR_VCENTER_SERVER:5480

Click Stop button and wait until services stopping occurs.





Then cick Start and wait for completion.


After this I was able to correctly vMotion guest VMs!!

giovedì 25 luglio 2013

VMware: This system is not a supported platform

I encountered this error while installing HP branded Windows 2008 OEM on VMware ESXi 5.1.


This error occurs due to the check Windows performs to verify it is being installed on a HP branded machine.

Anyway this can be easily solved as stated in Installation of Microsoft Software Products Sold by HP (as OEM) on Virtual Machines Is Now Supported

Poweroff your VM, right click on it, choose Edit Settings -> Options and click Configuration Parameters


Now click Add Row and insert:

Name -> SMBIOS.reflectHost 

Value -> TRUE

as depicted in image below:


Click OK and poweron VM. This time you will be able to install Windows 2008 OEM correctly.

If you prefer you can manually edit the .vmx file of your virtual machine, using a text editor, adding a new line:

SMBIOS.reflectHost = TRUE

That's all!!

mercoledì 17 luglio 2013

Oracle UCM: DisableNtfs8dot3

If you have ever installed an instance of Oracle WebCenter Content on a Windows server you probably stepped into this error:


The weblayout directory is on a filesystem with 8dot3 semantics. Legacy 16-bit 8dot3 filenames conflict with revision labels and will cause file loss. Disable 8dot3 semantics by running "Installer DisableNtfs8dot3" and then restarting Windows.




This can be solved in two ways:

1)Using Oracle suggested procedure

This is done running Installer.exe with DisableNtfs8dot3 parameter.

To do this open command prompt (Start -> Run -> cmd) and go to:


<DomainHome>\ucm\cs\bin\Installer.exe DisableNtfs8dot3


In my server it was:


E:\Oracle\Middleware\user_projects\domains\ecm_domain\ucm\cs\bin\Installer.exe DisableNtfs8dot3


2)Editing a registry key

Open regedit (Start -> Run -> regedit) and go to:

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/FileSystem

Edit NtfsDisable8dot3NameCreation key and change its value to 1 (default value is 2).


After this restart UCM instance (if you edit registry also a server reboot would be necessary) and alert message will disappear.

That's all!!

martedì 25 giugno 2013

VMware: Merge multiple vmdks into a single vmdk

When importing VMs from Player/Workstation to ESXi sometimes occurr that original vmdk files are separated into multiple vmdks.

This is because vmdks of a fixed small size are sometimes choosen by user creating guest VM in VMware Player/Workstation due to their better transportability respect to a single vmdk of a bigger size.

To merge multiple vmdks into a single vmdk file we need to use Virtual Disk Manager wich comes with VMware Workstation or can be downloaded separately.

If you have VMware Workstation you can find Virtual Disk Manager under:

C:\Program Files\VMware\VMware Workstation

or you can download it as part of vSphere 5.0 Virtual Disk Development Kit.

So, let's merge our vmdks using command promtp and calling for vmware-vdiskmanager.exe.

This is the synthax:

vmware-vdiskmanager.exe -r first.vmdk -t 0 merged.vmdk

where:

-r <sourcediskname>

-t <0|1|2|3>

0 — to create a growable virtual disk contained in a single virtual disk file

1 — to create a growable virtual disk split into 2GB files

2 — to create a preallocated virtual disk contained in a single virtual disk file

3 — to create a preallocated virtual disk split into 2GB files


Here you find more informations about Virtual Disk Manager options while the full manual can be found here.

That's all, happy merging!!

venerdì 14 giugno 2013

VMware: EMC VNX VSA in your lab

Do you have a vLab? Do you need to practice with EMC's Unisphere for managing VNX storage systems? This post is for you!!

In the following article I will explain how to deploy a virtual VNX storage to provide shared NFS storage in your lab. Please note this configuration is just for testing purpouses and not supported for production purpouses.

Let's first have some basics considerations:

VNX Virtual Storage appliance is a virtual machine that runs on a ESXi hypervisor that abstract underlying physical storage, usually local disks, to provide a shared NFS storage platform for all VMs.

Shared storage in a lab is tipically used for testing HA, DRS, Storage DRS, vMotions and Fault Tolerance.

This is a graphical representation of how this VNX VSA will be deployed in your lab:


As you can see physical storage is abstracted by VNX VSA and resulting shared storage is presented as datastore to ESXi hypersor(s) or VMs.

To deploy VNX VSA download it:

Download VNX VSA OVA

Open vSphere Web Client (or vSphere Client if you connect directly to an host or not have deployed vCenter in your lab yet) and deploy your OVA Template.






Power on your VNX VSA and go to console view since we will be prompted to configure networking for a proper startup.

Management IP
Subnet Mask
Default Gateway


Then:

Hostname
Domain name
DNS Server
NTP Server

 


Create a filesystem and export it as an NFS share on which datastores can be created.

Open your browser and go to Management IP address you setup during initial configuration to access Unisphere management.
Sadly I had to use Internet Explorer to access all functionalities of Unisphere. Neither Firefox, neither Chrome worked in my case.

Login to Unisphere:

Username: nasadmin
Password: nasadmin


Create a new network interface through which NFS share will be accessed so go to Settings -> Network -> Interface Wizard


During interface wizard you will be prompted to select an IP address for this new interface and MTU size (9000bytes if you use Jumbo Frame). Please note that both MTU size and network segment will be accordingly set up in our vSwitches VMKernel ports. But we will go into this later in the article.


Now let's create a filesystem to be shared. Go to Storage -> FileSystem Wizard, and setup filesystem according to your preferences.



And finally create our NFS Export. Go to Storage -> Shared Folders -> NFS -> Create. Choose the filesystem to be shared. the name to which it will be exported and enable hosts to access this share. In my case I inserted the IP of my vLab ESXi host.


Move to our ESXi host(s) networking configuration panel to add a new VMkernel for NFS traffic. As I stated before VMkernel must be in the same network segment of your VNX VSA network interface you previously created.


As you can see in the image above my VMkernel IP is 192.168.116.209 which is in the same 192.168.116.x network segment of VNX VSA network interface 192.168.116.208. When creating VMkernel remember to set MTU according to the previously set one. In my case I set MTU for this VMkernel to 9000bytes.

Final step is to create a new datastore on our NFS export.


This new datastore can be assigned to more than one ESXi hosts.

Here's a slide deck from Simon Seagrave containing some technical informations about EMC VNX and VNX VSA.

That's all!!