このセクションでは、カスタム IP アドレス管理プロファイルを構成する手順について説明します。

NSX Advanced Load Balancer は、仮想サービスの自動 IP アドレス割り当て機能を提供するために、NS1、TCPWave などのサードパーティの IP アドレス管理プロバイダとの統合をサポートします。

カスタム IP アドレス管理の構成

カスタム IP アドレス管理を構成する手順は次のとおりです。

  1. Python スクリプトをアップロードする

  2. カスタム IP アドレス管理プロファイルを作成する

  3. カスタム IP アドレス管理プロファイルをクラウドに添付する

  4. 仮想サービスを作成する

手順 1: Python スクリプトをアップロードする

一部の期待される関数を持つ Python スクリプト(以下の [Python スクリプト] セクションで説明)がコントローラにアップロードされます。このスクリプトで定義された関数は、サードパーティ プロバイダからの IP アドレス管理のために NSX Advanced Load Balancer が呼び出します。

スクリプトに加えて、次のキー/値パラメータを追加できます。これらのパラメータは、IP アドレス管理プロバイダと通信するためにスクリプト内の関数で使用されます。

  • ユーザー名 — <username>

  • パスワード — <password>(is_sensitive フラグが True に設定)

  • サーバ — 1.2.3.4

これらのパラメータ(プロバイダ固有の情報)は、IP アドレス管理プロバイダとの通信に使用されます。

注:
  • 上記のパラメータは、あくまでも単なる例です。スクリプトで使用されているメソッドに基づいて、パラメータがスクリプトに渡されます。

  • ファイル名は、拡張子が .py であり、PEP8 命名規則に準拠している必要があります。

ユーザー インターフェイスを使用した構成

  1. [テンプレート] > [プロファイル] > [カスタム IP アドレス管理/DNS] の順に移動し、[作成] をクリックします。

  2. [名前] を指定し、[スクリプト].py ファイルをアップロードします。

  3. [スクリプト パラメータの追加] をクリックし、次の詳細を入力します。

    ユーザー名:

    <username>

    パスワード:

    <password>(Sensitive チェックボックスがオンの状態)。

    サーバ:

    1.2.3.4

    wapi_version:

    network_view:

    デフォルト

    dns_view:

    デフォルト

  4. [保存] をクリックします。

CLI を使用した構成

  1. コントローラの /var/lib/avi/ipamdnsscripts/ の場所にスクリプトをコピーします。

  2. configure customipamdnsprofile を使用します。たとえば、次のように以下の属性を持つ custom_ipam_script.py スクリプトがアップロードされます。



手順 2:カスタム IP アドレス管理プロファイルを作成する

CLI を使用した構成

  1. configure ipamdnsproviderprofile <profile name> コマンドを使用して、IP アドレス管理プロバイダ プロファイルを作成します。

    注:

    プロファイル構成に使用するパラメータは、環境によって異なります。



  2. 目的の名前(例:custom-ipam-profile)を指定します。

  3. [タイプ] として IPAMDNS_TYPE_CUSTOM を選択します。

  4. custom_ipam_dns_profile_ref の値として custom-ipam-script を指定します(手順 1 で作成したスクリプト オブジェクトの名前)。



必要に応じて使用可能なサブネットを追加します。設定されている場合は、仮想サービスのプロビジョニング中に、[VIP アドレス割り当てネットワーク] で、使用可能な複数のサブネットから選択するオプションを使用できます(「手順 4:仮想サービスを作成する」セクションを参照)。設定されていない場合は、プロバイダから使用可能なすべてのネットワーク/サブネットが一覧表示されます。

手順 3:カスタム IP アドレス管理プロファイルをクラウドに添付する

ユーザー インターフェイスを使用した構成

  1. クラウドのカスタム IP アドレス管理オプションを関連付けるには、[インフラストラクチャ] > [クラウド] の順に移動し、手順 2 で作成したカスタム IP アドレス管理プロファイルを使用します。

CLI を使用した構成

  1. configure cloud <cloud name> を使用して、IP アドレス管理プロファイルをクラウドに添付します。

  2. ipam_provider_ref の値として custom-ipam-profile を指定します。



手順 4:仮想サービスを作成する

  1. 新しい仮想サービスを作成すると、カスタム IP アドレス管理プロファイルと、プロバイダを使用して IP アドレス管理レコードを自動的に作成するスクリプトが使用されます。

  2. 仮想サービスに次の必須属性を指定します。

    名前:

    仮想サービスの名前。

    VIP アドレス割り当てのネットワーク:

    IP アドレス割り当て用のネットワーク/サブネットを選択します(ユーザー インターフェイスを使用する場合にのみ必須)。

    サーバ:

    バックエンド サーバの IP アドレス。

ユーザー インターフェイスを使用した構成

  1. [アプリケーション] > [仮想サービス] の順に移動して、[作成] をクリックします。

  2. 仮想サービスの作成に成功すると、次に示すように IP アドレスが仮想サービスに割り当てられます。また、プロバイダを使用して IP アドレス管理レコードが仮想サービス用に作成されます。

CLI を使用した構成

  1. configure vsvsip <vsvip name> コマンドと configure virtualservice <vs name> コマンドを使用して、それぞれ vsvipvs を作成します。

Python スクリプト

  1. スクリプトには、必要なすべての関数と例外クラスが定義されている必要があります。そうでなければ、IP アドレス管理プロファイルの作成中に「カスタム IP アドレス管理プロファイル スクリプトに、必要な関数/例外クラス {function_or_exception_names} がありません」というエラー メッセージが表示されます。

  2. 必要な関数は次のとおりです。

    1. TestLogin

    2. GetAvailableNetworksAndSubnets

    3. GetIpamRecord

    4. CreateIpamRecord

    5. DeleteIpamRecord

    6. UpdateIpamRecord

  3. 必要な例外クラスは次のとおりです。

    1. CustomIpamAuthenticationErrorException

    2. CustomIpamRecordNotFoundException

    3. CustomIpamNoFreeIpException

    4. CustomIpamNotImplementedException

    5. CustomIpamGeneralException

  4. CustomIpamNotImplementedException は、スクリプトに関数/機能が実装されていない場合に発生する可能性があります。

  5. スクリプトのログ記録には、auth_paramslogger_name を使用することをお勧めします。スクリプトからログ ステートメントを保存するために、tenant-specific デバッグ ログ ファイル(名前:custom_ipam_script_<tenant_name>.log)が作成されます。管理テナントの場合、ログ ステートメントは /var/lib/avi/log/custom_ipam_script.log の場所にあります。

  6. プロバイダ スクリプトを検証するための別の Python スクリプトも提供されます。

注:

さまざまな IP アドレス管理プロバイダ用のサンプル スクリプトが開発中であり、完了次第使用可能になります。

スクリプト テンプレートの例を次に示します。

"""
This script allows the user to communicate with custom IPAM provider.

Required Functions
------------------
1. TestLogin: Function to verify provider credentials, used in the UI during IPAM profile configuration.
2. GetAvailableNetworksAndSubnets: Function to return available networks/subnets from the provider.
3. GetIpamRecord: Function to return the info of the given IPAM record.
4. CreateIpamRecord: Function to create an IPAM record with the provider.
5. DeleteIpamRecord: Funtion to delete a given IPAM record from the provider.
6. UpdateIpamRecord: Function to update a given IPAM record.

Required Exception Classes
--------------------------
1. CustomIpamAuthenticationErrorException: Raised when authentication fails.
2. CustomIpamRecordNotFoundException: Raised when given record not found.
3. CustomIpamNoFreeIpException: Raised when no free IP available in the given subnets/networks.
4. CustomIpamNotImplementedException: Raised when the functionality is not implemented.
5. CustomIpamGeneralException: Raised for other types of exceptions.
"""

class CustomIpamAuthenticationErrorException(Exception):
    """
    Raised when authentication fails.
    """
    pass

class CustomIpamRecordNotFoundException(Exception):
    """
    Raised when given record not found.
    """
    pass

class CustomIpamNoFreeIpException(Exception):
    """
    Raised when no free IP available in the given subnets/networks.
    """
    pass

class CustomIpamNotImplementedException(Exception):
    """
    Raised when the functionality is not implemented.
    """
    pass

class CustomIpamGeneralException(Exception):
    """
    Raised for other types of exceptions.
    """
    pass
    
    
def TestLogin(auth_params):
    """
    Function to validate user credentials. This function is called from IPAM profile 
    configuration UI page.
    Args
    ----
        auth_params: (dict of str: str)
            Parameters required for authentication. These are script parameters provided while 
            creating a Custom IPAM profile.
            Eg: auth_params can have following keys
            server: Server ip address of the custom IPAM provider
            username: self explanatory
            password: self explanatory 
            logger_name: logger name   
    Returns
    -------
        Return True on success    
    Raises
    ------
        CustomIpamNotImplementedException: if this function is not implemented.
        CustomIpamAuthenticationErrorException: if authentication fails.
    """
    1. Check all credentials params are given else raise an exception.
    2. Raise an exception if test login fails.
 
        
def GetAvailableNetworksAndSubnets(auth_params, ip_type):
    """ 
    Function to retrieve networks/subnets from the provider.
    Called from the IPAM profile configuration to populate usable subnets on the UI.
    Note: Subnets are represented in CIDR format.
    Args
    ----
        auth_params: (dict of str: str)
            Parameters required for authentication.
        ip_type: (str)
            IP type supported by the networks/subnets. Allowed values: V4_ONLY, V6_ONLY and V4_V6.
    Returns
    -------
        subnet_list: (list of dict of str : str)
            network (str): network id/name
            v4_subnet (str): V4 subnet
            v6_subnet (str): V6 subnet
            v4_available_ip_count (str): V4 free ips count of the network/v4_subnet
            v6_available_ip_count (str): V6 free ips count of the network/v6_subnet
        each dict has 5 keys: network, v4_subnet, v6_subnet, v4_available_ip_count, v6_available_ip_count
        v4_available_ip_count and v6_available_ip_count are optional, currenty this function returns the first 3 keys. returning counts is TBD.
    Raises
    ------
        None
    """
    1.  return all the available networks and subnets.     
 
    
def GetIpamRecord(auth_params, record_info):
    """
    Function to return the info of the given IPAM record.
    Args
    ----
        auth_params: (dict of str: str)
            Parameters required for authentication.
        record_info: (dict of str: str)
            id (str): uuid of vsvip.
            fqdns (list of str): list of fqdn from dns_info in vsvip. 
    Returns
    -------
        alloc_info(dict of str: str): 
            Dictionary of following keys
            v4_ip (str): IPv4 of the record
            v4_subnet (str): IPv4 subnet
            v6_ip (str): IPv6 of the record
            v6_subnet (str): IPv6 subnet
            network (str): network id/name
    Raises
    ------
        CustomIpamNotImplementedException: if this function is not implemented.
        CustomIpamGeneralException: if the api request fails.
    """
    1. Get the reference of the given IPAM record.
    2. Raise a valid error message if the given record not found.
    3. Return ipam record info like ipv4, ipv6, and its subnet/network name
    
    
def CreateIpamRecord(auth_params, record_info):
    """
    Implements a Custom Rest API to create an IPAM record.
    Args
    ----
        auth_params: (dict of str: str)
            Parameters required for authentication.
        record_info: (dict of str: str)
            New record information with following keys.
            id (str): uuid of vsvip.
            fqdns (list of str): list of fqdn from dns_info in vsvip.
            preferred_ip (str): the vsvip IPv4 if it's already configured by the user.
            preferred_ip6 (str): the vsvip IPv6 if it's already configured by the user.
            allocation_type (str): IP allocation type. Allowed values: V4_ONLY, V6_ONLY and V4_V6.
            nw_and_subnet_list (list of tuples : str): List of networks and subnets to use for new IPAM
            record IP allocation. Each tuple has 3 values (network, v4_subnet, v6_subnet).
    Returns
    -------
        alloc_info(dict of str: str): 
            Dictionary of following keys
            v4_ip (str): allocated IPv4
            v4_subnet (str): subnet used for IPv4 allocation.
            v6_ip (str): allocated IPv6
            v6_subnet (str): subnet used for IPv6 allocation.
            network (str): network used for IPv4/IPv6 allocation.
    Raises
    ------
        CustomIpamNoFreeIpException: if no free ip available.
        CustomIpamGeneralException: if create record fails for any other reason.
    """
    1. Either id or fqdns can be used as the name/identifier to create a new IPAM record, choose according to the requirements.
    2. If the preferred_ip/preferred_ip6 is set, call specific rest URL to create an IPAM record (according to the allocation_type).
    3. If the nw_and_subnet_list is empty call GetAvailableNetworksAndSubnets() to use any available
       subnets or networks for IP allocaton.
    4. Based on the allocation_type, build payload data and call specific rest URL to create an IPAM record.
    5. If create IPAM record fails, raise an exception.


def DeleteIpamRecord(auth_params, record_info):
    """
    Implements a Custom Rest API to delete an IPAM record.
    Args
    ----
        auth_params: (dict of str: str)
            Parameters required for authentication.
        record_info: (dict of str: str)
            Record to be deleted. Has following keys.
            id (str): uuid of vsvip.
            fqdns (list of str): list of fqdn from dns_info in vsvip.
    Returns
    -------
        True on successfully deleting the record.
    Raises
    ------
        CustomIpamRecordNotFoundException: if the given record not found
        CustomIpamGeneralException: if delete record request fails.
    """
    1. Get the reference of the given IPAM record.
    2. Raise a valid error message if the given record not found.
    3. Delete the record, if it fails, raise an exception.
              
              
def UpdateIpamRecord(auth_params, new_record_info, old_record_info):
    """
    Function to handle update IPAM record requests. Eg: Change of allocation_type from 
    V4_ONLY to V6_ONLY.
    Args
    ----
        auth_params: (dict of str: str)
            Parameters required for authentication.
        new_record_info: (dict of str: str)
            New record information with following keys.
            id (str): uuid of vsvip.
            fqdns (list of str): list of fqdn from dns_info in vsvip.
            preferred_ip (str): the vsvip IPv4 if it's already configured by the user.
            preferred_ip6 (str): the vsvip IPv6 if it's already configured by the user.
            allocation_type (str): IP allocation type. Allowed values: V4_ONLY, V6_ONLY and V4_V6.
            nw_and_subnet_list (list of tuples : str): List of networks and subnets to use for an 
                IPAM record IP allocation. Each tuple has 3 values (network, v4_subnet, v6_subnet)
        old_record_info: (dict of str: str)
            Old record information with following keys.
            id (str): uuid of vsvip.
            fqdns (list of str): list of fqdn from dns_info in vsvip of an old record.
            preferred_ip (str): old record's preferred IPv4.
            preferred_ip6 (str): old record's preferred IPv6.
            allocation_type (str): old record's IP allocation type. Allowed values: V4_ONLY, V6_ONLY and V4_V6.
            nw_and_subnet_list (list of tuples : str): List of networks and subnets used for an old IPAM
                record IP allocation. Each tuple has 3 values (network, v4_subnet, v6_subnet)
    Returns
    -------
        alloc_info(dict of str: str): 
            Dictionary of following keys
            v4_ip (str): allocated IPv4
            v4_subnet (str): subnet used for IPv4 allocation.
            v6_ip (str): allocated IPv6
            v6_subnet (str): subnet used for IPv6 allocation.
            network (str): network used for IPv4/IPv6 allocation.
    Raises
    ------
        CustomIpamNotImplementedException: if this function or specific update requests not implemented.
        CustomIpamRecordNotFoundException: if the given record not found
        CustomIpamGeneralException: if the api request fails for any other reason.
    """
    1. Raise CustomIpamNotImplementedException exception if the UpdateIpamRecord function or specific update request is not implemented.
    2. Get the reference of the given IPAM record.
    3. Raise a valid error message if the given record not found.
    4. Call specific rest URL based on the update type, if the update request fails, raise an exception.