本节介绍了如何使用 CLI 配置 DNS 配置文件。
上载 Python 脚本
将 Python 脚本上载到 NSX Advanced Load Balancer 以使用自定义 DNS 配置文件。使用以下脚本将所需的自定义 DNS 脚本上载到 NSX Advanced Load Balancer 控制器 中。
" 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 ""
可以在脚本中使用以下参数:
username:<username>
password:<password>
API version:<version number>
使用 CLI 创建自定义 DNS 配置文件
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>
在上面的配置片段中,上载的 custom_dns_script.py
脚本包含以下属性。
Name:
custom-dns-profile
Username:dnsuser
Password:将
is_sensitive
标记设置为 True 的密码脚本的 URI:controller://ipamdnsscripts/custom_dns_script.py
可以使用以下语法上载脚本:controller://ipamdnsscripts/<script name>
以下是 show customipamdnsprofile custom-dns-profile
命令的输出。
[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 +------------------+--------------------------------------------------+