Aegis ‘Depot’ Activity – Hyper-V Integration Part 3 - Importing, Exporting, Renaming and Deleting Virtual Machines

Aegis ‘Depot’ Activity – Hyper-V Integration Part 3 - Importing, Exporting, Renaming and Deleting Virtual Machines

Welcome to Part 3 of Hyper-V Integration Activities for NetIQ Aegis.   This is a 4 part cool tool Activity Library which will introduce and extend the functionality with new activities in each part bringing the power of Aegis Automation to Hyper-V environments.

In Part 1 (here) I provided Aegis Activities to Find, View Details and Modify the Power State of Hyper-V Virtual Machines.

Part 2 (here) focused on Virtual Machine Snapshots - taking / applying / listing and deleting snapshots.

Part 3 adds on activities to Import / Export / Rename and Deleting Virtual Machines.

 

Export Virtual Machine

Exporting Virtual Machines serves many purposes in Hyper-V from having an offline copy of a Virtual Machine, migrating a Virtual Machine from one server to another or to perform a 'Clone' operation on the same Hyper-V server.  The 'Export Virtual Machine' activity along with the 'Import Virtual Machine' activity enables each of these functions.

Like all the other Hyper-V activities discussed so far, each of these activities use common connection parameters with some extra configuration specific to the activity.

For the export you need to specify the Virtual Machine to export, the Path to export the file to (on the Hyper-V server not Aegis Server!) and whether or not to also export state files including Disks and Snapshots.

11

Note the Virtual Machine needs to be in a powered down state before it can be exported or the activity will succeed but return a Result = False output along with a Failure message like : "Export virtual system failed with error InvalidState".  Remember you can check the Virtual Machine State using the 'Get VM Details' activity in advance.

Once a Virtual Machine has been exported it is ready to be copied to a new Hyper-V machine or Imported as a New Virtual back into the same system.  The Export Virtual Machine may take a long time to export depending on the size of disks and snapshots (if the Copy VM State option is selected).

 

Import Virtual Machine

So now we have exported a Virtual Machine successfully, next we want to import the Virtual Machine into Hyper-V again, on the same or different server.  For a different server you need to copy (can be done via workflow) the export files to a location accessible to the new server.   Remember that these activities are part of an overall solution, you will probably have some workflow logic which which requests the export/import process to run as well as steps between the export and import process like moving the export, validating the target Hyper-V server etc.

You need to specify the Path to import the Virtual Machine from (this path will contain sub-folders called 'Virtual Machines', 'Snapshots' and 'Virtual Hard Disks').

If you exported from the same Hyper-V server you will need to also select the 'generate new id' option as the existing ID will already exist (unless you have already deleted the original Virtual Machine).  It is probably good practice to enable this by default even if importing on a remote system as you may perform the same operation at a later point and wonder how you get a conflict.

22

The import process will usually complete successfully with warnings - generally warnings about devices which are likely to occur when importing a machine back to the same server.  You will probably see an output of the activity similar to this :

33

The corresponding event on the event viewer may look like this:

'sigea-test - (06/02/2015 - 10:14:25)': The file name '' is invalid. You cannot use the following names (LPTn, COMn, PRN, AUX, NUL, CON) because they are reserved by Windows. (Virtual machine ID B73223CF-C998-49B1-B796-57B66124633F)

 

Note that once you import a Virtual Machine, it cannot be re-imported as the import files are now in fact a registered Virtual Machine.  You need to perform one export for each import.

 

Hyper-V Activities Top Tip #2

Importing/Exporting will work best when Virtual Disks are stored with the Virtual Machine to prevent errors where files already exist.  For example if you keep all your Virtual disks separately at  C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\ then importing files may cause conflicts if a disk name already exists as it will attempt to copy the disk to the same location.

 

Rename Virtual Machine

Now that we have imported out Virtual Machine, you may find that 2 Virtual Machines exist with the same name - Unique names are not required.  In this case among others you will probably want to use the Rename Virtual Machine activity.

This is a very straight forward activity ... Just supply the virtual machine to rename and its new name and a simple Result True/False output with Information message.

When you search for Virtual Machines by name, they are listed in creation date order, oldest first.

44

 

Delete Virtual Machine

If you want to export / import a virtual machine on a single machine in order to relocate disks for example, or just for general cleanup procedure for old unused Virtual Machines, you will want to use the delete activity.

The activity functions in the same was as the Hyper-V console, when you perform the deletion Virtual Disks associated with the Virtual Machine are not deleted.  This needs to be noted if you plan to export a Virtual Machine with the same name to the same location as files will already exist.

55

Before a Virtual Machine can be deleted it must be in a powered off state.

 

Hyper-V Activities Top Tip #3

To find a virtual machines current state - is it powered on or off?  - use the Get VM Details activity and look at the 'Enabled State' output.  These are the main enabled states you are likely to see - for a full lists an explanations see the info on MSDN

Unknown - The state of the VM could not be determined.
Enabled - The VM is running.
Disabled - The VM is turned off.
Paused - The VM is paused.
Suspended - The VM is in a saved state.
Starting - The VM is starting.
Saving - The VM is saving its state.
Stopping - The VM is turning off.
Pausing - The VM is pausing.
Resuming - The VM is resuming from a paused state.

 

Hyper-V Activity Use Cases:

These activities bring the ability to automate more tasks in Hyper-V for example:

1. Automate Migration of Virtual Machines from one Hyper-V server to another

2. Move Virtual Machine data from one storage location to another on the same Hyper-V server.

3. Automate backup of Virtual Machines.

4. Keep Virtual Machine display names in sync with Virtual Machine Host names.

 

So there you go - watch out for Part 4 where I'll be adding on activities to work with automating VM Creation and modifying the number of CPUs and Startup RAM of Virtual Machines!

 

Activity Installation Instructions are here:

https://www.netiq.com/communities/cool-solutions/how-to-install-a-custom-depot-aegis-activity-from-netiq-cool-tools
Attachments

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2015-02-18 19:57
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.