nrvr.machine.ports
index
/usr/lib/python2.7/site-packages/nrvr/machine/ports.py

nrvr.machine.ports - Create and modify a .ports file
 
The main class provided by this module is PortsFile.
 
To be expanded as needed.
 
Idea and first implementation - Leo Baschy <srguiwiz12 AT nrvr DOT com>
 
Contributor - Nora Baschy
 
Public repository - https://github.com/srguiwiz/nrvr-commander
 
Copyright (c) Nirvana Research 2006-2015.
Simplified BSD License

 
Modules
       
codecs
os

 
Classes
       
__builtin__.object
PortsFile

 
class PortsFile(__builtin__.object)
    A .ports file for a machine.
 
Example content::
 
    <?xml version="1.0" encoding="utf-8"?>
    <ports>
      <ssh>
        <ipaddress>10.123.45.67</ipaddress>
        <user>root</user>
        <pwd>redwood</pwd>
      </ssh>
      <shutdown>
        <command>shutdown -P now</command>
        <user>root</user>
        <protocol>ssh</protocol>
      </shutdown>
      <ssh>
        <ipaddress>10.123.45.67</ipaddress>
        <user>joe</user>
        <pwd>dummy</pwd>
      </ssh>
      <regularuser>joe</regularuser>
    </ports>
 
  Methods defined here:
__init__(self, portsFilePath)
Create new .ports file descriptor.
 
A descriptor can describe a .ports file that does or doesn't yet exist on the host disk.
changeIPAddress(self, oldIpAddress, newIpAddress)
Set .ports file entry for shutdown command for machine.
create(self)
Create a .ports file.
 
As implemented creates an empty container.
 
Does nothing in case file already exist on the host disk.
exists(self)
Return True if file exists on the host disk.
getPorts(self, protocol=None, user=None)
Return a list of dictionaries of .ports file entries for a user.
 
If self.portsFileContent is None then return None.
 
If no match then return empty list [].
 
protocol
    e.g. "ssh".
    
    If None then all.
 
user
    e.g. "joe".
    
    If None then all.
getRegularUser(self)
Return a regular user from .ports file entry.
Often the main user.
 
If none then return None.
modify(self, portsFileContentModifyingMethod)
Recommended safe wrapper to modify .ports file.
 
Does nothing in case file doesn't exist on the host disk.
Intentionally does nothing to support installation policies where .ports files
are not to be stored.
 
To make sure file exists, call create().
removeSsh(self, ipaddress, user)
Remove .ports file entry for ssh access for a user.
setRegularUser(self, regularUser)
Set .ports file entry for a regular user.
Often the main user.
 
regularUser
    name of regular user.
    
    If falsy then remove entry.
setShutdown(self, command='shutdown -P now', user='root', protocol='ssh')
Set .ports file entry for shutdown command for machine.
setSsh(self, ipaddress, user, pwd)
Set .ports file entry for ssh access for a user.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
portsFileContent
An xml.etree.ElementTree instance.
 
If not exists() may be None.
portsFilePath
Path of the .ports file.