def update_LoadBalancer(self, loadBalancerId, updatedLoadBalancer,
                            tenant_id):

        self._setup_nitrowrapper(tenant_id, loadBalancerId)

        dbLoadBalancer = self._get_new_loadBalancer_object()

        dbLoadBalancer = self.db.fill_loadBalancer_object(
            tenant_id, loadBalancerId, dbLoadBalancer)

        if not dbLoadBalancer:
            raise ItemNotFoundException(
                "No loadBalancer with id %s was found" % loadBalancerId)

        if dbLoadBalancer.status == "DELETED":
            raise ImmutableEntityException(
                "loadBalancer with id %s was deleted and cannot be updated" %
                loadBalancerId)

        internalLoadBalancer = updatedLoadBalancer

        internalLoadBalancerId = NitroUtils.get_internal_loadBalancerId(
            tenant_id, loadBalancerId, dbLoadBalancer)

        self._update_LoadBalancerInternal(internalLoadBalancerId,
                                          internalLoadBalancer)

        dbLoadBalancer = self.db.update_loadBalancer(tenant_id, loadBalancerId,
                                                     internalLoadBalancer)

        internalLoadBalancerId = NitroUtils.get_internal_loadBalancerId(
            tenant_id, loadBalancerId, dbLoadBalancer)

        loadBalancer = self._get_LoadBalancerInternal(internalLoadBalancerId)

        loadBalancer.id = dbLoadBalancer.id
        loadBalancer.protocol = dbLoadBalancer.protocol
        loadBalancer.algorithm = dbLoadBalancer.algorithm
        loadBalancer.created = dbLoadBalancer.created
        loadBalancer.updated = dbLoadBalancer.updated

        self.db.fill_loadBalancer_vips_info(tenant_id, loadBalancer.id,
                                            loadBalancer)

        self.logger.debug(
            "Successfully completed update loadbalancer operation on the adapter"
        )

        return loadBalancer
Exemplo n.º 2
0
    def update_LBNode(self, loadBalancerId, nodeId, lbnode, tenant_id):

        self._setup_nitrowrapper(tenant_id, loadBalancerId)


        """"
        dbLoadBalancer = self._get_new_loadBalancer_object()

        dbLoadBalancer = self.db.fill_loadBalancer_object(tenant_id, loadBalancerId, dbLoadBalancer)

        if not dbLoadBalancer:
            raise ItemNotFoundException("No loadBalancer with id %s was found" % loadBalancerId)
        
        if dbLoadBalancer.status == "DELETED":
            raise ImmutableEntityException("loadBalancer with id %s was deleted and cannot be updated" % loadBalancerId)
        """

        loadBalancer = self.lbadapter.get_LoadBalancer(loadBalancerId, tenant_id)


        internal_loadBalancerId = NitroUtils.get_internal_loadBalancerId(tenant_id, loadBalancerId, loadBalancer)

        lbnode.id = nodeId
 
        lbnode = self._update_LBNodeInternal(internal_loadBalancerId, loadBalancer, nodeId, lbnode)

        self.db.update_loadBalancer_updatetime(tenant_id, loadBalancerId)
 
        return lbnode
    def add_LoadBalancer(self, newLoadBalancer, tenant_id):

        self.logger.debug("adding loadbalancer %s" % repr(newLoadBalancer))

        existing_ids = self.db.get_tenant_loadBalancers(tenant_id)
        loadBalancerId = str(NitroUtils.generate_loadbalancerid(existing_ids))

        self._setup_nitrowrapper(tenant_id, loadBalancerId)

        self._allocate_loadBalancer_vips(newLoadBalancer, tenant_id,
                                         loadBalancerId)

        internalLoadBalancer = newLoadBalancer
        internalLoadBalancerId = NitroUtils.get_internal_loadBalancerId(
            tenant_id, loadBalancerId, internalLoadBalancer)

        self._add_LoadBalancerInternal(internalLoadBalancerId,
                                       internalLoadBalancer)

        loadBalancer = self._get_LoadBalancerInternal(internalLoadBalancerId)

        loadBalancer.id = loadBalancerId
        loadBalancer.protocol = internalLoadBalancer.protocol
        loadBalancer.algorithm = internalLoadBalancer.algorithm

        self.db.create_loadBalancer(tenant_id, loadBalancer)

        self.db.fill_loadBalancer_vips_info(tenant_id, loadBalancer.id,
                                            loadBalancer)

        return loadBalancer
Exemplo n.º 4
0
    def list_LBNodes(self, tenant_id, loadBalancerId):

        self._setup_nitrowrapper(tenant_id, loadBalancerId)

        loadBalancer = self.lbadapter.get_LoadBalancer(loadBalancerId, tenant_id)

        internal_loadBalancerId = NitroUtils.get_internal_loadBalancerId(tenant_id, loadBalancerId, loadBalancer)

        return self._list_LBNodesInternal(internal_loadBalancerId, loadBalancer)
Exemplo n.º 5
0
    def remove_LBNode(self, loadBalancerId, nodeId, tenant_id):

        self._setup_nitrowrapper(tenant_id, loadBalancerId)

        loadBalancer = self.lbadapter.get_LoadBalancer(loadBalancerId, tenant_id)

        internal_loadBalancerId = NitroUtils.get_internal_loadBalancerId(tenant_id, loadBalancerId, loadBalancer)

        self._remove_LBNodeInternal(internal_loadBalancerId, loadBalancer, nodeId)

        self.db.update_loadBalancer_updatetime(tenant_id, loadBalancerId)
Exemplo n.º 6
0
    def get_LBNode(self, tenant_id, loadBalancerId, nodeId):

        self._setup_nitrowrapper(tenant_id, loadBalancerId)

        loadBalancer = self.lbadapter.get_LoadBalancer(loadBalancerId, tenant_id)

        internal_loadBalancerId = NitroUtils.get_internal_loadBalancerId(tenant_id, loadBalancerId, loadBalancer)

        lbnode = self._get_LBNodeInternal(internal_loadBalancerId, loadBalancer, nodeId)

        return lbnode 
    def remove_LoadBalancer(self, loadBalancerId, tenant_id):

        self._setup_nitrowrapper(tenant_id, loadBalancerId)

        loadBalancer = self.get_LoadBalancer(loadBalancerId, tenant_id)

        internal_loadBalancerId = NitroUtils.get_internal_loadBalancerId(
            tenant_id, loadBalancerId, loadBalancer)

        self._remove_LoadBalancerInternal(internal_loadBalancerId,
                                          loadBalancer)

        self.db.remove_loadBalancer(tenant_id, loadBalancerId)
    def get_LBHealthMonitor(self, tenant_id, loadBalancerId):

        self._setup_nitrowrapper(tenant_id, loadBalancerId)

        loadBalancer = self.lbadapter.get_LoadBalancer(loadBalancerId,
                                                       tenant_id)

        internal_loadBalancerId = NitroUtils.get_internal_loadBalancerId(
            tenant_id, loadBalancerId, loadBalancer)

        healthMonitor = self._get_LBHealthMonitorInternal(
            internal_loadBalancerId, loadBalancer)

        return healthMonitor
Exemplo n.º 9
0
    def add_LBNode(self, lbnode, tenant_id, loadBalancerId):

        self._setup_nitrowrapper(tenant_id, loadBalancerId)

        loadBalancer = self.lbadapter.get_LoadBalancer(loadBalancerId, tenant_id)


        internal_loadBalancerId = NitroUtils.get_internal_loadBalancerId(tenant_id, loadBalancerId, loadBalancer)

        task_list = self._get_netscaler_tasks("ADD", internal_loadBalancerId, loadBalancer, node=lbnode)
        
        self.logger.debug("add task list: " + str(task_list))

        self.nitrowrapper.process_netscaler_task_list(task_list) 

        added_node = self.get_LBNode(tenant_id, loadBalancerId, lbnode.id)

        self.db.update_loadBalancer_updatetime(tenant_id, loadBalancerId)

        return added_node
    def update_LBHealthMonitor(self, tenant_id, loadBalancerId, healthMonitor):

        self._setup_nitrowrapper(tenant_id, loadBalancerId)

        loadBalancer = self.lbadapter.get_LoadBalancer(loadBalancerId,
                                                       tenant_id)

        if loadBalancer.status == "DELETED":
            raise ItemNotFoundException("loadbalancer %s not found" %
                                        loadBalancerId)

        internal_loadBalancerId = NitroUtils.get_internal_loadBalancerId(
            tenant_id, loadBalancerId, loadBalancer)

        healthMonitor = self._update_LBHealthMonitorInternal(
            internal_loadBalancerId, loadBalancer, healthMonitor)

        self.db.update_loadBalancer_updatetime(tenant_id, loadBalancerId)

        return healthMonitor
    def get_LoadBalancer(self, loadBalancerId, tenant_id):

        self._setup_nitrowrapper(tenant_id, loadBalancerId)

        dbLoadBalancer = self._get_new_loadBalancer_object()

        dbLoadBalancer = self.db.fill_loadBalancer_object(
            tenant_id, loadBalancerId, dbLoadBalancer)

        if not dbLoadBalancer:
            raise ItemNotFoundException(
                "No loadBalancer with id %s was found" % loadBalancerId)

        if dbLoadBalancer.status == "DELETED":
            dict_obj = dbLoadBalancer.get_as_dictionary()
            del dict_obj["protocol"]
            del dict_obj["algorithm"]

            return dbLoadBalancer

        internal_loadBalancerId = NitroUtils.get_internal_loadBalancerId(
            tenant_id, loadBalancerId, dbLoadBalancer)

        loadBalancer = self._get_LoadBalancerInternal(internal_loadBalancerId)

        loadBalancer.id = dbLoadBalancer.id
        """ XXX- We should check whether the values in the DB are different from those returned from NetScaler
                 and change the DB to match what is on NetScaler (NetScaler is the authoritative source)
        """

        loadBalancer.protocol = dbLoadBalancer.protocol
        loadBalancer.algorithm = dbLoadBalancer.algorithm
        loadBalancer.created = dbLoadBalancer.created
        loadBalancer.updated = dbLoadBalancer.updated

        self.db.fill_loadBalancer_vips_info(tenant_id, loadBalancer.id,
                                            loadBalancer)

        return loadBalancer
Exemplo n.º 12
0
    def add_LBNodes(self, lbnodes, tenant_id, loadBalancerId):

        self._setup_nitrowrapper(tenant_id, loadBalancerId)

        self.logger.debug("Adding nodes to loadbalancer %s" % loadBalancerId)

        loadBalancer = self.lbadapter.get_LoadBalancer(loadBalancerId, tenant_id)

        internal_loadBalancerId = NitroUtils.get_internal_loadBalancerId(tenant_id, loadBalancerId, loadBalancer)

        task_list = self._get_netscaler_tasks("ADDMULTI", internal_loadBalancerId, loadBalancer, node=lbnodes)

        self.nitrowrapper.process_netscaler_task_list(task_list) 

        added_nodes = []

        for lbnode in lbnodes:
            node = self._get_LBNodeInternal(internal_loadBalancerId, loadBalancer, lbnode.id)
            added_nodes.append(node)     

        self.db.update_loadBalancer_updatetime(tenant_id, loadBalancerId)

        return added_nodes