more changes on the way

This commit is contained in:
Alex Huang 2010-11-01 15:01:22 -07:00
parent cd1c903260
commit 394af1b29c
4 changed files with 25 additions and 20 deletions

View File

@ -33,7 +33,7 @@ updateResourceLimit=com.cloud.api.commands.UpdateResourceLimitCmd;3
listResourceLimits=com.cloud.api.commands.ListResourceLimitsCmd;15
#### VM commands
deployVirtualMachine=com.cloud.api.commands.DeployVm2Cmd;11
deployVirtualMachine=com.cloud.api.commands.DeployVMCmd;11
destroyVirtualMachine=com.cloud.api.commands.DestroyVMCmd;15
rebootVirtualMachine=com.cloud.api.commands.RebootVMCmd;15
startVirtualMachine=com.cloud.api.commands.StartVMCmd;15

View File

@ -177,7 +177,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
return null;
}
Long[] array = allPossibleIps.toArray(new Long[allPossibleIps.size()]);
return NetUtils.long2Ip(array[_rand.nextInt() % array.length]);
return NetUtils.long2Ip(array[_rand.nextInt(array.length)]);
}
@Override

View File

@ -23,6 +23,7 @@ import com.cloud.network.Network.Mode;
import com.cloud.network.Network.TrafficType;
import com.cloud.network.NetworkConfiguration;
import com.cloud.network.NetworkConfigurationVO;
import com.cloud.network.dao.NetworkConfigurationDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.resource.Resource.ReservationStrategy;
import com.cloud.user.Account;
@ -38,6 +39,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
@Inject DataCenterDao _dcDao;
@Inject VlanDao _vlanDao;
@Inject NetworkConfigurationDao _networkConfigDao;
@Override
public NetworkConfiguration design(NetworkOffering offering, DeploymentPlan plan, NetworkConfiguration config, Account owner) {
@ -65,6 +67,12 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
nic.setStrategy(ReservationStrategy.Create);
}
String mac = _networkConfigDao.getNextAvailableMacAddress(config.getId());
if (mac == null) {
throw new InsufficientAddressCapacityException("Not enough mac addresses");
}
nic.setMacAddress(mac);
return nic;
}
@ -75,29 +83,27 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
}
DataCenter dc = dest.getDataCenter();
long dcId = dc.getId();
String[] macs = _dcDao.getNextAvailableMacAddressPair(dcId);
Pair<String, VlanVO> ipAndVlan = _vlanDao.assignIpAddress(dcId, vm.getVm().getAccountId(), vm.getVm().getDomainId(), VlanType.VirtualNetwork, true);
if (ipAndVlan == null) {
throw new InsufficientVirtualNetworkCapcityException("Unable to get public ip address in " + dcId);
if (ch.getIp4Address() != null) {
Pair<String, VlanVO> ipAndVlan = _vlanDao.assignIpAddress(dcId, vm.getVm().getAccountId(), vm.getVm().getDomainId(), VlanType.VirtualNetwork, true);
if (ipAndVlan == null) {
throw new InsufficientVirtualNetworkCapcityException("Unable to get public ip address in " + dcId);
}
VlanVO vlan = ipAndVlan.second();
ch.setIp4Address(ipAndVlan.first());
ch.setGateway(vlan.getVlanGateway());
ch.setNetmask(vlan.getVlanNetmask());
ch.setIsolationUri(IsolationType.Vlan.toUri(vlan.getVlanId()));
ch.setBroadcastType(BroadcastDomainType.Vlan);
ch.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlan.getVlanId()));
ch.setFormat(AddressFormat.Ip4);
ch.setReservationId(Long.toString(vlan.getId()));
}
VlanVO vlan = ipAndVlan.second();
ch.setIp4Address(ipAndVlan.first());
ch.setGateway(vlan.getVlanGateway());
ch.setNetmask(vlan.getVlanNetmask());
ch.setIsolationUri(IsolationType.Vlan.toUri(vlan.getVlanId()));
ch.setBroadcastType(BroadcastDomainType.Vlan);
ch.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlan.getVlanId()));
ch.setMacAddress(macs[1]);
ch.setFormat(AddressFormat.Ip4);
ch.setReservationId(Long.toString(vlan.getId()));
ch.setDns1(dc.getDns1());
ch.setDns2(dc.getDns2());
return Long.toString(vlan.getId());
return ch.getReservationId();
}
@Override

View File

@ -122,7 +122,6 @@ public class MauriceMoss implements VmManager {
throw new CloudRuntimeException("Guest OS is not set");
}
//VMInstanceVO vm = _vmDao.findById(vm.getId());
VirtualMachineProfile vmProfile = new VirtualMachineProfile(vm, serviceOffering, guestOS.getDisplayName(), template.getHypervisorType());
Transaction txn = Transaction.currentTxn();