diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index c565a03ffae..4ba3b9cdab6 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -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 diff --git a/server/src/com/cloud/network/configuration/GuestNetworkGuru.java b/server/src/com/cloud/network/configuration/GuestNetworkGuru.java index 9e93fdcd600..5e58bbba0f3 100644 --- a/server/src/com/cloud/network/configuration/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/configuration/GuestNetworkGuru.java @@ -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 diff --git a/server/src/com/cloud/network/configuration/PublicNetworkGuru.java b/server/src/com/cloud/network/configuration/PublicNetworkGuru.java index f2918cdc27c..25f13f3c82e 100644 --- a/server/src/com/cloud/network/configuration/PublicNetworkGuru.java +++ b/server/src/com/cloud/network/configuration/PublicNetworkGuru.java @@ -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 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 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 diff --git a/server/src/com/cloud/vm/MauriceMoss.java b/server/src/com/cloud/vm/MauriceMoss.java index 86aa4ec0373..c2a5046ec33 100644 --- a/server/src/com/cloud/vm/MauriceMoss.java +++ b/server/src/com/cloud/vm/MauriceMoss.java @@ -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();