当前位置: 首页>>代码示例>>Python>>正文


Python models.EnvironmentVip类代码示例

本文整理汇总了Python中networkapi.ambiente.models.EnvironmentVip的典型用法代码示例。如果您正苦于以下问题:Python EnvironmentVip类的具体用法?Python EnvironmentVip怎么用?Python EnvironmentVip使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了EnvironmentVip类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_environment_vip

def create_environment_vip(environment_vip):

    try:
        env = EnvironmentVip()
        env.create_v3(environment_vip)
    except Exception, e:
        raise NetworkAPIException(str(e))
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:7,代码来源:facade.py

示例2: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Handles GET requests to find all finalitys of environment VIP.

        URLs: /vip/get/finality
        """

        self.log.info("Find all finality distinct of environment_vip")

        try:
            # Commons Validations

            # User permission
            if not has_perm(user, AdminPermission.VIPS_REQUEST, AdminPermission.READ_OPERATION):
                self.log.error(u"User does not have permission to perform the operation.")
                return self.not_authorized()

            evip = EnvironmentVip()
            # Business Validations
            evips = evip.list_all_finalitys()

            finality_map = dict()
            finality_list = []

            for evip in evips:
                finality_map["finality"] = evip.get("finalidade_txt")
                finality_list.append(finality_map)
                finality_map = dict()

            return self.response(dumps_networkapi({"finalidade": finality_list}))

        except InvalidValueError, e:
            self.log.error(u"Parameter %s is invalid. Value: %s.", e.param, e.value)
            return self.response_error(269, e.param, e.value)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:33,代码来源:EnvironmentVipGetFinalityResource.py

示例3: handle_post

    def handle_post(self, request, user, *args, **kwargs):
        """Treat requests Post to search cliente_txt of  Environment VIP by finalidade_txt

        URL: environmentvip/search/
        """

        try:

            self.log.info(
                'Search cliente_txt Environment VIP by finalidade_txt')

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no value to the networkapi tag of XML request.')

            environmentvip_map = networkapi_map.get('vip')
            if environmentvip_map is None:
                return self.response_error(3, u'There is no value to the vip tag of XML request.')

            # Get XML data
            finalidade = environmentvip_map.get('finalidade_txt')
            if not is_valid_string_maxsize(finalidade, 50) or not is_valid_string_minsize(finalidade, 3) or not is_valid_text(finalidade):
                self.log.error(
                    u'The finalidade_txt parameter is not a valid value: %s.', finalidade)
                raise InvalidValueError(None, 'finalidade_txt', finalidade)

            environmentVip = EnvironmentVip()

            evip_values = environmentVip.list_all_clientes_by_finalitys(
                finalidade)

            evips = dict()
            evips_list = []

            for evip in evip_values:
                evips['finalidade_txt'] = finalidade
                evips['cliente_txt'] = evip.get('cliente_txt')
                evips_list.append(evips)
                evips = dict()

            return self.response(dumps_networkapi({'cliente_txt': evips_list}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:54,代码来源:EnvironmentVipGetClienteTxtResource.py

示例4: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat GET requests list all Environment VIP Availables.

        URL: environmentvip/search/id_vlan
        """
        try:

            id_vlan = int(kwargs['id_vlan'])

            self.log.info("List all Environment VIP availables")

            # Commons Validations

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Business Rules
            evips = EnvironmentVip.objects.all()
            evip_list = EnvironmentVip.available_evips(
                EnvironmentVip(), evips, id_vlan)

            return self.response(dumps_networkapi({'environment_vip': evip_list}))

        except (EnvironmentVipError, GrupoError), e:
            self.log.error(e)
            return self.response_error(1)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:29,代码来源:EnvironmentVipSearchResource.py

示例5: handle_delete

    def handle_delete(self, request, user, *args, **kwargs):
        """
        Handles DELETE requests to create a relationship of Environment with EnvironmentVip.

        URL: environment/<environment_id>/environmentvip/<environment_vip_id>/
        """

        self.log.info("Remove a relationship of Environment with EnvironmentVip")

        try:

            # Commons Validations

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                self.log.error(u"User does not have permission to perform the operation.")
                raise UserNotAuthorizedError(None)

            # Valid Environment
            environment_id = kwargs.get("environment_id")
            if not is_valid_int_greater_zero_param(environment_id):
                self.log.error(u"The environment_id parameter is not a valid value: %s.", environment_id)
                raise InvalidValueError(None, "environment_id", environment_id)

            # Valid EnvironmentVip ID
            environment_vip_id = kwargs.get("environment_vip_id")
            if not is_valid_int_greater_zero_param(environment_vip_id):
                self.log.error(u"The id_environment_vip parameter is not a valid value: %s.", environment_vip_id)
                raise InvalidValueError(None, "environment_vip_id", environment_vip_id)

            # Business Validations

            # Existing Environment ID
            environment = Ambiente.get_by_pk(environment_id)
            # Existing EnvironmentVip ID
            environment_vip = EnvironmentVip.get_by_pk(environment_vip_id)
            # Business Rules
            environment_environment_vip = EnvironmentEnvironmentVip().get_by_environment_environment_vip(
                environment.id, environment_vip.id
            )
            server_pool_list = EnvironmentEnvironmentVip.get_server_pool_member_by_environment_environment_vip(
                environment_environment_vip
            )

            # Valid integraty between environment/environmentvip related with reals
            # if exists reals fot this environment then raise a exception
            if server_pool_list:
                raise EnvironmentEnvironmentServerPoolLinked({"environment": environment.name})

            # Delete
            environment_environment_vip.delete()

            # Return nothing
            return self.response(dumps_networkapi({}))

        except UserNotAuthorizedError:
            return self.not_authorized()
        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:59,代码来源:EnvironmentEnvironmentVipAssociationResource.py

示例6: handle_post

    def handle_post(self, request, user, *args, **kwargs):
        """Treat requests POST to insert Environment VIP.

        URL: environmentvip/
        """

        try:

            self.log.info('Add Environment VIP')

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no value to the networkapi tag  of XML request.')

            environmentvip_map = networkapi_map.get('environment_vip')
            if environmentvip_map is None:
                return self.response_error(3, u'There is no value to the environment_vip tag of XML request.')

            # New Environment Vip
            environment_vip = EnvironmentVip()

            # Valid Environment Vip
            environment_vip.valid_environment_vip(environmentvip_map)

            try:
                # Save Environment Vip
                environment_vip.save()
            except Exception, e:
                self.log.error(u'Failed to save the environment vip.')
                raise EnvironmentVipError(
                    e, u'Failed to save the environment vip')

            environment_map = dict()
            environment_map['id'] = environment_vip.id

            return self.response(dumps_networkapi({'environment_vip': environment_map}))
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:46,代码来源:EnvironmentVipResource.py

示例7: handle_delete

    def handle_delete(self, request, user, *args, **kwargs):
        """
        Handles DELETE requests to remove a relationship of OptionVip with EnvironmentVip.

        URL: optionvip/<id_option_vip>/environmentvip/<id_environment_vip>/
        """

        self.log.info("Remove a relationship of OptionVip with EnvironmentVip")

        try:

            # Commons Validations

            # User permission
            if not has_perm(user, AdminPermission.OPTION_VIP, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Valid OptionVip ID
            option_vip_id = kwargs.get('id_option_vip')
            if not is_valid_int_greater_zero_param(option_vip_id):
                self.log.error(
                    u'The id_option_vip parameter is not a valid value: %s.', option_vip_id)
                raise InvalidValueError(None, 'id_option_vip', option_vip_id)

            # Valid EnvironmentVip ID
            environment_vip_id = kwargs.get('id_environment_vip')
            if not is_valid_int_greater_zero_param(environment_vip_id):
                self.log.error(
                    u'The id_environment_vip parameter is not a valid value: %s.', environment_vip_id)
                raise InvalidValueError(
                    None, 'id_environment_vip', environment_vip_id)

            # Business Validations

            # Existing OptionVip ID
            option_vip = OptionVip.get_by_pk(option_vip_id)

            # Existing EnvironmentVip ID
            environment_vip = EnvironmentVip.get_by_pk(environment_vip_id)

            # Business Rules

            # Find
            opt_vip_env_vip = OptionVipEnvironmentVip().get_by_option_environment(
                option_vip.id, environment_vip.id)

            # Delete
            opt_vip_env_vip.delete()

            # Return nothing
            return self.response(dumps_networkapi({}))

        except UserNotAuthorizedError:
            return self.not_authorized()
        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:58,代码来源:OptionVipEnvironmentVipAssociationResource.py

示例8: handle_put

    def handle_put(self, request, user, *args, **kwargs):
        """Treat requests PUT to change Environment VIP.

        URL: environmentvip/<id_environment_vip>/
        """

        try:

            self.log.info('Change Environment VIP')

            id_environment_vip = kwargs.get('id_environment_vip')

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no value to the networkapi tag  of XML request.')

            environmentvip_map = networkapi_map.get('environment_vip')
            if environmentvip_map is None:
                return self.response_error(3, u'There is no value to the environment_vip tag of XML request.')

            # Valid Environment VIP ID
            if not is_valid_int_greater_zero_param(id_environment_vip):
                self.log.error(
                    u'The id_environment_vip parameter is not a valid value: %s.', id_environment_vip)
                raise InvalidValueError(
                    None, 'id_environment_vip', id_environment_vip)

            # Find Environment VIP by ID to check if it exist
            environment_vip = EnvironmentVip.get_by_pk(id_environment_vip)

            with distributedlock(LOCK_ENVIRONMENT_VIP % id_environment_vip):

                # Valid Environment Vip
                environment_vip.valid_environment_vip(environmentvip_map)

                try:
                    # Update Environment Vip
                    environment_vip.save()
                except Exception, e:
                    self.log.error(u'Failed to update the environment vip.')
                    raise EnvironmentVipError(
                        e, u'Failed to update the environment vip')

                return self.response(dumps_networkapi({}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:57,代码来源:EnvironmentVipResource.py

示例9: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat requests GET to list all the VIPs related to Environment VIP. 

        URL: environmentvip/<id_environment_vip>/vip/all'
        """

        try:

            self.log.info(
                "GET to list all the VIPs related to Environment VIP")

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Get data
            id_environment_vip = kwargs.get('id_environment_vip')

            # Valid Environment VIP ID
            if not is_valid_int_greater_zero_param(id_environment_vip):
                self.log.error(
                    u'The id_environment_vip parameter is not a valid value: %s.', id_environment_vip)
                raise InvalidValueError(
                    None, 'id_environment_vip', id_environment_vip)

            # Find Environment VIP by ID to check if it exist
            environment_vip = EnvironmentVip.get_by_pk(id_environment_vip)

            # Find Request VIP - IPv4 by ID Environment
            vips_ipv4 = RequisicaoVips.objects.filter(
                ip__networkipv4__ambient_vip__id=environment_vip.id)

            # Find Request VIP - IPv6 by ID Environment
            vips_ipv6 = RequisicaoVips.objects.filter(
                ipv6__networkipv6__ambient_vip__id=environment_vip.id)

            vips = {}
            for vips_ip in [vips_ipv4, vips_ipv6]:

                for vip in vips_ip:

                    v = {}
                    v = vip.variables_to_map()
                    v['id'] = vip.id
                    v['validado'] = vip.validado
                    v['vip_criado'] = vip.vip_criado
                    v['id_ip'] = vip.ip_id
                    v['id_ipv6'] = vip.ipv6_id
                    v['id_healthcheck_expect'] = vip.healthcheck_expect_id
                    vips['vip_%s' % (vip.id)] = v

            return self.response(dumps_networkapi(vips))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:57,代码来源:RequestAllVipsEnviromentVipResource.py

示例10: validate

    def validate(self, attrs):
        """
        Check the Environment Vip is valid.
        """

        try:
            finalidade = attrs.get("finalidade")
            cliente = attrs.get("cliente")
            ambiente = attrs.get("ambiente")

            EnvironmentVip.get_by_values(finalidade, cliente, ambiente)

            ip_to_vip = attrs.get("ip") or attrs.get("ipv6")

            if not ip_to_vip:
                raise serializers.ValidationError("Is required to enter any Ip")

        except EnvironmentVipNotFoundError, exception:
            raise serializers.ValidationError(exception.message)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:19,代码来源:serializers.py

示例11: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat requests GET to list all the Environment by Environment Vip.

        URL: environment/environmentvip/<environment_vip_id>'
        """

        try:

            self.log.info(
                'GET to list all the Environment by Environment Vip.')

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            environment_vip_id = kwargs.get('environment_vip_id')

            # Valid Environment VIP ID
            if not is_valid_int_greater_zero_param(environment_vip_id):
                self.log.error(
                    u'The id_environment_vip parameter is not a valid value: %s.', environment_vip_id)
                raise InvalidValueError(
                    None, 'environment_vip_id', environment_vip_id)

            # Find Environment VIP by ID to check if it exist
            environment_vip = EnvironmentVip.get_by_pk(environment_vip_id)

            environment_related_list = []

            for env_env_vip in environment_vip.environmentenvironmentvip_set.all():
                environment_map = {}
                environment_map['environment_id'] = env_env_vip.environment.id
                environment_map[
                    'environment_vip_id'] = env_env_vip.environment_vip.id
                environment_map[
                    'environment'] = env_env_vip.environment.grupo_l3.nome
                environment_map[
                    'ambiente_logico_name'] = env_env_vip.environment.ambiente_logico.nome
                environment_map[
                    'divisao_dc_name'] = env_env_vip.environment.divisao_dc.nome

                environment_related_list.append(environment_map)

            return self.response(dumps_networkapi({'environment_related_list': environment_related_list}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:52,代码来源:EnvironmentAllGetByEnvironmentVipResource.py

示例12: handle_delete

    def handle_delete(self, request, user, *args, **kwargs):
        """Treat requests PUT to delete Environment VIP.

        URL: environmentvip/<id_environment_vip>/
        """

        try:

            self.log.info('Delete Environment VIP')

            id_environment_vip = kwargs.get('id_environment_vip')

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Valid Environment VIP ID
            if not is_valid_int_greater_zero_param(id_environment_vip):
                self.log.error(
                    u'The id_environment_vip parameter is not a valid value: %s.', id_environment_vip)
                raise InvalidValueError(
                    None, 'id_environment_vip', id_environment_vip)

            # Find Environment VIP by ID to check if it exist
            environment_vip = EnvironmentVip.get_by_pk(id_environment_vip)

            with distributedlock(LOCK_ENVIRONMENT_VIP % id_environment_vip):

                # Find networkIPv4 by Environment VIP to check if is greater
                # than zero
                if len(NetworkIPv4.objects.filter(ambient_vip=environment_vip.id)) > 0:
                    return self.response_error(284)

                # Find networkIPv6 by Environment VIP to check if is greater
                # than zero
                if len(NetworkIPv6.objects.filter(ambient_vip=environment_vip.id)) > 0:
                    return self.response_error(285)

                try:
                    # Delete Environment Vip
                    environment_vip.delete()
                except Exception, e:
                    self.log.error(u'Failed to delete the environment vip.')
                    raise EnvironmentVipError(
                        e, u'Failed to delete the environment vip')

                return self.response(dumps_networkapi({}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:52,代码来源:EnvironmentVipResource.py

示例13: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat requests GET to list all traffic return of the Option VIP by Environment Vip.

        URL: environment-vip/get/trafficreturn/<id_evip>
        """

        try:

            self.log.info("GET to list all the Option VIP by Environment Vip - traffic return.")

            # User permission
            if not has_perm(user, AdminPermission.OPTION_VIP, AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            id_environment_vip = kwargs.get('id_evip')

            # Valid Environment VIP ID
            if not is_valid_int_greater_zero_param(id_environment_vip):
                self.log.error(
                    u'The id_environment_vip parameter is not a valid value: %s.', id_environment_vip)
                raise InvalidValueError(
                    None, 'id_environment_vip', id_environment_vip)

            # Find Environment VIP by ID to check if it exist
            environment_vip = EnvironmentVip.get_by_pk(id_environment_vip)

            #self.log.info(str(environment_vip))

            ovips = OptionVip.get_all_trafficreturn(environment_vip.id)

            #self.log.info(str(ovips))

            ovip_dict = dict()
            ovip_list = []

            for ovip in ovips:
                ovip_dict['trafficreturn_opt'] = ovip.nome_opcao_txt
                ovip_list.append(ovip_dict)
                ovip_dict = dict()

            self.log.info(str(ovip_list))

            return self.response(dumps_networkapi({'trafficreturn_opt': ovip_list}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:51,代码来源:OptionVipGetTrafficReturnByEVipResource.py

示例14: validate

    def validate(self, attrs):
        """
        Check the Environment Vip is valid.
        """

        try:
            finalidade = attrs.get('finalidade')
            cliente = attrs.get('cliente')
            ambiente = attrs.get('ambiente')

            EnvironmentVip.get_by_values(
                finalidade,
                cliente,
                ambiente
            )

            ip_to_vip = attrs.get('ip') or attrs.get('ipv6')

            if not ip_to_vip:
                raise serializers.ValidationError('Is required to enter any Ip')

        except EnvironmentVipNotFoundError, exception:
            raise serializers.ValidationError(exception.message)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:23,代码来源:serializers.py

示例15: server_pool_ips_can_associate_with_vip_request

def server_pool_ips_can_associate_with_vip_request(vip_request, vip_port_to_pool_to_remove=[]):

    try:
        environment_vip = EnvironmentVip.get_by_values(vip_request.finalidade, vip_request.cliente, vip_request.ambiente)

        server_pool_list_add_list = _get_server_pool_list(vip_request)
        server_pool_list_remove_list = _get_server_pool_list_by_vip_port_to_pool(vip_port_to_pool_to_remove)

        for server_pool in server_pool_list_add_list:

            if server_pool not in server_pool_list_remove_list:
                server_pool_member_list = server_pool.serverpoolmember_set.all()
                _reals_can_associate_server_pool_by_environment_vip_on_request_vip(server_pool, server_pool_member_list, environment_vip)

    except Exception, error:
        log.error(error)
        raise error
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:17,代码来源:facade.py


注:本文中的networkapi.ambiente.models.EnvironmentVip类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。