Skip to content

Instantly share code, notes, and snippets.

@michaelrice
Created April 29, 2015 14:30
Show Gist options
  • Select an option

  • Save michaelrice/1ed5f2d8c352cf14c996 to your computer and use it in GitHub Desktop.

Select an option

Save michaelrice/1ed5f2d8c352cf14c996 to your computer and use it in GitHub Desktop.
remove host from vcenter
boolean removeHostFromVCenter() {
try {
// This only works on a HostSystem that is a member of a cluster.
return hostSystem.destroy_Task().waitForMe().equals(Task.SUCCESS)
}
catch (NotSupported ns) {
// If the host parent is a ComputeResource destroy it.
// That means its a stand alone hostsystem.
if (hostSystem.parent.class.equals(ComputeResource.class)) {
log.debug("Stand alone HostSystem found. Destroying ComputeResource to remove from vCenter.")
return hostSystem.parent.destroy_Task().waitForMe().equals(Task.SUCCESS)
}
log.error("Unable to remove HostSystem from Vcenter", ns)
return false
}
catch (Exception e) {
log.error("An unexpected error occurred.", e)
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment