macquivr
Contributor
Contributor

Destroying a Host

Jump to solution

When I use VIJava HostSystem.Destroy_Task() to destroy a Host on a VCenter I have I get "Operation is not supported by this object."

But if I use the VSphere GUI client, I right click on the Host, choose 'Remove' from the menu, and it Destroys it.

Both tasks in the Task Activity tab say 'Destroy Host' with the same host name, just one says 'Operation not supported' and the other says 'Completed'

Using VIJava is there a special way I need to remove the host from the VCenter other than find the HostSystem entity and call its Destory_Task() method?

- JT

0 Kudos
1 Solution

Accepted Solutions
lamw
Community Manager
Community Manager

I recall you need to use DisconnectHost_Task first and then you can use Destroy_Task. This is the same set of operations you would need if you did this via the vSphere Client, if your ESX(i) host is still connected and not disconnected, you will get an error if you try to click on "remove", you will need to disconnect first and then remove operation will be successful, so you'll need to do the same using the APIs.

=========================================================================

William Lam

VMware vExpert 2009,2010

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

View solution in original post

0 Kudos
6 Replies
lamw
Community Manager
Community Manager

I recall you need to use DisconnectHost_Task first and then you can use Destroy_Task. This is the same set of operations you would need if you did this via the vSphere Client, if your ESX(i) host is still connected and not disconnected, you will get an error if you try to click on "remove", you will need to disconnect first and then remove operation will be successful, so you'll need to do the same using the APIs.

=========================================================================

William Lam

VMware vExpert 2009,2010

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
macquivr
Contributor
Contributor

Thanks for the advice.

- JT

0 Kudos
macquivr
Contributor
Contributor

But unfortunately, I tried it (after just assuming it would work), and I get the same result, perhaps I should say this is with VCenter 2.5 (not 4.0 or 4.1)

I disconnected the host and the Destroy_Task on the HostSystem says 'Operation not supported by object.'

Is there a RemoveHost_Task() on a object (like a Datacenter or ClusterComputeResource)? though if there was It would probably say that under 'Task activity' when performed using the VSphere client GUI.

- JT

0 Kudos
macquivr
Contributor
Contributor

I'm reading the ManagedObject API doc and I think I have to destroy the ComputeResource object associated with the HostSystem.

Maybe.

- JT

0 Kudos
lamw
Community Manager
Community Manager

The operations apply to both VI 2.5 and vSphere 4.x APIs.

Try this, put the host into maintenance mode first and then perform the Destroy_Task, this is how one of the vCLI's host operations performs removal of a host from vCenter.

=========================================================================

William Lam

VMware vExpert 2009,2010

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
rmrobert
VMware Employee
VMware Employee

This is correct.  You must issue Destroy_Task on the parent ComputeResource.  You can do host.parent.Destroy_Task().wait_for_completion (or whatever- that's how it looks in RbVmomi)

0 Kudos