def action_disable(args, nitro): if args.object == "csvserver": csvserver = NSCSVServer() csvserver.set_name(args.object_name) NSCSVServer.disable(nitro, csvserver) print "Disabled cs vserver: %s" % args.object_name if args.object == "lbvserver": lbvserver = NSLBVServer() lbvserver.set_name(args.object_name) NSLBVServer.disable(nitro, lbvserver) print "Disabled lb vserver: %s" % args.object_name if args.object == "server": server = NSServer() server.set_name(args.object_name) server.set_delay(args.delay) server.set_graceful(args.graceful) NSServer.disable(nitro, server) print "Disabled server: %s" % args.object_name if args.object == "service": service = NSService() service.set_name(args.object_name) service.set_delay(args.delay) service.set_graceful(args.graceful) NSService.disable(nitro, service) print "Disabled service: %s" % args.object_name
def vserver_delete(v_name, **connection_args): ''' Delete a lb vserver CLI Example: .. code-block:: bash salt '*' netscaler.vserver_delete 'vserverName' ''' ret = True vserver = _vserver_get(v_name, **connection_args) if vserver is None: return False nitro = _connect(**connection_args) if nitro is None: return False try: NSLBVServer.delete(nitro, vserver) except NSNitroError as e: log.debug( 'netscaler module error - NSVServer.delete() failed: {0}'.format( e.message)) ret = False _disconnect(nitro) return ret
def action_get(args, nitro): if args.object == "csvserver": csvserver = NSCSVServer() csvserver.set_name(args.object_name) csvserver = NSCSVServer.get(nitro, csvserver) print "--- CS vserver: " + csvserver.get_name() + " ---" for k in sorted(csvserver.options.iterkeys(), key=lambda k: k): print "\t%s: %s" % (k, csvserver.options[k]) if args.object == "lbvserver": lbvserver = NSLBVServer() lbvserver.set_name(args.object_name) lbvserver = NSLBVServer.get(nitro, lbvserver) print "--- LB vserver: " + lbvserver.get_name() + " ---" for k in sorted(lbvserver.options.iterkeys(), key=lambda k: k): print "\t%s: %s" % (k, lbvserver.options[k]) if args.object == "server": server = NSServer() server.set_name(args.object_name) server = NSServer.get(nitro, server) print "--- Server: " + server.get_name() + " ---" for k in sorted(server.options.iterkeys(), key=lambda k: k): print "\t%s: %s" % (k, server.options[k]) if args.object == "service": service = NSService() service.set_name(args.object_name) service = NSService.get(nitro, service) print "--- Service: " + service.get_name() + " ---" for k in sorted(service.options.iterkeys(), key=lambda k: k): print "\t%s: %s" % (k, service.options[k])
def _vserver_get(v_name, **connection_args): nitro = _connect(**connection_args) vserver = NSLBVServer() vserver.set_name(v_name) if nitro is None: return None try: vserver = NSLBVServer.get(nitro, vserver) except NSNitroError, e: log.debug('netscaler module error - NSLBVServer.get() failed: {0}'.format(e.message)) vserver = None
def _vserver_get(v_name, **connection_args): nitro = _connect(**connection_args) vserver = NSLBVServer() vserver.set_name(v_name) if nitro is None: return None try: vserver = NSLBVServer.get(nitro, vserver) except NSNitroError as error: log.debug("netscaler module error - NSLBVServer.get() failed: {0}".format(error)) vserver = None _disconnect(nitro) return vserver
def _vserver_get(v_name, **connection_args): nitro = _connect(**connection_args) vserver = NSLBVServer() vserver.set_name(v_name) if nitro is None: return None try: vserver = NSLBVServer.get(nitro, vserver) except NSNitroError, e: log.debug( 'netscaler module error - NSLBVServer.get() failed: {0}'.format( e.message)) vserver = None
def _vserver_get(v_name, **connection_args): nitro = _connect(**connection_args) vserver = NSLBVServer() vserver.set_name(v_name) if nitro is None: return None try: vserver = NSLBVServer.get(nitro, vserver) except NSNitroError as error: log.debug("netscaler module error - NSLBVServer.get() failed: %s", error) vserver = None _disconnect(nitro) return vserver
def _vserver_get_all(**connection_args): nitro = _connect(**connection_args) vservers = None try: vservers = NSLBVServer.get_all(nitro) except NSNitroError, e: log.debug('netscaler module error - NSLBVServer.get_all() failed: {0}'.format(e.message))
def action_rename(args, nitro): if args.object == "csvserver": csvserver = NSCSVServer() csvserver.set_name(args.object_name) csvserver.set_newname(args.newname) NSCSVServer.rename(nitro, csvserver) print "Renamed CS vserver from '%s' to '%s'." % (args.object_name, args.newname) if args.object == "lbvserver": lbvserver = NSLBVServer() lbvserver.set_name(args.object_name) lbvserver.set_newname(args.newname) NSLBVServer.rename(nitro, lbvserver) print "Renamed LB vserver from '%s' to '%s'." % (args.object_name, args.newname) if args.object == "server": server = NSServer() server.set_name(args.object_name) server.set_newname(args.newname) NSServer.rename(nitro, server) print "Renamed server from '%s' to '%s'." % (args.object_name, args.newname) if args.object == "service": service = NSService() service.set_name(args.object_name) service.set_newname(args.newname) NSService.rename(nitro, service) print "Renamed service from '%s' to '%s'." % (args.object_name, args.newname)
def vserver_delete(v_name, **connection_args): ''' Delete a lb vserver CLI Example: .. code-block:: bash salt '*' netscaler.vserver_delete 'vserverName' ''' ret = True vserver = _vserver_get(v_name, **connection_args) if vserver is None: return False nitro = _connect(**connection_args) if nitro is None: return False try: NSLBVServer.delete(nitro, vserver) except NSNitroError, e: log.debug('netscaler module error - NSVServer.delete() failed: {0}'.format(e.message)) ret = False
def action_enable(args, nitro): if args.object == "csvserver": csvserver = NSCSVServer() csvserver.set_name(args.object_name) NSCSVServer.enable(nitro, csvserver) print "Enabled cs vserver: %s" % args.object_name if args.object == "lbvserver": lbvserver = NSLBVServer() lbvserver.set_name(args.object_name) NSLBVServer.enable(nitro, lbvserver) print "Enabled lb vserver: %s" % args.object_name if args.object == "server": server = NSServer() server.set_name(args.object_name) NSServer.enable(nitro, server) print "Enabled server: %s" % args.object_name if args.object == "service": service = NSService() service.set_name(args.object_name) NSService.enable(nitro, service) print "Enabled service: %s" % args.object_name
def vserver_delete(v_name, **connection_args): """ Delete a lb vserver CLI Example: .. code-block:: bash salt '*' netscaler.vserver_delete 'vserverName' """ ret = True vserver = _vserver_get(v_name, **connection_args) if vserver is None: return False nitro = _connect(**connection_args) if nitro is None: return False try: NSLBVServer.delete(nitro, vserver) except NSNitroError as error: log.debug("netscaler module error - NSVServer.delete() failed: {0}".format(error)) ret = False _disconnect(nitro) return ret
def lbvserver_delete(lbvs_name, **connection_args): """ remove/delete sg to a monitor CLI Example: .. code-block:: bash salt '*' netscaler.lbvserver_delete 'lbvsName' """ ret = True nitro = _connect(**connection_args) if nitro is None: return False lbvs = NSLBVServer() lbvs.set_name(lbvs_name) try: NSLBVServer.delete(nitro, lbvs) except NSNitroError as error: log.debug("netscaler module error - NSLBVServer.delete() failed: %s", error) ret = False _disconnect(nitro) return ret
parser.add_argument('--saveconfig', action='store_true', help='save loadbalancer config') parser.add_argument('--dargs', action='store_true', help='show service') args = parser.parse_args() if args.dargs: print(args) sys.exit(0) nitro = NSNitro(args.lbip, args.user, args.password) try: nitro.login() if args.enablelbvserver: lbvserver = NSLBVServer() lbvserver.set_name(args.enablelbvserver) NSLBVServer.enable(nitro, lbvserver) print "Enabled lb vserver: %s" % args.enablelbvserver sys.exit(0) if args.saveconfig: NSConfig.save(nitro) print "Saved Netscaler configuration" sys.exit(0) if args.disablelbvserver: lbvserver = NSLBVServer() lbvserver.set_name(args.disablelbvserver) NSLBVServer.disable(nitro, lbvserver) print "Disabled lb vserver: %s" % args.disablelbvserver
def vserver_add(v_name, v_ip, v_port, v_type, **connection_args): ''' Add a new lb vserver CLI Example: .. code-block:: bash salt '*' netscaler.vserver_add 'vserverName' 'vserverIP' 'vserverPort' 'vserverType' salt '*' netscaler.vserver_add 'alex.patate.chaude.443' '1.2.3.4' '443' 'SSL' ''' ret = True if vserver_exists(v_name, **connection_args): return False nitro = _connect(**connection_args) if nitro is None: return False vserver = NSLBVServer() vserver.set_name(v_name) vserver.set_ipv46(v_ip) vserver.set_port(v_port) vserver.set_servicetype(v_type.upper()) try: NSLBVServer.add(nitro, vserver) except NSNitroError, e: log.debug('netscaler module error - NSLBVServer.add() failed: {0}'.format(e.message)) ret = False
def lbvserver_update(lbvs_name, persistencetype, rule, resrule, **connection_args): """ update lb vs server CLI Example: .. code-block:: bash salt '*' netscaler.lbvserver_update 'lbvsName' """ ret = True nitro = _connect(**connection_args) if nitro is None: return False lbvs = NSLBVServer() lbvs.set_name(lbvs_name) lbvs.set_persistencetype(persistencetype) lbvs.set_rule(rule) lbvs.set_resrule(resrule) try: NSLBVServer.update(nitro, lbvs) except NSNitroError as error: log.debug("netscaler module error - NSLBVServer.update() failed: %s", error) ret = False _disconnect(nitro) return ret
def lbvserver_add(lbvs_name, lbvs_type, persistype, backupvs, ip, port, clttimeout, timeout, **connection_args): """ Add lb vs server CLI Example: .. code-block:: bash salt '*' netscaler.lbvserver_add 'lbvsName' 'lbvsType' """ ret = True nitro = _connect(**connection_args) if nitro is None: return False lbvs = NSLBVServer() lbvs.set_name(lbvs_name) lbvs.set_servicetype(lbvs_type) lbvs.set_ipv46(ip) lbvs.set_port(port) lbvs.set_persistencetype(persistype) lbvs.set_backupvserver(backupvs) lbvs.set_clttimeout(clttimeout) lbvs.set_timeout(timeout) try: NSLBVServer.add(nitro, lbvs) except NSNitroError as error: log.debug("netscaler module error - NSLBVServer.add() failed: %s", error) ret = False _disconnect(nitro) return ret
def vserver_add(v_name, v_ip, v_port, v_type, **connection_args): ''' Add a new lb vserver CLI Example: .. code-block:: bash salt '*' netscaler.vserver_add 'vserverName' 'vserverIP' 'vserverPort' 'vserverType' salt '*' netscaler.vserver_add 'alex.patate.chaude.443' '1.2.3.4' '443' 'SSL' ''' ret = True if vserver_exists(v_name, **connection_args): return False nitro = _connect(**connection_args) if nitro is None: return False vserver = NSLBVServer() vserver.set_name(v_name) vserver.set_ipv46(v_ip) vserver.set_port(v_port) vserver.set_servicetype(v_type.upper()) try: NSLBVServer.add(nitro, vserver) except NSNitroError as e: log.debug( 'netscaler module error - NSLBVServer.add() failed: {0}'.format( e.message)) ret = False _disconnect(nitro) return ret
def action_addlbvserver(args, nitro): lbvserver = NSLBVServer() lbvserver.set_name(args.lbvserver) lbvserver.set_ipv46(args.ip) lbvserver.set_port(args.port) lbvserver.set_clttimeout(args.clttimeout) lbvserver.set_persistencetype(args.persistencetype) lbvserver.set_servicetype(args.servicetype) NSLBVServer.add(nitro, lbvserver) print "lb vserver %s (%s:%d/%s) was added" % (args.lbvserver, args.ip, args.port, args.servicetype)
try: NSServiceGroupServerBinding.delete(nitro, svcgrpbinding) print "unbound server %s from service group %s on port %s" % (args.servername, args.servicegroupname, args.serviceport) except nsnitro.nsexceptions.nsexceptions.NSNitroNserrNoent as e: print "Error: ", e.message finally: nitro.logout() sys.exit(0) if args.addlbvserver: if not args.port or not args.ip: print "--ip and --port are required for adding LB Vserver" nitro.logout() sys.exit(0) lbvserver = NSLBVServer() lbvserver.set_name(args.addlbvserver) lbvserver.set_ipv46(args.ip) lbvserver.set_port(args.port) lbvserver.set_clttimeout(args.clttimeout) lbvserver.set_persistencetype(args.persistencetype) lbvserver.set_servicetype(args.servicetype) NSLBVServer.add(nitro, lbvserver) print "lb vserver %s (%s:%d/%s) was added" % (args.addlbvserver, args.ip, args.port, args.servicetype) nitro.logout() sys.exit(0) if args.enablelbvserver: lbvserver = NSLBVServer() lbvserver.set_name(args.enablelbvserver) NSLBVServer.enable(nitro, lbvserver)