Module: Chef::Knife::Cloud::GoogleServiceHelpers

Included in:
GoogleService
Defined in:
lib/chef/knife/cloud/google_service_helpers.rb

Constant Summary collapse

REQUIRED_KEYS =
[:gce_project].freeze

Instance Method Summary collapse

Instance Method Details

#check_for_missing_config_values!(*keys) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chef/knife/cloud/google_service_helpers.rb', line 35

def check_for_missing_config_values!(*keys)
  keys_to_check = REQUIRED_KEYS + keys

  missing = keys_to_check.select { |x| config[x].nil? }

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

#create_service_instanceObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/chef/knife/cloud/google_service_helpers.rb', line 24

def create_service_instance
  Chef::Knife::Cloud::GoogleService.new(
    project:       config[:gce_project],
    zone:          config[:gce_zone],
    wait_time:     config[:request_timeout],
    refresh_rate:  config[:request_refresh_rate],
    max_pages:     config[:gce_max_pages],
    max_page_size: config[:gce_max_page_size]
  )
end

#private_ip_for(server) ⇒ Object



47
48
49
50
51
# File 'lib/chef/knife/cloud/google_service_helpers.rb', line 47

def private_ip_for(server)
  server.network_interfaces.first.network_ip
rescue NoMethodError
  "unknown"
end

#public_ip_for(server) ⇒ Object



53
54
55
56
57
# File 'lib/chef/knife/cloud/google_service_helpers.rb', line 53

def public_ip_for(server)
  server.network_interfaces.first.access_configs.first.nat_ip
rescue NoMethodError
  "unknown"
end

#valid_disk_size?(size) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/chef/knife/cloud/google_service_helpers.rb', line 59

def valid_disk_size?(size)
  size.between?(10, 10_000)
end