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 unbind_lbvserver_service(self, client):
        try:
            obj = []
            obj = [lbvserver_service_binding() for _ in range(2)]
            obj[0].name = "lb1"
            obj[0].servicename = "svc1"
            obj[1].name = "lb2"
            obj[1].servicename = "svc2"
            lbvserver_service_binding.delete(client, obj)

            lbv = lbvserver_service_binding()
            lbv.name = "lb3"
            lbv.servicename = "svc3"
            lbvserver_service_binding.delete(client, lbv)
            print("unbind_lbvserver_service:: done")
        except nitro_exception as e:
            print("Exception::unbind_lbvserver_service::errocode - " + str(e.errorcode) + ", message - " + e.message)
        except Exception as e:
            print("Exception::unbind_lbvserver_service:: " + str(e.args))
Example #3
0
    def unbind_lbvserver_service(self, client):
        try:
            obj = []
            obj = [lbvserver_service_binding() for _ in range(2)]
            obj[0].name = "lb1"
            obj[0].servicename = "svc1"
            obj[1].name = "lb2"
            obj[1].servicename = "svc2"
            lbvserver_service_binding.delete(client, obj)

            lbv = lbvserver_service_binding()
            lbv.name = "lb3"
            lbv.servicename = "svc3"
            lbvserver_service_binding.delete(client, lbv)
            print("unbind_lbvserver_service:: done")
        except nitro_exception as e:
            print("Exception::unbind_lbvserver_service::errocode - " +
                  str(e.errorcode) + ", message - " + e.message)
        except Exception as e:
            print("Exception::unbind_lbvserver_service:: " + str(e.args))
Example #4
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
Example #5
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
Example #6
0
    def HandleDropEvent(self, jstring):
        d = json.loads(jstring)
        svcname = d['name']
        bndg = LBVSRVRSVC.lbvserver_service_binding()
        bndg.name = self.name
        bndg.servicename = svcname

        try:
            LBVSRVRSVC.lbvserver_service_binding.add(self.sess, bndg)
        except NITROEXCEPTION as e:
            print 'service drop failed'
        except Exception as e:
            print 'service drop failed'

        return
    def addlbvserver_bindings(self, client, lb_vserver_name , svc_name,SRVS,j) :
        try :
            obj = [ lbvserver_service_binding() for _ in range(j)]
            for l in range (1,j):
                print ("l="+str(l))
                obj[l].name = lb_vserver_name
                obj[l].servicename = svc_name+"-"+SRVS+str(l)
                lbvserver_service_binding.add(client, obj[l])
                l += 1
                print("addlbvserver_bindings - "+lbvserver_service_binding.add(client, obj[l])+" -Done\n")

        except nitro_exception as e :
            print("Exception::addlbvserver_bindings::errorcode="+str(e.errorcode)+",message="+ e.message)
        except Exception as e:
            print("Exception::addlbvserver_bindings::message="+str(e.args))
Example #8
0
    def addlbvserver_bindings(self, client) :
        try :
            obj = lbvserver_service_binding()
            obj.name = "lb_vip"
            obj.servicename = "svc10"
            obj.weight = 77
            lbvserver_service_binding.add(client, obj)
            lbvserver_service_binding.delete(client, obj)
            print("addlbvserver_bindings - Done")
            svc = [ service() for _ in range(2)] 
            svc[0].name = "svc_1"
            svc[0].ip = "1.1.1.1"
            svc[0].port = 80
            svc[0].servicetype = service.Servicetype.HTTP

            svc[1].name = "svc_2"
            svc[1].ip = "1.1.1.1"
            svc[1].port = 81
            svc[1].servicetype = service.Servicetype.HTTP

            bindsvc = [lbvserver_service_binding() for _ in range(2)]
            bindsvc[0].name = "lb_vip"
            bindsvc[0].servicename = "svc_1"
            bindsvc[0].weight = 20

            bindsvc[1].name = "lb_vip"
            bindsvc[1].servicename = "svc_2"
            bindsvc[1].weight = 30

            service.add(client, svc)
            lbvserver_service_binding.add(client, bindsvc)			
            print("addlbvserver_bindings - Done")
        except nitro_exception as e :
            print("Exception::addlbvserver_bindings::errorcode="+str(e.errorcode)+",message="+ e.message)
        except Exception as e:
            print("Exception::addlbvserver_bindings::message="+str(e.args))
Example #9
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