Example #1
0
 def normalizeStaticIp(self,
                       ipaddress,
                       netmask="255.255.255.0",
                       gateway=None,
                       nameservers=None):
     """Normalize static IP options for network configuration.
     
     As implemented only supports IPv4.
     
     ipaddress
         IP address.
     
     netmask
         netmask.
         Defaults to 255.255.255.0.
     
     gateway
         gateway.
         If None then default to ip.1.
     
     nameservers
         one nameserver or a list of nameservers.
         If None then default to gateway.
         If empty list then remove option.
     
     return
         a NetworkConfigurationStaticParameters instance."""
     # also see http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s1-kickstart2-options.html
     # sanity check
     ipaddress = IPAddress.asString(ipaddress)
     if not re.match(r"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$",
                     ipaddress):
         raise Exception(
             "won't accept apparently impossible IP address {0}".format(
                 ipaddress))
     netmask = IPAddress.asString(netmask)
     if gateway is None:
         # default to ip.1
         gateway = IPAddress.bitOr(IPAddress.bitAnd(ipaddress, netmask),
                                   "0.0.0.1")
     gateway = IPAddress.asString(gateway)
     if nameservers is None:
         # default to gateway
         nameservers = [gateway]
     elif not isinstance(nameservers, list):
         # process one as a list of one
         nameservers = [nameservers]
     else:
         # given a list already
         nameservers = nameservers
     nameserversStrings = [
         IPAddress.asString(oneNameserver) for oneNameserver in nameservers
     ]
     normalized = NetworkConfigurationStaticParameters(
         ipaddress=ipaddress,
         netmask=netmask,
         gateway=gateway,
         nameservers=nameserversStrings)
     return normalized
 def normalizeStaticIp(self, ipaddress, netmask="255.255.255.0", gateway=None, nameservers=None):
     """Normalize static IP options for network configuration.
     
     As implemented only supports IPv4.
     
     ipaddress
         IP address.
     
     netmask
         netmask.
         Defaults to 255.255.255.0.
     
     gateway
         gateway.
         If None then default to ip.1.
     
     nameservers
         one nameserver or a list of nameservers.
         If None then default to gateway.
         If empty list then remove option.
     
     return
         a NetworkConfigurationStaticParameters instance."""
     # also see http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s1-kickstart2-options.html
     # sanity check
     ipaddress = IPAddress.asString(ipaddress)
     if not re.match(r"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", ipaddress):
         raise Exception("won't accept apparently impossible IP address {0}".format(ipaddress))
     netmask = IPAddress.asString(netmask)
     if gateway is None:
         # default to ip.1
         gateway = IPAddress.bitOr(IPAddress.bitAnd(ipaddress, netmask), "0.0.0.1")
     gateway = IPAddress.asString(gateway)
     if nameservers is None:
         # default to gateway
         nameservers = [gateway]
     elif not isinstance(nameservers, list):
         # process one as a list of one
         nameservers = [nameservers]
     else:
         # given a list already
         nameservers = nameservers
     nameserversStrings = [IPAddress.asString(oneNameserver) for oneNameserver in nameservers]
     normalized = NetworkConfigurationStaticParameters(ipaddress=ipaddress,
                                                       netmask=netmask,
                                                       gateway=gateway,
                                                       nameservers=nameserversStrings)
     return normalized
Example #3
0
 def localprefix(self):
     return IPAddress.bitAnd(self.ipaddress, self.netmask)
 def localprefix(self):
     return IPAddress.bitAnd(self.ipaddress, self.netmask)