Puppet Function: gcompute_address_ip
- Defined in:
- lib/puppet/functions/gcompute_address_ip.rb
- Function type:
- Ruby 4.x API
Overview
Returns the IP address associated with the Address managed by a ‘gcompute_address` resource.
Arguments:
- name: string
the name of the address resource
- region: string
the region where the address resource is allocated
- project: string
the project name where resource is allocated
- cred: authorization
the credential to use to authorize the information request
Examples:
- gcompute_address_ip('my-server', 'us-central1', 'myproject', $fn_auth)
The credential parameter should be allocated with a ‘gauth_credential_*_for_function` call.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/puppet/functions/gcompute_address_ip.rb', line 51 Puppet::Functions.create_function(:gcompute_address_ip) do dispatch :gcompute_address_ip do param 'String', :name param 'String', :region param 'String', :project param 'Runtime[ruby, "Google::Authorization"]', :cred end def gcompute_address_ip(name, region, project, cred) get_request = ::Google::Compute::Network::Get.new( gcompute_address_self_link(name, region, project), cred ) response = JSON.parse(get_request.send.body) response['address'] end def gcompute_address_self_link(name, region, project) URI.join( 'https://www.googleapis.com/compute/v1/', "projects/#{project}/", "regions/#{region}/", "addresses/#{name}" ) end end |