Delete a Virtual Machine (SPF) - TechNet Articles - United States (English) - TechNet Wiki

This page is now retired and kept for archival purposes. This programming guide has been published on MSDN at http://msdn.microsoft.com/library/jj643273.aspx

This article is part of the Service Provider Foundation Programmers Guide (SPF).

Table of Contents

You can delete a virtual machine from Service Provider Foundation by passing the instance of the virtual machine to the DeleteObject method of the service. When using HTTP, use the DELETE operation with the specific virtual machine identified in the URI.

 Tip
Before a virtual machine can be deleted, it must be in a stopped state. To learn how to stop a virtual machine, see Start or Stop a Virtual Machine (SPF).

To delete a virtual machine with .NET

  1. Connect to the Service Provider Foundation VMM service.

  2. Query for a specific SpfVMM.VirtualMachine.

  3. Call the DeleteObject method on the VMM service object reference and pass in the virtual machine reference.

  4. Call the SaveChanges method on the VMM service object reference.

To delete a virtual machine with HTTP

  1. Create a new HTTP DELETE operation.

  2. Set the URL to the appropriate URI of a specific virtual machine: https://server:30005/subscription-id/services/systemcenter/vmm/VirtualMachines(ID=guid'vm-id',StampId=guid'stamp-id')

  3. Add the HTTP headers.

    Specifically, add the x-ms-principal-id header, which can be set to any value.

  4. Create an empty HTTP body.

  5. Submit the HTTP request.

Example

The following example deletes a specific virtual machine.

SpfVMM.VMM vmmService = new SpfVMM.VMM(new Uri("https://wapserver:30005/97FD50F3-1DC0-41B6-A7C0-2B4FF4C3F7E3/services/systemcenter/vmm/"));
vmmService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

var virtualMachine = vmmService.VirtualMachines.Where(vm => vm.ID == new Guid("2fa28d03-8d6d-486b-ae61-9694a2db5d6f")).FirstOrDefault();

if (virtualMachine != null)
{
    vmmService.DeleteObject(virtualMachine);
    vmmService.SaveChanges();
}

The following is an example HTTP request sent to the server:

DELETE https://wapserver:30005/97FD50F3-1DC0-41B6-A7C0-2B4FF4C3F7E3/services/systemcenter/vmm/VirtualMachines(ID=guid'2fa28d03-8d6d-486b-ae61-9694a2db5d6f',StampId=guid'ba4146fa-fb41-4f59-a193-ad00c52a138c') HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
x-ms-principal-id: user@contoso.com
Content-Type: application/json;odata=minimalmetadata
Host: wapserver:30005
Content-Length: 0
Expect: 100-continue
Authorization: Negotiate YIIGXgYGKwYBBQUCoIIGUjCCBk6gMDAuBgkqhkiC9xIBAgIGCSqGSIb3EgECAgYKKwYBBAGCNwICHgYKKwYBBAGCNwICCqKCBhgEggYUYIIGEAYJKoZIhvcSAQICAQBuggX/MIIF+6ADAgEFoQMCAQ6iBwMFACAAAACjggSPYYIEizCCBIegAwIBBaEJGwdDRE0uTEFCoiMwIaADAgECoRowGBsESFRUUBsQc3Bmbi00NTcuY2RtLmxhYqOCBE4wggRKoAMCARKhAwIBC6KCBDwEggQ4YxKWDhXtvdW7cOad2YYLdIl1i006LdvK5X1L+Dq5D+rKCF9MuKeeO634eKeCvEg8ogIQuKlZWwCNikXuxKMAp6Js3tjKqV8cOIFYcbn3NjFc2h0iM2hRPlZgx+WleniD83tu57OufXVmrG242TXohgXOB+HldgJszR6eKE4qebx9pfzkgO2TMZOU8e+/2+q+rOK0E9lPk1bAGVI8IhsbeUjiWzg15P2TmhePpAG7Tqn+DRmU134ywJe5WVxmwMzPA9x0RqGKAaeutXKIeSHkSOXVf1Kzfursl03YH+1YMhAu5tj/DLTAu4BKKjYa4/sVo3+lXomaqOOPrwijLGT2XfxsXWe2Tcq/T/yUChrzOOv9hQSRXctB/3FF+S7+yqxNrkcBINIAElQXu+cLhGnMtR6HT5bmSO56ezxxUzYYQ9pBBZ2pqpyEr6LtJ8CWNIYLFRuRkffrXL9a+ioSayAJMC/gmuPxN1JjwT1TcSAQUhUYuZrxahrnZHQjkV0+b+Wpjwfx0cQG7S2i/ACf05G+TJU/QOHCwqP0R8dkwZjQNJ0VmpnlDw2DQNnI7cBH3dFcLh8XI13uo16aZiHOU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Zd1f+PaeruPwlVBK5ZMqIkwjlPMx45H0cFBov3g+/eZzAppwEDycz4DOK8iXgbyZMprBQU7Sq0dF4tDke6zaaWFD9fKRxngIzbLodr22WtiZebUkULuvJOhI7FRlSIA1mH5yZFmqINa/XIHZguBtMhWJFSeg8vwrQRlJGwaA8swtOGO33z5/HMnM8xOasqH5tmCCatTUy3bj1vkhXJpJqHAzRq16b1XsYIdOWoYW3qzgFusoqDrMv4faKj2vZuUSQ7UDBSwGTOfEbQvQgY+DswJF6HFenryyVomQR6q7c/U23kzRePWemhKHefWDnBfSeQ1wV1hcP1DwS/GR+SbvDOiweD0hM4sL0mT5/U6BAd6EFgroWLZAJDQq6AHQbb7mmRTJRRUjwUcVtm2xAo15Pvj6csOW7wdFzP5Z0htdCxUCQvGdrjj98Q+EE/owKgtIKeETBiePkB3haoWvaomj7e/s+R9MJe5ik0+zjuFpYWQr91joxCwPwv2YPC8GOQcmqqKhigVqyq0=

The following is an example HTTP response from the server:

HTTP/1.1 204 No Content
Cache-Control: no-cache
Server: Microsoft-IIS/8.5
x-ms-request-id: 957320a6-6f62-48ef-a854-a721c579c595
X-Content-Type-Options: nosniff
request-id: eda9bde6-834a-0001-46f1-aaed4a83ce01
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
Persistent-Auth: true
X-Powered-By: ASP.NET
WWW-Authenticate: Negotiate oYG2MIGzoAMKAQChCwYJKoZIgvcSAQICooGeBIGbYIGYBgkqhkiG9xIBAgICAG+BiDCBhaADAgEFoQMCAQ+ieTB3oAMCARKicARuBxmfiEwlR7iFBMUoozIOaNsMQD/wtFve4X/yoFT27BiUaibkryGn/tS8in4Nc/ohfIvteyhLhB44+zjZ83aqgE3SW2IpDJJ7pFSGFQDpFQk7I5auEyB9enwfORHt8gAX/0/u8mdAjkaP51HyBls=
Date: Wed, 07 Aug 2013 21:53:32 GMT