def gen_one(): try: ip = pool.GenerateFree() except errors.AddressPoolError: raise errors.ReservationError( "Cannot generate IP. Network is full") return (RESERVE_ACTION, ip, net_uuid)
def _UnlockedReserveIp(self, net_uuid, address, ec_id, check=True): """Reserve a given IPv4 address for use by an instance. """ nobj = self._UnlockedGetNetwork(net_uuid) pool = AddressPool(nobj) try: isreserved = pool.IsReserved(address) isextreserved = pool.IsReserved(address, external=True) except errors.AddressPoolError: raise errors.ReservationError("IP address not in network") if isreserved: raise errors.ReservationError("IP address already in use") if check and isextreserved: raise errors.ReservationError("IP is externally reserved") return self._temporary_ips.Reserve(ec_id, (RESERVE_ACTION, address, net_uuid))
def Reserve(self, ec_id, resource): if self.Reserved(resource): raise errors.ReservationError( "Duplicate reservation for resource '%s'" % str(resource)) if ec_id not in self._ec_reserved: self._ec_reserved[ec_id] = set([resource]) else: self._ec_reserved[ec_id].add(resource)
def ReserveLV(self, lv_name, ec_id): """Reserve an VG/LV pair for an instance. @type lv_name: string @param lv_name: the logical volume name to reserve """ all_lvs = self._AllLVs() if lv_name in all_lvs: raise errors.ReservationError("LV already in use") else: self._temporary_lvs.Reserve(ec_id, lv_name)
def ReserveMAC(self, mac, ec_id): """Reserve a MAC for an instance. This only checks instances managed by this cluster, it does not check for potential collisions elsewhere. """ all_macs = self._AllMACs() if mac in all_macs: raise errors.ReservationError("mac already in use") else: self._temporary_macs.Reserve(ec_id, mac)