Class: Chef::Knife::Cloud::VraServerCreate

Inherits:
ServerCreateCommand
  • Object
show all
Includes:
VraServiceHelpers, VraServiceOptions, ServerCreateOptions
Defined in:
lib/chef/knife/vra_server_create.rb

Instance Method Summary collapse

Methods included from VraServiceHelpers

#check_for_missing_config_values!, #create_service_instance, #validate!, #verify_ssl?, #wait_for_request

Methods included from VraServiceOptions

included

Instance Method Details

#before_bootstrapObject



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

def before_bootstrap
  super

  config[:chef_node_name] ||= server.name
  config[:bootstrap_ip_address] = hostname_for_server
end

#before_exec_commandObject



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/chef/knife/vra_server_create.rb', line 90

def before_exec_command
  super

  @create_options = {
    catalog_id: @name_args.first,
    project_id: config[:project_id],
    image_mapping: config[:image_mapping],
    flavor_mapping: config[:flavor_mapping],
    version: config[:version],
    name: config[:name],
    extra_params: extra_params,
  }
end

#extra_paramsObject



111
112
113
114
115
116
117
118
# File 'lib/chef/knife/vra_server_create.rb', line 111

def extra_params
  return if Chef::Config[:knife][:vra_extra_params].nil? || Chef::Config[:knife][:vra_extra_params].empty?

  Chef::Config[:knife][:vra_extra_params].each_with_object([]) do |(key, value_str), memo|
    type, value = value_str.split(":")
    memo << { key: key, type: type, value: value }
  end
end

#hostname_for_serverObject



130
131
132
133
134
# File 'lib/chef/knife/vra_server_create.rb', line 130

def hostname_for_server
  ip_address = server.ip_address

  ip_address.nil? ? server.name : ip_address
end

#validate_extra_params!Object



120
121
122
123
124
125
126
127
128
# File 'lib/chef/knife/vra_server_create.rb', line 120

def validate_extra_params!
  return if extra_params.nil?

  extra_params.each do |param|
    raise ArgumentError, "No type and value set for extra parameter #{param[:key]}" if param[:type].nil? || param[:value].nil?
    raise ArgumentError, "Invalid parameter type for #{param[:key]} - must be string or integer" unless
      param[:type] == "string" || param[:type] == "integer"
  end
end

#validate_params!Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/chef/knife/vra_server_create.rb', line 77

def validate_params!
  super

  if @name_args.empty?
    ui.error("You must supply a Catalog ID to use for your new server.")
    exit 1
  end

  check_for_missing_config_values!(:name, :flavor_mapping, :image_mapping, :project_id)

  validate_extra_params!
end