lib/ruby_nsx_cli/nsx_objects/nsx_edge.rb
# Adds a DHCP relay agent to the specified edge for the specified vNIC
# This method is not safe to run concurrently
#
# @param edge_id [String] Edge Id to add the DHCP agent to
# @param gi_address [String] Gateway IP address
# @param vnic_index [Integer] vNIC index of the interface on the specified edge to add the DHCP relay agent
# @return [RestClient::Response] Response from the NSX API
Adds a DHCP relay agent to the specified edge for the specified vNIC
This method is not safe to run concurrently
Adds a DHCP relay agent to the specified edge for the specified vNIC This method is not safe to run concurrently
def add_dhcp_agent(edge_id, vnic_index, gi_address)
      api_endpoint = "/api/4.0/edges/#{edge_id}/dhcp/config/relay"
      dhcp_agent_hash = {
          :vnic_index => vnic_index,
          :gi_address => gi_address
      }
      validate_edge_args(dhcp_agent_hash, edge_id)
      dhcp_agent_obj = OpenStruct.new(dhcp_agent_hash)
      dhcp_agent_xml = render_template('/templates/dhcp/relayagent.xml.erb', dhcp_agent_obj)
      current_dhcp_config = get("/api/4.0/edges/#{edge_id}/dhcp/config/relay")
      @logger.info("Checking if DHCP agent already exists on edge: #{edge_id}")
      if check_dhcp_agent_exists(current_dhcp_config, vnic_index, gi_address)
        @logger.info("Skipping Agent - DHCP agent already exists (vnicIndex: #{vnic_index} giAddress #{gi_address})")
        return
      end
      @logger.info("Adding Agent (vnicIndex: #{vnic_index} giAddress #{gi_address})")
      payload = inject_xml(current_dhcp_config, 'relay', 'relayAgents', dhcp_agent_xml)
      payload = strip_xml_root_pi(payload)
      put(:api_endpoint => api_endpoint, :payload => payload)
    end
def add_dhcp_agent ( edge_id , vnic_index , gi_address ) api_endpoint = "/api/4.0/edges/#{edge_id}/dhcp/config/relay" dhcp_agent_hash = { :vnic_index => vnic_index , :gi_address => gi_address } validate_edge_args ( dhcp_agent_hash , edge_id ) dhcp_agent_obj = OpenStruct . new ( dhcp_agent_hash ) dhcp_agent_xml = render_template ( '/templates/dhcp/relayagent.xml.erb' , dhcp_agent_obj ) current_dhcp_config = get ( "/api/4.0/edges/#{edge_id}/dhcp/config/relay" ) @logger . info ( "Checking if DHCP agent already exists on edge: #{edge_id}" ) if check_dhcp_agent_exists ( current_dhcp_config , vnic_index , gi_address ) @logger . info ( "Skipping Agent - DHCP agent already exists (vnicIndex: #{vnic_index} giAddress #{gi_address})" ) return end @logger . info ( "Adding Agent (vnicIndex: #{vnic_index} giAddress #{gi_address})" ) payload = inject_xml ( current_dhcp_config , 'relay' , 'relayAgents' , dhcp_agent_xml ) payload = strip_xml_root_pi ( payload ) put ( :api_endpoint => api_endpoint , :payload => payload ) end
Adds a DHCP relay agent to the specified edge for the specified vNIC
This method is not safe to run concurrently
Adds a DHCP relay agent to the specified edge for the specified vNIC This method is not safe to run concurrently
# The DHCP configuration must be retrieved as the put operation overrides the current config # There does not seem to be an alternative way of doing this # Grandparent xml node must be provided in the case that the parent node does not exist # i.e. <relayAgents /> does not exist if there are no current relay agents on the edge # Strip out XML pi at top of response to prevent 500 errors due to bad formatting of XML payload
Response from the NSX API
Response from the NSX API
RestClient::Response
edge_id
Edge Id to add the DHCP agent to
Edge Id to add the DHCP agent to
vnic_index
vNIC index of the interface on the specified edge to add the DHCP relay agent
vNIC index of the interface on the specified edge to add the DHCP relay agent
gi_address
Gateway IP address
Gateway IP address