Beispiel #1
0
    def _UnlockedCommitIp(self, action, net_uuid, address):
        """Commit a reserved IP address to an IP pool.

    The IP address is taken from the network's IP pool and marked as reserved.

    """
        nobj = self._UnlockedGetNetwork(net_uuid)
        pool = AddressPool(nobj)
        if action == RESERVE_ACTION:
            pool.Reserve(address)
        elif action == RELEASE_ACTION:
            pool.Release(address)
Beispiel #2
0
    def CreateNic(self,
                  uuid=None,
                  name=None,
                  mac=None,
                  ip=None,
                  network=None,
                  nicparams=None,
                  netinfo=None):
        """Create a new L{objecs.NIC} object

    @rtype: L{objects.NIC}
    @return: the newly create NIC object

    """
        nic_id = self._cur_nic_id
        self._cur_nic_id += 1

        if uuid is None:
            uuid = self._GetUuid()
        if name is None:
            name = "mock_nic_%d" % nic_id
        if mac is None:
            mac = "aa:00:00:aa:%02x:%02x" % (nic_id / 0xff, nic_id % 0xff)
        if isinstance(network, objects.Network):
            if ip:
                pool = AddressPool(network)
                pool.Reserve(ip)
            network = network.uuid
        if nicparams is None:
            nicparams = {}

        return objects.NIC(uuid=uuid,
                           name=name,
                           mac=mac,
                           ip=ip,
                           network=network,
                           nicparams=nicparams,
                           netinfo=netinfo)