Example #1
0
	def basic_lbv(self, client, lbv_name, svc_name) : 
		try : 
			#Create an instance of the virtual server class
			new_lbvserver_obj = lbvserver()

			#Create a new virtual server
			new_lbvserver_obj.name = lbv_name
			new_lbvserver_obj.ipv46 = "10.217.242.76"
			new_lbvserver_obj.servicetype = "HTTP"
			new_lbvserver_obj.port = 80
			new_lbvserver_obj.lbmethod = "ROUNDROBIN"

			#get all lbvservers and shove them into a list 
			#FIXME this is not working as expected it.  it sets all list members to the same lbv object
			resources = lbvserver.get(client)
			for resource in resources:
				if resource.name == lbv_name:
					print("lbvserver resource::name="+resource.name+" exists.")
					lbvserver.delete(client, new_lbvserver_obj)
					break
			lbvserver.add(client, new_lbvserver_obj)

			#bind service to lbv
			bindObj = lbvserver_service_binding()
			bindObj.name = lbv_name
			bindObj.servicename = svc_name
			bindObj.weight = 20
			lbvserver_service_binding.add(client, bindObj)

			print("basic_lbv - Done")
		except nitro_exception as e :
			print("Exception::basic_lbv::errorcode="+str(e.errorcode)+",message="+ e.message)
		except Exception as e:
			print("Exception::basic_lbv::message="+str(e.args))
Example #2
0
    def main(cls, args_):
        if (len(args_) < 3):
            print("Usage: run.bat <ip> <username> <password>")
            return

        config = MyFirstNitroApplication()
        config.ip = args_[1]
        config.username = args_[2]
        config.password = args_[3]

        try:

            #Create an instance of the nitro_service class to connect to the appliance
            ns_session = nitro_service(config.ip, "HTTP")

            ns_session.set_credential(
                config.username,
                config.password)  #to make arguments more generic
            ns_session.timeout = 310
            #Log on to the appliance using your credentials
            ns_session.login()

            #Enable the load balancing feature.
            features_to_be_enabled = "lb"
            ns_session.enable_features(features_to_be_enabled)

            #Create an instance of the virtual server class
            new_lbvserver_obj = lbvserver()

            #Create a new virtual server
            new_lbvserver_obj.name = "MyFirstLbVServer"
            new_lbvserver_obj.ipv46 = "10.102.29.88"
            new_lbvserver_obj.servicetype = "HTTP"
            new_lbvserver_obj.port = 80
            new_lbvserver_obj.lbmethod = "ROUNDROBIN"
            lbvserver.add(ns_session, new_lbvserver_obj)

            #Retrieve the details of the virtual server
            new_lbvserver_obj = lbvserver.get(ns_session,
                                              new_lbvserver_obj.name)
            print("Name : " + new_lbvserver_obj.name + "\n" + "Protocol : " +
                  new_lbvserver_obj.servicetype)

            #Delete the virtual server
            lbvserver.delete(ns_session, new_lbvserver_obj.name)

            #Save the configurations
            ns_session.save_config()

            #Logout from the NetScaler appliance
            ns_session.logout()

        except nitro_exception as e:
            print("Exception::errorcode=" + str(e.errorcode) + ",message=" +
                  e.message)
        except Exception as e:
            print("Exception::message=" + str(e.args))
        return
	def main(cls, args_):
		if(len(args_) < 3):
			print("Usage: run.bat <ip> <username> <password>")
			return

		config = MyFirstNitroApplication()
		config.ip = args_[1]
		config.username = args_[2]
		config.password = args_[3] 
		
		try :
			
			#Create an instance of the nitro_service class to connect to the appliance
			ns_session = nitro_service(config.ip,"HTTP")
			
			ns_session.set_credential("nsroot", "nsroot")
			ns_session.timeout = 310
			#Log on to the appliance using your credentials
			ns_session.login()
			
			#Enable the load balancing feature.
			features_to_be_enabled = "lb"			
			ns_session.enable_features(features_to_be_enabled)
			
			#Create an instance of the virtual server class
			new_lbvserver_obj = lbvserver()
			
			#Create a new virtual server
			new_lbvserver_obj.name = "MyFirstLbVServer"
			new_lbvserver_obj.ipv46 = "10.102.29.88"
			new_lbvserver_obj.servicetype = "HTTP"
			new_lbvserver_obj.port = 80
			new_lbvserver_obj.lbmethod = "ROUNDROBIN"
			lbvserver.add(ns_session, new_lbvserver_obj)
					
			#Retrieve the details of the virtual server
			new_lbvserver_obj = lbvserver.get(ns_session,new_lbvserver_obj.name)
			print("Name : " +new_lbvserver_obj.name +"\n" +"Protocol : " +new_lbvserver_obj.servicetype)

			#Delete the virtual server
			lbvserver.delete(ns_session, new_lbvserver_obj.name)
			
			#Save the configurations
			ns_session.save_config()
			
			#Logout from the NetScaler appliance
			ns_session.logout()
			
		except nitro_exception as  e:
			print("Exception::errorcode="+str(e.errorcode)+",message="+ e.message)
		except Exception as e:         
			print("Exception::message="+str(e.args))
		return
Example #4
0
    def _create_lb(self, lbname):
        try:
            lb = lbvserver.get(self.ns_session, lbname)
            if (lb.name == lbname):
                logger.info("LB %s is already configured " % lbname)
                return
        except nitro_exception:
            pass

        lb = lbvserver()
        lb.name = lbname
        lb.servicetype = "HTTP"
        lbvserver.add(self.ns_session, lb)
Example #5
0
    def get_lb(self, domain: str) -> NitroLB:
        """Get an CS/LB based on a domain"""
        try:
            # lookup ip of domain
            ip = socket.gethostbyname(domain)

            for client in self.clients:
                # lookup lb
                for lb in lbvserver.get(client):
                    if lb.ipv46 == ip:
                        # lb found
                        return NitroLB(client, lb)
                for lb in csvserver.get(client):
                    if lb.ipv46 == ip:
                        # lb found
                        return NitroLB(client, lb)
        except socket.gaierror as e:
            raise DomainNotFound(domain)
        raise DomainNotFound(domain)
Example #6
0
	def stats(self, client, lbv_name, svc_name) : 
		try : 
			obj = lbvserver_stats.get(client, lbv_name)         
			print("statlbvserver_byname result::name="+lbvserver.get(client, lbv_name).ipv46+", servicetype="+obj.type +",totalrequests="+obj.totalrequests)

			obj_svc = service_stats.get(client, svc_name)         
			print("statservice_byname result::name="+obj_svc.name+", servicetype="+obj_svc.servicetype +",totalrequests="+obj_svc.totalrequests)

			#obj_svcgms = servicegroupmember_stats()
			#obj_svcgms.servicegroupname = svcg_name
			#obj_svcgms.ip = "192.168.2.10"
			#obj_svcgms.port = 80
			#obj1_svcgms = servicegroupmember_stats.get(client, obj_svcgms)
			#print("statservicegrpmem result::req="+obj1_svcgms.servicegroupname+", curClintConnctions="+obj1_svcgms.curclntconnections)
			print("stats - Done")
		except nitro_exception as e :
			print("Exception::stats::errorcode="+str(e.errorcode)+",message="+ e.message)
		except Exception as e:
			print("Exception::stats::message="+str(e.args))
Example #7
0
    def _create_lb(self, lbname, lbmethod, vip, port):
        try:
            lb = lbvserver.get(self.ns_session, lbname)
            if (lb.name == lbname) and \
                    (lb.ipv46 == vip) and \
                    (str(lb.port) == port):
                logger.info("LB %s is already configured " % lbname)
                return
            else:
                logger.info("LB %s is already configured with a different \
                            VIP/port : %s:%s\n" % (lb.name, lb.ipv46, lb.port))
                raise Exception("LB %s already configured with different VIP/\
                                port : %s:%s\n" % (lbname, lb.ipv46, lb.port))
        except nitro_exception as e:
            pass

        lb = lbvserver()
        lb.name = lbname
        lb.ipv46 = vip
        lb.servicetype = "HTTP"
        lb.port = port
        lb.lbmethod = lbmethod
        lbvserver.add(self.ns_session, lb)
Example #8
0
    def _create_lb(self, lbname, lbmethod, vip, port):
        try:
            lb = lbvserver.get(self.ns_session, lbname)
            if (lb.name == lbname) and \
                    (lb.ipv46 == vip) and \
                    (str(lb.port) == port):
                logger.info("LB %s is already configured " % lbname)
                return
            else:
                logger.info("LB %s is already configured with a different \
                            VIP/port : %s:%s\n" % (lb.name, lb.ipv46, lb.port))
                raise Exception("LB %s already configured with different VIP/\
                                port : %s:%s\n" % (lbname, lb.ipv46, lb.port))
        except nitro_exception as e:
            pass

        lb = lbvserver()
        lb.name = lbname
        lb.ipv46 = vip
        lb.servicetype = "HTTP"
        lb.port = port
        lb.lbmethod = lbmethod
        lbvserver.add(self.ns_session, lb)
Example #9
0
	def main(cls, args_):
		if(len(args_) < 3):
			print("Usage: run.bat <ip> <username> <password>")
			return

		config = basic_lbvServer()
		config.ip = args_[1]
		config.username = args_[2]
		config.password = args_[3] 
		
		try :
			
			#Create an instance of the nitro_service class to connect to the appliance
			ns_session = nitro_service("10.217.242.90","HTTP")
			
			ns_session.set_credential("nsroot", config.password)
			ns_session.timeout = 310
			#Log on to the appliance using your credentials
			ns_session.login()
			
			#Enable the load balancing feature.
			features_to_be_enabled = "lb"			
			ns_session.enable_features(features_to_be_enabled)
			
			#Create an instance of the server class
			server_obj = server()

			#Create an instance of the service class
			service_obj = service()

			#Create an instance of the virtual server class
			new_lbvserver_obj = lbvserver()

			#Create a new virtual server
			new_lbvserver_obj.name = "MyFirstLbVServer"
			new_lbvserver_obj.ipv46 = "10.102.29.88"
			new_lbvserver_obj.servicetype = "HTTP"
			new_lbvserver_obj.port = 80
			new_lbvserver_obj.lbmethod = "ROUNDROBIN"
			#lbvserver.delete(ns_session, new_lbvserver_obj.name)
			#lbvserver.add(ns_session, new_lbvserver_obj)
					
			#Retrieve the details of the virtual server
			new_lbvserver_obj = lbvserver.get(ns_session,new_lbvserver_obj.name)
			print("Name : " +new_lbvserver_obj.name +"\n" +"Protocol : " +new_lbvserver_obj.servicetype)

			#Retrieve state of a lbvserver
			obj_lbv = lbvserver_stats.get(ns_session, "MyFirstLbVServer")
			print("statlbvserver_byname result::name="+obj_lbv.name+", servicetype="+obj_lbv.type +",state="+obj_lbv.state)

			#Retrieve state of a servicegroup
			obj_svcg = servicegroup.get(ns_session, "http_svcg")
			print("statsvcg_byname result::name="+obj_svcg.servicegroupname+", servicetype="+obj_svcg.servicetype +",state="+obj_svcg.servicegroupeffectivestate)

			#Delete the virtual server
			#lbvserver.delete(ns_session, new_lbvserver_obj.name)
			
			#Save the configurations
			ns_session.save_config()
			
			#Logout from the NetScaler appliance
			ns_session.logout()
			
		except nitro_exception as  e:
			print("Exception::errorcode="+str(e.errorcode)+",message="+ e.message)
		except Exception as e:         
			print("Exception::message="+str(e.args))
		return
    def main(cls, args_):
        if (len(args_) < 3):
            print("Usage: run.bat <ip> <username> <password>")
            return

        config = MyFirstNitroApplication()
        config.ip = args_[1]
        config.username = args_[2]
        config.password = args_[3]

        try:

            #Create an instance of the nitro_service class to connect to the appliance
            ns_session = nitro_service(config.ip, "HTTP")

            ns_session.set_credential(
                config.username,
                config.password)  #to make arguments more generic
            ns_session.timeout = 310
            # To skip invalid arguments for Add/Update/Delete Operations (HTTP POST/PUT/DELETE Request)
            # Set this argument to True when newer version of SDK is used with older version of Netscaler
            ns_session.skipinvalidarg = True
            # By setting this argument to True, add operation will take care of adding or updating the entity without throwing any error
            ns_session.idempotent = True
            # By setting this argument to True HTTP Basic Auth will be used and there is no need for login() and logout() calls
            ns_session.basic_auth = False
            #Log on to the appliance using your credentials
            ns_session.login()

            #Enable the load balancing feature.
            features_to_be_enabled = "lb"
            ns_session.enable_features(features_to_be_enabled)

            #Create an instance of the virtual server class
            new_lbvserver_obj = lbvserver()

            #Create a new virtual server
            new_lbvserver_obj.name = "MyFirstLbVServer"
            new_lbvserver_obj.ipv46 = "10.102.29.88"
            new_lbvserver_obj.servicetype = "HTTP"
            new_lbvserver_obj.port = 80
            new_lbvserver_obj.lbmethod = "ROUNDROBIN"
            lbvserver.add(ns_session, new_lbvserver_obj)

            #Retrieve the details of the virtual server
            new_lbvserver_obj = lbvserver.get(ns_session,
                                              new_lbvserver_obj.name)
            print("Name : " + new_lbvserver_obj.name + "\n" + "Protocol : " +
                  new_lbvserver_obj.servicetype)

            #Delete the virtual server
            lbvserver.delete(ns_session, new_lbvserver_obj.name)

            #Save the configurations
            ns_session.save_config()

            #Logout from the NetScaler appliance
            ns_session.logout()

        except nitro_exception as e:
            print("Exception::errorcode=" + str(e.errorcode) + ",message=" +
                  e.message)
        except Exception as e:
            print("Exception::message=" + str(e.args))
        return
Example #11
0
                    dest='username',
                    type=str,
                    required=True,
                    help='api user')
PARSER.add_argument('--password',
                    dest='password',
                    type=str,
                    required=True,
                    help='password..duh?')
ARGS = PARSER.parse_args()

# Disable warnings about unverified HTTPS
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# login to netscaler
NS_SESSION = nitro_service(ARGS.netscaler, 'https')
NS_SESSION.certvalidation = False
NS_SESSION.hostnameverification = False
NS_SESSION.login(ARGS.username, ARGS.password, 3600)

# Find all virtual servers
LBRESULT = lbvserver.get(NS_SESSION)
CSRESULT = csvserver.get(NS_SESSION)
for vserver in LBRESULT:
    print vserver.name, 'is', vserver.curstate

for vserver in CSRESULT:
    print vserver.name, 'is', vserver.curstate

NS_SESSION.logout()