예제 #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 rmlbvserver_spaces(self, client):
     try:
         lbvserver.delete(client, "x y")
         print("rmlbvserver_spaces - Done")
     except nitro_exception as e:
         print("Exception::rmlbvserver_spaces::errorcode=" + str(e.errorcode) + ",message=" + e.message)
     except Exception as e:
         print("Exception::rmlbvserver_spaces::message=" + str(e.args))
예제 #3
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
예제 #4
0
 def rmlbvserver_spaces(self, client):
     try:
         lbvserver.delete(client, "x y")
         print("rmlbvserver_spaces - Done")
     except nitro_exception as e:
         print("Exception::rmlbvserver_spaces::errorcode=" +
               str(e.errorcode) + ",message=" + e.message)
     except Exception as e:
         print("Exception::rmlbvserver_spaces::message=" + str(e.args))
예제 #5
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
예제 #6
0
    def rmlbvserver_bulk(self, client):
        try:
            lbvs = []
            lbvs = [lbvserver() for _ in range(2)]
            for i in range(2):
                lbvs[i].name = "lb" + str(i + 3)
            lbvserver.delete(client, lbvs)

            lbvs = ["lb5", "lb6"]
            lbvserver.delete(client, lbvs)
            print("rmlbvserver_bulk::rc= done")
        except nitro_exception as e:
            print("Exception::rmlbvserver_bulk::rc=" + str(e.errorcode) + " , Message =" + e.message)
        except Exception as e:
            print("Exception::rmlbvserver_bulk::message=" + str(e.args))
예제 #7
0
    def rmlbvserver_bulk(self, client):
        try:
            lbvs = []
            lbvs = [lbvserver() for _ in range(2)]
            for i in range(2):
                lbvs[i].name = "lb" + str(i + 3)
            lbvserver.delete(client, lbvs)

            lbvs = ["lb5", "lb6"]
            lbvserver.delete(client, lbvs)
            print("rmlbvserver_bulk::rc= done")
        except nitro_exception as e:
            print("Exception::rmlbvserver_bulk::rc=" + str(e.errorcode) +
                  " , Message =" + e.message)
        except Exception as e:
            print("Exception::rmlbvserver_bulk::message=" + str(e.args))
예제 #8
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
예제 #9
0
 def rmlbvserver(self, client):
     try:
         response = lbvserver.delete(client, "lb_vip_post")
         if response.severity and response.severity == ("WARNING"):
             print("Warning : " + response.message)
         print("rmlbvserver - Done")
     except nitro_exception as e:
         print("Exception::rmlbvserver::errorcode=" + str(e.errorcode) + ",message=" + e.message)
     except Exception as e:
         print("Exception::rmlbvserver::message=" + str(e.args))
    def rmlbvserver(self, client,lb_vserver_name):
		try :
			response =lbvserver.delete(client,lb_vserver_name)
			if (response.severity and response.severity == ("WARNING")):
				print("Warning : " + response.message)
			print("rmlbvserver - "+lb_vserver_name+"Done\n")
		except nitro_exception as e :
			print("Exception::rmlbvserver::errorcode="+str(e.errorcode)+",message="+ e.message)
		except Exception as e :
			print("Exception::rmlbvserver::message="+str(e.args))
예제 #11
0
 def rmlbvserver(self, client):
     try:
         response = lbvserver.delete(client, "lb_vip_post")
         if (response.severity and response.severity == ("WARNING")):
             print("Warning : " + response.message)
         print("rmlbvserver - Done")
     except nitro_exception as e:
         print("Exception::rmlbvserver::errorcode=" + str(e.errorcode) +
               ",message=" + e.message)
     except Exception as e:
         print("Exception::rmlbvserver::message=" + str(e.args))
    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