All Classes Functions
nfio.Nfio Class Reference
Inheritance diagram for nfio.Nfio:

Public Member Functions

def __init__
 Instantiates a Nfio object. More...
 
def access
 
def chmod
 
def chown
 
def getattr
 Returns the file attributes of the file specified by path Args: path: Path of the file fh: Open file handle to the file Returns: A dictionary containing file attributes. More...
 
def readdir
 
def readlink
 
def mknod
 
def rmdir
 
def mkdir
 The semantics have been redefined to create a new VNF instance when a directory is created under a specific type of VNF directory. More...
 
def statfs
 
def unlink
 
def symlink
 
def rename
 
def link
 
def utimens
 
def open
 
def create
 
def read
 Reads an open file. More...
 
def write
 Write to an open file. More...
 
def truncate
 
def flush
 
def release
 
def fsync
 

Public Attributes

 root
 
 mountpoint
 
 hypervisor
 
 vnfs_ops
 
 module_root
 

Detailed Description

Definition at line 22 of file nfio.py.

Constructor & Destructor Documentation

def nfio.Nfio.__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.

Definition at line 52 of file nfio.py.

52 
53  module_root='middleboxes'):
54  self.root = root
55  self.mountpoint = mountpoint
56  self.hypervisor = hypervisor
57  self.vnfs_ops = VNFSOperations(root)
58  self.module_root = module_root
Provides a common set of operations for nfio.
module_root
Definition: nfio.py:57
root
Definition: nfio.py:53
hypervisor
Definition: nfio.py:55
mountpoint
Definition: nfio.py:54
vnfs_ops
Definition: nfio.py:56

Member Function Documentation

def nfio.Nfio.getattr (   self,
  path,
  fh = None 
)

Returns the file attributes of the file specified by path Args: path: Path of the file fh: Open file handle to the file Returns: A dictionary containing file attributes.

The dictionary contains the following keys: st_atime: Last access time st_ctime: File creation time st_gid: Group id of the owner group st_mode: File access mode st_mtime: Last modification time st_nlink: Number of symbolic links to the file st_size: Size of the file in bytes st_uid: User id of the file owner Note: For special placeholder files for VNFs, st_size is set to a constant 1000. This is to make sure read utilities such as cat work for these special placeholder files.

Definition at line 119 of file nfio.py.

120  def getattr(self, path, fh=None):
121  opcode = self.vnfs_ops.vnfs_get_opcode(path)
122  if opcode == VNFSOperations.OP_NF:
123  nf_type = self.vnfs_ops.vnfs_get_nf_type(path)
124  if len(nf_type) > 0:
125  try:
126  mbox_module = importlib.import_module(
127  self.module_root +
128  "." +
129  nf_type)
130  except ImportError:
131  logger.error('VNF module file missing. Add "' + nf_type
132  + '.py" under the directory ' + self.module_root)
133  ## TODO: raise an custom exception and handle it in a OS
134  ## specific way
135  raise OSError(errno.ENOSYS)
136  return mbox_module._getattr(self.root, path, fh)
137  full_path = self._full_path(path)
138  st = os.lstat(full_path)
139  file_name = self.vnfs_ops.vnfs_get_file_name(full_path)
140  return dict(
141  (key,
142  getattr(
143  st,
144  key)) for key in (
145  'st_atime',
146  'st_ctime',
147  'st_gid',
148  'st_mode',
149  'st_mtime',
150  'st_nlink',
151  'st_size',
152  'st_uid'))
module_root
Definition: nfio.py:57
def _full_path
Returns the absolute path of a partially specified path.
Definition: nfio.py:75
def getattr
Returns the file attributes of the file specified by path Args: path: Path of the file fh: Open file ...
Definition: nfio.py:119
root
Definition: nfio.py:53
def nfio.Nfio.mkdir (   self,
  path,
  mode 
)

The semantics have been redefined to create a new VNF instance when a directory is created under a specific type of VNF directory.

Args: path: path of the directory to create. The path also represents the name of the new VNF instance to be created. mode: File access mode for the new directory. Returns: If path does not correspond to a directory under a specific VNF type directory then errno.EPERM is returned. Otherwise the return code is same as os.mkdir()'s return code.

Definition at line 188 of file nfio.py.

189  def mkdir(self, path, mode):
190  opcode = self.vnfs_ops.vnfs_get_opcode(path)
191  if opcode == VNFSOperations.OP_NF:
192  nf_type = self.vnfs_ops.vnfs_get_nf_type(path)
193  # Check if this directory is an instance directory or a type
194  # directory
195  path_tokens = path.split("/")
196  if path_tokens.index("nf-types") == len(path_tokens) - 2:
197  return os.mkdir(self._full_path(path), mode)
198  mbox_module = importlib.import_module(
199  self.module_root +
200  "." +
201  nf_type)
202  result = mbox_module._mkdir(self.root, path, mode)
203  elif opcode == VNFSOperations.OP_UNDEFINED:
204  result = errno.EPERM
205  return result
module_root
Definition: nfio.py:57
def _full_path
Returns the absolute path of a partially specified path.
Definition: nfio.py:75
root
Definition: nfio.py:53
def mkdir
The semantics have been redefined to create a new VNF instance when a directory is created under a sp...
Definition: nfio.py:188
def nfio.Nfio.read (   self,
  path,
  length,
  offset,
  fh 
)

Reads an open file.

This nfio specific implementation parses path to see if the read is from any VNF or not. In case the read is from a VNF, the corresponding VNF module is loaded and the module's _read function is invoked to complete the read system call.

Args: path: path represents the path of the file to read from length: number of bytes to read from the file offset: byte offset indicating the starting byte to read from fh: file descriptor of the open file represented by path

Returns: length bytes from offset byte of the file represented by fh and path

Notes: VNFs can have special files which are placeholders for statistics such as number of received/sent bytes etc. VNFs provide their own implementation of read and handle reading of these special placeholder files.

Definition at line 273 of file nfio.py.

274  def read(self, path, length, offset, fh):
275  full_path = self._full_path(path)
276  opcode = self.vnfs_ops.vnfs_get_opcode(full_path)
277  file_name = self.vnfs_ops.vnfs_get_file_name(full_path)
278  if opcode == self.vnfs_ops.OP_NF:
279  nf_type = self.vnfs_ops.vnfs_get_nf_type(path)
280  mbox_module = importlib.import_module(
281  self.module_root +
282  "." +
283  nf_type)
284  return mbox_module._read(self.root, path, length, offset, fh)
285  os.lseek(fh, offset, os.SEEK_SET)
286  return os.read(fh, length)
def read
Reads an open file.
Definition: nfio.py:273
module_root
Definition: nfio.py:57
def _full_path
Returns the absolute path of a partially specified path.
Definition: nfio.py:75
root
Definition: nfio.py:53
def nfio.Nfio.write (   self,
  path,
  buf,
  offset,
  fh 
)

Write to an open file.

In this nfio specific implementation the path is parsed to see if the write is for any specific VNF or not. If the write is for any file under a VNF directory then the corresponding VNF module is loaded and the module's _write function is invoked.

Args: path: path to the file to write buf: the data to write offset: the byte offset at which the write should begin fh: file descriptor of the open file represented by path

Returns: Returns the number of bytes written to the file starting at offset

Note: VNFs can have special files where writing specific strings trigger a specific function. For example, writing 'activate' to the 'action' file of a VNF will start the VNF. VNF specific modules handle such special cases of writing.

Definition at line 309 of file nfio.py.

310  def write(self, path, buf, offset, fh):
311  opcode = self.vnfs_ops.vnfs_get_opcode(path)
312  full_path = self._full_path(path)
313  file_name = self.vnfs_ops.vnfs_get_file_name(path)
314  if opcode == VNFSOperations.OP_NF:
315  nf_type = self.vnfs_ops.vnfs_get_nf_type(full_path)
316  mbox_module = importlib.import_module(
317  self.module_root +
318  "." +
319  nf_type)
320  return mbox_module._write(self.root, path, buf, offset, fh)
321 
322  os.lseek(fh, offset, os.SEEK_SET)
323  return os.write(fh, buf)
def write
Write to an open file.
Definition: nfio.py:309
module_root
Definition: nfio.py:57
def _full_path
Returns the absolute path of a partially specified path.
Definition: nfio.py:75
root
Definition: nfio.py:53

The documentation for this class was generated from the following file: