1. Trang chủ
  2. » Công Nghệ Thông Tin

ADVANCED SERVER VIRTUALIZATION VMware and Microsoft Platforms in the Virtual Data center phần 9 docx

72 418 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 72
Dung lượng 1,1 MB

Nội dung

589 Chapter 25 Scripting with Microsoft Virtual Server, VMware GSX Server and ESX Server Where the consumer versions of Microsoft Virtual PC and VMware Worksta- tion come with command line control, no such simplicity is available with the virtualization server products. Virtualization server control is achieved through the graphical user-interfaces or programming.  ere is a lot of sample source code that either comes bundled with the products or is downloadable from the vendor support site; however this does not mean that all critical information is covered in detail. VMware provides their sample scripting examples installed with their products and Microsoft has a support site dedicated to scripting Vir- tual Server. Rather than reiterating what is bundled with the products, this chap- ter is taking a real-world need like performing backups of virtual machines and presents a walk-through on how to accomplish that task with each of the script- ing application programming interfaces (APIs). Getting Started with Application Programming Interfaces (APIs)  e starting point in writing a script or “scripting” any application is to fi nd out what language bindings are provided to drive the product’s automation facili- ties. Sometimes it is a built-in scripting language, other times it is a static or dy- namically loaded native library or a managed programming assembly or interop library like for a Microsoft .NET service. In the case of Microsoft Virtual Server and VMware GSX Server on Windows their scripting interfaces are driven by a Component Object Model (COM) library that is registered with Windows Marshall_AU3931_C025.indd 589Marshall_AU3931_C025.indd 589 4/13/2006 1:58:15 PM4/13/2006 1:58:15 PM 590  Advanced Server Virtualization upon product installation. For VMware ESX Server its scripting interface is driven by Perl version 5.6 integration modules. Since both vendors’ virtualiza- tion product APIs on Windows are written in COM, they are easily accessible through Visual Basic scripting, VBScript. For complex automation and complex data structure manipulation it is necessary to use an integrated development environment (IDE) and either the Visual Basic or C++ programming language, however for simplicity and ease of use the examples used in this chapter will be based on VBScript. The VMware Application Programming Interface VMware refers to their APIs as VmCOM and VmPerl named after the bindings they are implemented with respectively.  e programmable objects in VmCOM are registered under the ProgId VMComLib.*. For ESX Server or GSX Server on Linux, the underlying API bindings are written in Perl version 5.6 modules. VMware provides both VmCOM and VmPerl access on Windows and only VmPerl on Linux since COM is not available. Figure 25.1 contains the high- level interfaces used to access specifi c VMware functionality.  e defi nitive reference guide for these interfaces is provided in a document entitled VMware Scripting API Guide (Adobe PDF format).  e latest Script- ing API guide is available on VMware’s Web site at http://www.vmware.com/ support/developer/scripting-API. VMware VirtualCenter Infrastructure Software Development Kit (SDK) In addition to the host-level scripting APIs, VMware also publishes a set of high-level Web Services interfaces to manage an entire data center installation of GSX Server and ESX Server called the VMware Virtual Center Infrastructure SDK.  e Virtual Center Infrastructure SDK is not as easily scriptable and uses a Common Information Model (CIM)-based object and data model for each host, virtual machine, and guest it manages. It is possible to script the Virtual Center Infrastructure SDK using any client that can interpret a Web Services Defi nition Language (WSDL) specifi cation. WSDL automation is available Interface Name Manages VmConnectParams Connecting to virtual machines Vm ServerCtl Operations for all virtual machines VmCollection General collections of VMware objects VmCtl Operations for a specifi c virtual mahine VmQuestion Virtual server status and interactive management prompts Figure 25.1 High-Level VMware Interfaces. Marshall_AU3931_C025.indd 590Marshall_AU3931_C025.indd 590 4/13/2006 1:58:17 PM4/13/2006 1:58:17 PM Scripting with Microsoft Virtual Server, VMware GSX Server and ESX Server  591 through a WS-* compatible Perl library but is usually done from a Java2 or .NET integrated development environment.  e Virtual Center Infrastructure SDK is beyond the scope of this chapter but the off ering demands additional investigation if systems management of virtual machines on a site-wide deploy- ment scale is important. The Microsoft Virtual Server 2005 Application Programming Interface  e Microsoft Virtual Server API is called the Microsoft Virtual Server 2005 COM API and is registered in the COM registry under its ProgId “VirtualServ- er.Application.”  e Virtual Server COM API is a rich set of interfaces that handles host and guest OS device and power state management, monitoring, and control. In fact the entire Web-based Virtual Server Administrative Console is a natively built Web server CGI component that uses the COM API exclu- sively to manage Virtual Server. Anything that is possible via the Web interface is scriptable by programming.  e API contains a few options that are not exposed through the Web interface and that makes it a bit more powerful than the user interface such as creating virtual machines and virtual networks in arbitrary path locations. For reference, the complete set of interfaces in the Virtual Server API are listed in Figure 25.2, Figure 25.3, and Figure 25.4. Microsoft Virtual Server 2005 COM Interfaces  e starting point to managing all of the Virtual Server 2005 interfaces is the IVMVirtualServer interface. IVMVirtualServer has many methods that return Interface Name Manages IVMAccessRights User and Group Access Rights: accounts and IVMAccessRightsCollection permissions for accessing Virtual Server IVMAccountant CPU scheduling, disk and network i/o counters and VM uptime IVMDHCPVirtualNetworkServer DHCP parameters for virtual networks IVMDisplay Dimensions, video mode and thumbnail of guest OS displays. IVMDVDDrive Collection of and specifi c CD/DVD device media IVMDVDDriveCollection connected to a host drive or captured virtual media and IVMDVDDriveEvents insertion/removal of media event notifi cation. IVMFloppyDrive Floppy device media connected to a host drive or IVMFloppyDriveCollection captured virtual media and insertion/removal of IVMFloppyDriveEvents media event notifi cation. Figure 25.2 Virtual Server General Security and Removable Media Interfaces. Marshall_AU3931_C025.indd 591Marshall_AU3931_C025.indd 591 4/13/2006 1:58:17 PM4/13/2006 1:58:17 PM 592  Advanced Server Virtualization Figure 25.4 Virtual Server Host, Virtual Machine Events, and Network Interfaces. IVMGuestOS Guest OS services: Heartbeat, time synchronization, VM Additions and orderly OS shutdown. IVMHardDisk Collection of and specifi c virtual Hard Disk fi les IVMHardDiskConnection of IDE and SCSI disks, including Undo disks. IVMHardDiskConnectionCollection IVMHostlnfo Detailed CPU, memory, OS, networking, serial and parallel ports and removable devices of the host system. IVMKeyboard Simulation of typing keys in a Guest OS. IVMMouse Guest OS mouse status and simulation of button and mouse clicks. IVMNetworkAdapter Collection of and characteristics of virtual network IVMNetworkAdapterCollection adapter cards. IVMParallelPort Collection of and characteristics of the virtual IVMParallelPortCollection parallel port (LPT). IVMRCAuthenticator Collection of and enumeration of supported IVMRCAuthenticatorCollection Authentication methods over the VMRC remote console interface. IVMSCSIController Collection and parameters of the virtual SCSI IVMSCSIControllerCollection controller cards including bus sharing. IVMSecurity Applies fi ne-grain security controls over Virtual Server objects. IVMSerialPort Collection of and characteristics of the virtual IVMSerialPortCollection serial ports. IVMSupportDriver Collection of and enumeration of support drivers IVMSupportDriverCollection installed on the host system. IVMTask Collection of and enumeration of task status for long IVMTaskCollection running operations like merging undo disks or starting up a virtual machine. Figure 25.3 Virtual Server Guest OS Interfaces. IVMVirtualMachine Collection of and top-level managing objects and events IVMVirtualMachineCollection for a Virtual Machine. IVMVirtualMachineEvents IVMVirtualNetwork Collection of and enumeration of physical and virtual IVMVirtualNetworkCollection networks that virtual network adapters are connected to. IVMVirtualServer Collection of and top-level managing objects and events IVMVirtualServerEvents for Virtual Server 2005. Marshall_AU3931_C025.indd 592Marshall_AU3931_C025.indd 592 4/13/2006 1:58:17 PM4/13/2006 1:58:17 PM Scripting with Microsoft Virtual Server, VMware GSX Server and ESX Server  593 concrete instances of all other interface types. Next to IVMVirtualServer, the object accessed the most frequently is IVMVirtualMachine and in turn the IVMGuestOS object is used to manage such operations as graceful guest OS shutdowns. Controlling a Virtual Server Through Scripting  e preceding sections described the APIs and their access interfaces, this section will apply the APIs in a useful exercise. Each of the APIs organizes the controls over virtual servers into a set of interfaces and objects representing the virtual server application, a virtual machine, and many of its attached virtual devices. As virtual machines are created, each virtualization platform builds collections of objects that compose a complete state of the host installation. In addition to the basic objects, the control of the virtual machine breaks down further into a fam- ily of related operations like power state management (e.g., turning the virtual machine on, off , or suspending it) and virtual device management—changing the state of the attached virtual hard disks, CD/DVD-ROM media and virtual networking (e.g., connecting and disconnecting media or networking access). As calls are made into API methods or to update the state of virtual server objects, the calls are actually updating either the underlying virtual machine confi gura- tion or the internal running states of the virtualization platform. In many cases scripting API invocations are manipulating the same control methods that the graphical user-interfaces of Microsoft Virtual Server and VMware are. Because scripting is another aspect of controlling a virtualized server, confl ict is avoided by controlling the server through the graphical user-interface or through scripting, these are mutu- ally exclusively.  is means that only one control method can be used at a time, not both simultaneously. What happens if the exclusivity rule is not followed? A change in one control method aff ects the internal state of other controlling environments. In other words there is no proper arbitration or brokering. While the graphical user-interfaces are generally status refl ecting point-and- click tools, scripts are usually not and are not expecting their basic assumptions to be disrupted by changes by the virtualization platform GUIs. It is safest to run a script on a virtual machine when the graphical user interface is not run- ning. Where this is unavoidable, do not have virtualization management screens active for the same machines accessed through scripting automation. Even if the GUI is running an “observation mode” and not changing a virtual machine’s confi guration, the GUI and script sometimes have to have locking access to the Marshall_AU3931_C025.indd 593Marshall_AU3931_C025.indd 593 4/13/2006 1:58:17 PM4/13/2006 1:58:17 PM 594  Advanced Server Virtualization underlying object resources, which are not designed to be shared.  e locking prevents either control method from obtaining the write-exclusivity required to change makes.  ese types of locking errors are diffi cult to debug and diag- nose or worse resolve themselves, which just leads to user frustration and testing problems. Programming References Are a Key to Success  ere is a saying, “Sometime you don’t know, what you don’t know.”  is most certainly applies to scripting.  ere are a lot of possible dead ends and road- blocks than can be run into, this is why it is critical to have technical refer- ences available. With this in mind, it is important to become familiar with the programming references for the virtual server product(s) that are going to be scripted against. For Microsoft Virtual Server the main source of reference is the “Virtual Server Programming Guide” in the Virtual Server Start menu group and available code examples in Microsoft’s Script Center Repository at http:// www.microsoft.com/technet/scriptcenter/scripts/default.mspx.  e Program- ming Guide is the ultimate reference for every object, method, property, con- stants, and enumerations.  e Script Center Repository is a collection chocked full of sample code and best practices that provide just enough information to cobble together a solution or to get familiar with subtle details on a particular operation like shutting down a virtual machine. For VMware GSX Server and ESX Server the choice is installing the Script- ing API and downloading the latest documentation from VMware at http:// www.vmware.com/support/developer/scripting_download.html. If the API is installed, the sample scripts are in \Program Files\VMware\VMware VmCOM Scripting API\SampleScripts. As with most references it is unnecessary to read them cover-to-cover. It is only necessary to index and search through the refer- ences as needed. Real-World Scripting: Backing up Virtual Machines Now armed with all the information and references needed, the best way to learn is by writing a script that is not only useful, but used on a regular basis to solve a problem. One of the most common problems with running virtualization is that the diffi culty of backing up the environment is multiplied by an order of magnitude, because now instead of just backing up the host, the backup must include all of the virtual machines.  ese virtual machines represent running machines themselves, so to just backup the host is not enough to have the virtual machines covered. Backing up running virtual machines is a challenge because the virtual machine hard disk fi les are large and open or “in use.”  is is further compounded by the fact that the content state of the virtual machine is chang- ing while you are backing up. Assuming there is a maintenance window for each Marshall_AU3931_C025.indd 594Marshall_AU3931_C025.indd 594 4/13/2006 1:58:17 PM4/13/2006 1:58:17 PM Scripting with Microsoft Virtual Server, VMware GSX Server and ESX Server  595 virtual machine, it is better to take that machine temporarily out of service, back it up, and then fi nally start it again.  at sounds easy but virtual machines can be in various power states of operation like turned off , suspended, or running. Backups should not be disruptive, so the expectation is to backup a single virtual machine at a time and leave it in the same state as it was before the backup took place. If a virtual machine were on, it is expected to be able to safely shutdown the guest operating system and back up the virtual machine fi les, then restart the machine. Finally, to minimize downtime the scripting APIs have special access to features of virtualization like undoable disks or redo logs that allow capturing changes to a snapshot of the virtual hard disk while it is running. In other words, virtual machine backups can minimize downtime if a backup creates a runtime redo log or undoable drive that allows the base disk to be backed up with a consistent disk state (meaning no writes are occurring to the base disk during backup, because it is in a read only mode). After the backup, the virtualization platforms can merge any changes made briefl y during the backup and continue.  e advantage of this fl exibility is that downtime is minimized to that virtual machine’s backup time. It does not always require a restart to enable a layer of diff erencing disk or merge the diff erences once a backup is complete, assuming the write changes during the backup are reasonably small (a few hundred MBs at most). Security and Microsoft Virtual Server As part of Microsoft’s Trustworthy Computing Initiative, Microsoft performed a comprehensive security audit of Virtual Server API and the access methods need- ed to invoke it. To simplify the scripting code, if Distributed COM (DCOM) allows remote scripting of Virtual Server it is easiest to set the authentication and impersonation defaults in the dcomcnfg MMC snap-in to “Connect” and “Im- personate” respectively. Without these changes, additional programmatic COM security initialization using COM’s CoInitialize and CoInitializeSecurity with principal identity (log-in) information is required to run these scripts.  ose additional security modes are not covered in this chapter. Backing Up Microsoft Virtual Server  e backup strategy here is to access Virtual Server and get a list of registered virtual machines, for each virtual machine, obtain its pre-backup power state, shutdown the machine if is running, then defer the backup of the virtual ma- chine fi les themselves to the preferred backup method and resume the operation of the virtual machine in the same power state as before the backup.  e main takeaway here is to not simply shutdown all virtual machines, back them up Marshall_AU3931_C025.indd 595Marshall_AU3931_C025.indd 595 4/13/2006 1:58:17 PM4/13/2006 1:58:17 PM 596  Advanced Server Virtualization and power on without regard to their initial state.  is would be problematic if you do not have the host capacity to run all registered machines simultaneously. Below is the code to do this: ‘Enable error handling On Error Resume Next ‘Instantiate a Virtual Server COM API object Set objVS = CreateObject(“VirtualServer.Application”) ‘Get a collection of all virtual machines Set colVMs = objVS.VirtualMachines ‘Iterate through the collection of virtual machines For Each objVM in colVMS ‘objVM is the currently selected VM from the collection ‘Get the current VM’s power state and save for later Set objPowerState = objVM.State If (Not objPowerState = vmstate_Off Then ‘The VM is ON, request a shutdown ‘if VM Additions are installed Set objGuestOS = objVM.GuestOS If (Not objGuestOS is Nothing) Then ‘We have VM Additions, request a graceful shutdown Set ShutdownTask = objGuestOS.Shutdown() ‘Wait for the Guest to shutdown ShutdownTask.WaitForCompletion() Else ‘One choice is to powerdown the VM to ‘prevent virtual disks from changing objVM.TurnOff() ‘Another possibility is to Save the VM State Set SaveTask = objVM.Save() SaveTask.WaitForCompletion() End If End If ‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’ ’’’ ‘Backup the fi les using your preferred backup method ‘ ‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’ ’’’ ‘Recall the original power state and restore it If (Not objPowerState = vmstate_Off Then Marshall_AU3931_C025.indd 596Marshall_AU3931_C025.indd 596 4/13/2006 1:58:17 PM4/13/2006 1:58:17 PM Scripting with Microsoft Virtual Server, VMware GSX Server and ESX Server  597 ‘ The machine was running before the backup, resume operations If (objPowerState = vmstate_Running) Then ‘This will startup or unsave a virtualm machine Set StartupTask = objVM.Startup() ‘This is optional. Comment out to speed up backups StartupTask.WaitForCompletion() End If End If Next Backing Up VMware GSX Server To backup GSX Server, fi rst the VMware inventory of virtual machines must be accessed and a list of registered virtual machines must be gotten.  en for each virtual machine, obtain its pre-backup power state and shutdown the machine if it is running. Next, defer the backup of the virtual machine fi les themselves to the preferred backup method and resume the operation of the virtual machine in the same power state as before the backup.  e main takeaway here is to preserve the initial state all virtual machines. If this was not done and all machines were powered on simultaneously, then the host could run out of capacity when trying to run all registered machines simultaneously. ‘Instantiate GSX Server vmCOM API objects Set cp = CreateObject(“VmCOM.VmConnectParams”) Set server = CreateObject(“VmCOM.VmServerCtl”) ‘Connect to GSX Server server.Connect cp ‘Get a collection of all virtual machines Set vmCollection = server.RegisteredVmNames ‘Iterate through the collection of virtual machines For each vmName in vmCollection ‘Instantiate a vmCOM Control object Set vm = CreateObject(“VmCOM.VmCtl”) s = “path=” & vmName On Error Resume Next ‘ Clear error object ‘Connect to this virtual machine by path vm.Connect cp,vmName If err.Number = vmErr_VMBUSY Then ‘Include warning s = s & “ UNAVAILABLE (controlled by local console)” Marshall_AU3931_C025.indd 597Marshall_AU3931_C025.indd 597 4/13/2006 1:58:18 PM4/13/2006 1:58:18 PM 598  Advanced Server Virtualization ElseIf err.Number <> 0 Then ‘If not busy get error s = s & “ ERROR CONNECTING desc=’” & err. Description & “’” Else ‘Reset error control, making errors fatal past this point On Error Goto 0 s = s & “ state=” & State2Str(vm) & “ os=” & _ vm.Confi g(“guestos”) ‘Check to see if a vmQuestion is pending against ‘the virtual machine If vm.ExecutionState = vmExecutionState_Stuck Then ‘Retrieve the question and answer choices Set q = vm.PendingQuestion Set choices = q.choices s = s & “ question= ‘” & q.text & “’ choices=” For each choice in choices s = s & “[“ & choice & “] “ Next ‘Check for redo log questions Set r = new RegExp r.pattern = “undoable disk” r.ignorecase = True Set matches = r.Execute(q.text) If matches.count > 0 Then ‘Check for OK or redo log answers in choices For i = 1 to choices.count If choices(i) = “Append” Or _ choices(i) = “Keep” Or _ choices(i) = “OK” Then WScript.Echo(s) s = “ > Automatically “ _ & “selecting ‘” & q.choices(i) vm.AnswerQuestion q,i Exit For End If Next End If End If Marshall_AU3931_C025.indd 598Marshall_AU3931_C025.indd 598 4/13/2006 1:58:18 PM4/13/2006 1:58:18 PM [...]... up and the iSCSI Initiator is installed, point the initiator at the target and setup the quorum Virtual to Physical Clustering using GSX Server Virtual to Physical clustering using GSX Server is configured using iSCSI in the same fashion that Virtual to Virtual clustering is setup and installed The only exception to this is the use of a physical machine in place of a second virtual machine for the other... useful in creating simple batch files to perform these functions (powering off, starting, suspending, and resuming virtual machines) To power off the virtual machine, the suspend batch file should include the following line: vmware- cmd \.vmx stop Once the virtual machine is powered off, the backup agent can safely begin backing up the virtual machine’s directory and files Once the. .. Marshall_AU 393 1_C026.indd 618 4/13/2006 2:01:31 PM Other Advanced Topics Active Passive Virtual Machine 1 Virtual Machine 1 Passive Active Virtual Machine 2 Virtual Machine 2 Active Passive Virtual Machine 3 Virtual Machine 3 Passive Active Virtual Machine 4 Virtual Machine 4 Active Passive Virtual Machine 5 Virtual Machine 5 Server1 Figure 26.2 6 19 Server 2 Clustered Virtual Machines on Two Physical Servers... Function Backing Up VMware ESX Server The backup strategy in this case is similar to VMware GSX Server, which is to the VMware inventory of virtual machines must be accessed and a list of Marshall_AU 393 1_C025.indd 599 4/13/2006 1:58:18 PM 600 Advanced Server Virtualization registered virtual machines must be gotten Then for each virtual machine, obtain its pre-backup power state and shutdown the machine if... the other clustered node as the heartbeat • Configure the third network card as the remote disk network (this network should point to the iSCSI target that will house the quorum and any shared data disks) • Install Windows Server 2003 Enterprise or Windows 2000 Advanced Server on the virtual machine Marshall_AU 393 1_C026.indd 6 19 4/13/2006 2:01:31 PM 620 Advanced Server Virtualization • Install the Microsoft. .. from the virtual machine instance undef $vm; } } # Destroy the server object and disconnect from the host server undef $server; Summary Scripting is important in automating many of the daily operations when leveraging virtualization To prepare to write scripts involving virtualization, a familiar- Marshall_AU 393 1_C025.indd 602 4/13/2006 1:58:18 PM Scripting with Microsoft Virtual Server, VMware GSX Server. .. pulling the Marshall_AU 393 1_C026.indd 608 4/13/2006 2:01: 29 PM Other Advanced Topics 6 09 power cord from the back of the server When the virtual machine is powered on, it may or may not boot If the virtual machine does boot, there is still some chance that the data may be corrupted in some form If a virtual machine is going to be moved from one host server to another, it is safer to power down the virtual. .. to virtual • Ensure that the virtual machine has two virtual network adapters, if it does not, add an additional network adapter Microsoft Virtual Server Virtual to Virtual Clustering Microsoft Virtual Server is configured identically to VMware s GSX Server However, Virtual Server will support clustering only when the host is running Microsoft Windows Server 2003 Enterprise Edition The virtual machine... that of the GUI-based interfaces Utilizing scripting is a necessity when using virtualization in any large scale deployments Marshall_AU 393 1_C025.indd 603 4/13/2006 1:58:18 PM Marshall_AU 393 1_C025.indd 604 4/13/2006 1:58:18 PM Chapter 26 Other Advanced Topics Building upon the information presented up to this point, this chapter introduces advanced topics including backing up and restoring virtualization. .. server with the assurance that it will register and function just as it did on the host server on which it was backed up Keep in mind that virtual disk files should not (typically) be backed up while the virtual machine is powered on When the virtual machine is powered on, the base disk file is open and being written to by the virtual machine In most cases, powering off or suspending the virtual machine . for the virtual server product(s) that are going to be scripted against. For Microsoft Virtual Server the main source of reference is the Virtual Server Programming Guide” in the Virtual Server. 26 Other Advanced Topics Building upon the information presented up to this point, this chapter intro- duces advanced topics including backing up and restoring virtualization host servers and virtual. interfaces in the Virtual Server API are listed in Figure 25.2, Figure 25.3, and Figure 25.4. Microsoft Virtual Server 2005 COM Interfaces  e starting point to managing all of the Virtual Server

Ngày đăng: 08/08/2014, 21:21

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN