Class: Chef::Knife::Cloud::VcenterVmClone

Inherits:
ServerCreateCommand
  • Object
show all
Includes:
VcenterServiceOptions, ServerCreateOptions
Defined in:
lib/chef/knife/vcenter_vm_clone.rb

Overview

Extends the ServerCreateCommand for specific vCenter

Instance Method Summary collapse

Methods included from VcenterServiceOptions

included

Instance Method Details

#before_bootstrapObject

determine the IP address to use to bootstrap the machine with chef



104
105
106
107
108
109
110
# File 'lib/chef/knife/vcenter_vm_clone.rb', line 104

def before_bootstrap
  super

  config[:chef_node_name] = config[:chef_node_name] || server.name

  config[:bootstrap_ip_address] = hostname_for_server
end

#before_exec_commandObject

Creates the @create_options to hand off to the next step



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/chef/knife/vcenter_vm_clone.rb', line 87

def before_exec_command
  super

  @create_options = {
    name: @name_args[0],
    type: "clone",
    template: config[:template],
    targethost: config[:targethost],
    datacenter: config[:datacenter],
    poweron: !config[:disable_power_on],
    folder: config[:folder],
    resource_pool: config[:pool],
  }
end

#hostname_for_serverObject

Gets the ipaddress for the VM to bootstrap with



114
115
116
117
118
# File 'lib/chef/knife/vcenter_vm_clone.rb', line 114

def hostname_for_server
  ipaddress = service.ipaddress

  ipaddress.nil? ? server.name : ipaddress
end

#validate_params!Object

Validates the parameters and maksessure you have a template, name, or datacenter



75
76
77
78
79
80
81
82
83
# File 'lib/chef/knife/vcenter_vm_clone.rb', line 75

def validate_params!
  super

  if @name_args.empty?
    ui.error("You must provide the name of the new machine")
  end

  check_for_missing_config_values!(:template, :datacenter)
end