예제 #1
0
파일: ids.py 프로젝트: srcvirus/nf.io
def _read(root, path, length, offset, fh):
    f_path = full_path(root, path)
    vnfs_ops = VNFSOperations(root)
    file_name = vnfs_ops.vnfs_get_file_name(f_path)
    nf_path = ''
    if file_name in special_files:
        tokens = f_path.encode('ascii').split('/')
        last_index_to_keep = tokens.index('nf-types') + 3
        nf_path = "/".join(tokens[0:last_index_to_keep])
    if file_name == "rx_bytes":
        ret_str = vnfs_ops.vnfs_get_rx_bytes(nf_path)
        if offset >= len(ret_str):
            ret_str = ''
    elif file_name == 'tx_bytes':
        ret_str = vnfs_ops.vnfs_get_tx_bytes(nf_path)
        if offset >= len(ret_str):
            ret_str = ''
    elif file_name == 'pkt_drops':
        ret_str = vnfs_ops.vnfs_get_pkt_drops(nf_path)
        if offset >= len(ret_str):
            ret_str = ''
    elif file_name == 'status':
        ret_str = vnfs_ops.vnfs_get_status(nf_path)
        if offset >= len(ret_str):
            ret_str = ''
    else:
        os.lseek(fh, offset, os.SEEK_SET)
        ret_str = os.read(fh, length)
    return ret_str
예제 #2
0
파일: nfio.py 프로젝트: srcvirus/nf.io
    def __init__(self,
                 root,
                 mountpoint,
                 hypervisor='Docker',
                 module_root='middleboxes'):
        """Instantiates a Nfio object.

        Args:
            root: The root directory of nfio file system. The root directory
                stores persistent state about the system.
            mountpoint: The mountpoint of nfio file system. The mountpoint is
                required to intercept the file system calls via fuse. All the
                file system calls for fuse mounted files/directories are
                intercepted by libfuse and our provided implementation is
                executed.
            hypervisor: The type of hypervisor to use for deploying VNFs. The
                default is to use Docker containers. However, we also plan to
                add support for Libvirt.
            module_root: Root directory of the middlebox modules. Each middlebox
                provides it's own implementation of certain system calls in a
                separate module. module_root points to the root of that module.
                If nothing is provided a default of 'middleboxes' will be
                assumed.
        Returns:
            Nothing. Mounts nf.io file system at the specified mountpoint and
            creates a loop to act upon different file system calls.
        """
        self.root = root
        self.mountpoint = mountpoint
        self.hypervisor = hypervisor
        self.vnfs_ops = VNFSOperations(root)
        self.module_root = module_root
예제 #3
0
def _getattr(root, path, fh=None):
    vnfs_ops = VNFSOperations(root)
    f_path = full_path(root, path)
    st = os.lstat(f_path)
    file_name = vnfs_ops.vnfs_get_file_name(f_path)
    return_dictionary = dict()
    return_dictionary['st_atime'] = st.st_atime
    return_dictionary['st_ctime'] = st.st_ctime
    return_dictionary['st_gid'] = st.st_gid
    return_dictionary['st_mode'] = st.st_mode
    return_dictionary['st_mtime'] = st.st_mtime
    return_dictionary['st_nlink'] = st.st_nlink
    return_dictionary['st_size'] = st.st_size
    return_dictionary['st_uid'] = st.st_uid
    if file_name in special_files:
       return_dictionary['st_size'] = 1000
    return return_dictionary
예제 #4
0
파일: ids.py 프로젝트: srcvirus/nf.io
def _write(root, path, buf, offset, fh):
    f_path = full_path(root, path)
    vnfs_ops = VNFSOperations(root)
    file_name = vnfs_ops.vnfs_get_file_name(f_path)
    if file_name == "action":
        path_tokens = f_path.split("/")
        nf_path = "/".join(path_tokens[0:path_tokens.index("nf-types") + 3])
        if buf.rstrip("\n") == "activate":
            vnfs_ops.vnfs_deploy_nf(nf_path)
        elif buf.rstrip("\n") == "stop":
            vnfs_ops.vnfs_stop_vnf(nf_path)
        elif buf.rstrip("\n") == "start":
            vnfs_ops.vnfs_start_vnf(nf_path)
        elif buf.rstrip("\n") == "destroy":
            vnfs_ops.vnfs_destroy_vnf(nf_path)
        os.lseek(fh, offset, os.SEEK_SET)
        os.write(fh, buf.rstrip("\n"))
        return len(buf)
    else:
        os.lseek(fh, offset, os.SEEK_SET)
        return os.write(fh, buf)
예제 #5
0
def _write(root, path, buf, offset, fh):
    f_path = full_path(root, path)
    vnfs_ops = VNFSOperations(root)
    file_name = vnfs_ops.vnfs_get_file_name(f_path)
    #if file_name == "action":
    if file_name in special_files and special_files[file_name]+'_write' in globals():
        try:
            nf_config = get_nf_config(vnfs_ops, f_path)
            # call the custom write function
            logger.info('Writing to ' + file_name  + ' in ' + 
                nf_config['nf_instance_name'] + '@' + nf_config['host'])
            ret_str = globals()[special_files[file_name]+'_write'](vnfs_ops._hypervisor, 
                nf_config, buf.rstrip("\n"))
            logger.info('Successfully wrote ' + file_name + 
                ' in ' + nf_config['nf_instance_name'] + '@' + nf_config['host'])
        except errors.nfioError, ex:
            logger.error('Failed to write ' + file_name + 
                ' in ' + nf_config['nf_instance_name'] + '@' + nf_config['host'] +
                ' : ' + ex.__class__.__name__)
            #raise OSError(ex.errno, os.strerror(ex.errno))
        os.lseek(fh, offset, os.SEEK_SET)
        os.write(fh, buf.rstrip("\n"))
        return len(buf)
예제 #6
0
def _read(root, path, length, offset, fh):
    f_path = full_path(root, path)
    vnfs_ops = VNFSOperations(root)
    file_name = vnfs_ops.vnfs_get_file_name(f_path)
    nf_path = ''
    ret_str = ''
    if file_name in special_files and special_files[file_name]+'_read' in globals():

        try:
            nf_config = get_nf_config(vnfs_ops, f_path)
            # call the custom read function
            logger.info('Reading ' + file_name  + ' from ' + 
                nf_config['nf_instance_name'] + '@' + nf_config['host'])
            ret_str = globals()[special_files[file_name]+'_read'](vnfs_ops._hypervisor, 
                nf_config)
            logger.info('Successfully read ' + file_name + 
                ' from ' + nf_config['nf_instance_name'] + '@' + nf_config['host'])
        except errors.nfioError, ex:
            logger.error('Failed to read ' + file_name + 
                ' from ' + nf_config['nf_instance_name'] + '@' + nf_config['host'] +
                ' : ' + ex.__class__.__name__)
            #raise OSError(ex.errno, os.strerror(ex.errno))
        if offset >= len(ret_str):
            ret_str = ''
예제 #7
0
파일: nginx.py 프로젝트: srcvirus/nf.io
def _write(root, path, buf, offset, fh):
    f_path = full_path(root, path)
    vnfs_ops = VNFSOperations(root)
    file_name = vnfs_ops.vnfs_get_file_name(f_path)
    #if file_name == "action":
    if file_name in special_files and special_files[
            file_name] + '_write' in globals():
        try:
            nf_config = get_nf_config(vnfs_ops, f_path)
            # call the custom write function
            logger.info('Writing to ' + file_name + ' in ' +
                        nf_config['nf_instance_name'] + '@' +
                        nf_config['host'])
            ret_str = globals()[special_files[file_name] + '_write'](
                vnfs_ops._hypervisor, nf_config, buf.rstrip("\n"))
        except errors.HypervisorError, ex:
            logger.debug('raised OSErro ' + str(ex.errno))
            raise OSError(ex.errno, os.strerror(ex.errno))
        logger.info('Successfully wrote ' + file_name + ' in ' +
                    nf_config['nf_instance_name'] + '@' + nf_config['host'])

        #if buf.rstrip("\n") == "activate":
        #    try:
        #        vnfs_ops.vnfs_deploy_nf(nf_path)
        #    except errors.VNFCreateError:
        #        #raise OSError(errno.EBUSY, os.strerror(errno.EBUSY))
        #        raise OSError(747, 'Cannot create VNF')
        #elif buf.rstrip("\n") == "stop":
        #    vnfs_ops.vnfs_stop_vnf(nf_path)
        #elif buf.rstrip("\n") == "start":
        #    vnfs_ops.vnfs_start_vnf(nf_path)
        #elif buf.rstrip("\n") == "destroy":
        #    vnfs_ops.vnfs_destroy_vnf(nf_path)
        os.lseek(fh, offset, os.SEEK_SET)
        os.write(fh, buf.rstrip("\n"))
        return len(buf)
예제 #8
0
def _mkdir(root, path, mode):
    vnfs_ops = VNFSOperations(root)
    result = vnfs_ops.vnfs_create_vnf_instance(path, mode)
    return result