VMware Cloud Community
Sirry
Enthusiast
Enthusiast
Jump to solution

Automating vCloud: "Disable Host" and "Redeploy All VMs"

Are these two functions available through any API/SDK? I cannot seem to find it for PowerCLI or the REST interfaces. Perhaps I am reading outdated/incorrect documentation? Any help would be great! Thanks.

Reply
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

Here's a sample script that shows how to enable/disable a host through PowerCLI.

# Connect to the vCloud director and store the connection (you can also acquire it from $global:DefaultCIServers).

# You'll need to connect as an administrator

$server = Connect-CIServer ...

# Acquire the extension API object (it holds the references to the hosts)

$extension = $server.ExtensionData.GetAdmin().GetExtension()

# Get the host references

$hosts = $extension.GetHostReferences()

# Get the reference to the host you need

$hostRef = $hosts.HostReference | where { $_.Name -eq "192.168.0.1"}

# Since this is just a reference to the host, you'll need to acquire the host object itself (also known as host "view")

# Normally this is done by using Get-CIView and passing the Id/href to the -Id parameter of the cmdlet like this: Get-CIView -Id $hostRef.Href

# But since this is a Reference object, we've created an easier way to get the corresponding view:

$myHost = $hostRef.GetCIView()

# Now you can enable or disable the host

$myHost.Enable()

$myHost.Disable()

However I'm not sure about the "Redeploy All VMs". I think this can be accomplished through the vCenter Server, by issuing EnterMaintenanceMode on the host (can be done through PowerCLI), but I'm not sure whether you can do it from the vCloud Director API.

View solution in original post

Reply
0 Kudos
3 Replies
Sirry
Enthusiast
Enthusiast
Jump to solution

Update:

Disable and Enabling hosts using the API can be done. Referenced on page 195 of the vCloud API programming Guide.

Still no idea how to do this with PowerCLI, and don't know how to "Redeploy All VMs" using either/any method.

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

Here's a sample script that shows how to enable/disable a host through PowerCLI.

# Connect to the vCloud director and store the connection (you can also acquire it from $global:DefaultCIServers).

# You'll need to connect as an administrator

$server = Connect-CIServer ...

# Acquire the extension API object (it holds the references to the hosts)

$extension = $server.ExtensionData.GetAdmin().GetExtension()

# Get the host references

$hosts = $extension.GetHostReferences()

# Get the reference to the host you need

$hostRef = $hosts.HostReference | where { $_.Name -eq "192.168.0.1"}

# Since this is just a reference to the host, you'll need to acquire the host object itself (also known as host "view")

# Normally this is done by using Get-CIView and passing the Id/href to the -Id parameter of the cmdlet like this: Get-CIView -Id $hostRef.Href

# But since this is a Reference object, we've created an easier way to get the corresponding view:

$myHost = $hostRef.GetCIView()

# Now you can enable or disable the host

$myHost.Enable()

$myHost.Disable()

However I'm not sure about the "Redeploy All VMs". I think this can be accomplished through the vCenter Server, by issuing EnterMaintenanceMode on the host (can be done through PowerCLI), but I'm not sure whether you can do it from the vCloud Director API.

Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Yeah I couldnt see it in the API either, looking at VC when we "Redeploy All VMs" it looks like it uses maintenance mode to do this, so an enter maintenance mode and then leave maintenance mode should do it, here is a function i wrote i while back for vCD 1.5.1 which should do the same, of course the only issue is you need to connect to the VC as well.

I also went on in this function to unprepare the host but have removed that bit as you didnt say you wanted to do that.

Connect-VIServer labvc -User root -Password password

Connect-CIServer labvcd -User Administrator -Password "password"

Function Remove-CIHost {

      Param (

            $CIHost

      )

      Process {

            # Locate the vCloud Director Host

            $search = Search-cloud -QueryType Host -Name $CIHost

            $HostView = Get-CIView -SearchResult $search

            # Disable in vCloud Director

            if ($HostView.Enabled) {

                $DisabledHost = $HostView.Disable()

            }

            # Set VMHost into Maint Mode

            $MaintenanceHost = Set-VMHost -State Maintenance -VMHost $CIHost | Out-Null

            $HostView = Get-CIView -SearchResult $search

            $HostView

      }

}

Remove-CIHost -CIHost 10.20.181.170

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com