Provisioning VMware Virtual Machines from EMCLI in less than 10 minutes

by bluemedora_editor on August 19, 2013

One of the recent additions to the Enterprise Manager plugin for VMware is the ability to manage your virtualized environment right from within Enterprise Manager (EM). Utilizing the powerful jobs framework of Enterprise Manager you can now clone existing VMware Virtual Machines or deploy your VMware Templates right from Enterprise Manager. This can save days, weeks, and sometimes even months of time by streamlining the process for requesting/acquiring resources for your virtualized Oracle workloads!

The integration with the EM jobs framework means that you can, in addition to cloning from within the plugin, clone VMware Virtual Machines or deploy Templates from the EM Jobs Library in the web console or from the command line utility EMCLI. This post will walk you through all the necessary steps to clone a VM using EMCLI.

A few pre-reqs:

  • The Enterprise Manager plugin for VMware must be deployed and a VMware Home target created.
  • Your version of Enterprise Manager 12c must be R3 in order to clone a VM from the EMCLI to work.
  • Default Preferred Credentials must be set on the VMware Home target type.
  • The VMware credentials used when adding the VMware Home target must have permissions to clone/edit the source Virtual Machine.
  • EMCLI must be installed and in your PATH variable.

Let’s jump right in!

1. First things first, we need to ssh into the OMS where the VMware plugin is deployed and ensure that EMCLI is in your PATH.

[user]@~$ssh oracle@em-oel6-demo
oracle@em-oel6-demo's password:
Last login: Fri Aug 16 14:55:15 2013 from 10.66.2.115
[oracle@em-oel6-demo ~]$ which emcli
/apps/oracle/oms/oms/bin/emcli

2. Next, log in to EMCLI.

[oracle@em-oel6-demo ~]$ emcli login -username=sysman
Enter password :
Login successful

3. Now we need to verify that we have the clone job available. Job #38, “vsphere_clone_vm”, is the job used to clone a VMware Virtual Machine as well as deploy from a Template.

[oracle@em-oel6-demo ~]$ emcli get_job_types
Following is the list of job types that can be used to create jobs or library jobs from EMCLI:
1. ASMSQLScript
2. BlockAgent
3. CoherenceCacheAddition
4. CoherenceNodesRefresh
5. Config Log Archive Locations
6. DbMachineDashboard
7. DiscoverPDBEntities
8. FusionMiddlewareProcessControl
9. GlassFishProcessControl
10. InstallKernelModuleJob
11. Log Rotation
12. OSCommand
13. OpatchPatchUpdate_PA
14. RMANScript
15. RefreshFromEMStore
16. RefreshFromMetalink
17. SOABulkRecovery
18. SQLScript
19. ShutdownDB
20. StartDepartedCohNodes
21. StartDepartedCohStoreNodes
22. StartupDB
23. StatspackPurge
24. Upgrade Exalogic Systems
25. WebLogic Control
26. WebLogic Domain Discover
27. host_enter_maintenance_mode
28. host_exit_maintenance_mode
29. vm_clone_vm
30. vm_delete
31. vm_power_off
32. vm_power_on
33. vm_reconfig
34. vm_reset
35. vm_restart_guest
36. vm_shutdown_guest
37. vm_suspend
38. vsphere_clone_vm
39. vsphere_delete_vm

4. Next, we need to know what parameters are available. For this we’ll use another EMCLI command and redirect the output to a file. We want to save the output to a file because we need to use the file as input for creating the job later on.

[oracle@em-oel6-demo ~]$ emcli describe_job_type -type=vsphere_clone_vm > /tmp/clone_properties.txt [oracle@em-oel6-demo ~]$ cat /tmp/clone_properties.txt

# Description: (Optional) The user specified name of the job
name=

# Description: (Optional) The job type for this job
type=vsphere_clone_vm

# Description: (Optional) The user specified description of the job
description=

# Description: The job owner. The job owner is the user who creates the job.
# Default: the logged in user
# The job owner information displayed here is for documentation only and user is not expected to change it.
owner=

# Description: (Optional) The kind of job
# Legal Values: active, library
kind=

# Fill in the target list before submitting.
# For Example:
# target_list=MyTarget:bm_vsphere
target_list=<target_name>:<target_type>

# Credential Usage: defaultHostCred
# Description:
cred.defaultHostCred.<target_name>:<target_type>=

# Description: (Optional) vsphere_clone_vm_5
variable.clonename=

# Description: (Optional) vsphere_clone_vm_9
variable.cluster=

# Description: (Optional) vsphere_clone_vm_29
variable.computername=

# Description: (Optional) vsphere_clone_vm_7
variable.datacenter=

# Description: (Optional) vsphere_clone_vm_15
variable.datastore=

# Description: (Optional) vsphere_clone_vm_25
variable.dnsserver=

# Description: (Optional) vsphere_clone_vm_31
variable.domain=

# Description: (Optional) vsphere_clone_vm_23
variable.gateway=

# Description: (Optional) vsphere_clone_vm_11
variable.hypervisor=

# Description: (Optional) vsphere_clone_vm_19
variable.ip=

# Description: (Optional) vsphere_clone_vm_27
variable.os=

# Description: (Optional) vsphere_clone_vm_33
variable.ownername=

# Description: (Optional) vsphere_clone_vm_35
variable.ownerorg=

# Description: (Optional) vsphere_clone_vm_13
variable.pool=

# Description: (Optional) vsphere_clone_vm_17
variable.poweron=

# Description: (Optional) vsphere_clone_vm_21
variable.subnet=

# Description: (Optional) vsphere_clone_vm_37
variable.timezone=

# Description: (Optional) vsphere_clone_vm_3
variable.vm=

# Description: (Optional) Notify the job owner when a selected state occurs
# Allowed Values: SCHEDULED, RUNNING, ACTION_REQUIRED, SUSPENDED, SUCCEEDED, PROBLEMS
notification=

5. Next, we’ll open the file we just created and add all of the required information. Below is a sample properties file that is filled in. I’ve replaced the default comments to better explain what each option is.

[oracle@em-oel6-demo ~]$ cat /tmp/clone_properties.txt
# Name of the job that will appear in EM Jobs Activity Page.
# THIS MUST BE UNIQUE FROM ANY OTHER PREVIOUS/EXECUTING JOB!
name=CLONE_TEMPLATE_1

# This is the job type, and for cloning a VMware VM or Template
# this will stay the same across all jobs.
type=vsphere_clone_vm

# If you want the job to execute immediately, use "active".
# If you want to save the job to the library to reference
# or execute later, use "library".
kind=active

# This is the name of the VMware Plugin target, for us it's "PVM",
# followed by the target type, which will always remain "bm_vsphere".
target_list=PVM:bm_vsphere

# You need to have Default Preferred Credentials set for
# the VMware Home target type. If you have them set, this
# will be the same for you.
cred.defaultHostCred.<all_targets>:bm_vsphere=SET:HostCreds

# Name of the source VMware VM or Template.
variable.vm=oel6-template

# Name of the soon-to-be-created Virtual Machine.
variable.clonename=oel6-oracle-db

# Name of the datacenter that the new VM will be located in.
variable.datacenter=Demo

# IMPORTANT! ONLY SPECIFY ONE: A HYPERVISOR OR A CLUSTER.
# If datacenter is configured for DRS: only specify cluster.
# If datacenter is NOT configured for DRS: only specify hypervisor.
variable.cluster=Demo-Cluster
variable.hypervisor=

# OPTIONAL.
# Name of the resource pool the new VM will be placed in.
variable.pool=

# Name of the datastore the new VM will be located on.
variable.datastore=iscsi

# Whether to power new VM on after cloned.
# Possible values: "true" or "false"
variable.poweron=false

# Type of Operating System the SOURCE VM is.
# Possible values: "Linux" or "Windows"
variable.os=Linux

#################################################
# The fields below are optional, however, if #
# any field is populated, they are ALL required #
# with the exception of OS specific params that #
# are different than the OS of the source VM. #
#################################################

#### LINUX ONLY ####
# Domain the VM OS will be a part of
variable.domain=

#### WINDOWS ONLY ####
# THIS VALUE IS AN INTEGER. Use the VMware Plugin docs to find the correct value.
variable.timezone=

#### WINDOWS ONLY ####
# Owner name
variable.ownername=

#### WINDOWS ONLY ####
# Owner organization
variable.ownerorg=

# IP Address of DNS server the new VM should use.
variable.dnsserver=

# IP Address of the gateway.
variable.gateway=

# IP Address of the new VM.
variable.ip=

# Subnet Mask of the new VM.
variable.subnet=

# Name of the computer.
variable.computername=

6. Now, simply execute the job!

[oracle@em-oel6-demo ~]$ emcli create_job -input_file=property_file:/tmp/clone_properties.txt Creation of job "CLONE_TEMPLATE_1" was successful.

7. Execute the following command to get the Execution ID, which is required to view the output from the job.

[oracle@em-oel6-demo ~]$ emcli get_jobs -status=2
Name              Type              Job ID                            Execution ID                      Scheduled            Completed  TZ Offset  Status   Status ID  Owner   Target Type  Target Name
CLONE_TEMPLATE_1  vsphere_clone_vm  E41802045F6D1C9EE040007F01002122  E41802045F6F1C9EE040007F01002122  2013-08-16 17:09:40  none       GMT-04:00  Running  2          SYSMAN  bm_vsphere   PVM

8. Periodically check the status of the job with the following command.

[oracle@em-oel6-demo ~]$ emcli get_job_execution_detail -execution=E41802045F6F1C9EE040007F01002122 -xml -showOutput | grep '^ -'
 - 0% complete...
 - 5% complete...
 - 10% complete...
 - 15% complete...
 - 20% complete...
 - 25% complete...
 - 30% complete...
 - 35% complete...
 - 40% complete...
 - 45% complete...
 - 50% complete...

9. Here is what the output looks like when it’s complete:

[oracle@em-oel6-demo ~]$ emcli get_job_execution_detail -execution=E41802045F6F1C9EE040007F01002122 -xml -showOutput | grep '^ -'
 - 0% complete...
 - 5% complete...
 - 10% complete...
 - 15% complete...
 - 20% complete...
 - 25% complete...
 - 30% complete...
 - 35% complete...
 - 40% complete...
 - 45% complete...
 - 50% complete...
 - 55% complete...
 - 60% complete...
 - 65% complete...
 - 70% complete...
 - 75% complete...
 - 80% complete...
 - 85% complete...
 - 90% complete...
 - 100% complete

10. Because no error was returned, we know the job was successful! While completely unnecessary, I verified that the job completed from vCenter as well.

There you have it!

In less than 10 minutes of console time we’ve created a new VMware Virtual Machine using EMCLI. The next steps are up to you. Do you want to modify the Memory or CPU configuration of the new Virtual Machine? Perhaps power it on or off? Maybe you want to delete it since you were just testing out this tutorial? Or maybe you want to automate this process even further and create a script that will do all of the console work here for you? All of these are possible using the latest release of the Enterprise Manager plugin for VMware!

Get started

Try BindPlane for free. No credit card required.

Sign up
True Visibility
BindPlane for VMware vRealize Operations

True Visibility allows cloud management teams to use VMware vRealize’s powerful machine learning and capacity planning engine across their entire hybrid cloud environment.

Azure Monitor...everything
BindPlane for Microsoft Azure Monitor

Make Azure Monitor your first-pane-of-glass across your entire multi-cloud, multi-database or hybrid platform environment.

Thank you for contacting us. Your information was received. We'll be in touch shortly.