Esempio n. 1
0
def update_neighbor_v4(obj, user):
    """Update NeighborV4."""

    try:
        obj_to_update = get_neighbor_v4_by_id(obj.get('id'))
        obj_to_update.update_v4(obj, user)
    except NeighborV4Error as e:
        raise ValidationAPIException(str(e))
    except DontHavePermissionForPeerGroupException as e:
        raise ValidationAPIException(str(e))
    except LocalIpAndRemoteIpAreInDifferentVrfsException as e:
        raise ValidationAPIException(str(e))
    except LocalIpAndLocalAsnAtDifferentEquipmentsException as e:
        raise ValidationAPIException(str(e))
    except RemoteIpAndRemoteAsnAtDifferentEquipmentsException as e:
        raise ValidationAPIException(str(e))
    except LocalIpAndPeerGroupAtDifferentEnvironmentsException as e:
        raise ValidationAPIException(str(e))
    except NeighborDuplicatedException as e:
        raise ValidationAPIException(str(e))
    except NeighborV4IsDeployed as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except NeighborV4DoesNotExistException as e:
        raise ObjectDoesNotExistException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))

    return obj_to_update
Esempio n. 2
0
def post_cidr(obj):

    from netaddr import IPNetwork

    try:
        cidr = EnvCIDR()

        data = dict()
        data['id'] = obj.get('id')
        data['ip_version'] = obj.get('ip_version')
        data['subnet_mask'] = obj.get('subnet_mask')
        data['network_type'] = obj.get('network_type')
        data['environment'] = obj.get('environment')
        data['network'] = obj.get('network')

        try:
            network = IPNetwork(obj.get('network'))
        except Exception as e:
            raise ValidationAPIException(str(e))

        environment = Ambiente().get_by_pk(int(obj.get('environment')))
        msg = list()
        if not cidr.check_cidr(environment, obj.get('network')):
            message = "The network is not a subnet of the father environment."
            msg.append(
                dict(message=message, environment_id=obj.get('environment')))
            log.info(message)

        duplicated_cidr = cidr.check_duplicated_cidr(environment,
                                                     obj.get('network'))

        duplicated_ids = [ids.id_env.id for ids in duplicated_cidr]

        if duplicated_cidr:
            message = "CIDR %s overlaps with networks from environments: %s" % \
                      (obj.get('network'), duplicated_ids)
            msg.append(
                dict(message=message, environment_id=obj.get('environment')))
            log.info(message)

        data['network_first_ip'] = int(network.ip)
        data['network_last_ip'] = int(network.broadcast)
        data['network_mask'] = network.prefixlen

        response = cidr.post(data)

    except CIDRErrorV3 as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))

    return response, msg
Esempio n. 3
0
def get_cidr(cidr=None, environment=None):
    """Return a list of CIDR."""

    try:
        env_cidr = EnvCIDR()
        cidr = env_cidr.get(cidr_id=cidr, env_id=environment)
    except CIDRErrorV3 as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))
    else:
        return cidr
Esempio n. 4
0
def create_as(as_):
    """Create AS."""

    try:
        as_obj = Asn()
        as_obj.create_v4(as_)
    except AsnErrorV4 as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))

    return as_obj
Esempio n. 5
0
def create_neighbor_v6(obj, user):
    """Create NeighborV6."""

    try:
        obj_to_create = NeighborV6()
        obj_to_create.create_v4(obj, user)
    except NeighborV6Error as e:
        raise ValidationAPIException(str(e))
    except DontHavePermissionForPeerGroupException as e:
        raise ValidationAPIException(str(e))
    except LocalIpAndRemoteIpAreInDifferentVrfsException as e:
        raise ValidationAPIException(str(e))
    except LocalIpAndLocalAsnAtDifferentEquipmentsException as e:
        raise ValidationAPIException(str(e))
    except RemoteIpAndRemoteAsnAtDifferentEquipmentsException as e:
        raise ValidationAPIException(str(e))
    except LocalIpAndPeerGroupAtDifferentEnvironmentsException as e:
        raise ValidationAPIException(str(e))
    except NeighborDuplicatedException as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))

    return obj_to_create
def create_list_config_bgp(obj):
    """Create ListConfigBGP."""

    try:
        obj_to_create = ListConfigBGP()
        obj_to_create.create_v4(obj)
    except ListConfigBGPError as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))

    return obj_to_create
Esempio n. 7
0
def create_route_map(obj):
    """Create RouteMap."""

    try:
        obj_to_create = RouteMap()
        obj_to_create.create_v4(obj)
    except RouteMapError as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))

    return obj_to_create
Esempio n. 8
0
def create_environment(env):
    """Create environment."""

    try:
        env_obj = Ambiente()
        env_obj.create_v3(env)
    except EnvironmentErrorV3 as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))

    return env_obj
Esempio n. 9
0
def _create_pool_member(members, pool):
    """Creates pool members"""
    for member in members:
        ip = Ip.get_by_pk(member['ip']['id']) if member['ip'] else None
        ipv6 = Ipv6.get_by_pk(member['ipv6']['id']) if member['ipv6'] else None
        identifier = ip.ip_formated if ip else ipv6.ip_formated

        pool_member = ServerPoolMember()
        pool_member.server_pool = pool
        pool_member.ip = ip
        pool_member.ipv6 = ipv6
        pool_member.identifier = identifier
        pool_member.weight = member['weight']
        pool_member.priority = member['priority']
        pool_member.port_real = member['port_real']
        pool_member.member_status = member['member_status']
        pool_member.limit = member['limit']
        pool_member.save()

        # vip with dsrl3 using pool
        if pool.dscp:

            mbs = pool_member.get_spm_by_eqpt_id(pool_member.equipment.id)

            # check all the pools related to this pool vip request to filter
            # dscp value
            related_viprequestports = pool.vips[0].viprequestport_set.all()
            vippools = [
                p.viprequestportpool_set.all()[0].server_pool_id
                for p in related_viprequestports
            ]

            sps = ServerPool.objects.filter(serverpoolmember__in=mbs).exclude(
                id__in=vippools)
            dscps = [sp.dscp for sp in sps]

            mb_name = '{}:{}'.format(
                (ip.ip_formated if ip else ipv6.ip_formated),
                member['port_real'])
            if pool.dscp in dscps:
                raise ValidationAPIException(
                    'DRSL3 Restriction: Pool Member {} cannot be insert'
                    ' in Pool {}, because already in other pool'.format(
                        mb_name, pool.identifier))

            if pool_member.port_real != pool.default_port:
                raise ValidationAPIException(
                    'DRSL3 Restriction: Pool Member {} cannot have different'
                    ' port of Pool {}'.format(mb_name, pool.identifier))
Esempio n. 10
0
def update_as(as_):
    """Update AS."""

    try:
        as_obj = get_as_by_id(as_.get('id'))
        as_obj.update_v4(as_)
    except AsnErrorV4 as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except exceptions.AsnDoesNotExistException as e:
        raise ObjectDoesNotExistException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))

    return as_obj
Esempio n. 11
0
def _update_pool_member(members):
    """Updates pool members"""
    for member in members:
        ip = Ip.get_by_pk(member['ip']['id']) if member['ip'] else None
        ipv6 = Ipv6.get_by_pk(member['ipv6']['id']) if member['ipv6'] else None

        pool_member = ServerPoolMember.objects.get(id=member['id'])
        pool_member.ip = ip
        pool_member.ipv6 = ipv6
        pool_member.weight = member['weight']
        pool_member.priority = member['priority']
        pool_member.port_real = member['port_real']
        pool_member.member_status = member['member_status']
        pool_member.limit = member['limit']
        pool_member.save()

        if pool_member.server_pool.dscp:
            if pool_member.port_real != pool_member.server_pool.default_port:

                mb_name = '{}:{}'.format(
                    (ip.ip_formated if ip else ipv6.ip_formated),
                    member['port_real'])

                raise ValidationAPIException(
                    'DRSL3 Restriction: Pool Member {} cannot have different '
                    'port of Pool {}'.format(
                        mb_name, pool_member.server_pool.identifier))
Esempio n. 12
0
def update_interface(interface):

    try:
        interface_obj = Interface.objects.get(id=interface.get('id'))
        interface_obj.update_v3(interface)
    except models.InterfaceError, e:
        raise ValidationAPIException(e.message)
Esempio n. 13
0
def create_interface_environments(interface_environment):

    try:
        interface_envs_obj = EnvironmentInterface()
        interface_envs_obj.create_v3(interface_environment)
    except models.InterfaceError, e:
        raise ValidationAPIException(e.message)
Esempio n. 14
0
def create_interface(interface):

    try:
        interface_obj = Interface()
        interface_obj.create_v3(interface)
    except models.InterfaceError, e:
        raise ValidationAPIException(e.message)
Esempio n. 15
0
def post_cidr_auto(obj):
    try:
        cidr = EnvCIDR()
        subnet, _ = cidr.checkAvailableCIDR(obj.get('environment'),
                                            obj.get('ip_version'))
        obj["network"] = subnet
        response, msg = post_cidr(obj)

    except CIDRErrorV3 as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))

    return response, msg
Esempio n. 16
0
def create_pool(pool, user):
    """Creates pool"""

    try:
        sp = ServerPool()
        sp.create_v3(pool, user)
    except exceptions.InvalidIdentifierAlreadyPoolException, e:
        raise ValidationAPIException(e.detail)
Esempio n. 17
0
def update_environment(env):
    """Update environment."""

    try:
        env_obj = get_environment_by_id(env.get('id'))
        env_obj.update_v3(env)
    except EnvironmentErrorV3, e:
        raise ValidationAPIException(str(e))
Esempio n. 18
0
def create_dc_environment(env):
    """Create environment."""

    try:
        env_obj = DivisaoDc()
        env_obj.create_v3(env)
    except EnvironmentErrorV3, e:
        raise ValidationAPIException(str(e))
Esempio n. 19
0
def delete_list_config_bgp(obj_ids):
    """Delete ListConfigBGP."""

    for obj_id in obj_ids:
        try:
            obj_to_delete = get_list_config_bgp_by_id(obj_id)
            obj_to_delete.delete_v4()
        except ListConfigBGPDoesNotExistException as e:
            raise ObjectDoesNotExistException(str(e))
        except ListConfigBGPAssociatedToRouteMapEntryException as e:
            raise ValidationAPIException(str(e))
        except ListConfigBGPIsDeployedException as e:
            raise ValidationAPIException(str(e))
        except ListConfigBGPError as e:
            raise NetworkAPIException(str(e))
        except Exception as e:
            raise NetworkAPIException(str(e))
Esempio n. 20
0
def create_neighbor(neighbor):
    """Create Neighbor."""

    try:
        neighbor_obj = Neighbor()
        neighbor_obj.create_v4(neighbor)
    except NeighborErrorV4, e:
        raise ValidationAPIException(str(e))
Esempio n. 21
0
def update_neighbor(neighbor):
    """Update Neighbor."""

    try:
        neighbor_obj = get_neighbor_by_id(neighbor.get('id'))
        neighbor_obj.update_v4(neighbor)
    except NeighborErrorV4, e:
        raise ValidationAPIException(str(e))
Esempio n. 22
0
def create_virtual_interface(vi_):
    """Create Virtual Interface."""

    try:
        vi_obj = VirtualInterface()
        vi_obj.create_v4(vi_)
    except VirtualInterfaceErrorV4, e:
        raise ValidationAPIException(str(e))
Esempio n. 23
0
def update_as(as_):
    """Update AS."""

    try:
        as_obj = get_as_by_id(as_.get('id'))
        as_obj.update_v4(as_)
    except AsErrorV4, e:
        raise ValidationAPIException(str(e))
Esempio n. 24
0
def create_vip_request(vip_request, user):
    """Create Vip Request."""

    try:
        vip = VipRequest()
        vip.create_v3(vip_request, user)
    except ValidationAPIException, e:
        raise ValidationAPIException(str(e))
Esempio n. 25
0
def create_as(as_):
    """Create AS."""

    try:
        as_obj = As()
        as_obj.create_v4(as_)
    except AsErrorV4, e:
        raise ValidationAPIException(str(e))
Esempio n. 26
0
def create_logic_environment(env):
    """Create environment."""

    try:
        env_obj = AmbienteLogico()
        env_obj.create_v3(env)
    except EnvironmentErrorV3, e:
        raise ValidationAPIException(str(e))
Esempio n. 27
0
def update_virtual_interface(vi_):
    """Update Virtual Interface."""

    try:
        vi_obj = get_virtual_interface_by_id(vi_.get('id'))
        vi_obj.update_v4(vi_)
    except VirtualInterfaceErrorV4, e:
        raise ValidationAPIException(str(e))
Esempio n. 28
0
def create_l3_environment(env):
    """Create environment."""

    try:
        env_obj = GrupoL3()
        env_obj.create_v3(env)
    except EnvironmentErrorV3, e:
        raise ValidationAPIException(str(e))
Esempio n. 29
0
def create_route_map_entry(obj):
    """Create RouteMapEntry."""

    try:
        obj_to_create = RouteMapEntry()
        obj_to_create.create_v4(obj)
    except RouteMapEntryError as e:
        raise ValidationAPIException(str(e))
    except RouteMapEntryDuplicatedException as e:
        raise ValidationAPIException(str(e))
    except RouteMapEntryWithDeployedRouteMapException as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))

    return obj_to_create
Esempio n. 30
0
def update_route_map(obj):
    """Update RouteMap."""

    try:
        obj_to_update = get_route_map_by_id(obj.get('id'))
        obj_to_update.update_v4(obj)
    except RouteMapError as e:
        raise ValidationAPIException(str(e))
    except RouteMapIsDeployedException as e:
        raise ValidationAPIException(str(e))
    except ValidationAPIException as e:
        raise ValidationAPIException(str(e))
    except RouteMapDoesNotExistException as e:
        raise ObjectDoesNotExistException(str(e))
    except Exception as e:
        raise NetworkAPIException(str(e))

    return obj_to_update