Create a Virtual Machine Checkpoint (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

Create a Virtual Machine Checkpoint (SPF)

This iv class="hierarchy-list-header">

Virtual Machine Checkpoints provide a way to capture the state of a Virtual Machine. The Checkpoint can then be used to restore the Virtual Machine back to the way it was when the Checkpoint was created.

To create a Checkpoint, you only need reference the GUID of the Virtual Machine. The user that creates the Checkpoint must have the Checkpoint permission in their user role. For more information, see Add a Permission to a User Role (SPF). A Checkpoint is created with the VMCheckPoints OData collection.

To create a checkpoint with .NET

  1. Connect to the Service Provider Foundation VMM service.

  2. Obtain the ID of the SpfVMM.VirtualMachine you want to create a checkpoint for.

  3. Create a new instance of the SpfVMM.VMCheckPoint class.

  4. Set the VMId property to the ID of the Virtual Machine.

  5. Set the StampId property to the stamp that the Checkpoint will reside.

  6. Set the Name and Description properties to something that will help identify and describe why the Checkpoint has been created.

  7. Call the AddToVMCheckPoints method on the VMM service object reference and pass in the Checkpoint reference.

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

To create a checkpoint with HTTP

  1. Create a new HTTP POST operation.

  2. Set the URL to the VMCheckPoints collection: https://server:30005/subscription-id/services/systemcenter/vmm/VMCheckPoints.

  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 checkpoint entity. The entity should have the following properties set:

    1. Set the VMId property to the ID of the Virtual Machine you want to create a checkpoint of.
    2. Set the StampId property to the stamp that the Checkpoint will reside.
    3. Set the Name and Description properties to something that will help identify and describe why the Checkpoint has been created.
  5. Submit the HTTP request.

Example

The following example shows how to create a Virtual Machine Checkpoint using .NET. For more information, see Programming in Visual Studio with Service Provider Foundation Services.

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("3499b02c-8dc9-4c0d-aa83-097a1340cbda")).FirstOrDefault();
 
if (virtualMachine != null)
{
    var checkpoint = new SpfVMM.VMCheckPoint();
    checkpoint.VMId = virtualMachine.ID;
    checkpoint.Name = "Testing Checkpoint #1";
    checkpoint.StampId = virtualMachine.StampId;
    checkpoint.Description = String.Format("This is a snapshot of the VM taken at {0}", DateTime.Now);
 
    vmmService.AddToVMCheckPoints(checkpoint);
    vmmService.SaveChanges();
}

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

POST https://wapserver:30005/97FD50F3-1DC0-41B6-A7C0-2B4FF4C3F7E3/services/systemcenter/vmm/VMCheckPoints HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agpan>checkpoint.Description = String.Format("This is a snapshot of the VM taken at {0}",
 DateTime.Now);
 
    vmmService.AddToVMCheckPoinent: Microsoft ADO.NET Data Services x-ms-principal-id: user@contoso.com Content-Type: application/json;odata=minimalmetadata Host: wapserver:30005 Content-Length: 463 Expect: 100-continue { "odata.type": "VMM.VMCheckPoint", "Accessibility": null, "AddedTime": null, "CheckpointID": null, "Confirm": null, "Description": "This is a snapshot of the VM taken at 8/19/2013 3:02:33 PM", "Enabled": null, "ID": "00000000-0000-0000-0000-000000000000", "ModifiedTime": null, "Name": "Testing Checkpoint #1", "ParentCheckpointID": null, "RunAsynchronously": null, "StampId": "ba4146fa-fb41-4f59-a193-ad00c52a138c", "VMCheckPointAction": null, "VMId": "3499b02c-8dc9-4c0d-aa83-097a1340cbda" }

The following is an example HTTP response from the server:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 651
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Location: https://wapserver:30005/97FD50F3-1DC0-41B6-A7C0-2B4FF4C3F7E3/services/systemcenter/vmm/VMCheckPoints(ID=guid'a11cc636-5521-4f88-92b2-cad392911fe0',StampId=guid'ba4146fa-fb41-4f59-a193-ad00c52a138c')
Server: Microsoft-IIS/8.5
x-ms-request-id: e381ad2b-2375-45e4-a45f-64a1447a4ef6
X-Content-Type-Options: nosniff
request-id: eda9bde6-834a-0001-3608-abed4a83ce01
DataServiceVersion: 3.0;
X-AspNet-Version: 4.0.30319
Persistent-Auth: true
X-Powered-By: ASP.NET
Date: Mon, 19 Aug 2013 22:02:36 GMT

{
    "odata.metadata": "https://wapserver:30005/97FD50F3-1DC0-41B6-A7C0-2B4FF4C3F7E3/services/systemcenter/vmm/$metadata#VMCheckPoints/@Element",
    "Accessibility": "Public",
    "AddedTime": "2013-08-19T15:02:36.591591-07:00",
    "CheckpointID": null,
    "Confirm": null,
    "Description": "This is a snapshot of the VM taken at 8/19/2013 3:02:33 PM",
    "Enabled": true,
    "ID": "a11cc636-5521-4f88-92b2-cad392911fe0",
    "ModifiedTime": "2013-08-19T15:02:36.8185926-07:00",
    "Name": "Testing Checkpoint #1",
    "ParentCheckpointID": null,
    "RunAsynchronously": null,
    "StampId": "ba4146fa-fb41-4f59-a193-ad00c52a138c",
    "VMCheckPointAction": null,
    "VMId": "3499b02c-8dc9-4c0d-aa83-097a1340cbda"
}