Ejemplo n.º 1
0
    def _delete_vip(self, tratado):

        pools_del = list()
        vts = virtualserver.VirtualServer(self._lb)
        try:
            self._lb._channel.System.Session.start_transaction()
            if tratado.get('vips'):
                vps_names = [vp['name'] for vp in tratado.get('vips')]
                vts.delete(vps_names=vps_names)

                rule_l7 = [
                    '{}_RULE_L7'.format(vp['name'])
                    for vp in tratado.get('vips') if vp.get('pool_l7')
                ]
                if rule_l7:
                    rl = rule.Rule(self._lb)
                    rl.delete(rule_names=rule_l7)

            # CACHE
            if tratado.get('vips_cache'):
                vps_names = [vp['name'] for vp in tratado.get('vips_cache')]
                vts.delete(vps_names=vps_names)
        except Exception, e:
            self._lb._channel.System.Session.rollback_transaction()
            log.error(e)
            raise e
Ejemplo n.º 2
0
    def _cleanup_vip(self, tratado):

        pools_del = list()
        vts = virtualserver.VirtualServer(self._lb)
        if tratado.get('vips'):
            for vip in tratado.get('vips'):
                try:
                    vts.delete(vps_names=[vip['name']])
                except:
                    pass

                try:
                    if vip.get('pool_l7'):
                        rl = rule.Rule(self._lb)
                        rl.delete(rule_names='{}_RULE_L7'.format(vip['name']))
                except:
                    pass

        # CACHE
        if tratado.get('vips_cache'):
            for vip in tratado.get('vips_cache'):
                vts.delete(vps_names=[vip['name']])
    def update(self, **kwargs):
        self.__properties = {
            'profiles': list(),
            'profiles_timeout_tcp': {
                'profile_names': list(),
                'timeouts': list()
            },
            'profiles_timeout_udp': {
                'profile_names': list(),
                'timeouts': list()
            },
            'profiles_timeout_fastl4': {
                'profile_names': list(),
                'timeouts': list(),
                'loose_close_state': list(),
            },
            'profiles_persistence': {
                'virtual_servers': list(),
                'profiles': list()
            },
            'translate_port_state': {
                'virtual_servers': list(),
                'states': list()
            },
            'vip_snat_auto': {
                'virtual_servers': list()
            },
            'vip_snat_none': {
                'virtual_servers': list()
            },
            'vip_snat_pool': {
                'virtual_servers': list(),
                'pools': list()
            }
        }

        virtual_servers = [
            vip_request['name'] for vip_request in kwargs['vips']
        ]

        resources = {'virtual_servers': list(), 'pool': list()}

        vip_rules = {'virtual_servers': list(), 'rules': list()}

        vip_dscp = {'pool_names': list(), 'values': list()}

        rule_l7 = list()
        rule_l7_delete = list()

        profiles_list = list()

        for idx, vip_request in enumerate(kwargs['vips']):

            self.__prepare_properties(vip_request, profiles_list)

            # default pool
            resources['pool'].append(vip_request['pool'])
            resources['virtual_servers'].append(vip_request['name'])

            # DSCP
            vip_dscp['values'].append(
                vip_request['optionsvip']['dscp']['value'])
            vip_dscp['pool_names'].append(
                vip_request['optionsvip']['dscp']['pool_name'])

            # RULES

            rules = list()
            if vip_request.get('pool_l7'):
                rule_definition = vip_request['pool_l7']
                rule_name = '{}_RULE_L7'.format(vip_request['name'])

                rule_l7.append({
                    'rule_name': rule_name,
                    'rule_definition': rule_definition
                })

                rules.append({'rule_name': rule_name, 'priority': 1})
            else:
                rule_l7_delete.append('{}_RULE_L7'.format(vip_request['name']))

            if vip_request.get('rules'):
                for rule_name in vip_request['rules']:
                    rules.append({'rule_name': rule_name, 'priority': 1})

            if rules:
                vip_rules['rules'].append(rules)
                vip_rules['virtual_servers'].append(vip_request['name'])

        try:
            self._lb._channel.System.Session.start_transaction()

            if rule_l7:
                rl = rule.Rule(self._lb)
                rls = rl.list()
                for rl_l7 in rule_l7:
                    if '/Common/{}'.format(rl_l7['rule_name']) in rls:
                        rl.update(rules=[rl_l7])
                    else:
                        rl.create(rules=[rl_l7])

        except Exception, e:
            log.error(e)
            self._lb._channel.System.Session.rollback_transaction()
            raise e
    def create(self, **kwargs):
        self.__properties = {
            'profiles': list(),
            'profiles_timeout_tcp': {
                'profile_names': list(),
                'timeouts': list()
            },
            'profiles_timeout_udp': {
                'profile_names': list(),
                'timeouts': list()
            },
            'profiles_timeout_fastl4': {
                'profile_names': list(),
                'timeouts': list(),
                'loose_close_state': list(),
            },
            'profiles_persistence': {
                'virtual_servers': list(),
                'profiles': list()
            },
            'translate_port_state': {
                'virtual_servers': list(),
                'states': list()
            },
            'vip_snat_auto': {
                'virtual_servers': list()
            },
            'vip_snat_none': {
                'virtual_servers': list()
            },
            'vip_snat_pool': {
                'virtual_servers': list(),
                'pools': list()
            }
        }
        vip_definitions = list()
        vip_wildmasks = list()
        vip_resources = list()
        vip_profiles = list()

        vip_rules = {'virtual_servers': list(), 'rules': list()}

        vip_traffic_groups = {
            'virtual_addresses': list(),
            'traffic_groups': list()
        }

        vip_dscp = {'pool_names': list(), 'values': list()}

        rule_l7 = list()

        fastl4 = ProfileFastL4(self._lb)
        tcp = ProfileTCP(self._lb)
        http = ProfileHttp(self._lb)
        udp = ProfileUDP(self._lb)
        profiles_list = tcp.get_list() + http.get_list() + \
            fastl4.get_list() + udp.get_list()

        for vip_request in kwargs['vips']:

            self.__prepare_properties(vip_request, profiles_list)

            # VIP
            vip_definitions.append({
                'name':
                vip_request['name'],
                'address':
                vip_request['address'],
                'port':
                vip_request['port'],
                'protocol':
                types.procotol_type(vip_request['optionsvip']['l4_protocol']
                                    ['nome_opcao_txt'].lower())
            })

            vip_wildmasks.append('255.255.255.255')

            vip_resources.append({
                'type': 'RESOURCE_TYPE_POOL',
                'default_pool_name': vip_request.get('pool')
            })

            # DSCP
            if vip_request.get('optionsvip').get('dscp'):
                vip_dscp['values'].append(
                    vip_request['optionsvip']['dscp']['value'])
                vip_dscp['pool_names'].append(
                    vip_request['optionsvip']['dscp']['pool_name'])

            # TRAFFIC GROUP
            if vip_request.get('optionsvip').get('traffic_group'):
                vip_traffic_groups['virtual_addresses'].append(
                    vip_request['address'])
                vip_traffic_groups['traffic_groups'].append(
                    vip_request['optionsvip']['traffic_group'])

            # RULES
            rules = list()
            if vip_request.get('pool_l7'):
                rule_definition = vip_request['pool_l7']
                rule_name = '{}_RULE_L7'.format(vip_request['name'])

                rule_l7.append({
                    'rule_name': rule_name,
                    'rule_definition': rule_definition
                })

                rules.append({'rule_name': rule_name, 'priority': 1})

            if vip_request.get('rules'):
                for rule_name in vip_request['rules']:
                    rules.append({'rule_name': rule_name, 'priority': 1})

            if rules:
                vip_rules['rules'].append(rules)
                vip_rules['virtual_servers'].append(vip_request['name'])

        try:
            self._lb._channel.System.Session.start_transaction()

            if rule_l7:
                rl = rule.Rule(self._lb)
                rl.create(rules=rule_l7)

        except Exception, e:
            log.error(e)
            self._lb._channel.System.Session.rollback_transaction()
            raise e
                    self.__properties['profiles_persistence'])

                self.__set_dscp(dscp=vip_dscp)

                self.__set_translate_port_state(
                    self.__properties['translate_port_state'])

            except Exception, e:
                log.error(e)
                self._lb._channel.System.Session.rollback_transaction()
                raise e
            else:
                self._lb._channel.System.Session.submit_transaction()

                if rule_l7_delete:
                    rl = rule.Rule(self._lb)
                    for rl_l7 in rule_l7_delete:
                        try:
                            rl.delete(rule_names=[rl_l7])
                        except Exception, e:
                            log.info(e)
                            pass

    @logger
    def __create_vip(self, **kwargs):
        self._lb._channel.LocalLB.VirtualServer.create(
            definitions=kwargs['definitions'],
            wildmasks=kwargs['wildmasks'],
            resources=kwargs['resources'],
            profiles=kwargs['profiles'])