module OneviewChefProvisioningDriver::OneViewHelper

Helpers for OneView actions

Public Instance Methods

available_hardware_for_profile(profile, location = nil) click to toggle source

Get an available hardware for a template. If a specific location is requested, find it @return [OneviewSDK::ServerHardware]

# File lib/chef/provisioning/oneview/oneview_helper.rb, line 29
def available_hardware_for_profile(profile, location = nil)
  Chef::Log.debug "Specific hardware requested: #{location}" if location
  hw_list = profile.get_available_hardware
  raise 'Error! No available blades that are compatible with the server template!' if hw_list.empty?
  if location
    chosen_blade = hw_list.find { |h| h['name'] == location }
    return chosen_blade if chosen_blade
    raise "Specified hardware '#{location}' doesn't exist or doesn't match the given template"
  end
  hw_list.first # If no location is specified, return the first matching HW
end
profile_from_template(template_name, profile_name) click to toggle source

Create new Profile from template or server profile @return [OneviewSDK::ServerProfile] server profile

# File lib/chef/provisioning/oneview/oneview_helper.rb, line 6
def profile_from_template(template_name, profile_name)
  raise 'Template name missing! Please set machine_options[:driver_options][:server_template]' unless template_name
  if @ov.api_version >= 200
    # Look for Server Profile Template (OneView 2.0 or higher)
    template = OneviewSDK::ServerProfileTemplate.find_by(@ov, name: template_name).first
    return template.new_profile(profile_name) if template
  end

  # Look for Server Profile as second option
  profile = OneviewSDK::ServerProfile.find_by(@ov, name: template_name).first
  raise "Template '#{template_name}' not found! Please match the template name with one that exists on OneView." unless profile
  profile['name'] = profile_name

  # Remove unwanted fields
  %w(uri serialNumber uuid taskUri enclosureBay enclosureUri).each { |key| profile.data.delete(key) }
  profile['connections'].each do |c|
    %w(wwnn wwpn mac deploymentStatus interconnectUri wwpnType macType).each { |key| c[key] = nil }
  end
  profile
end
wait_for_profile(action_handler, machine_name, profile) click to toggle source

Wait for the profile to finish being applied @return [TrueClass, FalseClass]

# File lib/chef/provisioning/oneview/oneview_helper.rb, line 43
def wait_for_profile(action_handler, machine_name, profile)
  return true if profile['state'] == 'Normal'
  action_handler.perform_action "Apply profile '#{profile['name']}' for machine '#{machine_name}'" do
    action_handler.report_progress "INFO: Applying profile '#{profile['name']}' for machine '#{machine_name}'"
    @ov.wait_for(profile['taskUri'])
  end
  profile.refresh
  raise "Server profile state '#{profile['state']}' not 'Normal'" unless profile['state'] == 'Normal'
end