def _deploy_config_in_equipment(self, rel_filename):

        # validate filename
        path = os.path.abspath(TFTPBOOT_FILES_PATH + rel_filename)
        if not path.startswith(TFTPBOOT_FILES_PATH):
            raise exceptions.InvalidFilenameException(rel_filename)

        # if type(self.equipment) is not Equipamento:
        #     log.error('Invalid data for equipment')
        #     raise api_exceptions.NetworkAPIException()

        if self.equipment.maintenance:
            raise AllEquipmentsAreInMaintenanceException()

        return self._applyconfig(rel_filename)
Esempio n. 2
0
def deploy_config_in_equipment_synchronous(rel_filename,
                                           equipment,
                                           lockvar,
                                           tftpserver=None,
                                           equipment_access=None):
    """Apply configuration file on equipment

    Args:
            rel_filename: relative file path from TFTPBOOT_FILES_PATH to apply
                          in equipment
            equipment: networkapi.equipamento.Equipamento() or Equipamento().id
            lockvar: distributed lock variable to use when applying config to
                     equipment
            equipment_access: networkapi.equipamento.EquipamentoAcesso() to use
            tftpserver: source TFTP server address

    Returns:
            equipment output

    Raises:
    """

    # validate filename
    path = os.path.abspath(TFTPBOOT_FILES_PATH + rel_filename)
    if not path.startswith(TFTPBOOT_FILES_PATH):
        raise exceptions.InvalidFilenameException(rel_filename)

    if type(equipment) is int:
        equipment = Equipamento.get_by_pk(equipment)
    elif type(equipment) is Equipamento:
        pass
    else:
        log.error('Invalid data for equipment')
        raise api_exceptions.NetworkAPIException()

    if equipment.maintenance:
        raise AllEquipmentsAreInMaintenanceException()

    with distributedlock(lockvar):
        return _applyconfig(equipment, rel_filename, equipment_access,
                            tftpserver)
Esempio n. 3
0
    def _apply_config(self, filename):

        if self.equipment.maintenance:
            raise AllEquipmentsAreInMaintenanceException()

        self._copy_script_file_to_config(filename)
Esempio n. 4
0
def networkIPv6_deploy(request, network_id):
    """Deploy network L3 configuration in the environment routers for network ipv6

    Receives optional parameter equipments to specify what equipment should
    receive network configuration
    """

    networkipv6 = NetworkIPv6.get_by_pk(int(network_id))
    environment = networkipv6.vlan.ambiente
    equipments_id_list = None
    if request.DATA is not None:
        equipments_id_list = request.DATA.get('equipments', None)

    equipment_list = []

    if equipments_id_list is not None:
        if type(equipments_id_list) is not list:
            raise api_exceptions.ValidationException('equipments')

        for equip in equipments_id_list:
            try:
                int(equip)
            except ValueError:
                raise api_exceptions.ValidationException('equipments')

        # Check that equipments received as parameters are in correct vlan
        # environment
        equipment_list = Equipamento.objects.filter(
            equipamentoambiente__ambiente=environment,
            id__in=equipments_id_list)
        log.info('list = %s' % equipment_list)
        if len(equipment_list) != len(equipments_id_list):
            log.error(
                'Error: equipments %s are not part of network environment.' %
                equipments_id_list)
            raise exceptions.EquipmentIDNotInCorrectEnvException()
    else:
        # TODO GET network routers
        equipment_list = Equipamento.objects.filter(
            ipv6equipament__ip__networkipv6=networkipv6,
            equipamentoambiente__ambiente=networkipv6.vlan.ambiente,
            equipamentoambiente__is_router=1).distinct()
        if len(equipment_list) == 0:
            raise exceptions.NoEnvironmentRoutersFoundException()

    # Check permission to configure equipments
    for equip in equipment_list:
        # User permission
        if not has_perm(request.user, AdminPermission.EQUIPMENT_MANAGEMENT,
                        AdminPermission.WRITE_OPERATION, None, equip.id,
                        AdminPermission.EQUIP_WRITE_OPERATION):
            log.error(
                u'User does not have permission to perform the operation.')
            raise PermissionDenied(
                'No permission to configure equipment %s-%s' %
                (equip.id, equip.nome))

    if all_equipments_are_in_maintenance(equipment_list):
        raise AllEquipmentsAreInMaintenanceException()

    try:
        # deploy network configuration
        if request.method == 'POST':
            returned_data = facade.deploy_networkIPv6_configuration(
                request.user, networkipv6, equipment_list)
        elif request.method == 'DELETE':
            returned_data = facade.remove_deploy_networkIPv6_configuration(
                request.user, networkipv6, equipment_list)

        return Response(returned_data)

    except Exception, exception:
        log.error(exception)
        raise api_exceptions.NetworkAPIException()
Esempio n. 5
0
    def _apply_config(self, filename):
        log.info("_apply_config")
        if self.equipment.maintenance:
            raise AllEquipmentsAreInMaintenanceException()

        self.copyScriptFileToConfig(filename, destination='running-config')