Example #1
0
    def from_datastruct(self,seed_data):
        self.name             = self.load_item(seed_data, 'name')
        self.cidr             = _CIDR(self.load_item(seed_data, 'cidr'))
        self.address          = _IP(self.load_item(seed_data, 'address', self.cidr[0]))
        self.gateway          = _IP(self.load_item(seed_data, 'gateway', self.cidr[-2]))
        self.broadcast        = _IP(self.load_item(seed_data, 'broadcast', self.cidr[-1]))
        self.nameservers      = [_IP(i) for i in self.load_item(seed_data, 'nameservers', [])]
        self.reserved         = [_CIDR(c) for c in self.load_item(seed_data, 'reserved', [])]
        self.used_addresses   = self.load_item(seed_data, 'used_addresses', {})
        self.free_addresses   = [_CIDR(c) for c in self.load_item(seed_data, 'free_addresses', [])]
        self.comment          = self.load_item(seed_data, 'comment', '')

        return self
Example #2
0
 def _add_to_free(self, addr, compact=True):
     """
     Add addr to the list of free addresses.  If compact is True,
     then take the list of CIDRs in free_addresses and compact it.
     """
     addr = _IP(addr).cidr()
     self.free_addresses.append(addr)
     if compact:
         self.free_addreses = self._compact(self.free_addresses)
 def _add_to_free(self, addr, compact=True):
     """
     Add addr to the list of free addresses.  If compact is True,
     then take the list of CIDRs in free_addresses and compact it.
     """
     addr = _IP(addr).cidr()
     self.free_addresses.append(addr)
     if compact:
         self.free_addreses = self._compact(self.free_addresses)
Example #4
0
 def set_nameservers(self, nameservers):
     old = self.nameservers
     nameservers = [_IP(s.strip()) for s in nameservers.split(',')]
     if old != None:
         for ns in old:
             if ns not in nameservers:
                 self._add_to_free(ns)
     for ns in nameservers:
         if ns not in old:
             self._remove_from_free(ns)
     self.nameservers = nameservers
 def set_broadcast(self, broadcast):
     if broadcast is None:
         # FIXME:
         self.broadcast = None
         return
     broadcast = broadcast.strip()
     if broadcast == "":
         self.broadcast = broadcast
     else:
         if self.broadcast != None:
             self._add_to_free(broadcast)
         self.broadcast = _IP(broadcast)
         self._remove_from_free(self.broadcast)
     return True
 def set_gateway(self, gateway):
     if gateway is None:
         # FIXME
         self.gateway = None
         return
     gateway = gateway.strip()
     if gateway == "":
         self.gateway = gateway
     else:
         if self.gateway != None:
             self._add_to_free(gateway)
         self.gateway = _IP(gateway)
         self._remove_from_free(self.gateway)
     return True
 def set_address(self, address):
     if address is None:
         # FIXME: probably wrong handling, need to reimpl "is_valid"
         # logic for all objects?
         self.address = None
         return
     address = address.strip()
     if address == "":
         self.address = address
     else:
         if self.address != None:
             self._add_to_free(address)
         self.address = _IP(address)
         self._remove_from_free(self.address)
     return True
Example #8
0
 def set_broadcast(self, broadcast):
     if self.broadcast != None:
         self._add_to_free(broadcast)
     self.broadcast = _IP(broadcast)
     self._remove_from_free(self.broadcast)
Example #9
0
 def set_gateway(self, gateway):
     if self.gateway != None:
         self._add_to_free(gateway)
     self.gateway = _IP(gateway)
     self._remove_from_free(self.gateway)
Example #10
0
 def set_address(self, address):
     if self.address != None:
         self._add_to_free(address)
     self.address = _IP(address)
     self._remove_from_free(self.address)