diff --git a/api/src/com/cloud/vm/Nic.java b/api/src/com/cloud/vm/Nic.java index 621a7c1e43f..54d93d00221 100644 --- a/api/src/com/cloud/vm/Nic.java +++ b/api/src/com/cloud/vm/Nic.java @@ -25,6 +25,7 @@ import com.cloud.resource.Resource; * Nic represents one nic on the VM. */ public interface Nic extends Resource { + boolean isDefaultNic(); String getIp4Address(); diff --git a/api/src/com/cloud/vm/NicProfile.java b/api/src/com/cloud/vm/NicProfile.java index ab89c55ac8e..74edf3d7a91 100644 --- a/api/src/com/cloud/vm/NicProfile.java +++ b/api/src/com/cloud/vm/NicProfile.java @@ -194,6 +194,10 @@ public class NicProfile { this.macAddress = nic.getMacAddress(); this.reservationId = nic.getReservationId(); this.strategy = nic.getReservationStrategy(); + this.deviceId = nic.getDeviceId(); + this.defaultNic = nic.isDefaultNic(); + this.broadcastUri = broadcastUri; + this.isolationUri = isolationUri; } public NicProfile(long id, BroadcastDomainType type, Mode mode, long vmId) { diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 543e878ca9b..f71a0c42471 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -531,7 +531,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach @Override public ConsoleProxyVO startProxy(long proxyVmId, long startEventId) { try { - return start2(proxyVmId, startEventId); + return start(proxyVmId, startEventId); } catch (StorageUnavailableException e) { s_logger.warn("Exception while trying to start console proxy", e); return null; @@ -887,7 +887,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach if (s_logger.isDebugEnabled()) s_logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId); - Map context = createProxyInstance2(dataCenterId); + Map context = createProxyInstance(dataCenterId); long proxyVmId = (Long) context.get("proxyVmId"); if (proxyVmId == 0) { @@ -927,7 +927,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach if (s_logger.isDebugEnabled()) s_logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId); - Map context = createProxyInstance2(dataCenterId); + Map context = createProxyInstance(dataCenterId); long proxyVmId = (Long) context.get("proxyVmId"); if (proxyVmId == 0) { @@ -1468,7 +1468,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach try { if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { - readyProxy = start2(readyProxy.getId(), 0); + readyProxy = start(readyProxy.getId(), 0); } finally { proxyLock.unlock(); } diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java index ce60a6a8b28..83d74fd6746 100644 --- a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java @@ -57,7 +57,8 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis ServiceOffering offering = vmProfile.getServiceOffering(); VirtualMachine vm = vmProfile.getVirtualMachine(); - VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), offering.getRamSize(), null, vmProfile.getOs()); + VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), offering.getSpeed(), offering.getRamSize() * 1024l * 1024l, offering.getRamSize() * 1024l * 1024l, null, vmProfile.getOs()); + to.setBootArgs(vmProfile.getBootArgs()); List nicProfiles = vmProfile.getNics(); NicTO[] nics = new NicTO[nicProfiles.size()]; diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 211d860bbc1..d1c06b06777 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -302,9 +302,9 @@ public interface NetworkManager extends Manager { List getSystemAccountNetworkOfferings(String... offeringNames); - List allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException; + void allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException; - List prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws InsufficientNetworkCapacityException, ConcurrentOperationException, ResourceUnavailableException; + void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws InsufficientNetworkCapacityException, ConcurrentOperationException, ResourceUnavailableException; void release(VirtualMachineProfile vmProfile); DomainRouter upgradeRouter(UpgradeRouterCmd cmd); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index c53fcd994ff..f7c4c436fea 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -17,6 +17,7 @@ */ package com.cloud.network; +import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -1759,9 +1760,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService { } @Override @DB - public List allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException { - List nicProfiles = new ArrayList(networks.size()); - + public void allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException { Transaction txn = Transaction.currentTxn(); txn.start(); @@ -1809,7 +1808,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService { deviceIds[devId] = true; nics.add(vo); - nicProfiles.add(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri())); + vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri())); } if (defaultNic == null && nics.size() > 2) { @@ -1819,8 +1818,6 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService { } txn.commit(); - - return nicProfiles; } protected Integer applyProfileToNic(NicVO vo, NicProfile profile, Integer deviceId) { @@ -1933,7 +1930,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService { } @Override - public List prepare(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) throws InsufficientNetworkCapacityException, ConcurrentOperationException, ResourceUnavailableException { + public void prepare(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) throws InsufficientNetworkCapacityException, ConcurrentOperationException, ResourceUnavailableException { List nics = _nicDao.listBy(vmProfile.getId()); for (NicVO nic : nics) { Pair implemented = implementNetworkConfiguration(nic.getNetworkConfigurationId(), dest, context); @@ -1943,7 +1940,14 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService { if (nic.getReservationStrategy() == ReservationStrategy.Start) { nic.setState(Resource.State.Reserving); _nicDao.update(nic.getId(), nic); - profile = toNicProfile(nic); + URI broadcastUri = nic.getBroadcastUri(); + if (broadcastUri == null) { + config.getBroadcastUri(); + } + + URI isolationUri = nic.getIsolationUri(); + + profile = new NicProfile(nic, config, broadcastUri, isolationUri); String reservationId = concierge.reserve(profile, config, vmProfile, dest); nic.setIp4Address(profile.getIp4Address()); nic.setIp6Address(profile.getIp6Address()); @@ -1967,7 +1971,6 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService { vmProfile.addNic(profile); } - return vmProfile.getNics(); } @Override @@ -1984,12 +1987,6 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService { } } - NicProfile toNicProfile(NicVO nic) { - NetworkConfiguration config = _networkConfigDao.findById(nic.getNetworkConfigurationId()); - NicProfile profile = new NicProfile(nic, config, nic.getBroadcastUri(), nic.getIsolationUri()); - return profile; - } - public void release(long vmId) { List nics = _nicDao.listBy(vmId); diff --git a/server/src/com/cloud/network/configuration/GuestNetworkGuru.java b/server/src/com/cloud/network/configuration/GuestNetworkGuru.java index 4a463194be9..ec7b8a0cf42 100644 --- a/server/src/com/cloud/network/configuration/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/configuration/GuestNetworkGuru.java @@ -140,7 +140,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm) + public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { if (config.getTrafficType() != TrafficType.Guest) { return null; diff --git a/server/src/com/cloud/network/configuration/PublicNetworkGuru.java b/server/src/com/cloud/network/configuration/PublicNetworkGuru.java index bdc61c9978e..4477f307ed9 100644 --- a/server/src/com/cloud/network/configuration/PublicNetworkGuru.java +++ b/server/src/com/cloud/network/configuration/PublicNetworkGuru.java @@ -86,7 +86,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { DataCenter dc = dest.getDataCenter(); long dcId = dc.getId(); - if (ch.getIp4Address() != null) { + if (ch.getIp4Address() == null) { Pair ipAndVlan = _vlanDao.assignIpAddress(dcId, vm.getVirtualMachine().getAccountId(), vm.getVirtualMachine().getDomainId(), VlanType.VirtualNetwork, true); if (ipAndVlan == null) { throw new InsufficientVirtualNetworkCapcityException("Unable to get public ip address in " + dcId); diff --git a/server/src/com/cloud/vm/ItWorkVO.java b/server/src/com/cloud/vm/ItWorkVO.java index 157cf011b48..f104d791c73 100644 --- a/server/src/com/cloud/vm/ItWorkVO.java +++ b/server/src/com/cloud/vm/ItWorkVO.java @@ -71,6 +71,7 @@ public class ItWorkVO { this.managementServerId = managementServerId; this.type = type; this.threadName = Thread.currentThread().getName(); + this.state = State.Working; } public String getId() { diff --git a/server/src/com/cloud/vm/MauriceMoss.java b/server/src/com/cloud/vm/MauriceMoss.java index 23395b2c16f..39a06cbb456 100644 --- a/server/src/com/cloud/vm/MauriceMoss.java +++ b/server/src/com/cloud/vm/MauriceMoss.java @@ -150,8 +150,7 @@ public class MauriceMoss implements VmManager, ClusterManagerListener { if (s_logger.isDebugEnabled()) { s_logger.debug("Allocating nics for " + vm); } - List nics = _networkMgr.allocate(vmProfile, networks); - vmProfile.setNics(nics); + _networkMgr.allocate(vmProfile, networks); if (dataDiskOfferings == null) { dataDiskOfferings = new ArrayList>(0); @@ -161,14 +160,13 @@ public class MauriceMoss implements VmManager, ClusterManagerListener { s_logger.debug("Allocaing disks for " + vm); } - List disks = new ArrayList(dataDiskOfferings.size() + 1); if (template.getFormat() == ImageFormat.ISO) { - disks.add(_storageMgr.allocateRawVolume(VolumeType.ROOT, "ROOT-" + vm.getId(), rootDiskOffering.first(), rootDiskOffering.second(), vm, owner)); + _storageMgr.allocateRawVolume(VolumeType.ROOT, "ROOT-" + vm.getId(), rootDiskOffering.first(), rootDiskOffering.second(), vm, owner); } else { - disks.add(_storageMgr.allocateTemplatedVolume(VolumeType.ROOT, "ROOT-" + vm.getId(), rootDiskOffering.first(), template, vm, owner)); + _storageMgr.allocateTemplatedVolume(VolumeType.ROOT, "ROOT-" + vm.getId(), rootDiskOffering.first(), template, vm, owner); } for (Pair offering : dataDiskOfferings) { - disks.add(_storageMgr.allocateRawVolume(VolumeType.DATADISK, "DATA-" + vm.getId(), offering.first(), offering.second(), vm, owner)); + _storageMgr.allocateRawVolume(VolumeType.DATADISK, "DATA-" + vm.getId(), offering.first(), offering.second(), vm, owner); } _vmDao.updateIf(vm, Event.OperationSucceeded, null); @@ -284,10 +282,12 @@ public class MauriceMoss implements VmManager, ClusterManagerListener { DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodId(), null, null); HypervisorGuru hvGuru = _hvGurus.get(template.getHypervisorType()); + @SuppressWarnings("unchecked") + VirtualMachineGuru vmGuru = (VirtualMachineGuru)_vmGurus.get(vm.getType()); + // Determine the VM's OS description GuestOSVO guestOS = _guestOsDao.findById(vm.getGuestOSId()); - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, guestOS.getDisplayName(), template, offering, null, params); if (!_vmDao.updateIf(vm, Event.StartRequested, null)) { throw new ConcurrentOperationException("Unable to start vm " + vm + " due to concurrent operations"); } @@ -295,6 +295,7 @@ public class MauriceMoss implements VmManager, ClusterManagerListener { ExcludeList avoids = new ExcludeList(); int retry = _retry; while (retry-- != 0) { // It's != so that it can match -1. + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, guestOS.getDisplayName(), template, offering, null, params); DeployDestination dest = null; for (DeploymentPlanner planner : _planners) { dest = planner.plan(vmProfile, plan, avoids); @@ -323,15 +324,13 @@ public class MauriceMoss implements VmManager, ClusterManagerListener { } _networkMgr.prepare(vmProfile, dest, context); + vmGuru.finalizeVirtualMachineProfile(vmProfile, dest, context); VirtualMachineTO vmTO = hvGuru.implement(vmProfile); Commands cmds = new Commands(OnError.Revert); cmds.addCommand(new Start2Command(vmTO)); - @SuppressWarnings("unchecked") - VirtualMachineGuru vmGuru = (VirtualMachineGuru)_vmGurus.get(vm.getType()); - vmGuru.finalizeDeployment(cmds, vmProfile, dest, context); try { Answer[] answers = _agentMgr.send(dest.getHost().getId(), cmds); @@ -352,7 +351,7 @@ public class MauriceMoss implements VmManager, ClusterManagerListener { } if (s_logger.isDebugEnabled()) { - s_logger.debug("Creation complete for VM " + vmProfile); + s_logger.debug("Creation complete for VM " + vm); } return null;