Change The Storage Profile of vCloud Director Organisations vApps VMs with PowerCLI

Just only one level of storage profile change available in vCloud Director, its VM level and via GUI you have to change step by step every VM.

No way to change it vApp level , Organisation level or Provider level

From Matt Vogt blog find a script but can’t success and debug it, end of the day find that script do not turn href value. I do not have enough knowledge about PowerShell and other thing but start to learn about it.

href is link , show the path of thing you want to play. The link below indicate one of the storage profile GUID
Href            : https://v.dorukcloud.com/api/admin/extension/pvdcStorageProfile/1e38cfc5-079b-45ab-a185-c4e0ec1b45c8

This is the script what we run on our environment (Version 1)

Before execute the script you have to connect vCloud Director like below

Connect-CIServer -Server v.dorukcloud.com -User ‘your_user_name’ -Password ‘your_password’

Then continue the script

# Get vApp, Storage Profile from client
# Script will wait your input to get it

$vappName = read-host “vApp name”
$profileName = read-host “Storage Profile”

# Change each VM’s Storage Profile in the vApp
# Take the output of Get-CIVApp command and set the CIvApp variable

$CIvApp = Get-CIVApp $vappName

#Because of multiple VM can be inside vApp, we are going into loop
Foreach ($CIVM in ($CIvApp | Get-CIVM))

{
#Extensiondata help to dive vCenter SDK
$newSettings = $CIVM.extensiondata
$newSettings.storageprofile.name = “$profileName”

#Just only changing the profile name is not enough , you have to update the storage profile link below before Update the server data. Here i set it manually but you get it automatically.
#Here you should not forget that related storage profile need to be set under organisation vDC if not then you can not set it.
$newSettings.storageprofile.Href=”https://xxx.your_url.com/api/admin/vdcStorageProfile/78382381-a56f-4cea-b3eb-ee28abe07f87″

Write-Host “Changing the storage profile for $CIVM to $profileName”
#And start the extion , you will see that there is a migration task will be kicked on venter which make a storage change.
$newSettings.UpdateServerData()
}

a

This is the script what we run on our environment (Version 2)

# Script V2
# This script find out required Storage Profile from vDC Storage Profile list
# Related SP name requested from client # If related SP not available warn you, how? If there is no href catched then looks like there is no match what you enter as a SP name

$HREF = $NULL

# Get vApp, Storage Profile and OrgvDC names

$vDCName = read-host “vDC name”
$vappName = read-host “vApp name”
$profileName = read-host “Storage Profile”

# Change each VM’s Storage Profile in the vApp

$VDCSP = Get-OrgVdc -Name $vDCName
$VDCSP = $VDCSP.ExtensionData.VdcStorageProfiles
$VDCSP = $VDCSP.VdcStorageProfile

# This loop turn you the HREF of SP which name is “XivTunafishPerformance”
# You can use variable here of you want. In this script manually described.

for ($i=0;$i -le $VDCSP.Length -1;$i++)
{
write-host ” existing storage profile ” $vdcsp[$i].Name -foregroundcolor red -backgroundcolor yellow

if ($vdcsp[$i].Name -eq “XivTunafishPerformance”)
{
write-host “XivTunafishPerformance u buldum ”
$HREF = $vdcsp[$i].Href
break
}
}

if ($HREF -eq $NULL)
{
Write-host “Looks like there is no storage profile set on org vdc”
break
}
ELSE
{
$CIvApp = Get-CIVApp $vappName

Foreach ($CIVM in ($CIvApp | Get-CIVM))
{
$newSettings = $CIVM.extensiondata
$newSettings.storageprofile.name = “$profileName”
$newSettings.storageprofile.Href = “$HREF”
Write-Host “Changing the storage profile for $CIVM to $profileName”
$newSettings.UpdateServerData()
}
}

Thanks Matt
VM

Posted on 10/11/2013, in vDirector 5.1 and tagged , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: