コード例 #1
0
ファイル: Cli.py プロジェクト: wangchaobin/GloboNetworkAPI
    def _deploy_config_in_equipment(self, rel_filename):

        path = os.path.abspath(TFTPBOOT_FILES_PATH + rel_filename)
        if not path.startswith(TFTPBOOT_FILES_PATH):
            raise deploy_exc.InvalidFilenameException(rel_filename)

        return self._apply_config(rel_filename)
コード例 #2
0
def create_file_from_script(script, prefix_name=''):
    """Creates a file with script content

    Args:
            script: string with commands script
            prefix_name: prefix to use in filename

    Returns:
            file name created with path relative to networkapi.settings.TFTPBOOT_FILES_PATH

    Raises:
            IOError: if cannot write file
    """

    if prefix_name == '':
        prefix_name = 'script_reqid_'

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

    request_id = getattr(local, 'request_id', NO_REQUEST_ID)
    filename_out = prefix_name + str(request_id)
    filename_to_save = CONFIG_FILES_PATH + filename_out

    # Save new file
    try:
        file_handle = open(filename_to_save, 'w')
        file_handle.write(script)
        file_handle.close()
    except IOError, e:
        log.error('Error writing to config file: %s' % filename_to_save)
        raise e
コード例 #3
0
    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)
コード例 #4
0
ファイル: facade.py プロジェクト: wangchaobin/GloboNetworkAPI
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)