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



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

def before_bootstrap
  super

  config[:chef_node_name] = locate_config_value(: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



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

def before_exec_command
  super

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

#hostname_for_serverObject

Gets the ipaddress for the VM to bootstrap with



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

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



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

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