Module: Chef::Knife::Cloud::VraServiceHelpers

Includes:
Helpers
Included in:
VraServerCreate, VraService
Defined in:
lib/chef/knife/cloud/vra_service_helpers.rb

Instance Method Summary collapse

Instance Method Details

#check_for_missing_config_values!(*keys) ⇒ Object

rubocop:disable Style/GuardClause


80
81
82
83
84
85
86
87
# File 'lib/chef/knife/cloud/vra_service_helpers.rb', line 80

def check_for_missing_config_values!(*keys)
  missing = keys.select { |x| config[x].nil? }

  unless missing.empty?
    ui.error("The following required parameters are missing: #{missing.join(", ")}")
    exit(1)
  end
end

#create_service_instanceObject


29
30
31
32
33
34
35
36
# File 'lib/chef/knife/cloud/vra_service_helpers.rb', line 29

def create_service_instance
  Chef::Knife::Cloud::VraService.new(username:  config[:vra_username],
                                     password:  config[:vra_password],
                                     base_url:  config[:vra_base_url],
                                     tenant:    config[:vra_tenant],
                                     page_size: config[:vra_page_size],
                                     verify_ssl: verify_ssl?)
end

#validate!Object


75
76
77
# File 'lib/chef/knife/cloud/vra_service_helpers.rb', line 75

def validate!
  check_for_missing_config_values!(:vra_username, :vra_password, :vra_base_url, :vra_tenant)
end

#verify_ssl?Boolean

Returns:

  • (Boolean)

38
39
40
# File 'lib/chef/knife/cloud/vra_service_helpers.rb', line 38

def verify_ssl?
  !config[:vra_disable_ssl_verify]
end

#wait_for_request(request, wait_time = 600, refresh_rate = 2) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/chef/knife/cloud/vra_service_helpers.rb', line 42

def wait_for_request(request, wait_time = 600, refresh_rate = 2)
  print "Waiting for request to complete."

  last_status = ""

  begin
    Timeout.timeout(wait_time) do
      loop do
        request.refresh

        if request.completed?
          print "\n"
          break
        end

        if last_status == request.status
          print "."
        else
          last_status = request.status
          print "\n"
          print "Current request status: #{request.status}."
        end

        sleep refresh_rate
      end
    end
  rescue Timeout::Error
    ui.msg("")
    ui.error("Request did not complete in #{wait_time} seconds. Check the Requests tab in the vRA UI for more information.")
    exit 1
  end
end