How to Create a Virtual Machine from a VHD

 

Applies To: System Center 2016 - Service Provider Foundation, System Center Technical Preview

To create a virtual machine with Service Provider Foundation, you must know to which stamp and to which private cloud the virtual machine is to be assigned. The virtual machine must be created from a virtual hard disk (VHD) or a template. For more information about how to create a virtual machine from a template, see How to Create a Virtual Machine from a Template.

The hard disk that is attached to the virtual machine must be bootable. If it is not bootable, Virtual Machine Manager (VMM) locks the virtual machine, and you must reconfigure the virtual machine by using host management software such as Hyper-V.

To create a virtual machine by using .NET

  1. Connect to the Service Provider FoundationVMM service.

  2. Create a new instance of the SpfVMM.VirtualMachine class.

  3. Set the CloudId property of the virtual machine.

  4. Set the StampId property of the virtual machine.

  5. Set the VirtualHardDiskId property to the Guid of the hard disk.

  6. Set the Name property of the virtual machine.

  7. Provide the provisioning settings to be used by the VHD. Generally, these settings are set by the Organization, ProductKey, LocalAdminUserName, and LocalAdminPassword properties.

  8. Call the AddToVirtualMachines method on the VMM service object reference and pass in the virtual machine reference.

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

To create a virtual machine by using HTTP

  1. Create a new HTTP POST operation.

  2. Set the URL to the appropriate URI: https://server:port/SC2012/VMM/subscription-id/Microsoft.Management.Odata.svc/VirtualMachines.

  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 that contains the virtual machine entity.

  5. Submit the HTTP request.

Example

The following code example shows how to create a 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 hardDisk = vmmService.VirtualHardDisks.Where(vhd => vhd.ID == new Guid("fbb2c54a-4c69-46ca-9d48-146a7a2acc88"));  
var stamp = hardDisk.First().StampId;  
  
var vm = new SpfVMM.VirtualMachine();  
vm.VirtualHardDiskId = new Guid("fbb2c54a-4c69-46ca-9d48-146a7a2acc88");  
vm.CloudId = new Guid("6f15c12a-0ebb-453e-b366-87f6c4c8d80f");  
vm.StampId = stamp;  
  
vm.Name = "Test VM1";  
vm.StartVM = true;  
  
vmmService.AddToVirtualMachines(vm);  
vmmService.SaveChanges();  
  

Example

The following code example shows an HTTP request that is sent to the server.

{  
    "AddedTime": null,  
    "Agent": null,  
    "AllocatedGPU": null,  
    "BackupEnabled": null,  
    "BlockDynamicOptimization": null,  
    "BlockLiveMigrationIfHostBusy": null,  
    "CPUCount": null,  
    "CPULimitForMigration": null,  
    "CPULimitFunctionality": null,  
    "CPUMax": null,  
    "CPURelativeWeight": null,  
    "CPUReserve": null,  
    "CPUType": null,  
    "CPUUtilization": null,  
    "CanVMConnect": null,  
    "CapabilityProfile": null,  
    "CheckpointLocation": null,  
    "CloudId": "6f15c12a-0ebb-453e-b366-87f6c4c8d80f",  
    "CloudVMRoleName": null,  
    "ComputerName": null,  
    "ComputerTierId": null,  
    "CostCenter": null,  
    "CreationSource": null,  
    "CreationTime": null,  
    "DataExchangeEnabled": null,  
    "DelayStart": null,  
    "DelayStartSeconds": null,  
    "DeployPath": null,  
    "DeploymentErrorInfo": {  
        "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,  
        "odata.type": "VMM.ErrorInfo"  
    },  
    "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": [],  
    "GrantedToList@odata.type": "Collection(VMM.UserAndRole)",  
    "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": "Test VM1",  
    "NetworkUtilization": null,  
    "NewVirtualNetworkAdapterInput": [],  
    "NewVirtualNetworkAdapterInput@odata.type": "Collection(VMM.NewVMVirtualNetworkAdapterInput)",  
    "NumLock": null,  
    "OperatingSystem": null,  
    "OperatingSystemInstance": {  
        "Architecture": null,  
        "Description": null,  
        "Edition": null,  
        "Name": null,  
        "OSType": null,  
        "ProductType": null,  
        "Version": null,  
        "odata.type": "VMM.OperatingSystem"  
    },  
    "OperatingSystemShutdownEnabled": null,  
    "Operation": null,  
    "OrganizationName": null,  
    "Owner": {  
        "RoleID": null,  
        "RoleName": null,  
        "UserName": null,  
        "odata.type": "VMM.UserAndRole"  
    },  
    "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": "2063fa8c-3cbe-4397-93e7-170dda5a75dc",  
    "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,  
    "VMBaseConfigurationId": null,  
    "VMCPath": null,  
    "VMConfigResource": null,  
    "VMHostName": null,  
    "VMId": null,  
    "VMNetworkAssignments": [],  
    "VMNetworkAssignments@odata.type": "Collection(VMM.VMNetworkAssignment)",  
    "VMResource": null,  
    "VMResourceGroup": null,  
    "VMTemplateId": null,  
    "VirtualHardDiskId": "fbb2c54a-4c69-46ca-9d48-146a7a2acc88",  
    "VirtualMachineState": null,  
    "VirtualizationPlatform": null,  
    "WorkGroup": null,  
    "odata.type": "VMM.VirtualMachine"  
}  
  

Example

The following code example shows the HTTP response from the server.

  
{  
    "AddedTime": "2013-10-15T08:50:24.0930734-07:00",  
    "Agent": null,  
    "AllocatedGPU": null,  
    "BackupEnabled": false,  
    "BlockDynamicOptimization": null,  
    "BlockLiveMigrationIfHostBusy": null,  
    "CPUCount": 1,  
    "CPULimitForMigration": null,  
    "CPULimitFunctionality": null,  
    "CPUMax": 100,  
    "CPURelativeWeight": null,  
    "CPUReserve": 0,  
    "CPUType": "3.60 GHz Xeon (2 MB L2 cache)",  
    "CPUUtilization": 0,  
    "CanVMConnect": null,  
    "CapabilityProfile": null,  
    "CheckpointLocation": null,  
    "CloudId": "6f15c12a-0ebb-453e-b366-87f6c4c8d80f",  
    "CloudVMRoleName": null,  
    "ComputerName": "PIB5M2VZZG0GN12",  
    "ComputerTierId": null,  
    "CostCenter": null,  
    "CreationSource": "Temporary Template24e9117f-a090-4dbe-a507-2c28cf8e189b",  
    "CreationTime": "2013-10-15T08:50:24.0930734-07:00",  
    "DataExchangeEnabled": false,  
    "DelayStart": 0,  
    "DelayStartSeconds": null,  
    "DeployPath": null,  
    "DeploymentErrorInfo": {  
        "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  
    },  
    "Description": "",  
    "DiskIO": 0,  
    "Dismiss": null,  
    "Domain": null,  
    "DynamicMemoryBufferPercentage": null,  
    "DynamicMemoryDemandMB": 0,  
    "DynamicMemoryEnabled": false,  
    "DynamicMemoryMaximumMB": null,  
    "Enabled": true,  
    "ExcludeFromPRO": false,  
    "ExpectedCPUUtilization": 20,  
    "FailedJobID": "8d3abb0b-8649-40fd-95a7-06e7c47db2e4",  
    "FullName": null,  
    "Generation": 1,  
    "GrantedToList": [],  
    "HardwareProfileId": null,  
    "HasPassthroughDisk": false,  
    "HasSavedState": false,  
    "HasVMAdditions": false,  
    "HeartbeatEnabled": false,  
    "HighlyAvailable": null,  
    "ID": "75f6b4a3-d998-4fd1-bd0d-7ba4a249c7f9",  
    "IsFaultTolerant": false,  
    "IsHighlyAvailable": false,  
    "IsRecoveryVM": false,  
    "IsUndergoingLiveMigration": false,  
    "LastRestoredCheckpointId": null,  
    "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": null,  
    "ModifiedTime": "2013-10-15T08:50:26.0774981-07:00",  
    "MostRecentTaskId": "8d3abb0b-8649-40fd-95a7-06e7c47db2e4",  
    "Name": "Test VM1",  
    "NetworkUtilization": 0,  
    "NewVirtualNetworkAdapterInput": [],  
    "NumLock": null,  
    "OperatingSystem": "CentOS Linux 6 (64 bit)",  
    "OperatingSystemInstance": {  
        "Architecture": null,  
        "Description": null,  
        "Edition": null,  
        "Name": null,  
        "OSType": null,  
        "ProductType": null,  
        "Version": null  
    },  
    "OperatingSystemShutdownEnabled": false,  
    "Operation": null,  
    "OrganizationName": null,  
    "Owner": {  
        "RoleID": "75700cd5-893e-4f68-ada7-50ef4668acc6",  
        "RoleName": "Administrator",  
        "UserName": "Domain\\CurrentUser"  
    },  
    "Password": null,  
    "Path": null,  
    "PerfCPUUtilization": -1,  
    "PerfDiskBytesRead": "-1",  
    "PerfDiskBytesWrite": "-1",  
    "PerfNetworkBytesRead": "-1",  
    "PerfNetworkBytesWrite": "-1",  
    "ProductKey": null,  
    "Retry": null,  
    "RunAsAccountUserName": null,  
    "RunGuestAccount": null,  
    "ServiceDeploymentErrorMessage": null,  
    "ServiceId": null,  
    "SharePath": null,  
    "SourceObjectType": "VM Template",  
    "StampId": "2063fa8c-3cbe-4397-93e7-170dda5a75dc",  
    "StartAction": "NeverAutoTurnOnVM",  
    "StartVM": null,  
    "Status": "UnderCreation",  
    "StatusString": "Creating...",  
    "StopAction": "SaveVM",  
    "Tag": "(none)",  
    "TimeSynchronizationEnabled": false,  
    "TimeZone": null,  
    "TotalSize": "0",  
    "Undo": null,  
    "UndoDisksEnabled": false,  
    "UpgradeDomain": null,  
    "UseCluster": null,  
    "UseLAN": null,  
    "UserName": null,  
    "VMBaseConfigurationId": null,  
    "VMCPath": null,  
    "VMConfigResource": null,  
    "VMConnection@odata.mediaContentType": "application/x-rdp",  
    "VMHostName": null,  
    "VMId": null,  
    "VMNetworkAssignments": [],  
    "VMResource": null,  
    "VMResourceGroup": null,  
    "VMTemplateId": null,  
    "VirtualHardDiskId": null,  
    "VirtualMachineState": "PowerOff",  
    "VirtualizationPlatform": "HyperV",  
    "WorkGroup": null,  
    "odata.metadata": "https://spfserver:8090/SC2012R2/VMM/Microsoft.Management.Odata.svc/$metadata#VirtualMachines/@Element"  
}  

See Also

Virtual Machine Management
How to Get a List of Virtual Machines
How to Create a Virtual Machine from a Template
How to Delete a Virtual Machine
How to Start and Stop Virtual Machines