Пример #1
0
    def _get_netscaler_service_from_node(self, loadBalancerId, loadBalancer, nodeId, node):

        service_obj = {}
     

        for key in node:
 
            self.logger.debug("Examining key \"%s\" of node object" % key)

            if key == "_properties":
                continue

            if key == "id":
                service_obj["name"] = NitroUtils.get_servicename_from_nodeid(loadBalancerId, nodeId)
                continue

            if key == "address":
                service_obj["ip"] = node.address
                continue 
            
            if key == "port":
                service_obj["port"] = node.port
                continue                


        if loadBalancer:
            servicetype = NitroUtils.get_servicetype_from_protocol(loadBalancer.protocol)
            servicetype = NitroUtils.get_decrypted_version_of_servicetype(servicetype)
            service_obj["servicetype"] = servicetype 


        return service_obj
    def _get_netscaler_updatenode_protocol_task(self, loadBalancerId,
                                                loadBalancer, node,
                                                newLoadBalancerId):

        servicename = NitroUtils.get_servicename_from_nodeid(
            loadBalancerId, node.id)

        if not "protocol" in loadBalancer:
            return None

        lbprotocol = loadBalancer.protocol

        servicetype = NitroUtils.get_servicetype_from_protocol(lbprotocol)
        servicetype = NitroUtils.get_decrypted_version_of_servicetype(
            servicetype)

        service = {}
        service["name"] = servicename
        service["protocol"] = servicetype

        task = {}
        task["name"] = servicename
        task["type"] = "service"
        task["operation"] = "UPDATE"
        task["state"] = service

        return task
Пример #3
0
    def get_netscaler_addnodes_tasks(self, loadBalancerId, loadBalancer, nodes, existing_ids=[]):


        """ 
        Preconditions: 
                  A. The lbvserver object must have the following attributes
                     for this method to work:
                         1. name 
                         2. service_type

                  B. The lb_algorithm must contain a non empty value
        """
                        

        total_nodes = len(existing_ids) + len(nodes)

        self.logger.debug("existing node ids are: %s" % str(existing_ids))

        if total_nodes > MAX_NODES_PER_LOADBALANCER:
            raise OverLimitException("Number of nodes exceeds maximum of %s allowed per load balancer" % MAX_NODES_PER_LOADBALANCER)
 
        task_list = []

        for node in nodes:

            if not "id" in node:
                operation = "ADD"
                nodeid = NitroUtils.generate_nodeid(existing_ids)
                existing_ids.append(nodeid) 
                node.id = str(nodeid)

            else:
                operation = "UPDATE"

            task = self._get_netscaler_addservice_task(loadBalancerId, loadBalancer, node.id, node)
            task["operation"] = operation
            task_list.append(task)    
              
            task = self.get_netscaler_addservicebinding_task(loadBalancerId, loadBalancer, node.id, node)
            task_list.append(task)

            service_name = NitroUtils.get_servicename_from_nodeid(loadBalancerId, node.id)

            if operation == "ADD": 
                task = self._get_netscaler_addservicestatus_task(loadBalancerId, loadBalancer, node.id, node)
                task = self._get_netscaler_addmonitorbinding_task(loadBalancerId, loadBalancer, node)

            if operation == "UPDATE":
                task = self._get_netscaler_updateservicestatus_task(loadBalancerId, loadBalancer, node.id, node)

            if task:
                task_list.append(task) 
        

        return task_list  
Пример #4
0
    def _get_netscaler_removeservice_task(self, loadBalancerId, loadBalancer, nodeId):
                 
        servicename = NitroUtils.get_servicename_from_nodeid(loadBalancerId, nodeId)
                                                                                          
        task = {}
        task["type"] = "service"
        task["name"] = servicename
        task["operation"] = "REMOVE"
        task["state"] = None

        return task
Пример #5
0
    def _get_netscaler_node_currentcondition(self, loadBalancerId, loadBalancer, nodeId):

        service_name = NitroUtils.get_servicename_from_nodeid(loadBalancerId, nodeId)

        service = self.nitrowrapper.get_netscaler_entity("service", service_name)

        svrstate = service["svrstate"]

        current_condition = NitroUtils.get_condition_from_svrstate(svrstate)

        return current_condition
    def _get_netscaler_monitorbinding_from_healthmonitor(
            self, loadBalancerId, node, healthMonitor):

        monitor_name = NitroUtils.get_monitorname_from_loadBalancerId(
            loadBalancerId)
        service_name = NitroUtils.get_servicename_from_nodeid(
            loadBalancerId, node.id)

        monitor_binding = {}
        monitor_binding["monitorname"] = monitor_name
        monitor_binding["servicename"] = service_name

        return monitor_binding
Пример #7
0
    def get_netscaler_removeservicebinding_task(self, loadBalancerId, loadBalancer, nodeId):

        lbvserver_name = NitroUtils.get_lbvservername_from_loadbalancerid(loadBalancerId)
        servicename = NitroUtils.get_servicename_from_nodeid(loadBalancerId, nodeId)

        args = "servicename:" +  servicename
        args += ","
        args += "name:" + lbvserver_name

        task = {}
        task["type"] = "lbvserver_service_binding"
        task["name"] = lbvserver_name + "?args=" + args
        task["operation"] = "REMOVE"
        task["state"] = None

        return task
    def get_netscaler_removemonitorbinding_task(self, loadBalancerId,
                                                loadBalancer, nodeId):

        monitor_name = NitroUtils.get_monitorname_from_loadBalancerId(
            loadBalancerId)
        servicename = NitroUtils.get_servicename_from_nodeid(
            loadBalancerId, nodeId)

        args = "servicename:" + servicename

        task = {}
        task["type"] = "lbmonitor_service_binding"
        task["name"] = monitor_name + "?args=" + args
        task["operation"] = "REMOVE"
        task["state"] = None

        return task
Пример #9
0
    def _get_netscaler_getservicebinding_task(self, loadBalancerId, loadBalancer, nodeId):

        self.logger.debug("loadBalancer Id is: %s" % loadBalancerId)
        self.logger.debug("node Id is: %s" % nodeId)

        lbvserver_name = NitroUtils.get_lbvservername_from_loadbalancerid(loadBalancerId) 
        service_name = NitroUtils.get_servicename_from_nodeid(loadBalancerId, nodeId)

        args = "servicename:" + service_name
                                                                                                        
        task = {}

        task["type"] = "lbvserver_service_binding"
        task["name"] = lbvserver_name + "?filter=" + args
        task["operation"] = "GET"
        task["state"] = None

        return task
Пример #10
0
    def _get_netscaler_servicebinding_from_node(self, loadBalancerId, loadBalancer, nodeId, node):

        service_binding_obj = {}

        lbvserver_name = NitroUtils.get_lbvservername_from_loadbalancerid(loadBalancerId)
        service_name =  NitroUtils.get_servicename_from_nodeid(loadBalancerId, nodeId)

        service_binding_obj["name"] = lbvserver_name
        service_binding_obj["servicename"] = service_name


        if "weight" in node and node.weight != 1 :
            if not loadBalancer.algorithm.startswith("WEIGHTED_"):
                raise BadRequestException("validation fault", "invalid object", 
                                          "LB algorithm in use doesn't allow for weighted nodes")

            service_binding_obj["weight"] = node["weight"]

        return service_binding_obj
Пример #11
0
    def _get_netscaler_addservicestatus_task(self, loadBalancerId, loadBalancer, nodeId, node):

        if not "condition" in node:
            return None

        service_name = NitroUtils.get_servicename_from_nodeid(loadBalancerId, nodeId)

        service = {}
        service["name"] = service_name

        task = {}
        task["type"] = "service"
        task["name"] = service_name
        task["state"] = service

        if node.condition == "ENABLED":
            task["operation"] = "ENABLE"
        else:
            task["operation"] = "DISABLE" 

        return task