How to Start and Stop Virtual Machines
Applies To: System Center 2016 - Service Provider Foundation, System Center Technical Preview
When you have reference to a virtual machine, you can control the state of it by changing the Operation
property and by submitting the changed entity to the server. The virtual machine then responds to the operation that you submitted. This process 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 forces it to shut down, set the Operation
property to Stop
.
To start or stop a virtual machine by using .NET
Connect to the Service Provider Foundation
VMM
service.Query for a specific
SpfVMM.VirtualMachine
.Set the
Operation
property of the virtual machine to eitherStart
orStop
.Call the
UpdateObject
method on theVMM
service object reference and pass in the virtual machine reference.Call the
SaveChanges
method on theVMM
service object reference.
To start or stop a virtual machine by using HTTP
Create a new
HTTP
PUT or MERGE operation.Set the URL to the appropriate URI of a specific virtual machine: https://server:30006/subscription-id/services/systemcenter/vmm/VirtualMachines(ID=guid'vm-id',StampId=guid'stamp-id')
Add the HTTP headers.
Specifically, add the
x-ms-principal-id
header, which can be set to any value.Create the HTTP payload that contains the virtual machine entity, by using key properties and the
Operation
property set toStart
orStop
.Important
If you supply only the key and changed properties, use a
MERGE
operation. ThePUT
operation is used when you want to replace all properties on the entity with new or default values. TheMERGE
operation updates the existing entity with the supplied properties. ThePUT
operation updates the existing entity with the supplied properties, but resets all missing properties back to their default values.Submit the HTTP request.
Example
The following code example shows how to stop an existing virtual machine by using .NET. For more information, seeProgramming in Visual Studio with Service Provider Foundation Services.
SpfVMM.VMM vmmService = new SpfVMM.VMM(new Uri("https://wapserver:30006/97FD50F3-1DC0-41B6-A7C0-2B4FF4C3F7E3/services/systemcenter/vmm/"));
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();
}
Example
The following code example shows an HTTP request that is sent to the server.
MERGE https://wapserver:30006/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:30006
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+cLhGnMtR6HT5bmSO56ezxxUzYYQ9pBBZ2pqpyEr6LtJ8CWNIYLFRuRkffrXL9a+ioSayAJMC/gmuPxN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NF6DhG7jgJZJhkBZDmnO2G375lfo+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"
}
Example
The following code example shows the 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
See Also
Virtual Machine Management
How to Get a List of Virtual Machines
How to Create a Virtual Machine from a Template
How to Create a Virtual Machine from a VHD
How to Delete a Virtual Machine