Exemplo n.º 1
0
    def execute(self, l7rule, listeners, vthunder):
        policy = l7rule.l7policy
        rules = policy.l7rules

        for index, rule in enumerate(rules):
            if rule.id == l7rule.id:
                del rules[index]
                break
        policy.rules = rules
        l7rule.l7policy = policy
        l7policy = l7rule.l7policy
        filename = l7policy.id
        p = PolicyUtil()
        script = p.createPolicy(l7policy)
        size = len(script.encode('utf-8'))
        listener = listeners[0]
        c_pers, s_pers = utils.get_sess_pers_templates(listener.default_pool)
        kargs = {}
        listener.protocol = openstack_mappings.virtual_port_protocol(
            self.axapi_client, listener.protocol)
        try:
            self.axapi_client.slb.aflex_policy.create(file=filename,
                                                      script=script,
                                                      size=size,
                                                      action="import")
            LOG.debug("Successfully deleted l7rule: %s", l7rule.id)
        except (acos_errors.ACOSException, exceptions.ConnectionError) as e:
            LOG.warning("Failed to delete l7rule: %s", str(e))
            raise e

        try:
            get_listener = self.axapi_client.slb.virtual_server.vport.get(
                listener.load_balancer_id, listener.name, listener.protocol,
                listener.protocol_port)
            LOG.debug("Successfully fetched listener %s for l7rule %s",
                      listener.id, l7rule.id)
        except (acos_errors.ACOSException, exceptions.ConnectionError) as e:
            LOG.exception("Failed to get listener %s for l7rule: %s",
                          listener.id, l7rule.id)
            raise e

        if 'aflex-scripts' in get_listener['port']:
            aflex_scripts = get_listener['port']['aflex-scripts']
            aflex_scripts.append({"aflex": filename})
        else:
            aflex_scripts = [{"aflex": filename}]
        kargs["aflex-scripts"] = aflex_scripts

        try:
            self.axapi_client.slb.virtual_server.vport.update(
                listener.load_balancer_id, listener.name, listener.protocol,
                listener.protocol_port, listener.default_pool_id, s_pers,
                c_pers, 1, **kargs)
            LOG.debug("Successfully dissociated l7rule %s from listener %s",
                      l7rule.id, listener.id)
        except (acos_errors.ACOSException, exceptions.ConnectionError) as e:
            LOG.exception("Failed to dissociate l7rule %s from listener %s",
                          l7rule.id, listener.id)
            raise e
Exemplo n.º 2
0
    def execute(self, l7rule, listeners, vthunder):
        policy = l7rule.l7policy
        rules = policy.l7rules

        for index, rule in enumerate(rules):
            if rule.id == l7rule.id:
                del rules[index]
                break
        policy.rules = rules
        l7rule.l7policy = policy
        l7policy = l7rule.l7policy
        filename = l7policy.id
        p = PolicyUtil()
        script = p.createPolicy(l7policy)
        size = len(script.encode('utf-8'))
        listener = listeners[0]
        c_pers, s_pers = utils.get_sess_pers_templates(listener.default_pool)
        kargs = {}
        try:
            self.axapi_client.slb.aflex_policy.create(file=filename,
                                                      script=script,
                                                      size=size,
                                                      action="import")
            LOG.debug("aFlex policy deleted successfully.")
        except Exception as e:
            LOG.warning("Failed to delete l7rule: %s", str(e))
            raise

        try:
            get_listener = self.axapi_client.slb.virtual_server.vport.get(
                listener.load_balancer_id, listener.name, listener.protocol,
                listener.protocol_port)
        except Exception as e:
            LOG.warning("Failed to delete l7rule: %s", str(e))
            raise

        aflex_scripts = []
        if 'aflex-scripts' in get_listener['port']:
            aflex_scripts = get_listener['port']['aflex-scripts']
            aflex_scripts.append({"aflex": filename})
        else:
            aflex_scripts = [{"aflex": filename}]
        kargs["aflex-scripts"] = aflex_scripts

        try:
            self.axapi_client.slb.virtual_server.vport.update(
                listener.load_balancer_id, listener.name, listener.protocol,
                listener.protocol_port, listener.default_pool_id, s_pers,
                c_pers, 1, **kargs)
            LOG.debug("Listener updated successfully: %s", listener.id)
        except Exception as e:
            LOG.warning("Failed to delete l7rule: %s", str(e))
            raise
Exemplo n.º 3
0
    def execute(self, l7rule, listeners, vthunder):
        """ Execute create health monitor for amphora """
        axapi_version = acos_client.AXAPI_21 if vthunder.axapi_version == 21 else acos_client.AXAPI_30
        try:
            l7policy = l7rule.l7policy
            filename = l7policy.id
            action = "import"
            p = PolicyUtil()
            script = p.createPolicy(l7policy)
            size = len(script.encode('utf-8'))
            c = self.client_factory(vthunder)
            out = c.slb.aflex_policy.create(file=filename,
                                            script=script,
                                            size=size,
                                            action=action)
            LOG.info("aFlex policy created successfully.")
        except Exception as e:
            print(str(e))
            LOG.info("Error occurred")
        try:
            # get SLB vPort
            listener = listeners[0]

            new_listener = listeners[0]
            c = self.client_factory(vthunder)
            get_listener = c.slb.virtual_server.vport.get(
                listener.load_balancer_id, listener.name, listener.protocol,
                listener.protocol_port)

            aflex_scripts = []
            if 'aflex-scripts' in get_listener['port']:
                aflex_scripts = get_listener['port']['aflex-scripts']
                aflex_scripts.append({"aflex": filename})
            else:
                aflex_scripts = [{"aflex": filename}]

            persistence = persist.PersistHandler(c, listener.default_pool)

            s_pers = persistence.s_persistence()
            c_pers = persistence.c_persistence()

            kargs = {}
            kargs["aflex-scripts"] = aflex_scripts

            update_listener = c.slb.virtual_server.vport.update(
                listener.load_balancer_id, listener.name, listener.protocol,
                listener.protocol_port, listener.default_pool_id, s_pers,
                c_pers, 1, **kargs)
            LOG.info("Listener updated successfully.")
        except Exception as e:
            print(str(e))
            LOG.info("Error occurred")
Exemplo n.º 4
0
    def set(self, l7policy, listeners):
        filename = l7policy.id
        p = PolicyUtil()
        script = p.createPolicy(l7policy)
        size = len(script.encode('utf-8'))
        listener = listeners[0]
        c_pers, s_pers = utils.get_sess_pers_templates(listener.default_pool)
        kargs = {}
        listener.protocol = openstack_mappings.virtual_port_protocol(self.axapi_client,
                                                                     listener.protocol)
        try:
            self.axapi_client.slb.aflex_policy.create(
                file=filename, script=script, size=size, action="import")
            LOG.debug("Successfully created l7policy: %s", l7policy.id)
        except (acos_errors.ACOSException, exceptions.ConnectionError) as e:
            LOG.exception("Failed to create/update l7policy: %s", l7policy.id)
            raise e

        try:
            get_listener = self.axapi_client.slb.virtual_server.vport.get(
                listener.load_balancer_id, listener.id,
                listener.protocol, listener.protocol_port)
            LOG.debug("Successfully fetched listener %s for l7policy %s", listener.id, l7policy.id)
        except (acos_errors.ACOSException, exceptions.ConnectionError) as e:
            LOG.exception("Failed to get listener %s for l7policy: %s", listener.id, l7policy.id)
            raise e

        if 'aflex-scripts' in get_listener['port']:
            aflex_scripts = get_listener['port']['aflex-scripts']
            aflex_scripts.append({"aflex": filename})
        else:
            aflex_scripts = [{"aflex": filename}]
        kargs["aflex_scripts"] = aflex_scripts

        try:
            self.axapi_client.slb.virtual_server.vport.update(
                listener.load_balancer_id, listener.id,
                listener.protocol, listener.protocol_port,
                listener.default_pool_id, s_pers,
                c_pers, 1, **kargs)
            LOG.debug(
                "Successfully associated l7policy %s to listener %s",
                l7policy.id,
                listener.id)
        except (acos_errors.ACOSException, exceptions.ConnectionError) as e:
            LOG.exception(
                "Failed to associate l7policy %s to listener %s",
                l7policy.id,
                listener.id)
            raise e
Exemplo n.º 5
0
    def set(self, l7rule, listeners):
        l7policy = l7rule.l7policy
        filename = l7policy.id
        p = PolicyUtil()
        script = p.createPolicy(l7policy)
        size = len(script.encode('utf-8'))
        listener = listeners[0]
        c_pers, s_pers = utils.get_sess_pers_templates(listener.default_pool)
        kargs = {}
        get_listener = None
        try:
            self.axapi_client.slb.aflex_policy.create(file=filename,
                                                      script=script,
                                                      size=size,
                                                      action="import")
            LOG.debug("aFlex policy created successfully.")
        except Exception as e:
            LOG.exception("Failed to create/update l7rule: %s", str(e))
            raise

        try:
            get_listener = self.axapi_client.slb.virtual_server.vport.get(
                listener.load_balancer_id, listener.name, listener.protocol,
                listener.protocol_port)
        except Exception as e:
            LOG.exception("Failed to get listener for l7rule: %s", str(e))
            raise

        aflex_scripts = []
        if 'aflex-scripts' in get_listener['port']:
            aflex_scripts = get_listener['port']['aflex-scripts']
            aflex_scripts.append({"aflex": filename})
        else:
            aflex_scripts = [{"aflex": filename}]
        kargs["aflex-scripts"] = aflex_scripts

        try:
            self.axapi_client.slb.virtual_server.vport.update(
                listener.load_balancer_id, listener.name, listener.protocol,
                listener.protocol_port, listener.default_pool_id, s_pers,
                c_pers, 1, **kargs)
            LOG.debug("Listener updated successfully: %s", listener.id)
        except Exception as e:
            LOG.exception("Failed to create/update l7rule: %s", str(e))
            raise