def unset_gslb_service_cip(self, client) : try : gslbservice1 = gslbservice() gslbservice1.servicename = "svc0" arr=["cip"] gslbservice.unset(client, gslbservice1, arr) print("unset_gslb_service_cip - Done") except nitro_exception as e : print("Exception::unset_gslb_service_cip::errorcode="+str(e.errorcode)+",message="+ e.message) except Exception as e: print("Exception::unset_gslb_service_cip::message="+str(e.args))
def set_gslb_service_cip(self, client) : try : gslbservice1 = gslbservice() gslbservice1.servicename = "svc0" gslbservice1.cip = "enabled" gslbservice.update(client, gslbservice1) print("set_gslb_service_cip - Done") except nitro_exception as e : print("Exception::set_gslb_service_cip::errorcode="+str(e.errorcode)+",message="+ e.message) except Exception as e: print("Exception::set_gslb_service_cip::message="+str(e.args))
def add_gslb_service(self, client) : try : port=80 no=100 gslbservice1 = gslbservice() gslbservice1.servicename = "svc0" gslbservice1.ip = "10.102.3.239" gslbservice1.maxclient = no gslbservice1.port = port gslbservice1.sitename = "bangalore1" gslbservice1.servicetype = "http" gslbservice.add(client, gslbservice1) print("add_gslb_service - Done") except nitro_exception as e : print("Exception::add_gslb_service::errorcode="+str(e.errorcode)+",message="+ e.message) except Exception as e: print("Exception::add_gslb_service::message="+str(e.args))
def main(): module_specific_arguments = dict( servicename=dict(type='str'), cnameentry=dict(type='str'), servername=dict(type='str'), servicetype=dict( type='str', choices=[ 'HTTP', 'FTP', 'TCP', 'UDP', 'SSL', 'SSL_BRIDGE', 'SSL_TCP', 'NNTP', 'ANY', 'SIP_UDP', 'SIP_TCP', 'SIP_SSL', 'RADIUS', 'RDP', 'RTSP', 'MYSQL', 'MSSQL', 'ORACLE', ] ), port=dict(type='int'), publicip=dict(type='str'), publicport=dict(type='int'), maxclient=dict(type='float'), healthmonitor=dict(type='bool'), sitename=dict(type='str'), cip=dict( type='str', choices=[ 'enabled', 'disabled', ] ), cipheader=dict(type='str'), sitepersistence=dict( type='str', choices=[ 'ConnectionProxy', 'HTTPRedirect', 'NONE', ] ), siteprefix=dict(type='str'), clttimeout=dict(type='float'), maxbandwidth=dict(type='float'), downstateflush=dict( type='str', choices=[ 'enabled', 'disabled', ] ), maxaaausers=dict(type='float'), monthreshold=dict(type='float'), hashid=dict(type='float'), comment=dict(type='str'), appflowlog=dict( type='str', choices=[ 'enabled', 'disabled', ] ), ipaddress=dict(type='str'), ) hand_inserted_arguments = dict( monitor_bindings=dict(type='list'), ) argument_spec = dict() argument_spec.update(netscaler_common_arguments) argument_spec.update(module_specific_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') # 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)) readwrite_attrs = [ 'servicename', 'cnameentry', 'ip', 'servername', 'servicetype', 'port', 'publicip', 'publicport', 'maxclient', 'healthmonitor', 'sitename', 'cip', 'cipheader', 'sitepersistence', 'siteprefix', 'clttimeout', 'maxbandwidth', 'downstateflush', 'maxaaausers', 'monthreshold', 'hashid', 'comment', 'appflowlog', 'ipaddress', ] readonly_attrs = [ 'gslb', 'svrstate', 'svreffgslbstate', 'gslbthreshold', 'gslbsvcstats', 'monstate', 'preferredlocation', 'monitor_state', 'statechangetimesec', 'tickssincelaststatechange', 'threshold', 'clmonowner', 'clmonview', '__count', ] immutable_attrs = [ 'servicename', 'cnameentry', 'ip', 'servername', 'servicetype', 'port', 'sitename', 'state', 'cipheader', 'cookietimeout', 'clttimeout', 'svrtimeout', 'viewip', 'monitor_name_svc', 'newname', ] transforms = { 'healthmonitor': ['bool_yes_no'], 'cip': [lambda v: v.upper()], 'downstateflush': [lambda v: v.upper()], 'appflowlog': [lambda v: v.upper()], } # params = copy.deepcopy(module.params) module.params['ip'] = module.params['ipaddress'] # Instantiate config proxy gslb_service_proxy = ConfigProxy( actual=gslbservice(), client=client, attribute_values_dict=module.params, transforms=transforms, readwrite_attrs=readwrite_attrs, readonly_attrs=readonly_attrs, immutable_attrs=immutable_attrs, ) try: ensure_feature_is_enabled(client, 'GSLB') # Apply appropriate state if module.params['state'] == 'present': if not gslb_service_exists(client, module): if not module.check_mode: gslb_service_proxy.add() sync_monitor_bindings(client, module) if module.params['save_config']: client.save_config() module_result['changed'] = True elif not all_identical(client, module, gslb_service_proxy): # Check if we try to change value of immutable attributes immutables_changed = get_immutables_intersection(gslb_service_proxy, diff_list(client, module, gslb_service_proxy).keys()) if immutables_changed != []: module.fail_json( msg='Cannot update immutable attributes %s' % (immutables_changed,), diff=diff_list(client, module, gslb_service_proxy), **module_result ) # Update main configuration object if not gslb_service_identical(client, module, gslb_service_proxy): if not module.check_mode: gslb_service_proxy.update() # Update monitor bindigns if not monitor_bindings_identical(client, module): if not module.check_mode: sync_monitor_bindings(client, module) # Fallthrough to save and change status update module_result['changed'] = True if module.params['save_config']: client.save_config() else: module_result['changed'] = False # Sanity check for state if not module.check_mode: if not gslb_service_exists(client, module): module.fail_json(msg='GSLB service does not exist', **module_result) if not gslb_service_identical(client, module, gslb_service_proxy): module.fail_json( msg='GSLB service differs from configured', diff=diff_list(client, module, gslb_service_proxy), **module_result ) if not monitor_bindings_identical(client, module): module.fail_json( msg='Monitor bindings differ from configured', diff=diff_list(client, module, gslb_service_proxy), **module_result ) elif module.params['state'] == 'absent': if gslb_service_exists(client, module): if not module.check_mode: gslb_service_proxy.delete() if module.params['save_config']: client.save_config() module_result['changed'] = True else: module_result['changed'] = False # Sanity check for state if not module.check_mode: if gslb_service_exists(client, module): module.fail_json(msg='GSLB service still exists', **module_result) 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(): module_specific_arguments = dict( servicename=dict(type='str'), cnameentry=dict(type='str'), servername=dict(type='str'), servicetype=dict(type='str', choices=[ 'HTTP', 'FTP', 'TCP', 'UDP', 'SSL', 'SSL_BRIDGE', 'SSL_TCP', 'NNTP', 'ANY', 'SIP_UDP', 'SIP_TCP', 'SIP_SSL', 'RADIUS', 'RDP', 'RTSP', 'MYSQL', 'MSSQL', 'ORACLE', ]), port=dict(type='int'), publicip=dict(type='str'), publicport=dict(type='int'), maxclient=dict(type='float'), healthmonitor=dict(type='bool'), sitename=dict(type='str'), cip=dict(type='str', choices=[ 'enabled', 'disabled', ]), cipheader=dict(type='str'), sitepersistence=dict(type='str', choices=[ 'ConnectionProxy', 'HTTPRedirect', 'NONE', ]), siteprefix=dict(type='str'), clttimeout=dict(type='float'), maxbandwidth=dict(type='float'), downstateflush=dict(type='str', choices=[ 'enabled', 'disabled', ]), maxaaausers=dict(type='float'), monthreshold=dict(type='float'), hashid=dict(type='float'), comment=dict(type='str'), appflowlog=dict(type='str', choices=[ 'enabled', 'disabled', ]), ipaddress=dict(type='str'), ) hand_inserted_arguments = dict(monitor_bindings=dict(type='list'), ) argument_spec = dict() argument_spec.update(netscaler_common_arguments) argument_spec.update(module_specific_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') # 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)) readwrite_attrs = [ 'servicename', 'cnameentry', 'ip', 'servername', 'servicetype', 'port', 'publicip', 'publicport', 'maxclient', 'healthmonitor', 'sitename', 'cip', 'cipheader', 'sitepersistence', 'siteprefix', 'clttimeout', 'maxbandwidth', 'downstateflush', 'maxaaausers', 'monthreshold', 'hashid', 'comment', 'appflowlog', 'ipaddress', ] readonly_attrs = [ 'gslb', 'svrstate', 'svreffgslbstate', 'gslbthreshold', 'gslbsvcstats', 'monstate', 'preferredlocation', 'monitor_state', 'statechangetimesec', 'tickssincelaststatechange', 'threshold', 'clmonowner', 'clmonview', '__count', ] immutable_attrs = [ 'servicename', 'cnameentry', 'ip', 'servername', 'servicetype', 'port', 'sitename', 'state', 'cipheader', 'cookietimeout', 'clttimeout', 'svrtimeout', 'viewip', 'monitor_name_svc', 'newname', ] transforms = { 'healthmonitor': ['bool_yes_no'], 'cip': [lambda v: v.upper()], 'downstateflush': [lambda v: v.upper()], 'appflowlog': [lambda v: v.upper()], } # params = copy.deepcopy(module.params) module.params['ip'] = module.params['ipaddress'] # Instantiate config proxy gslb_service_proxy = ConfigProxy( actual=gslbservice(), client=client, attribute_values_dict=module.params, transforms=transforms, readwrite_attrs=readwrite_attrs, readonly_attrs=readonly_attrs, immutable_attrs=immutable_attrs, ) try: ensure_feature_is_enabled(client, 'GSLB') # Apply appropriate state if module.params['state'] == 'present': if not gslb_service_exists(client, module): if not module.check_mode: gslb_service_proxy.add() sync_monitor_bindings(client, module) if module.params['save_config']: client.save_config() module_result['changed'] = True elif not all_identical(client, module, gslb_service_proxy): # Check if we try to change value of immutable attributes immutables_changed = get_immutables_intersection( gslb_service_proxy, diff_list(client, module, gslb_service_proxy).keys()) if immutables_changed != []: module.fail_json( msg='Cannot update immutable attributes %s' % (immutables_changed, ), diff=diff_list(client, module, gslb_service_proxy), **module_result) # Update main configuration object if not gslb_service_identical(client, module, gslb_service_proxy): if not module.check_mode: gslb_service_proxy.update() # Update monitor bindigns if not monitor_bindings_identical(client, module): if not module.check_mode: sync_monitor_bindings(client, module) # Fallthrough to save and change status update module_result['changed'] = True if module.params['save_config']: client.save_config() else: module_result['changed'] = False # Sanity check for state if not module.check_mode: if not gslb_service_exists(client, module): module.fail_json(msg='GSLB service does not exist', **module_result) if not gslb_service_identical(client, module, gslb_service_proxy): module.fail_json( msg='GSLB service differs from configured', diff=diff_list(client, module, gslb_service_proxy), **module_result) if not monitor_bindings_identical(client, module): module.fail_json( msg='Monitor bindings differ from configured', diff=diff_list(client, module, gslb_service_proxy), **module_result) elif module.params['state'] == 'absent': if gslb_service_exists(client, module): if not module.check_mode: gslb_service_proxy.delete() if module.params['save_config']: client.save_config() module_result['changed'] = True else: module_result['changed'] = False # Sanity check for state if not module.check_mode: if gslb_service_exists(client, module): module.fail_json(msg='GSLB service still exists', **module_result) 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)