All Classes Functions
vnfs_operations.VNFSOperations Class Reference

Provides a common set of operations for nfio. More...

Public Member Functions

def __init__
 
def vnfs_create_vnf_instance
 Create the file system structure for a VNF. More...
 
def vnfs_get_opcode
 Determinse the type of operation based on the path. More...
 
def vnfs_get_nf_type
 Parse the type of VNF from path. More...
 
def vnfs_get_file_name
 Return the name of the file represented by a path. More...
 
def vnfs_is_nf_instance
 Determines if a path represents an nf instance directory. More...
 
def vnfs_get_instance_configuration
 Return the configuration parameters related to a VNF instance. More...
 
def vnfs_deploy_nf
 Deploys and STARTS a VNF instance. More...
 
def vnfs_stop_vnf
 Stops a VNF instance. More...
 
def vnfs_start_vnf
 Starts a deployed VNF instance. More...
 
def vnfs_destroy_vnf
 Destroys a deployed VNF instance. More...
 
def vnfs_get_rx_bytes
 Reads the number of bytes received by a VNF instance. More...
 
def vnfs_get_tx_bytes
 Reads the number of bytes sent by a VNF instance. More...
 
def vnfs_get_pkt_drops
 Reads the number of packets dropped by a VNF instance. More...
 
def vnfs_get_status
 Get the status of a VNF instance, e.g., the VNF is running/suspended/stopped etc. More...
 
def vnfs_get_ip
 Get the status of a VNF instance, e.g., the VNF is running/suspended/stopped etc. More...
 

Public Attributes

 vnfs_root
 

Static Public Attributes

int OP_UNDEFINED = 0xFF
 
int OP_NF = 0x01
 

Detailed Description

Provides a common set of operations for nfio.

These operations act as a helper.

Definition at line 25 of file vnfs_operations.py.

Member Function Documentation

def vnfs_operations.VNFSOperations.vnfs_create_vnf_instance (   self,
  path,
  mode 
)

Create the file system structure for a VNF.

Args: path: path of the new VNF instance. mode: file creation mode for the new VNF instance directory.

Returns: returns the return code of os.mkdir

Definition at line 52 of file vnfs_operations.py.

52 
53  def vnfs_create_vnf_instance(self, path, mode):
54  logger.info('Creating file/directory structure in ' + path)
55  full_path = self._full_path(path)
56  result = os.mkdir(full_path)
57  default_file_mode = 0o644
58  os.open(
59  full_path +
60  "/status",
61  os.O_WRONLY | os.O_CREAT,
62  default_file_mode)
63 
64  os.mkdir(full_path + "/config", mode)
65  os.open(full_path + "/config/boot.conf", os.O_WRONLY | os.O_CREAT,
66  default_file_mode)
67  os.mkdir(full_path + "/machine", mode)
68  os.open(full_path + "/machine/ip", os.O_WRONLY | os.O_CREAT,
69  default_file_mode)
70  os.open(full_path + "/machine/vm.vcpu", os.O_WRONLY | os.O_CREAT,
71  default_file_mode)
72  os.open(full_path + "/machine/vm.memory", os.O_WRONLY | os.O_CREAT,
73  default_file_mode)
74  os.open(full_path + "/machine/vm.image", os.O_WRONLY | os.O_CREAT,
75  default_file_mode)
76  os.open(full_path + "/machine/vm.ip", os.O_WRONLY | os.O_CREAT,
77  default_file_mode)
78  os.open(full_path + "/action", os.O_WRONLY | os.O_CREAT,
79  default_file_mode)
80 
81  default_file_mode = 0o444
82  os.mkdir(full_path + "/stats", mode)
83  os.open(full_path + "/stats/rx_bytes", os.O_WRONLY | os.O_CREAT,
84  default_file_mode)
85  os.open(full_path + "/stats/tx_bytes", os.O_WRONLY | os.O_CREAT,
86  default_file_mode)
87  os.open(full_path + "/stats/pkt_drops", os.O_WRONLY | os.O_CREAT,
88  default_file_mode)
89  logger.info('Finished creating file/directory structure in ' + path)
90  return result
def vnfs_create_vnf_instance
Create the file system structure for a VNF.
def vnfs_operations.VNFSOperations.vnfs_deploy_nf (   self,
  nf_path 
)

Deploys and STARTS a VNF instance.

Args: nf_path: path of the VNF instance.

Returns
void

Definition at line 207 of file vnfs_operations.py.

208  def vnfs_deploy_nf(self, nf_path):
209  logger.info('Deploying new VNF at ' + nf_path)
210  nf_instance_name, nf_type, ip_address, image_name = self.vnfs_get_instance_configuration(nf_path)
211  try:
212  cont_id = self._hypervisor.deploy(
213  ip_address, getpass.getuser(), image_name, nf_instance_name)
214  logger.debug(cont_id)
215  except errors.VNFDeployError:
216  logger.info('Instance: ' + nf_instance_name + ' deployment failed')
217  else:
218  logger.info('Instance: ' + nf_instance_name
219  + ' successfully deployed')
220  try:
221  logger.info('Starting the deployed VNF instance: '
222  + nf_instance_name)
223  self._hypervisor.start(ip_address, cont_id)
224  except errors.VNFStartError:
225  logger.info('Instance: ' + nf_instance_name + ' start failed')
226  # destroy the deployed VNF
227  self._hypervisor.destroy(ip_address, cont_id)
228  logger.info('Instance: ' + nf_instance_name
229  + ' destroyed')
230  else:
231  logger.info('Instance: ' + nf_instance_name
232  + ' successfully deployed and started')
def vnfs_deploy_nf
Deploys and STARTS a VNF instance.
def vnfs_get_instance_configuration
Return the configuration parameters related to a VNF instance.
def vnfs_operations.VNFSOperations.vnfs_destroy_vnf (   self,
  nf_path 
)

Destroys a deployed VNF instance.

Args: nf_path: path of the VNF instance.

Returns: return codes are described in hypervisor.hypervisor_return_codes module.

Definition at line 278 of file vnfs_operations.py.

279  def vnfs_destroy_vnf(self, nf_path):
280  logger.info("Destroying VNF at " + nf_path)
281  nf_instance_name, nf_type, ip_address, image_name = self.vnfs_get_instance_configuration(
282  nf_path)
283  self._hypervisor.destroy(ip_address, getpass.getuser(), nf_instance_name)
284  logger.info('Instance: ' + nf_instance_name + ' successfully destroyed')
def vnfs_destroy_vnf
Destroys a deployed VNF instance.
def vnfs_get_instance_configuration
Return the configuration parameters related to a VNF instance.
def vnfs_operations.VNFSOperations.vnfs_get_file_name (   self,
  path 
)

Return the name of the file represented by a path.

Args: path: the path of the file in concern

Returns: returns the name of the file, i.e., last token after / in the path.

Definition at line 141 of file vnfs_operations.py.

142  def vnfs_get_file_name(self, path):
143 
144  return path.split('/')[-1]
def vnfs_get_file_name
Return the name of the file represented by a path.
def vnfs_operations.VNFSOperations.vnfs_get_instance_configuration (   self,
  nf_path 
)

Return the configuration parameters related to a VNF instance.

Args: nf_path: path of the VNF instance. e.g., /mnt/vnfsmnt/firewall/fw-alpha

Returns: A tuple representing the configuration of the VNF instance. The tuple is organized in the following order: nf_instance_name: name of the VNF instance. nf_type: type of the VNF. ip_address: IP address of the machine where this VNF will be deployed. image_name: name of the VM/container image for that VNF.

Definition at line 184 of file vnfs_operations.py.

185  def vnfs_get_instance_configuration(self, nf_path):
186  nf_instance_name = self.vnfs_get_file_name(nf_path)
187  nf_type = self.vnfs_get_nf_type(nf_path)
188  ip_address = ''
189  logger.debug(nf_path + '/machine/ip')
190  with open(nf_path + '/machine/ip') as ip_fd:
191  ip_address = ip_fd.readline().rstrip('\n')
192  image_name = ''
193  with open(nf_path + '/machine/vm.image') as img_fd:
194  image_name = img_fd.readline().rstrip('\n')
195  logger.info("Instance name: " + nf_instance_name + ", type: "
196  + nf_type + ", host-ip: " + ip_address + " VNF image: " + image_name)
197  return nf_instance_name, nf_type, ip_address, image_name
def vnfs_get_instance_configuration
Return the configuration parameters related to a VNF instance.
def vnfs_get_file_name
Return the name of the file represented by a path.
def vnfs_get_nf_type
Parse the type of VNF from path.
def vnfs_operations.VNFSOperations.vnfs_get_ip (   self,
  nf_path 
)

Get the status of a VNF instance, e.g., the VNF is running/suspended/stopped etc.

Args: nf_path: path of the VNF instance.

Returns: Hypervisor specific status of the VNF. For example, if Docker is being used for VNF deployment then Docker specific container status message is returned.

Definition at line 390 of file vnfs_operations.py.

391  def vnfs_get_ip(self, nf_path):
392  logger.info('Reading ip at ' + nf_path)
393  nf_instance_name, nf_type, ip_address, image_name = self.vnfs_get_instance_configuration(
394  nf_path)
395  cont_ip = self._hypervisor.get_ip(ip_address, getpass.getuser(), nf_instance_name)
396  logger.debug('cont_ip ' + cont_ip)
397  logger.info('Successfully read ip')
398  return cont_ip
399 
def vnfs_get_instance_configuration
Return the configuration parameters related to a VNF instance.
def vnfs_get_ip
Get the status of a VNF instance, e.g., the VNF is running/suspended/stopped etc. ...
def vnfs_operations.VNFSOperations.vnfs_get_nf_type (   self,
  path 
)

Parse the type of VNF from path.

Args: path: the path of the file/directory on which some operation is being performed.

Returns: Returns the type of VNF parsed from the path, e.g., if the path is /mnt/vnfsroot/nf-types/firewall/fw-alpha/action then returns firewall.

Definition at line 122 of file vnfs_operations.py.

123  def vnfs_get_nf_type(self, path):
124  tokens = self._full_path(path).encode('ascii').split('/')
125  try:
126  return tokens[tokens.index("nf-types") + 1]
127  except ValueError:
128  return ""
129  except IndexError:
130  return ""
def vnfs_get_nf_type
Parse the type of VNF from path.
def vnfs_operations.VNFSOperations.vnfs_get_opcode (   self,
  path 
)

Determinse the type of operation based on the path.

Args: path: path to the file/directory on which the operation is being performed

Returns: If the file is under nf-types subdirectory in the nfio mount, then returns OP_NF. Otherwise, returns OP_UNDEFINED.

Definition at line 103 of file vnfs_operations.py.

104  def vnfs_get_opcode(self, path):
105  tokens = self._full_path(path).encode('ascii').split('/')
106  if "nf-types" in tokens:
107  return VNFSOperations.OP_NF
108  return VNFSOperations.OP_UNDEFINED
def vnfs_get_opcode
Determinse the type of operation based on the path.
def vnfs_operations.VNFSOperations.vnfs_get_pkt_drops (   self,
  nf_path 
)

Reads the number of packets dropped by a VNF instance.

Args: nf_path: path of the VNF instance.

Returns: returns the number of packets dropped by a VNF instance.

Definition at line 339 of file vnfs_operations.py.

340  def vnfs_get_pkt_drops(self, nf_path):
341  logger.info('Reading pkt_drops at ' + nf_path)
342  nf_instance_name, nf_type, ip_address, image_name = self.vnfs_get_instance_configuration(
343  nf_path)
344  command = "ifconfig eth0 | grep -Eo 'RX .* dropped:[0-9]+' | cut -d':' -f 4"
345  response = self._hypervisor.execute_in_guest(
346  ip_address,
347  getpass.getuser(), nf_instance_name,
348  command)
349  logger.info('Successfully read pkt_drops')
350  return response
def vnfs_get_instance_configuration
Return the configuration parameters related to a VNF instance.
def vnfs_get_pkt_drops
Reads the number of packets dropped by a VNF instance.
def vnfs_operations.VNFSOperations.vnfs_get_rx_bytes (   self,
  nf_path 
)

Reads the number of bytes received by a VNF instance.

Args: nf_path: path of the VNF instance.

Returns: returns the number of bytes received by a VNF instance.

Definition at line 295 of file vnfs_operations.py.

296  def vnfs_get_rx_bytes(self, nf_path):
297  logger.info('Reading rx_bytes at ' + nf_path)
298  nf_instance_name, nf_type, ip_address, image_name = self.vnfs_get_instance_configuration(
299  nf_path)
300  command = "ifconfig eth0 | grep -Eo 'RX bytes:[0-9]+' | cut -d':' -f 2"
301  response = self._hypervisor.execute_in_guest(
302  ip_address,
303  getpass.getuser(), nf_instance_name,
304  command)
305  logger.info('Successfully read rx_bytes')
306  return response
def vnfs_get_rx_bytes
Reads the number of bytes received by a VNF instance.
def vnfs_get_instance_configuration
Return the configuration parameters related to a VNF instance.
def vnfs_operations.VNFSOperations.vnfs_get_status (   self,
  nf_path 
)

Get the status of a VNF instance, e.g., the VNF is running/suspended/stopped etc.

Args: nf_path: path of the VNF instance.

Returns: Hypervisor specific status of the VNF. For example, if Docker is being used for VNF deployment then Docker specific container status message is returned.

Definition at line 364 of file vnfs_operations.py.

365  def vnfs_get_status(self, nf_path):
366  logger.info('Reading status at ' + nf_path)
367  nf_instance_name, nf_type, ip_address, image_name = self.vnfs_get_instance_configuration(
368  nf_path)
369  response = ''
370  try:
371  response = self._hypervisor.guest_status(ip_address, getpass.getuser(),
372  nf_instance_name)
374  logger.info('Instance: ' + nf_instance_name + ' does not exist')
375  logger.info('Successfully read status')
376  return response
def vnfs_get_status
Get the status of a VNF instance, e.g., the VNF is running/suspended/stopped etc. ...
def vnfs_get_instance_configuration
Return the configuration parameters related to a VNF instance.
def vnfs_operations.VNFSOperations.vnfs_get_tx_bytes (   self,
  nf_path 
)

Reads the number of bytes sent by a VNF instance.

Args: nf_path: path of the VNF instance.

Returns: returns the number of bytes sent by a VNF instance.

Definition at line 317 of file vnfs_operations.py.

318  def vnfs_get_tx_bytes(self, nf_path):
319  logger.info('Reading tx_bytes at ' + nf_path)
320  nf_instance_name, nf_type, ip_address, image_name = self.vnfs_get_instance_configuration(
321  nf_path)
322  command = "ifconfig eth0 | grep -Eo 'TX bytes:[0-9]+' | cut -d':' -f 2"
323  response = self._hypervisor.execute_in_guest(
324  ip_address,
325  getpass.getuser(), nf_instance_name,
326  command)
327  logger.info('Successfully read tx_bytes')
328  return response
def vnfs_get_instance_configuration
Return the configuration parameters related to a VNF instance.
def vnfs_get_tx_bytes
Reads the number of bytes sent by a VNF instance.
def vnfs_operations.VNFSOperations.vnfs_is_nf_instance (   self,
  path 
)

Determines if a path represents an nf instance directory.

Args: path: path of the file/directory in concern.

Returns: True: if path represents an nf instance directory. For example, if path is /mnt/vnfsmnt/nf-types/firewall/fw-alpha then returns True.

False: if the path does not represent an nf instance directory. For example, if path is /mnt/vnfsmnt/nf-types/firewall/fw-alpha/action then returns False.

Definition at line 160 of file vnfs_operations.py.

161  def vnfs_is_nf_instance(self, path):
162  tokens = self._full_path(path).encode('ascii').split('/')
163  if ('nf-types' in tokens) and len(tokens) > tokens.index('nf-types') + \
164  1:
165  return True
166  return False
def vnfs_is_nf_instance
Determines if a path represents an nf instance directory.
def vnfs_operations.VNFSOperations.vnfs_start_vnf (   self,
  nf_path 
)

Starts a deployed VNF instance.

Args: nf_path: path of the VNF instance.

Returns: return codes are described in hypervisor.hypervisor_return_codes module.

Definition at line 260 of file vnfs_operations.py.

261  def vnfs_start_vnf(self, nf_path):
262  logger.info("Starting VNF at " + nf_path)
263  nf_instance_name, nf_type, ip_address, image_name = self.vnfs_get_instance_configuration(
264  nf_path)
265  self._hypervisor.start(ip_address, getpass.getuser(), nf_instance_name)
266  logger.info('Instance: ' + nf_instance_name + ' successfully started')
def vnfs_start_vnf
Starts a deployed VNF instance.
def vnfs_get_instance_configuration
Return the configuration parameters related to a VNF instance.
def vnfs_operations.VNFSOperations.vnfs_stop_vnf (   self,
  nf_path 
)

Stops a VNF instance.

Args: nf_path: path of the VNF instance.

Returns
void

Definition at line 242 of file vnfs_operations.py.

243  def vnfs_stop_vnf(self, nf_path):
244  logger.info("Stopping VNF at " + nf_path)
245  nf_instance_name, nf_type, ip_address, image_name = self.vnfs_get_instance_configuration(
246  nf_path)
247  self._hypervisor.stop(ip_address, getpass.getuser(), nf_instance_name )
248  logger.info('Instance: ' + nf_instance_name + ' successfully stopped')
def vnfs_stop_vnf
Stops a VNF instance.
def vnfs_get_instance_configuration
Return the configuration parameters related to a VNF instance.

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