예제 #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))
예제 #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
예제 #3
0
 def add_lbvserver_post(self, client) :
     try :
         obj = lbvserver()
         obj.name = "lb_vip_post"
         obj.servicetype = lbvserver.Servicetype.HTTP
         lbvserver.add(client,obj) 
         print("add_lbvserver_post - Done")
     except nitro_exception as e :
         print("Exception::add_lbvserver_post::errorcode="+str(e.errorcode)+",message="+ e.message)
     except Exception as e:
         print("Exception::add_lbvserver_post::message="+str(e.args))
예제 #4
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("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
예제 #5
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)
예제 #6
0
 def add_lbvs_bulk(self, client) : 
     try :
         lb = [lbvserver() for _ in range(2)]
         lb[0].name = "lb1"
         lb[0].servicetype = lbvserver.Servicetype.HTTP
         
         lb[1].name = "lb2"
         lb[1].servicetype = lbvserver.Servicetype.SSL
         
         lbvserver.add(client, lb)
         print("add_lbvs_bulk - Done")
         lbvserver.enable(client, lb)
         print("enable bulk resources - Done")
     except nitro_exception as e :
         print("Exception::add_lbvs_bulk::errorcode="+str(e.errorcode)+",message="+ e.message)
     except Exception as e:
         print("Exception::add_lbvs_bulk::message="+str(e.args))
예제 #7
0
파일: nitro.py 프로젝트: zbukhari/netscaler
    def lbvserver(self, action, name, ipv46, servicetype, port, lbmethod):
        '''This function is interactive and will allow one to add a load-balancing
virtual server.

	param @action string add or delete (delete only requires the name)
	param @name string specifying the name of the virtual server
	param @ipv46 string representation of an IPv4 or IPv6 address
	param @servicetype string: HTTP, FTP, TCP, UDP, SSL, SSL_BRIDGE,
		SSL_TCP, NNTP, DNS, DHCPRA, ANY, SIP_UDP, DNS_TCP, RTSP.
	param @port - integer representing port for this service.
	param @lbmethod string: ROUNDROBIN, LEASTCONNECTION,
		LEASTRESPONSETIME, URLHASH, DOMAINHASH, DESTINATIONIPHASH,
		SOURCEIPHASH, SRCIPDESTIPHASH, LEASTBANDWIDTH, LEASTPACKETS,
		TOKEN, SRCIPDESTIPHASH, CUSTOMLOAD
'''

        # Enable the load balancing feature.
        try:
            features_to_be_enabled = "lb"
            self._sess.enable_features(
                features_to_be_enabled)  # Check into this @@@

            # Create an instance of the virtual server class
            obj = lbvserver()
            # Prepare the variables
            obj.name = name
            obj.ipv46 = ipv46
            obj.servicetype = servicetype
            obj.port = port
            obj.lbmethod = lbmethod

            if action == 'add':
                lbvserver.add(self._sess, obj)
            elif action == 'delete':
                lbvserver.delete(self._sess, obj)
        except nitro_exception as e:
            print("Exception::errorcode=" + str(e.errorcode) + ",message=" +
                  e.message)
        except Exception as e:
            print("Exception::message=" + str(e.args))
        else:
            return True

        return False
예제 #8
0
 def bindsslvs_cert (self, client) : 
     try :
         lbvs = lbvserver()
         lbvs.name = "ssl_vs"
         lbvs.servicetype = lbvserver.Servicetype.SSL
         lbvs.ipv46 = "1.1.1.1"
         lbvs.port = 443
         lbvserver.add(client, lbvs)
         obj = [sslvserver_sslcertkey_binding() for _ in range(2)]
         obj[0].vservername = "ssl_vs"
         obj[0].certkeyname = "xx"
         obj[1].vservername = "ssl_vs"
         obj[1].certkeyname = "yy"
         sslvserver_sslcertkey_binding.add(client, obj)	
         print("bindsslvs_cert - Done")
     except nitro_exception as e :
         print("Exception::bindsslvs_cert::errorcode="+str(e.errorcode)+",message="+ e.message)
     except Exception as e:
         print("Exception::bindsslvs_cert::message="+str(e.args))
 def add_lbvserver(self, client,lb_vserver_name) :
     try :
         obj = lbvserver()
         obj.name = lb_vserver_name
         obj.servicetype = lbvserver.Servicetype.HTTP
         response = lbvserver.add(client, obj)
         print("add_lbvserver - Done\n")
         if response.severity and response.severity =="WARNING" :
             print("\tWarning : " + response.message)
     except nitro_exception as e :
         print("Exception::add_lbvserver::errorcode="+str(e.errorcode)+",message="+ e.message)
     except Exception as e:
         print("Exception::add_lbvserver::message="+str(e.args))
예제 #10
0
    def addLBVServers(self):
        """Configure the lbvservers for the NetScaler"""
        if "lbvs" in self.cfg.keys():
            #Lets loop through all lbvservers
            for lbvs in self.cfg['lbvs']:
                try:
                    #Setup a new lbvserver
                    newLBVS = lbvserver()
                    newLBVS.name = lbvs['name']
                    newLBVS.servicetype = lbvs['servicetype']
                    newLBVS.ipv46 = lbvs['ipv46']

                    #check these optional values
                    if "port" in lbvs.keys():
                        newLBVS.port = lbvs['port']
                    if "persistencetype" in lbvs.keys():
                        newLBVS.persistencetype = lbvs['persistencetype']
                    if "lbmethod" in lbvs.keys():
                        newLBVS.lbmethod = lbvs['lbmethod']

                    #Add the lbvs
                    response = lbvserver.add(self.ns_session, newLBVS)
                    if response.severity and response.severity == "WARNING":
                        print("\tWarning : " + response.message)

                except nitro_exception as e:
                    print("Exception::errorcode=" + str(e.errorcode) +
                          ",message=" + e.message)
                except Exception as e:
                    print("Exception::message=" + str(e.args))

                #If we have services to bind, lets do it.
                if "services" in lbvs.keys():
                    for svc in lbvs['services']:
                        #Create a new binding
                        newSVCBinding = lbvserver_service_binding()
                        newSVCBinding.name = lbvs['name']
                        newSVCBinding.servicename = svc['servicename']
                        newSVCBinding.weight = svc['weight']

                        #Add the binding!
                        try:
                            lbvserver_service_binding.add(
                                self.ns_session, newSVCBinding)
                        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
예제 #11
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)
예제 #12
0
    def addLBVServers(self):
        """Configure the lbvservers for the NetScaler"""
        if "lbvs" in self.cfg.keys():
            #Lets loop through all lbvservers
            for lbvs in self.cfg['lbvs']:
                try:
                    #Setup a new lbvserver
                    newLBVS = lbvserver()
                    newLBVS.name = lbvs['name']
                    newLBVS.servicetype = lbvs['servicetype']
                    newLBVS.ipv46 = lbvs['ipv46']

                    #check these optional values
                    if "port" in lbvs.keys():
                        newLBVS.port = lbvs['port']
                    if "persistencetype" in lbvs.keys():
                        newLBVS.persistencetype = lbvs['persistencetype']
                    if "lbmethod" in lbvs.keys():
                        newLBVS.lbmethod = lbvs['lbmethod']

                    #Add the lbvs
                    response = lbvserver.add(self.ns_session, newLBVS)
                    if response.severity and response.severity == "WARNING":
                        print("\tWarning : " + response.message)

                except nitro_exception as e:
                    print("Exception::errorcode=" +
                          str(e.errorcode) + ",message=" + e.message)
                except Exception as e:
                    print("Exception::message=" + str(e.args))

                #If we have services to bind, lets do it.
                if "services" in lbvs.keys():
                    for svc in lbvs['services']:
                        #Create a new binding
                        newSVCBinding = lbvserver_service_binding()
                        newSVCBinding.name = lbvs['name']
                        newSVCBinding.servicename = svc['servicename']
                        newSVCBinding.weight = svc['weight']

                        #Add the binding!
                        try:
                            lbvserver_service_binding.add(self.ns_session,
                                                          newSVCBinding)
                        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
예제 #13
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)
    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
예제 #15
0
    def addLBVServers(self):
        """Configure the lbvservers for the NetScaler"""
        #Setup a new lbvserver1
        newLBVS = lbvserver()
        newLBVS.name = self.vserver1
        newLBVS.servicetype = "ssl"
        newLBVS.ipv46 = self.vip1
        newLBVS.port = "443"
        newLBVS.persistencetype = "COOKIEINSERT"
        newLBVS.lbmethod = "ROUNDROBIN"

        try:
            #Add the lbvs
            response = lbvserver.add(self.ns_session, newLBVS)
            if response.severity and response.severity == "WARNING":
                print("\tWarning : " + response.message)

        except nitro_exception as e:
            print("Exception::errorcode=" + str(e.errorcode) + ",message=" +
                  e.message)
        except Exception as e:
            print("Exception::message=" + str(e.args))

        newSVCBinding = lbvserver_service_binding()
        newSVCBinding.name = self.vserver1
        newSVCBinding.servicename = self.service1
        #newSVCBinding.weight = "1"
        #Add the binding!
        try:
            lbvserver_service_binding.add(self.ns_session, newSVCBinding)
        except nitro_exception as e:
            print("Exception::errorcode=" + str(e.errorcode) + ",message=" +
                  e.message)
        except Exception as e:
            print("Exception::message=" + str(e.args))

        #Setup a new lbvserver2
        newLBVS = lbvserver()
        newLBVS.name = self.vserver2
        newLBVS.servicetype = "http"
        newLBVS.ipv46 = self.vip2
        newLBVS.port = "80"
        newLBVS.persistencetype = "COOKIEINSERT"
        newLBVS.lbmethod = "ROUNDROBIN"

        try:
            #Add the lbvs
            response = lbvserver.add(self.ns_session, newLBVS)
            if response.severity and response.severity == "WARNING":
                print("\tWarning : " + response.message)

        except nitro_exception as e:
            print("Exception::errorcode=" + str(e.errorcode) + ",message=" +
                  e.message)
        except Exception as e:
            print("Exception::message=" + str(e.args))

        newSVCBinding = lbvserver_service_binding()
        newSVCBinding.name = self.vserver2
        newSVCBinding.servicename = self.service1
        #newSVCBinding.weight = "1"
        #Add the binding!
        try:
            lbvserver_service_binding.add(self.ns_session, newSVCBinding)
        except nitro_exception as e:
            print("Exception::errorcode=" + str(e.errorcode) + ",message=" +
                  e.message)
        except Exception as e:
            print("Exception::message=" + str(e.args))

        #Setup a new lbvserver3
        newLBVS = lbvserver()
        newLBVS.name = self.vserver3
        newLBVS.servicetype = "http"
        newLBVS.ipv46 = self.vip3
        newLBVS.port = "80"
        newLBVS.persistencetype = "COOKIEINSERT"
        newLBVS.lbmethod = "ROUNDROBIN"

        try:
            #Add the lbvs
            response = lbvserver.add(self.ns_session, newLBVS)
            if response.severity and response.severity == "WARNING":
                print("\tWarning : " + response.message)

        except nitro_exception as e:
            print("Exception::errorcode=" + str(e.errorcode) + ",message=" +
                  e.message)
        except Exception as e:
            print("Exception::message=" + str(e.args))

        newSVCBinding = lbvserver_service_binding()
        newSVCBinding.name = self.vserver3
        newSVCBinding.servicename = self.service1
        #newSVCBinding.weight = "1"
        #Add the binding!
        try:
            lbvserver_service_binding.add(self.ns_session, newSVCBinding)
        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