Escolar Documentos
Profissional Documentos
Cultura Documentos
I.
DESCRIPTION
InventorySnapshot allows a user to "snapshot" a given vCenter inventory configuration and then
reproduce it.
To learn how to run InventorySnapshot, please go to section IV. To learn more about the fling, read
on
The "inventory" includes the Datacenter folders, datacenters, clusters, resource pools, vApps, hierarchy,
roles and permissions, configuration settings, and custom fields. In other words, if you have an inventory
with a given set of hosts and VMs organized into a group of clusters, we can faithfully reproduce this
environment, including the cluster settings and custom roles you may have defined.
As a simple example, suppose you have an inventory with one datacenter (DC A), one cluster (Cluster A),
and two hosts (Host A and Host B). At a high level, our fling emits a PowerCLI script that, when executed,
does the following:
1. Create Datacenter DC A.
2. Create cluster Cluster A.
3. Add host Host A to Cluster A.
4. Add host Host B to Cluster A.
Notice that this can be helpful for a variety of reasons. For example, suppose youve spent a lot of time
creating a development vCenter environment, and now you wish to deploy it in production. Using our
fling, you can snapshot your dev environment and then run it against the production vCenter server,
saving you the task of laboriously adding each host, creating the proper clusters and resource pools, etc.
II.
C. Assumptions
We make the following assumptions about an inventory:
1. VMs are already registered on their hosts.
2. Entity names (VMs, Folders, etc.) are unique within an inventory.
III.
BASIC OVERVIEW
This vCenter fling takes a snapshot of the vCenter inventory and creates a bunch of binary files to
describe this inventory and the configuration of the various entities (clusters, networks, etc.). More
importantly, it also creates a file called "createInventory.ps1." This is a PowerCLI script.
This PowerCLI script contains commands to re-create the inventory that you've just archived. Feel free
to take a look! It is important to note that re-creating most inventories requires adding hosts. As a
placeholder for the actual passwords of the hosts being added, our script generates -password
'PASSWORD' in the createInventory.ps1 script. Using the UI, we enable you to change the passwords
for each host. Of course, you can also open up the file in the editor of your choice and change them
yourself. Please note that for now, we store the PowerCLI script as a plaintext file, so your passwords are
cleartext. If there is sufficient demand, we can work on changing this.
Therefore, using our fling in the most basic way is a three-step process:
a. Snapshot the inventory using the UI.
a. In Windows, double-click on inventorySnapshot.bat to bring up the UI.
b. In Linux and MacOS, use the inventorySnapshot.sh shell script to bring up the UI.
b. Edit the createInventory.ps1 PowerCLI script so that the host passwords are correct. You can
do this using the UI, or you can manually edit the createInventory.ps1 file using your
favorite text editor. Just search for 'PASSWORD' to see where you need to input the proper
passwords. If you use the UI, the file is saved as createInventory-PasswordModified.ps1.
c. Login to a vCenter server using the PowerCLI, change into the directory that contains the
createInventory.ps1 script, and just type .\createInventory-PasswordModified.ps1. If you
edited the script by hand and saved it as createInventory.ps1, then type
createInventory.ps1 instead.
IV.
1. We assume you are running this on Windows. For Linux or MacOS users, the steps are almost
exactly the same, except you will use inventorySnapshot.sh instead of inventorySnapshot.bat, and
you will have to copy the generated PowerCLI files to a Windows host to run them.
2. Download the zip file from the web site. Let's call this "inventorysnapshot.zip."
3. When you unzip this file, you'll see a directory called inventorysnapshot. We will assume that you
have downloaded this in C:\, so that the full path is C:\inventorysnapshot\.
4. If you go into this directory, you will see a file called inventorySnapshot.bat. Double-click on this file
(or just run it from the command-line) and a UI will appear (see Figure 1).
Figure 1: Login screen for InventorySnapshot UI. Use "inventorySnapshot.bat" (or inventorySnapshot.sh in Linux/MacOS) to
get this screen.
6. Once you have filled in these 4 fields, click on the Take Snapshot button. After some time
(depending on the size of the inventory), a new screen will appear, as seen in Figure 2.
Figure 2: InventorySnapshot output. After InventorySnapshot has snapshotted an inventory, this tabbed view appears. The
tabbed view contains the generated PowerCLI code and tabs for changing passwords and selecting portions of inventory to
restore.
7. This tabbed view has 4 screens. The default screen (PowerCLI Code) shows the PowerCLI code that
was generated by the InventorySnapshot application after clicking Take Snapshot from the login
screen. This screen is not editable, but you can scroll through it to take a look at the code that has
been generated to recreate your inventory. This code is also written to a file called
createInventory.ps1 in the destination directory that you specified in step 5.
8. If you click on the Host Information tab at the top of the screen, you will see a new screen that will
let you edit the passwords in the PowerCLI file and save this edited PowerCLI into a new file. The
Host Information tab is shown in Figure 3.
Figure 3: The Host Information tab. This view allows the user to edit generated PowerCLI file so that it has the proper host
passwords.
10. After editing the passwords and clicking Commit changes, a dialog box shows up to indicate that a
file named createInventory-PasswordModified.ps1 has been created in the destination directory
that you specified.
11. Next, you can click on the Inventory Tree tab to see an overview of your inventory. This overview
will be similar to the view you can see in the UI client, but it may have some extra elements (like
default host folders) that are typically hidden in the VI client, as you can see in Figure 4.
Figure 4: Inventory Tree View. The Inventory Tree shows you the inventory of the vCenter that you have just snapshotted,
including some extra folders that are typically hidden in the VI client.
12. By default, when you clicked on Commit changes in the Host Information tab, our
InventorySnapshot UI created a PowerCLI file named createInventory-PasswordModified.ps1. This
file allows you to recreate an entire inventory. If you would like a script that recreates an individual
datacenter, you can do this from the Inventory Tree view. To do this, click on the datacenter in the
Inventory Tree view, make sure all elements beneath it are selected (this is typically accomplished
by minimizing the datacenter and then clicking on its checkbox), and then click on Commit
changes at the bottom of the screen. A screenshot of the UI when a given datacenter (in this case,
AppCloud) has been clicked is shown in Figure 5.
Figure 5: Inventory Tree View with a specific datacenter selected. After selecting a datacenter and clicking on "Commit
changes", you can go to the "Generate New PowerCLI Code" tab to create a file to reproduce this datacenter.
13. Once you have clicked on Commit changes, a confirmation dialog box comes up. This box tells you
all of the datacenters that you have selected as well as all of the clusters underneath those
datacenters. In this case, the AppCloud datacenter was selected, and it has one cluster inside
called AppCloudCluster. See Figure 6.
Figure 6: Dialog box showing selected datacenter and the clusters it contains. When you go to the "Generate New PowerCLI
Code" tab and hit "Generate PowerCLI Code", PowerCLI files for this datacenter and its cluster will be created.
14. Next, please click on the Generate New PowerCLI Code tab, shown in Figure 7.
Figure 7: Generate New PowerCLI Code tab. When you click on the "Generate PowerCLI code" button, PowerCLI files for
restoring the inventory and the datacenters you've selected will be generated.
15. On the Generate New PowerCLI Code tab, click on the Generate PowerCLI code button. For our
example, since we selected a datacenter, and that datacenter has 1 cluster, we will see 3 dialog
boxes.
a. createInventory-PasswordModified.ps1: a PowerCLI script to reproduce the entire
inventory.
16. You can now take these PowerCLI files, connect to the same or to a different vCenter server using
the PowerCLI, and then execute these scripts.
a. If you want to reproduce the entire inventory, use createInventory-PasswordModified.ps1.
b. If you want to reproduce just a single datacenter, use createInventory-DatacenterAppCloud.ps1 (assuming the datacenter is named AppCloud).
c. If you want to reproduce just a single cluster, use createInventoryClusterComputeResource-AppCloudCluster.ps1 (assuming the cluster is named
AppCloudCluster).
Important note: the InventorySnapshot UI runs on Linux, MacOS, and Windows, but PowerCLI only
runs on Windows. So if you run InventorySnapshot on Linux or MacOS, you will have to copy the
generated PowerCLI files to a Windows host in order to run them.
To run the script, follow these steps:
a. Start up the PowerCLI, connect to the vCenter server that youd like to archive (connectviserver <serverName>, and change directory (cd) into the directory with the inventory snapshot
PowerCLI files. In the next 3 steps (b, c, and d), we assume you want to create this inventory on an
entirely new vCenter server named vcenter.mydomain.com and that youve saved the PowerCLI
files in the directory called C:\tmp\10.115.147.115-733pm.
b. [vSphere PowerCLI ]> connect-viserver vcenter.mydomain.com.
(<you will be prompted for a username and password>)
c. [vSphere PowerCLI]> cd C:\tmp\10.115.147.115-733pm\
d. [vSphere PowerCLI]> createInventory-PasswordModified.ps1
17. To exit the UI, click on the X at the top right of the screen. Sorry, we havent added a menu-driven
interface for exiting yet.
V.
At present, we generate PowerCLI code in order to reproduce an inventory. As a result, this generated
code can only be run on Windows. However, to generate the PowerCLI code, you can use Linux,
Windows, or MacOS. If you look at the generated code before youve used the UI to modify the
passwords (lets say createInventory.ps1), the file looks something like this:
# ### START RESTORE DC: Empty DC 3
# ### START CREATE DC: Empty DC 3
# Create DC: Empty DC 3 in folder: null
$folder = Get-Folder -NoRecursion
New-Datacenter -Location $folder -name "Empty DC 3"
# ### END CREATE DC: Empty DC 3
# ### START CREATE FOLDER: DC Folder 1
# Create Datacenter Folder DC Folder 1
$parentFolder = Get-Folder -NoRecursion
New-Folder -name "DC Folder 1" -Location $parentFolder
1. The lines that begin with # ### START or # ### END are called markers. We use these
comments to help you understand what the code is doing. For example, the above snippet is
creating a datacenter named Empty DC 3 and creating a datacenter folder named DC Folder
1.
2. In recreating an inventory, you will invariably have to add hosts. You will see lines like these in
the createInventory.ps1 script:
Add-VMHost 10.115.144.34 -Location $cluster -user root -password
'PASSWORD' -Force
Using the UI, you can edit the passwords for each host accordingly. This creates a file called
createInventory-PasswordModified.ps1. Alternatively, you can edit this file by hand to replace
PASSWORD with the appropriate password for that host. You will have to do this for each host
in the file.
VI.
<lots of code>
# Get Authorization Manager
$_this = Get-View -Id AuthorizationManager-AuthorizationManager
# Set permissions
$_this.SetEntityPermissions($entityMoRef,$permission)
# ### END UPDATE ROLE_PERM: ALL
The code between the markers ### START UPDATE ROLE_PERM: ALL and ### END UPDATE
ROLE_PERM: ALL restores permissions and roles. In theory, if you just copied this code to a separate
PowerCLI file and then ran it on the destination server, you could reproduce roles and permissions on
the destination. However, there are some important caveats:
1. You must have the same users and groups (from Windows) installed on the destination server
before you run this PowerCLI code. If restoration of roles and permission does not work, please
make sure that the users and groups on the source vCenter server are present on the
destination vCenter server.
2. The code that weve generated is extremely slow and very general. For example, it tries to
restore all permissions (including the standard permissions that are included in every vCenter
installation). This may result in some benign errors in which our PowerCLI code tries to restore
roles that already exist. If you see errors like the following when you run the script, it is likely
due to this issue, and these errors can be safely ignored:
Exception calling "SetEntityPermissions" with "2" argument(s): "The requested
change cannot be completed because it could leave the system without full
administrative privileges for a user or group."
At C:\tmp\10.115.147.115-656pm\createInventory-Datacenter-AppCloud.ps1:1187
char:28
3. There are certainly faster ways to do this. We have not worked on optimizing this code yet.
E. Restoring RP settings
To restore a resource pools settings (for example, after disabling DRS in a cluster), we recommend you
simply execute the steps above for Restoring DRS cluster settings (specifically, step 1 within that
section). Namely, you snapshot the inventory, disable DRS, and then execute createInventoryClusterComputeResource-ABC.ps1 to recreate the cluster. Note that when recreating a cluster, the
PowerCLI code will attempt to create a cluster (using New-Cluster) and then add hosts (using AddVMHost). Sample errors are shown below. Both of these operations will fail simply because the cluster
already exists and the hosts are already added. Under these circumstances, these errors can be safely
ignored.
New-Cluster : 4/30/2011 10:40:00 PM
New-Cluster
The name 'haCluster'
already exists.
At C:\tmp\vCenterA\createInventoryClusterComputeResource-haCluster.ps1:7 char:12
+ New-Cluster <<<< -Location $folder -Name "haCluster" -DRSEnabled -DRSMode
FullyAutomated
+ CategoryInfo
: NotSpecified: (:) [New-Cluster], DuplicateName
+ FullyQualifiedErrorId : Client20_ComputeResourceServiceImpl_CreateCluste
r_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewCluster
There is one more error you might see throughout the PowerCLI output. The following error is simply
an artifact of how our code is implemented and is benign, so you can safely ignore it. It occurs most
frequently when restoring Resource Pools, though it may occur in other contexts (in each case, it is
benign and can be ignored):
The term 'null' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At C:\tmp\vCenterA\createInventory-ClusterComputeResource-haCluster.ps1:438 char:51
+ $myRPConfigSpec.CpuAllocation.OverHeadLimit = null <<<<
+ CategoryInfo
dException
+ FullyQualifiedErrorId : CommandNotFoundException
The PowerCLI between these markers shows you how to save and restore custom fields in PowerCLI. If a
custom field already exists, PowerCLI will emit a benign error that looks like this:
Exception calling "AddCustomFieldDef" with "4" argument(s): "The name 'Application
Name' already exists."
At C:\tmp\vCenterA\createInventory-PasswordModified.ps1:1463 char:26
+ $cfView.AddCustomFieldDef <<<< ("Application Name", "VirtualMachine", $fdp, $
fip)
+ CategoryInfo
+ FullyQualifiedErrorId : DotNetMethodException
This error simply indicates that the custom field definition already exists. It can be ignored.
<lots of code>
# ### END CREATE DVS: <dvs name>
# ### START UPDATE DVS: <dvs name>
<lots of code>
# ### END UPDATE DVS: <dvs name>
# ### START UPDATE DVPortgroup: <portgroup name>
<lots of code>
# ### END UPDATE DVPortgroup: <portgroup name>
There are almost certainly more efficient ways to perform this operation. We hope to make this faster in
future releases.
VII.
CAVEATS/KNOWN BUGS
C. SPECIAL CHARACTERS
Please avoid special characters (except -, which is fine) in the names of your VMs, etc. This may cause
the script not to work properly. Also, if you have # in your passwords, the PowerCLI scripts might have
unpredictable behavior.
VIII.
Basic troubleshooting