Share via


Start or Stop a Virtual Machine (SPF)

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)]].

When you have reference to a virtual machine, you can control the state of it by changing the Operation property and submitting the changed entity to the server. The virtual machine will then respond to the operation you gave it. This can be used to start and stop the virtual machine among other operations.

To start a stopped virtual machine, set the Operation property to Start.

To stop a running virtual machine, which will forcibly shut it down, set the Operation property to Stop.

To start or stop a virtual machine with .NET

  1. Connect to the Service Provider Foundation VMM service.

  2. Query for a specific SpfVMM.VirtualMachine.

  3. Set the Operation property of the virtual machine to either Start or Stop.

  4. Call the UpdateObject method on the VMM service object reference, and pass in the virtual machine reference.

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

To start or stop a virtual machine with HTTP

  1. Create a new HTTP PUT or MERGE 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 the HTTP payload containing the virtual machine entity, with key properties, and the Operation property set to Start or Stop.

    Note

If you supply only the key and changed properties, use a MERGE operation. PUT is used when you want to replace all properties on the entity with new or default values. The MERGE operation updates the existing entity with the properties supplied. PUT will update the existing entity with the properties supplied, but will reset all missing properties back to their default values.

  1. Submit the HTTP request.

Example

The following example shows how to stop an existing virtual machine using .NET.

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)
{
    virtualMachine.Operation = "Stop";

    vmmService.UpdateObject(virtualMachine);
    vmmService.SaveChanges();
}

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

MERGE 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: 179
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+cLhGnMtR6HT5bmSO56ezx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pB6sNVEFeGFiFeV3DsMj08B5wSeublAMFyGxdGTZWnM3sToxs+S9C1o+4Lw+VlNF6DhG7jgJZJhkBZDmnO2G375lfo+vzXFyMQD0Ujbx9r2P93YxD5A2Z5ka4BlTOBs1dG94XOHrhG89TQa92h/QHffwgbQpL2846ghwqFb9qc3nabzAy6QzcX/VZd1f+PaeruPwlVBK5ZMqIkwjlPMx45H0cFBS/GR+SbvDOiweD0hM4sL0mT5/U6BAd6EFgroWLZAJDQq6AHQbb7mmRTJRRUjwUcVtm2xAo15Pvj6csOW7wdFzP5Z0htdCxUCQvGdrjj98Q+EE/owKgtIKeETBiePkB3haoWvaomj7e/s+R9MJe5ik0+zjuFpYWQr91joxCwPwv2YPC8GOQcmqqKhigVqyq0=

{
    "odata.type": "VMM.VirtualMachine",
    "ModifiedTime": "2013-08-06T23:17:18.4061005-07:00",
    "Operation": "Stop"
}

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