diff --git a/api/src/com/cloud/vm/NetworkConcierge.java b/api/src/com/cloud/vm/NetworkConcierge.java index 6611466e0f6..96dd78d3e7b 100644 --- a/api/src/com/cloud/vm/NetworkConcierge.java +++ b/api/src/com/cloud/vm/NetworkConcierge.java @@ -23,7 +23,7 @@ public interface NetworkConcierge extends Concierge { boolean create(Nic nic) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException; - String reserve(long vmId, NicProfile ch, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException; + String reserve(VirtualMachine vm, NicProfile ch, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException; boolean release(String uniqueName, String uniqueId); } diff --git a/api/src/com/cloud/vm/VirtualMachine.java b/api/src/com/cloud/vm/VirtualMachine.java index 6594f9a2d38..1984f83eac6 100755 --- a/api/src/com/cloud/vm/VirtualMachine.java +++ b/api/src/com/cloud/vm/VirtualMachine.java @@ -19,11 +19,14 @@ package com.cloud.vm; import java.util.Date; +import com.cloud.domain.PartOf; +import com.cloud.user.OwnedBy; + /** * VirtualMachine describes the properties held by a virtual machine * */ -public interface VirtualMachine extends RunningOn { +public interface VirtualMachine extends RunningOn, OwnedBy, PartOf { public enum Event { CreateRequested, StartRequested, diff --git a/core/src/com/cloud/vm/ConsoleProxyVO.java b/core/src/com/cloud/vm/ConsoleProxyVO.java index 25e3defeeb5..c2e13672b0f 100644 --- a/core/src/com/cloud/vm/ConsoleProxyVO.java +++ b/core/src/com/cloud/vm/ConsoleProxyVO.java @@ -97,13 +97,14 @@ public class ConsoleProxyVO extends VMInstanceVO implements ConsoleProxy { /** * Correct constructor to use. */ - public ConsoleProxyVO(long id, String name, long templateId, long guestOSId, long dataCenterId, int activeSession) { - super(id, name, name, Type.ConsoleProxy, templateId, guestOSId, false); + public ConsoleProxyVO(long id, long serviceOfferingId, String name, long templateId, long guestOSId, long dataCenterId, long domainId, long accountId, int activeSession) { + super(id, serviceOfferingId, name, name, Type.ConsoleProxy, templateId, guestOSId, domainId, accountId, false); this.activeSession = activeSession; } public ConsoleProxyVO( - long id, + long id, + long serviceOfferingId, String name, String guestMacAddress, String guestIpAddress, @@ -119,7 +120,9 @@ public class ConsoleProxyVO extends VMInstanceVO implements ConsoleProxy { Long vlanDbId, String vlanId, long podId, - long dataCenterId, + long dataCenterId, + long domainId, + long accountId, String gateway, Long hostId, String dns1, @@ -127,8 +130,8 @@ public class ConsoleProxyVO extends VMInstanceVO implements ConsoleProxy { String domain, int ramSize, int activeSession) { - super(id, name, name, Type.ConsoleProxy, templateId, guestOSId, - privateMacAddress, privateIpAddress, privateNetmask, dataCenterId, podId, true, hostId); + super(id, serviceOfferingId, name, name, Type.ConsoleProxy, templateId, guestOSId, + privateMacAddress, privateIpAddress, privateNetmask, dataCenterId, podId, domainId, accountId, true, hostId); this.gateway = gateway; this.publicIpAddress = publicIpAddress; this.publicNetmask = publicNetmask; diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index 13f6c94c939..12f4cafb1cb 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -35,12 +35,6 @@ import com.cloud.utils.net.NetUtils; @PrimaryKeyJoinColumn(name="id") @DiscriminatorValue(value="DomainRouter") public class DomainRouterVO extends VMInstanceVO implements DomainRouter { - @Column(name="account_id", updatable=false, nullable=false) - private long accountId = -1; - - @Column(name="domain_id", updatable=false, nullable=false) - private long domainId = 0; - @Column(name="ram_size", updatable=false, nullable=false) private int ramSize; @@ -94,6 +88,7 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { private Role role = Role.DHCP_FIREWALL_LB_PASSWD_USERDATA; public DomainRouterVO(long id, + long serviceOfferingId, String name, String instanceName, String privateMacAddress, @@ -120,7 +115,7 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { Long hostId, String dns1, String dns2) { - super(id, name, instanceName, Type.DomainRouter, templateId, guestOSId, privateMacAddress, privateIpAddress, privateNetmask, dataCenterId, podId, true, hostId); + super(id, serviceOfferingId, name, instanceName, Type.DomainRouter, templateId, guestOSId, privateMacAddress, privateIpAddress, privateNetmask, dataCenterId, podId, domainId, accountId, true, hostId); this.privateMacAddress = privateMacAddress; this.guestMacAddress = guestMacAddress; this.guestIpAddress = guestIpAddress; @@ -142,6 +137,7 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { } public DomainRouterVO(long id, + long serviceOfferingId, String name, String privateMacAddress, String privateIpAddress, @@ -164,15 +160,7 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { String domain, String dns1, String dns2) { - this(id, name, name, privateMacAddress, privateIpAddress, privateNetmask, templateId, guestOSId, guestMacAddress, guestIpAddress, guestNetmask, null, accountId, domainId, publicMacAddress, publicIpAddress, publicNetMask, vlanDbId, vlanId, podId, dataCenterId, ramSize, gateway, domain, null, dns1, dns2); - } - - public long getAccountId() { - return accountId; - } - - public long getDomainId() { - return domainId; + this(id, serviceOfferingId, name, name, privateMacAddress, privateIpAddress, privateNetmask, templateId, guestOSId, guestMacAddress, guestIpAddress, guestNetmask, null, accountId, domainId, publicMacAddress, publicIpAddress, publicNetMask, vlanDbId, vlanId, podId, dataCenterId, ramSize, gateway, domain, null, dns1, dns2); } public void setGateway(String gateway) { @@ -319,6 +307,7 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { this.zoneVlan = zoneVlan; } + @Override public String getZoneVlan() { return zoneVlan; } @@ -327,6 +316,7 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { this.guestZoneMacAddress = guestZoneMacAddress; } + @Override public String getGuestZoneMacAddress() { return guestZoneMacAddress; } diff --git a/core/src/com/cloud/vm/SecondaryStorageVmVO.java b/core/src/com/cloud/vm/SecondaryStorageVmVO.java index 716af5b9fb0..320c808608c 100644 --- a/core/src/com/cloud/vm/SecondaryStorageVmVO.java +++ b/core/src/com/cloud/vm/SecondaryStorageVmVO.java @@ -89,7 +89,8 @@ public class SecondaryStorageVmVO extends VMInstanceVO implements SecondaryStora public SecondaryStorageVmVO( - long id, + long id, + long serviceOfferingId, String name, String guestMacAddress, String guestIpAddress, @@ -105,7 +106,9 @@ public class SecondaryStorageVmVO extends VMInstanceVO implements SecondaryStora Long vlanDbId, String vlanId, long podId, - long dataCenterId, + long dataCenterId, + long domainId, + long accountId, String gateway, Long hostId, String dns1, @@ -114,8 +117,8 @@ public class SecondaryStorageVmVO extends VMInstanceVO implements SecondaryStora int ramSize, String guid, String nfsShare) { - super(id, name, name, Type.SecondaryStorageVm, templateId, guestOSId, - privateMacAddress, privateIpAddress, privateNetmask, dataCenterId, podId, true, hostId); + super(id, serviceOfferingId, name, name, Type.SecondaryStorageVm, templateId, guestOSId, + privateMacAddress, privateIpAddress, privateNetmask, dataCenterId, podId, domainId, accountId, true, hostId); this.gateway = gateway; this.publicIpAddress = publicIpAddress; this.publicNetmask = publicNetmask; diff --git a/core/src/com/cloud/vm/UserVmVO.java b/core/src/com/cloud/vm/UserVmVO.java index 6ab4f55f2e4..56aca34e6b4 100755 --- a/core/src/com/cloud/vm/UserVmVO.java +++ b/core/src/com/cloud/vm/UserVmVO.java @@ -31,12 +31,6 @@ import com.cloud.uservm.UserVm; @PrimaryKeyJoinColumn(name="id") public class UserVmVO extends VMInstanceVO implements UserVm { - @Column(name="account_id", updatable=false, nullable=false) - private long accountId = -1; - - @Column(name="domain_id", updatable=false, nullable=false) - private long domainId = -1; - @Column(name="domain_router_id", updatable=true, nullable=true) Long domainRouterId; @@ -74,15 +68,6 @@ public class UserVmVO extends VMInstanceVO implements UserVm { private String displayName; @Override - public long getAccountId() { - return accountId; - } - - @Override - public long getDomainId() { - return domainId; - } - public String getGuestIpAddress() { return guestIpAddress; } @@ -92,7 +77,8 @@ public class UserVmVO extends VMInstanceVO implements UserVm { setPrivateIpAddress(guestIpAddress); } - public String getGuestMacAddress() { + @Override + public String getGuestMacAddress() { return guestMacAddress; } @@ -153,7 +139,7 @@ public class UserVmVO extends VMInstanceVO implements UserVm { long accountId, long serviceOfferingId, String userData) { - super(id, displayName, instanceName, Type.User, templateId, guestOsId, haEnabled); + super(id, serviceOfferingId, displayName, instanceName, Type.User, templateId, guestOsId, domainId, accountId, haEnabled); this.userData = userData; this.displayName = displayName; @@ -178,11 +164,8 @@ public class UserVmVO extends VMInstanceVO implements UserVm { boolean haEnabled, String displayName, String userData) { - super(id, name, name, Type.User, templateId, guestOSId, guestMacAddress, guestIpAddress, guestNetMask, dcId, podId, haEnabled, null); - this.serviceOfferingId = serviceOfferingId; + super(id, serviceOfferingId, name, name, Type.User, templateId, guestOSId, guestMacAddress, guestIpAddress, guestNetMask, dcId, podId, domainId, accountId, haEnabled, null); this.domainRouterId = routerId; - this.accountId = accountId; - this.domainId = domainId; this.guestIpAddress = guestIpAddress; this.guestNetmask = guestNetMask; this.guestMacAddress = guestMacAddress; diff --git a/core/src/com/cloud/vm/VMInstanceVO.java b/core/src/com/cloud/vm/VMInstanceVO.java index 6b109c1ad95..640dbc10926 100644 --- a/core/src/com/cloud/vm/VMInstanceVO.java +++ b/core/src/com/cloud/vm/VMInstanceVO.java @@ -125,13 +125,24 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject context = createProxyInstance(dataCenterId); + Map context = createProxyInstance2(dataCenterId); long proxyVmId = (Long) context.get("proxyVmId"); if (proxyVmId == 0) { @@ -884,7 +884,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 = createProxyInstance(dataCenterId); + Map context = createProxyInstance2(dataCenterId); long proxyVmId = (Long) context.get("proxyVmId"); if (proxyVmId == 0) { @@ -979,13 +979,15 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach String vlanGateway = publicIpAndVlan._gateWay; String vlanNetmask = publicIpAndVlan._netMask; + + AccountVO systemAccount = _accountMgr.getSystemAccount(); txn.start(); ConsoleProxyVO proxy; String name = VirtualMachineName.getConsoleProxyName(id, _instance).intern(); - proxy = new ConsoleProxyVO(id, name, guestMacAddress, null, NetUtils.getLinkLocalNetMask(), privateMacAddress, null, cidrNetmask, + proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, guestMacAddress, null, NetUtils.getLinkLocalNetMask(), privateMacAddress, null, cidrNetmask, _template.getId(), _template.getGuestOSId(), publicMacAddress, publicIpAddress, vlanNetmask, publicIpAndVlan._vlanDbId, - publicIpAndVlan._vlanid, pod.first().getId(), dataCenterId, vlanGateway, null, dc.getDns1(), dc.getDns2(), _domain, + publicIpAndVlan._vlanid, pod.first().getId(), dataCenterId, systemAccount.getDomainId(), systemAccount.getId(), vlanGateway, null, dc.getDns1(), dc.getDns2(), _domain, _proxyRamSize, 0); proxy.setLastHostId(pod.second()); @@ -1016,6 +1018,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach long id = _consoleProxyDao.getNextInSequence(Long.class, "id"); String name = VirtualMachineName.getConsoleProxyName(id, _instance); DataCenterVO dc = _dcDao.findById(dataCenterId); + AccountVO systemAcct = _accountMgr.getSystemAccount(); DataCenterDeployment plan = new DataCenterDeployment(dataCenterId, 1); @@ -1024,7 +1027,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach for (NetworkOfferingVO offering : offerings) { profiles.add(_networkMgr.setupNetworkConfiguration(_accountMgr.getSystemAccount(), offering, plan)); } - ConsoleProxyVO proxy = new ConsoleProxyVO(id, name, _template.getId(), _template.getGuestOSId(), dataCenterId, 0); + ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, _template.getId(), _template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), 0); proxy = _consoleProxyDao.persist(proxy); try { VirtualMachineProfile vmProfile = _vmMgr.allocate(proxy, _template, _serviceOffering, profiles, plan, _accountMgr.getSystemAccount()); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 0b0070f648d..ef6ae1733dd 100644 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -427,6 +427,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager router = new DomainRouterVO(id, + _offering.getId(), name, mgmtMacAddress, null, @@ -612,6 +613,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager } router = new DomainRouterVO(id, + _offering.getId(), name, privateMacAddress, null, @@ -2475,7 +2477,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager NetworkConcierge concierge = _networkConcierges.get(nic.getReserver()); nic.setState(Resource.State.Reserving); _nicDao.update(nic.getId(), nic); - concierge.reserve(vmProfile.getId(), toNicProfile(nic), dest); + concierge.reserve(null, toNicProfile(nic), dest); } else { } diff --git a/server/src/com/cloud/network/configuration/ControlNetworkGuru.java b/server/src/com/cloud/network/configuration/ControlNetworkGuru.java index 6daa2b8d035..985e0c365d1 100644 --- a/server/src/com/cloud/network/configuration/ControlNetworkGuru.java +++ b/server/src/com/cloud/network/configuration/ControlNetworkGuru.java @@ -106,9 +106,9 @@ public class ControlNetworkGuru extends AdapterBase implements NetworkGuru, Netw } @Override - public String reserve(long vmId, NicProfile nic, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, + public String reserve(VirtualMachine vm, NicProfile nic, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { - String ip = _dcDao.allocateLinkLocalPrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), vmId); + String ip = _dcDao.allocateLinkLocalPrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), vm.getId()); nic.setIp4Address(ip); nic.setMacAddress("FE:FF:FF:FF:FF:FF"); return Long.toString(nic.getId()); diff --git a/server/src/com/cloud/network/configuration/PodBasedNetworkGuru.java b/server/src/com/cloud/network/configuration/PodBasedNetworkGuru.java index 3b446ccbb9a..7a72cdf0f97 100644 --- a/server/src/com/cloud/network/configuration/PodBasedNetworkGuru.java +++ b/server/src/com/cloud/network/configuration/PodBasedNetworkGuru.java @@ -77,7 +77,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru, Net } @Override - public String reserve(long vmId, NicProfile nic, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, + public String reserve(VirtualMachine vm, NicProfile nic, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { Pod pod = dest.getPod(); String ip = _dcDao.allocatePrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), nic.getId()); diff --git a/server/src/com/cloud/network/configuration/PublicNetworkGuru.java b/server/src/com/cloud/network/configuration/PublicNetworkGuru.java index 64e2aa7519c..9a247040312 100644 --- a/server/src/com/cloud/network/configuration/PublicNetworkGuru.java +++ b/server/src/com/cloud/network/configuration/PublicNetworkGuru.java @@ -5,9 +5,15 @@ package com.cloud.network.configuration; import javax.ejb.Local; +import org.apache.log4j.Logger; + +import com.cloud.dc.Vlan.VlanType; +import com.cloud.dc.VlanVO; import com.cloud.dc.dao.DataCenterDao; +import com.cloud.dc.dao.VlanDao; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; +import com.cloud.domain.DomainVO; import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientVirtualNetworkCapcityException; import com.cloud.network.Network.BroadcastDomainType; @@ -17,6 +23,7 @@ import com.cloud.network.NetworkConfiguration; import com.cloud.network.NetworkConfigurationVO; import com.cloud.offering.NetworkOffering; import com.cloud.user.Account; +import com.cloud.utils.Pair; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.Inject; import com.cloud.utils.exception.CloudRuntimeException; @@ -27,7 +34,10 @@ import com.cloud.vm.VirtualMachine; @Local(value={NetworkGuru.class, NetworkConcierge.class}) public class PublicNetworkGuru extends AdapterBase implements NetworkGuru, NetworkConcierge { + private static final Logger s_logger = Logger.getLogger(PublicNetworkGuru.class); + @Inject DataCenterDao _dcDao; + @Inject VlanDao _vlanDao; @Override public NetworkConfiguration design(NetworkOffering offering, DeploymentPlan plan, NetworkConfiguration config, Account owner) { @@ -67,10 +77,25 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru, Netwo } @Override - public String reserve(long vmId, NicProfile ch, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, - InsufficientAddressCapacityException { - - return null; + public String reserve(VirtualMachine vm, NicProfile ch, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { + long dcId = dest.getDataCenter().getId(); + long podId = dest.getPod().getId(); + + Pair ipAndVlan = _vlanDao.assignIpAddress(dcId, vm.getAccountId(), vm.getDomainId(), VlanType.VirtualNetwork, true); + + if (ipAndVlan == null) { + s_logger.debug("Unable to get public ip address (type=Virtual) for console proxy vm for data center : " + dcId); + ipAndVlan = _vlanDao.assignPodDirectAttachIpAddress(dcId, podId, Account.ACCOUNT_ID_SYSTEM, DomainVO.ROOT_DOMAIN); + if (ipAndVlan == null) + s_logger.debug("Unable to get public ip address (type=DirectAttach) for console proxy vm for data center : " + dcId); + } + if (ipAndVlan != null) { + VlanVO vlan = ipAndVlan.second(); + return null; +// networkInfo net = new networkInfo(ipAndVlan.first(), vlan.getVlanNetmask(), vlan.getVlanGateway(), vlan.getId(), vlan.getVlanId()); + // return net; + } + return null; } @Override @@ -80,8 +105,6 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru, Netwo @Override public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination) { - - // TODO Auto-generated method stub - return null; + return config; } } diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 526132cd3bb..9073529922c 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -59,8 +59,8 @@ import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; -import com.cloud.dc.VlanVO; import com.cloud.dc.Vlan.VlanType; +import com.cloud.dc.VlanVO; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.VlanDao; @@ -83,19 +83,18 @@ import com.cloud.info.RunningHostCountInfo; import com.cloud.info.RunningHostInfoAgregator; import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo; import com.cloud.network.IpAddrAllocator; -import com.cloud.network.NetworkManager; import com.cloud.network.IpAddrAllocator.networkInfo; +import com.cloud.network.NetworkManager; import com.cloud.network.dao.IPAddressDao; import com.cloud.offering.NetworkOffering; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePoolVO; import com.cloud.storage.VMTemplateHostVO; +import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VolumeVO; -import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.storage.dao.VMTemplateDao; @@ -103,6 +102,7 @@ import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.storage.template.TemplateConstants; import com.cloud.user.Account; +import com.cloud.user.AccountManager; import com.cloud.user.AccountVO; import com.cloud.user.User; import com.cloud.user.dao.AccountDao; @@ -123,9 +123,9 @@ import com.cloud.utils.net.NetUtils; import com.cloud.vm.SecondaryStorageVmVO; import com.cloud.vm.State; import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.Event; import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.VirtualMachineName; -import com.cloud.vm.VirtualMachine.Event; import com.cloud.vm.dao.SecondaryStorageVmDao; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.VMInstanceDao; @@ -204,6 +204,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V @Inject private ConfigurationDao _configDao; @Inject private EventDao _eventDao; @Inject private ServiceOfferingDao _offeringDao; + @Inject private AccountManager _accountMgr; private IpAddrAllocator _IpAllocator; @@ -525,7 +526,8 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V return null; } - public boolean generateFirewallConfiguration(Long hostId){ + @Override + public boolean generateFirewallConfiguration(Long hostId){ if (hostId == null) { return true; } @@ -740,14 +742,15 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V String vlanGateway = publicIpAndVlan._gateWay; String vlanNetmask = publicIpAndVlan._netMask; + AccountVO systemAcct = _accountMgr.getSystemAccount(); txn.start(); SecondaryStorageVmVO secStorageVm; String name = VirtualMachineName.getSystemVmName(id, _instance, "s").intern(); - secStorageVm = new SecondaryStorageVmVO(id, name, guestMacAddress, null, NetUtils.getLinkLocalNetMask(), + secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, guestMacAddress, null, NetUtils.getLinkLocalNetMask(), privateMacAddress, null, cidrNetmask, _template.getId(), _template.getGuestOSId(), publicMacAddress, publicIpAddress, vlanNetmask, publicIpAndVlan._vlanDbId, publicIpAndVlan._vlanid, - pod.first().getId(), dataCenterId, vlanGateway, null, + pod.first().getId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), vlanGateway, null, dc.getInternalDns1(), dc.getInternalDns2(), _domain, _secStorageVmRamSize, secHost.getGuid(), secHost.getStorageUrl()); secStorageVm.setLastHostId(pod.second()); diff --git a/setup/db/create-index-fk.sql b/setup/db/create-index-fk.sql index 66ab9628e48..e37cadaca1b 100755 --- a/setup/db/create-index-fk.sql +++ b/setup/db/create-index-fk.sql @@ -119,6 +119,8 @@ ALTER TABLE `cloud`.`vm_instance` ADD INDEX `i_vm_instance__last_host_id`(`last_ ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `fk_vm_instance__template_id` FOREIGN KEY `fk_vm_instance__template_id` (`vm_template_id`) REFERENCES `vm_template` (`id`); ALTER TABLE `cloud`.`vm_instance` ADD INDEX `i_vm_instance__template_id`(`vm_template_id`); +ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `fk_vm_instance__account_id` FOREIGN KEY `fk_vm_instance__account_id` (`account_id`) REFERENCES `account` (`id`); +ALTER TABLE `cloud`.`vm_instance` ADD INDEX `i_vm_instance__account_id`(`account_id`); ALTER TABLE `cloud`.`service_offering` ADD CONSTRAINT `fk_service_offering__id` FOREIGN KEY `fk_service_offering__id`(`id`) REFERENCES `disk_offering`(`id`) ON DELETE CASCADE; @@ -127,8 +129,6 @@ ALTER TABLE `cloud`.`user_vm` ADD INDEX `i_user_vm__domain_router_id`(`domain_ro ALTER TABLE `cloud`.`user_vm` ADD CONSTRAINT `fk_user_vm__service_offering_id` FOREIGN KEY `fk_user_vm__service_offering_id` (`service_offering_id`) REFERENCES `service_offering` (`id`); ALTER TABLE `cloud`.`user_vm` ADD INDEX `i_user_vm__service_offering_id`(`service_offering_id`); ALTER TABLE `cloud`.`user_vm` ADD CONSTRAINT `fk_user_vm__id` FOREIGN KEY `fk_user_vm__id` (`id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE; -ALTER TABLE `cloud`.`user_vm` ADD CONSTRAINT `fk_user_vm__account_id` FOREIGN KEY `fk_user_vm__account_id` (`account_id`) REFERENCES `account` (`id`); -ALTER TABLE `cloud`.`user_vm` ADD INDEX `i_user_vm__account_id`(`account_id`); ALTER TABLE `cloud`.`user_vm` ADD CONSTRAINT `fk_user_vm__external_ip_address` FOREIGN KEY `fk_user_vm__external_ip_address` (`external_ip_address`) REFERENCES `user_ip_address` (`public_ip_address`); ALTER TABLE `cloud`.`user_vm` ADD INDEX `i_user_vm__external_ip_address`(`external_ip_address`); ALTER TABLE `cloud`.`user_vm` ADD CONSTRAINT `fk_user_vm__external_vlan_db_id` FOREIGN KEY `fk_user_vm__external_vlan_db_id` (`external_vlan_db_id`) REFERENCES `vlan` (`id`); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 9878ac4cd11..f5e1c510304 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -539,26 +539,6 @@ CREATE TABLE `cloud`.`vm_template` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `cloud`.`vm_instance2` ( - `id` bigint unsigned UNIQUE NOT NULL, - `instance_name` varchar(255) NOT NULL COMMENT 'name of the vm instance running on the hosts', - `state` varchar(32) NOT NULL, - `update_count` bigint unsigned NOT NULL DEFAULT 0 COMMENT 'date state was updated', - `vm_template_id` bigint unsigned, - `guest_os_id` bigint unsigned NOT NULL, - `host_id` bigint unsigned, - `last_host_id` bigint unsigned COMMENT 'tentative host for first run or last host that it has been running on', - `proxy_id` bigint unsigned NULL COMMENT 'console proxy allocated in previous session', - `proxy_assign_time` DATETIME NULL COMMENT 'time when console proxy was assigned', - `vnc_password` varchar(255) NOT NULL COMMENT 'vnc password', - `ha_enabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Should HA be enabled for this VM', - `update_time` datetime COMMENT 'date the destroy was requested', - `created` datetime NOT NULL COMMENT 'date created', - `removed` datetime COMMENT 'date removed if not null', - `type` varchar(32) NOT NULL COMMENT 'type of vm it is', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - CREATE TABLE `cloud`.`vm_instance` ( `id` bigint unsigned UNIQUE NOT NULL, `name` varchar(255) NOT NULL, @@ -583,6 +563,9 @@ CREATE TABLE `cloud`.`vm_instance` ( `created` datetime NOT NULL COMMENT 'date created', `removed` datetime COMMENT 'date removed if not null', `type` varchar(32) NOT NULL COMMENT 'type of vm it is', + `account_id` bigint unsigned NOT NULL COMMENT 'user id of owner', + `domain_id` bigint unsigned NOT NULL, + `service_offering_id` bigint unsigned NOT NULL COMMENT 'service offering id', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -593,8 +576,6 @@ CREATE TABLE `cloud`.`user_vm` ( `domain_router_id` bigint unsigned COMMENT 'router id', `vnet` varchar(18) COMMENT 'vnet', `dc_vlan` varchar(18) COMMENT 'zone vlan', - `account_id` bigint unsigned NOT NULL COMMENT 'user id of owner', - `domain_id` bigint unsigned NOT NULL, `guest_ip_address` varchar(15) COMMENT 'ip address within the guest network', `guest_mac_address` varchar(17) COMMENT 'mac address within the guest network', `guest_netmask` varchar(15) COMMENT 'netmask within the guest network', @@ -602,7 +583,6 @@ CREATE TABLE `cloud`.`user_vm` ( `external_mac_address` varchar(17) COMMENT 'mac address within the external network', `external_vlan_db_id` bigint unsigned COMMENT 'foreign key into vlan table', `user_data` varchar(2048), - `service_offering_id` bigint unsigned NOT NULL COMMENT 'service offering id', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;