Share via


Update (PUT) a VirtualMachine [SPFSDK][VMMREF]

 

Applies To: Windows Azure Pack

Updates a VirtualMachine [SPFSDK][VMMREF] entity by using the HTTP PUT operation.

Here is a list of examples related to this collection operation.

  • Example: Start a virtual machine

  • Example: Stop a virtual machine

  • Example: Repair a virtual machine

  • Example: Change owner of a virtual machine

The RunAsynchronously query parameter may be added to the URL, set to a value of 1. This will tell the service to return immediately after the request is sent instead of waiting for the update to finish, which could cause the request to timeout. For example:

https://contoso.com:30005/ae122d5f-3aab-4d75-ad48-d6593246a49e/services/systemcenter/vmm/VirtualMachines(ID=guid'38c9c3b9-9288-4d7a-82fa-501cd4eb9ecb',StampId=guid'd70c1a9b-c241-48f5-880a-b6c36071e653')?RunAsynchronously=1

Request

For more information about the placeholders used in the URI, see URL placeholders.

Method

Request URI

HTTP Version

PUT

https://{server-name}:{auth-port}/{subscription-id}/services/systemcenter/vmm/VirtualMachines(ID=Guid'[value]',StampId=Guid'[value]')

HTTP/1.1

Request URI Parameters

URI Parameter

Description

ID

Required. [Edm.Guid] The identifier of the entity.

StampId

Required. [Edm.Guid] The identifier of the stamp that restricts the query.

Request Headers

This operation does not use any non-standard request headers.

For more information about the common request headers used by this operation, see Common HTTP request information

Request Body

The request body should contain a single (depending on the request headers) XML or JSON encoded VirtualMachine [SPFSDK][VMMREF] entity that is to be updated. Here is the request body of a single entity.

{
  "odata.type": "VMM.VirtualMachine",
  "AddedTime": null,
  "Agent": null,
  "AllocatedGPU": null,
  "BackupEnabled": null,
  "BlockDynamicOptimization": null,
  "BlockLiveMigrationIfHostBusy": null,
  "CanVMConnect": null,
  "CapabilityProfile": null,
  "CheckpointLocation": null,
  "CloudId": "10f8e459-e7c3-4c40-b47c-b8f758ef4dc1",
  "CloudVMRoleName": null,
  "ComputerName": null,
  "ComputerTierId": null,
  "CostCenter": null,
  "CPUCount": null,
  "CPULimitForMigration": null,
  "CPULimitFunctionality": null,
  "CPUMax": null,
  "CPURelativeWeight": null,
  "CPUReserve": null,
  "CPUType": null,
  "CPUUtilization": null,
  "CreationSource": null,
  "CreationTime": null,
  "DataExchangeEnabled": null,
  "DelayStart": null,
  "DelayStartSeconds": null,
  "DeploymentErrorInfo": {
    "odata.type": "VMM.ErrorInfo",
    "CloudProblem": null,
    "Code": null,
    "DetailedCode": null,
    "DetailedErrorCode": null,
    "DetailedSource": null,
    "DisplayableErrorCode": null,
    "ErrorCodeString": null,
    "ErrorType": null,
    "ExceptionDetails": null,
    "IsConditionallyTerminating": null,
    "IsDeploymentBlocker": null,
    "IsMomAlert": null,
    "IsSuccess": null,
    "IsTerminating": null,
    "MessageParameters": null,
    "MomAlertSeverity": null,
    "Problem": null,
    "RecommendedAction": null,
    "RecommendedActionCLI": null,
    "ShowDetailedError": null
  },
  "DeployPath": null,
  "Description": null,
  "DiskIO": null,
  "Dismiss": null,
  "Domain": null,
  "DynamicMemoryBufferPercentage": null,
  "DynamicMemoryDemandMB": null,
  "DynamicMemoryEnabled": null,
  "DynamicMemoryMaximumMB": null,
  "Enabled": null,
  "ExcludeFromPRO": null,
  "ExpectedCPUUtilization": null,
  "FailedJobID": null,
  "FullName": null,
  "Generation": null,
  "GrantedToList@odata.type": "Collection(VMM.UserAndRole)",
  "GrantedToList": [],
  "HardwareProfileId": null,
  "HasPassthroughDisk": null,
  "HasSavedState": null,
  "HasVMAdditions": null,
  "HeartbeatEnabled": null,
  "HighlyAvailable": null,
  "ID": "00000000-0000-0000-0000-000000000000",
  "IsFaultTolerant": null,
  "IsHighlyAvailable": null,
  "IsRecoveryVM": null,
  "IsUndergoingLiveMigration": null,
  "LastRestoredCheckpointId": null,
  "LibraryGroup": null,
  "LimitCPUForMigration": null,
  "LimitCPUFunctionality": null,
  "LinuxAdministratorSSHKey": null,
  "LinuxAdministratorSSHKeyString": null,
  "LinuxDomainName": null,
  "LocalAdminPassword": null,
  "LocalAdminRunAsAccountName": null,
  "LocalAdminUserName": null,
  "Location": null,
  "MarkedAsTemplate": null,
  "Memory": null,
  "MemoryAssignedMB": null,
  "MemoryAvailablePercentage": null,
  "MemoryWeight": null,
  "ModifiedTime": null,
  "MostRecentTaskId": null,
  "Name": "Tenent Test Virtual Machine 1",
  "NetworkUtilization": null,
  "NewVirtualNetworkAdapterInput@odata.type": "Collection(VMM.NewVMVirtualNetworkAdapterInput)",
  "NewVirtualNetworkAdapterInput": [],
  "NumLock": null,
  "OperatingSystem": null,
  "OperatingSystemInstance": {
    "odata.type": "VMM.OperatingSystem",
    "Architecture": null,
    "Description": null,
    "Edition": null,
    "Name": null,
    "OSType": null,
    "ProductType": null,
    "Version": null
  },
  "OperatingSystemShutdownEnabled": null,
  "Operation": null,
  "OrganizationName": null,
  "Owner": {
    "odata.type": "VMM.UserAndRole",
    "RoleID": null,
    "RoleName": null,
    "UserName": null
  },
  "Password": null,
  "Path": null,
  "PerfCPUUtilization": null,
  "PerfDiskBytesRead": null,
  "PerfDiskBytesWrite": null,
  "PerfNetworkBytesRead": null,
  "PerfNetworkBytesWrite": null,
  "ProductKey": null,
  "Retry": null,
  "RunAsAccountUserName": null,
  "RunGuestAccount": null,
  "ServiceDeploymentErrorMessage": null,
  "ServiceId": null,
  "SharePath": null,
  "SourceObjectType": null,
  "StampId": "d70c1a9b-c241-48f5-880a-b6c36071e653",
  "StartAction": null,
  "StartVM": null,
  "Status": null,
  "StatusString": null,
  "StopAction": null,
  "Tag": null,
  "TimeSynchronizationEnabled": null,
  "TimeZone": null,
  "TotalSize": null,
  "Undo": null,
  "UndoDisksEnabled": null,
  "UpgradeDomain": null,
  "UseCluster": null,
  "UseLAN": null,
  "UserName": null,
  "VirtualHardDiskId": null,
  "VirtualizationPlatform": null,
  "VirtualMachineState": null,
  "VMBaseConfigurationId": null,
  "VMConfigResource": null,
  "VMCPath": null,
  "VMHostName": null,
  "VMId": null,
  "VMNetworkAssignments@odata.type": "Collection(VMM.VMNetworkAssignment)",
  "VMNetworkAssignments": [],
  "VMResource": null,
  "VMResourceGroup": null,
  "VMTemplateId": "34f5a0a7-316b-443c-9859-788a08c02409",
  "WorkGroup": null
}

Response

Response Codes

This operation does not return any non-standard OData response codes. If successful, it will return code 204 No Content.

Response Headers

This operation does not use any non-standard response headers.

For more information about the common response headers used by this operation, see Common HTTP response information.

Response Body

None

Example: Start a virtual machine

This example starts a stopped virtual machine. If the virtual machine is in a failed state, you will first need to repair it.

For a full list of possible operations to perform on a virtual machine, see the Operation property of the VirtualMachine [SPFSDK][VMMREF] entity reference.

For more information about how to get started with using the code examples provided in this programming guide, see Programming in Visual Studio with Service Provider Foundation Services.

Guid virtualMachineId = new Guid("38c9c3b9-9288-4d7a-82fa-501cd4eb9ecb");
Guid stampId = new Guid("d70c1a9b-c241-48f5-880a-b6c36071e653");

var vm = vmmService.VirtualMachines.Where(v => v.StampId == stampId && v.ID == virtualMachineId).First();

vm.Operation = "Start";

vmmService.UpdateObject(vm);
vmmService.SaveChanges(System.Data.Services.Client.SaveChangesOptions.PatchOnUpdate);

HTTP Request

PATCH https://contoso.com:30005/ae122d5f-3aab-4d75-ad48-d6593246a49e/services/systemcenter/vmm/VirtualMachines(ID=guid'38c9c3b9-9288-4d7a-82fa-501cd4eb9ecb',StampId=guid'd70c1a9b-c241-48f5-880a-b6c36071e653') HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: Bearer {ENCODED AUTHENTICATION TOKEN}
x-ms-principal-id: tenant@fabrikam.com
Host: contoso.com:30005
Content-Length: 4387
Expect: 100-continue

{"odata.type":"VMM.VirtualMachine","AddedTime":"2014-09-03T14:39:37.637-07:00","Agent":null,"AllocatedGPU":null,"BackupEnabled":true,"BlockDynamicOptimization":null,"BlockLiveMigrationIfHostBusy":null,"CanVMConnect":true,"CapabilityProfile":null,"CheckpointLocation":null,"CloudId":"10f8e459-e7c3-4c40-b47c-b8f758ef4dc1","CloudVMRoleName":null,"ComputerName":"SV8GAQ8Z2E48UEB","ComputerTierId":null,"CostCenter":null,"CPUCount":1,"CPULimitForMigration":null,"CPULimitFunctionality":null,"CPUMax":100,"CPURelativeWeight":null,"CPUReserve":0,"CPUType":"3.60 GHz Xeon (2 MB L2 cache)","CPUUtilization":0,"CreationSource":"Temporary Templatea34cad51-1d34-4f47-96fa-18915a1b2fe1","CreationTime":"2014-09-03T14:39:37.637-07:00","DataExchangeEnabled":true,"DelayStart":0,"DelayStartSeconds":null,"DeploymentErrorInfo":{"odata.type":"VMM.ErrorInfo","CloudProblem":null,"Code":null,"DetailedCode":null,"DetailedErrorCode":null,"DetailedSource":null,"DisplayableErrorCode":null,"ErrorCodeString":null,"ErrorType":null,"ExceptionDetails":null,"IsConditionallyTerminating":null,"IsDeploymentBlocker":null,"IsMomAlert":null,"IsSuccess":null,"IsTerminating":null,"MessageParameters":null,"MomAlertSeverity":null,"Problem":null,"RecommendedAction":null,"RecommendedActionCLI":null,"ShowDetailedError":null},"DeployPath":null,"Description":"","DiskIO":0,"Dismiss":null,"Domain":null,"DynamicMemoryBufferPercentage":null,"DynamicMemoryDemandMB":0,"DynamicMemoryEnabled":false,"DynamicMemoryMaximumMB":null,"Enabled":true,"ExcludeFromPRO":false,"ExpectedCPUUtilization":20,"FailedJobID":null,"FullName":null,"Generation":1,"GrantedToList@odata.type":"Collection(VMM.UserAndRole)","GrantedToList":[],"HardwareProfileId":null,"HasPassthroughDisk":false,"HasSavedState":false,"HasVMAdditions":false,"HeartbeatEnabled":true,"HighlyAvailable":null,"ID":"38c9c3b9-9288-4d7a-82fa-501cd4eb9ecb","IsFaultTolerant":false,"IsHighlyAvailable":false,"IsRecoveryVM":false,"IsUndergoingLiveMigration":false,"LastRestoredCheckpointId":"143ff497-7de0-48b7-9f9a-b9082360c39f","LibraryGroup":"","LimitCPUForMigration":false,"LimitCPUFunctionality":false,"LinuxAdministratorSSHKey":null,"LinuxAdministratorSSHKeyString":null,"LinuxDomainName":null,"LocalAdminPassword":null,"LocalAdminRunAsAccountName":null,"LocalAdminUserName":null,"Location":"","MarkedAsTemplate":false,"Memory":512,"MemoryAssignedMB":0,"MemoryAvailablePercentage":null,"MemoryWeight":5000,"ModifiedTime":"2014-09-04T11:23:38.833-07:00","MostRecentTaskId":"f7233b8f-1e75-4cbf-8755-d7c61a2a8b08","Name":"Tenent Test Virtual Machine #3","NetworkUtilization":0,"NewVirtualNetworkAdapterInput@odata.type":"Collection(VMM.NewVMVirtualNetworkAdapterInput)","NewVirtualNetworkAdapterInput":[],"NumLock":null,"OperatingSystem":"CentOS Linux 6 (64 bit)","OperatingSystemInstance":{"odata.type":"VMM.OperatingSystem","Architecture":"amd64","Description":"CentOS Linux 6 (64 bit)","Edition":null,"Name":"CentOS Linux 6 (64 bit)","OSType":"Linux","ProductType":null,"Version":null},"OperatingSystemShutdownEnabled":true,"Operation":"Start","OrganizationName":null,"Owner":{"odata.type":"VMM.UserAndRole","RoleID":"ae122d5f-3aab-4d75-ad48-d6593246a49e","RoleName":"tenant@fabrikam.com_ae122d5f-3aab-4d75-ad48-d6593246a49e","UserName":"tenant@fabrikam.com"},"Password":null,"Path":null,"PerfCPUUtilization":0,"PerfDiskBytesRead":"0","PerfDiskBytesWrite":"0","PerfNetworkBytesRead":"0","PerfNetworkBytesWrite":"0","ProductKey":null,"Retry":null,"RunAsAccountUserName":null,"RunGuestAccount":null,"ServiceDeploymentErrorMessage":null,"ServiceId":null,"SharePath":null,"SourceObjectType":"VM Template","StampId":"d70c1a9b-c241-48f5-880a-b6c36071e653","StartAction":"TurnOnVMIfRunningWhenVSStopped","StartVM":null,"Status":"PowerOff","StatusString":"Stopped","StopAction":"SaveVM","Tag":"(none)","TimeSynchronizationEnabled":true,"TimeZone":null,"TotalSize":"1745819648","Undo":null,"UndoDisksEnabled":false,"UpgradeDomain":null,"UseCluster":null,"UseLAN":null,"UserName":null,"VirtualHardDiskId":null,"VirtualizationPlatform":"HyperV","VirtualMachineState":"PowerOff","VMBaseConfigurationId":null,"VMConfigResource":null,"VMCPath":null,"VMHostName":null,"VMId":"3e524555-8902-4a33-b9d5-933a01e2e638","VMNetworkAssignments@odata.type":"Collection(VMM.VMNetworkAssignment)","VMNetworkAssignments":[],"VMResource":null,"VMResourceGroup":null,"VMTemplateId":null,"WorkGroup":null}

HTTP Response

HTTP/1.1 204 No Content
Cache-Control: no-cache
Content-Length: 0
Server: Microsoft-IIS/8.5
x-ms-request-id: 3b69ebf2-c739-4bcd-b70d-ca2472aca3ee
X-Content-Type-Options: nosniff
request-id: d3df681c-b278-0000-61ce-e1d378b2cf01
DataServiceVersion: 1.0;
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Thu, 04 Sep 2014 19:09:23 GMT

Example: Stop a virtual machine

This example stops a virtual machine.

For a full list of possible operations to perform on a virtual machine, see the Operation property of the VirtualMachine [SPFSDK][VMMREF] entity reference.

For more information about how to get started with using the code examples provided in this programming guide, see Programming in Visual Studio with Service Provider Foundation Services.

Guid virtualMachineId = new Guid("38c9c3b9-9288-4d7a-82fa-501cd4eb9ecb");
Guid stampId = new Guid("d70c1a9b-c241-48f5-880a-b6c36071e653");

var vm = vmmService.VirtualMachines.Where(v => v.StampId == stampId && v.ID == virtualMachineId).First();

vm.Operation = "Shutdown";

vmmService.UpdateObject(vm);
vmmService.SaveChanges();

HTTP Request

MERGE https://contoso.com:30005/ae122d5f-3aab-4d75-ad48-d6593246a49e/services/systemcenter/vmm/VirtualMachines(ID=guid'38c9c3b9-9288-4d7a-82fa-501cd4eb9ecb',StampId=guid'd70c1a9b-c241-48f5-880a-b6c36071e653') HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: Bearer {ENCODED AUTHENTICATION TOKEN}
x-ms-principal-id: tenant@fabrikam.com
Host: contoso.com:30005
Content-Length: 4392
Expect: 100-continue

{"odata.type":"VMM.VirtualMachine","AddedTime":"2014-09-03T14:39:37.637-07:00","Agent":null,"AllocatedGPU":null,"BackupEnabled":true,"BlockDynamicOptimization":null,"BlockLiveMigrationIfHostBusy":null,"CanVMConnect":true,"CapabilityProfile":null,"CheckpointLocation":null,"CloudId":"10f8e459-e7c3-4c40-b47c-b8f758ef4dc1","CloudVMRoleName":null,"ComputerName":"SV8GAQ8Z2E48UEB","ComputerTierId":null,"CostCenter":null,"CPUCount":1,"CPULimitForMigration":null,"CPULimitFunctionality":null,"CPUMax":100,"CPURelativeWeight":null,"CPUReserve":0,"CPUType":"3.60 GHz Xeon (2 MB L2 cache)","CPUUtilization":0,"CreationSource":"Temporary Templatea34cad51-1d34-4f47-96fa-18915a1b2fe1","CreationTime":"2014-09-03T14:39:37.637-07:00","DataExchangeEnabled":true,"DelayStart":0,"DelayStartSeconds":null,"DeploymentErrorInfo":{"odata.type":"VMM.ErrorInfo","CloudProblem":null,"Code":null,"DetailedCode":null,"DetailedErrorCode":null,"DetailedSource":null,"DisplayableErrorCode":null,"ErrorCodeString":null,"ErrorType":null,"ExceptionDetails":null,"IsConditionallyTerminating":null,"IsDeploymentBlocker":null,"IsMomAlert":null,"IsSuccess":null,"IsTerminating":null,"MessageParameters":null,"MomAlertSeverity":null,"Problem":null,"RecommendedAction":null,"RecommendedActionCLI":null,"ShowDetailedError":null},"DeployPath":null,"Description":"","DiskIO":0,"Dismiss":null,"Domain":null,"DynamicMemoryBufferPercentage":null,"DynamicMemoryDemandMB":512,"DynamicMemoryEnabled":false,"DynamicMemoryMaximumMB":null,"Enabled":true,"ExcludeFromPRO":false,"ExpectedCPUUtilization":20,"FailedJobID":null,"FullName":null,"Generation":1,"GrantedToList@odata.type":"Collection(VMM.UserAndRole)","GrantedToList":[],"HardwareProfileId":null,"HasPassthroughDisk":false,"HasSavedState":false,"HasVMAdditions":true,"HeartbeatEnabled":true,"HighlyAvailable":null,"ID":"38c9c3b9-9288-4d7a-82fa-501cd4eb9ecb","IsFaultTolerant":false,"IsHighlyAvailable":false,"IsRecoveryVM":false,"IsUndergoingLiveMigration":false,"LastRestoredCheckpointId":"143ff497-7de0-48b7-9f9a-b9082360c39f","LibraryGroup":"","LimitCPUForMigration":false,"LimitCPUFunctionality":false,"LinuxAdministratorSSHKey":null,"LinuxAdministratorSSHKeyString":null,"LinuxDomainName":null,"LocalAdminPassword":null,"LocalAdminRunAsAccountName":null,"LocalAdminUserName":null,"Location":"","MarkedAsTemplate":false,"Memory":512,"MemoryAssignedMB":512,"MemoryAvailablePercentage":0,"MemoryWeight":5000,"ModifiedTime":"2014-09-04T12:10:09.2558297-07:00","MostRecentTaskId":"3b69ebf2-c739-4bcd-b70d-ca2472aca3ee","Name":"Tenent Test Virtual Machine #3","NetworkUtilization":0,"NewVirtualNetworkAdapterInput@odata.type":"Collection(VMM.NewVMVirtualNetworkAdapterInput)","NewVirtualNetworkAdapterInput":[],"NumLock":null,"OperatingSystem":"CentOS Linux 6 (64 bit)","OperatingSystemInstance":{"odata.type":"VMM.OperatingSystem","Architecture":"amd64","Description":"CentOS Linux 6 (64 bit)","Edition":null,"Name":"CentOS Linux 6 (64 bit)","OSType":"Linux","ProductType":null,"Version":null},"OperatingSystemShutdownEnabled":true,"Operation":"Shutdown","OrganizationName":null,"Owner":{"odata.type":"VMM.UserAndRole","RoleID":"ae122d5f-3aab-4d75-ad48-d6593246a49e","RoleName":"tenant@fabrikam.com_ae122d5f-3aab-4d75-ad48-d6593246a49e","UserName":"tenant@fabrikam.com"},"Password":null,"Path":null,"PerfCPUUtilization":0,"PerfDiskBytesRead":"0","PerfDiskBytesWrite":"0","PerfNetworkBytesRead":"0","PerfNetworkBytesWrite":"0","ProductKey":null,"Retry":null,"RunAsAccountUserName":null,"RunGuestAccount":null,"ServiceDeploymentErrorMessage":null,"ServiceId":null,"SharePath":null,"SourceObjectType":"VM Template","StampId":"d70c1a9b-c241-48f5-880a-b6c36071e653","StartAction":"TurnOnVMIfRunningWhenVSStopped","StartVM":null,"Status":"Running","StatusString":"Running","StopAction":"SaveVM","Tag":"(none)","TimeSynchronizationEnabled":true,"TimeZone":null,"TotalSize":"1745819648","Undo":null,"UndoDisksEnabled":false,"UpgradeDomain":null,"UseCluster":null,"UseLAN":null,"UserName":null,"VirtualHardDiskId":null,"VirtualizationPlatform":"HyperV","VirtualMachineState":"Running","VMBaseConfigurationId":null,"VMConfigResource":null,"VMCPath":null,"VMHostName":null,"VMId":"3e524555-8902-4a33-b9d5-933a01e2e638","VMNetworkAssignments@odata.type":"Collection(VMM.VMNetworkAssignment)","VMNetworkAssignments":[],"VMResource":null,"VMResourceGroup":null,"VMTemplateId":null,"WorkGroup":null}

HTTP Response

HTTP/1.1 204 No Content
Cache-Control: no-cache
Content-Length: 0
Server: Microsoft-IIS/8.5
x-ms-request-id: 900551e0-cbf0-4a1c-8517-5c0ebb0751c3
X-Content-Type-Options: nosniff
request-id: d3df681c-b278-0000-91ce-e1d378b2cf01
DataServiceVersion: 1.0;
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Thu, 04 Sep 2014 19:12:11 GMT

Example: Repair a virtual machine

This example dismisses the failed state of a virtual machine. If you want to retry the job that put the virtual machine into a failed state, change the Dismiss property to false.

For a full list of possible operations to perform on a virtual machine, see the Operation property of the VirtualMachine [SPFSDK][VMMREF] entity reference.

For more information about how to get started with using the code examples provided in this programming guide, see Programming in Visual Studio with Service Provider Foundation Services.

Guid virtualMachineId = new Guid("38c9c3b9-9288-4d7a-82fa-501cd4eb9ecb");
Guid stampId = new Guid("d70c1a9b-c241-48f5-880a-b6c36071e653");

var vm = vmmService.VirtualMachines.Where(v => v.StampId == stampId && v.ID == virtualMachineId).First();

vm.Operation = "Repair";
vm.Dismiss = true;

vmmService.UpdateObject(vm);
vmmService.SaveChanges();

Example: Change owner of a virtual machine

This example sets the current owner of the virtual machine. If you are connected to the hoster administrator endpoint, you can change the owner to any tenant. But if you’re connected to the tenant endpoint as a tenant, you can only change ownership to a sub-tenant.

For more information about how to get started with using the code examples provided in this programming guide, see Programming in Visual Studio with Service Provider Foundation Services.

// If this is run as a Tenant, you can only assign the owner of the VM to a sub-tenant
// If this is run as the Hoster Admin, you can assign the owner of the VM to anyone

Guid stampId = new Guid("d70c1a9b-c241-48f5-880a-b6c36071e653");
Guid vmId = new Guid("38c9c3b9-9288-4d7a-82fa-501cd4eb9ecb");

// Get the VM that you want to change owners of
var vm = vmmService.VirtualMachines.Where(v => v.StampId == stampId && v.ID == vmId).First();

// Get the user you want to move the VM to
Guid newUserRoleId = new Guid("ae122d5f-3aab-4d75-ad48-d6593246a49e");
var userRole = vmmService.UserRoles.Where(u => u.ID == newUserRoleId).First();

// Configure the user role object for the VM
var newOwner = new SpfVMM.UserAndRole();
newOwner.RoleID = newUserRoleId;
newOwner.RoleName = userRole.Name;
newOwner.UserName = userRole.Name.Substring(0, userRole.Name.LastIndexOf('_'));

// Assign the user role to the VM
vm.Owner = newOwner;

// Save the changes
vmmService.UpdateObject(vm);
vmmService.SaveChanges();

HTTP Request

MERGE https://contoso.com:30005/ae122d5f-3aab-4d75-ad48-d6593246a49e/services/systemcenter/vmm/VirtualMachines(ID=guid'38c9c3b9-9288-4d7a-82fa-501cd4eb9ecb',StampId=guid'd70c1a9b-c241-48f5-880a-b6c36071e653') HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: Bearer
x-ms-principal-id: tenant@fabrikam.com
Host: contoso.com:30005
Content-Length: 4386
Expect: 100-continue

{"odata.type":"VMM.VirtualMachine","AddedTime":"2014-09-03T14:39:37.637-07:00","Agent":null,"AllocatedGPU":null,"BackupEnabled":true,"BlockDynamicOptimization":null,"BlockLiveMigrationIfHostBusy":null,"CanVMConnect":true,"CapabilityProfile":null,"CheckpointLocation":null,"CloudId":"10f8e459-e7c3-4c40-b47c-b8f758ef4dc1","CloudVMRoleName":null,"ComputerName":"SV8GAQ8Z2E48UEB","ComputerTierId":null,"CostCenter":null,"CPUCount":1,"CPULimitForMigration":null,"CPULimitFunctionality":null,"CPUMax":100,"CPURelativeWeight":null,"CPUReserve":0,"CPUType":"3.60 GHz Xeon (2 MB L2 cache)","CPUUtilization":0,"CreationSource":"Temporary Templatea34cad51-1d34-4f47-96fa-18915a1b2fe1","CreationTime":"2014-09-03T14:39:37.637-07:00","DataExchangeEnabled":true,"DelayStart":0,"DelayStartSeconds":null,"DeploymentErrorInfo":{"odata.type":"VMM.ErrorInfo","CloudProblem":null,"Code":null,"DetailedCode":null,"DetailedErrorCode":null,"DetailedSource":null,"DisplayableErrorCode":null,"ErrorCodeString":null,"ErrorType":null,"ExceptionDetails":null,"IsConditionallyTerminating":null,"IsDeploymentBlocker":null,"IsMomAlert":null,"IsSuccess":null,"IsTerminating":null,"MessageParameters":null,"MomAlertSeverity":null,"Problem":null,"RecommendedAction":null,"RecommendedActionCLI":null,"ShowDetailedError":null},"DeployPath":null,"Description":"","DiskIO":0,"Dismiss":null,"Domain":null,"DynamicMemoryBufferPercentage":null,"DynamicMemoryDemandMB":0,"DynamicMemoryEnabled":false,"DynamicMemoryMaximumMB":null,"Enabled":true,"ExcludeFromPRO":false,"ExpectedCPUUtilization":20,"FailedJobID":null,"FullName":null,"Generation":1,"GrantedToList@odata.type":"Collection(VMM.UserAndRole)","GrantedToList":[],"HardwareProfileId":null,"HasPassthroughDisk":false,"HasSavedState":false,"HasVMAdditions":true,"HeartbeatEnabled":true,"HighlyAvailable":null,"ID":"38c9c3b9-9288-4d7a-82fa-501cd4eb9ecb","IsFaultTolerant":false,"IsHighlyAvailable":false,"IsRecoveryVM":false,"IsUndergoingLiveMigration":false,"LastRestoredCheckpointId":"143ff497-7de0-48b7-9f9a-b9082360c39f","LibraryGroup":"","LimitCPUForMigration":false,"LimitCPUFunctionality":false,"LinuxAdministratorSSHKey":null,"LinuxAdministratorSSHKeyString":null,"LinuxDomainName":null,"LocalAdminPassword":null,"LocalAdminRunAsAccountName":null,"LocalAdminUserName":null,"Location":"","MarkedAsTemplate":false,"Memory":512,"MemoryAssignedMB":0,"MemoryAvailablePercentage":null,"MemoryWeight":5000,"ModifiedTime":"2014-09-04T12:21:10.684712-07:00","MostRecentTaskId":"00f2e2ae-d232-43a3-b738-e6743e89e586","Name":"Tenent Test Virtual Machine #3","NetworkUtilization":0,"NewVirtualNetworkAdapterInput@odata.type":"Collection(VMM.NewVMVirtualNetworkAdapterInput)","NewVirtualNetworkAdapterInput":[],"NumLock":null,"OperatingSystem":"CentOS Linux 6 (64 bit)","OperatingSystemInstance":{"odata.type":"VMM.OperatingSystem","Architecture":"amd64","Description":"CentOS Linux 6 (64 bit)","Edition":null,"Name":"CentOS Linux 6 (64 bit)","OSType":"Linux","ProductType":null,"Version":null},"OperatingSystemShutdownEnabled":true,"Operation":null,"OrganizationName":null,"Owner":{"odata.type":"VMM.UserAndRole","RoleID":"ae122d5f-3aab-4d75-ad48-d6593246a49e","RoleName":"tenant@fabrikam.com_ae122d5f-3aab-4d75-ad48-d6593246a49e","UserName":"tenant@fabrikam.com"},"Password":null,"Path":null,"PerfCPUUtilization":0,"PerfDiskBytesRead":"0","PerfDiskBytesWrite":"0","PerfNetworkBytesRead":"0","PerfNetworkBytesWrite":"0","ProductKey":null,"Retry":null,"RunAsAccountUserName":null,"RunGuestAccount":null,"ServiceDeploymentErrorMessage":null,"ServiceId":null,"SharePath":null,"SourceObjectType":"VM Template","StampId":"d70c1a9b-c241-48f5-880a-b6c36071e653","StartAction":"TurnOnVMIfRunningWhenVSStopped","StartVM":null,"Status":"PowerOff","StatusString":"Stopped","StopAction":"SaveVM","Tag":"(none)","TimeSynchronizationEnabled":true,"TimeZone":null,"TotalSize":"1745819648","Undo":null,"UndoDisksEnabled":false,"UpgradeDomain":null,"UseCluster":null,"UseLAN":null,"UserName":null,"VirtualHardDiskId":null,"VirtualizationPlatform":"HyperV","VirtualMachineState":"PowerOff","VMBaseConfigurationId":null,"VMConfigResource":null,"VMCPath":null,"VMHostName":null,"VMId":"3e524555-8902-4a33-b9d5-933a01e2e638","VMNetworkAssignments@odata.type":"Collection(VMM.VMNetworkAssignment)","VMNetworkAssignments":[],"VMResource":null,"VMResourceGroup":null,"VMTemplateId":null,"WorkGroup":null}

HTTP Response

HTTP/1.1 204 No Content
Cache-Control: no-cache
Content-Length: 0
Server: Microsoft-IIS/8.5
x-ms-request-id: cdd8161e-08de-4040-b131-0d30a4fbf119
X-Content-Type-Options: nosniff
request-id: d3df681c-b278-0000-a9cf-e1d378b2cf01
DataServiceVersion: 1.0;
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Thu, 04 Sep 2014 19:21:57 GMT

See Also

VirtualMachines Collection [SPFSDK][VMMREF]
VirtualMachine [SPFSDK][VMMREF]