diff --git a/api/src/com/cloud/offering/NetworkOffering.java b/api/src/com/cloud/offering/NetworkOffering.java index 72e2a2bbbab..5f522ebff6a 100644 --- a/api/src/com/cloud/offering/NetworkOffering.java +++ b/api/src/com/cloud/offering/NetworkOffering.java @@ -16,8 +16,6 @@ // under the License. package com.cloud.offering; -import java.util.Map; - import org.apache.cloudstack.acl.InfrastructureEntity; import org.apache.cloudstack.api.Identity; import org.apache.cloudstack.api.InternalIdentity; @@ -61,6 +59,8 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity, public final static String DefaultSharedEIPandELBNetworkOffering = "DefaultSharedNetscalerEIPandELBNetworkOffering"; public final static String DefaultIsolatedNetworkOfferingForVpcNetworks = "DefaultIsolatedNetworkOfferingForVpcNetworks"; public final static String DefaultIsolatedNetworkOfferingForVpcNetworksNoLB = "DefaultIsolatedNetworkOfferingForVpcNetworksNoLB"; + public final static String DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB = "DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB"; + /** * @return name for the network offering. diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java index f2dd3499b84..0417b187e38 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java @@ -70,9 +70,6 @@ public class ListClustersCmd extends BaseListCmd { @Parameter(name=ApiConstants.MANAGED_STATE, type=CommandType.STRING, description="whether this cluster is managed by cloudstack") private String managedState; - @Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to") - private String zoneType; - @Parameter(name=ApiConstants.SHOW_CAPACITIES, type=CommandType.BOOLEAN, description="flag to display the capacity of the clusters") private Boolean showCapacities; @@ -117,10 +114,7 @@ public class ListClustersCmd extends BaseListCmd { this.managedState = managedstate; } - public String getZoneType() { - return zoneType; - } - + public Boolean getShowCapacities() { return showCapacities; } diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java index b2d77b85dd2..e902e650332 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java @@ -70,13 +70,12 @@ public class FindHostsForMigrationCmd extends BaseListCmd { public void execute() { ListResponse response = null; Pair,Integer> result; - List hostsWithCapacity = new ArrayList(); Map hostsRequiringStorageMotion; Ternary,Integer>, List, Map> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), this.getStartIndex(), this.getPageSizeVal()); result = hostsForMigration.first(); - hostsWithCapacity = hostsForMigration.second(); + List hostsWithCapacity = hostsForMigration.second(); hostsRequiringStorageMotion = hostsForMigration.third(); response = new ListResponse(); diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java index eaaec3091a7..1e378fae464 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java @@ -171,11 +171,10 @@ public class ListHostsCmd extends BaseListCmd { response = _queryService.searchForServers(this); } else { Pair,Integer> result; - List hostsWithCapacity = new ArrayList(); Ternary,Integer>, List, Map> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), this.getStartIndex(), this.getPageSizeVal()); result = hostsForMigration.first(); - hostsWithCapacity = hostsForMigration.second(); + List hostsWithCapacity = hostsForMigration.second(); response = new ListResponse(); List hostResponses = new ArrayList(); diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java index 6410715727c..febb0c337eb 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java @@ -95,7 +95,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd { @Parameter(name=ApiConstants.IS_PERSISTENT, type=CommandType.BOOLEAN, description="true if network offering supports persistent networks; defaulted to false if not specified") private Boolean isPersistent; - @Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, since="4.2.0", description="Template details in key/value pairs." + + @Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, since="4.2.0", description="Network offering details in key/value pairs." + " Supported keys are internallbprovider/publiclbprovider with service provider as a value") protected Map details; diff --git a/api/src/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java b/api/src/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java index db233ae441e..3dace4244ae 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java @@ -55,9 +55,6 @@ public class ListPodsByCmd extends BaseListCmd { @Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="list pods by allocation state") private String allocationState; - @Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to") - private String zoneType; - @Parameter(name=ApiConstants.SHOW_CAPACITIES, type=CommandType.BOOLEAN, description="flag to display the capacity of the pods") private Boolean showCapacities; @@ -81,10 +78,6 @@ public class ListPodsByCmd extends BaseListCmd { return allocationState; } - public String getZoneType() { - return zoneType; - } - public Boolean getShowCapacities() { return showCapacities; } diff --git a/api/src/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java b/api/src/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java index 75bcce00acf..1f77c2c5164 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java @@ -81,9 +81,8 @@ public class ListPortableIpRangesCmd extends BaseListCmd { public void execute(){ ListResponse response = new ListResponse(); List responses = new ArrayList(); - List portableIpRanges = new ArrayList(); - portableIpRanges = _configService.listPortableIpRanges(this); + List portableIpRanges = _configService.listPortableIpRanges(this); if (portableIpRanges != null && !portableIpRanges.isEmpty()) { for (PortableIpRange range : portableIpRanges) { PortableIpRangeResponse rangeResponse = _responseGenerator.createPortableIPRangeResponse(range); diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java index b5a0f3fdd4d..f230a20d513 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java @@ -74,9 +74,6 @@ public class ListSystemVMsCmd extends BaseListCmd { description="the storage ID where vm's volumes belong to", since="3.0.1") private Long storageId; - @Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to") - private String zoneType; - ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -113,10 +110,6 @@ public class ListSystemVMsCmd extends BaseListCmd { return storageId; } - public String getZoneType() { - return zoneType; - } - ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java index f872c120074..9e6abec74e2 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java @@ -78,9 +78,6 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd { description="the ID of the zone") private Long zoneId; - @Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to") - private String zoneType; - ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -118,10 +115,6 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd { return zoneId; } - public String getZoneType() { - return zoneType; - } - public boolean listInReadyState() { Account account = UserContext.current().getCaller(); // It is account specific if account is admin type and domainId and accountName are not null @@ -160,8 +153,7 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd { List templateResponses = new ArrayList(); for (Pair iso : isoZonePairSet) { - List responses = new ArrayList(); - responses = _responseGenerator.createIsoResponses(iso.first(), iso.second(), listInReadyState()); + List responses = _responseGenerator.createIsoResponses(iso.first(), iso.second(), listInReadyState()); templateResponses.addAll(responses); } response.setResponses(templateResponses); diff --git a/api/src/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java index d25e2c05597..afce0926e4d 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java @@ -48,9 +48,6 @@ public class ListNetworksCmd extends BaseListTaggedResourcesCmd { description="the Zone ID of the network") private Long zoneId; - @Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to") - private String zoneType; - @Parameter(name=ApiConstants.TYPE, type=CommandType.STRING, description="the type of the network. Supported values are: Isolated and Shared") private String guestIpType; @@ -99,10 +96,6 @@ public class ListNetworksCmd extends BaseListTaggedResourcesCmd { return zoneId; } - public String getZoneType() { - return zoneType; - } - public String getGuestIpType() { return guestIpType; } diff --git a/api/src/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java b/api/src/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java index e4ae76908e8..8859ba53c53 100644 --- a/api/src/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java @@ -59,13 +59,11 @@ public class ListSnapshotsCmd extends BaseListTaggedResourcesCmd { @Parameter(name=ApiConstants.VOLUME_ID, type=CommandType.UUID, entityType = VolumeResponse.class, description="the ID of the disk volume") private Long volumeId; - - @Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to") - private String zoneType; @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "list snapshots by zone id") private Long zoneId; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -90,14 +88,10 @@ public class ListSnapshotsCmd extends BaseListTaggedResourcesCmd { return volumeId; } - public String getZoneType() { - return zoneType; - } - public Long getZoneId() { return zoneId; - } - + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java index f0fc24153f6..dc94d676661 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java @@ -68,10 +68,6 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd { @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class, description="list templates by zoneId") private Long zoneId; - - @Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to") - private String zoneType; - ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -96,10 +92,6 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd { return zoneId; } - public String getZoneType() { - return zoneType; - } - public boolean listInReadyState() { Account account = UserContext.current().getCaller(); @@ -133,8 +125,7 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd { List templateResponses = new ArrayList(); for (Pair template : templateZonePairSet) { - List responses = new ArrayList(); - responses = _responseGenerator.createTemplateResponses(template.first().longValue(), template.second(), listInReadyState()); + List responses = _responseGenerator.createTemplateResponses(template.first().longValue(), template.second(), listInReadyState()); templateResponses.addAll(responses); } diff --git a/awsapi/web/web.xml b/awsapi/web/web.xml index 7efe43d03f3..5ded12b342f 100644 --- a/awsapi/web/web.xml +++ b/awsapi/web/web.xml @@ -22,16 +22,17 @@ - - - org.springframework.web.context.ContextLoaderListener - + CloudBridge + contextConfigLocation classpath:applicationContext.xml - CloudBridge + + org.springframework.web.context.ContextLoaderListener + + EC2MainServlet EC2 Main Servlet diff --git a/core/src/com/cloud/network/HAProxyConfigurator.java b/core/src/com/cloud/network/HAProxyConfigurator.java index 29fdf4ae256..162571fa689 100644 --- a/core/src/com/cloud/network/HAProxyConfigurator.java +++ b/core/src/com/cloud/network/HAProxyConfigurator.java @@ -33,7 +33,6 @@ import com.cloud.agent.api.to.LoadBalancerTO; import com.cloud.agent.api.to.PortForwardingRuleTO; import com.cloud.agent.api.to.LoadBalancerTO.DestinationTO; import com.cloud.agent.api.to.LoadBalancerTO.StickinessPolicyTO; -import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource; import com.cloud.network.rules.LbStickinessMethod.StickinessMethodType; import com.cloud.utils.net.NetUtils; @@ -41,6 +40,7 @@ import com.cloud.utils.net.NetUtils; public class HAProxyConfigurator implements LoadBalancerConfigurator { private static final Logger s_logger = Logger.getLogger(HAProxyConfigurator.class); + private static final String blankLine = "\t "; private static String[] globalSection = { "global", "\tlog 127.0.0.1:3914 local0 warning", "\tmaxconn 4096", @@ -86,9 +86,9 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { List result = new ArrayList(); result.addAll(Arrays.asList(globalSection)); - result.add(getBlankLine()); + result.add(blankLine); result.addAll(Arrays.asList(defaultsSection)); - result.add(getBlankLine()); + result.add(blankLine); if (pools.isEmpty()) { // haproxy cannot handle empty listen / frontend or backend, so add @@ -96,7 +96,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { // on port 9 result.addAll(Arrays.asList(defaultListen)); } - result.add(getBlankLine()); + result.add(blankLine); for (Map.Entry> e : pools.entrySet()) { List poolRules = getRulesForPool(e.getKey(), e.getValue()); @@ -143,7 +143,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { .append(rule.getDstPortRange()[0]).append(" check"); result.add(sb.toString()); } - result.add(getBlankLine()); + result.add(blankLine); return result; } @@ -507,14 +507,10 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { result.add(sb.toString()); } - result.add(getBlankLine()); + result.add(blankLine); return result; } - private String getBlankLine() { - return new String("\t "); - } - private String generateStatsRule(LoadBalancerConfigCommand lbCmd, String ruleName, String statsIp) { StringBuilder rule = new StringBuilder("\nlisten ").append(ruleName) @@ -534,7 +530,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { List result = new ArrayList(); result.addAll(Arrays.asList(globalSection)); - result.add(getBlankLine()); + result.add(blankLine); result.addAll(Arrays.asList(defaultsSection)); if (!lbCmd.lbStatsVisibility.equals("disabled")) { /* new rule : listen admin_page guestip/link-local:8081 */ @@ -568,7 +564,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { } } - result.add(getBlankLine()); + result.add(blankLine); boolean has_listener = false; for (LoadBalancerTO lbTO : lbCmd.getLoadBalancers()) { if ( lbTO.isRevoked() ) { @@ -578,7 +574,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { result.addAll(poolRules); has_listener = true; } - result.add(getBlankLine()); + result.add(blankLine); if ( !has_listener) { // haproxy cannot handle empty listen / frontend or backend, so add // a dummy listener diff --git a/docs/en-US/Release_Notes.xml b/docs/en-US/Release_Notes.xml index 2ae87320e40..8843f4c2e20 100644 --- a/docs/en-US/Release_Notes.xml +++ b/docs/en-US/Release_Notes.xml @@ -398,7 +398,7 @@ under the License. SSH keypair assigned to a virtual machine. -
+
Issues Fixed in 4.1.0 Apache CloudStack uses Jira to track its issues. All new features and bugs for 4.1.0 have been tracked diff --git a/docs/en-US/configure-package-repository.xml b/docs/en-US/configure-package-repository.xml index c8ba48f2717..cda46773f53 100644 --- a/docs/en-US/configure-package-repository.xml +++ b/docs/en-US/configure-package-repository.xml @@ -44,7 +44,7 @@ DEB package repository You can add a DEB package repository to your apt sources with the following commands. Please note that only packages for Ubuntu 12.04 LTS (precise) are being built at this time. Use your preferred editor and open (or create) /etc/apt/sources.list.d/cloudstack.list. Add the community provided repository to the file: -deb http://cloudstack.apt-get.eu/ubuntu precise 4.0 +deb http://cloudstack.apt-get.eu/ubuntu precise 4.1 We now have to add the public key to the trusted keys. $ wget -O - http://cloudstack.apt-get.eu/release.asc|apt-key add - Now update your local apt cache. @@ -60,7 +60,7 @@ [cloudstack] name=cloudstack -baseurl=http://cloudstack.apt-get.eu/rhel/4.0/ +baseurl=http://cloudstack.apt-get.eu/rhel/4.1/ enabled=1 gpgcheck=0 diff --git a/docs/en-US/management-server-install-db-local.xml b/docs/en-US/management-server-install-db-local.xml index 918cdc0a265..310327fcc75 100644 --- a/docs/en-US/management-server-install-db-local.xml +++ b/docs/en-US/management-server-install-db-local.xml @@ -143,6 +143,14 @@ binlog-format = 'ROW' -i <management_server_ip> When this script is finished, you should see a message like “Successfully initialized the database.” + + If the script is unable to connect to the MySQL database, check + the "localhost" loopback address in /etc/hosts. It should + be pointing to the IPv4 loopback address "127.0.0.1" and not the IPv6 loopback + address ::1. Alternatively, reconfigure MySQL to bind to the IPv6 loopback + interface. + + If you are running the KVM hypervisor on the same machine with the Management Server, diff --git a/docs/pot/configure-package-repository.pot b/docs/pot/configure-package-repository.pot index e91535826a5..c0ee374254a 100644 --- a/docs/pot/configure-package-repository.pot +++ b/docs/pot/configure-package-repository.pot @@ -60,7 +60,7 @@ msgstr "" #. Tag: programlisting #, no-c-format -msgid "deb http://cloudstack.apt-get.eu/ubuntu precise 4.0" +msgid "deb http://cloudstack.apt-get.eu/ubuntu precise 4.1" msgstr "" #. Tag: para @@ -118,7 +118,7 @@ msgstr "" msgid "\n" "[cloudstack]\n" "name=cloudstack\n" -"baseurl=http://cloudstack.apt-get.eu/rhel/4.0/\n" +"baseurl=http://cloudstack.apt-get.eu/rhel/4.1/\n" "enabled=1\n" "gpgcheck=0\n" " " diff --git a/engine/schema/src/com/cloud/dc/dao/DataCenterDao.java b/engine/schema/src/com/cloud/dc/dao/DataCenterDao.java index e54b9bbbe29..ed6e6965312 100755 --- a/engine/schema/src/com/cloud/dc/dao/DataCenterDao.java +++ b/engine/schema/src/com/cloud/dc/dao/DataCenterDao.java @@ -36,7 +36,7 @@ public interface DataCenterDao extends GenericDao { Pair allocatePrivateIpAddress(long id, long podId, long instanceId, String reservationId); DataCenterIpAddressVO allocatePrivateIpAddress(long id, String reservationId); String allocateLinkLocalIpAddress(long id, long podId, long instanceId, String reservationId); - String allocateVnet(long dcId, long physicalNetworkId, long accountId, String reservationId); + String allocateVnet(long dcId, long physicalNetworkId, long accountId, String reservationId, boolean canUseSystemGuestVlans); void releaseVnet(String vnet, long dcId, long physicalNetworkId, long accountId, String reservationId); void releasePrivateIpAddress(String ipAddress, long dcId, Long instanceId); diff --git a/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java index 4d9d01065ca..503306f6722 100755 --- a/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java +++ b/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java @@ -192,22 +192,27 @@ public class DataCenterDaoImpl extends GenericDaoBase implem } @Override - public String allocateVnet(long dataCenterId, long physicalNetworkId, long accountId, String reservationId) { + public String allocateVnet(long dataCenterId, long physicalNetworkId, long accountId, String reservationId, + boolean canUseSystemGuestVlans) { ArrayList dedicatedVlanDbIds = new ArrayList(); + boolean useDedicatedGuestVlans = false; List maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(accountId); for (AccountGuestVlanMapVO map : maps) { dedicatedVlanDbIds.add(map.getId()); } if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) { + useDedicatedGuestVlans = true; DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, dedicatedVlanDbIds); if (vo != null) return vo.getVnet(); } - DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, null); - if (vo == null) { - return null; + if (!useDedicatedGuestVlans || (useDedicatedGuestVlans && canUseSystemGuestVlans)) { + DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, null); + if (vo != null) { + return vo.getVnet(); + } } - return vo.getVnet(); + return null; } @Override diff --git a/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java b/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java index 3ae0bf38b0b..fae315b01a0 100755 --- a/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java @@ -414,4 +414,8 @@ public class NetworkOfferingVO implements NetworkOffering { return publicLb; } + public void setInternalLb(boolean internalLb) { + this.internalLb = internalLb; + } + } diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java index 852075792df..7c66dd4b46b 100755 --- a/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java +++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java @@ -56,7 +56,7 @@ public interface VMTemplateDao extends GenericDao, StateDao< public Set> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List permittedAccounts, Account caller, - ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags, String zoneType); + ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags); public Set> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java index 25ae933740d..d45ef73168b 100755 --- a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java +++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java @@ -521,7 +521,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem public Set> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr,List permittedAccounts, - Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags, String zoneType) { + Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags) { StringBuilder builder = new StringBuilder(); if (!permittedAccounts.isEmpty()) { for (Account permittedAccount : permittedAccounts) { @@ -565,12 +565,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem if ((templateFilter == TemplateFilter.featured) || (templateFilter == TemplateFilter.community)) { dataCenterJoin = " INNER JOIN data_center dc on (h.data_center_id = dc.id)"; } - - if (zoneType != null) { - dataCenterJoin = " INNER JOIN template_host_ref thr on (t.id = thr.template_id) INNER JOIN host h on (thr.host_id = h.id)"; - dataCenterJoin += " INNER JOIN data_center dc on (h.data_center_id = dc.id)"; - } - + if (templateFilter == TemplateFilter.sharedexecutable || templateFilter == TemplateFilter.shared ){ lpjoin = " INNER JOIN launch_permission lp ON t.id = lp.template_id "; } @@ -697,7 +692,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem } sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable, hyperType, zoneId, - onlyReady, showDomr, zoneType) + groupByClause + getOrderByLimit(pageSize, startIndex); + onlyReady, showDomr) + groupByClause + getOrderByLimit(pageSize, startIndex); pstmt = txn.prepareStatement(sql); rs = pstmt.executeQuery(); @@ -758,7 +753,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem return templateZonePairList; } - private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady, boolean showDomr, String zoneType) { + private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady, boolean showDomr) { String sql = ""; if (keyword != null) { sql += " t.name LIKE \"%" + keyword + "%\" AND"; @@ -788,15 +783,11 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem sql += " AND h.data_center_id = " +zoneId; } }else if (zoneId != null){ - sql += " AND tzr.zone_id = " +zoneId+ " AND tzr.removed is null" ; + sql += " AND tzr.zone_id = " +zoneId+ " AND tzr.removed is null" ; }else{ sql += " AND tzr.removed is null "; } - - if (zoneType != null){ - sql += " AND dc.networktype = '" + zoneType + "'"; - } - + if (!showDomr){ sql += " AND t.type != '" +Storage.TemplateType.SYSTEM.toString() + "'"; } diff --git a/engine/storage/src/org/apache/cloudstack/storage/HypervisorHostEndPointRpcServer.java b/engine/storage/src/org/apache/cloudstack/storage/HypervisorHostEndPointRpcServer.java index bc217769d91..060b490e6a8 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/HypervisorHostEndPointRpcServer.java +++ b/engine/storage/src/org/apache/cloudstack/storage/HypervisorHostEndPointRpcServer.java @@ -46,7 +46,7 @@ public class HypervisorHostEndPointRpcServer implements HostEndpointRpcServer { } public HypervisorHostEndPointRpcServer(RpcProvider rpcProvider) { - rpcProvider = rpcProvider; + this.rpcProvider = rpcProvider; rpcProvider.registerRpcServiceEndpoint(RpcServiceDispatcher.getDispatcher(this)); } diff --git a/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java b/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java index e753b131ef7..f660b7c7838 100644 --- a/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java +++ b/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java @@ -162,7 +162,7 @@ public class BigSwitchVnsGuestNetworkGuru extends GuestNetworkGuru { } String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, - network.getAccountId(), context.getReservationId()); + network.getAccountId(), context.getReservationId(), canUseSystemGuestVlan(network.getAccountId())); if (vnet == null) { throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a " + "part of network " + network + " implement ", DataCenter.class, dcId); diff --git a/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java b/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java index 781b4b9b2f2..bbdf1108f90 100644 --- a/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java +++ b/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java @@ -94,7 +94,8 @@ public class OvsGuestNetworkGuru extends GuestNetworkGuru { protected void allocateVnet(Network network, NetworkVO implemented, long dcId, long physicalNetworkId, String reservationId) throws InsufficientVirtualNetworkCapcityException { if (network.getBroadcastUri() == null) { - String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId); + String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, + canUseSystemGuestVlan(network.getAccountId())); if (vnet == null) { throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a part of network " + network + " implement ", DataCenter.class, dcId); } diff --git a/server/src/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java index 6d0cde1ac6b..f2b9525b2cc 100644 --- a/server/src/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java +++ b/server/src/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java @@ -25,6 +25,7 @@ import javax.inject.Inject; import com.cloud.capacity.Capacity; import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType; +import org.apache.commons.lang.ObjectUtils; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -79,17 +80,12 @@ public class StoragePoolJoinDaoImpl extends GenericDaoBase> defaultINetworkOfferingProvidersForVpcNetwork = new HashMap>(); - defaultProviders.clear(); - defaultProviders.add(Network.Provider.VPCVirtualRouter); - defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Dhcp, defaultProviders); - defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Dns, defaultProviders); - defaultINetworkOfferingProvidersForVpcNetwork.put(Service.UserData, defaultProviders); - defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Firewall, defaultProviders); - defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Gateway, defaultProviders); - defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Lb, defaultProviders); - defaultINetworkOfferingProvidersForVpcNetwork.put(Service.SourceNat, defaultProviders); - defaultINetworkOfferingProvidersForVpcNetwork.put(Service.StaticNat, defaultProviders); - defaultINetworkOfferingProvidersForVpcNetwork.put(Service.PortForwarding, defaultProviders); - defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Vpn, defaultProviders); - + //#4 - default isolated offering with Source nat service if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, - null, false, Availability.Required, null, defaultINetworkOfferingProvidersForVpcNetwork, + null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false, false, null); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } + //#5 - default vpc offering with LB service if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks, "Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest, @@ -1352,6 +1353,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L _networkOfferingDao.update(offering.getId(), offering); } + //#6 - default vpc offering with no LB service if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB) == null) { //remove LB service defaultVPCOffProviders.remove(Service.Lb); @@ -1363,6 +1365,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L _networkOfferingDao.update(offering.getId(), offering); } + //#7 - isolated offering with source nat disabled if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true, @@ -1371,6 +1374,33 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } + + //#8 - network offering with internal lb service + Map> internalLbOffProviders = + new HashMap>(); + Set defaultVpcProvider = new HashSet(); + defaultVpcProvider.add(Network.Provider.VPCVirtualRouter); + + Set defaultInternalLbProvider = new HashSet(); + defaultInternalLbProvider.add(Network.Provider.InternalLbVm); + + internalLbOffProviders.put(Service.Dhcp, defaultVpcProvider); + internalLbOffProviders.put(Service.Dns, defaultVpcProvider); + internalLbOffProviders.put(Service.UserData, defaultVpcProvider); + internalLbOffProviders.put(Service.NetworkACL, defaultVpcProvider); + internalLbOffProviders.put(Service.Gateway, defaultVpcProvider); + internalLbOffProviders.put(Service.Lb, defaultInternalLbProvider); + internalLbOffProviders.put(Service.SourceNat, defaultVpcProvider); + + if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB) == null) { + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB, + "Offering for Isolated VPC networks with Internal Lb support", TrafficType.Guest, + null, false, Availability.Optional, null, internalLbOffProviders, + true, Network.GuestType.Isolated, false, null, false, null, false, false, null); + offering.setState(NetworkOffering.State.Enabled); + offering.setInternalLb(true); + _networkOfferingDao.update(offering.getId(), offering); + } Map> netscalerServiceProviders = new HashMap>(); Set vrProvider = new HashSet(); diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java index f026dbc2a32..aace68d9642 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -1355,7 +1355,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { Long id = cmd.getId(); String keyword = cmd.getKeyword(); Long zoneId = cmd.getZoneId(); - String zoneType = cmd.getZoneType(); Account caller = UserContext.current().getCaller(); Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); @@ -1503,40 +1502,40 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { if (!permittedAccounts.isEmpty()) { //get account level networks networksToReturn.addAll(listAccountSpecificNetworks( - buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, - physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, zoneType), searchFilter, + buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, + physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, permittedAccounts)); //get domain level networks if (domainId != null) { networksToReturn .addAll(listDomainLevelNetworks( buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, - physicalNetworkId, aclType, true, restartRequired, specifyIpRanges, vpcId, tags, zoneType), searchFilter, + physicalNetworkId, aclType, true, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, domainId, false)); } } else { //add account specific networks networksToReturn.addAll(listAccountSpecificNetworksByDomainPath( - buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, - physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, zoneType), searchFilter, path, + buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, + physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, path, isRecursive)); //add domain specific networks of domain + parent domains networksToReturn.addAll(listDomainSpecificNetworksByDomainPath( - buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, - physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, zoneType), searchFilter, path, + buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, + physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, path, isRecursive)); //add networks of subdomains if (domainId == null) { networksToReturn .addAll(listDomainLevelNetworks( buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, - physicalNetworkId, aclType, true, restartRequired, specifyIpRanges, vpcId, tags, zoneType), searchFilter, + physicalNetworkId, aclType, true, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, caller.getDomainId(), true)); } } } else { networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, - guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, zoneType), + guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter); } @@ -1581,7 +1580,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { private SearchCriteria buildNetworkSearchCriteria(SearchBuilder sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId, - String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges, Long vpcId, Map tags, String zoneType) { + String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges, Long vpcId, Map tags) { SearchCriteria sc = sb.create(); @@ -1603,10 +1602,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId); } - if(zoneType != null) { - sc.setJoinParameters("zoneSearch", "networkType", zoneType); - } - if (guestIpType != null) { sc.addAnd("guestType", SearchCriteria.Op.EQ, guestIpType); } diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java index eb1b3dc4b24..87098f5049b 100644 --- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java @@ -130,7 +130,8 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { // Get a vlan tag int vlanTag; if (config.getBroadcastUri() == null) { - String vnet = _dcDao.allocateVnet(zone.getId(), config.getPhysicalNetworkId(), config.getAccountId(), context.getReservationId()); + String vnet = _dcDao.allocateVnet(zone.getId(), config.getPhysicalNetworkId(), config.getAccountId(), + context.getReservationId(), canUseSystemGuestVlan(config.getAccountId())); try { vlanTag = Integer.parseInt(vnet); diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index 32ce744979b..89b0694e114 100755 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -26,6 +26,7 @@ import javax.ejb.Local; import javax.inject.Inject; import com.cloud.event.ActionEventUtils; +import com.cloud.server.ConfigurationServer; import com.cloud.utils.Pair; import org.apache.log4j.Logger; @@ -98,6 +99,8 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur IPAddressDao _ipAddressDao; @Inject protected PhysicalNetworkDao _physicalNetworkDao; + @Inject + ConfigurationServer _configServer; Random _rand = new Random(System.currentTimeMillis()); private static final TrafficType[] _trafficTypes = {TrafficType.Guest}; @@ -155,6 +158,11 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur return _isolationMethods; } + public boolean canUseSystemGuestVlan(long accountId) { + return Boolean.parseBoolean(_configServer.getConfigValue(Config.UseSystemGuestVlans.key(), + Config.ConfigurationParameterScope.account.toString(), accountId)); + } + protected abstract boolean canHandle(NetworkOffering offering, final NetworkType networkType, PhysicalNetwork physicalNetwork); @Override @@ -260,7 +268,8 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur protected void allocateVnet(Network network, NetworkVO implemented, long dcId, long physicalNetworkId, String reservationId) throws InsufficientVirtualNetworkCapcityException { if (network.getBroadcastUri() == null) { - String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId); + String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, + canUseSystemGuestVlan(network.getAccountId())); if (vnet == null) { throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a " + "part of network " + network + " implement ", DataCenter.class, dcId); diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index d334d7efb53..510455b5213 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -1151,8 +1151,33 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio _ntwkOfferingServiceMapDao.persist(offService); s_logger.trace("Added service for the network offering: " + offService); } + + //offering #8 - network offering with internal lb service + NetworkOfferingVO internalLbOff = new NetworkOfferingVO( + NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB, + "Offering for Isolated Vpc networks with Internal LB support", + TrafficType.Guest, + false, false, null, null, true, Availability.Optional, + null, Network.GuestType.Isolated, false, false, false, true, false); + internalLbOff.setState(NetworkOffering.State.Enabled); + internalLbOff = _networkOfferingDao.persistDefaultNetworkOffering(internalLbOff); + Map internalLbOffProviders = new HashMap(); + internalLbOffProviders.put(Service.Dhcp, Provider.VPCVirtualRouter); + internalLbOffProviders.put(Service.Dns, Provider.VPCVirtualRouter); + internalLbOffProviders.put(Service.UserData, Provider.VPCVirtualRouter); + internalLbOffProviders.put(Service.NetworkACL, Provider.VPCVirtualRouter); + internalLbOffProviders.put(Service.Gateway, Provider.VPCVirtualRouter); + internalLbOffProviders.put(Service.Lb, Provider.InternalLbVm); + internalLbOffProviders.put(Service.SourceNat, Provider.VPCVirtualRouter); + + for (Service service : internalLbOffProviders.keySet()) { + NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO + (internalLbOff.getId(), service, internalLbOffProviders.get(service)); + _ntwkOfferingServiceMapDao.persist(offService); + s_logger.trace("Added service for the network offering: " + offService); + } txn.commit(); } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 96c72e4a4e2..dea761df5da 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -996,67 +996,46 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public Pair, Integer> searchForClusters(ListClustersCmd cmd) { - Object id = cmd.getId(); + Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); + SearchCriteria sc = _clusterDao.createSearchCriteria(); + + Object id = cmd.getId(); Object name = cmd.getClusterName(); Object podId = cmd.getPodId(); Long zoneId = cmd.getZoneId(); Object hypervisorType = cmd.getHypervisorType(); Object clusterType = cmd.getClusterType(); Object allocationState = cmd.getAllocationState(); - String zoneType = cmd.getZoneType(); String keyword = cmd.getKeyword(); + zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId); - - Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); - - SearchBuilder sb = _clusterDao.createSearchBuilder(); - sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); - sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); - sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ); - sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); - sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ); - sb.and("clusterType", sb.entity().getClusterType(), SearchCriteria.Op.EQ); - sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ); - - if(zoneType != null) { - SearchBuilder zoneSb = _dcDao.createSearchBuilder(); - zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ); - sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER); - } - - - SearchCriteria sc = sb.create(); if (id != null) { - sc.setParameters("id", id); + sc.addAnd("id", SearchCriteria.Op.EQ, id); } if (name != null) { - sc.setParameters("name", "%" + name + "%"); + sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); } if (podId != null) { - sc.setParameters("podId", podId); + sc.addAnd("podId", SearchCriteria.Op.EQ, podId); } if (zoneId != null) { - sc.setParameters("dataCenterId", zoneId); + sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId); } if (hypervisorType != null) { - sc.setParameters("hypervisorType", hypervisorType); + sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hypervisorType); } if (clusterType != null) { - sc.setParameters("clusterType", clusterType); + sc.addAnd("clusterType", SearchCriteria.Op.EQ, clusterType); } if (allocationState != null) { - sc.setParameters("allocationState", allocationState); - } - - if(zoneType != null) { - sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType); + sc.addAnd("allocationState", SearchCriteria.Op.EQ, allocationState); } if (keyword != null) { @@ -1469,29 +1448,17 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public Pair, Integer> searchForPods(ListPodsByCmd cmd) { + Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal()); + SearchCriteria sc = _hostPodDao.createSearchCriteria(); + String podName = cmd.getPodName(); Long id = cmd.getId(); Long zoneId = cmd.getZoneId(); Object keyword = cmd.getKeyword(); Object allocationState = cmd.getAllocationState(); - String zoneType = cmd.getZoneType(); + zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId); - - Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal()); - SearchBuilder sb = _hostPodDao.createSearchBuilder(); - sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); - sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); - sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); - sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ); - - if(zoneType != null) { - SearchBuilder zoneSb = _dcDao.createSearchBuilder(); - zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ); - sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER); - } - - SearchCriteria sc = sb.create(); if (keyword != null) { SearchCriteria ssc = _hostPodDao.createSearchCriteria(); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); @@ -1501,23 +1468,19 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe } if (id != null) { - sc.setParameters("id", id); + sc.addAnd("id", SearchCriteria.Op.EQ, id); } if (podName != null) { - sc.setParameters("name", "%" + podName + "%"); + sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + podName + "%"); } if (zoneId != null) { - sc.setParameters("dataCenterId", zoneId); + sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId); } if (allocationState != null) { - sc.setParameters("allocationState", allocationState); - } - - if(zoneType != null) { - sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType); + sc.addAnd("allocationState", SearchCriteria.Op.EQ, allocationState); } Pair, Integer> result = _hostPodDao.searchAndCount(sc, searchFilter); @@ -1756,7 +1719,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor()); return listTemplates(cmd.getId(), cmd.getIsoName(), cmd.getKeyword(), isoFilter, true, cmd.isBootable(), cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), hypervisorType, true, cmd.listInReadyState(), permittedAccounts, caller, - listProjectResourcesCriteria, tags, cmd.getZoneType()); + listProjectResourcesCriteria, tags); } @Override @@ -1789,12 +1752,12 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor()); return listTemplates(id, cmd.getTemplateName(), cmd.getKeyword(), templateFilter, false, null, cmd.getPageSizeVal(), cmd.getStartIndex(), - cmd.getZoneId(), hypervisorType, showDomr, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags, cmd.getZoneType()); + cmd.getZoneId(), hypervisorType, showDomr, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags); } private Set> listTemplates(Long templateId, String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable, Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean showDomr, boolean onlyReady, - List permittedAccounts, Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags, String zoneType) { + List permittedAccounts, Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags) { VMTemplateVO template = null; if (templateId != null) { @@ -1835,7 +1798,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe startIndex, zoneId, hyperType, onlyReady, showDomr, permittedAccounts, caller, tags); Set> templateZonePairSet2 = new HashSet>(); templateZonePairSet2 = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, hypers, bootable, domain, pageSize, - startIndex, zoneId, hyperType, onlyReady, showDomr, permittedAccounts, caller, listProjectResourcesCriteria, tags, zoneType); + startIndex, zoneId, hyperType, onlyReady, showDomr, permittedAccounts, caller, listProjectResourcesCriteria, tags); for (Pair tmpltPair : templateZonePairSet2) { if (!templateZonePairSet.contains(new Pair(tmpltPair.first(), -1L))) { @@ -1859,7 +1822,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe Set> templateZonePairSet2 = new HashSet>(); templateZonePairSet2 = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, hypers, bootable, domain, pageSize, startIndex, zoneId, hyperType, onlyReady, showDomr, - permittedAccounts, caller, listProjectResourcesCriteria, tags, zoneType); + permittedAccounts, caller, listProjectResourcesCriteria, tags); for (Pair tmpltPair : templateZonePairSet2) { if (!templateZonePairSet.contains(new Pair(tmpltPair.first(), -1L))) { @@ -1877,7 +1840,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe } else { if (template == null) { templateZonePairSet = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, hypers, bootable, domain, pageSize, - startIndex, zoneId, hyperType, onlyReady, showDomr, permittedAccounts, caller, listProjectResourcesCriteria, tags, zoneType); + startIndex, zoneId, hyperType, onlyReady, showDomr, permittedAccounts, caller, listProjectResourcesCriteria, tags); } else { // if template is not public, perform permission check here if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { @@ -3115,7 +3078,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe public Pair, Integer> searchForSystemVm(ListSystemVMsCmd cmd) { String type = cmd.getSystemVmType(); Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId()); - String zoneType = cmd.getZoneType(); Long id = cmd.getId(); String name = cmd.getSystemVmName(); String state = cmd.getState(); @@ -3142,12 +3104,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe sb.join("volumeSearch", volumeSearch, sb.entity().getId(), volumeSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); } - if(zoneType != null) { - SearchBuilder zoneSb = _dcDao.createSearchBuilder(); - zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ); - sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER); - } - SearchCriteria sc = sb.create(); if (keyword != null) { @@ -3188,10 +3144,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe sc.setJoinParameters("volumeSearch", "poolId", storageId); } - if(zoneType != null) { - sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType); - } - Pair, Integer> result = _vmInstanceDao.searchAndCount(sc, searchFilter); return new Pair, Integer>(result.first(), result.second()); } diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 480e666bbfa..20b435c60dc 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -779,6 +779,9 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C HypervisorType hypervisorType = HypervisorType.KVM; if (scopeType == ScopeType.ZONE) { + // ignore passed clusterId and podId + clusterId = null; + podId = null; String hypervisor = cmd.getHypervisor(); if (hypervisor != null) { try { diff --git a/server/src/com/cloud/storage/s3/S3ManagerImpl.java b/server/src/com/cloud/storage/s3/S3ManagerImpl.java index 61e5573394d..91fa9c34f0f 100644 --- a/server/src/com/cloud/storage/s3/S3ManagerImpl.java +++ b/server/src/com/cloud/storage/s3/S3ManagerImpl.java @@ -41,7 +41,6 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.Callable; -import javax.annotation.PostConstruct; import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; @@ -193,13 +192,12 @@ public class S3ManagerImpl extends ManagerBase implements S3Manager { } - @SuppressWarnings("unchecked") - private String determineLockId(final long accountId, final long templateId) { + static String determineLockId(final long accountId, final long templateId) { // TBD The lock scope may be too coarse grained. Deletes need to lock // the template across all zones where upload and download could // probably safely scoped to the zone ... - return join(asList("S3_TEMPLATE", accountId, templateId), "_"); + return join("_", "S3_TEMPLATE", accountId, templateId); } @@ -397,9 +395,7 @@ public class S3ManagerImpl extends ManagerBase implements S3Manager { throw new CloudRuntimeException(errMsg); } - final String installPath = join( - asList("template", "tmpl", accountId, - templateId), File.separator); + final String installPath = join(File.separator, "template", "tmpl", accountId, templateId); final VMTemplateHostVO tmpltHost = new VMTemplateHostVO( secondaryStorageHost.getId(), templateId, now(), 100, Status.DOWNLOADED, null, null, diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index 02e34288766..c720169b2d3 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -58,7 +58,6 @@ import com.cloud.configuration.Resource.ResourceType; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter; -import com.cloud.dc.DataCenterVO; import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.domain.dao.DomainDao; @@ -572,7 +571,6 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, String keyword = cmd.getKeyword(); String snapshotTypeStr = cmd.getSnapshotType(); String intervalTypeStr = cmd.getIntervalType(); - String zoneType = cmd.getZoneType(); Map tags = cmd.getTags(); Long zoneId = cmd.getZoneId(); @@ -606,23 +604,17 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); if (tags != null && !tags.isEmpty()) { - SearchBuilder tagSearch = _resourceTagDao.createSearchBuilder(); - for (int count=0; count < tags.size(); count++) { - tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ); - tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ); - tagSearch.cp(); - } - tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); - sb.groupBy(sb.entity().getId()); - sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER); + SearchBuilder tagSearch = _resourceTagDao.createSearchBuilder(); + for (int count=0; count < tags.size(); count++) { + tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ); + tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ); + tagSearch.cp(); } + tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + sb.groupBy(sb.entity().getId()); + sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER); + } - if(zoneType != null) { - SearchBuilder zoneSb = _dcDao.createSearchBuilder(); - zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ); - sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER); - } - SearchCriteria sc = sb.create(); _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); @@ -640,14 +632,10 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, } } - if(zoneType != null) { - sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType); - } - if (zoneId != null) { sc.setParameters("dataCenterId", zoneId); } - + if (name != null) { sc.setParameters("name", "%" + name + "%"); } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 1c8ab75f183..e8ea0242e11 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -509,18 +509,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use // update the password in vm_details table too // Check if an SSH key pair was selected for the instance and if so // use it to encrypt & save the vm password - String sshPublicKey = userVm.getDetail("SSH.PublicKey"); - if (sshPublicKey != null && !sshPublicKey.equals("") - && password != null && !password.equals("saved_password")) { - String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey( - sshPublicKey, password); - if (encryptedPasswd == null) { - throw new CloudRuntimeException("Error encrypting password"); - } - - userVm.setDetail("Encrypted.Password", encryptedPasswd); - _vmDao.saveDetails(userVm); - } + encryptAndStorePassword(userVm, password); } else { throw new CloudRuntimeException( "Failed to reset password for the virtual machine "); @@ -643,13 +632,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use if (template != null && template.getEnablePassword()) { userVm.setPassword(password); //update the encrypted password in vm_details table too - if (sshPublicKey != null && !sshPublicKey.equals("") && password != null && !password.equals("saved_password")) { - String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey(sshPublicKey, password); - if (encryptedPasswd == null) { - throw new CloudRuntimeException("Error encrypting password"); - } - userVm.setDetail("Encrypted.Password", encryptedPasswd); - } + encryptAndStorePassword(userVm, password); } _vmDao.saveDetails(userVm); } else { @@ -3304,18 +3287,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use // Check if an SSH key pair was selected for the instance and if so // use it to encrypt & save the vm password - String sshPublicKey = vm.getDetail("SSH.PublicKey"); - if (sshPublicKey != null && !sshPublicKey.equals("") - && password != null && !password.equals("saved_password")) { - String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey( - sshPublicKey, password); - if (encryptedPasswd == null) { - throw new CloudRuntimeException("Error encrypting password"); - } - - vm.setDetail("Encrypted.Password", encryptedPasswd); - _vmDao.saveDetails(vm); - } + encryptAndStorePassword(vm, password); params = new HashMap(); if (additionalParams != null) { @@ -3832,7 +3804,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use "No permission to migrate VM, Only Root Admin can migrate a VM!"); } - UserVmVO vm = _vmDao.findById(vmId); + VMInstanceVO vm = _vmInstanceDao.findById(vmId); if (vm == null) { throw new InvalidParameterValueException( "Unable to find the VM by id=" + vmId); @@ -3923,7 +3895,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use + " already has max Running VMs(count includes system VMs), cannot migrate to this host"); } - collectVmDiskStatistics(vm); + UserVmVO uservm = _vmDao.findById(vmId); + if (uservm != null) { + collectVmDiskStatistics(uservm); + } VMInstanceVO migratedVm = _itMgr.migrate(vm, srcHostId, dest); return migratedVm; } @@ -4621,15 +4596,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use // update the password in vm_details table too // Check if an SSH key pair was selected for the instance and if so // use it to encrypt & save the vm password - String sshPublicKey = vm.getDetail("SSH.PublicKey"); - if (sshPublicKey != null && !sshPublicKey.equals("") && password != null && !password.equals("saved_password")) { - String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey(sshPublicKey, password); - if (encryptedPasswd == null) { - throw new CloudRuntimeException("VM reset is completed but error occurred when encrypting newly created password"); - } - vm.setDetail("Encrypted.Password", encryptedPasswd); - _vmDao.saveDetails(vm); - } + encryptAndStorePassword(vm, password); } else { throw new CloudRuntimeException("VM reset is completed but failed to reset password for the virtual machine "); } @@ -4717,5 +4684,24 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use if (vm.getState() == State.Running) collectVmDiskStatistics(vm); } + + private void encryptAndStorePassword(UserVmVO vm, String password) { + String sshPublicKey = vm.getDetail("SSH.PublicKey"); + if (sshPublicKey != null && !sshPublicKey.equals("") + && password != null && !password.equals("saved_password")) { + if (!sshPublicKey.startsWith("ssh-rsa")) { + s_logger.warn("Only RSA public keys can be used to encrypt a vm password."); + return; + } + String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey( + sshPublicKey, password); + if (encryptedPasswd == null) { + throw new CloudRuntimeException("Error encrypting password"); + } + + vm.setDetail("Encrypted.Password", encryptedPasswd); + _vmDao.saveDetails(vm); + } + } } diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index e7fa5b2f1bc..9ddba8307b8 100755 --- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -22,7 +22,6 @@ import static com.cloud.utils.S3Utils.putDirectory; import static com.cloud.utils.StringUtils.join; import static com.cloud.utils.db.GlobalLock.executeWithNoWaitLock; import static java.lang.String.format; -import static java.util.Arrays.asList; import static org.apache.commons.lang.StringUtils.substringAfterLast; import java.io.BufferedWriter; @@ -217,19 +216,16 @@ SecondaryStorageResource { } } - @SuppressWarnings("unchecked") - private String determineS3TemplateDirectory(final Long accountId, + static String determineS3TemplateDirectory(final Long accountId, final Long templateId) { - return join(asList(TEMPLATE_ROOT_DIR, accountId, templateId), - S3Utils.SEPARATOR); + return join(S3Utils.SEPARATOR, TEMPLATE_ROOT_DIR, accountId, templateId); } - @SuppressWarnings("unchecked") private String determineStorageTemplatePath(final String storagePath, final Long accountId, final Long templateId) { - return join( - asList(getRootDir(storagePath), TEMPLATE_ROOT_DIR, accountId, - templateId), File.separator); + return join(File.separator, + getRootDir(storagePath), TEMPLATE_ROOT_DIR, accountId, + templateId); } private Answer execute( @@ -405,10 +401,7 @@ SecondaryStorageResource { s_logger.debug(String .format("Determining key using account id %1$s and template id %2$s", accountId, templateId)); - return join( - asList(determineS3TemplateDirectory( - accountId, templateId), file - .getName()), S3Utils.SEPARATOR); + return join(S3Utils.SEPARATOR, determineS3TemplateDirectory(accountId, templateId), file.getName()); } }); diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql index 6b136579c2d..bcdf2d986d5 100644 --- a/setup/db/db/schema-410to420.sql +++ b/setup/db/db/schema-410to420.sql @@ -1881,3 +1881,6 @@ SET foreign_key_checks = 1; UPDATE `cloud`.`snapshot_policy` set uuid=id WHERE uuid is NULL; #update shared sg enabled network with not null name in Advance Security Group enabled network UPDATE `cloud`.`networks` set name='Shared SG enabled network', display_text='Shared SG enabled network' WHERE name IS null AND traffic_type='Guest' AND data_center_id IN (select id from data_center where networktype='Advanced' and is_security_group_enabled=1) AND acl_type='Domain'; + +INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'use.system.public.ips', 'true', 'If true, when account has dedicated public ip range(s), once the ips dedicated to the account have been consumed ips will be acquired from the system pool'); +INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'use.system.guest.vlans', 'true', 'If true, when account has dedicated guest vlan range(s), once the vlans dedicated to the account have been consumed vlans will be allocated from the system pool'); diff --git a/setup/dev/advanced.cfg b/setup/dev/advanced.cfg index 302016569ab..3d0854d8aa7 100644 --- a/setup/dev/advanced.cfg +++ b/setup/dev/advanced.cfg @@ -218,7 +218,8 @@ "mgtSvrIp": "localhost", "passwd": "password", "user": "root", - "port": 8096 + "port": 8096, + "hypervisor" : "simulator" } ] } diff --git a/test/integration/component/test_blocker_bugs.py b/test/integration/component/test_blocker_bugs.py index d099bf1a448..1f7ac97afb3 100644 --- a/test/integration/component/test_blocker_bugs.py +++ b/test/integration/component/test_blocker_bugs.py @@ -68,11 +68,6 @@ class Services: "publicport": 22, "protocol": 'TCP', }, - "volume": { - "diskname": "APP Data Volume", - "size": 1, # in GBs - "diskdevice": "/dev/xvdb", # Data Disk - }, "templates": { "displaytext": 'Template from snapshot', "name": 'Template from snapshot', @@ -86,13 +81,6 @@ class Services: "isextractable": True, "passwordenabled": True, }, - "paths": { - "mount_dir": "/mnt/tmp", - "sub_dir": "test", - "sub_lvl_dir1": "test1", - "sub_lvl_dir2": "test2", - "random_data": "random.data", - }, "static_nat": { "startport": 22, "endport": 22, @@ -104,297 +92,6 @@ class Services: } -class TestSnapshots(cloudstackTestCase): - - @classmethod - def setUpClass(cls): - cls.api_client = super(TestSnapshots, cls).getClsTestClient().getApiClient() - cls.services = Services().services - # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.services['mode'] = cls.zone.networktype - cls.disk_offering = DiskOffering.create( - cls.api_client, - cls.services["disk_offering"] - ) - cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - cls.services["virtual_machine"]["zoneid"] = cls.zone.id - cls.services["volume"]["zoneid"] = cls.zone.id - - cls.services["template"] = cls.template.id - cls.services["zoneid"] = cls.zone.id - - # Create VMs, NAT Rules etc - cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) - - cls.services["account"] = cls.account.name - - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) - cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - templateid=cls.template.id, - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - mode=cls.services["mode"] - ) - - cls._cleanup = [ - cls.service_offering, - cls.disk_offering, - cls.account, - ] - return - - @classmethod - def tearDownClass(cls): - try: - #Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return - - def setUp(self): - self.apiclient = self.testClient.getApiClient() - self.dbclient = self.testClient.getDbConnection() - self.cleanup = [] - return - - def tearDown(self): - try: - #Clean up, terminate the created instance, volumes and snapshots - cleanup_resources(self.apiclient, self.cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return - - @attr(tags = ["advanced", "advancedns"]) - def test_01_volume_from_snapshot(self): - """TS_BUG_001-Test Creating snapshot from volume having spaces in name(KVM) - """ - - - # Validate the following - #1. Create a virtual machine and data volume - #2. Attach data volume to VM - #3. Login to machine; create temp/test directories on data volume - #4. Snapshot the Volume - #5. Create another Volume from snapshot - #6. Mount/Attach volume to another server - #7. Compare data - - random_data_0 = random_gen(100) - random_data_1 = random_gen(100) - - volume = Volume.create( - self.apiclient, - self.services["volume"], - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid, - diskofferingid=self.disk_offering.id - ) - self.debug("Created volume with ID: %s" % volume.id) - self.virtual_machine.attach_volume( - self.apiclient, - volume - ) - self.debug("Attach volume: %s to VM: %s" % - (volume.id, self.virtual_machine.id)) - try: - ssh_client = self.virtual_machine.get_ssh_client() - except Exception as e: - self.fail("SSH failed for VM: %s" % - self.virtual_machine.ipaddress) - - self.debug("Formatting volume: %s to ext3" % volume.id) - #Format partition using ext3 - format_volume_to_ext3( - ssh_client, - self.services["volume"]["diskdevice"] - ) - cmds = [ - "mkdir -p %s" % self.services["paths"]["mount_dir"], - "mount %s1 %s" % ( - self.services["volume"]["diskdevice"], - self.services["paths"]["mount_dir"] - ), - "mkdir -p %s/%s/{%s,%s} " % ( - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["sub_lvl_dir2"] - ), - "echo %s > %s/%s/%s/%s" % ( - random_data_0, - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["random_data"] - ), - "echo %s > %s/%s/%s/%s" % ( - random_data_1, - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir2"], - self.services["paths"]["random_data"] - ), - ] - for c in cmds: - self.debug("Command: %s" % c) - ssh_client.execute(c) - - # Unmount the Sec Storage - cmds = [ - "umount %s" % (self.services["paths"]["mount_dir"]), - ] - for c in cmds: - self.debug("Command: %s" % c) - ssh_client.execute(c) - - list_volume_response = Volume.list( - self.apiclient, - virtualmachineid=self.virtual_machine.id, - type='DATADISK', - listall=True - ) - - self.assertEqual( - isinstance(list_volume_response, list), - True, - "Check list volume response for valid data" - ) - volume_response = list_volume_response[0] - #Create snapshot from attached volume - snapshot = Snapshot.create( - self.apiclient, - volume_response.id, - account=self.account.name, - domainid=self.account.domainid - ) - self.debug("Created snapshot: %s" % snapshot.id) - #Create volume from snapshot - volume_from_snapshot = Volume.create_from_snapshot( - self.apiclient, - snapshot.id, - self.services["volume"], - account=self.account.name, - domainid=self.account.domainid - ) - self.debug("Created Volume: %s from Snapshot: %s" % ( - volume_from_snapshot.id, - snapshot.id)) - volumes = Volume.list( - self.apiclient, - id=volume_from_snapshot.id - ) - self.assertEqual( - isinstance(volumes, list), - True, - "Check list response returns a valid list" - ) - - self.assertNotEqual( - len(volumes), - None, - "Check Volume list Length" - ) - self.assertEqual( - volumes[0].id, - volume_from_snapshot.id, - "Check Volume in the List Volumes" - ) - #Attaching volume to new VM - new_virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - templateid=self.template.id, - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - mode=self.services["mode"] - ) - self.debug("Deployed new VM for account: %s" % self.account.name) - self.cleanup.append(new_virtual_machine) - - self.debug("Attaching volume: %s to VM: %s" % ( - volume_from_snapshot.id, - new_virtual_machine.id - )) - - cmd = attachVolume.attachVolumeCmd() - cmd.id = volume_from_snapshot.id - cmd.virtualmachineid = new_virtual_machine.id - self.apiclient.attachVolume(cmd) - - try: - #Login to VM to verify test directories and files - ssh = new_virtual_machine.get_ssh_client() - - cmds = [ - "mkdir -p %s" % self.services["paths"]["mount_dir"], - "mount %s1 %s" % ( - self.services["volume"]["diskdevice"], - self.services["paths"]["mount_dir"] - ), - ] - - for c in cmds: - self.debug("Command: %s" % c) - ssh.execute(c) - - returned_data_0 = ssh.execute( - "cat %s/%s/%s/%s" % ( - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["random_data"] - )) - returned_data_1 = ssh.execute( - "cat %s/%s/%s/%s" % ( - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir2"], - self.services["paths"]["random_data"] - )) - except Exception as e: - self.fail("SSH access failed for VM: %s" % - new_virtual_machine.ipaddress) - #Verify returned data - self.assertEqual( - random_data_0, - returned_data_0[0], - "Verify newly attached volume contents with existing one" - ) - self.assertEqual( - random_data_1, - returned_data_1[0], - "Verify newly attached volume contents with existing one" - ) - # Unmount the Sec Storage - cmds = [ - "umount %s" % (self.services["paths"]["mount_dir"]), - ] - for c in cmds: - self.debug("Command: %s" % c) - ssh_client.execute(c) - return - - class TestTemplate(cloudstackTestCase): def setUp(self): diff --git a/test/integration/component/test_explicit_dedication.py b/test/integration/component/test_explicit_dedication.py index 21a4904e71b..e1991ac5219 100644 --- a/test/integration/component/test_explicit_dedication.py +++ b/test/integration/component/test_explicit_dedication.py @@ -87,9 +87,6 @@ class Services: "name": "Cent OS Template", "passwordenabled": True, }, - "diskdevice": '/dev/xvdd', - # Disk device where ISO is attached to instance - "mount_dir": "/mnt/tmp", "sleep": 60, "timeout": 10, "ostype": 'CentOS 5.3 (64-bit)' diff --git a/test/integration/component/test_implicit_planner.py b/test/integration/component/test_implicit_planner.py index ffcd248b462..854b48148c6 100644 --- a/test/integration/component/test_implicit_planner.py +++ b/test/integration/component/test_implicit_planner.py @@ -80,9 +80,6 @@ class Services: "name": "Cent OS Template", "passwordenabled": True, }, - "diskdevice": '/dev/xvdd', - # Disk device where ISO is attached to instance - "mount_dir": "/mnt/tmp", "sleep": 60, "timeout": 10, #Migrate VM to hostid diff --git a/test/integration/component/test_netscaler_lb.py b/test/integration/component/test_netscaler_lb.py index b4e6c30497f..9d06275f26c 100644 --- a/test/integration/component/test_netscaler_lb.py +++ b/test/integration/component/test_netscaler_lb.py @@ -1085,7 +1085,7 @@ class TestAddMultipleVmsLb(cloudstackTestCase): # 3. Acquire Ip address and create LB rule on it. Add multiple VMs to # this rule. LB rule should be # In Netscaler: For every Vm added to the LB rule: - # 1. A server and service instance is created using guest VM’s IP and + # 1. A server and service instance is created using guest VMs IP and # port number on the Netscaler LB device, # 2. This service is bound to lb virtual server corresponding to lb # rule. diff --git a/test/integration/component/test_redundant_router.py b/test/integration/component/test_redundant_router.py index a87818a4ccb..914b17496dc 100644 --- a/test/integration/component/test_redundant_router.py +++ b/test/integration/component/test_redundant_router.py @@ -65,13 +65,6 @@ class Services: "publicport": 22, "protocol": 'TCP', }, - "volume": { - "diskname": "APP Data Volume", - "size": 1, - # in GBs - "diskdevice": "/dev/xvdb", - # Data Disk - }, "static_nat": { "startport": 22, "endport": 22, diff --git a/test/integration/component/test_shared_networks.py b/test/integration/component/test_shared_networks.py index cb2b55f705a..6bcfbfdfb39 100644 --- a/test/integration/component/test_shared_networks.py +++ b/test/integration/component/test_shared_networks.py @@ -19,6 +19,7 @@ """ #Import Local Modules import marvin +from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.integration.lib.utils import * diff --git a/test/integration/component/test_snapshots.py b/test/integration/component/test_snapshots.py index 014b55afcc1..708a8b29996 100644 --- a/test/integration/component/test_snapshots.py +++ b/test/integration/component/test_snapshots.py @@ -108,6 +108,18 @@ class Services: "ostype": "CentOS 5.3 (64-bit)", "templatefilter": 'self', }, + "volume": { + "diskname": "APP Data Volume", + "size": 1, # in GBs + "diskdevice": "/dev/xvdb", # Data Disk + }, + "paths": { + "mount_dir": "/mnt/tmp", + "sub_dir": "test", + "sub_lvl_dir1": "test1", + "sub_lvl_dir2": "test2", + "random_data": "random.data", + }, "diskdevice": "/dev/xvda", "diskname": "TestDiskServ", "size": 1, # GBs @@ -377,6 +389,11 @@ class TestSnapshots(cloudstackTestCase): cls.services["zoneid"] = cls.zone.id cls.services["diskoffering"] = cls.disk_offering.id + #determine device type from hypervisor + hosts = Host.list(cls.api_client, id=cls.virtual_machine.hostid) + if len(hosts) > 0 and hosts[0].hypervisor.lower() == "kvm": + cls.service["volume"]["diskdevice"] = "/dev/vdb" + # Create VMs, NAT Rules etc cls.account = Account.create( cls.api_client, @@ -583,81 +600,102 @@ class TestSnapshots(cloudstackTestCase): return @attr(speed = "slow") - @attr(tags = ["advanced", "advancedns", "smoke", "xen"]) - def test_03_volume_from_snapshot(self): - """Create volumes from snapshots + @attr(tags = ["advanced", "advancedns", "basic", "sg"]) + def test_01_volume_from_snapshot(self): + """Test Creating snapshot from volume having spaces in name(KVM) """ - #1. Login to machine; create temp/test directories on data volume - #2. Snapshot the Volume - #3. Create another Volume from snapshot - #4. Mount/Attach volume to another server - #5. Compare data + # Validate the following + #1. Create a virtual machine and data volume + #2. Attach data volume to VM + #3. Login to machine; create temp/test directories on data volume + #4. Snapshot the Volume + #5. Create another Volume from snapshot + #6. Mount/Attach volume to another server + #7. Compare data + random_data_0 = random_gen(100) random_data_1 = random_gen(100) + volume = Volume.create( + self.apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id + ) + self.debug("Created volume with ID: %s" % volume.id) + self.virtual_machine.attach_volume( + self.apiclient, + volume + ) + self.debug("Attach volume: %s to VM: %s" % + (volume.id, self.virtual_machine.id)) + + try: ssh_client = self.virtual_machine.get_ssh_client() + except Exception as e: + self.fail("SSH failed for VM: %s" % + self.virtual_machine.ipaddress) - #Format partition using ext3 - format_volume_to_ext3( + self.debug("Formatting volume: %s to ext3" % volume.id) + #Format partition using ext3 + format_volume_to_ext3( ssh_client, - self.services["diskdevice"] + self.services["volume"]["diskdevice"] ) - cmds = [ - "mkdir -p %s" % self.services["mount_dir"], + cmds = [ + "mkdir -p %s" % self.services["paths"]["mount_dir"], "mount %s1 %s" % ( - self.services["diskdevice"], - self.services["mount_dir"] + self.services["volume"]["diskdevice"], + self.services["paths"]["mount_dir"] ), "mkdir -p %s/%s/{%s,%s} " % ( - self.services["mount_dir"], - self.services["sub_dir"], - self.services["sub_lvl_dir1"], - self.services["sub_lvl_dir2"] - ), + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["sub_lvl_dir2"] + ), "echo %s > %s/%s/%s/%s" % ( - random_data_0, - self.services["mount_dir"], - self.services["sub_dir"], - self.services["sub_lvl_dir1"], - self.services["random_data"] - ), + random_data_0, + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["random_data"] + ), "echo %s > %s/%s/%s/%s" % ( - random_data_1, - self.services["mount_dir"], - self.services["sub_dir"], - self.services["sub_lvl_dir2"], - self.services["random_data"] - ), + random_data_1, + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir2"], + self.services["paths"]["random_data"] + ), ] - for c in cmds: - self.debug(c) - ssh_client.execute(c) + for c in cmds: + self.debug("Command: %s" % c) + ssh_client.execute(c) - except Exception as e: - self.fail("SSH failed for VM with IP: %s" % - self.virtual_machine.ipaddress) # Unmount the Sec Storage cmds = [ - "umount %s" % (self.services["mount_dir"]), + "umount %s" % (self.services["paths"]["mount_dir"]), ] + for c in cmds: + self.debug("Command: %s" % c) + ssh_client.execute(c) - try: - for c in cmds: - self.debug(c) - ssh_client.execute(c) - - except Exception as e: - self.fail("SSH failed for VM with IP: %s" % - self.virtual_machine.ipaddress) - - list_volume_response = list_volumes( + list_volume_response = Volume.list( self.apiclient, virtualmachineid=self.virtual_machine.id, type='DATADISK', listall=True ) + self.assertEqual( + isinstance(list_volume_response, list), + True, + "Check list volume response for valid data" + ) volume_response = list_volume_response[0] #Create snapshot from attached volume snapshot = Snapshot.create( @@ -666,81 +704,94 @@ class TestSnapshots(cloudstackTestCase): account=self.account.name, domainid=self.account.domainid ) - self.debug("Created Snapshot from volume: %s" % volume_response.id) - + self.debug("Created snapshot: %s" % snapshot.id) #Create volume from snapshot - self.debug("Creating volume from snapshot: %s" % snapshot.id) - volume = Volume.create_from_snapshot( + volume_from_snapshot = Volume.create_from_snapshot( self.apiclient, snapshot.id, - self.services, + self.services["volume"], account=self.account.name, domainid=self.account.domainid ) - - volumes = list_volumes( + self.debug("Created Volume: %s from Snapshot: %s" % ( + volume_from_snapshot.id, + snapshot.id)) + volumes = Volume.list( self.apiclient, - id=volume.id + id=volume_from_snapshot.id ) self.assertEqual( isinstance(volumes, list), True, "Check list response returns a valid list" ) + self.assertNotEqual( len(volumes), None, "Check Volume list Length" ) - self.assertEqual( volumes[0].id, - volume.id, + volume_from_snapshot.id, "Check Volume in the List Volumes" ) #Attaching volume to new VM - new_virtual_machine = self.virtual_machine_without_disk + new_virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["server_without_disk"], + templateid=self.template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + mode=self.services["mode"] + ) + self.debug("Deployed new VM for account: %s" % self.account.name) self.cleanup.append(new_virtual_machine) - cmd = attachVolume.attachVolumeCmd() - cmd.id = volume.id - cmd.virtualmachineid = new_virtual_machine.id - self.apiclient.attachVolume(cmd) + self.debug("Attaching volume: %s to VM: %s" % ( + volume_from_snapshot.id, + new_virtual_machine.id + )) + + self.new_virtual_machine.attach_volume( + self.apiclient, + volume_from_snapshot + ) try: #Login to VM to verify test directories and files ssh = new_virtual_machine.get_ssh_client() cmds = [ - "mkdir -p %s" % self.services["mount_dir"], + "mkdir -p %s" % self.services["paths"]["mount_dir"], "mount %s1 %s" % ( - self.services["diskdevice"], - self.services["mount_dir"] + self.services["volume"]["diskdevice"], + self.services["paths"]["mount_dir"] ), ] for c in cmds: - self.debug(c) - result = ssh.execute(c) - self.debug(result) - - returned_data_0 = ssh.execute("cat %s/%s/%s/%s" % ( - self.services["mount_dir"], - self.services["sub_dir"], - self.services["sub_lvl_dir1"], - self.services["random_data"] - )) - returned_data_1 = ssh.execute("cat %s/%s/%s/%s" % ( - self.services["mount_dir"], - self.services["sub_dir"], - self.services["sub_lvl_dir2"], - self.services["random_data"] - )) + self.debug("Command: %s" % c) + ssh.execute(c) + returned_data_0 = ssh.execute( + "cat %s/%s/%s/%s" % ( + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["random_data"] + )) + returned_data_1 = ssh.execute( + "cat %s/%s/%s/%s" % ( + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir2"], + self.services["paths"]["random_data"] + )) except Exception as e: - self.fail("SSH failed for VM with IP: %s" % - self.new_virtual_machine.ipaddress) - + self.fail("SSH access failed for VM: %s" % + new_virtual_machine.ipaddress) #Verify returned data self.assertEqual( random_data_0, @@ -754,15 +805,11 @@ class TestSnapshots(cloudstackTestCase): ) # Unmount the Sec Storage cmds = [ - "umount %s" % (self.services["mount_dir"]), + "umount %s" % (self.services["paths"]["mount_dir"]), ] - try: - for c in cmds: - ssh_client.execute(c) - - except Exception as e: - self.fail("SSH failed for VM with IP: %s" % - self.new_virtual_machine.ipaddress) + for c in cmds: + self.debug("Command: %s" % c) + ssh_client.execute(c) return @attr(speed = "slow") @@ -1182,6 +1229,7 @@ class TestSnapshots(cloudstackTestCase): new_virtual_machine.ipaddress) return + class TestCreateVMsnapshotTemplate(cloudstackTestCase): @classmethod @@ -1560,7 +1608,7 @@ class TestAccountSnapshotClean(cloudstackTestCase): return @attr(speed = "slow") - @attr(tags = ["advanced", "advancedns"]) + @attr(tags = ["advanced", "advancedns", "basic", "sg"]) def test_02_accountSnapshotClean(self): """Test snapshot cleanup after account deletion """ @@ -1852,6 +1900,11 @@ class TestSnapshotDetachedDisk(cloudstackTestCase): cls.services["template"] = template.id + #determine device type from hypervisor + hosts = Host.list(cls.api_client, id=cls.virtual_machine.hostid) + if len(hosts) > 0 and hosts[0].hypervisor.lower() == "kvm": + cls.service["volume"]["diskdevice"] = "/dev/vdb" + # Create VMs, NAT Rules etc cls.account = Account.create( cls.api_client, @@ -1905,7 +1958,7 @@ class TestSnapshotDetachedDisk(cloudstackTestCase): return @attr(speed = "slow") - @attr(tags = ["advanced", "advancedns", "xen"]) + @attr(tags = ["advanced", "advancedns", "basic", "sg"]) def test_03_snapshot_detachedDisk(self): """Test snapshot from detached disk """ @@ -1941,7 +1994,7 @@ class TestSnapshotDetachedDisk(cloudstackTestCase): #Format partition using ext3 format_volume_to_ext3( ssh_client, - self.services["diskdevice"] + self.services["volume"]["diskdevice"] ) cmds = [ "mkdir -p %s" % self.services["mount_dir"], diff --git a/test/integration/component/test_storage_motion.py b/test/integration/component/test_storage_motion.py index 0dcc7f8e8d1..eda77d1a629 100644 --- a/test/integration/component/test_storage_motion.py +++ b/test/integration/component/test_storage_motion.py @@ -79,9 +79,6 @@ class Services: "name": "Cent OS Template", "passwordenabled": True, }, - "diskdevice": '/dev/xvdd', - # Disk device where ISO is attached to instance - "mount_dir": "/mnt/tmp", "sleep": 60, "timeout": 10, #Migrate VM to hostid diff --git a/test/integration/component/test_volumes.py b/test/integration/component/test_volumes.py index 34a067930de..369cefcaf34 100644 --- a/test/integration/component/test_volumes.py +++ b/test/integration/component/test_volumes.py @@ -26,10 +26,7 @@ from marvin.integration.lib.base import * from marvin.integration.lib.common import * from marvin.remoteSSHClient import remoteSSHClient #Import System modules -import os -import urllib import time -import tempfile class Services: diff --git a/test/integration/component/test_vpc.py b/test/integration/component/test_vpc.py index acf7a8eb2e3..cc7069533db 100644 --- a/test/integration/component/test_vpc.py +++ b/test/integration/component/test_vpc.py @@ -20,6 +20,7 @@ #Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * +from marvin.cloudstackException import cloudstackAPIException from marvin.cloudstackAPI import * from marvin.integration.lib.utils import * from marvin.integration.lib.base import * @@ -795,16 +796,16 @@ class TestVPC(cloudstackTestCase): self.services["vpc"], vpcofferingid=self.vpc_off.id, zoneid=self.zone.id, - account=self.user.account.name, - domainid=self.user.account.domainid + account=self.user.name, + domainid=self.user.domainid ) self.validate_vpc_network(vpc_2) self.debug("Validating list VPCs call by passing account and domain") vpcs = VPC.list( self.apiclient, - account=self.user.account.name, - domainid=self.user.account.domainid, + account=self.user.name, + domainid=self.user.domainid, listall=True ) self.assertEqual( @@ -820,7 +821,7 @@ class TestVPC(cloudstackTestCase): ) return - @attr(tags=["advanced", "intervlan"]) + @attr(tags=["advanced", "intervlan", "multiple"]) def test_07_restart_network_vm_running(self): """ Test Restart VPC when there are multiple networks associated """ @@ -1650,7 +1651,7 @@ class TestVPC(cloudstackTestCase): @attr(tags=["advanced", "intervlan"]) def test_11_deploy_vm_wo_network_netdomain(self): - """ Test deployment of vm in a VPC without network netdomain + """ Test deployment of vm in a VPC without network domain """ # 1. Create VPC without providing networkDomain. @@ -1923,8 +1924,7 @@ class TestVPC(cloudstackTestCase): @attr(tags=["advanced", "intervlan"]) def test_14_deploy_vm_1(self): - """ Test deployment of vm in a network from user account. But the VPC is created - without account/domain ID + """ Test vm deploy in network by a user where VPC was created without account/domain ID """ # 1. Create VPC without providing account/domain ID. @@ -1935,18 +1935,19 @@ class TestVPC(cloudstackTestCase): self.apiclient, self.services["account"] ) - self.debug("Created account: %s" % user.account.name) + self.debug("Created account: %s" % user.name) self.cleanup.append(user) self.services["vpc"]["cidr"] = "10.1.1.1/16" self.debug("creating a VPC network in the account: %s" % - user.account.name) + user.name) - userapiclient = self.testClient.createNewApiClient( - UserName=user.account.name, - DomainName=user.account.domain, + userapiclient = self.testClient.createUserApiClient( + UserName=user.name, + DomainName=user.domain, acctType=0) + vpc = VPC.create( userapiclient, self.services["vpc"], @@ -1999,8 +2000,7 @@ class TestVPC(cloudstackTestCase): @attr(tags=["advanced", "intervlan"]) def test_15_deploy_vm_2(self): - """ Test deployment of vm in a network from domain admin account. But the VPC is created - without account/domain ID + """ Test deployment of vm in a network in a domain admin account where VPC is created without account/domain ID """ # 1. Create VPC without providing account/domain ID. @@ -2016,18 +2016,18 @@ class TestVPC(cloudstackTestCase): self.apiclient, self.services["account"] ) - self.debug("Created account: %s" % user.account.name) + self.debug("Created account: %s" % user.name) self.cleanup.append(user) self.services["vpc"]["cidr"] = "10.1.1.1/16" self.debug("creating a VPC network in the account: %s" % - user.account.name) + user.name) #0 - User, 1 - Root Admin, 2 - Domain Admin - userapiclient = self.testClient.createNewApiClient( - UserName=user.account.name, - DomainName=self.services["domain"]["name"], - acctType=2) + userapiclient = self.testClient.getUserApiClient( + account=user.name, + domain=self.services["domain"]["name"], + type=2) vpc = VPC.create( userapiclient, @@ -2092,23 +2092,23 @@ class TestVPC(cloudstackTestCase): self.apiclient, self.services["account"] ) - self.debug("Created account: %s" % user.account.name) + self.debug("Created account: %s" % user.name) self.cleanup.append(user) self.services["vpc"]["cidr"] = "10.1.1.1/16" self.debug("creating a VPC network in the account: %s" % - user.account.name) + user.name) - userapiclient = self.testClient.createNewApiClient( - UserName=user.account.name, - DomainName=user.account.domain, - acctType=0) + userapiclient = self.testClient.getUserApiClient( + account=user.name, + domain=user.domain, + type=0) vpc = VPC.create( self.apiclient, self.services["vpc"], - account=user.account.name, - domainid=user.account.domainid, + account=user.name, + domainid=user.domainid, vpcofferingid=self.vpc_off.id, zoneid=self.zone.id, ) @@ -2176,82 +2176,39 @@ class TestVPC(cloudstackTestCase): self.apiclient, self.services["domain_admin"] ) - self.debug("Created account: %s" % domain_admin.account.name) + self.debug("Created account: %s" % domain_admin.name) self.cleanup.append(domain_admin) - da_apiclient = self.testClient.createNewApiClient( - UserName=domain_admin.account.name, - #DomainName=self.services["domain"]["name"], - DomainName=domain_admin.account.domain, - acctType=2) + da_apiclient = self.testClient.getUserApiClient( + account=domain_admin.name, + domain=domain_admin.domain, + type=2) user = Account.create( self.apiclient, self.services["account"] ) - self.debug("Created account: %s" % user.account.name) + self.debug("Created account: %s" % user.name) self.cleanup.append(user) self.services["vpc"]["cidr"] = "10.1.1.1/16" self.debug("creating a VPC network in the account: %s" % - user.account.name) + user.name) #0 - User, 1 - Root Admin, 2 - Domain Admin - userapiclient = self.testClient.createNewApiClient( - UserName=user.account.name, - DomainName=user.account.domain, - acctType=0) + userapiclient = self.testClient.getUserApiClient( + account=user.name, + domain=user.domain, + type=0) - vpc = VPC.create( - da_apiclient, - self.services["vpc"], - account=user.account.name, - domainid=user.account.domainid, - vpcofferingid=self.vpc_off.id, - zoneid=self.zone.id, - ) - self.validate_vpc_network(vpc) - - self.network_offering = NetworkOffering.create( - self.apiclient, - self.services["network_offering"], - conservemode=False - ) - # Enable Network offering - self.network_offering.update(self.apiclient, state='Enabled') - self._cleanup.append(self.network_offering) - - gateway = vpc.cidr.split('/')[0] - # Split the cidr to retrieve gateway - # for eg. cidr = 10.0.0.1/24 - # Gateway = 10.0.0.1 - - # Creating network using the network offering created - self.debug("Creating network with network offering: %s" % - self.network_offering.id) - network = Network.create( - userapiclient, - self.services["network"], - networkofferingid=self.network_offering.id, - zoneid=self.zone.id, - gateway=gateway, - vpcid=vpc.id - ) - self.debug("Created network with ID: %s" % network.id) - - # Spawn an instance in that network - virtual_machine = VirtualMachine.create( - userapiclient, - self.services["virtual_machine"], - serviceofferingid=self.service_offering.id, - networkids=[str(network.id)] - ) - self.debug("Deployed VM in network: %s" % network.id) - - self.assertNotEqual(virtual_machine, - None, - "VM creation in the network failed") - - return + with self.assertRaises(cloudstackAPIException): + vpc = VPC.create( + da_apiclient, + self.services["vpc"], + account=user.name, + domainid=user.domainid, + vpcofferingid=self.vpc_off.id, + zoneid=self.zone.id, + ) @attr(tags=["advanced", "intervlan"]) def test_18_create_net_for_user_diff_domain_by_doadmin(self): @@ -2271,29 +2228,29 @@ class TestVPC(cloudstackTestCase): self.apiclient, self.services["domain_admin"] ) - self.debug("Created account: %s" % domain_admin.account.name) + self.debug("Created account: %s" % domain_admin.name) self.cleanup.append(domain_admin) - da_apiclient = self.testClient.createNewApiClient( - UserName=domain_admin.account.name, - DomainName=self.services["domain"]["name"], - acctType=2) + da_apiclient = self.testClient.getUserApiClient( + account=domain_admin.name, + domain=self.services["domain"]["name"], + type=2) user = Account.create( self.apiclient, self.services["account"] ) - self.debug("Created account: %s" % user.account.name) + self.debug("Created account: %s" % user.name) self.cleanup.append(user) self.services["vpc"]["cidr"] = "10.1.1.1/16" self.debug("creating a VPC network in the account: %s" % - user.account.name) + user.name) #0 - User, 1 - Root Admin, 2 - Domain Admin - userapiclient = self.testClient.createNewApiClient( - UserName=user.account.name, - DomainName=user.account.domain, - acctType=0) + userapiclient = self.testClient.getUserApiClient( + account=user.name, + domain=user.domain, + type=0) vpc = VPC.create( da_apiclient, @@ -2453,7 +2410,7 @@ class TestVPC(cloudstackTestCase): vpc_networks = VPC.list( self.apiclient, - id=network.id + id=vpc.id ) self.assertEqual( @@ -2467,7 +2424,4 @@ class TestVPC(cloudstackTestCase): self.assertEqual(vpc_networks[0].displaytext, new_display_text, - "Updation of VPC display text failed.") - - - + "Updation of VPC display text failed.") \ No newline at end of file diff --git a/test/integration/component/test_vpc_network_lbrules.py b/test/integration/component/test_vpc_network_lbrules.py index 66d6c4d4018..3461bb4e426 100644 --- a/test/integration/component/test_vpc_network_lbrules.py +++ b/test/integration/component/test_vpc_network_lbrules.py @@ -408,7 +408,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase): self.services["vpc_offering"] ) - self._cleanup.append(self.vpc_off) + self._cleanup.append(vpc_off) self.debug("Enabling the VPC offering created") vpc_off.update(self.apiclient, state='Enabled') diff --git a/test/integration/component/test_vpc_network_pfrules.py b/test/integration/component/test_vpc_network_pfrules.py index 92b04ad3f21..8d1d9eccd0b 100644 --- a/test/integration/component/test_vpc_network_pfrules.py +++ b/test/integration/component/test_vpc_network_pfrules.py @@ -406,7 +406,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): self.services["vpc_offering"] ) - self._cleanup.append(self.vpc_off) + self._cleanup.append(vpc_off) self.debug("Enabling the VPC offering created") vpc_off.update(self.apiclient, state='Enabled') diff --git a/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py b/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py index af832995245..fc8e71648af 100644 --- a/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py +++ b/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py @@ -16,7 +16,7 @@ # under the License. from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import Account, VirtualMachine, ServiceOffering, Host +from marvin.integration.lib.base import Account, VirtualMachine, ServiceOffering, Host, Cluster from marvin.integration.lib.common import get_zone, get_domain, get_template, cleanup_resources from nose.plugins.attrib import attr @@ -77,6 +77,7 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase): ) cls.services["account"] = cls.account.name cls.hosts = Host.list(cls.apiclient, type='Routing') + cls.clusters = Cluster.list(cls.apiclient) cls.cleanup = [ cls.account ] @@ -241,10 +242,13 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase): ) vm1clusterid = filter(lambda c: c.id == vm1.hostid, self.hosts)[0].clusterid vm2clusterid = filter(lambda c: c.id == vm2.hostid, self.hosts)[0].clusterid + + vm1podid = filter(lambda p: p.id == vm1clusterid, self.clusters)[0].podid + vm2podid = filter(lambda p: p.id == vm2clusterid, self.clusters)[0].podid self.assertEqual( - vm1clusterid, - vm2clusterid, - msg="VMs (%s, %s) meant to be concentrated are deployed on different clusters (%s, %s)" % (vm1.id, vm2.id, vm1clusterid, vm2clusterid) + vm1podid, + vm2podid, + msg="VMs (%s, %s) meant to be pod concentrated are deployed on different pods (%s, %s)" % (vm1.id, vm2.id, vm1clusterid, vm2clusterid) ) @classmethod diff --git a/test/integration/smoke/test_nic.py b/test/integration/smoke/test_nic.py index 8e8d3407dfb..0d43a920e97 100644 --- a/test/integration/smoke/test_nic.py +++ b/test/integration/smoke/test_nic.py @@ -122,9 +122,6 @@ class Services: "name": "Cent OS Template", "passwordenabled": True, }, - "diskdevice": '/dev/xvdd', - # Disk device where ISO is attached to instance - "mount_dir": "/mnt/tmp", "sleep": 60, "timeout": 10, #Migrate VM to hostid diff --git a/test/integration/smoke/test_portable_publicip.py b/test/integration/smoke/test_portable_publicip.py index 5b2fbc7e307..9a3a398c17a 100644 --- a/test/integration/smoke/test_portable_publicip.py +++ b/test/integration/smoke/test_portable_publicip.py @@ -21,7 +21,6 @@ from marvin.cloudstackAPI import * from marvin.integration.lib.utils import * from marvin.integration.lib.base import * from marvin.integration.lib.common import * -from marvin import remoteSSHClient from nose.plugins.attrib import attr class Services: diff --git a/test/integration/smoke/test_resource_detail.py b/test/integration/smoke/test_resource_detail.py index 1d5db3ae4e6..93bc2ffc1f1 100644 --- a/test/integration/smoke/test_resource_detail.py +++ b/test/integration/smoke/test_resource_detail.py @@ -91,9 +91,6 @@ class Services: "name": "xs", "passwordenabled": False, }, - "diskdevice": '/dev/xvdd', - # Disk device where ISO is attached to instance - "mount_dir": "/mnt/tmp", "sleep": 60, "timeout": 10, #Migrate VM to hostid diff --git a/test/integration/smoke/test_scale_vm.py b/test/integration/smoke/test_scale_vm.py index fa2418b7cd8..b23ddd1b2cd 100644 --- a/test/integration/smoke/test_scale_vm.py +++ b/test/integration/smoke/test_scale_vm.py @@ -85,9 +85,6 @@ class Services: "name": "xs", "passwordenabled": False, }, - "diskdevice": '/dev/xvdd', - # Disk device where ISO is attached to instance - "mount_dir": "/mnt/tmp", "sleep": 60, "timeout": 10, #Migrate VM to hostid diff --git a/test/integration/smoke/test_vm_life_cycle.py b/test/integration/smoke/test_vm_life_cycle.py index 9aaa13fcb57..a7283478879 100644 --- a/test/integration/smoke/test_vm_life_cycle.py +++ b/test/integration/smoke/test_vm_life_cycle.py @@ -739,7 +739,7 @@ class TestVMLifeCycle(cloudstackTestCase): self.debug("Found %s host" % hosts[0].hypervisor) if hosts[0].hypervisor.lower() == "kvm": - self.services["diskdevice"] = "/dev/vda" + self.services["diskdevice"] = "/dev/vdb" try: ssh_client = self.virtual_machine.get_ssh_client() diff --git a/test/integration/smoke/test_volumes.py b/test/integration/smoke/test_volumes.py index 7039c6ffe66..4c4b78076e7 100644 --- a/test/integration/smoke/test_volumes.py +++ b/test/integration/smoke/test_volumes.py @@ -80,7 +80,6 @@ class Services: "privateport": 22, "publicport": 22, "protocol": 'TCP', - "diskdevice": "/dev/xvdb", "ostype": 'CentOS 5.5 (64-bit)', "sleep": 10, "timeout": 600, diff --git a/tools/marvin/marvin/cloudstackTestClient.py b/tools/marvin/marvin/cloudstackTestClient.py index d85a61c4872..37380d62f73 100644 --- a/tools/marvin/marvin/cloudstackTestClient.py +++ b/tools/marvin/marvin/cloudstackTestClient.py @@ -121,6 +121,7 @@ class cloudstackTestClient(object): apiKey, securityKey, self.connection.asyncTimeout, self.connection.logging) self.userApiClient = cloudstackAPIClient.CloudStackAPIClient(newUserConnection) self.userApiClient.connection = newUserConnection + self.userApiClient.hypervisor = self.apiClient.hypervisor return self.userApiClient def close(self): diff --git a/ui/scripts/network.js b/ui/scripts/network.js index fb63e4b4f19..ddde9c967e5 100755 --- a/ui/scripts/network.js +++ b/ui/scripts/network.js @@ -4532,78 +4532,67 @@ docID: 'helpVPCDomain', label: 'label.DNS.domain.for.guest.networks' }, - - loadbalancer:{ //Support for Netscaler as an external device for load balancing - label:'Load Balancer', + publicLoadBalancerProvider:{ + label:'Public Load Balancer Provider', select:function(args){ - $.ajax({ - url:createURL('listVPCOfferings&listall=true'), - dataType:'json', - success:function(json){ - var items=[]; - var vpcObj = json.listvpcofferingsresponse.vpcoffering; - $(vpcObj).each(function(){ - items.push({id:this.id , description:this.name}); - }); - args.response.success({data:items}); - - } - - }); - - } - - } - + var items = []; + items.push({id: 'VpcVirtualRouter', description: 'VpcVirtualRouter'}); + items.push({id: 'Netscaler', description: 'Netscaler'}); + args.response.success({data: items}); + } + } } }, - action: function(args) { - /* var defaultvpcofferingid; - $.ajax({ - url: createURL("listVPCOfferings"), - dataType: "json", - data: { - isdefault: true - }, - async: false, - success: function(json) { - defaultvpcofferingid = json.listvpcofferingsresponse.vpcoffering[0].id; - } - });*/ - - var dataObj = { - name: args.data.name, - displaytext: args.data.displaytext, - zoneid: args.data.zoneid, - cidr: args.data.cidr, - vpcofferingid: args.data.loadbalancer // Support for external load balancer - }; - - if(args.data.networkdomain != null && args.data.networkdomain.length > 0) - $.extend(dataObj, { networkdomain: args.data.networkdomain }); - - $.ajax({ - url: createURL("createVPC"), - dataType: "json", - data: dataObj, - async: true, - success: function(json) { - var jid = json.createvpcresponse.jobid; - args.response.success( - {_custom: - {jobId: jid, - getUpdatedItem: function(json) { - return json.queryasyncjobresultresponse.jobresult.vpc; - } + action: function(args) { + var vpcOfferingName; + if (args.data.publicLoadBalancerProvider == 'VpcVirtualRouter') + vpcOfferingName = 'Default VPC offering'; + else if (args.data.publicLoadBalancerProvider == 'Netscaler') + vpcOfferingName = 'Default VPC offering with Netscaler'; + + $.ajax({ + url:createURL('listVPCOfferings'), + data: { + name: vpcOfferingName + }, + success:function(json){ + var vpcofferingid = json.listvpcofferingsresponse.vpcoffering[0].id; + + var dataObj = { + name: args.data.name, + displaytext: args.data.displaytext, + zoneid: args.data.zoneid, + cidr: args.data.cidr, + vpcofferingid: vpcofferingid + }; + + if(args.data.networkdomain != null && args.data.networkdomain.length > 0) + $.extend(dataObj, { networkdomain: args.data.networkdomain }); + + $.ajax({ + url: createURL("createVPC"), + dataType: "json", + data: dataObj, + async: true, + success: function(json) { + var jid = json.createvpcresponse.jobid; + args.response.success( + {_custom: + {jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.vpc; + } + } + }); + }, + error: function(data) { + args.response.error(parseXMLHttpResponse(data)); } - }); - }, - error: function(data) { - args.response.error(parseXMLHttpResponse(data)); - } - }); - }, - + }); + } + }); + + }, notification: { poll: pollAsyncJobResult } diff --git a/utils/src/com/cloud/utils/S3Utils.java b/utils/src/com/cloud/utils/S3Utils.java index b7273a14869..33a3ebde660 100644 --- a/utils/src/com/cloud/utils/S3Utils.java +++ b/utils/src/com/cloud/utils/S3Utils.java @@ -155,8 +155,8 @@ public final class S3Utils { try { tempFile = createTempFile( - join(asList(targetDirectory.getName(), currentTimeMillis(), - "part"), "-"), "tmp", targetDirectory); + join("-", targetDirectory.getName(), currentTimeMillis(), + "part"), "tmp", targetDirectory); tempFile.deleteOnExit(); if (LOGGER.isDebugEnabled()) { diff --git a/utils/src/com/cloud/utils/StringUtils.java b/utils/src/com/cloud/utils/StringUtils.java index 14ff4b1ae94..359b169e1b2 100644 --- a/utils/src/com/cloud/utils/StringUtils.java +++ b/utils/src/com/cloud/utils/StringUtils.java @@ -16,8 +16,6 @@ // under the License. package com.cloud.utils; -import static java.util.Arrays.asList; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -25,8 +23,6 @@ import java.util.regex.Pattern; import org.owasp.esapi.StringUtilities; -// StringUtils exists in Apache Commons Lang, but rather than import the entire JAR to our system, for now -// just implement the method needed public class StringUtils { private static final char[] hexChar = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' @@ -50,7 +46,7 @@ public class StringUtils { public static String join(final String delimiter, final Object... components) { - return join(asList(components), delimiter); + return org.apache.commons.lang.StringUtils.join(components, delimiter); } /** diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java index 5c13454da79..60993799b41 100755 --- a/utils/src/com/cloud/utils/net/NetUtils.java +++ b/utils/src/com/cloud/utils/net/NetUtils.java @@ -257,7 +257,7 @@ public class NetUtils { return ipFromInetAddress(addr); } - return new String("127.0.0.1"); + return "127.0.0.1"; } public static String ipFromInetAddress(InetAddress addr) { diff --git a/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java b/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java index 2755c548048..a14e5a4a9d7 100644 --- a/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java +++ b/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java @@ -82,7 +82,7 @@ public class SSHKeysHelper { if (!keyMaterial.contains(" ")) keyMaterial = new String(Base64.decodeBase64(keyMaterial.getBytes())); - if (!keyMaterial.startsWith("ssh-rsa") || !keyMaterial.contains(" ")) + if ((!keyMaterial.startsWith("ssh-rsa") && !keyMaterial.startsWith("ssh-dss")) || !keyMaterial.contains(" ")) return null; String[] key = keyMaterial.split(" "); diff --git a/utils/test/com/cloud/utils/StringUtilsTest.java b/utils/test/com/cloud/utils/StringUtilsTest.java index 3c162c75c02..796efbaacd7 100644 --- a/utils/test/com/cloud/utils/StringUtilsTest.java +++ b/utils/test/com/cloud/utils/StringUtilsTest.java @@ -103,4 +103,9 @@ public class StringUtilsTest { assertEquals(result, expected); } + @Test + public void testJoin() { + assertEquals("a-b-c", StringUtils.join("-", "a", "b", "c")); + assertEquals("", StringUtils.join("-")); + } } diff --git a/utils/test/com/cloud/utils/crypto/RSAHelperTest.java b/utils/test/com/cloud/utils/crypto/RSAHelperTest.java new file mode 100644 index 00000000000..d1f496e1ab1 --- /dev/null +++ b/utils/test/com/cloud/utils/crypto/RSAHelperTest.java @@ -0,0 +1,50 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.utils.crypto; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.cloud.utils.crypt.RSAHelper; + +public class RSAHelperTest { + @Test + public void testEncryptWithRSA() { + String rsaKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2D2Cs0XAEqm+ajJpumIPrMpKp0CWtIW+8ZY2/MJCW" + + "hge1eY18u9I3PPnkMVJsTOaN0wQojjw4AkKgKjNZXA9wyUq56UyN/stmipu8zifWPgxQGDRkuzzZ6buk" + + "ef8q2Awjpo8hv5/0SRPJxQLEafESnUP+Uu/LUwk5VVC7PHzywJRUGFuzDl/uT72+6hqpL2YpC6aTl4/P" + + "2eDvUQhCdL9dBmUSFX8ftT53W1jhsaQl7mPElVgSCtWz3IyRkogobMPrpJW/IPKEiojKIuvNoNv4CDR6" + + "ybeVjHOJMb9wi62rXo+CzUsW0Y4jPOX/OykAm5vrNOhQhw0aaBcv5XVv8BRX"; + String encryptedString = RSAHelper.encryptWithSSHPublicKey(rsaKey, "content"); + assertNotNull(encryptedString); + } + + @Test + public void testEncryptWithDSA() { + String dssKey = "ssh-dss AAAAB3NzaC1kc3MAAACBALbaewDnzZ5AcGbZno7VW1m7Si3Q+yEANXZioVupfSwOP0q9aP2iV"+ + "tyqq575JnUVZXMDR2Gr254F/qCJ0TKAvucN0gcd2XslX4jBcu1Z7s7YZf6d7fC58k0NE6/keokJNKhQO" + + "i56iirRzSA/YFrD64mzfq6rEmai0q7GjGGP0RT1AAAAFQDO5++6JonyqnoRkV9Yl1OaEOPjVwAAAIAYA" + + "tqtKtU/INlTIuL3wt3nyKzwPUnz3fqxP5Ger3OlRZsOahalTFt2OF5jGGmCunyBTRteOetZObr0QhUIF" + + "4bSDr6UiYYYbH1ES0ws/t1mDIeTh3UUHV1QYACN6c07FKyKLMtB9AthiG2FMLKCEedG3NeXItuNzsuQD" + + "+n/K1rzMAAAAIBi5SM4pFPiB7BvTZvARV56vrG5QNgWVazSwbwgl/EACiWYbRauHDUQA9f+Rq+ayWcsR" + + "os1CD+Q81y9SmlQaZVKkSPZLxXfu5bi3s4o431xjilhZdt4vKbj2pK364IjghJPNBBfmRXzlj9awKxr/" + + "UebZcBgNRyeky7VZSbbF2jQSQ=="; + String encryptedString = RSAHelper.encryptWithSSHPublicKey(dssKey, "content"); + assertNull(encryptedString); + } +} diff --git a/utils/test/com/cloud/utils/net/NetUtilsTest.java b/utils/test/com/cloud/utils/net/NetUtilsTest.java index 38fe21d5324..3cfc98fb3b6 100644 --- a/utils/test/com/cloud/utils/net/NetUtilsTest.java +++ b/utils/test/com/cloud/utils/net/NetUtilsTest.java @@ -168,4 +168,9 @@ public class NetUtilsTest extends TestCase { newMac = NetUtils.generateMacOnIncrease(mac, 16); assertTrue(newMac.equals("06:00:0f:00:45:67")); } + + @Test + public void testGetLocalIPString() { + assertNotNull(NetUtils.getLocalIPString()); + } } diff --git a/utils/test/com/cloud/utils/ssh/SSHKeysHelperTest.java b/utils/test/com/cloud/utils/ssh/SSHKeysHelperTest.java new file mode 100644 index 00000000000..6402e3ef347 --- /dev/null +++ b/utils/test/com/cloud/utils/ssh/SSHKeysHelperTest.java @@ -0,0 +1,69 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.utils.ssh; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class SSHKeysHelperTest { + @Test + public void rsaKeyTest() { + String rsaKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2D2Cs0XAEqm+ajJpumIPrMpKp0CWtIW+8ZY2/MJCW" + + "hge1eY18u9I3PPnkMVJsTOaN0wQojjw4AkKgKjNZXA9wyUq56UyN/stmipu8zifWPgxQGDRkuzzZ6buk" + + "ef8q2Awjpo8hv5/0SRPJxQLEafESnUP+Uu/LUwk5VVC7PHzywJRUGFuzDl/uT72+6hqpL2YpC6aTl4/P" + + "2eDvUQhCdL9dBmUSFX8ftT53W1jhsaQl7mPElVgSCtWz3IyRkogobMPrpJW/IPKEiojKIuvNoNv4CDR6" + + "ybeVjHOJMb9wi62rXo+CzUsW0Y4jPOX/OykAm5vrNOhQhw0aaBcv5XVv8BRX test@testkey"; + String storedRsaKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2D2Cs0XAEqm+ajJpumIPrMpKp0CWtIW+8ZY2/MJCW" + + "hge1eY18u9I3PPnkMVJsTOaN0wQojjw4AkKgKjNZXA9wyUq56UyN/stmipu8zifWPgxQGDRkuzzZ6buk" + + "ef8q2Awjpo8hv5/0SRPJxQLEafESnUP+Uu/LUwk5VVC7PHzywJRUGFuzDl/uT72+6hqpL2YpC6aTl4/P" + + "2eDvUQhCdL9dBmUSFX8ftT53W1jhsaQl7mPElVgSCtWz3IyRkogobMPrpJW/IPKEiojKIuvNoNv4CDR6" + + "ybeVjHOJMb9wi62rXo+CzUsW0Y4jPOX/OykAm5vrNOhQhw0aaBcv5XVv8BRX"; + String parsedKey = SSHKeysHelper.getPublicKeyFromKeyMaterial(rsaKey); + String fingerprint = SSHKeysHelper.getPublicKeyFingerprint(parsedKey); + + assertTrue(storedRsaKey.equals(parsedKey)); + assertTrue("f6:96:3f:f4:78:f7:80:11:6c:f8:e3:2b:40:20:f1:14".equals(fingerprint)); + + } + + @Test + public void dsaKeyTest() { + String dssKey = "ssh-dss AAAAB3NzaC1kc3MAAACBALbaewDnzZ5AcGbZno7VW1m7Si3Q+yEANXZioVupfSwOP0q9aP2iV"+ + "tyqq575JnUVZXMDR2Gr254F/qCJ0TKAvucN0gcd2XslX4jBcu1Z7s7YZf6d7fC58k0NE6/keokJNKhQO" + + "i56iirRzSA/YFrD64mzfq6rEmai0q7GjGGP0RT1AAAAFQDO5++6JonyqnoRkV9Yl1OaEOPjVwAAAIAYA" + + "tqtKtU/INlTIuL3wt3nyKzwPUnz3fqxP5Ger3OlRZsOahalTFt2OF5jGGmCunyBTRteOetZObr0QhUIF" + + "4bSDr6UiYYYbH1ES0ws/t1mDIeTh3UUHV1QYACN6c07FKyKLMtB9AthiG2FMLKCEedG3NeXItuNzsuQD" + + "+n/K1rzMAAAAIBi5SM4pFPiB7BvTZvARV56vrG5QNgWVazSwbwgl/EACiWYbRauHDUQA9f+Rq+ayWcsR" + + "os1CD+Q81y9SmlQaZVKkSPZLxXfu5bi3s4o431xjilhZdt4vKbj2pK364IjghJPNBBfmRXzlj9awKxr/" + + "UebZcBgNRyeky7VZSbbF2jQSQ== test key"; + String storedDssKey = "ssh-dss AAAAB3NzaC1kc3MAAACBALbaewDnzZ5AcGbZno7VW1m7Si3Q+yEANXZioVupfSwOP0q9aP2iV"+ + "tyqq575JnUVZXMDR2Gr254F/qCJ0TKAvucN0gcd2XslX4jBcu1Z7s7YZf6d7fC58k0NE6/keokJNKhQO" + + "i56iirRzSA/YFrD64mzfq6rEmai0q7GjGGP0RT1AAAAFQDO5++6JonyqnoRkV9Yl1OaEOPjVwAAAIAYA" + + "tqtKtU/INlTIuL3wt3nyKzwPUnz3fqxP5Ger3OlRZsOahalTFt2OF5jGGmCunyBTRteOetZObr0QhUIF" + + "4bSDr6UiYYYbH1ES0ws/t1mDIeTh3UUHV1QYACN6c07FKyKLMtB9AthiG2FMLKCEedG3NeXItuNzsuQD" + + "+n/K1rzMAAAAIBi5SM4pFPiB7BvTZvARV56vrG5QNgWVazSwbwgl/EACiWYbRauHDUQA9f+Rq+ayWcsR" + + "os1CD+Q81y9SmlQaZVKkSPZLxXfu5bi3s4o431xjilhZdt4vKbj2pK364IjghJPNBBfmRXzlj9awKxr/" + + "UebZcBgNRyeky7VZSbbF2jQSQ=="; + String parsedKey = SSHKeysHelper.getPublicKeyFromKeyMaterial(dssKey); + String fingerprint = SSHKeysHelper.getPublicKeyFingerprint(parsedKey); + + assertTrue(storedDssKey.equals(parsedKey)); + assertTrue("fc:6e:ef:31:93:f8:92:2b:a9:03:c7:06:90:f5:ec:bb".equals(fingerprint)); + + } +}