lib/chef/knife/vsphere_vm_clone.rb
def generate_adapter_map(ip = nil, gw = nil, mac = nil)
    settings = RbVmomi::VIM.CustomizationIPSettings

    if ip.nil? || ip.downcase == 'dhcp'
      settings.ip = RbVmomi::VIM::CustomizationDhcpIpGenerator.new
    else
      cidr_ip = NetAddr::CIDR.create(ip)
      settings.ip = RbVmomi::VIM::CustomizationFixedIp(ipAddress: cidr_ip.ip)
      settings.subnetMask = cidr_ip.netmask_ext

      # TODO: want to confirm gw/ip are in same subnet?
      # Only set gateway on first IP.
      if config[:customization_ips].split(',').first == ip
        if gw.nil?
          settings.gateway = [cidr_ip.network(Objectify: true).next_ip]
        else
          gw_cidr = NetAddr::CIDR.create(gw)
          settings.gateway = [gw_cidr.ip]
        end
      end
    end

    adapter_map = RbVmomi::VIM.CustomizationAdapterMapping
    adapter_map.macAddress = mac if !mac.nil? && (mac != AUTO_MAC)
    adapter_map.adapter = settings
    adapter_map
  end
# Generates a CustomizationAdapterMapping (currently only single IPv4 address) object
# @param ip [String] Any static IP address to use, or "dhcp" for DHCP
# @param gw [String] If static, the gateway for the interface, otherwise network address + 1 will be used
# @return [RbVmomi::VIM::CustomizationIPSettings]
Generates a CustomizationAdapterMapping (currently only single IPv4 address) object
Generates a CustomizationAdapterMapping ( currently only single IPv4 address ) object
def generate_adapter_map(ip = nil, gw = nil, mac = nil)
    settings = RbVmomi::VIM.CustomizationIPSettings
    if ip.nil? || ip.downcase == 'dhcp'
      settings.ip = RbVmomi::VIM::CustomizationDhcpIpGenerator.new
    else
      cidr_ip = NetAddr::CIDR.create(ip)
      settings.ip = RbVmomi::VIM::CustomizationFixedIp(ipAddress: cidr_ip.ip)
      settings.subnetMask = cidr_ip.netmask_ext
      if config[:customization_ips].split(',').first == ip
        if gw.nil?
          settings.gateway = [cidr_ip.network(Objectify: true).next_ip]
        else
          gw_cidr = NetAddr::CIDR.create(gw)
          settings.gateway = [gw_cidr.ip]
        end
      end
    end
    adapter_map = RbVmomi::VIM.CustomizationAdapterMapping
    adapter_map.macAddress = mac if !mac.nil? && (mac != AUTO_MAC)
    adapter_map.adapter = settings
    adapter_map
  end
def generate_adapter_map ( ip = nil , gw = nil , mac = nil ) settings = RbVmomi :: VIM . CustomizationIPSettings if ip . nil? || ip . downcase == 'dhcp' settings . ip = RbVmomi :: VIM :: CustomizationDhcpIpGenerator . new else cidr_ip = NetAddr :: CIDR . create ( ip ) settings . ip = RbVmomi :: VIM :: CustomizationFixedIp ( ipAddress : cidr_ip . ip ) settings . subnetMask = cidr_ip . netmask_ext if config [ :customization_ips ] . split ( ',' ) . first == ip if gw . nil? settings . gateway = [ cidr_ip . network ( Objectify : true ) . next_ip ] else gw_cidr = NetAddr :: CIDR . create ( gw ) settings . gateway = [ gw_cidr . ip ] end end end adapter_map = RbVmomi :: VIM . CustomizationAdapterMapping adapter_map . macAddress = mac if ! mac . nil? && ( mac != AUTO_MAC ) adapter_map . adapter = settings adapter_map end
Generates a CustomizationAdapterMapping (currently only single IPv4 address) object
Generates a CustomizationAdapterMapping ( currently only single IPv4 address ) object
# TODO: want to confirm gw/ip are in same subnet? # Only set gateway on first IP.
None
RbVmomi::VIM::CustomizationIPSettings
ip
Any static IP address to use, or "dhcp" for DHCP
Any static IP address to use or " dhcp " for DHCP
gw
If static, the gateway for the interface, otherwise network address + 1 will be used
If static the gateway for the interface otherwise network address + 1 will be used
mac