|
Server : Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 System : Linux server.jackjohnson.com 2.6.32-279.5.2.el6.x86_64 #1 SMP Fri Aug 24 01:07:11 UTC 2012 x86_64 User : jackjohn ( 502) PHP Version : 5.3.17 Disable Function : NONE Directory : /usr/share/system-config-network/netconfpkg/ |
Upload File : |
"Host Module"
import socket
from netconfpkg.NCAliasList import AliasList
from netconfpkg.NC_functions import testHostname
from netconfpkg.gdt import (Gdtstruct, gdtstruct_properties, Gdtstr)
class Host_base(Gdtstruct):
gdtstruct_properties([
('IP', Gdtstr, "Test doc string"),
('Hostname', Gdtstr, "Test doc string"),
('AliasList', AliasList, "Test doc string"),
])
def __init__(self):
super(Host_base, self).__init__()
self.IP = None
self.Hostname = None
self.AliasList = AliasList()
def createAliasList(self):
if not self.AliasList:
self.AliasList = AliasList()
return self.AliasList
class Host(Host_base):
HostID = None
def __init__(self):
super(Host, self).__init__()
# special store for the original comment
self.Comment = None
# special store for the original line
self.origLine = None
def testIP(self):
try:
socket.inet_pton(socket.AF_INET, self.IP)
except socket.error:
try:
socket.inet_pton(socket.AF_INET6, self.IP)
except socket.error:
return False
return True
def testHostname(self):
return testHostname(self.Hostname)
def test(self):
if not self.testIP():
raise ValueError("IP")
if not self.testHostname():
raise ValueError("Hostname")
if self.AliasList and not self.AliasList.test():
raise ValueError("Alias")