Beispiel #1
0
def AddTCPMonitor(sess, name, interval=5, downtime=5):
    monitor = LBMON.lbmonitor()
    monitor.monitorname = name
    monitor.type = LBMON.lbmonitor.Type.TCP
    monitor.downtime = downtime
    monitor.interval = interval
    LBMON.lbmonitor.add(sess, monitor)
    return monitor
Beispiel #2
0
 def rmlbmonitor(self, client):
     try:
         mon = lbmonitor()
         mon.monitorname = "dns1"
         mon.type = "DNS"
         lbmonitor.delete(client, mon)
         print("rmlbmonitor - Done")
     except nitro_exception as e:
         print("Exception::rmlbmonitor::errorcode=" + str(e.errorcode) + ",message=" + e.message)
     except Exception as e:
         print("Exception::rmlbmonitor::message=" + str(e.args))
Beispiel #3
0
 def add_monitor(self, client) :
     try :
         obj = lbmonitor()
         obj.monitorname = "dns1"
         obj.type = lbmonitor.Type.DNS
         lbmonitor.add(client,obj)
         print("add_monitor - Done")
     except nitro_exception as e :
         print("Exception::add_monitor::errorcode="+str(e.errorcode)+",message="+ e.message)
     except Exception as e:
         print("Exception::add_monitor::message="+str(e.args))
Beispiel #4
0
 def rmlbmonitor(self, client):
     try:
         mon = lbmonitor()
         mon.monitorname = "dns1"
         mon.type = "DNS"
         lbmonitor.delete(client, mon)
         print("rmlbmonitor - Done")
     except nitro_exception as e:
         print("Exception::rmlbmonitor::errorcode=" + str(e.errorcode) +
               ",message=" + e.message)
     except Exception as e:
         print("Exception::rmlbmonitor::message=" + str(e.args))
Beispiel #5
0
def     AddTCPMonitor(sess,name,interval=3,downtime=3) :
        print 'going to add tcp monitor {}'.format(name)
        
        try :
                monitor = LBMON.lbmonitor.get(sess,name)
                if monitor :
                        print 'found monitor {}'.format(name)
                        return
        except NITROEXCEPTION.nitro_exception as e :
                print 'AddMonitor exception {}'.format(e.message)
        except Exception as e :
                print 'AddMonitor exception {}'.format(e.message)

        
        monitor = LBMON.lbmonitor()
        monitor.monitorname = name
        monitor.type = LBMON.lbmonitor.Type.TCP
        monitor.downtime = downtime
        monitor.interval = interval
        print 'going to add monitor'
        LBMON.lbmonitor.add(sess,monitor)
        print 'add monitor'
        return monitor
Beispiel #6
0
def main():

    module_specific_arguments = dict(

        monitorname=dict(type='str'),

        type=dict(
            type='str',
            choices=[
                'PING',
                'TCP',
                'HTTP',
                'TCP-ECV',
                'HTTP-ECV',
                'UDP-ECV',
                'DNS',
                'FTP',
                'LDNS-PING',
                'LDNS-TCP',
                'LDNS-DNS',
                'RADIUS',
                'USER',
                'HTTP-INLINE',
                'SIP-UDP',
                'SIP-TCP',
                'LOAD',
                'FTP-EXTENDED',
                'SMTP',
                'SNMP',
                'NNTP',
                'MYSQL',
                'MYSQL-ECV',
                'MSSQL-ECV',
                'ORACLE-ECV',
                'LDAP',
                'POP3',
                'CITRIX-XML-SERVICE',
                'CITRIX-WEB-INTERFACE',
                'DNS-TCP',
                'RTSP',
                'ARP',
                'CITRIX-AG',
                'CITRIX-AAC-LOGINPAGE',
                'CITRIX-AAC-LAS',
                'CITRIX-XD-DDC',
                'ND6',
                'CITRIX-WI-EXTENDED',
                'DIAMETER',
                'RADIUS_ACCOUNTING',
                'STOREFRONT',
                'APPC',
                'SMPP',
                'CITRIX-XNC-ECV',
                'CITRIX-XDM',
                'CITRIX-STA-SERVICE',
                'CITRIX-STA-SERVICE-NHOP',
            ]
        ),

        action=dict(
            type='str',
            choices=[
                'NONE',
                'LOG',
                'DOWN',
            ]
        ),
        respcode=dict(type='list'),
        httprequest=dict(type='str'),
        rtsprequest=dict(type='str'),
        customheaders=dict(type='str'),
        maxforwards=dict(type='float'),
        sipmethod=dict(
            type='str',
            choices=[
                'OPTIONS',
                'INVITE',
                'REGISTER',
            ]
        ),
        sipuri=dict(type='str'),
        sipreguri=dict(type='str'),
        send=dict(type='str'),
        recv=dict(type='str'),
        query=dict(type='str'),
        querytype=dict(
            type='str',
            choices=[
                'Address',
                'Zone',
                'AAAA',
            ]
        ),
        scriptname=dict(type='str'),
        scriptargs=dict(type='str'),
        dispatcherip=dict(type='str'),
        dispatcherport=dict(type='int'),
        username=dict(type='str'),
        password=dict(type='str'),
        secondarypassword=dict(type='str'),
        logonpointname=dict(type='str'),
        lasversion=dict(type='str'),
        radkey=dict(type='str'),
        radnasid=dict(type='str'),
        radnasip=dict(type='str'),
        radaccounttype=dict(type='float'),
        radframedip=dict(type='str'),
        radapn=dict(type='str'),
        radmsisdn=dict(type='str'),
        radaccountsession=dict(type='str'),
        lrtm=dict(
            type='str',
            choices=[
                'enabled',
                'disabled',
            ]
        ),
        deviation=dict(type='float'),
        units1=dict(
            type='str',
            choices=[
                'SEC',
                'MSEC',
                'MIN',
            ]
        ),
        interval=dict(type='int'),
        units3=dict(
            type='str',
            choices=[
                'SEC',
                'MSEC',
                'MIN',
            ]
        ),
        resptimeout=dict(type='int'),
        units4=dict(
            type='str',
            choices=[
                'SEC',
                'MSEC',
                'MIN',
            ]
        ),
        resptimeoutthresh=dict(type='float'),
        retries=dict(type='int'),
        failureretries=dict(type='int'),
        alertretries=dict(type='int'),
        successretries=dict(type='int'),
        downtime=dict(type='int'),
        units2=dict(
            type='str',
            choices=[
                'SEC',
                'MSEC',
                'MIN',
            ]
        ),
        destip=dict(type='str'),
        destport=dict(type='int'),
        reverse=dict(type='bool'),
        transparent=dict(type='bool'),
        iptunnel=dict(type='bool'),
        tos=dict(type='bool'),
        tosid=dict(type='float'),
        secure=dict(type='bool'),
        validatecred=dict(type='bool'),
        domain=dict(type='str'),
        ipaddress=dict(type='list'),
        group=dict(type='str'),
        filename=dict(type='str'),
        basedn=dict(type='str'),
        binddn=dict(type='str'),
        filter=dict(type='str'),
        attribute=dict(type='str'),
        database=dict(type='str'),
        oraclesid=dict(type='str'),
        sqlquery=dict(type='str'),
        evalrule=dict(type='str'),
        mssqlprotocolversion=dict(
            type='str',
            choices=[
                '70',
                '2000',
                '2000SP1',
                '2005',
                '2008',
                '2008R2',
                '2012',
                '2014',
            ]
        ),
        Snmpoid=dict(type='str'),
        snmpcommunity=dict(type='str'),
        snmpthreshold=dict(type='str'),
        snmpversion=dict(
            type='str',
            choices=[
                'V1',
                'V2',
            ]
        ),
        application=dict(type='str'),
        sitepath=dict(type='str'),
        storename=dict(type='str'),
        storefrontacctservice=dict(type='bool'),
        hostname=dict(type='str'),
        netprofile=dict(type='str'),
        originhost=dict(type='str'),
        originrealm=dict(type='str'),
        hostipaddress=dict(type='str'),
        vendorid=dict(type='float'),
        productname=dict(type='str'),
        firmwarerevision=dict(type='float'),
        authapplicationid=dict(type='list'),
        acctapplicationid=dict(type='list'),
        inbandsecurityid=dict(
            type='str',
            choices=[
                'NO_INBAND_SECURITY',
                'TLS',
            ]
        ),
        supportedvendorids=dict(type='list'),
        vendorspecificvendorid=dict(type='float'),
        vendorspecificauthapplicationids=dict(type='list'),
        vendorspecificacctapplicationids=dict(type='list'),
        storedb=dict(
            type='str',
            choices=[
                'enabled',
                'disabled',
            ]
        ),
        storefrontcheckbackendservices=dict(type='bool'),
        trofscode=dict(type='float'),
        trofsstring=dict(type='str'),
    )

    hand_inserted_arguments = dict()

    argument_spec = dict()
    argument_spec.update(module_specific_arguments)
    argument_spec.update(netscaler_common_arguments)
    argument_spec.update(hand_inserted_arguments)

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )

    module_result = dict(
        changed=False,
        failed=False,
        loglines=loglines,
    )

    # Fail the module if imports failed
    if not PYTHON_SDK_IMPORTED:
        module.fail_json(msg='Could not load nitro python sdk', **module_result)

    # Fallthrough to rest of execution
    client = get_nitro_client(module)

    try:
        client.login()
    except nitro_exception as e:
        msg = "nitro exception during login. errorcode=%s, message=%s" % (str(e.errorcode), e.message)
        module.fail_json(msg=msg)
    except Exception as e:
        if str(type(e)) == "<class 'requests.exceptions.ConnectionError'>":
            module.fail_json(msg='Connection error %s' % str(e))
        elif str(type(e)) == "<class 'requests.exceptions.SSLError'>":
            module.fail_json(msg='SSL Error %s' % str(e))
        else:
            module.fail_json(msg='Unexpected error during login %s' % str(e))

    # Instantiate lb monitor object
    readwrite_attrs = [
        'monitorname',
        'type',
        'action',
        'respcode',
        'httprequest',
        'rtsprequest',
        'customheaders',
        'maxforwards',
        'sipmethod',
        'sipuri',
        'sipreguri',
        'send',
        'recv',
        'query',
        'querytype',
        'scriptname',
        'scriptargs',
        'dispatcherip',
        'dispatcherport',
        'username',
        'password',
        'secondarypassword',
        'logonpointname',
        'lasversion',
        'radkey',
        'radnasid',
        'radnasip',
        'radaccounttype',
        'radframedip',
        'radapn',
        'radmsisdn',
        'radaccountsession',
        'lrtm',
        'deviation',
        'units1',
        'interval',
        'units3',
        'resptimeout',
        'units4',
        'resptimeoutthresh',
        'retries',
        'failureretries',
        'alertretries',
        'successretries',
        'downtime',
        'units2',
        'destip',
        'destport',
        'reverse',
        'transparent',
        'iptunnel',
        'tos',
        'tosid',
        'secure',
        'validatecred',
        'domain',
        'ipaddress',
        'group',
        'filename',
        'basedn',
        'binddn',
        'filter',
        'attribute',
        'database',
        'oraclesid',
        'sqlquery',
        'evalrule',
        'mssqlprotocolversion',
        'Snmpoid',
        'snmpcommunity',
        'snmpthreshold',
        'snmpversion',
        'application',
        'sitepath',
        'storename',
        'storefrontacctservice',
        'netprofile',
        'originhost',
        'originrealm',
        'hostipaddress',
        'vendorid',
        'productname',
        'firmwarerevision',
        'authapplicationid',
        'acctapplicationid',
        'inbandsecurityid',
        'supportedvendorids',
        'vendorspecificvendorid',
        'vendorspecificauthapplicationids',
        'vendorspecificacctapplicationids',
        'storedb',
        'storefrontcheckbackendservices',
        'trofscode',
        'trofsstring',
    ]

    readonly_attrs = [
        'lrtmconf',
        'lrtmconfstr',
        'dynamicresponsetimeout',
        'dynamicinterval',
        'multimetrictable',
        'dup_state',
        'dup_weight',
        'weight',
    ]

    immutable_attrs = [
        'monitorname',
        'type',
        'units1',
        'units3',
        'units4',
        'units2',
        'Snmpoid',
        'hostname',
        'servicename',
        'servicegroupname',
    ]

    transforms = {
        'storefrontcheckbackendservices': ['bool_yes_no'],
        'secure': ['bool_yes_no'],
        'tos': ['bool_yes_no'],
        'validatecred': ['bool_yes_no'],
        'storefrontacctservice': ['bool_yes_no'],
        'iptunnel': ['bool_yes_no'],
        'transparent': ['bool_yes_no'],
        'reverse': ['bool_yes_no'],
        'lrtm': [lambda v: v.upper()],
        'storedb': [lambda v: v.upper()],
    }

    lbmonitor_proxy = ConfigProxy(
        actual=lbmonitor(),
        client=client,
        attribute_values_dict=module.params,
        readwrite_attrs=readwrite_attrs,
        readonly_attrs=readonly_attrs,
        immutable_attrs=immutable_attrs,
        transforms=transforms,
    )

    try:
        ensure_feature_is_enabled(client, 'LB')

        if module.params['state'] == 'present':
            log('Applying actions for state present')
            if not lbmonitor_exists(client, module):
                if not module.check_mode:
                    log('Adding monitor')
                    lbmonitor_proxy.add()
                    if module.params['save_config']:
                        client.save_config()
                module_result['changed'] = True
            elif not lbmonitor_identical(client, module, lbmonitor_proxy):

                # Check if we try to change value of immutable attributes
                immutables_changed = get_immutables_intersection(lbmonitor_proxy, diff_list(client, module, lbmonitor_proxy).keys())
                if immutables_changed != []:
                    diff = diff_list(client, module, lbmonitor_proxy)
                    msg = 'Cannot update immutable attributes %s' % (immutables_changed,)
                    module.fail_json(msg=msg, diff=diff, **module_result)

                if not module.check_mode:
                    log('Updating monitor')
                    lbmonitor_proxy.update()
                    if module.params['save_config']:
                        client.save_config()
                module_result['changed'] = True
            else:
                log('Doing nothing for monitor')
                module_result['changed'] = False

            # Sanity check for result
            log('Sanity checks for state present')
            if not module.check_mode:
                if not lbmonitor_exists(client, module):
                    module.fail_json(msg='lb monitor does not exist', **module_result)
                if not lbmonitor_identical(client, module, lbmonitor_proxy):
                    module.fail_json(
                        msg='lb monitor is not configured correctly',
                        diff=diff_list(client, module, lbmonitor_proxy),
                        **module_result
                    )

        elif module.params['state'] == 'absent':
            log('Applying actions for state absent')
            if lbmonitor_exists(client, module):
                if not module.check_mode:
                    lbmonitor_proxy.delete()
                    if module.params['save_config']:
                        client.save_config()
                module_result['changed'] = True
            else:
                module_result['changed'] = False

            # Sanity check for result
            log('Sanity checks for state absent')
            if not module.check_mode:
                if lbmonitor_exists(client, module):
                    module.fail_json(msg='lb monitor still exists', **module_result)

        module_result['actual_attributes'] = lbmonitor_proxy.get_actual_rw_attributes(filter='monitorname')
    except nitro_exception as e:
        msg = "nitro exception errorcode=%s, message=%s" % (str(e.errorcode), e.message)
        module.fail_json(msg=msg, **module_result)

    client.logout()

    module.exit_json(**module_result)
def main():
    from ansible.module_utils.netscaler import ConfigProxy, get_nitro_client, netscaler_common_arguments, log, loglines

    try:
        from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception
        from nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbmonitor import lbmonitor
        python_sdk_imported = True
    except ImportError as e:
        python_sdk_imported = False

    module_specific_arguments = dict(
        monitorname=dict(type='str', ),
        type=dict(
            type='str',
            choices=[
                u'PING', u'TCP', u'HTTP', u'TCP-ECV', u'HTTP-ECV', u'UDP-ECV',
                u'DNS', u'FTP', u'LDNS-PING', u'LDNS-TCP', u'LDNS-DNS',
                u'RADIUS', u'USER', u'HTTP-INLINE', u'SIP-UDP', u'SIP-TCP',
                u'LOAD', u'FTP-EXTENDED', u'SMTP', u'SNMP', u'NNTP', u'MYSQL',
                u'MYSQL-ECV', u'MSSQL-ECV', u'ORACLE-ECV', u'LDAP', u'POP3',
                u'CITRIX-XML-SERVICE', u'CITRIX-WEB-INTERFACE', u'DNS-TCP',
                u'RTSP', u'ARP', u'CITRIX-AG', u'CITRIX-AAC-LOGINPAGE',
                u'CITRIX-AAC-LAS', u'CITRIX-XD-DDC', u'ND6',
                u'CITRIX-WI-EXTENDED', u'DIAMETER', u'RADIUS_ACCOUNTING',
                u'STOREFRONT', u'APPC', u'SMPP', u'CITRIX-XNC-ECV',
                u'CITRIX-XDM', u'CITRIX-STA-SERVICE',
                u'CITRIX-STA-SERVICE-NHOP'
            ]),
        action=dict(type='str', choices=[u'NONE', u'LOG', u'DOWN']),
        respcode=dict(type='list', ),
        httprequest=dict(type='str', ),
        rtsprequest=dict(type='str', ),
        customheaders=dict(type='str', ),
        maxforwards=dict(type='float', ),
        sipmethod=dict(type='str',
                       choices=[u'OPTIONS', u'INVITE', u'REGISTER']),
        sipuri=dict(type='str', ),
        sipreguri=dict(type='str', ),
        send=dict(type='str', ),
        recv=dict(type='str', ),
        query=dict(type='str', ),
        querytype=dict(type='str', choices=[u'Address', u'Zone', u'AAAA']),
        scriptname=dict(type='str', ),
        scriptargs=dict(type='str', ),
        dispatcherip=dict(type='str', ),
        dispatcherport=dict(type='int', ),
        username=dict(type='str', ),
        password=dict(type='str', ),
        secondarypassword=dict(type='str', ),
        logonpointname=dict(type='str', ),
        lasversion=dict(type='str', ),
        radkey=dict(type='str', ),
        radnasid=dict(type='str', ),
        radnasip=dict(type='str', ),
        radaccounttype=dict(type='float', ),
        radframedip=dict(type='str', ),
        radapn=dict(type='str', ),
        radmsisdn=dict(type='str', ),
        radaccountsession=dict(type='str', ),
        lrtm=dict(type='str', choices=[u'ENABLED', u'DISABLED']),
        deviation=dict(type='float', ),
        units1=dict(type='str', choices=[u'SEC', u'MSEC', u'MIN']),
        interval=dict(type='int', ),
        units3=dict(type='str', choices=[u'SEC', u'MSEC', u'MIN']),
        resptimeout=dict(type='int', ),
        units4=dict(type='str', choices=[u'SEC', u'MSEC', u'MIN']),
        resptimeoutthresh=dict(type='float', ),
        retries=dict(type='int', ),
        failureretries=dict(type='int', ),
        alertretries=dict(type='int', ),
        successretries=dict(type='int', ),
        downtime=dict(type='int', ),
        units2=dict(type='str', choices=[u'SEC', u'MSEC', u'MIN']),
        destip=dict(type='str', ),
        destport=dict(type='int', ),
        state=dict(type='str', choices=[u'ENABLED', u'DISABLED']),
        reverse=dict(type='str', choices=[u'YES', u'NO']),
        transparent=dict(type='str', choices=[u'YES', u'NO']),
        iptunnel=dict(type='str', choices=[u'YES', u'NO']),
        tos=dict(type='str', choices=[u'YES', u'NO']),
        tosid=dict(type='float', ),
        secure=dict(type='str', choices=[u'YES', u'NO']),
        validatecred=dict(type='str', choices=[u'YES', u'NO']),
        domain=dict(type='str', ),
        ipaddress=dict(type='list', ),
        group=dict(type='str', ),
        filename=dict(type='str', ),
        basedn=dict(type='str', ),
        binddn=dict(type='str', ),
        filter=dict(type='str', ),
        attribute=dict(type='str', ),
        database=dict(type='str', ),
        oraclesid=dict(type='str', ),
        sqlquery=dict(type='str', ),
        evalrule=dict(type='str', ),
        mssqlprotocolversion=dict(type='str',
                                  choices=[
                                      u'70', u'2000', u'2000SP1', u'2005',
                                      u'2008', u'2008R2', u'2012', u'2014'
                                  ]),
        Snmpoid=dict(type='str', ),
        snmpcommunity=dict(type='str', ),
        snmpthreshold=dict(type='str', ),
        snmpversion=dict(type='str', choices=[u'V1', u'V2']),
        metrictable=dict(type='str', ),
        application=dict(type='str', ),
        sitepath=dict(type='str', ),
        storename=dict(type='str', ),
        storefrontacctservice=dict(type='str', choices=[u'YES', u'NO']),
        hostname=dict(type='str', ),
        netprofile=dict(type='str', ),
        originhost=dict(type='str', ),
        originrealm=dict(type='str', ),
        hostipaddress=dict(type='str', ),
        vendorid=dict(type='float', ),
        productname=dict(type='str', ),
        firmwarerevision=dict(type='float', ),
        authapplicationid=dict(type='list', ),
        acctapplicationid=dict(type='list', ),
        inbandsecurityid=dict(type='str',
                              choices=[u'NO_INBAND_SECURITY', u'TLS']),
        supportedvendorids=dict(type='list', ),
        vendorspecificvendorid=dict(type='float', ),
        vendorspecificauthapplicationids=dict(type='list', ),
        vendorspecificacctapplicationids=dict(type='list', ),
        kcdaccount=dict(type='str', ),
        storedb=dict(type='str', choices=[u'ENABLED', u'DISABLED']),
        storefrontcheckbackendservices=dict(type='str',
                                            choices=[u'YES', u'NO']),
        trofscode=dict(type='float', ),
        trofsstring=dict(type='str', ),
        metric=dict(type='str', ),
        metricthreshold=dict(type='float', ),
        metricweight=dict(type='float', ),
        servicename=dict(type='str', ),
        servicegroupname=dict(type='str', ),
    )

    argument_spec = dict()
    argument_spec.update(module_specific_arguments)
    argument_spec.update(netscaler_common_arguments)

    # Hand wired arguments
    #argument_spec.update(dict( servicegroupbindings=dict(type='list')))

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )

    module_result = dict(
        changed=False,
        failed=False,
        loglines=loglines,
    )

    # Fail the module if imports failed
    if not python_sdk_imported:
        module.fail_json(msg='Could not load nitro python sdk')

    # Fallthrough to rest of execution
    client = get_nitro_client(module)
    client.login()

    # Instantiate lb vserver object
    readwrite_attrs = [
        u'monitorname', u'type', u'action', u'respcode', u'httprequest',
        u'rtsprequest', u'customheaders', u'maxforwards', u'sipmethod',
        u'sipuri', u'sipreguri', u'send', u'recv', u'query', u'querytype',
        u'scriptname', u'scriptargs', u'dispatcherip', u'dispatcherport',
        u'username', u'password', u'secondarypassword', u'logonpointname',
        u'lasversion', u'radkey', u'radnasid', u'radnasip', u'radaccounttype',
        u'radframedip', u'radapn', u'radmsisdn', u'radaccountsession', u'lrtm',
        u'deviation', u'units1', u'interval', u'units3', u'resptimeout',
        u'units4', u'resptimeoutthresh', u'retries', u'failureretries',
        u'alertretries', u'successretries', u'downtime', u'units2', u'destip',
        u'destport', u'state', u'reverse', u'transparent', u'iptunnel', u'tos',
        u'tosid', u'secure', u'validatecred', u'domain', u'ipaddress',
        u'group', u'filename', u'basedn', u'binddn', u'filter', u'attribute',
        u'database', u'oraclesid', u'sqlquery', u'evalrule',
        u'mssqlprotocolversion', u'Snmpoid', u'snmpcommunity',
        u'snmpthreshold', u'snmpversion', u'metrictable', u'application',
        u'sitepath', u'storename', u'storefrontacctservice', u'hostname',
        u'netprofile', u'originhost', u'originrealm', u'hostipaddress',
        u'vendorid', u'productname', u'firmwarerevision', u'authapplicationid',
        u'acctapplicationid', u'inbandsecurityid', u'supportedvendorids',
        u'vendorspecificvendorid', u'vendorspecificauthapplicationids',
        u'vendorspecificacctapplicationids', u'kcdaccount', u'storedb',
        u'storefrontcheckbackendservices', u'trofscode', u'trofsstring',
        u'sslprofile', u'metric', u'metricthreshold', u'metricweight',
        u'servicename', u'servicegroupname'
    ]
    readonly_attrs = [
        u'lrtmconf', u'lrtmconfstr', u'dynamicresponsetimeout',
        u'dynamicinterval', u'multimetrictable', u'dup_state', u'dup_weight',
        u'weight', u'__count'
    ]

    lbmonitor_proxy = ConfigProxy(
        actual=lbmonitor(),
        client=client,
        attribute_values_dict=module.params,
        readwrite_attrs=readwrite_attrs,
        readonly_attrs=readonly_attrs,
    )
Beispiel #8
0
def main():

    module_specific_arguments = dict(

        monitorname=dict(type='str'),

        type=dict(
            type='str',
            choices=[
                'PING',
                'TCP',
                'HTTP',
                'TCP-ECV',
                'HTTP-ECV',
                'UDP-ECV',
                'DNS',
                'FTP',
                'LDNS-PING',
                'LDNS-TCP',
                'LDNS-DNS',
                'RADIUS',
                'USER',
                'HTTP-INLINE',
                'SIP-UDP',
                'SIP-TCP',
                'LOAD',
                'FTP-EXTENDED',
                'SMTP',
                'SNMP',
                'NNTP',
                'MYSQL',
                'MYSQL-ECV',
                'MSSQL-ECV',
                'ORACLE-ECV',
                'LDAP',
                'POP3',
                'CITRIX-XML-SERVICE',
                'CITRIX-WEB-INTERFACE',
                'DNS-TCP',
                'RTSP',
                'ARP',
                'CITRIX-AG',
                'CITRIX-AAC-LOGINPAGE',
                'CITRIX-AAC-LAS',
                'CITRIX-XD-DDC',
                'ND6',
                'CITRIX-WI-EXTENDED',
                'DIAMETER',
                'RADIUS_ACCOUNTING',
                'STOREFRONT',
                'APPC',
                'SMPP',
                'CITRIX-XNC-ECV',
                'CITRIX-XDM',
                'CITRIX-STA-SERVICE',
                'CITRIX-STA-SERVICE-NHOP',
            ]
        ),

        action=dict(
            type='str',
            choices=[
                'NONE',
                'LOG',
                'DOWN',
            ]
        ),
        respcode=dict(type='list'),
        httprequest=dict(type='str'),
        rtsprequest=dict(type='str'),
        customheaders=dict(type='str'),
        maxforwards=dict(type='float'),
        sipmethod=dict(
            type='str',
            choices=[
                'OPTIONS',
                'INVITE',
                'REGISTER',
            ]
        ),
        sipuri=dict(type='str'),
        sipreguri=dict(type='str'),
        send=dict(type='str'),
        recv=dict(type='str'),
        query=dict(type='str'),
        querytype=dict(
            type='str',
            choices=[
                'Address',
                'Zone',
                'AAAA',
            ]
        ),
        scriptname=dict(type='str'),
        scriptargs=dict(type='str'),
        dispatcherip=dict(type='str'),
        dispatcherport=dict(type='int'),
        username=dict(type='str'),
        password=dict(type='str'),
        secondarypassword=dict(type='str'),
        logonpointname=dict(type='str'),
        lasversion=dict(type='str'),
        radkey=dict(type='str'),
        radnasid=dict(type='str'),
        radnasip=dict(type='str'),
        radaccounttype=dict(type='float'),
        radframedip=dict(type='str'),
        radapn=dict(type='str'),
        radmsisdn=dict(type='str'),
        radaccountsession=dict(type='str'),
        lrtm=dict(
            type='str',
            choices=[
                'enabled',
                'disabled',
            ]
        ),
        deviation=dict(type='float'),
        units1=dict(
            type='str',
            choices=[
                'SEC',
                'MSEC',
                'MIN',
            ]
        ),
        interval=dict(type='int'),
        units3=dict(
            type='str',
            choices=[
                'SEC',
                'MSEC',
                'MIN',
            ]
        ),
        resptimeout=dict(type='int'),
        units4=dict(
            type='str',
            choices=[
                'SEC',
                'MSEC',
                'MIN',
            ]
        ),
        resptimeoutthresh=dict(type='float'),
        retries=dict(type='int'),
        failureretries=dict(type='int'),
        alertretries=dict(type='int'),
        successretries=dict(type='int'),
        downtime=dict(type='int'),
        units2=dict(
            type='str',
            choices=[
                'SEC',
                'MSEC',
                'MIN',
            ]
        ),
        destip=dict(type='str'),
        destport=dict(type='int'),
        reverse=dict(type='bool'),
        transparent=dict(type='bool'),
        iptunnel=dict(type='bool'),
        tos=dict(type='bool'),
        tosid=dict(type='float'),
        secure=dict(type='bool'),
        validatecred=dict(type='bool'),
        domain=dict(type='str'),
        ipaddress=dict(type='list'),
        group=dict(type='str'),
        filename=dict(type='str'),
        basedn=dict(type='str'),
        binddn=dict(type='str'),
        filter=dict(type='str'),
        attribute=dict(type='str'),
        database=dict(type='str'),
        oraclesid=dict(type='str'),
        sqlquery=dict(type='str'),
        evalrule=dict(type='str'),
        mssqlprotocolversion=dict(
            type='str',
            choices=[
                '70',
                '2000',
                '2000SP1',
                '2005',
                '2008',
                '2008R2',
                '2012',
                '2014',
            ]
        ),
        Snmpoid=dict(type='str'),
        snmpcommunity=dict(type='str'),
        snmpthreshold=dict(type='str'),
        snmpversion=dict(
            type='str',
            choices=[
                'V1',
                'V2',
            ]
        ),
        application=dict(type='str'),
        sitepath=dict(type='str'),
        storename=dict(type='str'),
        storefrontacctservice=dict(type='bool'),
        hostname=dict(type='str'),
        netprofile=dict(type='str'),
        originhost=dict(type='str'),
        originrealm=dict(type='str'),
        hostipaddress=dict(type='str'),
        vendorid=dict(type='float'),
        productname=dict(type='str'),
        firmwarerevision=dict(type='float'),
        authapplicationid=dict(type='list'),
        acctapplicationid=dict(type='list'),
        inbandsecurityid=dict(
            type='str',
            choices=[
                'NO_INBAND_SECURITY',
                'TLS',
            ]
        ),
        supportedvendorids=dict(type='list'),
        vendorspecificvendorid=dict(type='float'),
        vendorspecificauthapplicationids=dict(type='list'),
        vendorspecificacctapplicationids=dict(type='list'),
        storedb=dict(
            type='str',
            choices=[
                'enabled',
                'disabled',
            ]
        ),
        storefrontcheckbackendservices=dict(type='bool'),
        trofscode=dict(type='float'),
        trofsstring=dict(type='str'),
    )

    hand_inserted_arguments = dict()

    argument_spec = dict()
    argument_spec.update(module_specific_arguments)
    argument_spec.update(netscaler_common_arguments)
    argument_spec.update(hand_inserted_arguments)

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )

    module_result = dict(
        changed=False,
        failed=False,
        loglines=loglines,
    )

    # Fail the module if imports failed
    if not PYTHON_SDK_IMPORTED:
        module.fail_json(msg='Could not load nitro python sdk', **module_result)

    # Fallthrough to rest of execution
    client = get_nitro_client(module)

    try:
        client.login()
    except nitro_exception as e:
        msg = "nitro exception during login. errorcode=%s, message=%s" % (str(e.errorcode), e.message)
        module.fail_json(msg=msg)
    except Exception as e:
        if str(type(e)) == "<class 'requests.exceptions.ConnectionError'>":
            module.fail_json(msg='Connection error %s' % str(e))
        elif str(type(e)) == "<class 'requests.exceptions.SSLError'>":
            module.fail_json(msg='SSL Error %s' % str(e))
        else:
            module.fail_json(msg='Unexpected error during login %s' % str(e))

    # Instantiate lb monitor object
    readwrite_attrs = [
        'monitorname',
        'type',
        'action',
        'respcode',
        'httprequest',
        'rtsprequest',
        'customheaders',
        'maxforwards',
        'sipmethod',
        'sipuri',
        'sipreguri',
        'send',
        'recv',
        'query',
        'querytype',
        'scriptname',
        'scriptargs',
        'dispatcherip',
        'dispatcherport',
        'username',
        'password',
        'secondarypassword',
        'logonpointname',
        'lasversion',
        'radkey',
        'radnasid',
        'radnasip',
        'radaccounttype',
        'radframedip',
        'radapn',
        'radmsisdn',
        'radaccountsession',
        'lrtm',
        'deviation',
        'units1',
        'interval',
        'units3',
        'resptimeout',
        'units4',
        'resptimeoutthresh',
        'retries',
        'failureretries',
        'alertretries',
        'successretries',
        'downtime',
        'units2',
        'destip',
        'destport',
        'reverse',
        'transparent',
        'iptunnel',
        'tos',
        'tosid',
        'secure',
        'validatecred',
        'domain',
        'ipaddress',
        'group',
        'filename',
        'basedn',
        'binddn',
        'filter',
        'attribute',
        'database',
        'oraclesid',
        'sqlquery',
        'evalrule',
        'mssqlprotocolversion',
        'Snmpoid',
        'snmpcommunity',
        'snmpthreshold',
        'snmpversion',
        'application',
        'sitepath',
        'storename',
        'storefrontacctservice',
        'netprofile',
        'originhost',
        'originrealm',
        'hostipaddress',
        'vendorid',
        'productname',
        'firmwarerevision',
        'authapplicationid',
        'acctapplicationid',
        'inbandsecurityid',
        'supportedvendorids',
        'vendorspecificvendorid',
        'vendorspecificauthapplicationids',
        'vendorspecificacctapplicationids',
        'storedb',
        'storefrontcheckbackendservices',
        'trofscode',
        'trofsstring',
    ]

    readonly_attrs = [
        'lrtmconf',
        'lrtmconfstr',
        'dynamicresponsetimeout',
        'dynamicinterval',
        'multimetrictable',
        'dup_state',
        'dup_weight',
        'weight',
    ]

    immutable_attrs = [
        'monitorname',
        'type',
        'units1',
        'units3',
        'units4',
        'units2',
        'Snmpoid',
        'hostname',
        'servicename',
        'servicegroupname',
    ]

    transforms = {
        'storefrontcheckbackendservices': ['bool_yes_no'],
        'secure': ['bool_yes_no'],
        'tos': ['bool_yes_no'],
        'validatecred': ['bool_yes_no'],
        'storefrontacctservice': ['bool_yes_no'],
        'iptunnel': ['bool_yes_no'],
        'transparent': ['bool_yes_no'],
        'reverse': ['bool_yes_no'],
        'lrtm': [lambda v: v.upper()],
        'storedb': [lambda v: v.upper()],
    }

    lbmonitor_proxy = ConfigProxy(
        actual=lbmonitor(),
        client=client,
        attribute_values_dict=module.params,
        readwrite_attrs=readwrite_attrs,
        readonly_attrs=readonly_attrs,
        immutable_attrs=immutable_attrs,
        transforms=transforms,
    )

    try:
        ensure_feature_is_enabled(client, 'LB')

        if module.params['state'] == 'present':
            log('Applying actions for state present')
            if not lbmonitor_exists(client, module):
                if not module.check_mode:
                    log('Adding monitor')
                    lbmonitor_proxy.add()
                    if module.params['save_config']:
                        client.save_config()
                module_result['changed'] = True
            elif not lbmonitor_identical(client, module, lbmonitor_proxy):

                # Check if we try to change value of immutable attributes
                immutables_changed = get_immutables_intersection(lbmonitor_proxy, diff_list(client, module, lbmonitor_proxy).keys())
                if immutables_changed != []:
                    diff = diff_list(client, module, lbmonitor_proxy)
                    msg = 'Cannot update immutable attributes %s' % (immutables_changed,)
                    module.fail_json(msg=msg, diff=diff, **module_result)

                if not module.check_mode:
                    log('Updating monitor')
                    lbmonitor_proxy.update()
                    if module.params['save_config']:
                        client.save_config()
                module_result['changed'] = True
            else:
                log('Doing nothing for monitor')
                module_result['changed'] = False

            # Sanity check for result
            log('Sanity checks for state present')
            if not module.check_mode:
                if not lbmonitor_exists(client, module):
                    module.fail_json(msg='lb monitor does not exist', **module_result)
                if not lbmonitor_identical(client, module, lbmonitor_proxy):
                    module.fail_json(
                        msg='lb monitor is not configured correctly',
                        diff=diff_list(client, module, lbmonitor_proxy),
                        **module_result
                    )

        elif module.params['state'] == 'absent':
            log('Applying actions for state absent')
            if lbmonitor_exists(client, module):
                if not module.check_mode:
                    lbmonitor_proxy.delete()
                    if module.params['save_config']:
                        client.save_config()
                module_result['changed'] = True
            else:
                module_result['changed'] = False

            # Sanity check for result
            log('Sanity checks for state absent')
            if not module.check_mode:
                if lbmonitor_exists(client, module):
                    module.fail_json(msg='lb monitor still exists', **module_result)

        module_result['actual_attributes'] = lbmonitor_proxy.get_actual_rw_attributes(filter='monitorname')
    except nitro_exception as e:
        msg = "nitro exception errorcode=%s, message=%s" % (str(e.errorcode), e.message)
        module.fail_json(msg=msg, **module_result)

    client.logout()

    module.exit_json(**module_result)
Beispiel #9
0
def main():
    from ansible.module_utils.netscaler import ConfigProxy, get_nitro_client, netscaler_common_arguments, log, loglines, ensure_feature_is_enabled

    try:
        from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception
        from nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbmonitor import lbmonitor
        from nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbmonbindings_service_binding import lbmonbindings_service_binding
        from nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbmonitor_service_binding import lbmonitor_service_binding
        from nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbmonitor_servicegroup_binding import lbmonitor_servicegroup_binding
        python_sdk_imported = True
    except ImportError as e:
        python_sdk_imported = False

    module_specific_arguments = dict(
        
        monitorname=dict(type='str'),
        
        type=dict(
        type='str',
        choices=[u'PING', u'TCP', u'HTTP', u'TCP-ECV', u'HTTP-ECV', u'UDP-ECV', u'DNS', u'FTP', u'LDNS-PING', u'LDNS-TCP', u'LDNS-DNS', u'RADIUS', u'USER', u'HTTP-INLINE', u'SIP-UDP', u'SIP-TCP', u'LOAD', u'FTP-EXTENDED', u'SMTP', u'SNMP', u'NNTP', u'MYSQL', u'MYSQL-ECV', u'MSSQL-ECV', u'ORACLE-ECV', u'LDAP', u'POP3', u'CITRIX-XML-SERVICE', u'CITRIX-WEB-INTERFACE', u'DNS-TCP', u'RTSP', u'ARP', u'CITRIX-AG', u'CITRIX-AAC-LOGINPAGE', u'CITRIX-AAC-LAS', u'CITRIX-XD-DDC', u'ND6', u'CITRIX-WI-EXTENDED', u'DIAMETER', u'RADIUS_ACCOUNTING', u'STOREFRONT', u'APPC', u'SMPP', u'CITRIX-XNC-ECV', u'CITRIX-XDM', u'CITRIX-STA-SERVICE', u'CITRIX-STA-SERVICE-NHOP']
        ),
        
        action=dict(
            type='str',
            choices=[u'NONE', u'LOG', u'DOWN']
        ),
        
        respcode=dict(type='list'),
        httprequest=dict(type='str',),
        rtsprequest=dict(type='str'),
        customheaders=dict(type='str'),
        maxforwards=dict(type='float'),
        sipmethod=dict(
            type='str',
            choices=[u'OPTIONS', u'INVITE', u'REGISTER']
        ),
        sipuri=dict(type='str'),
        sipreguri=dict(type='str'),
        send=dict(type='str'),
        recv=dict(type='str'),
        query=dict(type='str'),
        querytype=dict(
            type='str',
            choices=[u'Address', u'Zone', u'AAAA']
        ),
        scriptname=dict(type='str'),
        scriptargs=dict(type='str'),
        dispatcherip=dict(type='str'),
        dispatcherport=dict(type='int'),
        username=dict(type='str'),
        password=dict(type='str'),
        secondarypassword=dict(type='str'),
        logonpointname=dict(type='str'),
        lasversion=dict(type='str'),
        radkey=dict(type='str'),
        radnasid=dict(type='str'),
        radnasip=dict(type='str'),
        radaccounttype=dict(type='float'),
        radframedip=dict(type='str'),
        radapn=dict(type='str'),
        radmsisdn=dict(type='str'),
        radaccountsession=dict(type='str'),
        lrtm=dict(
            type='str',
            choices=[u'ENABLED', u'DISABLED']
        ),
        deviation=dict(type='float'),
        units1=dict(
            type='str',
            choices=[u'SEC', u'MSEC', u'MIN']
        ),
        interval=dict(type='int'),
        units3=dict(
            type='str',
            choices=[u'SEC', u'MSEC', u'MIN']
        ),
        resptimeout=dict(type='int'),
        units4=dict(
            type='str',
            choices=[u'SEC', u'MSEC', u'MIN']
        ),
        resptimeoutthresh=dict(type='float'),
        retries=dict(type='int'),
        failureretries=dict(type='int'),
        alertretries=dict(type='int'),
        successretries=dict(type='int'),
        downtime=dict(type='int'),
        units2=dict(
            type='str',
            choices=[u'SEC', u'MSEC', u'MIN']
        ),
        destip=dict(type='str'),
        destport=dict(type='int'),
        state=dict(
            type='str',
            choices=[u'ENABLED', u'DISABLED']
        ),
        reverse=dict(
            type='str',
            choices=[u'YES', u'NO']
        ),
        transparent=dict(
            type='str',
            choices=[u'YES', u'NO']
        ),
        iptunnel=dict(
            type='str',
            choices=[u'YES', u'NO']
        ),
        tos=dict(
            type='str',
            choices=[u'YES', u'NO']
        ),
        tosid=dict(type='float'),
        secure=dict(
            type='str',
            choices=[u'YES', u'NO']
        ),
        validatecred=dict(
            type='str',
            choices=[u'YES', u'NO']
        ),
        domain=dict(type='str'),
        ipaddress=dict(type='list'),
        group=dict(type='str'),
        filename=dict(type='str'),
        basedn=dict(type='str'),
        binddn=dict(type='str'),
        filter=dict(type='str'),
        attribute=dict(type='str'),
        database=dict(type='str'),
        oraclesid=dict(type='str'),
        sqlquery=dict(type='str'),
        evalrule=dict(type='str'),
        mssqlprotocolversion=dict(
            type='str',
            choices=[u'70', u'2000', u'2000SP1', u'2005', u'2008', u'2008R2', u'2012', u'2014']
        ),
        Snmpoid=dict(type='str'),
        snmpcommunity=dict(type='str'),
        snmpthreshold=dict(type='str'),
        snmpversion=dict(
            type='str',
            choices=[u'V1', u'V2']
        ),
        application=dict(type='str'),
        sitepath=dict(type='str'),
        storename=dict(type='str'),
        storefrontacctservice=dict(
            type='str',
            choices=[u'YES', u'NO']
        ),
        netprofile=dict(type='str'),
        originhost=dict(type='str'),
        originrealm=dict(type='str'),
        hostipaddress=dict(type='str'),
        vendorid=dict(type='float'),
        productname=dict(type='str'),
        firmwarerevision=dict(type='float'),
        authapplicationid=dict(type='list'),
        acctapplicationid=dict(type='list'),
        inbandsecurityid=dict(
            type='str',
            choices=[u'NO_INBAND_SECURITY', u'TLS']
        ),
        supportedvendorids=dict(type='list'),
        vendorspecificvendorid=dict(type='float'),
        vendorspecificauthapplicationids=dict(type='list'),
        vendorspecificacctapplicationids=dict(type='list'),
        storedb=dict(
            type='str',
            choices=[u'ENABLED', u'DISABLED']
        ),
        storefrontcheckbackendservices=dict(
            type='str',
            choices=[u'YES', u'NO']
        ),
        trofscode=dict(type='float'),
        trofsstring=dict(type='str'),
    )


    argument_spec = dict()
    argument_spec.update(module_specific_arguments)
    argument_spec.update(netscaler_common_arguments)

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )

    module_result = dict(
        changed=False,
        failed=False,
        loglines=loglines,
    )

    # Fail the module if imports failed
    if not python_sdk_imported:
        module.fail_json(msg='Could not load nitro python sdk', **module_result)

    # Fallthrough to rest of execution
    client = get_nitro_client(module)
    client.login()

    # Instantiate lb monitor object
    readwrite_attrs = [
        'monitorname', 
        'type', 
        'action', 
        'respcode', 
        'httprequest', 
        'rtsprequest', 
        'customheaders', 
        'maxforwards', 
        'sipmethod', 
        'sipuri', 
        'sipreguri', 
        'send', 
        'recv', 
        'query', 
        'querytype', 
        'scriptname', 
        'scriptargs', 
        'dispatcherip', 
        'dispatcherport', 
        'username', 
        'password', 
        'secondarypassword', 
        'logonpointname', 
        'lasversion', 
        'radkey', 
        'radnasid', 
        'radnasip', 
        'radaccounttype', 
        'radframedip', 
        'radapn', 
        'radmsisdn', 
        'radaccountsession', 
        'lrtm', 
        'deviation', 
        'units1', 
        'interval', 
        'units3', 
        'resptimeout', 
        'units4', 
        'resptimeoutthresh', 
        'retries', 
        'failureretries', 
        'alertretries', 
        'successretries', 
        'downtime', 
        'units2', 
        'destip', 
        'destport', 
        'state', 
        'reverse', 
        'transparent', 
        'iptunnel', 
        'tos', 
        'tosid', 
        'secure', 
        'validatecred', 
        'domain', 
        'ipaddress', 
        'group', 
        'filename', 
        'basedn', 
        'binddn', 
        'filter', 
        'attribute', 
        'database', 
        'oraclesid',
        'sqlquery', 
        'evalrule', 
        'mssqlprotocolversion', 
        'Snmpoid', 
        'snmpcommunity', 
        'snmpthreshold', 
        'snmpversion', 
        'application', 
        'sitepath', 
        'storename', 
        'storefrontacctservice', 
        'netprofile', 
        'originhost', 
        'originrealm', 
        'hostipaddress', 
        'vendorid', 
        'productname', 
        'firmwarerevision', 
        'authapplicationid', 
        'acctapplicationid', 
        'inbandsecurityid', 
        'supportedvendorids', 
        'vendorspecificvendorid', 
        'vendorspecificauthapplicationids', 
        'vendorspecificacctapplicationids', 
        'storedb', 
        'storefrontcheckbackendservices', 
        'trofscode', 
        'trofsstring', 
    ]

    readonly_attrs = [
        'lrtmconf', 
        'lrtmconfstr', 
        'dynamicresponsetimeout', 
        'dynamicinterval', 
        'multimetrictable', 
        'dup_state', 
        'dup_weight', 
        'weight', 
    ]

    lbmonitor_proxy = ConfigProxy(
        actual=lbmonitor(),
        client=client,
        attribute_values_dict = module.params,
        readwrite_attrs=readwrite_attrs,
        readonly_attrs=readonly_attrs,
        json_encodes=['evalrule'],
    )

    def lbmonitor_exists():
        log('Entering lbmonitor_exists')
        if lbmonitor.count_filtered(client, 'monitorname:%s' % module.params['monitorname']) > 0:
            return True
        else:
            return False

    def lbmonitor_identical():
        log('Entering lbmonitor_identical')

        count = lbmonitor.count_filtered(client, 'monitorname:%s' % module.params['monitorname'])
        if count == 0:
            return False

        lbmonitor_list = lbmonitor.get_filtered(client, 'monitorname:%s' % module.params['monitorname'])
        diff_dict = lbmonitor_proxy.diff_object(lbmonitor_list[0])

        # Skipping hashed fields since the cannot be compared directly
        # TODO emulate the hash function for effective equality comparison
        hashed_fields = [
            'password',
            'secondarypassword',
            'radkey',
        ]
        for key in hashed_fields:
            if key in diff_dict:
                del diff_dict[key]

        if diff_dict == {}:
            return True
        else:
            return False

    def get_configured_service_bindings():

        readwrite_attrs = [
            'weight', 
            'name', 
            'passive',
            'monstate',
        ]
        readonly_attrs = []

        configured_bindings = {}
        if 'servicebindings' in module.params and module.params['servicebindings'] is not None:
            for binding in module.params['servicebindings']:
                attribute_values_dict = copy.deepcopy(binding)
                attribute_values_dict['monitor_name'] = module.params['monitorname']
                key = binding['name'].strip()
                configured_bindings[key] = ConfigProxy(
                        actual=service_lbmonitor_binding(),
                        client=client,
                        attribute_values_dict=attribute_values_dict,
                        readwrite_attrs=readwrite_attrs,
                        readonly_attrs=readonly_attrs,
                    )
        return configured_bindings

    def get_actual_service_bindings():
        log('entering get_actual_service_bindings')
        if lbmonbindings_service_binding.count(client, module.params['monitorname']) == 0:
            return {}
        bindigs_list = lbmonbindings_service_binding.get(client, module.params['monitorname'])
        bindings = {}
        for item in bindigs_list:
            key = item.servicename
            log('bound service name %s' % key)
            bindings[key] = item

        return bindings

    def service_bindings_identical():
        log('service_bindings_identical')

        # Compare servicegroup keysets
        configured_servicegroup_bindings = get_configured_servicegroup_bindings()
        servicegroup_bindings = get_actual_servicegroup_bindings()
        configured_keyset = set(configured_servicegroup_bindings.keys())
        service_keyset = set(servicegroup_bindings.keys())
        log('len %s' % len(configured_keyset ^ service_keyset))
        if len(configured_keyset ^ service_keyset) > 0:
            return False

        # Compare servicegroup item to item
        for key in configured_servicegroup_bindings.keys():
            conf = configured_servicegroup_bindings[key]
            serv = servicegroup_bindings[key]
            log('sg diff %s' % conf.diff_object(serv))
            if not conf.has_equal_attributes(serv):
                return False

        # Compare service keysets
        configured_service_bindings = get_configured_service_bindings()
        service_bindings = get_actual_service_bindings()
        configured_keyset = set(configured_service_bindings.keys())
        service_keyset = set(service_bindings.keys())
        if len(configured_keyset ^ service_keyset) > 0:
            return False

        # Compare service item to item
        for key in configured_service_bindings.keys():
            conf = configured_service_bindings[key]
            serv = service_bindings[key]
            log('s diff %s' % conf.diff_object(serv))
            if not conf.has_equal_attributes(serv):
                return False

        # Fallthrough to success
        return True

    def delete_all_bindings():
        log('Entering delete_all_bindings')
        actual_bindings = get_actual_service_bindings()
        for binding in actual_bindings.values():
            lbmonitor_service_binding.delete(client, binding)

    def sync_bindings():
        delete_all_bindings()
        if 'servicebindings' in module.params and module.params['servicebindings'] is not None:
            for servicebinding in module.params['servicebindings']:
                attribute_values_dict  = copy.deepcopy(servicebinding)
                readwrite_attrs = [
                    'servicename',
                    'servicegroupname',
                    'weight',
                    'monitorname',
                ]
                attribute_values_dict['monitorname'] = module.params['monitorname']
                readonly_attrs = []
                binding_proxy = ConfigProxy(
                    actual=lbmonitor_service_binding(),
                    client=client,
                    attribute_values_dict=attribute_values_dict,
                    readwrite_attrs=readwrite_attrs,
                    readonly_attrs=readonly_attrs,
                )
                binding_proxy.add()

    def get_configured_servicegroup_bindings():

        readwrite_attrs = [
            'servicegroupname', 
            'port', 
            'state',
            'hashid',
            'serverid',
            'customserverid',
            'weight',
            'passive',
            'monstate'
        ]
        readonly_attrs = []

        configured_bindings = {}
        if 'servicegroupbindings' in module.params and module.params['servicegroupbindings'] is not None:
            for binding in module.params['servicegroupbindings']:
                attribute_values_dict = copy.deepcopy(binding)
                attribute_values_dict['monitor_name'] = module.params['monitorname']
                key = binding['servicegroupname'].strip()
                configured_bindings[key] = ConfigProxy(
                        actual=servicegroup_lbmonitor_binding(),
                        client=client,
                        attribute_values_dict=attribute_values_dict,
                        readwrite_attrs=readwrite_attrs,
                        readonly_attrs=readonly_attrs,
                    )
        return configured_bindings

    def diff_list():
        return lbmonitor_proxy.diff_object(lbmonitor.get_filtered(client, 'monitorname:%s' % module.params['monitorname'])[0]),

    try:
        ensure_feature_is_enabled(client, 'LB')

        #get_actual_servicegroup_bindings()
        if module.params['operation'] == 'present':
            if not lbmonitor_exists():
                if not module.check_mode:
                    log('Adding monitor')
                    lbmonitor_proxy.add()
                    lbmonitor_proxy.update()
                    sync_bindings()
                    client.save_config()
                module_result['changed'] = True
            elif not lbmonitor_identical():
                if not module.check_mode:
                    log('Updating monitor')
                    lbmonitor_proxy.update()
                    client.save_config()
                module_result['changed'] = True
            else:
                log('Doing nothing for monitor')
                module_result['changed'] = False

            # Sanity check for result
            if not module.check_mode:
                if not lbmonitor_exists():
                    module.fail_json(msg='Monitor does not seem to exist', **module_result)
                if not lbmonitor_identical():
                    module.fail_json(
                        msg='Monitor is not configured according to parameters given',
                        diff=diff_list(),
                        **module_result
                    )
            get_actual_service_bindings()

        elif module.params['operation'] == 'absent':
            if lbmonitor_exists():
                if not module.check_mode:
                    lbmonitor_proxy.delete()
                    client.save_config()
                module_result['changed'] = True
            else:
                module_result['changed'] = False

            # Sanity check for result
            if not module.check_mode:
                if lbmonitor_exists():
                    module.fail_json(msg='Server seems to be present', **module_result)

        module_result['actual_attributes'] = lbmonitor_proxy.get_actual_rw_attributes(filter='monitorname')
    except nitro_exception as e:
        msg = "nitro exception errorcode=" + str(e.errorcode) + ",message=" + e.message
        module.fail_json(msg=msg, **module_result)

    client.logout()

    module.exit_json(**module_result)