diff --git a/core/src/com/cloud/storage/StorageManager.java b/core/src/com/cloud/storage/StorageManager.java index b230bb971b6..c38c439b66d 100755 --- a/core/src/com/cloud/storage/StorageManager.java +++ b/core/src/com/cloud/storage/StorageManager.java @@ -36,7 +36,6 @@ import com.cloud.exception.ResourceInUseException; import com.cloud.exception.StorageUnavailableException; import com.cloud.host.Host; import com.cloud.host.HostVO; -import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.Volume.VolumeType; @@ -320,10 +319,10 @@ public interface StorageManager extends Manager { DiskProfile allocateRawVolume(VolumeType type, String name, DiskOfferingVO offering, Long size, T vm, AccountVO owner); DiskProfile allocateTemplatedVolume(VolumeType type, String name, DiskOfferingVO offering, VMTemplateVO template, T vm, AccountVO owner); - void create(T vm); Long findHostIdForStoragePool(StoragePool pool); void createCapacityEntry(StoragePoolVO storagePool, long allocated); VolumeTO[] prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException; + void release(VirtualMachineProfile vm); } diff --git a/server/src/com/cloud/network/NetworkConfigurationVO.java b/server/src/com/cloud/network/NetworkConfigurationVO.java index 8a9f81520b1..57d0e66bb20 100644 --- a/server/src/com/cloud/network/NetworkConfigurationVO.java +++ b/server/src/com/cloud/network/NetworkConfigurationVO.java @@ -25,6 +25,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; +import javax.persistence.TableGenerator; import com.cloud.network.Network.BroadcastDomainType; import com.cloud.network.Network.Mode; @@ -80,6 +81,10 @@ public class NetworkConfigurationVO implements NetworkConfiguration { @Column(name="dns") String dns; + @Column(name="mac_address_seq", updatable=false, nullable=false) + @TableGenerator(name="mac_address_seq", table="network_configuration", pkColumnName="id", valueColumnName="mac_address_seq", allocationSize=1) + long macAddress = 1; + public NetworkConfigurationVO() { } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 6e04cda5326..756cbc16f52 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -230,6 +230,7 @@ public interface NetworkManager extends Manager { List allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException; NicTO[] prepare(VirtualMachineProfile profile, DeployDestination dest) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException; + void release(VirtualMachineProfile vmProfile); void create(K vm); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 993da48171e..fd73165c7e4 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -2629,6 +2629,20 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager return nicTos; } + @Override + public void release(VirtualMachineProfile vmProfile) { + List nics = _nicDao.listBy(vmProfile.getId()); + for (NicVO nic : nics) { + NetworkConfigurationVO config = _networkProfileDao.findById(nic.getNetworkConfigurationId()); + if (nic.getReservationStrategy() == ReservationStrategy.Start) { + NetworkGuru concierge = _networkGurus.get(config.getGuruName()); + nic.setState(Resource.State.Releasing); + _nicDao.update(nic.getId(), nic); + concierge.release(nic.getReservationId()); + } + } + } + NicProfile toNicProfile(NicVO nic) { NetworkConfiguration config = _networkProfileDao.findById(nic.getNetworkConfigurationId()); NicProfile profile = new NicProfile(nic, config, nic.getBroadcastUri(), nic.getIsolationUri()); diff --git a/server/src/com/cloud/network/configuration/ControlNetworkGuru.java b/server/src/com/cloud/network/configuration/ControlNetworkGuru.java index 59bf7d3a83f..7570f4137fb 100644 --- a/server/src/com/cloud/network/configuration/ControlNetworkGuru.java +++ b/server/src/com/cloud/network/configuration/ControlNetworkGuru.java @@ -30,6 +30,7 @@ import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.Inject; import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.net.NetUtils; import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachineProfile; @@ -100,7 +101,7 @@ public class ControlNetworkGuru extends AdapterBase implements NetworkGuru { InsufficientAddressCapacityException { String ip = _dcDao.allocateLinkLocalPrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), vm.getId()); nic.setIp4Address(ip); - nic.setMacAddress("FE:FF:FF:FF:FF:FF"); + nic.setMacAddress(NetUtils.long2Mac(NetUtils.ip2Long(ip) | (14l << 40))); nic.setNetmask("255.255.0.0"); nic.setFormat(AddressFormat.Ip4); diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index b35c5742d1b..b5e0bf46f07 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -2461,99 +2461,7 @@ public class StorageManagerImpl implements StorageManager { } @Override - public void create(T vm) { - List vols = _volsDao.findByInstance(vm.getId()); - assert vols.size() >= 1 : "Come on, what's with the zero volumes for " + vm; - for (VolumeVO vol : vols) { - DiskProfile dskCh = createDiskCharacteristics(vol); - int retry = _retry; - while (--retry >= 0) { - - } - } - /* -StoragePoolVO pool = null; -final HashSet avoidPools = new HashSet(avoids); - -VolumeType volType = volume.getVolumeType(); - -VolumeTO created = null; -int retry = _retry; -while (--retry >= 0) { -created = null; - -txn.start(); - -long podId = pod.getId(); -pod = _podDao.lock(podId, true); -if (pod == null) { -txn.rollback(); -volume.setStatus(AsyncInstanceCreateStatus.Failed); -volume.setDestroyed(true); -_volsDao.persist(volume); -throw new CloudRuntimeException("Unable to acquire lock on the pod " + podId); -} - -pool = findStoragePool(dskCh, dc, pod, clusterId, offering, vm, template, avoidPools); -if (pool == null) { -txn.rollback(); -break; -} - -avoidPools.add(pool); -if (s_logger.isDebugEnabled()) { -s_logger.debug("Trying to create " + volume + " on " + pool); -} - -volume.setPoolId(pool.getId()); -_volsDao.persist(volume); - -txn.commit(); - -CreateCommand cmd = null; -VMTemplateStoragePoolVO tmpltStoredOn = null; -if (volume.getVolumeType() == VolumeType.ROOT && Storage.ImageFormat.ISO != template.getFormat()) { -tmpltStoredOn = _tmpltMgr.prepareTemplateForCreate(template, pool); -if (tmpltStoredOn == null) { -continue; -} -cmd = new CreateCommand(volume, vm, dskCh, tmpltStoredOn.getLocalDownloadPath(), pool); -} else { -cmd = new CreateCommand(volume, vm, dskCh, pool, size); -} - -Answer answer = sendToPool(pool, cmd); -if (answer != null && answer.getResult()) { -created = ((CreateAnswer)answer).getVolume(); -break; -} - -volume.setPoolId(null); -_volsDao.persist(volume); - -s_logger.debug("Retrying the create because it failed on pool " + pool); -} - -if (created == null) { -if (s_logger.isDebugEnabled()) { -s_logger.debug("Unable to create a volume for " + volume); -} -volume.setStatus(AsyncInstanceCreateStatus.Failed); -volume.setDestroyed(true); -_volsDao.persist(volume); - -return null; -} - -volume.setStatus(AsyncInstanceCreateStatus.Created); -volume.setFolder(pool.getPath()); -volume.setPath(created.getPath()); -volume.setSize(created.getSize()); -volume.setPoolType(pool.getPoolType()); -volume.setPodId(pod.getId()); -_volsDao.persist(volume); -return volume; - */ - + public void release(VirtualMachineProfile profile) { + // Right now we don't do anything. } } diff --git a/server/src/com/cloud/vm/MauriceMoss.java b/server/src/com/cloud/vm/MauriceMoss.java index 2036c9d9b18..ae1019b76a8 100644 --- a/server/src/com/cloud/vm/MauriceMoss.java +++ b/server/src/com/cloud/vm/MauriceMoss.java @@ -170,47 +170,6 @@ public class MauriceMoss implements VmManager { return allocate(vm, template, serviceOffering, new Pair(serviceOffering, null), null, networks, plan, owner); } - protected VirtualMachineProfile create(VirtualMachineProfile vmProfile, DeploymentPlan plan) throws InsufficientCapacityException { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creating actual resources for VM " + vmProfile); - } - - Journal journal = new Journal.LogJournal("Creating " + vmProfile, s_logger); - - Set avoids = new HashSet(); - int retry = _retry; - while (_retry-- > 0) { - DeployDestination context = null; - for (DeploymentPlanner dispatcher : _planners) { - context = dispatcher.plan(vmProfile, plan, avoids); - if (context != null) { - journal.record("Deployment found ", vmProfile, context); - break; - } - } - - if (context == null) { - throw new CloudRuntimeException("Unable to create a deployment for " + vmProfile); - } - - VMInstanceVO vm = _vmDao.findById(vmProfile.getId()); - - vm.setDataCenterId(context.getDataCenter().getId()); - vm.setPodId(context.getPod().getId()); - vm.setHostId(context.getHost().getId()); - _vmDao.update(vm.getId(), vm); - - _networkMgr.create(vm); - _storageMgr.create(vm); - } - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creation complete for VM " + vmProfile); - } - - return vmProfile; - } - @Override public void destroy() { // TODO Auto-generated method stub @@ -293,7 +252,6 @@ public class MauriceMoss implements VmManager { vm.setDataCenterId(dest.getDataCenter().getId()); vm.setPodId(dest.getPod().getId()); _vmDao.updateIf(vm, Event.OperationRetry, dest.getHost().getId()); - VirtualMachineTO vmTO = new VirtualMachineTO(vmProfile, bt); VolumeTO[] volumes = null; @@ -317,11 +275,13 @@ public class MauriceMoss implements VmManager { Start2Command cmd = new Start2Command(vmTO); try { Start2Answer answer = (Start2Answer)_agentMgr.send(dest.getHost().getId(), cmd); - if (!answer.getResult()) { - s_logger.info("Unable to start VM on " + dest.getHost() + " due to " + answer.getDetails()); - continue; + if (answer.getResult()) { + if (!_vmDao.updateIf(vm, Event.OperationSucceeded, dest.getHost().getId())) { + throw new CloudRuntimeException("Unable to transition to a new state."); + } + return vm; } - _vmDao.updateIf(vm, Event.OperationSucceeded, dest.getHost().getId()); + s_logger.info("Unable to start VM on " + dest.getHost() + " due to " + answer.getDetails()); } catch (AgentUnavailableException e) { s_logger.debug("Unable to send the start command to host " + dest.getHost()); continue; diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 8cfe9c1571b..eaaffefc8a8 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -104,6 +104,7 @@ CREATE TABLE `cloud`.`network_configurations` ( `data_center_id` bigint unsigned NOT NULL COMMENT 'data center id that this configuration is used in', `guru_name` varchar(255) NOT NULL COMMENT 'who is responsible for this type of network configuration', `state` varchar(32) NOT NULL COMMENT 'what state is this configuration in', + `mac_address_seq` bigint unsigned DEFAULT 1 COMMENT 'mac address seq number', `dns` varchar(255) COMMENT 'comma separated DNS list', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;