Skip to content

Commit

Permalink
Merge branch 'release/v0.3.2'
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
	lib/vagrant-vcenter/version.rb
  • Loading branch information
frapposelli committed Oct 15, 2014
2 parents 0c216b1 + 3a30fd5 commit a4d8d15
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 92 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Vagrant](http://www.vagrantup.com) provider for VMware vCenter®
=============

[Version 0.3.1](../../releases/tag/v0.3.1) has been released!
[Version 0.3.2](../../releases/tag/v0.3.2) has been released!
-------------

Please note that this software is still Alpha/Beta quality and is not recommended for production usage.
Expand Down Expand Up @@ -94,6 +94,7 @@ Vagrant.configure('2') do |config|
override.folder_name = 'Vagrant/centos'
when /precise/
override.folder_name = 'Vagrant/ubuntu/precise'
override.enable_vm_customization = false
end
end
node_config.nfs.functional = false
Expand Down
14 changes: 2 additions & 12 deletions example_box/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
# vagrant-vcenter box specifications [WIP]
# vagrant-vcenter box specifications

*Note that vagrant-vcenter currently supports only single VM vApp boxes*

BOX package should contain:

- `metadata.json` -- Vagrant metadata file
- `<boxname>.ovf` -- OVF descriptor of the vApp.
- `<boxname>.mf` -- OVF manifest file containing file hashes.
- `<boxname>-disk-<#>.vmdk` -- Associated VMDK files.
- `Vagrantfile`-- vagrant-vcenter default Vagrantfile

A [task is open](https://github.com/frapposelli/vagrant-vcenter/issues/12) for creating a veewee plugin to facilitate Box creation
[See this Wiki page for more information](https://github.com/gosddc/packer-post-processor-vagrant-vmware-ovf/wiki/vmware_ovf-Box-Format).
6 changes: 0 additions & 6 deletions example_box/Vagrantfile

This file was deleted.

1 change: 0 additions & 1 deletion example_box/metadata.json

This file was deleted.

131 changes: 91 additions & 40 deletions lib/vagrant-vcenter/action/build_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ def call(env)
# FIXME: Raise a correct exception
computer = dc.find_compute_resource(
config.computer_name) or fail 'Host not found'
rp = computer.resourcePool

if config.resourcepool_name
rp = computer.resourcePool.resourcePool.find {
|f| f.name == config.resourcepool_name
}
else
rp = computer.resourcePool
end

# FIXME: Raise a correct exception
template = dc.find_vm(
Expand Down Expand Up @@ -120,61 +127,105 @@ def call(env)
spec.config = config_spec
end

public_networks = env[:machine].config.vm.networks.select {
|n| n[0].eql? :public_network
}
if config.enable_vm_customization
public_networks = env[:machine].config.vm.networks.select {
|n| n[0].eql? :public_network
}

network_spec = public_networks.first[1] unless public_networks.empty?

@logger.debug("This is our network #{public_networks.inspect}")

if network_spec

# Check for sanity and validation of network parameters.

network_spec = public_networks.first[1]
# Specify ip but no netmask
if network_spec[:ip] && !network_spec[:netmask]
fail Errors::WrongNetworkSpec
end

@logger.debug("This is our network #{public_networks.inspect}")
# specify netmask but no ip
if !network_spec[:ip] && network_spec[:netmask]
fail Errors::WrongNetworkSpec
end

if network_spec
global_ip_settings = RbVmomi::VIM.CustomizationGlobalIPSettings(
:dnsServerList => network_spec[:dns_server_list],
:dnsSuffixList => network_spec[:dns_suffix_list])

# Check for sanity and validation of network parameters.
# if no ip and no netmask, let's default to dhcp
if !network_spec[:ip] && !network_spec[:netmask]
adapter = RbVmomi::VIM.CustomizationIPSettings(
:ip => RbVmomi::VIM.CustomizationDhcpIpGenerator())
else
adapter = RbVmomi::VIM.CustomizationIPSettings(
:gateway => [network_spec[:gateway]],
:ip => RbVmomi::VIM.CustomizationFixedIp(
:ipAddress => network_spec[:ip]),
:subnetMask => network_spec[:netmask])
end

# Specify ip but no netmask
if network_spec[:ip] && !network_spec[:netmask]
fail Errors::WrongNetworkSpec
nic_map = [RbVmomi::VIM.CustomizationAdapterMapping(
:adapter => adapter)]
end

# specify netmask but no ip
if !network_spec[:ip] && network_spec[:netmask]
fail Errors::WrongNetworkSpec
if config.prep_type.downcase == 'linux'
prep = RbVmomi::VIM.CustomizationLinuxPrep(
:domain => env[:machine].name.to_s.sub(/^[^.]+\./, ''),
:hostName => RbVmomi::VIM.CustomizationFixedName(
:name => env[:machine].name.to_s.split('.')[0]))
elsif config.prep_type.downcase == 'windows'
prep = RbVmomi::VIM.CustomizationSysprep(
:guiUnattended => RbVmomi::VIM.CustomizationGuiUnattended(
:autoLogon => false,
:autoLogonCount => 0,
:timeZone => 004
),
:identification => RbVmomi::VIM.CustomizationIdentification(),
:userData => RbVmomi::VIM.CustomizationUserData(
:computerName => RbVmomi::VIM.CustomizationFixedName(
:name => env[:machine].name.to_s.split('.')[0]),
:fullName => 'Vagrant',
:orgName => 'Vagrant',
:productId => 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'
)
)
else
fail "specification type #{config.prep_type} not supported"
end

global_ip_settings = RbVmomi::VIM.CustomizationGlobalIPSettings(
:dnsServerList => network_spec[:dns_server_list],
:dnsSuffixList => network_spec[:dns_suffix_list])
if prep && network_spec
# If prep and network specification are present, let's do a full config
cust_spec = RbVmomi::VIM.CustomizationSpec(
:globalIPSettings => global_ip_settings,
:identity => prep,
:nicSettingMap => nic_map)

prep = RbVmomi::VIM.CustomizationLinuxPrep(
:domain => env[:machine].name.to_s.sub(/^[^.]+\./, ''),
:hostName => RbVmomi::VIM.CustomizationFixedName(
:name => env[:machine].name.to_s.split('.')[0]))
spec.customization = cust_spec

elsif prep && !network_spec
# If no network specifications, default to dhcp
global_ip_settings = RbVmomi::VIM.CustomizationGlobalIPSettings(
:dnsServerList => [],
:dnsSuffixList => [])

# if no ip and no netmask, let's default to dhcp
if !network_spec[:ip] && !network_spec[:netmask]
adapter = RbVmomi::VIM.CustomizationIPSettings(
:ip => RbVmomi::VIM.CustomizationDhcpIpGenerator())
else
adapter = RbVmomi::VIM.CustomizationIPSettings(
:gateway => [network_spec[:gateway]],
:ip => RbVmomi::VIM.CustomizationFixedIp(
:ipAddress => network_spec[:ip]),
:subnetMask => network_spec[:netmask])
end
:ip => RbVmomi::VIM.CustomizationDhcpIpGenerator())

nic_map = [RbVmomi::VIM.CustomizationAdapterMapping(
:adapter => adapter)]
nic_map = [RbVmomi::VIM.CustomizationAdapterMapping(
:adapter => adapter)]

cust_spec = RbVmomi::VIM.CustomizationSpec(
:globalIPSettings => global_ip_settings,
:identity => prep,
:nicSettingMap => nic_map)
cust_spec = RbVmomi::VIM.CustomizationSpec(
:globalIPSettings => global_ip_settings,
:identity => prep,
:nicSettingMap => nic_map)

spec.customization = cust_spec
end
spec.customization = cust_spec
end

@logger.debug("Spec: #{spec.pretty_inspect}")
@logger.debug("Spec: #{spec.pretty_inspect}")
end

@logger.debug("disable_auto_vm_name: #{config.disable_auto_vm_name}")

Expand Down
39 changes: 11 additions & 28 deletions lib/vagrant-vcenter/action/inventory_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ def vcenter_upload_box(env)

box_ovf = "file://#{box_dir}/#{box_file}.ovf"

# Still relying on ruby-progressbar because report_progress basically
# sucks.

@logger.debug("OVF File: #{box_ovf}")

env[:ui].info("Adding [#{box_name}]")
Expand All @@ -51,12 +48,11 @@ def vcenter_upload_box(env)
root_vm_folder = dc.vmFolder
vm_folder = root_vm_folder
if config.template_folder_name.nil?
vm_folder = root_vm_folder.traverse(config.template_folder_name,
RbVmomi::VIM::Folder)
template_folder = root_vm_folder
else
template_folder = root_vm_folder.traverse!(
config.template_folder_name, RbVmomi::VIM::Folder)
end
template_folder = root_vm_folder.traverse!(
config.template_folder_name,
RbVmomi::VIM::Folder)

template_name = box_name

Expand Down Expand Up @@ -109,34 +105,21 @@ def vcenter_check_inventory(env)
if config.template_folder_name.nil?
box_to_search = box_name
else
box_to_search = config.template_folder_name +
'/' + box_name
box_to_search = config.template_folder_name + '/' + box_name
end

@logger.debug("This is the box we're looking for: #{box_to_search}")

config.template_id = dc.find_vm(box_to_search)

if config.template_id.nil?
env[:ui].warn("Template [#{box_name}] " +
'does not exist!')

user_input = env[:ui].ask(
"Would you like to upload the [#{box_name}]" +
" box?\nChoice (yes/no): "
)

if user_input.downcase == 'yes' || user_input.downcase == 'y'
env[:ui].info("Uploading [#{box_name}]...")
vcenter_upload_box(env)
else
env[:ui].error('Template not uploaded, exiting...')

# FIXME: wrong error message
fail VagrantPlugins::VCenter::Errors::VCenterError,
:message => 'Catalog not available, exiting...'
# Roll a dice to get a winner in the race.
sleep_time = rand * (3 - 1) + 1
@logger.debug("Sleeping #{sleep_time} to avoid race conditions.")
sleep(sleep_time)

end
env[:ui].info("Uploading [#{box_name}]...")
vcenter_upload_box(env)
else
@logger.debug("Template found at #{box_to_search}")
end
Expand Down
29 changes: 28 additions & 1 deletion lib/vagrant-vcenter/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class Config < Vagrant.plugin('2', :config)
# @return [String]
attr_accessor :folder_name

# Resource Pool Name where the item will live
#
# @return [String]
attr_accessor :resourcepool_name

# Catalog Name where the item resides
#
# @return [String]
Expand Down Expand Up @@ -75,6 +80,20 @@ class Config < Vagrant.plugin('2', :config)
# @return [String]
attr_accessor :vm_network_type

# Use prep and customization api in the building
# of the vm in vcenter
#
# Mostly this allows the static ip configuration
# of a vm
#
# @return [Bool]
attr_accessor :enable_vm_customization

# Type of the machine prep to use
#
# @return [String]
attr_accessor :prep_type

# num cpu
#
# @return [Fixnum]
Expand All @@ -93,6 +112,11 @@ class Config < Vagrant.plugin('2', :config)
attr_accessor :vcenter_cnx
attr_accessor :template_id

def initialize
@prep_type = 'linux'
@enable_vm_customization = true
end

def validate(machine)
errors = _detected_errors

Expand All @@ -111,7 +135,10 @@ def validate(machine)
I18n.t('vagrant_vcenter.config.computer_name') if computer_name.nil?
errors <<
I18n.t('vagrant_vcenter.config.network_name') if network_name.nil?

if enable_vm_customization
errors <<
I18n.t('vagrant_vcenter.config.no_prep_type') if prep_type.downcase != 'linux' && prep_type.downcase != 'windows'
end
{ 'vCenter Provider' => errors }
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-vcenter/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Plugin < Vagrant.plugin('2')
Cap::PublicAddress
end

provider_capability(:vcenter, :winrm_info) do
provider_capability(:vcenter, :read_winrm_info) do
require_relative 'cap/winrm_info'
Cap::WinRM
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-vcenter/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module VagrantPlugins
# Set version for vagrant-vcenter gem.
module VCenter
VERSION = '0.3.1'
VERSION = '0.3.2'
end
end
2 changes: 1 addition & 1 deletion locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ en:
resourcepool_name: |-
Configuration must specify a resource pool name
no_prep_type: |-
The only supported prep type is linux. hack away.
The only supported prep types are windows and linux.
ipaddress: |-
Configuration must specify a ipaddress
gateway: |-
Expand Down

0 comments on commit a4d8d15

Please sign in to comment.