Feature #2438

Ability to deploy hosts from vmware templates

Added by Oliver Weinmann over 4 years ago. Updated about 2 years ago.

Status:Closed
Priority:Normal
Assigned To:-
Category:Compute resources
Target version:Sprint 22
Difficulty: Bugzilla link:
Found in release: Pull request:
Story points-
Velocity based estimate-
Release1.5.0Release relationshipAuto

Description

Hi,

it would be nice to deploy hosts from VMware templates to speedup the deployment process.

Regards,
Oliver


Related issues

Related to Foreman - Feature #5125: List available VMware images New 04/09/2014
Duplicated by Foreman - Feature #2703: Create vmware virtual machines by cloning a template Duplicate 06/24/2013

Associated revisions

Revision 33040495
Added by Rufus Post over 3 years ago

fixes #2438 - Add image build capability to vsphere using templates

History

#1 Updated by Jon McKenzie over 4 years ago

+1 to this. I work in an environment with multiple, disconnected LANs, so in many instances, I need to be able to provision from templates to reduce provisioning errors, reduce the chance that someone has changed something, not have to rely on network resources (that may be down), etc.

#2 Updated by Jason Ashby about 4 years ago

I would love this functionality. Looks like rbvmomi, the gem used by Foreman to talk to VMware, has the ability to deploy from an OVF.

http://rdoc.info/github/rlane/rbvmomi/master/RbVmomi/VIM/OvfManager

So I think you could convert the VMware template to OVF format and make it accessible via http. I'm thinking:

- add new medium in Foreman pointing to my "golden" OVF.
- then I can create a new host in Foreman using the OVF as the source + any applicable fields.

I'm not sure how the kickstart portion would work in regards to setting up networking, etc... to get the new host handed off to puppet. Not sure you can configure the guest OS' network when deploying from OVF.

Anyone have any ideas, concerns? I'd be happy to work on this.

#3 Updated by Jason Ashby about 4 years ago

You can mark this as a duplicate of http://projects.theforeman.org/issues/2703. I know 2703 is newer, but it has some better info and code to start with.

#4 Updated by Dominic Cleal about 4 years ago

  • Duplicated by Feature #2703: Create vmware virtual machines by cloning a template added

#5 Updated by Dominic Cleal about 4 years ago

  • Description updated (diff)
  • Category set to Compute resources

I kept this one as it's got more votes, thanks for pointing it out Jason. (But yes, do check the other issue for a script snippet.)

#6 Updated by Jason Ashby about 4 years ago

Here is a script to launch a VM from a VMware template, allowing a static IP and networking to be set on the guest OS. This expands on Ronny's script in issue 2703.

#!/usr/bin/ruby
require 'rubygems'
require 'fog'
require 'pp'

credentials = {
    :provider         => "vsphere",
    :vsphere_username => "myadminuser",
    :vsphere_password => "*********",
    :vsphere_server   => "vcenter.example.com",
    :vsphere_ssl      => true,
    :vsphere_expected_pubkey_hash => "89d0foof6e6aef34e1ed20ae04dffad48085355e6bfoo792e9435b5a4f1b3e9" 
}

connection = Fog::Compute.new(credentials)
puts "Connected to #{connection.vsphere_server} as #{connection.vsphere_username} (API version #{connection.vsphere_rev})" 

options = {
    'datacenter'    => 'Baltimore',
    'template_path' => '/centos_6_4',
    'power_on'      => true,
    'memoryMB'      => '1024',
    'network_label' => '172.18.2.x',
    'numCPUs'       => 2,
    'datastore'     => 'VM NFS Mount',
    'wait'          => true,
    'hostname'      => 'tester',
    'name'          => 'Tester',
    'customization_spec' => {
        'domain'     => 'example.com',
        'ipsettings' => {
            'ip'      => '172.18.2.10',
            'gateway' => ['172.18.2.1'],
            'subnetMask' => '255.255.255.0',
        },
     },
}

puts "Deploying new VM from template.  This may take a few minutes..." 
new_vm=connection.vm_clone(options)
pp new_vm

Side note: I had to change the guest OS setting on my CentOS 6 template to RHEL 6 due to CentOS guest customization not being supported in vSphere per the error below. You need to convert the template to a VM, change the guest OS to Red Hat, and convert back to a template and you're golden.

/usr/lib/ruby/gems/1.8/gems/rbvmomi-1.6.0/lib/rbvmomi/vim/Task.rb:11:in `wait_for_completion': UncustomizableGuest: Customization of the guest operating system 'centos64Guest' is not supported in this configuration. Microsoft Vista (TM) and Linux guests with Logical Volume Manager are supported only for recent ESX host and VMware Tools versions. Refer to vCenter documentation for supported configurations. (RbVmomi::Fault)
        from /usr/lib/ruby/gems/1.8/gems/fog-1.15.0/lib/fog/vsphere/requests/compute/vm_clone.rb:259:in `vm_clone'
        from ./fogtest.rb:46

#7 Updated by Jason Ashby about 4 years ago

I'll see about incorporating this in Foreman. First, one should be able to retrieve a list of available templates from a compute resource and have that populate a drop-down in the deploy New Host view. I'm not sure if all the fields when deploying a new host in Foreman are applicable/supported by fog's vm_clone or even vSphere, so the functionality may be limited. Still, having this ability through Foreman to deploy a new host via template would be huge in my environment.

#8 Updated by Dominic Cleal about 4 years ago

Thanks for looking into this Jason. You might want to investigate Foreman's image support, which allows you to associate a compute resource image with an operating system, so it's available to select on the new host form. CRs such as EC2 and OpenStack use this method, but we'll need to support both methods for VMware.

#9 Updated by Jason Ashby about 4 years ago

Will do Dominic, thanks.

I'm running into an issue with fog where I can't deploy a VM to a different datacenter/resource pool other than where the template resides. Hopefully I'll get some info while I dig into this issue myself. Details on github:

https://github.com/fog/fog/issues/2233

#10 Updated by Ronny M about 4 years ago

Beside (or instead of) a template selection drop-down menu I was thinking that it would be nice if vmware templates could be linked to an hosts selected OS version.
This way selecting, for example Redhat/CentOS 6.4 64bit OS for a host would default to a vmware template (rhel6_64bit) that is optimized for this OS version without the need of having to select a template from a drop-down menu. The drop-down menu could then be used to override a default or if no default template would exist for an OS version.

This minimizes the amount of configuration changes a user has to do for creating a host and could also prevent a maybe unnecessary selection of a wrong template for a configured/chosen OS version.

#11 Updated by Rufus Post almost 4 years ago

I have a PR open for a basic implementation, looking for feedback and have more time to invest in this https://github.com/theforeman/foreman/pull/1183

#12 Updated by Dominic Cleal almost 4 years ago

  • Status changed from New to Ready For Testing
  • Target version set to Sprint 19

#13 Updated by Dmitri Dolguikh almost 4 years ago

  • Target version changed from Sprint 19 to Sprint 20

#14 Updated by Dmitri Dolguikh over 3 years ago

  • Target version changed from Sprint 20 to Sprint 21

#15 Updated by Dmitri Dolguikh over 3 years ago

  • Target version changed from Sprint 21 to Sprint 22

#16 Updated by Jean-Christophe Counio over 3 years ago

Hi,

This a a very good and needed feature, and I'd love to see that in 1.5.0.
Just a few comments :
- The PR actually doesn't use VmWare templates from what I tested. It requires one of the VMs in the list of 'Virtual Machines', which are actual VMs (that can be off) but not VmWare templates
- If the image VM is located in a folder, it fails since it it try to take it from the root. Moving the image VM to the root of the DataCenter solved the issue
- The image id to enter when creating the image is indeed the UUID. It's ok when you know it, but since the field is common to many cloud servers, the UI isn't explicit on this

Thanks

JC

#17 Updated by Dominic Cleal over 3 years ago

This is very unlikely to land in Foreman 1.5 now as we're approaching feature freeze this week, and the PR still has issues as you noted. If anybody has the time to resurrect it and address the noted issues, that'd be much appreciated. We'd be happy to give guidance on the PR, foreman-dev mailing list or IRC channel.

#18 Updated by Jean-Christophe Counio over 3 years ago

I commented with a way to make the clone work when image isn't in the root in the PR.
Using Vms instead of templates isn't a blocker, what is important is to be able to clone, it saves a lot of time (eg for us, 3-7 mns to clone, 30-40mns to create new VMs with OS).
Maybe it's worth to merge it for 1.5.0 and go on with new issues/PR to improve it, since this one is opened for a while.

#19 Updated by Dominic Cleal over 3 years ago

  • Release set to 1.5.0

Thanks for your input Jean-Christophe, it's been very helpful.

#20 Updated by Dominic Cleal over 3 years ago

#21 Updated by Rufus Post over 3 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF