This section explains how to Configuring DNS Profile using CLI.

Uploading Python Script

A python script is uploaded to Avi Load Balancer to use a custom DNS profile. Use the following script to upload the desired custom DNS script to Avi Load Balancer Controller.

"
 Custom DNS script
  """
 import socket
 import os
 import getpass
 import requests
 import inspect
 import urllib
 import json
 import time
 
 def CreateOrUpdateRecord(record_info, params):
     username = params.get('username')
     passkey = params.get('password') 
     ip = record_info.get('f_ip_address', '') or record_info.get('ip_address', '')
     cname = record_info.get('cname', '')
     fqdn = record_info.get('fqdn') 
     ttl = record_info.get('ttl', 900)
     record_type = record_info.get('type', 'DNS_RECORD_A')
     dns_record_id = 0
     metadata_j = record_info.get('metadata', None)
     if metadata_j:
         metadata = json.loads(metadata_j)
         # Check if default of 0 as DNS record id is useful
         dns_record_id = metadata.get('dns_record_id', 0)
 
     if not fqdn:
         print "Not valid FQDN found %s, returning"%record_info
         return
 
     # REST API
     api = WebApiClient(username, passkey, domain)
     api.disable_ssl_chain_verification()
     param_dict = {
 	    # DNS Record Information
 	    "dns_record_id"         : dns_record_id,
 	    "fqdn"		    : fqdn,
 	    "type"		    : "CNAME" if record_type == 'DNS_RECORD_CNAME' else "A",
 	    "ttl"                   : str(ttl),
 	    "content"		    : cname if record_type == 'DNS_RECORD_CNAME' else ip,
 	    "site"		    : "ALL"             
     }
 
     # Send request to register the FQDN, failures can be raised and the VS creation will fail
     rsp = api.send_request("Update", param_dict)
     if not rsp:
         err_str = "ERROR:"
         err_str += "   STATUS: " + api.get_response_status()
         err_str += "   TYPE: " + str(api.get_error_type())
         err_str += "   MESSAGE: " + api.get_error_message()
         print err_str
         raise Exception("DNS record update failed with %s"%err_str)
 
 
 def DeleteRecord(record_info, params):
     username = params.get('username')
     passkey = params.get('password') 
     ip = record_info.get('f_ip_address', '') or record_info.get('ip_address', '')
     cname = record_info.get('cname', '')
     fqdn = record_info.get('fqdn') 
     ttl = record_info.get('ttl', 900)
     record_type = record_info.get('type', 'DNS_RECORD_A')
     dns_record_id = 0
     metadata_j = record_info.get('metadata', None)
     if metadata_j:
         metadata = json.loads(metadata_j)
         # Check if default of 0 as DNS record id is useful
         dns_record_id = metadata.get('dns_record_id', 0)
 
     api = WebApiClient(username, passkey, domain)
     api.disable_ssl_chain_verification()
     param_dict = {
 	    # DNS Record Information
 	    "dns_record_id"         : int(dns_record_id),
 	    "delete_reason"         : "Reason for deleting record",
 	    "push_immediately"      : True,
 	    "update_serial"         : True,                
     }
 
     rsp = api.send_request("Delete", param_dict)
     if not rsp:
         print "ERROR:"
         print "   STATUS: " + api.get_response_status()
         print "   TYPE: " + str(api.get_error_type())
         print "   MESSAGE: " + api.get_error_message()
     return ""

The following parameters can be used in the script:

  • username: <username>

  • password: <password>

  • API version: <version number>

Creating Custom DNS Profile using CLI

l
[admin-cntrl1]: > configure customipamdnsprofile custom-dns-profile

[admin-cntrl1]: customipamdnsprofile>
cancel          Exit the current submode without saving
do              Execute a show command
name            Name of the Custom IPAM DNS Profile.
new             (Editor Mode) Create new object in editor mode
no              Remove field
save            Save and exit the current submode
script_params   (submode)
script_uri      Script URI of form controller://ipamdnsscripts/<file-name>
show_schema     show object schema
tenant_ref      Help string not found for argument
watch           Watch a given show command
where           Display the in-progress object
[admin-cntrl1]: customipamdnsprofile>

In the above configuration snippet, the custom_dns_script.py script is uploaded with the following attributes.

  • Name: custom-dns-profile

  • Username: dnsuser

  • Password: Password with the is_sensitive flag set to True

  • URI for the script: controller://ipamdnsscripts/custom_dns_script.py

Use the following syntax for uploading your script. controller://ipamdnsscripts/<script name>

The following is the output of the show customipamdnsprofile custom-dns-profilecommand.

[admin:10-10-25-160]: > show customipamdnsprofile custom-dns-profile
+------------------+--------------------------------------------------- Field               | Value                                                                                                                           ----------------------------------------------------------------------+
| uuid       |customipamdnsprofile-c12faa8a-f0eb-4128-a976-98d30391b9f2            | name              |custom-dns-profile                                                                                                    |script_uri         | controller://ipamdnsscripts/custom_dns_script.py                                      | script_params[1]  |                                                                                                                                         | name              | username                                                                                                                    | value             | dnsuser                                                                                                                         |is_sensitive       | False                                                                                                                              |is_dynamic         | False                                                                                                                              |script_params[2]   |                                                                                                                                         |name               | password                                                                                                                     |value              | <sensitive>                                                                                                                  |is_sensitive       | True                                                                                                                                |is_dynamic         | False                                                                                                                               |tenant_ref         | admin                                                                                                                             +------------------+--------------------------------------------------+