| Dung K Hoang 的个人资料Dung's space日志网络 | 帮助 |
|
|
7月23日 Delegation Model in Hyper-V – Part 6
In previous posts, I have shown how to create Azman scopes and roles to delegate administration of Hyper-V virtual machines to domain users. Now that we have an AzMan scope, let’s see how you can apply it to a virtual machine or set of virtual machines. Note: In Hyper-V, there is no GUI interface to assign a scope to a VM, you need to use the Hyper-V WMI API In my example scenario, I have a set of VMs prefixed with “01_”and I want to delegate administration of those VMs to Student01 and only this account can view those VMs in Hyper-V mmc console. In Prt 4 and Part 5, I already created a scope called 01_Scope and some role definitions. Let’s apply this cope to 01_ VMs.
Script$VM_Service = get-wmiobject -namespace root\virtualization Msvm_VirtualSystemManagementService $ListofVMs =get-wmiobject -namespace root\virtualization Msvm_ComputerSystem -filter "ElementName <> Name " | ` foreach ($VM in $ListofVMs) {
} Et Voilà! /Dung Delegation Model in Hyper-V – Part 5
Today, I will show you how to create an AzMan scope and role definition to manage Hyper-V Virtual machines. As discussed in part 3, the ”Virtual Machine Manager Role” includes the following operations:
For this role, you create a new scope in AzMan, define the role and assign it to users inside this scope. Step-by-Step
In summary ,you have defined 2 roles in Azman and assign those roles to an user called Student01
The Hyper-V Azman configuration should look like this one: Note: Instead of assigning roles to user accounts, you can assign roles to a Windows Security group. For example, in my training environment, I create a SG called AllStudents and assign the Hyper-V Manager role to this SG.
Enjoy! /Dung 7月12日 Delegation Model in Hyper-V – Part 4
Now that you have a good understanding of AzMan, let’s implement a simple delegation model of Hyper-V. I use the following scenario as example. In my training labs, I have a group of students ( Student01, Student02….) to whom I assign a set of VMs as follow: Student01 will get and can only manage 01_ VMs , Student02 will get 02_ VMs…
Basic AzMan rolesTo delegate administration of a selected virtual machine to a user, an administrator needs to:
You need to define at least the following roles:
For this role, you create a new scope in AzMan, define the role and assign it to users inside this scope and not at the default scope level.
Step-by-StepIn this section,I will show you how to create the roles in AzMan.
You have successfully created the Hyper-V Manager Role. Bravo! Enjoy! /Dung 7月8日 Delegation Model in Hyper-V – Part 3
Today, let’s discuss about basic Hyper-V operations defined in AzMan. Displaying Hyper-V OperationsAs explained in previous posts, all pre-defined Hyper-V operations are stored in the InitialStore.XML file located under C:\Programdata\Microsoft\Windows\Hyper-V. You can view the list of operations from the AzMan console. However the output is not easy to view as is is confined inside a small dialog box. Fortunately, you can also use PowerShell to get the same list with the AzMan COM object. Here is a snippet of PS script to get the list in a CSV file $AppName = "Hyper-V Services" ## Open the Hyper-V AzMan Store ## ## $HyperVApp | select Name, Description | export-csv c:\ListOfOperations.csv You can then import the CSV file into Excel and create the following tables that group Hyper-V operations per category.
Enjoy! /Dung 7月7日 Delegation Model in Hyper-V – Part 2
In this post, I will show you how to explore the Hyper-V AzMan configuration from the GUI AzMan GUI interfaceThere is no pre-defined AzMan console in Windows Server 2008, you have to create your own one. To do this, run mmc.exe from a command window. In the mmc, click File –> Add/Remove Snap-in and add the snap-in named Authorization Manager. Save your mmc console for later use. In the AzMan mmc console, right click the node Authorization Manager and select Open Authorization Store…. In the Open Authorization Store…, select XML file and type in Store name: C:\Programdata\Microsoft\Windows\Hyper-V\InitialStore.xml assuming that C: is your system drive. Note: Be aware that the ProgramData folder is hidden, you cannot browse it. Figure 1 shows the GUI interface of AzMan Exploring Hyper-V OperationsTo see all pre-defined operations in Hyper-V, right click Tasks Definition and select New Task Definition…. Click Add…, ignore the informational message box. In the Add Definition dialog box, click the Operations tab, you will see the list of available Hyper-V operations as shown in Figure 2 below Using the same technique, you can create task definitions, role definitions. Once done, you can look at the node Role Assignments to create roles and assign it to users or group of users. Creating ScopesNow, right click Hyper-V Services and select New Scope… Provide a name for the new scope and you will see that a node is created under Hyper-V Services and has the following sub-hierarchy: !------ Groups All tasks, role definitions and role assignments created there will be valid only at this new scope level. On the other hand, tasks, role definitions created at the default scope level can be seen/used by the “child” scope. SummaryIt is quite easy to use the AzMan console to create tasks, roles and scopes. In the next posts, I will show how to use PowerShell scripts to automate those tasks! Stay tuned!
Enjoy! /Dung 7月4日 Delegation Model in Hyper-V – Part 1
OverviewIn MS Virtual Server 2005, to grant users access to virtual machines, you have to modify settings in two different places. First, you use the Web interface to change Security settings of Virtual Server and grant specific permissions to users ( Full Control, Read …). Second, you control access to the folders where virtual machines files are located with Access Control List (ACLs) set on files and folders. Hyper-V uses a different authorization model which is based on Windows Authorization Manager (AzMan). AzMan is a role-based access control framework that provides runtime access validation methods for Windows applications. In contrast with the file-based access control model, AzMan offers the following advantages:
AzMan exists since Windows 2003 R2 and is now an integrated component of the Windows platform. There are great resources that give an overview/ in-depth coverage of AzMan, you can find some good references here:
AzMan conceptsThere are basic concepts in AzMan that you need to be familiar with before we go into details on how Hyper-V implements/use it for delegation. I will not describe the architecture of AzMan here, you can find some excellent materials from the references listed above.
So the scope is really the “link” between AzMan and Hyper-V, you apply a set of permissions ( created thru tasks and roles) of a scope to a set of Hyper-V objects. Hyper-V provides a Default Scope that applies to all Hyper-V objects, so if an object has no custom scope defined, then it will use the Default Scope. Hyper-V’s default scope is named “Hyper-V Services”. Scopes can be created from the default scope and they inherits tasks, roles definition and roles assignment from the parent scope. For example, if you create a new scope and apply to a set of objects, the objects will get all permissions ( through roles) defined in this scope and the default scope. Hyper-V objects and ScopeAll Hyper-V objects use the Default Scope but I find out that very few of them can accept user-defined scopes in the current release ( RC1) of Hyper-V. So far the following classes can have customized scopes:
Basically, only virtual machines, virtual switch and the Virtual Machine Management Service can accept custom AzMan scopes. Those objects have the property ScopeOfResidence defined in their base classes. To apply an Azman scope to those objects, you set their ScopeOfResidence to the name of the scope defined in AzMan. In the current release of Hyper-V , there is no GUI interface to apply a scope. You have to use scripts! SummaryThis is an overview of AzMan and how it is used in conjunction with Hyper-V. In the next posts, I will go through the AzMan interface and shows some scripts to create scopes and apply them to Hyper-V objects. Enjoy! /Dung 7月2日 MS TechNet webcast - Demo scripts
For those who attended the MS TechNet webcast today, here are the scripts that I’ve used for the demo. I will have the AzMan demo scripts in a couple of days. Stay tuned!
Demo 1: Create Virtual Switch## #################################################################### Demo2 : Import virtual machines## #################################################################### Demo 3: Change VM’s states and take snapshots## #################################################################### Demo 4: Configure VMs’ resources## #################################################################### EnjoY! /Dung 6月16日 TechNet Webcast on Hyper-V WMI
I will deliver a TechNet webcast next month to talk on Hyper-V WMI and PowerShell Here is the link for register Webcast Name: Managing Hyper-V Virtual Machines with WMI and Windows PowerShell (Level 300) Date: 7/2/2008 08:00 AM PST – 09:00 AM PST
See you there! /Dung 6月13日 Hyper-V WMI Examples – Part XIX
Virtual Machine creation – Revisiting the topic againSince I start the blog, I have seen many questions on how to create a new virtual machine and define resources such as memory, NICs at creation time. I must admit that the same question is in the back of my mind since a while and after looking at this blog entry of the Virtual PC guy, http://blogs.msdn.com/virtual_pc_guy/archive/2008/05/28/scripting-vm-creation-with-hyper-v.aspx, I decide to re-visit the topic and cover multiple scenarios here. In order to create a new virtual machine in Hyper-V, you must use the method DefineVirtualSystem of the Msvm_VirtualSystemManagementService object. This method accepts 3 parameters:
It is quite intimidating for those who just want to create a virtual machine with resources pre-defined for this VM, but if you read this blog since the beginning, you will see that it’s quite simple :=). Scenario 1: Creating a blank VMI notice that if you call this method without any parameter, it will create a blank virtual machine! ( although the documentation mentions that the 1st parameter is mandatory). So in its simplest form, creating a VM can be achieved with 3 lines of scripts: Script$Server = “localhost” $VM_Service.DefineVirtualSystem() The virtual machine will be created and displayed as “New Virtual Machine”
Scenario 2: Creating a VM with a pre-defined nameThe blog post mentioned above shows how to create a new VM and specify a new display name at time of creation. I will not reproduce the code here but basically you create a new instance of the class MSvm_VirtualSystemGlobalSettingData, change the display name and then call DefineVirtualSystem.
Scenario 3: Creating a VM and specifying resourcesIn this scenario, I want to create a virtual machine with two NIC cards. For this, I will be leveraging some scripts developed/ shown in Hyper-V WMI Examples - Part XIV for creating network adapters. The first NIC will have static MAc Address while the second one will use dynamic MAC address. Script$Server = “localhost” $VMGlobalSettingClass = [WMIClass]”\\Localhost\root\virtualization:Msvm_VirtualSystemGlobalSettingData" $NewGS = $VMGlobalSettingClass.psbase.CreateInstance() ## Now Create 2 NICs $GUID1 = [GUID]::NewGUID().ToString() $DefaultNIC = gwmi -namespace root/virtualization Msvm_SyntheticEthernetPortSettingData | where {$_.InstanceID -like "*Default*"} $StaticNIC = DefaultNIC.psbase.Clone() $DynamicNIC = DefaultNIC.psbase.Clone() ## Build an array of resources as required by DefineVirtualSystem $RASD = @() $RASD += $StaticNIC.psbase.gettext(1) ## Finally call DefineVirtualSystem $VM_Service.DefineVirtualSystem($NewGS.__PATH, $RASD) Et Voilà! Now that you understand the process, you can leverage my other examples to add DVD drive, new hard disks when creating virtual machines. I will leave it to you as homework for this weekend!
Enjoy! /Dung 6月11日 Hyper-V WMI Examples – Part XVIII
How to find list of VMs connected to a given switch?In MS Virtual Server 2005, when looking at a virtual network, you can easily find a list of VMs that are attached to this network. Well, there is no easy way to find it within Hyper-V unless …. Andy Schneider has asked the same question on getting a list of connected VMs per switch. So here is the result. Enjoy! Steps
NoteThe script finds all virtual machines that are attached to a given virtual machines. Those virtual machines must be running ,.ie. powered on to be listed by the script. Script$ListofVMs = gwmi -namespace root\virtualization Msvm_ComputerSystem -filter "ElementName <> Name" foreach ($Switch in $ListofSwitches) foreach ($Port in $PortsOnSwitch) Enjoy! /Dung 6月10日 Hyper-V WMI Explained - Part II
Management ServicesIn Hyper-V there are 3 services that govern all management activities of the virtual environment:
The figure below maps various action items shown in the Hyper-V Manager console to the three services described above Until the next time! Enjoy, /Dung Hyper-V WMI Explained - Part I
IntroductionI received many requests to explain some PowerShell examples on Hyper-V WMI so now it's great time to start a new series to dive in more detailed explanation about Hyper-V WMI. First let me say that your support through e-mail in the last few months are exceptional and I'd like to thank all the folks who send comments/suggestions to enhance the examples ( except for some scams in the blog!). Second let me write down a short disclaimer before going into technical details.
DisclaimerAll the information provided here are based on my own understanding of Hyper-V WMI during many hours of trials and tests. I use the two documents to learn about Hyper-V WMI:
In addition, I extensively use PowerShell and especially the get-member cmdlet to discover methods and properties of WMI object classes. This is a must if you want to write scripts or code against Hyper-V WMI. There certainly are other tools to browse WMI objects and I find Powershell quite handy for me. Finally, explanations provided are my interpretation of the documentation and based on my own testing. As such all the errors are also mine too! Now let's start then! /Dung 6月6日 Hyper-V WMI Examples - Part XVII
Removing virtual machines from Hyper-VThe following script is used to remove virtual machines from the Hyper-V console. ## Connect to the Virtual Management Service
Enjoy! /Dung 6月3日 Hyper-V WMI Examples - Part XVI
Changing the Boot order of a VMSometimes you may want to change the Boot order of a VM, for instance, to PXE boot a VM, to boot from a CD/DVD, or to simply fix the order to always start booting from the disk. You use the Msvm_VirtualSystemSettingData class to change the boot order setting f a VM. Objects of this class represents virtual "motherboard"" of a virtual machine and store virtualization-specific settings of a VM.
Script$VMName = "My Virtual Machine" $VM_Service = get-wmiobject –namespace root\virtualization Msvm_VirtualSystemManagementService # Step 1 $VM = get-wmiobject –namespace \root\virtualization Msvm_ComputerSystem | where {$_.ElementName -like $VMName ) # Step 2 - Get its "motherboard" $MB = get-wmiobject –namespace \root\virtualization Msvm_VirtualSystemSettingData | where {$_.ElementName -like $VMName ) # Step 3 - Change the Boot Order # Values are 0: Boot from floppy – 1: Boot from CD – 2: Boot from disk – 3:PXE Boot $MB.BootOrder = 3,1,2,0 # Step 4 $VM_Service.ModifyVirtualSystem($VM.__PATH, $MB.psbase.GetText(1))
Et Voilà! Enjoy! /Dung 5月27日 Hyper-V WMI Examples - Part XV
Creating a new virtual machine from an existing virtual hard diskDue to numerous requests, I dedicate this entry to talk about creating a virtual machine from an existing virtual hard disk. It seems that some of you were not able to get it working using the example of adding a DVD as resource to an existing VM. I must admit that it's not intuitive and I still have to do it several times to make it right.
GoalCreate a new virtual machine based on an existing virtual hard disk. The VHD file is called C:\W2K3.VHD and the disk will be created on IDE Controller 0 at location 0. High level steps
Script$VHDFile = "C:\W2K3.vhd" # Step 1 $VM_Service = get-wmiobject –namespace root\virtualization Msvm_VirtualSystemManagementService if ($status.ReturnValue -eq 0) # Step 2 $ListOfControllers = get-wmiobject -namespace root\virtualization Msvm_ResourceAllocationSettingData ` # Step 3 $DiskDefault = get-wmiobject -namespace root\virtualization Msvm_ResourceAllocationSettingData | ` # Step 4 $VHDDefault = get-wmiobject -namespace root\virtualization Msvm_ResourceAllocationSettingData | `
Enjoy! /Dung 5月17日 Hyper-V WMI Examples - Part XIV
Hyper-V Virtual Networks - Connecting virtual machines to a virtual networkNow that you know how to create virtual networks, let me show how to connect a NIC of a given virtual machine to a network The script below is extracted from a discussion in the Virtualization Technet Forum. All credits go to AggieMatt! ## Assumes that you already identify a virtual switch and store it in a variable called $Switch ## Create a new SwitchPort Enjoy! /Dung Hyper-V WMI Examples - Part XII
Hyper-V Virtual Networks - Creating External Virtual NetworksFinally let's see how you can create an External virtual network. Here is an overview of high level steps: External Virtual Network
Script# Step 0: Connect to the Virtual Network Management Service # Step 1 ## Change the name used above to the name of your network adapter. # Step 2 # Store the path for later use # Step 3: Create two ports on the switch # Store the path for later use # Port for External # Store the path for later use # Step 4 Enjoy! /Dung 5月15日 Hyper-V WMI Examples - Part XI
Hyper-V Virtual Networks - Creating Internal Virtual NetworksLet's talk about how to create Internal Virtual Networks. In my previous post, I described the concept and high level steps to create internal virtual network. Steps to create a Internal Virtual Network
Script$SW_Service = get-wmiobject –namespace root\virtualization Msvm_VirtualSwitchManagementService ## Step 1 $Status = $Sw_Service.CreateInternalEthernetPort("Internal Network Adapter", "Internal NIC", "020304050607" ) if ($Status.ReturnValue -eq 0)
## Step 2 $NIC_Port = [WMI]$InternalEtherPortPATH # Find the LANEndPoint associated to this NIC ## Step 3 $Status = $SW_Service.CreateSwitch(“Internal_Network”, “Host and Guests Virtual Network”, 1024, “”) if ($Status.ReturnValue -eq 0)
## Step 4 $Status = $SW_Service.CreateSwitchPort($SwitchPATH, "Internal_Port" , "Internal Port for Host") if ($Status.ReturnValue -eq 0)
## Step 5 $Status = $SW_Service.ConnectSwitchPort($PortPATH , $LANEndPoint) ## Additional Step - Create a port to connect VM $Status = $SW_Service.CreateSwitchPort($SwitchPATH, "One_Port" , "A Switch Port to connect VM") if ($Status.ReturnValue -eq 0)
Enjoy! /Dung 5月13日 Hyper-V WMI Examples - Part XHyper-V Virtual Networks - Creating Private Virtual NetworksIn a previous post, I give you an overview of virtual networks and high-level steps to create virtual networks. Let's put it in practice today and show how to create a private virtual network. Steps to create a Private virtual network
Script$SW_Service = get-wmiobject –namespace root\virtualization Msvm_VirtualSwitchManagementService # Call CreateSwitch $Status = $SW_Service.CreateSwitch(“Private_Network”, “Guest only Virtual Network”, 1024, “”) if ($Status.ReturnValue -eq 0)
## Create a SwitchPort $Status = $SW_Service.CreateSwitchPort($SwitchPATH, "One_Port" , "A Switch Port to connect VM") if ($Status.ReturnValue -eq 0)
Enjoy! /Dung 5月12日 Hyper-V WMI Examples - Part IX
Hyper-V Virtual NetworksUp to now, we've spent a significant amount of time and blog entries to talk about virtual machines. Let's switch gear and discuss about virtual networks. Networking ConceptsIn Hyper-V, you create virtual networks and connect virtual network cards (NICs) of virtual machines to allow communications between the machines themselves, the host system and eventually the physical network. A virtual network, also called Virtual Switch can be one of the three following types: · Private: Virtual machines connected to this network can communicate between them. The host system has no connectivity with virtual machines · Internal: Virtual machines connected to this network can communicate between themselves and the host system. There is no connectivity with the physical network. · External: An external virtual network binds to the physical network adapter so that virtual machines as well as the host system can access the physical network. Virtual networks and connections of virtual machines to virtual networks are managed by a Hyper-V service called Virtual Switch Management Service. There is a WMI class associated to this service called Msvm_VirtualSwitchManagementService. Private Virtual NetworkWhen you create a private virtual network, the Virtual Network Manager Service running on the host system will create a Virtual Switch and allows you to connect virtual machines to this switch. The host system does not participate in this private network, as such, cannot communicate with virtual machines connected to it. This type of network is also known as "Guest-Only Network" or "Private Virtual Machine Network". The figure below shows a visual representation of a private virtual network.
Internal Virtual NetworkWhen you create an Internal virtual network, the Virtual Network Manager Service running on the host system will create: · A virtual network · A virtual NIC on the host system that will be connected to the virtual network. As such, all virtual machines connected to the Internal virtual network can communicate with the host system and vice-versa. It is important to note that existing physical network adapters are left untouched. The figure below shows a visual representation of an internal virtual network.
External Virtual NetworkWhen you create an External virtual network, you specify a physical network adapter for the virtual network to bind to. As a consequence, the Virtual Network Manager Service running on the host system will create: · A virtual network · A virtual NIC on the host system that will be connected to the virtual network The physical network adapter will then be connected to the virtual network. The latter will be acting as a router and allow both virtual machines and host system to connect to the physical network. Figure 3 illustrates the concept of an external virtual network. It's interesting to note that:
The figure below illustrates the concept of an external virtual network.
How to connect a virtual machine to a virtual network?Now that you understand the concept of virtual network, your next question would be to connect a virtual machine to a virtual network. Assume that your virtual machine already has a NIC and that you have created a virtual network, you will need to create a port on the virtual network, or to be exact, create a SwitchPort, and then associate this SwtichPort to a NIC by setting the Connection property of the NIC to the WMI Path of the SwitchPort. If your virtual machine does not have a NIC, you need to create one by duplicating the default instance of Msvm_SyntheticEthernetPortSettingData and perform the same operations as above. Overview of Msvm_VirtualSwitchManagementServiceThe Msvm_VirtualSwitchManagementService class is used to control the creation and configuration of virtual networks. As you can see from the explanations above, there are two distinct tasks in virtual networks management. First you create a virtual network and define its type – private, internal, external. Once the virtual network created, you then create ports on the switch for network connections. Second you connect virtual NICs (either from virtual machines or the host system) to a virtual network. The Msvm_VirtualSwitchManagementService class provides several methods to create virtual networks and configure its type. Creating a virtual network is very easy and consists of a single-step operation. To configure the type, you may need additional steps. Here is a high-level overview of steps to create and configure virtual networks. All the methods listed below come from the Msvm_VirtualSwitchManagementService class. Private Virtual Network
Internal Virtual Network
External Virtual Network
That's it! Until next time... /Dung |
|
|