Top Banner
Developing Solutions For Windows Server 2008 Hyper-V Using WMI Nihar Shah Senior Development Lead Microsoft Corporation ES1 0
90

Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Developing Solutions For Windows Server 2008 Hyper-V Using WMI

Nihar ShahSenior Development LeadMicrosoft Corporation

ES10

Page 2: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Overview Virtual Machines Virtual Machine Management Use Case – Creating a Virtual Machine Virtual Devices Resource Pools Use Case – Attaching a VHD to a Virtual Machine Networking Use Case – Configuring Networking Q & A

Agenda

Page 3: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

To provide a detailed overview of the WMI object model in Windows Server 2008 Hyper-V

To communicate “best practices” when programming against the Hyper-V WMI API

To develop an understanding of how to perform common tasksusing Windows Server 2008 Hyper-V

Goals

Page 4: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

overview

Page 5: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Version 2.12e of the DMTF standard Concrete subclasses use the Msvm_ prefix

Windows Server 2008 Hyper-V

Page 6: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Version 2.12e of the DMTF standard Concrete subclasses use the Msvm_ prefix

Snapshots Point-in-time representation of a VM

Configuration Disk Runtime state

Windows Server 2008 Hyper-V

Page 7: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Version 2.12e of the DMTF standard Concrete subclasses use the Msvm_ prefix

Snapshots Point-in-time representation of a VM

Configuration Disk Runtime state

Applying a snapshot Snapshot is unaffected “Current” configuration for the VM is overwritten Disk and runtime state are copied

Windows Server 2008 Hyper-V

Page 8: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Version 2.12e of the DMTF standard Concrete subclasses use the Msvm_ prefix

Snapshots Point-in-time representation of a VM

Configuration Disk Runtime state

Applying a snapshot Snapshot is unaffected “Current” configuration for the VM is overwritten Disk and runtime state are copied

Typically read-only

Windows Server 2008 Hyper-V

Page 9: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

virtual machines

Page 10: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Virtual Machine Object Model

LogicalDevice

Virtual Device in the VM

LogicalDevice

Virtual Device in the VM

ComputerSystem

Virtual Machine(Child Partition)

LogicalDevice

Virtual Device in the VM

VirtualSystemSettingData

Current Settings for the Virtual Machine

SystemDevice VirtualSystemSettingDataComponent

SettingsDefineState

VirtualSystemSettingData

Snapshot Settings for the Virtual Machine

ElementSettingData

VirtualSystemSettingDataComponent

ResourceAllocationSettingData

Current Settings for the Virtual Device

ResourceAllocationSettingData

Snapshot Settings for the Virtual Device

VirtualSystemGlobalSettingData

Global Settings for the Virtual Machine

SettingsDefineState

Page 11: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Virtual Machine

LogicalDevice

Virtual Device in the VM

LogicalDevice

Virtual Device in the VM

LogicalDevice

Virtual Device in the VM

VirtualSystemSettingData

Current Settings for the Virtual Machine

SystemDevice VirtualSystemSettingDataComponent

SettingsDefineState

VirtualSystemSettingData

Snapshot Settings for the Virtual Machine

ElementSettingData

VirtualSystemSettingDataComponent

ResourceAllocationSettingData

Current Settings for the Virtual Device

ResourceAllocationSettingData

Snapshot Settings for the Virtual Device

VirtualSystemGlobalSettingData

Global Settings for the Virtual Machine

SettingsDefineState

ComputerSystem

Virtual Machine(Child Partition)

Page 12: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Virtual Machine Settings

LogicalDevice

Virtual Device in the VM

LogicalDevice

Virtual Device in the VM

ComputerSystem

Virtual Machine(Child Partition)

LogicalDevice

Virtual Device in the VM

SystemDevice VirtualSystemSettingDataComponent

SettingsDefineState

VirtualSystemSettingDataComponent

ResourceAllocationSettingData

Current Settings for the Virtual Device

ResourceAllocationSettingData

Snapshot Settings for the Virtual Device

VirtualSystemGlobalSettingData

Global Settings for the Virtual Machine

SettingsDefineState

VirtualSystemSettingDataCurrent Settings for the

Virtual Machine

VirtualSystemSettingDataSnapshot Settings for the

Virtual Machine

ElementSettingData

Page 13: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Global Virtual Machine Settings

LogicalDevice

Virtual Device in the VM

LogicalDevice

Virtual Device in the VM

ComputerSystem

Virtual Machine(Child Partition)

LogicalDevice

Virtual Device in the VM

VirtualSystemSettingData

Current Settings for the Virtual Machine

SystemDevice VirtualSystemSettingDataComponent

SettingsDefineState

VirtualSystemSettingData

Snapshot Settings for the Virtual Machine

ElementSettingData

VirtualSystemSettingDataComponent

ResourceAllocationSettingData

Current Settings for the Virtual Device

ResourceAllocationSettingData

Snapshot Settings for the Virtual Device

SettingsDefineState

VirtualSystemGlobalSettingData

Global Settings for theVirtual Machine

Page 14: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Virtual Device

ComputerSystem

Virtual Machine(Child Partition)

VirtualSystemSettingData

Current Settings for the Virtual Machine

SystemDevice VirtualSystemSettingDataComponent

SettingsDefineState

VirtualSystemSettingData

Snapshot Settings for the Virtual Machine

ElementSettingData

VirtualSystemSettingDataComponent

ResourceAllocationSettingData

Current Settings for the Virtual Device

ResourceAllocationSettingData

Snapshot Settings for the Virtual Device

VirtualSystemGlobalSettingData

Global Settings for the Virtual Machine

SettingsDefineState

LogicalDevice

Virtual Device in the VM

LogicalDevice

Virtual Device in the VM

LogicalDevice

Virtual Device in the VM

Page 15: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Virtual Device Settings

SettingsDefineState

LogicalDevice

Virtual Device in the VM

LogicalDevice

Virtual Device in the VM

ComputerSystem

Virtual Machine(Child Partition)

LogicalDevice

Virtual Device in the VM

VirtualSystemSettingData

Current Settings for theVirtual Machine

SystemDeviceVirtualSystem

SettingDataComponent

SettingsDefineState

VirtualSystemSettingData

Snapshot Settings for theVirtual Machine

ElementSettingData

VirtualSystemSettingDataComponent

ResourceAllocationSettingData

Current Settings for theVirtual Device

ResourceAllocationSettingData

Snapshot Settings for the Virtual Device

VirtualSystemGlobalSettingData

Global Settings for theVirtual Machine

Page 16: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Msvm_ComputerSystem Represents either a physical or virtual machine

Msvm_HostedDependency Antecedent – Physical Machine Dependent – Virtual Machine

Virtual Machine

ComputerSystem

Virtual Machine(Child Partition)

HostedDependency

ComputerSystem

Physical Machine(Parent Partition)

Page 17: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Msvm_ComputerSystem EnabledState RequestStateChange()

“Enabled” “Disabled” “Paused” “Suspended” “Reset”

ProcessID

Virtual Machine

Page 18: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Msvm_VirtualSystemSettingData (VSSD) Current or snapshot settings for the VM

Associations Msvm_SettingsDefineState Msvm_ElementSettingData

SettingType Current = ‘3’ Snapshot = ‘5’

Virtual Machine Settings

ComputerSystem

Virtual Machine(Child Partition)

VirtualSystemSettingData

Current Settings for the Virtual Machine

SettingsDefineState

VirtualSystemSettingData

Snapshot Settings for the Virtual Machine

ElementSettingData

Page 19: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Msvm_VirtualSystemSettingData BIOS settings NUMA settings Notes Parent

Virtual Machine Settings

Page 20: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Msvm_VirtualSystemSettingData BIOS settings NUMA settings Notes Parent

Msvm_VirtualSystemGlobalSettingData ElementName Automatic startup/shutdown/recovery actions ScopeOfResidence ExternalDataRoot SnapshotDataRoot

Virtual Machine Settings

Page 21: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

virtual machine management

Page 22: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Msvm_VirtualSystemManagementService Methods for managing virtual machine elements

Virtual machines Devices Snapshots

Virtual Machine Management

Page 23: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Msvm_VirtualSystemManagementService Methods for managing virtual machine elements

Virtual machines Devices Snapshots

Embedded instances Intrinsic ‘Put’ and ‘Delete’ operations not supported CIM-XML format .NET -

ManagementObject.GetText(TextFormat.WmiDtd20) PowerShell - $obj.PsBase.GetText(1)

Virtual Machine Management

Page 24: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Asynchronous operations Return code

0 – Succeeded synchronously

Virtual Machine Management

Page 25: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Asynchronous operations Return code

0 – Succeeded synchronously 4096 – Operation started

CIM_ConcreteJob object indicates progress, completion status, and rich error information

Virtual Machine Management

Page 26: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Asynchronous operations Return code

0 – Succeeded synchronously 4096 – Operation started

CIM_ConcreteJob object indicates progress, completion status, and rich error information

Any other return code indicates an error Invalid parameter Insufficient memory Invalid virtual machine state

Virtual Machine Management

Page 27: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Create Virtual Machine

use case

Page 28: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Create Virtual Machine

# Get Msvm_VirtualSystemGlobalSettingData class definition$wmiClassString = "\\svr\root\virtualization:Msvm_VirtualSystemGlobalSettingData"$wmiClass = [WMIClass]$wmiClassString

Page 29: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Create Virtual Machine

# Get Msvm_VirtualSystemGlobalSettingData class definition$wmiClassString = "\\svr\root\virtualization:Msvm_VirtualSystemGlobalSettingData"$wmiClass = [WMIClass]$wmiClassString

#Create a local instance of the class$vsgsd = $wmiClass.CreateInstance()$vsgsd.psbase.Properties.Item("ElementName").value = "MyVM"

Page 30: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Create Virtual Machine

# Get Msvm_VirtualSystemGlobalSettingData class definition$wmiClassString = "\\svr\root\virtualization:Msvm_VirtualSystemGlobalSettingData"$wmiClass = [WMIClass]$wmiClassString

#Create a local instance of the class$vsgsd = $wmiClass.CreateInstance()$vsgsd.psbase.Properties.Item("ElementName").value = "MyVM"

# Serialize $vsgsd into an embedded instance$embeddedInstance = $vsgsd.psbase.GetText(1)

Page 31: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Create Virtual Machine

# Get Msvm_VirtualSystemGlobalSettingData class definition$wmiClassString = "\\svr\root\virtualization:Msvm_VirtualSystemGlobalSettingData"$wmiClass = [WMIClass]$wmiClassString

#Create a local instance of the class$vsgsd = $wmiClass.CreateInstance()$vsgsd.psbase.Properties.Item("ElementName").value = "MyVM"

# Serialize $vsgsd into an embedded instance$embeddedInstance = $vsgsd.psbase.GetText(1)

# Get Msvm_VirtualSystemManagementService instance$managementService = gwmi Msvm_VirtualSystemManagementService -namespace "root\virtualization" -ComputerName “svr“

Page 32: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Create Virtual Machine

# Get Msvm_VirtualSystemGlobalSettingData class definition$wmiClassString = "\\svr\root\virtualization:Msvm_VirtualSystemGlobalSettingData"$wmiClass = [WMIClass]$wmiClassString

#Create a local instance of the class$vsgsd = $wmiClass.CreateInstance()$vsgsd.psbase.Properties.Item("ElementName").value = "MyVM"

# Serialize $vsgsd into an embedded instance$embeddedInstance = $vsgsd.psbase.GetText(1)

# Get Msvm_VirtualSystemManagementService instance$managementService = gwmi Msvm_VirtualSystemManagementService -namespace "root\virtualization" -ComputerName "svr"

# Create the virtual machine$result = $managementService.DefineVirtualSystem( $embeddedInstance, $null)

Page 33: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

ConcreteJob Handling

# If ReturnValue = 4096, the operation is handled asynchronouslyif ($result.ReturnValue -eq 4096){}

Page 34: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

ConcreteJob Handling

# If ReturnValue = 4096, the operation is handled asynchronouslyif ($result.ReturnValue -eq 4096){ $job=[WMI]$result.job

# Loop while JobState = 3 ("Starting") or 4 ("Running") while ($job.JobState -eq 3 -or $job.JobState -eq 4) { }}

Page 35: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

ConcreteJob Handling

# If ReturnValue = 4096, the operation is handled asynchronouslyif ($result.ReturnValue -eq 4096){ $job=[WMI]$result.job

# Loop while JobState = 3 ("Starting") or 4 ("Running") while ($job.JobState -eq 3 -or $job.JobState -eq 4) { write-host $job.PercentComplete start-sleep 1 $job=[WMI]$Result.job }}

Page 36: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

ConcreteJob Handling

# If ReturnValue = 4096, the operation is handled asynchronouslyif ($result.ReturnValue -eq 4096){ $job=[WMI]$result.job

# Loop while JobState = 3 ("Starting") or 4 ("Running") while ($job.JobState -eq 3 -or $job.JobState -eq 4) { write-host $job.PercentComplete start-sleep 1 $job=[WMI]$Result.job }

# Indicate whether the operation succeeded if ($job.JobState -eq 7) write-host "Virtual machine created.“ else write-host $job.GetError}

Page 37: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

virtual devices

Page 38: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

CIM_LogicalDevice Only surfaced when the VM is powered on

Running/Paused/Transitional states Associations

Msvm_SystemDevice Msvm_SettingsDefineState

Emulated versus Synthetic devices

Virtual Devices

LogicalDevice

Virtual Device in the VM

SystemDevice

ComputerSystem

Virtual Machine(Child Partition)

Page 39: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

CIM_ResourceAllocationSettingData (RASD) Current or snapshot settings for a device Associated with “current” or “snapshot”

instance of Msvm_VirtualSystemSettingData

Virtual Device Settings

VirtualSystemSettingData

Current Settings for theVirtual Machine

VirtualSystemSettingDataComponent

VirtualSystemSettingData

Snapshot Settings for the Virtual Machine

VirtualSystemSettingDataComponent

ResourceAllocationSettingData

Snapshot Settings for the Virtual Device

ResourceAllocationSettingData

Current Settings for theVirtual Device

Page 40: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

CIM_ResourceAllocationSettingData Always present in a VM Device type

ResourceType ResourceSubType OtherResourceType

Virtual Device Settings

Page 41: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

CIM_ResourceAllocationSettingData Always present in a VM Device type

ResourceType ResourceSubType OtherResourceType

Virtual machine connectivity Parent Address

Virtual Device Settings

Page 42: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

CIM_ResourceAllocationSettingData Always present in a VM Device type

ResourceType ResourceSubType OtherResourceType

Virtual machine connectivity Parent Address

Physical machine connectivity HostResource[] Connection[]

Virtual Device Settings

Page 43: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

resource pools

Page 44: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Resource Pool Object Model

AllocationCapabilities

Capabilities for the Virtual Resources in the Pool

ResourceAllocationSettingData

Default Values for Each Property

ResourcePool

Pool of Resources Which May Be Allocated to a VM

ResourceAllocationSettingData

Minimum Values for Each Property

ResourceAllocationSettingData

Maximum Values for Each Property

ResourceAllocationSettingData

Increment Values for Each Property

ElementCapabilities

SettingsDefineCapabilities

Page 45: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Get instance of CIM_ResourcePool

Resource Pool Usage

Page 46: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Get instance of CIM_ResourcePool Navigate to “Default” RASD

Resource Pool Usage

Page 47: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Get instance of CIM_ResourcePool Navigate to “Default” RASD Modify RASD values

Respect minimum, maximum, and increment values specified in the other RASD instances

Resource Pool Usage

Page 48: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Get instance of CIM_ResourcePool Navigate to “Default” RASD Modify RASD values

Respect minimum, maximum, and increment values specified in the other RASD instances

Convert RASD into an embedded instance

Resource Pool Usage

Page 49: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Get instance of CIM_ResourcePool Navigate to “Default” RASD Modify RASD values

Respect minimum, maximum, and increment values specified in the other RASD instances

Convert RASD into an embedded instance Call AddVirtualSystemResources method

to add the device to a virtual machine

Resource Pool Usage

Page 50: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Add Storage to a Virtual Machine

use case

Page 51: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Pass-through Storage Controller Disk Drive

Connected directly to physical storage volume

Storage Types

Page 52: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Pass-through Storage Controller Disk Drive

Connected directly to physical storage volume Virtual Hard Disk (VHD)

Controller Disk Drive Logical Disk

Connected to VHD file

Storage Types

Page 53: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Get Existing IDE Controller

# Get the virtual machine object$Vm = Get-WmiObject -Namespace "root\virtualization" –Query "SELECT * From Msvm_ComputerSystem WHERE ElementName='MyVM'"

Page 54: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Get Existing IDE Controller

# Get the virtual machine object$Vm = Get-WmiObject -Namespace "root\virtualization" –Query "SELECT * From Msvm_ComputerSystem WHERE ElementName='MyVM'"

# Get the current VM settings object$Vssd = Get-WmiObject -Namespace "root\virtualization" –Query "ASSOCIATORS OF {$Vm} WHERE AssocClass=Msvm_SettingsDefineState ResultClass=Msvm_VirtualSystemSettingData"

Page 55: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Get Existing IDE Controller

# Get the virtual machine object$Vm = Get-WmiObject -Namespace "root\virtualization" –Query "SELECT * From Msvm_ComputerSystem WHERE ElementName='MyVM'"

# Get the current VM settings object$Vssd = Get-WmiObject -Namespace "root\virtualization" –Query "ASSOCIATORS OF {$Vm} WHERE AssocClass=Msvm_SettingsDefineState ResultClass=Msvm_VirtualSystemSettingData"

# Get the settings for IDE controller 0 on the VM$IdeRasd = (Get-WmiObject -Namespace "root\virtualization" -Query "ASSOCIATORS OF {$Vssd} WHERE AssocClass=Msvm_VirtualSystemSettingDataComponent ResultClass=Msvm_ResourceAllocationSettingData" | Where-Object {$_.ResourceType –eq 5 -and $_.Address –eq 0})

Page 56: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Get Default Disk Drive Settings

$DrivePool = Get-WmiObject -Namespace "root\virtualization" -Query "SELECT * FROM Msvm_ResourcePool WHERE ResourceType=22 AND ResourceSubType='Microsoft Synthetic Disk Drive'"

Page 57: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Get Default Disk Drive Settings

$DrivePool = Get-WmiObject -Namespace "root\virtualization" -Query "SELECT * FROM Msvm_ResourcePool WHERE ResourceType=22 AND ResourceSubType='Microsoft Synthetic Disk Drive'"

$DriveCaps = Get-WmiObject –Namespace "root\virtualization" –Query "ASSOCIATORS OF {$DrivePool} WHERE AssocClass=Msvm_ElementCapabilities ResultClass=Msvm_AllocationCapabilities"

Page 58: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Get Default Disk Drive Settings

$DrivePool = Get-WmiObject -Namespace "root\virtualization" -Query "SELECT * FROM Msvm_ResourcePool WHERE ResourceType=22 AND ResourceSubType='Microsoft Synthetic Disk Drive'"

$DriveCaps = Get-WmiObject –Namespace "root\virtualization" –Query "ASSOCIATORS OF {$DrivePool} WHERE AssocClass=Msvm_ElementCapabilities ResultClass=Msvm_AllocationCapabilities"

$DriveRasd = Get-WmiObject -Namespace "root\virtualization" -Query "REFERENCES OF {$DriveCaps} WHERE ResultClass=Msvm_SettingsDefineCapabilities" | Where-Object {$_.ValueRole -eq 0} | ForEach-Object {[Wmi]$_.PartComponent})

Page 59: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Configure And Add Disk Drive

# Configure the drive as the first device on the IDE controller$DriveRasd.Parent = $IdeRasd.__Path$DriveRasd.Address = 0

Page 60: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Configure And Add Disk Drive

# Configure the drive as the first device on the IDE controller$DriveRasd.Parent = $IdeRasd.__Path$DriveRasd.Address = 0

# The AddVirtualSystemResources method takes an array of embedded instances of CIM_ResourceAllocationSettingData$RasdArray = [string[]]@($DriveRasd.PSBase.GetText(1))

Page 61: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Configure And Add Disk Drive

# Configure the drive as the first device on the IDE controller$DriveRasd.Parent = $IdeRasd.__Path$DriveRasd.Address = 0

# The AddVirtualSystemResources method takes an array of embedded instances of CIM_ResourceAllocationSettingData$RasdArray = [string[]]@($DriveRasd.PSBase.GetText(1))

# Add the disk drive to the virtual machine$result = $ManagementService.AddVirtualSystemResources($Vm, $RasdArray)

Page 62: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Pass-through Storage HostResource[0] property on disk drive RASD

Attaching Storage To A Disk Drive

Page 63: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Pass-through Storage HostResource[0] property on disk drive RASD

Virtual Hard Disk Add LogicalDisk device

Attaching Storage To A Disk Drive

Page 64: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Pass-through Storage HostResource[0] property on disk drive RASD

Virtual Hard Disk Add LogicalDisk device

Find ResourcePool for VHDs ResourceType = 21 (“Storage Extent”) ResourceSubType =

“Microsoft Virtual Hard Disk”

Attaching Storage To A Disk Drive

Page 65: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Pass-through Storage HostResource[0] property on disk drive RASD

Virtual Hard Disk Add LogicalDisk device

Find ResourcePool for VHDs ResourceType = 21 (“Storage Extent”) ResourceSubType =

“Microsoft Virtual Hard Disk” Navigate to “Default” RASD

Attaching Storage To A Disk Drive

Page 66: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Pass-through Storage HostResource[0] property on disk drive RASD

Virtual Hard Disk Add LogicalDisk device

Find ResourcePool for VHDs ResourceType = 21 (“Storage Extent”) ResourceSubType =

“Microsoft Virtual Hard Disk” Navigate to “Default” RASD Configure settings

Parent = Object path of disk drive RASD Connection[0] = File system path to VHD file

Attaching Storage To A Disk Drive

Page 67: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Pass-through Storage HostResource[0] property on disk drive RASD

Virtual Hard Disk Add LogicalDisk device

Find ResourcePool for VHDs ResourceType = 21 (“Storage Extent”) ResourceSubType =

“Microsoft Virtual Hard Disk” Navigate to “Default” RASD Configure settings

Parent = Object path of disk drive RASD Connection[0] = File system path to VHD file

Call AddVirtualSystemResources

Attaching Storage To A Disk Drive

Page 68: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

ComputerSystem

Virtual Machine(Child Partition)

LogicalDevice

IDE Controller

VirtualSystemSettingData

Current Settings for the Virtual Machine

SettingsDefineState

SettingsDefineState

ResourceAllocationSettingData

Settings for the IDE Controller

LogicalDevice

Disk Drive

LogicalDevice

Logical Disk(Virtual Hard Disk)

ResourceAllocationSettingData

Settings for the Disk Drive

ResourceAllocationSettingData

Settings for the Logical Disk

VirtualSystemSettingDataComponent

SettingsDefineState

SettingsDefineState

SystemDevice

Attaching Storage To A Disk Drive

Page 69: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

networking

Page 70: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Networking Object Model

External (Physical)Internal (Parent)Virtual MachineComputerSystem

Virtual Machine(Child Partition)

EthernetPort

Virtual NIC Device

SystemDevice

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

SwitchPort

Port on the Virtual Switch

VirtualSwitch

Virtual Switch Device

HostedAccessPoint

VmLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

DeviceSAPImplementation

ActiveConnection

SwitchPort

Port on the Virtual Switch

ExternalEthernetPort

Physical NIC Device

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

InternalEthernetPort

Internal NIC Used to Describe Connectivity into the Host OS

HostedAccessPoint

SwitchPort

Port on the Virtual Switch

GlobalEthernetPortSAPImplementation

ActiveConnection ActiveConnection

GlobalEthernetPortSAPImplementation

Page 71: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Networking Object Model

External (Physical)Internal (Parent)Virtual MachineComputerSystem

Virtual Machine(Child Partition)

EthernetPort

Virtual NIC Device

SystemDevice

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

SwitchPort

Port on the Virtual Switch

VirtualSwitch

Virtual Switch DeviceHosted

AccessPoint

VmLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

DeviceSAPImplementation

ActiveConnection

SwitchPort

Port on the Virtual Switch

ExternalEthernetPort

Physical NIC Device

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

InternalEthernetPort

Internal NIC Used to Describe Connectivity into the Host OS

HostedAccessPoint

SwitchPort

Port on the Virtual Switch

GlobalEthernetPortSAPImplementation

ActiveConnection ActiveConnection

GlobalEthernetPortSAPImplementation

Page 72: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Networking Object Model

External (Physical)Internal (Parent)Virtual MachineComputerSystem

Virtual Machine(Child Partition)

EthernetPort

Virtual NIC Device

SystemDevice

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

SwitchPort

Port on the Virtual Switch

VirtualSwitch

Virtual Switch Device

HostedAccessPoint

VmLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

DeviceSAPImplementation

ActiveConnection

SwitchPort

Port on the Virtual Switch

ExternalEthernetPort

Physical NIC Device

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

InternalEthernetPort

Internal NIC Used to Describe Connectivity into the Host OS

HostedAccessPoint

SwitchPort

Port on the Virtual Switch

GlobalEthernetPortSAPImplementation

ActiveConnection ActiveConnection

GlobalEthernetPortSAPImplementation

Page 73: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Networking Object Model

Internal (Parent)Virtual MachineComputerSystem

Virtual Machine(Child Partition)

EthernetPort

Virtual NIC Device

SystemDevice

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

SwitchPort

Port on the Virtual Switch

VirtualSwitch

Virtual Switch Device

HostedAccessPoint

VmLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

DeviceSAPImplementation

ActiveConnection

SwitchPort

Port on the Virtual Switch

ExternalEthernetPort

Physical NIC Device

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

InternalEthernetPort

Internal NIC Used to Describe Connectivity into the Host OS

HostedAccessPoint

SwitchPort

Port on the Virtual Switch

GlobalEthernetPortSAPImplementation

ActiveConnection ActiveConnection

GlobalEthernetPortSAPImplementation

External (Physical)

Page 74: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

External (Physical)Virtual MachineComputerSystem

Virtual Machine(Child Partition)

EthernetPort

Virtual NIC Device

SystemDevice

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

SwitchPort

Port on the Virtual Switch

VirtualSwitch

Virtual Switch Device

HostedAccessPoint

VmLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

DeviceSAPImplementation

ActiveConnection

SwitchPort

Port on the Virtual Switch

ExternalEthernetPort

Physical NIC Device

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

InternalEthernetPort

Internal NIC Used to Describe Connectivity into the Host OS

HostedAccessPoint

SwitchPort

Port on the Virtual Switch

GlobalEthernetPortSAPImplementation

ActiveConnection ActiveConnection

GlobalEthernetPortSAPImplementation

Internal (Parent)

Networking Object Model

Page 75: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Networking Object Model

External (Physical)Internal (Parent)Virtual MachineComputerSystem

Virtual Machine(Child Partition)

EthernetPort

Virtual NIC Device

SystemDevice

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

SwitchPort

Port on the Virtual Switch

VirtualSwitch

Virtual Switch Device

HostedAccessPoint

VmLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

DeviceSAPImplementation

ActiveConnection

SwitchPort

Port on the Virtual Switch

ExternalEthernetPort

Physical NIC Device

SwitchLANEndpoint

Protocol Endpoint Used To Connect Two Networking Ports

InternalEthernetPort

Internal NIC Used to Describe Connectivity into the Host OS

HostedAccessPoint

SwitchPort

Port on the Virtual Switch

GlobalEthernetPortSAPImplementation

ActiveConnection ActiveConnection

GlobalEthernetPortSAPImplementation

Page 76: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Networking

use case

Page 77: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Create Virtual Switch

# Get an instance of the virtual switch management service$VirtualSwitchService = get-wmiobject –class "Msvm_VirtualSwitchManagementService" –namespace "root\virtualization" -computername "MyServer"

Page 78: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Create Virtual Switch

# Get an instance of the virtual switch management service$VirtualSwitchService = get-wmiobject –class "Msvm_VirtualSwitchManagementService" –namespace "root\virtualization" -computername "MyServer“

# Create a virtual switch$ReturnObject = $VirtualSwitchService.CreateSwitch( [guid]::NewGuid().ToString(), "My Switch", 1024, "")$CreatedSwitch = [WMI]$ReturnObject.CreatedVirtualSwitch

Page 79: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Create Switch Ports

# Create internal switch port$ReturnObject = $VirtualSwitchService.CreateSwitchPort($CreatedSwitch, [guid]::NewGuid().ToString(), "Internal Switch Port", "")$InternalSwitchPort = [WMI]$ReturnObject.CreatedSwitchPort

Page 80: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Create Switch Ports

# Create internal switch port$ReturnObject = $VirtualSwitchService.CreateSwitchPort($CreatedSwitch, [guid]::NewGuid().ToString(), "Internal Switch Port", "")$InternalSwitchPort = [WMI]$ReturnObject.CreatedSwitchPort

# Create external switch port$ReturnObject = $VirtualSwitchService.CreateSwitchPort($CreatedSwitch, [guid]::NewGuid().ToString(), "External Switch Port", "")$ExternalSwitchPort = [WMI]$ReturnObject.CreatedSwitchPort

# Create VM switch port$ReturnObject = $VirtualSwitchService.CreateSwitchPort($CreatedSwitch, [guid]::NewGuid().ToString(), "MyVm Switch Port", "")$VmSwitchPort = [WMI]$ReturnObject.CreatedSwitchPort

Page 81: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Setup Switch

# Find an unbound physical NIC$PhysicalNic = get-wmiobject -namespace "root\virtualization" -Query "SELECT * FROM Msvm_ExternalEthernetPort WHERE IsBound=False" -computername "MyServer" | select –first 1

Page 82: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Setup Switch

# Find an unbound physical NIC$PhysicalNic = get-wmiobject -namespace "root\virtualization" -Query "SELECT * FROM Msvm_ExternalEthernetPort WHERE IsBound=False" -computername "MyServer" | select –first 1

# Call SetupSwitch to create internal and external connectivity$result = $VirtualSwitchService.SetupSwitch( $ExternalSwitchPort, $InternalSwitchPort, $PhysicalNic, [guid]::NewGuid().ToString(), "Internal Ethernet Port")

Page 83: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Connect Virtual Machine

$NicPool = Get-WmiObject -Namespace "root\virtualization" -Query "SELECT * FROM Msvm_ResourcePool WHERE ResourceType=10 AND ResourceSubType='Microsoft Emulated Ethernet Port'"

$NicCaps = Get-WmiObject –Namespace "root\virtualization" –Query "ASSOCIATORS OF {$NicPool} WHERE AssocClass=Msvm_ElementCapabilities ResultClass=Msvm_AllocationCapabilities"

$NicRasd = Get-WmiObject -Namespace "root\virtualization" -Query "REFERENCES OF {$NicCaps} WHERE ResultClass=Msvm_SettingsDefineCapabilities" | Where-Object {$_.ValueRole -eq 0} | ForEach-Object {[Wmi]$_.PartComponent})

Page 84: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Connect Virtual Machine

# Configure the settings for the virtual NIC$NicRasd.Connection[0] = $VmSwitchPort.__Path

# The AddVirtualSystemResources method takes an array of embedded instances of CIM_ResourceAllocationSettingData$RasdArray = [string[]]@($NicRasd.PSBase.GetText(1))

# Add the virtual NIC to the VM$result = $ManagementService.AddVirtualSystemResources($Vm, $RasdArray)

Page 85: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

following up

Page 86: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Additional sessions Enabling Test Automation Using

Windows Server 2008 Hyper-V Thursday, Oct. 30th, 12:00 – 1:15 PM Room 403AB

Visit the hands-on-lab! Get hands on experience programming against

the Hyper-V WMI APIs with members of the Hyper-V team to answer your questions

Following Up

Page 87: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Evals & Recordings

Please fill

out your

evaluation for

this session at:

This session will be available as a recording at:

www.microsoftpdc.com

Page 88: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

Please use the microphones provided

Q&A

Page 89: Nihar Shah Senior Development Lead Microsoft Corporation ES10.

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market

conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 90: Nihar Shah Senior Development Lead Microsoft Corporation ES10.