diff --git a/api/src/com/cloud/network/NetworkModel.java b/api/src/com/cloud/network/NetworkModel.java index f84a8b0c76a..05307eb47aa 100644 --- a/api/src/com/cloud/network/NetworkModel.java +++ b/api/src/com/cloud/network/NetworkModel.java @@ -272,4 +272,6 @@ public interface NetworkModel { Map getNtwkOffDetails(long offId); Networks.IsolationType[] listNetworkIsolationMethods(); + + Nic getNicInNetworkIncludingRemoved(long vmId, long networkId); } \ No newline at end of file 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 69c69802bfe..eaaec3091a7 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 @@ -74,9 +74,6 @@ public class ListHostsCmd extends BaseListCmd { @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class, description="the Zone ID for the host") 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.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = UserVmResponse.class, required=false, description="lists hosts in the same cluster as this VM and flag hosts with enough CPU/RAm to host this VM") @@ -126,10 +123,6 @@ public class ListHostsCmd extends BaseListCmd { public Long getZoneId() { return zoneId; } - - public String getZoneType() { - return zoneType; - } public Long getVirtualMachineId() { return virtualMachineId; diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java index 17adb18ecc8..85a3c22a3e2 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java @@ -59,9 +59,6 @@ public class ListStoragePoolsCmd extends BaseListCmd { @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class, description="the Zone ID for the storage pool") 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.ID, type=CommandType.UUID, entityType = StoragePoolResponse.class, description="the ID of the storage pool") @@ -95,10 +92,6 @@ public class ListStoragePoolsCmd extends BaseListCmd { return zoneId; } - public String getZoneType() { - return zoneType; - } - public Long getId() { return id; } 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 d7e6bc87b7f..e4ae76908e8 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 @@ -26,6 +26,7 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.SnapshotResponse; import org.apache.cloudstack.api.response.VolumeResponse; +import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; import com.cloud.async.AsyncJob; @@ -62,6 +63,9 @@ public class ListSnapshotsCmd extends BaseListTaggedResourcesCmd { @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 /////////////////////// ///////////////////////////////////////////////////// @@ -89,6 +93,10 @@ public class ListSnapshotsCmd extends BaseListTaggedResourcesCmd { public String getZoneType() { return zoneType; } + + public Long getZoneId() { + return zoneId; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java index b2a2ce071f1..d3b29db2801 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java @@ -78,9 +78,6 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd { @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class, description="the availability zone ID") 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.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="list by network type; true if need to list vms using Virtual Network, false otherwise") private Boolean forVirtualNetwork; @@ -149,10 +146,6 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd { return zoneId; } - public String getZoneType() { - return zoneType; - } - public Boolean getForVirtualNetwork() { return forVirtualNetwork; } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java index 91316b02167..0bced56918b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java @@ -67,8 +67,6 @@ public class ListVolumesCmd extends BaseListTaggedResourcesCmd { description="the ID of the availability 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 /////////////////////// @@ -103,9 +101,6 @@ public class ListVolumesCmd extends BaseListTaggedResourcesCmd { return zoneId; } - public String getZoneType() { - return zoneType; - } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// diff --git a/api/src/org/apache/cloudstack/api/response/FirewallResponse.java b/api/src/org/apache/cloudstack/api/response/FirewallResponse.java index 26d243386fc..13a04b68f0b 100644 --- a/api/src/org/apache/cloudstack/api/response/FirewallResponse.java +++ b/api/src/org/apache/cloudstack/api/response/FirewallResponse.java @@ -39,10 +39,10 @@ public class FirewallResponse extends BaseResponse { private String endPort; @SerializedName(ApiConstants.IP_ADDRESS_ID) @Param(description="the public ip address id for the firewall rule") - private Long publicIpAddressId; + private String publicIpAddressId; @SerializedName(ApiConstants.NETWORK_ID) @Param(description="the network id of the firewall rule") - private Long networkId; + private String networkId; @SerializedName(ApiConstants.IP_ADDRESS) @Param(description="the public ip address for the firewall rule") private String publicIpAddress; @@ -78,7 +78,7 @@ public class FirewallResponse extends BaseResponse { this.endPort = endPort; } - public void setPublicIpAddressId(Long publicIpAddressId) { + public void setPublicIpAddressId(String publicIpAddressId) { this.publicIpAddressId = publicIpAddressId; } @@ -86,7 +86,7 @@ public class FirewallResponse extends BaseResponse { this.publicIpAddress = publicIpAddress; } - public void setNetworkId(Long networkId) { + public void setNetworkId(String networkId) { this.networkId = networkId; } diff --git a/api/src/org/apache/cloudstack/api/response/SnapshotResponse.java b/api/src/org/apache/cloudstack/api/response/SnapshotResponse.java index 7484ac965fd..ca74a18043b 100644 --- a/api/src/org/apache/cloudstack/api/response/SnapshotResponse.java +++ b/api/src/org/apache/cloudstack/api/response/SnapshotResponse.java @@ -93,6 +93,10 @@ public class SnapshotResponse extends BaseResponse implements ControlledEntityRe @Param(description = "the state of the snapshot. BackedUp means that snapshot is ready to be used; Creating - the snapshot is being allocated on the primary storage; BackingUp - the snapshot is being backed up on secondary storage") private Snapshot.State state; + @SerializedName(ApiConstants.ZONE_ID) + @Param(description = "id of the availability zone") + private String zoneId; + @SerializedName(ApiConstants.ZONE_NAME) @Param(description = "name of the availability zone") private String zoneName; @@ -181,6 +185,9 @@ public class SnapshotResponse extends BaseResponse implements ControlledEntityRe this.projectName = projectName; } + public void setZoneId(String zoneId) { + this.zoneId = zoneId; + } public void setZoneName(String zoneName) { this.zoneName = zoneName; } diff --git a/awsapi/src/com/cloud/bridge/service/controller/s3/ServiceProvider.java b/awsapi/src/com/cloud/bridge/service/controller/s3/ServiceProvider.java index 0f98518d8ef..a0892cc979b 100644 --- a/awsapi/src/com/cloud/bridge/service/controller/s3/ServiceProvider.java +++ b/awsapi/src/com/cloud/bridge/service/controller/s3/ServiceProvider.java @@ -91,8 +91,6 @@ public class ServiceProvider extends ManagerBase { // register service implementation object Transaction txn = Transaction.open(Transaction.AWSAPI_DB); txn.close(); - serviceMap.put(AmazonS3SkeletonInterface.class, new S3SerializableServiceImplementation(engine)); - serviceMap.put(AmazonEC2SkeletonInterface.class, new EC2SoapServiceImpl(EC2_engine)); } public synchronized static ServiceProvider getInstance() { @@ -101,7 +99,9 @@ public class ServiceProvider extends ManagerBase { @PostConstruct void initComponent() { - instance = this; + serviceMap.put(AmazonS3SkeletonInterface.class, new S3SerializableServiceImplementation(engine)); + serviceMap.put(AmazonEC2SkeletonInterface.class, new EC2SoapServiceImpl(EC2_engine)); + instance = this; } public boolean configure(String name, Map params) diff --git a/client/tomcatconf/nonossComponentContext.xml.in b/client/tomcatconf/nonossComponentContext.xml.in index 16fd88337fb..143aa220cfc 100644 --- a/client/tomcatconf/nonossComponentContext.xml.in +++ b/client/tomcatconf/nonossComponentContext.xml.in @@ -370,6 +370,7 @@ + diff --git a/core/src/com/cloud/agent/api/ScaleVmCommand.java b/core/src/com/cloud/agent/api/ScaleVmCommand.java index 35d22ad9d96..b3614856361 100644 --- a/core/src/com/cloud/agent/api/ScaleVmCommand.java +++ b/core/src/com/cloud/agent/api/ScaleVmCommand.java @@ -23,7 +23,8 @@ public class ScaleVmCommand extends Command { VirtualMachineTO vm; String vmName; int cpus; - Integer speed; + Integer minSpeed; + Integer maxSpeed; long minRam; long maxRam; @@ -40,14 +41,15 @@ public class ScaleVmCommand extends Command { } public ScaleVmCommand(String vmName, int cpus, - Integer speed, long minRam, long maxRam, boolean limitCpuUse) { + Integer minSpeed, Integer maxSpeed, long minRam, long maxRam, boolean limitCpuUse) { super(); this.vmName = vmName; this.cpus = cpus; - this.speed = speed; + this.minSpeed = minSpeed; + this.maxSpeed = maxSpeed; this.minRam = minRam; this.maxRam = maxRam; - this.vm = new VirtualMachineTO(1L, vmName, null, cpus, speed, minRam, maxRam, null, null, false, false, null); + this.vm = new VirtualMachineTO(1L, vmName, null, cpus, minSpeed, maxSpeed, minRam, maxRam, null, null, false, limitCpuUse, null); /*vm.setName(vmName); vm.setCpus(cpus); vm.setRam(minRam, maxRam);*/ @@ -57,14 +59,22 @@ public class ScaleVmCommand extends Command { this.cpus = cpus; } - public Integer getSpeed() { - return speed; + public Integer getMinSpeed() { + return minSpeed; } - public void setSpeed(Integer speed) { - this.speed = speed; + public void setMinSpeed(Integer minSpeed) { + this.minSpeed = minSpeed; } + public Integer getMaxSpeed() { + return minSpeed; + } + + public void setMaxSpeed(Integer maxSpeed) { + this.maxSpeed = maxSpeed; + } + public long getMinRam() { return minRam; } diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java index 9e40eefc11a..dae1c8591f4 100755 --- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java @@ -111,7 +111,7 @@ public class VirtualRoutingResource implements Manager { private String _routerProxyPath; private String _createIpAliasPath; private String _deleteIpAliasPath; - private String _configDhcpPath; + private String _callDnsMasqPath; private int _timeout; private int _startTimeout; @@ -625,7 +625,8 @@ public class VirtualRoutingResource implements Manager { String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); final Script command = new Script(_createIpAliasPath, _timeout, s_logger); List ipAliasTOs = cmd.getIpAliasList(); - String args=routerIp+" "; + String args = ""; + command.add(routerIp); for (IpAliasTO ipaliasto : ipAliasTOs) { args = args + ipaliasto.getAlias_count()+":"+ipaliasto.getRouterip()+":"+ipaliasto.getNetmask()+"-"; } @@ -637,7 +638,8 @@ public class VirtualRoutingResource implements Manager { protected Answer execute(final DeleteIpAliasCommand cmd) { final Script command = new Script(_deleteIpAliasPath, _timeout, s_logger); String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); - String args = ""; + String args =""; + command.add(routerIp); List revokedIpAliasTOs = cmd.getDeleteIpAliasTos(); for (IpAliasTO ipAliasTO : revokedIpAliasTOs) { args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-"; @@ -653,32 +655,26 @@ public class VirtualRoutingResource implements Manager { } protected Answer execute(final DnsMasqConfigCommand cmd) { - final Script command = new Script(_configDhcpPath, _timeout, s_logger); + final Script command = new Script(_callDnsMasqPath, _timeout, s_logger); String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); DnsMasqConfigurator configurator = new DnsMasqConfigurator(); String [] config = configurator.generateConfiguration(cmd); - File tmpCfgFile = null; + String cfgFileName = routerIp.replace(".","-")+"dns.cgf"; + String tmpCfgFileContents = ""; + for (int i = 0; i < config.length; i++) { + tmpCfgFileContents += config[i]; + tmpCfgFileContents += "\n"; + } + File permKey = new File("/root/.ssh/id_rsa.cloud"); + String cfgFilePath = "/tmp/"+cfgFileName; try { - String cfgFilePath = ""; - if (routerIp != null) { - tmpCfgFile = File.createTempFile(routerIp.replace('.', '_'), "cfg"); - final PrintWriter out - = new PrintWriter(new BufferedWriter(new FileWriter(tmpCfgFile))); - for (int i=0; i < config.length; i++) { - out.println(config[i]); - } - out.close(); - cfgFilePath = tmpCfgFile.getAbsolutePath(); - } + SshHelper.scpTo(routerIp, 3922, "root", permKey, null, "/tmp/", tmpCfgFileContents.getBytes(), cfgFileName, null); + command.add(routerIp); command.add(cfgFilePath); final String result = command.execute(); return new Answer(cmd, result == null, result); - } catch (final IOException e) { + } catch (Exception e) { return new Answer(cmd, false, e.getMessage()); - } finally { - if (tmpCfgFile != null) { - tmpCfgFile.delete(); - } } } @@ -1209,6 +1205,18 @@ public class VirtualRoutingResource implements Manager { if (_routerProxyPath == null) { throw new ConfigurationException("Unable to find router_proxy.sh"); } + _createIpAliasPath = findScript("createipAlias.sh"); + if (_createIpAliasPath == null) { + throw new ConfigurationException("unable to find createipAlias.sh"); + } + _deleteIpAliasPath = findScript("deleteipAlias.sh"); + if (_deleteIpAliasPath == null) { + throw new ConfigurationException("unable to find deleteipAlias.sh"); + } + _callDnsMasqPath = findScript("call_dnsmasq.sh"); + if (_callDnsMasqPath == null) { + throw new ConfigurationException("unable to find call_dnsmasq.sh"); + } return true; } diff --git a/docs/en-US/CloudStack_GSoC_Guide.xml b/docs/en-US/CloudStack_GSoC_Guide.xml index 243a0ca361b..1f435931363 100644 --- a/docs/en-US/CloudStack_GSoC_Guide.xml +++ b/docs/en-US/CloudStack_GSoC_Guide.xml @@ -49,6 +49,6 @@ - + diff --git a/docs/en-US/add-remove-nic-ui.xml b/docs/en-US/add-remove-nic-ui.xml new file mode 100644 index 00000000000..777ac7919fa --- /dev/null +++ b/docs/en-US/add-remove-nic-ui.xml @@ -0,0 +1,147 @@ + + +%BOOK_ENTITIES; +]> + +
+ Reconfiguring Physical Networks in VMs + &PRODUCT; provides you the ability to move VMs between networks and reconfigure a VM's + network. You can remove a VM from a physical network and add to a new physical network. You can + also change the default physical network of a virtual machine. With this functionality, hybrid + or traditional server loads can be accommodated with ease. + This feature is supported on XenServer and KVM hypervisors. +
+ Adding a Physical Network + + + Log in to the CloudPlatform UI as an administrator or end user. + + + In the left navigation, click Instances. + + + Choose the VM that you want to work with. + + + Click the NICs tab. + + + Click Add network to VM. + The Add network to VM dialog is displayed. + + + In the drop-down list, select the network that you would like to add this VM + to. + A new NIC is added for this network. You can view the following details in the NICs + page: + + + ID + + + Network Name + + + Type + + + IP Address + + + Gateway + + + Netmask + + + Is default + + + CIDR (for IPv6) + + + + +
+
+ Removing a Physical Network + + + Log in to the CloudPlatform UI as an administrator or end user. + + + In the left navigation, click Instances. + + + Choose the VM that you want to work with. + + + Click the NICs tab. + + + Locate the NIC you want to remove. + + + Click Remove NIC button. + + + + + remove-nic.png: button to remove a NIC + + + + + Click Yes to confirm. + + +
+
+ Selecting the Default Physical Network + + + Log in to the CloudPlatform UI as an administrator or end user. + + + In the left navigation, click Instances. + + + Choose the VM that you want to work with. + + + Click the NICs tab. + + + Locate the NIC you want to work with. + + + Click the Set default NIC button. + + + + + set-default-nic.png: button to set a NIC as default one. + + + + + Click Yes to confirm. + + +
+
diff --git a/docs/en-US/build-rpm.xml b/docs/en-US/build-rpm.xml index 7caf924bfe4..100a06f486e 100644 --- a/docs/en-US/build-rpm.xml +++ b/docs/en-US/build-rpm.xml @@ -48,6 +48,7 @@ under the License.
Generating RPMS Now that we have the prerequisites and source, you will cd to the packaging/centos63/ directory. + $ cd packaging/centos63 Generating RPMs is done using the package.sh script: $./package.sh diff --git a/docs/en-US/gsoc-meng.xml b/docs/en-US/gsoc-meng.xml new file mode 100644 index 00000000000..1de259dcac1 --- /dev/null +++ b/docs/en-US/gsoc-meng.xml @@ -0,0 +1,235 @@ + + +%BOOK_ENTITIES; +]> + + + + + Meng's 2013 GSoC Proposal + This chapter describes Meng's 2013 Google Summer of Code project within the &PRODUCT; ASF project. It is a copy paste of the submitted proposal. +
+ Project Description + + Getting a hadoop cluster going can be challenging and painful due to the tedious configuration phase and the diverse idiosyncrasies of each cloud provider. Apache Whirr[1] and Provisionr is a set of libraries for running cloud services in an automatic or semi-automatic fashion. They take advantage of a cloud-neutral library called jclouds[2] to create one-click, auto-configuring hadoop clusters on multiple clouds. Since jclouds supports CloudStack API, most of the services provided by Whirr and Provisionr should work out of the box on CloudStack. My first task is to test that assumption, make sure everything is well documented, and correct all issues with the latest version of CloudStack (4.0 and 4.1). + + + +The biggest challenge for hadoop provisioning is automatically configuring each instance at launch time based on what it is supposed to do, a process known as contextualization[3][4]. It causes last minute changes inside an instance to adapt to a cluster environment. Many automated cloud services are enabled by contextualization. For example in one-click hadoop clusters, contextualization basically amounts to generating and distributing ssh key pairs among instances, telling an instance where the master node is and what other slave nodes it should be aware of, etc. On EC2 contextualization is done via passing information through the EC2_USER_DATA entry[5][6]. Whirr and Provisionr embrace this feature to provision hadoop instances on EC2. My second task is to test and extend Whirr and Provisionr’s one-click solution on EC2 to CloudStack and also improve CloudStack’s support for Whirr and Provisionr to enable hadoop provisioning on CloudStack based clouds. + + +My third task is to add a Query API that is compatible with Amazon Elastic MapReduce (EMR) to CloudStack. Through this API, all hadoop provisioning functionality will be exposed and users can reuse cloud clients that are written for EMR to create and manage hadoop clusters on CloudStack based clouds. + +
+ +
+ Project Details + + Whirr defines four roles for the hadoop provisioning service: Namenode, JobTracker, Datanode and TaskTraker. With the help of CloudInit[7] (a popular package for cloud instance initialization), each VM instance is configured based on its role and a compressed file that is passed in the EC2_USER_DATA entry. Since CloudStack also supports EC2_USER_DATA, I think the most feasible way to have hadoop provisioning on CloudStack is to extend Whirr’s solution on EC2 to CloudStack platform and to make necessary adjustment based on CloudStack’s + + + + Whirr and Provisionr deal with two critical issues in their role configuration scripts (configure-hadoop-role_list): SSH key authentication and hostname configuration. + + + + SSH Key Authentication. The need for SSH Key based authentication is required so that the master node can login to slave nodes to start/stop hadoop daemons. Also each node needs to login to itself to start its own hadoop daemons. Traditionally this is done by generating a key pair on the master node and distributing the public key to all slave nodes. This can be only done with human intervention. Whirr works around this problem on EC2 by having a common key pair for all nodes in a hadoop cluster. Thus every node is able to login to one another. The key pair is provided by users and obtained by CloudInit inside an instance from metadata service. As far as I know, Cloudstack does not support user-provided ssh key authentication. Although CloudStack has the createSSHKeyPair API[8] to generate SSH keys and users can create an instance template that supports SSH keys, there is no easy way to have a unified SSH key on all cluster instances. Besides Whirr prefers minimal image management, so having a customized template doesn’t seem quite fit here. + + + Hostname configuration. The hostname of each instance has to be properly set and injected into the set of hadoop config files (core-site.xml, hdfs-site.xml, mapred-site.xml ). For an EC2 instance, its host name is converted from a combination of its public IP and an EC2-specific pre/suffix (e.g. an instance with IP 54.224.206.71 will have its hostname set to ec2-54-224-206-71.compute-1.amazonaws.com). This hostname amounts to the Fully Qualified Domain Name that uniquely identifies this node on the network. As for the case of CloudStack, if users do not specify a name the hostname that identifies a VM on a network will be a unique UUID generated by CloudStack[9]. + + + + + + + These two are the main issues that need support improvement on the CloudStack side. Other things like preparing disks, installing hadoop tarballs and starting hadoop daemons can be easily done as they are relatively role/instance-independent and static. Runurl can be used to simplify user-data scripts. + + + + + + After we achieve hadoop provisioning on CloudStack using Whirr we can go further to add a Query API to CloudStack to expose this functionality. I will write an API that is compatible with Amazon Elastic MapReduce Service (EMR)[10] so that users can reuse clients that are written for EMR to submit jobs to existing hadoop clusters, poll job status, terminate a hadoop instance and do other things on CloudStack based clouds. There are eight actions[11] now supported in EMR API. I will try to implement as many as I can during the period of GSoC. The following statements give some examples of the API that I will write. + + + +This will launch a new hadoop cluster with four instances using specified instance types and add a job flow to it. + + + +This will add a step to the existing job flow with ID j-3UN6WX5RRO2AG. This step will run the specified jar file. + + + +This will return the status of the given job flow. + +
+ +
+ Roadmap + + Jun. 17 ∼ Jun. 30 + + + Learn CloudStack and Apache Whirr/Provisionr APIs; Deploy a CloudStack cluster. + + + + Identify how EC2_USER_DATA is passed and executed on each CloudStack instance. + + + Figure out how the files passed in EC2_USER_DATA are acted upon by CloudInit. + + + Identify files in /etc/init/ that are used or modified by Whirr and Provisionr for hadoop related configuration. + + + Deploy a hadoop cluster on CloudStack via Whirr/Provisionr. This is to test what are missing in CloudStack or Whirr/Provisionr in terms of their support for each other. + + + Jul. 1∼ Aug. 1 + + + Write scripts to configure VM hostname on CloudStack with the help of CloudInit; + + + Write scripts to distribute SSH keys among CloudStack instances. Add the capability of using user-provided ssh key for authentication to CloudStack. + + + Take care of the other things left for hadoop provisioning, such as mounting disks, installing hadoop tarballs, etc. + + + Compose files that need to be passed in EC2_USER_DATA to each CloudStack instance . Test these files and write patches to make sure that Whirr/Provisionr can succefully deploy one-click hadoop clusters on CloudStack. + + + Aug. 3 ∼ Sep. 8 + + + Design and build an Elastic Mapreduce API for CloudStack that takes control of hadoop cluster creation and management. + + + Implement the eight actions defined in EMR API. This task might take a while. + + + + Sep. 10 ∼ Sep. 23 + + + + Code cleaning and documentation wrap up. + + + + + + +
+ +
+ Deliverables + + + + Whirr has limited support for CloudStack. Check what’s missing and make sure all steps are properly documented on the Whirr and CloudStack websites. + + + Contribute code to CloudStack and and send patches to Whirr/Provisionr if necessary to enable hadoop provisioning on CloudStack via Whirr/Provisionr. + + + Build an EMR-compatible API for CloudStack. + + +
+
+ Nice to have + In addition to the required deliverables, it’s nice to have the following: + + + + The capability to add and remove hadoop nodes dynamically to enable elastic hadoop clusters on CloudStack. + + + + A review of the existing tools that offer one-click provisioning and make sure that they support CloudStack based clouds. + + +
+ +
+ References + + + + + http://whirr.apache.org/ + + + http://www.jclouds.org/documentation/gettingstarted/what-is-jclouds/ + + + Katarzyna Keahey, Tim Freeman, Contextualization: Providing One-Click Virtual Clusters + + + http://www.nimbusproject.org/docs/current/clouds/clusters2.html + + + http://aws.amazon.com/amazon-linux-ami/ + + + https://svn.apache.org/repos/asf/whirr/branches/contrib-python/src/py/hadoop/cloud/data/hadoop-ec2-init-remote.sh + + + https://help.ubuntu.com/community/CloudInit + + + http://cloudstack.apache.org/docs/en-US/Apache_CloudStack/4.0.2/html/Installation_Guide/using-sshkeys.html + + + https://cwiki.apache.org/CLOUDSTACK/allow-user-provided-hostname-internal-vm-name-on-hypervisor-instead-of-cloud-platform-auto-generated-name-for-guest-vms.html + + +http://docs.aws.amazon.com/ElasticMapReduce/latest/API/Welcome.html + + + http://docs.aws.amazon.com/ElasticMapReduce/latest/API/API_Operations.html + + + http://buildacloud.org/blog/235-puppet-and-cloudstack.html + + +http://chriskleban-internet.blogspot.com/2012/03/build-cloud-cloudstack-instance.html + + + http://gehrcke.de/2009/06/aws-about-api/ + + + Apache_CloudStack-4.0.0-incubating-API_Developers_Guide-en-US.pdf + + + +
+ +
diff --git a/docs/en-US/images/remove-nic.png b/docs/en-US/images/remove-nic.png new file mode 100644 index 00000000000..27145cebbc7 Binary files /dev/null and b/docs/en-US/images/remove-nic.png differ diff --git a/docs/en-US/images/set-default-nic.png b/docs/en-US/images/set-default-nic.png new file mode 100644 index 00000000000..f329aef4a25 Binary files /dev/null and b/docs/en-US/images/set-default-nic.png differ diff --git a/docs/en-US/networks.xml b/docs/en-US/networks.xml index b557088273f..d1fc541659a 100644 --- a/docs/en-US/networks.xml +++ b/docs/en-US/networks.xml @@ -48,6 +48,7 @@ + diff --git a/docs/en-US/pvlan.xml b/docs/en-US/pvlan.xml index 96c1a78a85d..d569507f973 100644 --- a/docs/en-US/pvlan.xml +++ b/docs/en-US/pvlan.xml @@ -21,18 +21,65 @@ -->
Isolation in Advanced Zone Using Private VLAN - + Isolation of guest traffic in shared networks can be achieved by using Private VLANs + (PVLAN). PVLANs provide Layer 2 isolation between ports within the same VLAN. In a PVLAN-enabled + shared network, a user VM cannot reach other user VM though they can reach the DHCP server and + gateway, this would in turn allow users to control traffic within a network and help them deploy + multiple applications without communication between application as well as prevent communication + with other users’ VMs. + + + Isolate VMs in a shared networks by using Private VLANs. + + + Supported on KVM, XenServer, and VMware hypervisors + + + PVLAN-enabled shared network can be a part of multiple networks of a guest VM. + +
About Private VLAN - In an Ethernet switch, a VLAN is a broadcast domain in which hosts can establish direct + In an Ethernet switch, a VLAN is a broadcast domain where hosts can establish direct communication with each another at Layer 2. Private VLAN is designed as an extension of VLAN standard to add further segmentation of the logical broadcast domain. A regular VLAN is a single broadcast domain, whereas a private VLAN partitions a larger VLAN broadcast domain into smaller sub-domains. A sub-domain is represented by a pair of VLANs: a Primary VLAN and a - Secondary VLAN. The original VLAN that is being divided into smaller groups is called - Primary, That implies all VLAN pairs in a private VLAN share the same Primary VLAN. All the + Secondary VLAN. The original VLAN that is being divided into smaller groups is called Primary, + which implies that all VLAN pairs in a private VLAN share the same Primary VLAN. All the secondary VLANs exist only inside the Primary. Each Secondary VLAN has a specific VLAN ID - associated to it, which differentiates one sub-domain from another. + associated to it, which differentiates one sub-domain from another. + Three types of ports exist in a private VLAN domain, which essentially determine the + behaviour of the participating hosts. Each ports will have its own unique set of rules, which + regulate a connected host's ability to communicate with other connected host within the same + private VLAN domain. Configure each host that is part of a PVLAN pair can be by using one of + these three port designation: + + + Promiscuous: A promiscuous port can communicate with + all the interfaces, including the community and isolated host ports that belong to the + secondary VLANs. In Promiscuous mode, hosts are connected to promiscuous ports and are + able to communicate directly with resources on both primary and secondary VLAN. Routers, + DHCP servers, and other trusted devices are typically attached to promiscuous + ports. + + + Isolated VLANs: The ports within an isolated VLAN + cannot communicate with each other at the layer-2 level. The hosts that are connected to + Isolated ports can directly communicate only with the Promiscuous resources. If your + customer device needs to have access only to a gateway router, attach it to an isolated + port. + + + Community VLANs: The ports within a community VLAN + can communicate with each other and with the promiscuous ports, but they cannot + communicate with the ports in other communities at the layer-2 level. In a Community mode, + direct communication is permitted only with the hosts in the same community and those that + are connected to the Primary PVLAN in promiscuous mode. If your customer has two devices + that need to be isolated from other customers' devices, but to be able to communicate + among themselves, deploy them in community ports. + + For further reading: @@ -52,6 +99,149 @@
Prerequisites - Ensure that you configure private VLAN on your physical switches out-of-band. + + + Use a PVLAN supported switch. + See Private VLAN Catalyst Switch Support Matrixfor more information. + + + All the layer 2 switches, which are PVLAN-aware, are connected to each other, and one + of them is connected to a router. All the ports connected to the host would be configured + in trunk mode. Open Management VLAN, Primary VLAN (public) and Secondary Isolated VLAN + ports. Configure the switch port connected to the router in PVLAN promiscuous trunk mode, + which would translate an isolated VLAN to primary VLAN for the PVLAN-unaware router. + Note that only Cisco Catalyst 4500 has the PVLAN promiscuous trunk mode to connect + both normal VLAN and PVLAN to a PVLAN-unaware switch. For other Catalyst PVLAN support + switch, connect the switch to upper switch by using cables. The number of cables should be + greater than the number of PVLANs used. + + + Configure private VLAN on your physical switches out-of-band. + + + Before you use PVLAN on XenServer and KVM, enable Open vSwitch (OVS) . + + OVS on XenServer and KVM does not support PVLAN. Therefore, simulate PVLAN on OVS + for XenServer and KVM by modifying the flow table and tagging every traffic leaving + guest VMs with the secondary VLAN ID. + + + +
+
+ Creating a PVLAN-Enabled Guest Network + + + Log in to the CloudPlatform UI as administrator. + + + In the left navigation, choose Infrastructure. + + + On Zones, click View More. + + + Click the zone to which you want to add a guest network. + + + Click the Physical Network tab. + + + Click the physical network you want to work with. + + + On the Guest node of the diagram, click Configure. + + + Click the Network tab. + + + Click Add guest network. + The Add guest network window is displayed. + + + Specify the following: + + + Name: The name of the network. This will be + visible to the user. + + + Description: The short description of the network + that can be displayed to users. + + + VLAN ID: The unique ID of the VLAN. + + + Isolated VLAN ID: The unique ID of the Secondary + Isolated VLAN. + For the description on Secondary Isolated VLAN, see . + + + Scope: The available scopes are Domain, Account, + Project, and All. + + + Domain: Selecting Domain limits the scope of + this guest network to the domain you specify. The network will not be available + for other domains. If you select Subdomain Access, the guest network is available + to all the sub domains within the selected domain. + + + Account: The account for which the guest + network is being created for. You must specify the domain the account belongs + to. + + + Project: The project for which the guest + network is being created for. You must specify the domain the project belongs + to. + + + All: The guest network is available for all + the domains, account, projects within the selected zone. + + + + + Network Offering: If the administrator has + configured multiple network offerings, select the one you want to use for this + network. + + + Gateway: The gateway that the guests should + use. + + + Netmask: The netmask in use on the subnet the + guests will use. + + + IP Range: A range of IP addresses that are + accessible from the Internet and are assigned to the guest VMs. + If one NIC is used, these IPs should be in the same CIDR in the case of + IPv6. + + + IPv6 CIDR: The network prefix that defines the + guest network subnet. This is the CIDR that describes the IPv6 addresses in use in the + guest networks in this zone. To allot IP addresses from within a particular address + block, enter a CIDR. + + + Network Domain: A custom DNS suffix at the level + of a network. If you want to assign a special domain name to the guest VM network, + specify a DNS suffix. + + + + + Click OK to confirm. + +
diff --git a/docs/en-US/using-multiple-guest-networks.xml b/docs/en-US/using-multiple-guest-networks.xml index 4e7da1e187f..cb7e9c73be3 100644 --- a/docs/en-US/using-multiple-guest-networks.xml +++ b/docs/en-US/using-multiple-guest-networks.xml @@ -28,5 +28,6 @@ Each VM has just one default network. The virtual router's DHCP reply will set the guest's default gateway as that for the default network. Multiple non-default networks may be added to a guest in addition to the single, required default network. The administrator can control which networks are available as the default network. Additional networks can either be available to all accounts or be assigned to a specific account. Networks that are available to all accounts are zone-wide. Any user with access to the zone can create a VM with access to that network. These zone-wide networks provide little or no isolation between guests.Networks that are assigned to a specific account provide strong isolation. +
diff --git a/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java index ca299ea45bc..96fb1d91936 100755 --- a/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java @@ -25,6 +25,7 @@ import java.util.Map; import javax.inject.Inject; +import com.cloud.storage.VolumeManager; import org.apache.cloudstack.engine.cloud.entity.api.NetworkEntity; import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity; import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity; @@ -87,6 +88,9 @@ public class CloudOrchestrator implements OrchestrationService { @Inject protected AccountDao _accountDao = null; + @Inject + VolumeManager _volumeMgr; + public CloudOrchestrator() { } @@ -200,6 +204,7 @@ public class CloudOrchestrator implements OrchestrationService { "Disk offering " + diskOffering + " requires size parameter."); } + _volumeMgr.validateVolumeSizeRange(size * 1024 * 1024 * 1024); } dataDiskOfferings.add(new Pair(diskOffering, size)); } @@ -246,7 +251,8 @@ public class CloudOrchestrator implements OrchestrationService { throw new InvalidParameterValueException("Disk offering " + diskOffering + " requires size parameter."); } - } + _volumeMgr.validateVolumeSizeRange(size * 1024 * 1024 * 1024); + } rootDiskOffering.first(diskOffering); rootDiskOffering.second(size); diff --git a/engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java b/engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java index 0b9ff1a5ece..d14ad877ec9 100755 --- a/engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java +++ b/engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java @@ -116,11 +116,27 @@ public class CapacityDaoImpl extends GenericDaoBase implements private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2 = " GROUP BY cluster_id, capacity_type order by percent desc limit "; private static final String UPDATE_CAPACITY_STATE = "UPDATE `cloud`.`op_host_capacity` SET capacity_state = ? WHERE "; + /* In the below query"LIST_CLUSTERS_CROSSING_THRESHOLD" the threshold value is getting from the cluster_details table if not present then it gets from the global configuration + * + * CASE statement works like + * if (cluster_details table has thershold value) + * then + * if (value from the cluster_details table is not null) + * then + * query from the cluster_details table + * else + * query from the configuration table + * else + * query from the configuration table + * + * */ private static final String LIST_CLUSTERS_CROSSING_THRESHOLD = "SELECT clusterList.cluster_id " + "FROM ( SELECT cluster.cluster_id cluster_id, ( (sum(cluster.used) + sum(cluster.reserved) + ?)/sum(cluster.total) ) ratio, cluster.configValue value " + "FROM ( SELECT capacity.cluster_id cluster_id, capacity.used_capacity used, capacity.reserved_capacity reserved, capacity.total_capacity total, " + "CASE (SELECT count(*) FROM `cloud`.`cluster_details` details WHERE details.cluster_id = capacity.cluster_id AND details.name = ? ) " + - "WHEN 1 THEN ( SELECT details.value FROM `cloud`.`cluster_details` details WHERE details.cluster_id = capacity.cluster_id AND details.name = ? ) " + + "WHEN 1 THEN ( CASE WHEN (SELECT details.value FROM `cloud`.`cluster_details` details WHERE details.cluster_id = capacity.cluster_id AND details.name = ?) is NULL " + + "THEN (SELECT config.value FROM `cloud`.`configuration` config WHERE config.name = ?)" + + "ELSE (SELECT details.value FROM `cloud`.`cluster_details` details WHERE details.cluster_id = capacity.cluster_id AND details.name = ? ) END )" + "ELSE ( SELECT config.value FROM `cloud`.`configuration` config WHERE config.name = ?) " + "END configValue " + "FROM `cloud`.`op_host_capacity` capacity " + @@ -168,8 +184,10 @@ public class CapacityDaoImpl extends GenericDaoBase implements pstmt.setString(2, configName); pstmt.setString(3, configName); pstmt.setString(4, configName); - pstmt.setLong(5,zoneId); - pstmt.setShort(6,capacityType); + pstmt.setString(5, configName); + pstmt.setString(6, configName); + pstmt.setLong(7,zoneId); + pstmt.setShort(8,capacityType); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java index 1839ca45476..886011ecc31 100755 --- a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java +++ b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java @@ -155,6 +155,7 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen address.setAssociatedWithNetworkId(null); address.setVpcId(null); address.setSystem(false); + address.setVmIp(null); update(ipAddressId, address); } diff --git a/engine/schema/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java b/engine/schema/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java index 682a941856c..9a1d321ae91 100644 --- a/engine/schema/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java +++ b/engine/schema/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java @@ -43,5 +43,5 @@ public interface PortForwardingRulesDao extends GenericDao listByAccount(long accountId); List listByDestIpAddr(String ip4Address); - + PortForwardingRuleVO findByIdAndIp(long id, String secondaryIp); } diff --git a/engine/schema/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java b/engine/schema/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java index cc780cbd446..c0db7800378 100644 --- a/engine/schema/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java +++ b/engine/schema/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java @@ -158,5 +158,12 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase sc = AllFieldsSearch.create(); + sc.setParameters("id", id); + sc.setParameters("dstIp", secondaryIp); + return findOneBy(sc); + } } diff --git a/engine/schema/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java index 662ad4354a4..76359223bb3 100644 --- a/engine/schema/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java +++ b/engine/schema/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java @@ -62,7 +62,6 @@ public class SnapshotPolicyDaoImpl extends GenericDaoBase listByVolumeId(long volumeId, Filter filter) { SearchCriteria sc = VolumeIdSearch.create(); sc.setParameters("volumeId", volumeId); - sc.setParameters("active", true); return listBy(sc, filter); } diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java index 521ddd3de89..8f63a6c9485 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -105,6 +105,7 @@ public class Upgrade410to420 implements DbUpgrade { //First drop if it exists. (Due to patches shipped to customers some will have the index and some wont.) List indexList = new ArrayList(); s_logger.debug("Dropping index i_alert__last_sent if it exists"); + indexList.add("last_sent"); // in 4.1, we created this index that is not in convention. indexList.add("i_alert__last_sent"); DbUpgradeUtils.dropKeysIfExist(conn, "alert", indexList, false); diff --git a/engine/schema/src/com/cloud/usage/dao/UsageDao.java b/engine/schema/src/com/cloud/usage/dao/UsageDao.java index 8a806553112..f571b63ce40 100644 --- a/engine/schema/src/com/cloud/usage/dao/UsageDao.java +++ b/engine/schema/src/com/cloud/usage/dao/UsageDao.java @@ -38,6 +38,7 @@ public interface UsageDao extends GenericDao { Long getLastUserStatsId(); List listPublicTemplatesByAccount(long accountId); Long getLastVmDiskStatsId(); - void updateVmDiskStats(List vmNetStats); - void saveVmDiskStats(List vmNetStats); + void updateVmDiskStats(List vmDiskStats); + void saveVmDiskStats(List vmDiskStats); + void saveUsageRecords(List usageRecords); } diff --git a/engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java b/engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java index f7d5069eef9..2237d56dd72 100644 --- a/engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java +++ b/engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java @@ -18,6 +18,7 @@ package com.cloud.usage.dao; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.Timestamp; import java.sql.Types; import java.util.ArrayList; import java.util.Date; @@ -63,6 +64,8 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage " VALUES (?,?,?,?,?,?,?,?,?,?, ?, ?, ?, ?,?, ?, ?)"; private static final String UPDATE_VM_DISK_STATS = "UPDATE cloud_usage.vm_disk_statistics SET net_io_read=?, net_io_write=?, current_io_read=?, current_io_write=?, agg_io_read=?, agg_io_write=?, " + "net_bytes_read=?, net_bytes_write=?, current_bytes_read=?, current_bytes_write=?, agg_bytes_read=?, agg_bytes_write=? WHERE id=?"; + private static final String INSERT_USGAE_RECORDS = "INSERT INTO cloud_usage.cloud_usage (zone_id, account_id, domain_id, description, usage_display, usage_type, raw_usage, vm_instance_id, vm_name, offering_id, template_id, " + + "usage_id, type, size, network_id, start_date, end_date) VALUES (?,?,?,?,?,?,?,?,?, ?, ?, ?,?,?,?,?,?)"; protected final static TimeZone s_gmtTimeZone = TimeZone.getTimeZone("GMT"); @@ -375,4 +378,65 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage } } + + @Override + public void saveUsageRecords(List usageRecords) { + Transaction txn = Transaction.currentTxn(); + try { + txn.start(); + String sql = INSERT_USGAE_RECORDS; + PreparedStatement pstmt = null; + pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just want CLOUD_USAGE dataSource connection + for (UsageVO usageRecord : usageRecords) { + pstmt.setLong(1, usageRecord.getZoneId()); + pstmt.setLong(2, usageRecord.getAccountId()); + pstmt.setLong(3, usageRecord.getDomainId()); + pstmt.setString(4, usageRecord.getDescription()); + pstmt.setString(5, usageRecord.getUsageDisplay()); + pstmt.setInt(6, usageRecord.getUsageType()); + pstmt.setDouble(7, usageRecord.getRawUsage()); + if(usageRecord.getVmInstanceId() != null){ + pstmt.setLong(8, usageRecord.getVmInstanceId()); + } else { + pstmt.setNull(8, Types.BIGINT); + } + pstmt.setString(9, usageRecord.getVmName()); + if(usageRecord.getOfferingId() != null){ + pstmt.setLong(10, usageRecord.getOfferingId()); + } else { + pstmt.setNull(10, Types.BIGINT); + } + if(usageRecord.getTemplateId() != null){ + pstmt.setLong(11, usageRecord.getTemplateId()); + } else { + pstmt.setNull(11, Types.BIGINT); + } + if(usageRecord.getUsageId() != null){ + pstmt.setLong(12, usageRecord.getUsageId()); + } else { + pstmt.setNull(12, Types.BIGINT); + } + pstmt.setString(13, usageRecord.getType()); + if(usageRecord.getSize() != null){ + pstmt.setLong(14, usageRecord.getSize()); + } else { + pstmt.setNull(14, Types.BIGINT); + } + if(usageRecord.getNetworkId() != null){ + pstmt.setLong(15, usageRecord.getNetworkId()); + } else { + pstmt.setNull(15, Types.BIGINT); + } + pstmt.setTimestamp(16, new Timestamp(usageRecord.getStartDate().getTime())); + pstmt.setTimestamp(17, new Timestamp(usageRecord.getEndDate().getTime())); + pstmt.addBatch(); + } + pstmt.executeBatch(); + txn.commit(); + } catch (Exception ex) { + txn.rollback(); + s_logger.error("error saving usage records to cloud_usage db", ex); + throw new CloudRuntimeException(ex.getMessage()); + } + } } diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 60d2aebe91f..3c7e24d1f6a 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -3231,7 +3231,9 @@ ServerResource { ConsoleDef console = new ConsoleDef("pty", null, null, (short) 0); devices.addDevice(console); - GraphicDef grap = new GraphicDef("vnc", (short) 0, true, null, null, + //add the VNC port passwd here, get the passwd from the vmInstance. + String passwd = vmTO.getVncPassword(); + GraphicDef grap = new GraphicDef("vnc", (short) 0, true, null, passwd, null); devices.addDevice(grap); diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeDef.java index 7f9ceebe742..92f6e3958c1 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeDef.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeDef.java @@ -73,7 +73,7 @@ public class LibvirtStorageVolumeDef { storageVolBuilder.append("" + _volName + "\n"); if (_volSize != null) { storageVolBuilder - .append("" + _volSize + "\n"); + .append("" + _volSize + "\n"); } storageVolBuilder.append("\n"); storageVolBuilder.append("\n"); diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index 345b4e8e71c..3ee13480c5d 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -951,7 +951,7 @@ public class LibvirtVMDef { if (_listenAddr != null) { graphicBuilder.append(" listen='" + _listenAddr + "'"); } else { - graphicBuilder.append(" listen='' "); + graphicBuilder.append(" listen=''"); } if (_passwd != null) { graphicBuilder.append(" passwd='" + _passwd + "'"); diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java index 0bafd073f68..c82c31fc510 100644 --- a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java +++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java @@ -80,7 +80,7 @@ public class LibvirtComputingResourceTest { vmStr += "\n"; vmStr += "\n"; vmStr += "\n"; - vmStr += "\n"; + vmStr += "\n"; vmStr += "\n"; vmStr += "\n"; vmStr += "\n"; @@ -156,7 +156,7 @@ public class LibvirtComputingResourceTest { vmStr += "\n"; vmStr += "\n"; vmStr += "\n"; - vmStr += "\n"; + vmStr += "\n"; vmStr += "\n"; vmStr += "\n"; vmStr += "\n"; diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 34766a0d794..c35024c1cf1 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -832,7 +832,53 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa return new SetFirewallRulesAnswer(cmd, true, results); } + protected SetStaticNatRulesAnswer SetVPCStaticNatRules(SetStaticNatRulesCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource SetVPCStaticNatRulesCommand: " + _gson.toJson(cmd)); + } + + String[] results = new String[cmd.getRules().length]; + VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME); + String controlIp = getRouterSshControlIp(cmd); + + int i = 0; + boolean endResult = true; + for (StaticNatRuleTO rule : cmd.getRules()) { + // Prepare command to be send to VPC VR + String args = ""; + args += rule.revoked() ? " -D" : " -A"; + args += " -l " + rule.getSrcIp(); + args += " -r " + rule.getDstIp(); + + // Invoke command on VPC VR. + try { + Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null, "/opt/cloud/bin/vpc_staticnat.sh " + args); + + if (s_logger.isDebugEnabled()) + s_logger.debug("Executing script on domain router " + controlIp + ": /opt/cloud/bin/vpc_staticnat.sh " + args); + + if (!result.first()) { + s_logger.error("SetVPCStaticNatRulesCommand failure on setting one rule. args: " + args); + results[i++] = "Failed"; + endResult = false; + } else { + results[i++] = null; + } + } catch (Throwable e) { + s_logger.error("SetVPCStaticNatRulesCommand (args: " + args + ") failed on setting one rule due to " + VmwareHelper.getExceptionMessage(e), e); + results[i++] = "Failed"; + endResult = false; + } + } + return new SetStaticNatRulesAnswer(cmd, results, endResult); + } + protected Answer execute(SetStaticNatRulesCommand cmd) { + + if (cmd.getVpcId() != null) { + return SetVPCStaticNatRules(cmd); + } + if (s_logger.isInfoEnabled()) { s_logger.info("Executing resource SetFirewallRuleCommand: " + _gson.toJson(cmd)); } @@ -1236,9 +1282,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa if (!result.first()) { String msg = "SetNetworkACLAnswer on domain router " + routerIp + " failed. message: " + result.second(); s_logger.error(msg); + return new SetNetworkACLAnswer(cmd, false, results); } - - return new SetNetworkACLAnswer(cmd, false, results); } else { args=""; args += " -d " + "eth" + ethDeviceNum; @@ -1283,7 +1328,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa args += rule.revoked() ? " -D" : " -A"; args += " -P " + rule.getProtocol().toLowerCase(); args += " -l " + rule.getSrcIp(); - args += " -p " + rule.getStringSrcPortRange().replace(":", "-"); + args += " -p " + rule.getStringSrcPortRange(); args += " -r " + rule.getDstIp(); args += " -d " + rule.getStringDstPortRange().replace(":", "-"); @@ -2313,9 +2358,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa VmwareHypervisorHost hyperHost = getHyperHost(context); VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName()); VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); - int ramMb = (int) (vmSpec.getMinRam()); + int ramMb = (int) (vmSpec.getMinRam()/(1024 * 1024)); - VmwareHelper.setVmScaleUpConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getSpeed(), vmSpec.getSpeed(),(int) (vmSpec.getMaxRam()), ramMb, vmSpec.getLimitCpuUse()); + VmwareHelper.setVmScaleUpConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(), vmSpec.getMinSpeed(),(int) (vmSpec.getMaxRam()/(1024 * 1024)), ramMb, vmSpec.getLimitCpuUse()); if(!vmMo.configureVm(vmConfigSpec)) { throw new Exception("Unable to execute ScaleVmCommand"); @@ -3486,7 +3531,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa tgtHyperHost = new HostMO(getServiceContext(), morTgtHost); morDc = srcHyperHost.getHyperHostDatacenter(); morDcOfTargetHost = tgtHyperHost.getHyperHostDatacenter(); - if (morDc != morDcOfTargetHost) { + if (!morDc.getValue().equalsIgnoreCase(morDcOfTargetHost.getValue())) { String msg = "Source host & target host are in different datacentesr"; throw new CloudRuntimeException(msg); } diff --git a/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/resource/VmwareResourceTest.java b/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/resource/VmwareResourceTest.java index 3ca0b600e36..2f7160873a8 100644 --- a/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/resource/VmwareResourceTest.java +++ b/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/resource/VmwareResourceTest.java @@ -68,10 +68,11 @@ public class VmwareResourceTest { when(_resource.getHyperHost(context, null)).thenReturn(hyperHost); doReturn("i-2-3-VM").when(cmd).getVmName(); when(hyperHost.findVmOnHyperHost("i-2-3-VM")).thenReturn(vmMo); - doReturn(1024L).when(vmSpec).getMinRam(); + doReturn(536870912L).when(vmSpec).getMinRam(); doReturn(1).when(vmSpec).getCpus(); - doReturn(1000).when(vmSpec).getSpeed(); - doReturn(1024L).when(vmSpec).getMaxRam(); + doReturn(1000).when(vmSpec).getMinSpeed(); + doReturn(1000).when(vmSpec).getMaxSpeed(); + doReturn(536870912L).when(vmSpec).getMaxRam(); doReturn(false).when(vmSpec).getLimitCpuUse(); when(vmMo.configureVm(vmConfigSpec)).thenReturn(true); diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java index 6d9265db2dd..e360c984619 100755 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java @@ -445,6 +445,10 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L return new XenServer602Resource(); else if (prodBrand.equals("XenServer") && prodVersion.equals("6.1.0")) return new XenServer610Resource(); + else if (prodBrand.equals("XenServer") && prodVersion.equals("6.1.83")) + return new XenServer610Resource(); + else if (prodBrand.equals("XenServer") && prodVersion.equals("6.2.0")) + return new XenServer610Resource(); else if (prodBrand.equals("XenServer") && prodVersion.equals("5.6.100")) { String prodVersionTextShort = record.softwareVersion.get("product_version_text_short").trim(); if ("5.6 SP2".equals(prodVersionTextShort)) { @@ -453,11 +457,11 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L return new XenServer56FP1Resource(); } } else if (prodBrand.equals("XCP_Kronos")) { - return new XcpOssResource(); - } - - String msg = "Only support XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x; XenServer 5.6, XenServer 5.6 FP1, XenServer 5.6 SP2, Xenserver 6.0, 6.0.2, 6.1.0 but this one is " + prodBrand + " " + prodVersion; - _alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg); + return new XcpOssResource(); + } + + String msg = "Only support XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x; XenServer 5.6, XenServer 5.6 FP1, XenServer 5.6 SP2, Xenserver 6.0, 6.0.2, 6.1.0, 6.1.83, 6.2.0 but this one is " + prodBrand + " " + prodVersion; + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg); s_logger.debug(msg); throw new RuntimeException(msg); @@ -596,6 +600,10 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L resource = XenServer602Resource.class.getName(); } else if (prodBrand.equals("XenServer") && prodVersion.equals("6.1.0")) { resource = XenServer610Resource.class.getName(); + } else if (prodBrand.equals("XenServer") && prodVersion.equals("6.1.83")) { + resource = XenServer610Resource.class.getName(); + } else if (prodBrand.equals("XenServer") && prodVersion.equals("6.2.0")) { + resource = XenServer610Resource.class.getName(); } else if (prodBrand.equals("XenServer") && prodVersion.equals("5.6.100")) { String prodVersionTextShort = details.get("product_version_text_short").trim(); if ("5.6 SP2".equals(prodVersionTextShort)) { @@ -608,7 +616,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L } if( resource == null ){ - String msg = "Only support XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x; XenServer 5.6, 5.6 FP1, 5.6 SP2 and Xenserver 6.0 , 6.0.2, 6.1.0 but this one is " + prodBrand + " " + prodVersion; + String msg = "Only support XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x; XenServer 5.6, 5.6 FP1, 5.6 SP2 and Xenserver 6.0 , 6.0.2, 6.1.0, 6.1.83, 6.2.0 but this one is " + prodBrand + " " + prodVersion; s_logger.debug(msg); throw new RuntimeException(msg); } diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index ab259b9143b..ae8fb753a5b 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -687,16 +687,16 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe Long staticMemoryMax = vm.getMemoryStaticMax(conn); Long staticMemoryMin = vm.getMemoryStaticMin(conn); - Long newDynamicMemoryMin = vmSpec.getMinRam() * 1024 * 1024; - Long newDynamicMemoryMax = vmSpec.getMaxRam() * 1024 * 1024; + Long newDynamicMemoryMin = vmSpec.getMinRam(); + Long newDynamicMemoryMax = vmSpec.getMaxRam(); if (staticMemoryMin > newDynamicMemoryMin || newDynamicMemoryMax > staticMemoryMax) { throw new CloudRuntimeException("Cannot scale up the vm because of memory constraint violation: 0 <= memory-static-min <= memory-dynamic-min <= memory-dynamic-max <= memory-static-max "); } - vm.setMemoryDynamicRange(conn, vmSpec.getMinRam() * 1024 * 1024, vmSpec.getMaxRam() * 1024 * 1024); + vm.setMemoryDynamicRange(conn, newDynamicMemoryMin, newDynamicMemoryMax); vm.setVCPUsNumberLive(conn, (long)vmSpec.getCpus()); - Integer speed = vmSpec.getSpeed(); + Integer speed = vmSpec.getMinSpeed(); if (speed != null) { int cpuWeight = _maxWeight; //cpu_weight diff --git a/plugins/hypervisors/xen/test/com/cloud/hypervisor/xen/resource/CitrixResourceBaseTest.java b/plugins/hypervisors/xen/test/com/cloud/hypervisor/xen/resource/CitrixResourceBaseTest.java index 3328d4be50c..cb16ae2be15 100644 --- a/plugins/hypervisors/xen/test/com/cloud/hypervisor/xen/resource/CitrixResourceBaseTest.java +++ b/plugins/hypervisors/xen/test/com/cloud/hypervisor/xen/resource/CitrixResourceBaseTest.java @@ -113,10 +113,14 @@ public class CitrixResourceBaseTest { @Test public void testScaleVMF2() throws Types.XenAPIException, XmlRpcException { + when(vm.getMemoryStaticMax(conn)).thenReturn(1073741824L); + when(vm.getMemoryStaticMin(conn)).thenReturn(268435456L); + doReturn(536870912L).when(vmSpec).getMinRam(); + doReturn(536870912L).when(vmSpec).getMaxRam(); doNothing().when(vm).setMemoryDynamicRange(conn, 536870912L, 536870912L); doReturn(1).when(vmSpec).getCpus(); doNothing().when(vm).setVCPUsNumberLive(conn, 1L); - doReturn(500).when(vmSpec).getSpeed(); + doReturn(500).when(vmSpec).getMinSpeed(); doReturn(false).when(vmSpec).getLimitCpuUse(); Map args = (Map)mock(HashMap.class); when(host.callPlugin(conn, "vmops", "add_to_VCPUs_params_live", args)).thenReturn("Success"); @@ -132,10 +136,14 @@ public class CitrixResourceBaseTest { @Test public void testScaleVMF3() throws Types.XenAPIException, XmlRpcException { + when(vm.getMemoryStaticMax(conn)).thenReturn(1073741824L); + when(vm.getMemoryStaticMin(conn)).thenReturn(268435456L); + doReturn(536870912L).when(vmSpec).getMinRam(); + doReturn(536870912L).when(vmSpec).getMaxRam(); doNothing().when(vm).setMemoryDynamicRange(conn, 536870912L, 536870912L); doReturn(1).when(vmSpec).getCpus(); doNothing().when(vm).setVCPUsNumberLive(conn, 1L); - doReturn(500).when(vmSpec).getSpeed(); + doReturn(500).when(vmSpec).getMinSpeed(); doReturn(true).when(vmSpec).getLimitCpuUse(); doReturn(null).when(_resource).callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", "100", "vmname", "i-2-3-VM"); Map args = (Map)mock(HashMap.class); diff --git a/scripts/network/domr/call_dnsmasq.sh b/scripts/network/domr/call_dnsmasq.sh new file mode 100755 index 00000000000..097e18572a2 --- /dev/null +++ b/scripts/network/domr/call_dnsmasq.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# 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. + +usage() { + printf "Usage: %s: \n" $(basename $0) >&2 +} + +set -x + +cert="/root/.ssh/id_rsa.cloud" + +ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$1 "/root/dnsmasq.sh $2" +exit $? + diff --git a/scripts/network/domr/createipAlias.sh b/scripts/network/domr/createipAlias.sh new file mode 100755 index 00000000000..c35658e6679 --- /dev/null +++ b/scripts/network/domr/createipAlias.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# 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. + + +usage() { + printf " %s routerip \n" $(basename $0) >&2 +} + +set -x +cert="/root/.ssh/id_rsa.cloud" +ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$1 "/root/createIpAlias.sh $2" diff --git a/scripts/network/domr/deleteipAlias.sh b/scripts/network/domr/deleteipAlias.sh new file mode 100755 index 00000000000..6816edd524c --- /dev/null +++ b/scripts/network/domr/deleteipAlias.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# 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. + +usage() { + printf " %s routerip \n" $(basename $0) >&2 +} + +set -x +cert="/root/.ssh/id_rsa.cloud" +ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$1 "/root/deleteIpAlias.sh $2 $3" diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 36ed9a5082e..1106422a512 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -438,6 +438,7 @@ public class ApiResponseHelper implements ResponseGenerator { if (zone != null) { snapshotResponse.setZoneName(zone.getName()); snapshotResponse.setZoneType(zone.getNetworkType().toString()); + snapshotResponse.setZoneId(zone.getUuid()); } } snapshotResponse.setCreated(snapshot.getCreated()); @@ -2361,11 +2362,12 @@ public class ApiResponseHelper implements ResponseGenerator { if (fwRule.getTrafficType() == FirewallRule.TrafficType.Ingress) { IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId()); - response.setPublicIpAddressId(ip.getId()); + response.setPublicIpAddressId(ip.getUuid()); response.setPublicIpAddress(ip.getAddress().addr()); } else if (fwRule.getTrafficType() == FirewallRule.TrafficType.Egress) { response.setPublicIpAddress(null); - response.setNetworkId(fwRule.getNetworkId()); + Network network = ApiDBUtils.findNetworkById(fwRule.getNetworkId()); + response.setNetworkId(network.getUuid()); } FirewallRule.State state = fwRule.getState(); @@ -3352,8 +3354,8 @@ public class ApiResponseHelper implements ResponseGenerator { //Device Type usageRecResponse.setType(usageRecord.getType()); //VM Instance Id - VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString()); - usageRecResponse.setUsageId(vm.getUuid()); + VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getVmInstanceId().toString()); + usageRecResponse.setVirtualMachineId(vm.getUuid()); //Volume ID VolumeVO volume = _entityMgr.findByIdIncludingRemoved(VolumeVO.class, usageRecord.getUsageId().toString()); usageRecResponse.setUsageId(volume.getUuid()); diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index b0d8d9a9abe..fca4138b405 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -16,13 +16,9 @@ // under the License. package com.cloud.api.query; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -31,19 +27,9 @@ import java.util.Set; import javax.ejb.Local; import javax.inject.Inject; -import org.apache.cloudstack.api.BaseCmd; -import com.cloud.api.ApiDBUtils; -import com.cloud.server.ResourceMetaDataService; -import com.cloud.server.ResourceTag; -import com.cloud.server.TaggedResourceService; -import com.cloud.vm.NicDetailVO; -import com.cloud.vm.dao.NicDetailDao; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.affinity.AffinityGroupVMMapVO; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; -import com.cloud.storage.VolumeDetailVO; -import com.cloud.storage.dao.VolumeDetailsDao; - import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; import org.apache.cloudstack.api.command.admin.host.ListHostsCmd; import org.apache.cloudstack.api.command.admin.internallb.ListInternalLBVMsCmd; @@ -68,7 +54,28 @@ import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd; import org.apache.cloudstack.api.command.user.volume.ListResourceDetailsCmd; import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd; import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd; -import org.apache.cloudstack.api.response.*; +import org.apache.cloudstack.api.response.AccountResponse; +import org.apache.cloudstack.api.response.AsyncJobResponse; +import org.apache.cloudstack.api.response.DiskOfferingResponse; +import org.apache.cloudstack.api.response.DomainRouterResponse; +import org.apache.cloudstack.api.response.EventResponse; +import org.apache.cloudstack.api.response.HostResponse; +import org.apache.cloudstack.api.response.ImageStoreResponse; +import org.apache.cloudstack.api.response.InstanceGroupResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ProjectAccountResponse; +import org.apache.cloudstack.api.response.ProjectInvitationResponse; +import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.api.response.ResourceDetailResponse; +import org.apache.cloudstack.api.response.ResourceTagResponse; +import org.apache.cloudstack.api.response.SecurityGroupResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; +import org.apache.cloudstack.api.response.StoragePoolResponse; +import org.apache.cloudstack.api.response.TemplateResponse; +import org.apache.cloudstack.api.response.UserResponse; +import org.apache.cloudstack.api.response.UserVmResponse; +import org.apache.cloudstack.api.response.VolumeResponse; +import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.engine.subsystem.api.storage.TemplateState; import org.apache.cloudstack.query.QueryService; import org.apache.log4j.Logger; @@ -138,18 +145,20 @@ import com.cloud.projects.dao.ProjectAccountDao; import com.cloud.projects.dao.ProjectDao; import com.cloud.resource.ResourceManager; import com.cloud.server.Criteria; +import com.cloud.server.ResourceMetaDataService; +import com.cloud.server.ResourceTag; import com.cloud.server.ResourceTag.TaggedResourceType; +import com.cloud.server.TaggedResourceService; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.DataStoreRole; -import com.cloud.storage.ImageStore; -import com.cloud.storage.ScopeType; import com.cloud.storage.Storage; +import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.Volume; -import com.cloud.storage.Storage.ImageFormat; -import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; +import com.cloud.storage.VolumeDetailVO; import com.cloud.storage.dao.VMTemplateDao; +import com.cloud.storage.dao.VolumeDetailsDao; import com.cloud.template.VirtualMachineTemplate.TemplateFilter; import com.cloud.user.Account; import com.cloud.user.AccountManager; @@ -163,17 +172,18 @@ import com.cloud.utils.component.ManagerBase; import com.cloud.utils.db.Filter; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.Transaction; import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.NicDetailVO; import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.dao.DomainRouterDao; +import com.cloud.vm.dao.NicDetailDao; import com.cloud.vm.dao.UserVmDao; @Component -@Local(value = {QueryService.class }) +@Local(value = { QueryService.class }) public class QueryManagerImpl extends ManagerBase implements QueryService { public static final Logger s_logger = Logger.getLogger(QueryManagerImpl.class); @@ -285,8 +295,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { @Inject private TemplateJoinDao _templateJoinDao; - @Inject ResourceManager _resourceMgr; - @Inject private ResourceMetaDataService _resourceMetaDataMgr; + @Inject + ResourceManager _resourceMgr; + @Inject + private ResourceMetaDataService _resourceMetaDataMgr; @Inject private TaggedResourceService _taggedResourceMgr; @@ -299,22 +311,29 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { @Inject private DedicatedResourceDao _dedicatedDao; - /* (non-Javadoc) - * @see com.cloud.api.query.QueryService#searchForUsers(org.apache.cloudstack.api.command.admin.user.ListUsersCmd) + + /* + * (non-Javadoc) + * + * @see + * com.cloud.api.query.QueryService#searchForUsers(org.apache.cloudstack + * .api.command.admin.user.ListUsersCmd) */ @Override public ListResponse searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException { Pair, Integer> result = searchForUsersInternal(cmd); ListResponse response = new ListResponse(); - List userResponses = ViewResponseHelper.createUserResponse(result.first().toArray(new UserAccountJoinVO[result.first().size()])); + List userResponses = ViewResponseHelper.createUserResponse(result.first().toArray( + new UserAccountJoinVO[result.first().size()])); response.setResponses(userResponses, result.second()); return response; } - private Pair, Integer> searchForUsersInternal(ListUsersCmd cmd) throws PermissionDeniedException { + private Pair, Integer> searchForUsersInternal(ListUsersCmd cmd) + throws PermissionDeniedException { Account caller = UserContext.current().getCaller(); - //TODO: Integrate with ACL checkAccess refactoring + // TODO: Integrate with ACL checkAccess refactoring Long domainId = cmd.getDomainId(); if (domainId != null) { Domain domain = _domainDao.findById(domainId); @@ -346,7 +365,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } else if (id != null) { sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); } else { - // this condition is used to exclude system user from the search results + // this condition is used to exclude system user from the search + // results sb.and("id", sb.entity().getId(), SearchCriteria.Op.NEQ); } @@ -410,7 +430,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { public ListResponse searchForEvents(ListEventsCmd cmd) { Pair, Integer> result = searchForEventsInternal(cmd); ListResponse response = new ListResponse(); - List eventResponses = ViewResponseHelper.createEventResponse(result.first().toArray(new EventJoinVO[result.first().size()])); + List eventResponses = ViewResponseHelper.createEventResponse(result.first().toArray( + new EventJoinVO[result.first().size()])); response.setResponses(eventResponses, result.second()); return response; } @@ -430,15 +451,17 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Ternary domainIdRecursiveListProject = new Ternary( cmd.getDomainId(), cmd.isRecursive(), null); - _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, - cmd.listAll(), false); + _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, + domainIdRecursiveListProject, cmd.listAll(), false); Long domainId = domainIdRecursiveListProject.first(); Boolean isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Filter searchFilter = new Filter(EventJoinVO.class, "createDate", false, cmd.getStartIndex(), cmd.getPageSizeVal()); + Filter searchFilter = new Filter(EventJoinVO.class, "createDate", false, cmd.getStartIndex(), + cmd.getPageSizeVal()); SearchBuilder sb = _eventJoinDao.createSearchBuilder(); - _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("levelL", sb.entity().getLevel(), SearchCriteria.Op.LIKE); @@ -454,7 +477,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { SearchCriteria sc = sb.create(); // building ACL condition - _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); if (id != null) { sc.setParameters("id", id); @@ -487,7 +511,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.setParameters("archived", false); Pair, Integer> eventPair = null; - // event_view will not have duplicate rows for each event, so searchAndCount should be good enough. + // event_view will not have duplicate rows for each event, so + // searchAndCount should be good enough. if ((entryTime != null) && (duration != null)) { // TODO: waiting for response from dev list, logic is mystery to // me!! @@ -499,7 +524,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { * calMin.add(Calendar.SECOND, -entryTime); * calMax.add(Calendar.SECOND, -duration); Date minTime = * calMin.getTime(); Date maxTime = calMax.getTime(); - * + * * sc.setParameters("state", com.cloud.event.Event.State.Completed); * sc.setParameters("startId", 0); sc.setParameters("createDate", * minTime, maxTime); List startedEvents = @@ -520,7 +545,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { public ListResponse listTags(ListTagsCmd cmd) { Pair, Integer> tags = listTagsInternal(cmd); ListResponse response = new ListResponse(); - List tagResponses = ViewResponseHelper.createResourceTagResponse(false, tags.first().toArray(new ResourceTagJoinVO[tags.first().size()])); + List tagResponses = ViewResponseHelper.createResourceTagResponse(false, tags.first() + .toArray(new ResourceTagJoinVO[tags.first().size()])); response.setResponses(tagResponses, tags.second()); return response; } @@ -535,18 +561,20 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { String customerName = cmd.getCustomer(); boolean listAll = cmd.listAll(); - Ternary domainIdRecursiveListProject = - new Ternary(cmd.getDomainId(), cmd.isRecursive(), null); + Ternary domainIdRecursiveListProject = new Ternary( + cmd.getDomainId(), cmd.isRecursive(), null); - _accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), - cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false); + _accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, + domainIdRecursiveListProject, listAll, false); Long domainId = domainIdRecursiveListProject.first(); Boolean isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Filter searchFilter = new Filter(ResourceTagJoinVO.class, "resourceType", false, cmd.getStartIndex(), cmd.getPageSizeVal()); + Filter searchFilter = new Filter(ResourceTagJoinVO.class, "resourceType", false, cmd.getStartIndex(), + cmd.getPageSizeVal()); SearchBuilder sb = _resourceTagJoinDao.createSearchBuilder(); - _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); sb.and("key", sb.entity().getKey(), SearchCriteria.Op.EQ); sb.and("value", sb.entity().getValue(), SearchCriteria.Op.EQ); @@ -562,7 +590,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // now set the SC criteria... SearchCriteria sc = sb.create(); - _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); if (key != null) { sc.setParameters("key", key); @@ -589,13 +618,12 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { return result; } - - @Override public ListResponse searchForVmGroups(ListVMGroupsCmd cmd) { Pair, Integer> groups = searchForVmGroupsInternal(cmd); ListResponse response = new ListResponse(); - List grpResponses = ViewResponseHelper.createInstanceGroupResponse(groups.first().toArray(new InstanceGroupJoinVO[groups.first().size()])); + List grpResponses = ViewResponseHelper.createInstanceGroupResponse(groups.first() + .toArray(new InstanceGroupJoinVO[groups.first().size()])); response.setResponses(grpResponses, groups.second()); return response; } @@ -610,24 +638,25 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Ternary domainIdRecursiveListProject = new Ternary( cmd.getDomainId(), cmd.isRecursive(), null); - _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, - cmd.listAll(), false); + _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, + domainIdRecursiveListProject, cmd.listAll(), false); Long domainId = domainIdRecursiveListProject.first(); Boolean isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Filter searchFilter = new Filter(InstanceGroupJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); + Filter searchFilter = new Filter(InstanceGroupJoinVO.class, "id", true, cmd.getStartIndex(), + cmd.getPageSizeVal()); SearchBuilder sb = _vmGroupJoinDao.createSearchBuilder(); - _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); - + _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); - SearchCriteria sc = sb.create(); - _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); if (keyword != null) { SearchCriteria ssc = _vmGroupJoinDao.createSearchCriteria(); @@ -635,7 +664,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.addAnd("name", SearchCriteria.Op.SC, ssc); } - if (id != null) { sc.setParameters("id", id); } @@ -651,7 +679,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { public ListResponse searchForUserVMs(ListVMsCmd cmd) { Pair, Integer> result = searchForUserVMsInternal(cmd); ListResponse response = new ListResponse(); - List vmResponses = ViewResponseHelper.createUserVmResponse("virtualmachine", cmd.getDetails(), result.first().toArray(new UserVmJoinVO[result.first().size()])); + List vmResponses = ViewResponseHelper.createUserVmResponse("virtualmachine", cmd.getDetails(), + result.first().toArray(new UserVmJoinVO[result.first().size()])); response.setResponses(vmResponses, result.second()); return response; } @@ -664,20 +693,22 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Long id = cmd.getId(); Map tags = cmd.getTags(); - Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null); - _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false); + Ternary domainIdRecursiveListProject = new Ternary( + cmd.getDomainId(), cmd.isRecursive(), null); + _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, + domainIdRecursiveListProject, listAll, false); Long domainId = domainIdRecursiveListProject.first(); Boolean isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); Criteria c = new Criteria("id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal()); - //Criteria c = new Criteria(null, Boolean.FALSE, cmd.getStartIndex(), cmd.getPageSizeVal()); //version without default sorting + // Criteria c = new Criteria(null, Boolean.FALSE, cmd.getStartIndex(), + // cmd.getPageSizeVal()); //version without default sorting c.addCriteria(Criteria.KEYWORD, cmd.getKeyword()); c.addCriteria(Criteria.ID, cmd.getId()); c.addCriteria(Criteria.NAME, cmd.getInstanceName()); c.addCriteria(Criteria.STATE, cmd.getState()); c.addCriteria(Criteria.DATACENTERID, cmd.getZoneId()); - c.addCriteria(Criteria.DATACENTERTYPE, cmd.getZoneType()); c.addCriteria(Criteria.GROUPID, cmd.getGroupId()); c.addCriteria(Criteria.FOR_VIRTUAL_NETWORK, cmd.getForVirtualNetwork()); c.addCriteria(Criteria.NETWORKID, cmd.getNetworkId()); @@ -708,26 +739,28 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } c.addCriteria(Criteria.ISADMIN, _accountMgr.isAdmin(caller.getType())); - return searchForUserVMsByCriteria(c, caller, domainId, isRecursive, - permittedAccounts, listAll, listProjectResourcesCriteria, tags); + return searchForUserVMsByCriteria(c, caller, domainId, isRecursive, permittedAccounts, listAll, + listProjectResourcesCriteria, tags); } + private Pair, Integer> searchForUserVMsByCriteria(Criteria c, Account caller, Long domainId, + boolean isRecursive, List permittedAccounts, boolean listAll, + ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags) { + Filter searchFilter = new Filter(UserVmJoinVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), + c.getLimit()); - private Pair, Integer> searchForUserVMsByCriteria(Criteria c, Account caller, Long domainId, boolean isRecursive, - List permittedAccounts, boolean listAll, ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags) { - Filter searchFilter = new Filter(UserVmJoinVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit()); - - //first search distinct vm id by using query criteria and pagination + // first search distinct vm id by using query criteria and pagination SearchBuilder sb = _userVmJoinDao.createSearchBuilder(); - sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct ids - _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct + // ids + _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); Object id = c.getCriteria(Criteria.ID); Object name = c.getCriteria(Criteria.NAME); Object state = c.getCriteria(Criteria.STATE); Object notState = c.getCriteria(Criteria.NOTSTATE); Object zoneId = c.getCriteria(Criteria.DATACENTERID); - Object zoneType = c.getCriteria(Criteria.DATACENTERTYPE); Object pod = c.getCriteria(Criteria.PODID); Object hostId = c.getCriteria(Criteria.HOSTID); Object hostName = c.getCriteria(Criteria.HOSTNAME); @@ -750,7 +783,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sb.and("stateNEQ", sb.entity().getState(), SearchCriteria.Op.NEQ); sb.and("stateNIN", sb.entity().getState(), SearchCriteria.Op.NIN); sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); - sb.and("dataCenterType", sb.entity().getDataCenterType(), SearchCriteria.Op.EQ); sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ); sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ); sb.and("hostIdEQ", sb.entity().getHostId(), SearchCriteria.Op.EQ); @@ -764,7 +796,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } if (tags != null && !tags.isEmpty()) { - for (int count=0; count < tags.size(); count++) { + for (int count = 0; count < tags.size(); count++) { sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ); sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ); sb.cp(); @@ -775,7 +807,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ); } - if(vpcId != null && networkId == null){ + if (vpcId != null && networkId == null) { sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ); } @@ -791,7 +823,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { SearchCriteria sc = sb.create(); // building ACL condition - _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); if (tags != null && !tags.isEmpty()) { int count = 0; @@ -802,7 +835,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } } - if (groupId != null && (Long)groupId != -1) { + if (groupId != null && (Long) groupId != -1) { sc.setParameters("instanceGroupId", groupId); } @@ -832,7 +865,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.setParameters("networkId", networkId); } - if(vpcId != null && networkId == null){ + if (vpcId != null && networkId == null) { sc.setParameters("vpcId", vpcId); } @@ -865,10 +898,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } } - if (zoneType != null) { - sc.setParameters("dataCenterType", zoneType); - } - if (pod != null) { sc.setParameters("podId", pod); @@ -894,23 +923,22 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } // search vm details by ids - Pair, Integer> uniqueVmPair = _userVmJoinDao.searchAndCount(sc, searchFilter); + Pair, Integer> uniqueVmPair = _userVmJoinDao.searchAndCount(sc, searchFilter); Integer count = uniqueVmPair.second(); - if ( count.intValue() == 0 ){ + if (count.intValue() == 0) { // handle empty result cases return uniqueVmPair; } List uniqueVms = uniqueVmPair.first(); Long[] vmIds = new Long[uniqueVms.size()]; int i = 0; - for (UserVmJoinVO v : uniqueVms ){ + for (UserVmJoinVO v : uniqueVms) { vmIds[i++] = v.getId(); } List vms = _userVmJoinDao.searchByIds(vmIds); return new Pair, Integer>(vms, count); } - @Override public ListResponse searchForSecurityGroups(ListSecurityGroupsCmd cmd) { Pair, Integer> result = searchForSecurityGroupsInternal(cmd); @@ -920,7 +948,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { return response; } - private Pair, Integer> searchForSecurityGroupsInternal(ListSecurityGroupsCmd cmd) throws PermissionDeniedException, InvalidParameterValueException { + private Pair, Integer> searchForSecurityGroupsInternal(ListSecurityGroupsCmd cmd) + throws PermissionDeniedException, InvalidParameterValueException { Account caller = UserContext.current().getCaller(); Long instanceId = cmd.getVirtualMachineId(); String securityGroup = cmd.getSecurityGroupName(); @@ -932,28 +961,34 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { if (instanceId != null) { UserVmVO userVM = _userVmDao.findById(instanceId); if (userVM == null) { - throw new InvalidParameterValueException("Unable to list network groups for virtual machine instance " + instanceId + "; instance not found."); + throw new InvalidParameterValueException("Unable to list network groups for virtual machine instance " + + instanceId + "; instance not found."); } _accountMgr.checkAccess(caller, null, true, userVM); return listSecurityGroupRulesByVM(instanceId.longValue(), cmd.getStartIndex(), cmd.getPageSizeVal()); } - Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null); - _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false); + Ternary domainIdRecursiveListProject = new Ternary( + cmd.getDomainId(), cmd.isRecursive(), null); + _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, + domainIdRecursiveListProject, cmd.listAll(), false); Long domainId = domainIdRecursiveListProject.first(); Boolean isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Filter searchFilter = new Filter(SecurityGroupJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); + Filter searchFilter = new Filter(SecurityGroupJoinVO.class, "id", true, cmd.getStartIndex(), + cmd.getPageSizeVal()); SearchBuilder sb = _securityGroupJoinDao.createSearchBuilder(); - sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct ids - _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct + // ids + _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ); if (tags != null && !tags.isEmpty()) { - for (int count=0; count < tags.size(); count++) { + for (int count = 0; count < tags.size(); count++) { sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ); sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ); sb.cp(); @@ -961,7 +996,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } SearchCriteria sc = sb.create(); - _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); if (id != null) { sc.setParameters("id", id); @@ -988,9 +1024,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } // search security group together with rules - Pair, Integer> uniqueSgPair = _securityGroupJoinDao.searchAndCount(sc, searchFilter); + Pair, Integer> uniqueSgPair = _securityGroupJoinDao.searchAndCount(sc, searchFilter); Integer count = uniqueSgPair.second(); - if ( count.intValue() == 0 ){ + if (count.intValue() == 0) { // handle empty result cases return uniqueSgPair; } @@ -998,7 +1034,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { List uniqueSgs = uniqueSgPair.first(); Long[] sgIds = new Long[uniqueSgs.size()]; int i = 0; - for (SecurityGroupJoinVO v : uniqueSgs ){ + for (SecurityGroupJoinVO v : uniqueSgs) { sgIds[i++] = v.getId(); } List sgs = _securityGroupJoinDao.searchByIds(sgIds); @@ -1023,56 +1059,58 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { return new Pair, Integer>(sgs, count); } - @Override public ListResponse searchForRouters(ListRoutersCmd cmd) { - Pair, Integer> result = searchForRoutersInternal(cmd, cmd.getId(), cmd.getRouterName(), - cmd.getState(), cmd.getZoneId(), cmd.getPodId(), cmd.getHostId(), cmd.getKeyword(), cmd.getNetworkId(), - cmd.getVpcId(), cmd.getForVpc(), cmd.getRole(), cmd.getZoneType()); + Pair, Integer> result = searchForRoutersInternal(cmd, cmd.getId(), + cmd.getRouterName(), cmd.getState(), cmd.getZoneId(), cmd.getPodId(), cmd.getHostId(), + cmd.getKeyword(), cmd.getNetworkId(), cmd.getVpcId(), cmd.getForVpc(), cmd.getRole(), cmd.getZoneType()); ListResponse response = new ListResponse(); - List routerResponses = ViewResponseHelper.createDomainRouterResponse(result.first().toArray(new DomainRouterJoinVO[result.first().size()])); + List routerResponses = ViewResponseHelper.createDomainRouterResponse(result.first() + .toArray(new DomainRouterJoinVO[result.first().size()])); response.setResponses(routerResponses, result.second()); return response; } - @Override public ListResponse searchForInternalLbVms(ListInternalLBVMsCmd cmd) { - Pair, Integer> result = searchForRoutersInternal(cmd, cmd.getId(), cmd.getRouterName(), - cmd.getState(), cmd.getZoneId(), cmd.getPodId(), cmd.getHostId(), cmd.getKeyword(), cmd.getNetworkId(), - cmd.getVpcId(), cmd.getForVpc(), cmd.getRole(), cmd.getZoneType()); + Pair, Integer> result = searchForRoutersInternal(cmd, cmd.getId(), + cmd.getRouterName(), cmd.getState(), cmd.getZoneId(), cmd.getPodId(), cmd.getHostId(), + cmd.getKeyword(), cmd.getNetworkId(), cmd.getVpcId(), cmd.getForVpc(), cmd.getRole(), cmd.getZoneType()); ListResponse response = new ListResponse(); - List routerResponses = ViewResponseHelper.createDomainRouterResponse(result.first().toArray(new DomainRouterJoinVO[result.first().size()])); + List routerResponses = ViewResponseHelper.createDomainRouterResponse(result.first() + .toArray(new DomainRouterJoinVO[result.first().size()])); response.setResponses(routerResponses, result.second()); return response; } - - private Pair, Integer> searchForRoutersInternal(BaseListProjectAndAccountResourcesCmd cmd, Long id, - String name, String state, Long zoneId, Long podId, Long hostId, String keyword, Long networkId, Long vpcId, Boolean forVpc, String role, String zoneType) { - + private Pair, Integer> searchForRoutersInternal(BaseListProjectAndAccountResourcesCmd cmd, + Long id, String name, String state, Long zoneId, Long podId, Long hostId, String keyword, Long networkId, + Long vpcId, Boolean forVpc, String role, String zoneType) { Account caller = UserContext.current().getCaller(); List permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary( cmd.getDomainId(), cmd.isRecursive(), null); - _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, - cmd.listAll(), false); + _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, + domainIdRecursiveListProject, cmd.listAll(), false); Long domainId = domainIdRecursiveListProject.first(); Boolean isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Filter searchFilter = new Filter(DomainRouterJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); - //Filter searchFilter = new Filter(DomainRouterJoinVO.class, null, true, cmd.getStartIndex(), cmd.getPageSizeVal()); + Filter searchFilter = new Filter(DomainRouterJoinVO.class, "id", true, cmd.getStartIndex(), + cmd.getPageSizeVal()); + // Filter searchFilter = new Filter(DomainRouterJoinVO.class, null, + // true, cmd.getStartIndex(), cmd.getPageSizeVal()); SearchBuilder sb = _routerJoinDao.createSearchBuilder(); sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct // ids to get // number of // records with // pagination - _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); sb.and("name", sb.entity().getHostName(), SearchCriteria.Op.LIKE); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); @@ -1098,7 +1136,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } SearchCriteria sc = sb.create(); - _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); if (keyword != null) { SearchCriteria ssc = _routerJoinDao.createSearchCriteria(); @@ -1166,13 +1205,12 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { return new Pair, Integer>(vrs, count); } - - @Override public ListResponse listProjects(ListProjectsCmd cmd) { Pair, Integer> projects = listProjectsInternal(cmd); ListResponse response = new ListResponse(); - List projectResponses = ViewResponseHelper.createProjectResponse(projects.first().toArray(new ProjectJoinVO[projects.first().size()])); + List projectResponses = ViewResponseHelper.createProjectResponse(projects.first().toArray( + new ProjectJoinVO[projects.first().size()])); response.setResponses(projectResponses, projects.second()); return response; } @@ -1213,13 +1251,15 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { if (accountName != null) { Account owner = _accountMgr.getActiveAccountByName(accountName, domainId); if (owner == null) { - throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId); + throw new InvalidParameterValueException("Unable to find account " + accountName + + " in domain " + domainId); } accountId = owner.getId(); } } else { // domainId == null if (accountName != null) { - throw new InvalidParameterValueException("could not find account " + accountName + " because domain is not specified"); + throw new InvalidParameterValueException("could not find account " + accountName + + " because domain is not specified"); } } @@ -1321,19 +1361,19 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { return new Pair, Integer>(prjs, count); } - @Override public ListResponse listProjectInvitations(ListProjectInvitationsCmd cmd) { Pair, Integer> invites = listProjectInvitationsInternal(cmd); ListResponse response = new ListResponse(); - List projectInvitationResponses = - ViewResponseHelper.createProjectInvitationResponse(invites.first().toArray(new ProjectInvitationJoinVO[invites.first().size()])); + List projectInvitationResponses = ViewResponseHelper + .createProjectInvitationResponse(invites.first().toArray( + new ProjectInvitationJoinVO[invites.first().size()])); response.setResponses(projectInvitationResponses, invites.second()); return response; } - public Pair, Integer> listProjectInvitationsInternal(ListProjectInvitationsCmd cmd){ + public Pair, Integer> listProjectInvitationsInternal(ListProjectInvitationsCmd cmd) { Long id = cmd.getId(); Long projectId = cmd.getProjectId(); String accountName = cmd.getAccountName(); @@ -1348,15 +1388,18 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Account caller = UserContext.current().getCaller(); List permittedAccounts = new ArrayList(); - Ternary domainIdRecursiveListProject = new Ternary(domainId, isRecursive, null); - _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, true); + Ternary domainIdRecursiveListProject = new Ternary( + domainId, isRecursive, null); + _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, + domainIdRecursiveListProject, listAll, true); domainId = domainIdRecursiveListProject.first(); isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); Filter searchFilter = new Filter(ProjectInvitationJoinVO.class, "id", true, startIndex, pageSizeVal); SearchBuilder sb = _projectInvitationJoinDao.createSearchBuilder(); - _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); sb.and("projectId", sb.entity().getProjectId(), SearchCriteria.Op.EQ); sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ); @@ -1364,10 +1407,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); SearchCriteria sc = sb.create(); - _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); - - if (projectId != null){ + if (projectId != null) { sc.setParameters("projectId", projectId); } @@ -1381,24 +1424,24 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { if (activeOnly) { sc.setParameters("state", ProjectInvitation.State.Pending); - sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime()) - _projectMgr.getInvitationTimeout())); + sc.setParameters("created", + new Date((DateUtil.currentGMTTime().getTime()) - _projectMgr.getInvitationTimeout())); } return _projectInvitationJoinDao.searchAndCount(sc, searchFilter); } - @Override public ListResponse listProjectAccounts(ListProjectAccountsCmd cmd) { Pair, Integer> projectAccounts = listProjectAccountsInternal(cmd); ListResponse response = new ListResponse(); - List projectResponses = ViewResponseHelper.createProjectAccountResponse(projectAccounts.first().toArray(new ProjectAccountJoinVO[projectAccounts.first().size()])); + List projectResponses = ViewResponseHelper.createProjectAccountResponse(projectAccounts + .first().toArray(new ProjectAccountJoinVO[projectAccounts.first().size()])); response.setResponses(projectResponses, projectAccounts.second()); return response; } - public Pair, Integer> listProjectAccountsInternal(ListProjectAccountsCmd cmd) { long projectId = cmd.getProjectId(); String accountName = cmd.getAccountName(); @@ -1406,19 +1449,23 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Long startIndex = cmd.getStartIndex(); Long pageSizeVal = cmd.getPageSizeVal(); - //long projectId, String accountName, String role, Long startIndex, Long pageSizeVal) { + // long projectId, String accountName, String role, Long startIndex, + // Long pageSizeVal) { Account caller = UserContext.current().getCaller(); - //check that the project exists + // check that the project exists Project project = _projectDao.findById(projectId); if (project == null) { throw new InvalidParameterValueException("Unable to find the project id=" + projectId); } - //verify permissions - only accounts belonging to the project can list project's account - if (!_accountMgr.isAdmin(caller.getType()) && _projectAccountDao.findByProjectIdAccountId(projectId, caller.getAccountId()) == null) { - throw new PermissionDeniedException("Account " + caller + " is not authorized to list users of the project id=" + projectId); + // verify permissions - only accounts belonging to the project can list + // project's account + if (!_accountMgr.isAdmin(caller.getType()) + && _projectAccountDao.findByProjectIdAccountId(projectId, caller.getAccountId()) == null) { + throw new PermissionDeniedException("Account " + caller + + " is not authorized to list users of the project id=" + projectId); } Filter searchFilter = new Filter(ProjectAccountJoinVO.class, "id", false, startIndex, pageSizeVal); @@ -1443,18 +1490,20 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.setParameters("accountName", accountName); } - return _projectAccountJoinDao.searchAndCount(sc, searchFilter); + return _projectAccountJoinDao.searchAndCount(sc, searchFilter); } @Override public ListResponse searchForServers(ListHostsCmd cmd) { - //FIXME: do we need to support list hosts with VmId, maybe we should create another command just for this + // FIXME: do we need to support list hosts with VmId, maybe we should + // create another command just for this // Right now it is handled separately outside this QueryService s_logger.debug(">>>Searching for hosts>>>"); Pair, Integer> hosts = searchForServersInternal(cmd); ListResponse response = new ListResponse(); s_logger.debug(">>>Generating Response>>>"); - List hostResponses = ViewResponseHelper.createHostResponse(cmd.getDetails(), hosts.first().toArray(new HostJoinVO[hosts.first().size()])); + List hostResponses = ViewResponseHelper.createHostResponse(cmd.getDetails(), hosts.first() + .toArray(new HostJoinVO[hosts.first().size()])); response.setResponses(hostResponses, hosts.second()); return response; } @@ -1462,7 +1511,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { public Pair, Integer> searchForServersInternal(ListHostsCmd cmd) { Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId()); - String zoneType = cmd.getZoneType(); Object name = cmd.getHostName(); Object type = cmd.getType(); Object state = cmd.getState(); @@ -1478,13 +1526,13 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Filter searchFilter = new Filter(HostJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize); SearchBuilder sb = _hostJoinDao.createSearchBuilder(); - sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct ids + sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct + // ids sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); sb.and("type", sb.entity().getType(), SearchCriteria.Op.LIKE); sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ); sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ); - sb.and("dataCenterType", sb.entity().getZoneType(), SearchCriteria.Op.EQ); sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ); sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ); sb.and("resourceState", sb.entity().getResourceState(), SearchCriteria.Op.EQ); @@ -1501,7 +1549,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } - SearchCriteria sc = sb.create(); if (keyword != null) { @@ -1529,9 +1576,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { if (zoneId != null) { sc.setParameters("dataCenterId", zoneId); } - if (zoneType != null) { - sc.setParameters("dataCenterType", zoneType); - } if (pod != null) { sc.setParameters("podId", pod); } @@ -1548,16 +1592,16 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } // search host details by ids - Pair, Integer> uniqueHostPair = _hostJoinDao.searchAndCount(sc, searchFilter); + Pair, Integer> uniqueHostPair = _hostJoinDao.searchAndCount(sc, searchFilter); Integer count = uniqueHostPair.second(); - if ( count.intValue() == 0 ){ + if (count.intValue() == 0) { // handle empty result cases return uniqueHostPair; } List uniqueHosts = uniqueHostPair.first(); Long[] hostIds = new Long[uniqueHosts.size()]; int i = 0; - for (HostJoinVO v : uniqueHosts ){ + for (HostJoinVO v : uniqueHosts) { hostIds[i++] = v.getId(); } List hosts = _hostJoinDao.searchByIds(hostIds); @@ -1570,12 +1614,12 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Pair, Integer> result = searchForVolumesInternal(cmd); ListResponse response = new ListResponse(); - List volumeResponses = ViewResponseHelper.createVolumeResponse(result.first().toArray(new VolumeJoinVO[result.first().size()])); + List volumeResponses = ViewResponseHelper.createVolumeResponse(result.first().toArray( + new VolumeJoinVO[result.first().size()])); response.setResponses(volumeResponses, result.second()); return response; } - private Pair, Integer> searchForVolumesInternal(ListVolumesCmd cmd) { Account caller = UserContext.current().getCaller(); @@ -1589,20 +1633,23 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Map tags = cmd.getTags(); Long zoneId = cmd.getZoneId(); - String zoneType = cmd.getZoneType(); Long podId = null; if (_accountMgr.isAdmin(caller.getType())) { podId = cmd.getPodId(); } - Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null); - _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false); + Ternary domainIdRecursiveListProject = new Ternary( + cmd.getDomainId(), cmd.isRecursive(), null); + _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, + domainIdRecursiveListProject, cmd.listAll(), false); Long domainId = domainIdRecursiveListProject.first(); Boolean isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Filter searchFilter = new Filter(VolumeJoinVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal()); + Filter searchFilter = new Filter(VolumeJoinVO.class, "created", false, cmd.getStartIndex(), + cmd.getPageSizeVal()); - // hack for now, this should be done better but due to needing a join I opted to + // hack for now, this should be done better but due to needing a join I + // opted to // do this quickly and worry about making it pretty later SearchBuilder sb = _volumeJoinDao.createSearchBuilder(); sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct @@ -1610,14 +1657,14 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // number of // records with // pagination - _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("volumeType", sb.entity().getVolumeType(), SearchCriteria.Op.LIKE); sb.and("instanceId", sb.entity().getVmId(), SearchCriteria.Op.EQ); sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); - sb.and("dataCenterType", sb.entity().getDataCenterType(), SearchCriteria.Op.EQ); sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ); // Only return volumes that are not destroyed sb.and("state", sb.entity().getState(), SearchCriteria.Op.NEQ); @@ -1628,18 +1675,17 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sb.cp(); if (tags != null && !tags.isEmpty()) { - for (int count=0; count < tags.size(); count++) { + for (int count = 0; count < tags.size(); count++) { sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ); sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ); sb.cp(); } } - - // now set the SC criteria... SearchCriteria sc = sb.create(); - _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); if (keyword != null) { SearchCriteria ssc = _volumeJoinDao.createSearchCriteria(); @@ -1677,15 +1723,13 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { if (zoneId != null) { sc.setParameters("dataCenterId", zoneId); } - if (zoneType != null) { - sc.setParameters("dataCenterType", zoneType); - } if (podId != null) { sc.setParameters("podId", podId); } // Don't return DomR and ConsoleProxy volumes - sc.setParameters("type", VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm, VirtualMachine.Type.DomainRouter); + sc.setParameters("type", VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm, + VirtualMachine.Type.DomainRouter); // Only return volumes that are not destroyed sc.setParameters("state", Volume.State.Destroy); @@ -1711,12 +1755,12 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { public ListResponse searchForAccounts(ListAccountsCmd cmd) { Pair, Integer> result = searchForAccountsInternal(cmd); ListResponse response = new ListResponse(); - List accountResponses = ViewResponseHelper.createAccountResponse(result.first().toArray(new AccountJoinVO[result.first().size()])); + List accountResponses = ViewResponseHelper.createAccountResponse(result.first().toArray( + new AccountJoinVO[result.first().size()])); response.setResponses(accountResponses, result.second()); return response; } - private Pair, Integer> searchForAccountsInternal(ListAccountsCmd cmd) { Account caller = UserContext.current().getCaller(); Long domainId = cmd.getDomainId(); @@ -1746,7 +1790,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { if (accountName != null) { Account account = _accountDao.findActiveAccount(accountName, domainId); if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) { - throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain " + domainId); + throw new InvalidParameterValueException("Unable to find account by name " + accountName + + " in domain " + domainId); } _accountMgr.checkAccess(caller, null, true, account); } @@ -1783,7 +1828,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sb.and("typeNEQ", sb.entity().getType(), SearchCriteria.Op.NEQ); sb.and("idNEQ", sb.entity().getId(), SearchCriteria.Op.NEQ); - if (listForDomain && isRecursive) { sb.and("path", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE); } @@ -1838,12 +1882,12 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { public ListResponse searchForAsyncJobs(ListAsyncJobsCmd cmd) { Pair, Integer> result = searchForAsyncJobsInternal(cmd); ListResponse response = new ListResponse(); - List jobResponses = ViewResponseHelper.createAsyncJobResponse(result.first().toArray(new AsyncJobJoinVO[result.first().size()])); + List jobResponses = ViewResponseHelper.createAsyncJobResponse(result.first().toArray( + new AsyncJobJoinVO[result.first().size()])); response.setResponses(jobResponses, result.second()); return response; } - private Pair, Integer> searchForAsyncJobsInternal(ListAsyncJobsCmd cmd) { Account caller = UserContext.current().getCaller(); @@ -1852,8 +1896,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Ternary domainIdRecursiveListProject = new Ternary( cmd.getDomainId(), cmd.isRecursive(), null); - _accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), null, permittedAccounts, domainIdRecursiveListProject, - cmd.listAll(), false); + _accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), null, permittedAccounts, + domainIdRecursiveListProject, cmd.listAll(), false); Long domainId = domainIdRecursiveListProject.first(); Boolean isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); @@ -1918,7 +1962,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Pair, Integer> result = searchForStoragePoolsInternal(cmd); ListResponse response = new ListResponse(); - List poolResponses = ViewResponseHelper.createStoragePoolResponse(result.first().toArray(new StoragePoolJoinVO[result.first().size()])); + List poolResponses = ViewResponseHelper.createStoragePoolResponse(result.first().toArray( + new StoragePoolJoinVO[result.first().size()])); response.setResponses(poolResponses, result.second()); return response; } @@ -1926,7 +1971,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { private Pair, Integer> searchForStoragePoolsInternal(ListStoragePoolsCmd cmd) { Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId()); - String zoneType = cmd.getZoneType(); Object id = cmd.getId(); Object name = cmd.getStoragePoolName(); Object path = cmd.getPath(); @@ -1937,24 +1981,21 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Long startIndex = cmd.getStartIndex(); Long pageSize = cmd.getPageSizeVal(); - Filter searchFilter = new Filter(StoragePoolJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize); SearchBuilder sb = _poolJoinDao.createSearchBuilder(); - sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct ids + sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct + // ids sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ); sb.and("path", sb.entity().getPath(), SearchCriteria.Op.EQ); sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ); - sb.and("dataCenterType", sb.entity().getZoneType(), SearchCriteria.Op.EQ); sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ); sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ); sb.and("hostAddress", sb.entity().getHostAddress(), SearchCriteria.Op.EQ); - SearchCriteria sc = sb.create(); - if (keyword != null) { SearchCriteria ssc = _poolJoinDao.createSearchCriteria(); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); @@ -1977,9 +2018,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { if (zoneId != null) { sc.setParameters("dataCenterId", zoneId); } - if (zoneType != null) { - sc.setParameters("dataCenterType", zoneType); - } if (pod != null) { sc.setParameters("podId", pod); } @@ -2008,13 +2046,13 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } - @Override public ListResponse searchForImageStores(ListImageStoresCmd cmd) { Pair, Integer> result = searchForImageStoresInternal(cmd); ListResponse response = new ListResponse(); - List poolResponses = ViewResponseHelper.createImageStoreResponse(result.first().toArray(new ImageStoreJoinVO[result.first().size()])); + List poolResponses = ViewResponseHelper.createImageStoreResponse(result.first().toArray( + new ImageStoreJoinVO[result.first().size()])); response.setResponses(poolResponses, result.second()); return response; } @@ -2030,11 +2068,11 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Long startIndex = cmd.getStartIndex(); Long pageSize = cmd.getPageSizeVal(); - Filter searchFilter = new Filter(ImageStoreJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize); SearchBuilder sb = _imageStoreJoinDao.createSearchBuilder(); - sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct ids + sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct + // ids sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ); sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ); @@ -2042,15 +2080,13 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sb.and("provider", sb.entity().getProviderName(), SearchCriteria.Op.EQ); sb.and("role", sb.entity().getRole(), SearchCriteria.Op.EQ); - SearchCriteria sc = sb.create(); sc.setParameters("role", DataStoreRole.Image); - if (keyword != null) { SearchCriteria ssc = _imageStoreJoinDao.createSearchCriteria(); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - ssc.addOr("provider", SearchCriteria.Op.LIKE, "%" + keyword + "%" ); + ssc.addOr("provider", SearchCriteria.Op.LIKE, "%" + keyword + "%"); sc.addAnd("name", SearchCriteria.Op.SC, ssc); } @@ -2062,7 +2098,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.setParameters("name", name); } - if (zoneId != null) { sc.setParameters("dataCenterId", zoneId); } @@ -2091,12 +2126,12 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } - @Override public ListResponse searchForDiskOfferings(ListDiskOfferingsCmd cmd) { Pair, Integer> result = searchForDiskOfferingsInternal(cmd); ListResponse response = new ListResponse(); - List offeringResponses = ViewResponseHelper.createDiskOfferingResponse(result.first().toArray(new DiskOfferingJoinVO[result.first().size()])); + List offeringResponses = ViewResponseHelper.createDiskOfferingResponse(result.first() + .toArray(new DiskOfferingJoinVO[result.first().size()])); response.setResponses(offeringResponses, result.second()); return response; } @@ -2114,10 +2149,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); isAscending = (isAscending == null ? true : isAscending); - Filter searchFilter = new Filter(DiskOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal()); + Filter searchFilter = new Filter(DiskOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), + cmd.getPageSizeVal()); SearchCriteria sc = _diskOfferingJoinDao.createSearchCriteria(); - Account account = UserContext.current().getCaller(); Object name = cmd.getDiskOfferingName(); Object id = cmd.getId(); @@ -2127,31 +2162,32 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // if a domainId is provided, we just return the disk offering // associated with this domain if (domainId != null) { - if (account.getType() == Account.ACCOUNT_TYPE_ADMIN || isPermissible(account.getDomainId(), domainId) ) { + if (account.getType() == Account.ACCOUNT_TYPE_ADMIN || isPermissible(account.getDomainId(), domainId)) { // check if the user's domain == do's domain || user's domain is // a child of so's domain for non-root users sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); return _diskOfferingJoinDao.searchAndCount(sc, searchFilter); } else { - throw new PermissionDeniedException("The account:" + account.getAccountName() - + " does not fall in the same domain hierarchy as the disk offering"); + throw new PermissionDeniedException("The account:" + account.getAccountName() + + " does not fall in the same domain hierarchy as the disk offering"); } } - List domainIds = null; - // For non-root users, only return all offerings for the user's domain, and everything above till root + // For non-root users, only return all offerings for the user's domain, + // and everything above till root if ((account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { // find all domain Id up to root domain for this account domainIds = new ArrayList(); DomainVO domainRecord = _domainDao.findById(account.getDomainId()); - if ( domainRecord == null ){ + if (domainRecord == null) { s_logger.error("Could not find the domainId for account:" + account.getAccountName()); - throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName()); + throw new CloudAuthenticationException("Could not find the domainId for account:" + + account.getAccountName()); } domainIds.add(domainRecord.getId()); - while (domainRecord.getParent() != null ){ + while (domainRecord.getParent() != null) { domainRecord = _domainDao.findById(domainRecord.getParent()); domainIds.add(domainRecord.getId()); } @@ -2159,13 +2195,19 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { SearchCriteria spc = _diskOfferingJoinDao.createSearchCriteria(); spc.addOr("domainId", SearchCriteria.Op.IN, domainIds.toArray()); - spc.addOr("domainId", SearchCriteria.Op.NULL); // include public offering as where + spc.addOr("domainId", SearchCriteria.Op.NULL); // include public + // offering as where sc.addAnd("domainId", SearchCriteria.Op.SC, spc); - sc.addAnd("systemUse", SearchCriteria.Op.EQ, false); // non-root users should not see system offering at all + sc.addAnd("systemUse", SearchCriteria.Op.EQ, false); // non-root + // users should + // not see + // system + // offering at + // all } - if (keyword != null) { + if (keyword != null) { SearchCriteria ssc = _diskOfferingJoinDao.createSearchCriteria(); ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); @@ -2206,13 +2248,12 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { return _diskOfferingJoinDao.searchAndCount(sc, searchFilter); } - - @Override public ListResponse searchForServiceOfferings(ListServiceOfferingsCmd cmd) { Pair, Integer> result = searchForServiceOfferingsInternal(cmd); ListResponse response = new ListResponse(); - List offeringResponses = ViewResponseHelper.createServiceOfferingResponse(result.first().toArray(new ServiceOfferingJoinVO[result.first().size()])); + List offeringResponses = ViewResponseHelper.createServiceOfferingResponse(result + .first().toArray(new ServiceOfferingJoinVO[result.first().size()])); response.setResponses(offeringResponses, result.second()); return response; } @@ -2229,7 +2270,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // root Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); isAscending = (isAscending == null ? true : isAscending); - Filter searchFilter = new Filter(ServiceOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal()); + Filter searchFilter = new Filter(ServiceOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), + cmd.getPageSizeVal()); SearchCriteria sc = _srvOfferingJoinDao.createSearchCriteria(); Account caller = UserContext.current().getCaller(); @@ -2257,7 +2299,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } } - // boolean includePublicOfferings = false; + // boolean includePublicOfferings = false; if ((caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { // For non-root users. @@ -2267,23 +2309,24 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // find all domain Id up to root domain for this account List domainIds = new ArrayList(); DomainVO domainRecord = _domainDao.findById(caller.getDomainId()); - if ( domainRecord == null ){ + if (domainRecord == null) { s_logger.error("Could not find the domainId for account:" + caller.getAccountName()); - throw new CloudAuthenticationException("Could not find the domainId for account:" + caller.getAccountName()); + throw new CloudAuthenticationException("Could not find the domainId for account:" + + caller.getAccountName()); } domainIds.add(domainRecord.getId()); - while (domainRecord.getParent() != null ){ + while (domainRecord.getParent() != null) { domainRecord = _domainDao.findById(domainRecord.getParent()); domainIds.add(domainRecord.getId()); } SearchCriteria spc = _srvOfferingJoinDao.createSearchCriteria(); spc.addOr("domainId", SearchCriteria.Op.IN, domainIds.toArray()); - spc.addOr("domainId", SearchCriteria.Op.NULL); // include public offering as where + spc.addOr("domainId", SearchCriteria.Op.NULL); // include public + // offering as where sc.addAnd("domainId", SearchCriteria.Op.SC, spc); - } - else { + } else { // for root users if (caller.getDomainId() != 1 && isSystem) { // NON ROOT admin throw new InvalidParameterValueException("Non ROOT admins cannot access system's offering"); @@ -2302,7 +2345,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } else if (vmId != null) { UserVmVO vmInstance = _userVmDao.findById(vmId); if ((vmInstance == null) || (vmInstance.getRemoved() != null)) { - InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with specified id"); + InvalidParameterValueException ex = new InvalidParameterValueException( + "unable to find a virtual machine with specified id"); ex.addProxyObject(vmId.toString(), "vmId"); throw ex; } @@ -2324,7 +2368,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } if (isSystem != null) { - // note that for non-root users, isSystem is always false when control comes to here + // note that for non-root users, isSystem is always false when + // control comes to here sc.addAnd("systemUse", SearchCriteria.Op.EQ, isSystem); } @@ -2340,19 +2385,16 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } - - - @Override public ListResponse listDataCenters(ListZonesByCmd cmd) { Pair, Integer> result = listDataCentersInternal(cmd); ListResponse response = new ListResponse(); - List dcResponses = ViewResponseHelper.createDataCenterResponse(cmd.getShowCapacities(), result.first().toArray(new DataCenterJoinVO[result.first().size()])); + List dcResponses = ViewResponseHelper.createDataCenterResponse(cmd.getShowCapacities(), result + .first().toArray(new DataCenterJoinVO[result.first().size()])); response.setResponses(dcResponses, result.second()); return response; } - private Pair, Integer> listDataCentersInternal(ListZonesByCmd cmd) { Account account = UserContext.current().getCaller(); Long domainId = cmd.getDomainId(); @@ -2364,8 +2406,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Filter searchFilter = new Filter(DataCenterJoinVO.class, null, false, cmd.getStartIndex(), cmd.getPageSizeVal()); SearchCriteria sc = _dcJoinDao.createSearchCriteria(); - if(networkType != null) - sc.addAnd("networkType", SearchCriteria.Op.EQ, networkType); + if (networkType != null) + sc.addAnd("networkType", SearchCriteria.Op.EQ, networkType); if (id != null) { sc.addAnd("id", SearchCriteria.Op.EQ, id); @@ -2379,13 +2421,13 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.addAnd("name", SearchCriteria.Op.SC, ssc); } - /*List all resources due to Explicit Dedication except the dedicated resources of other account - * if (domainId != null) { - // for domainId != null - // right now, we made the decision to only list zones associated - // with this domain, private zone - sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); - } else */ + /* + * List all resources due to Explicit Dedication except the + * dedicated resources of other account if (domainId != null) { // + * for domainId != null // right now, we made the decision to only + * list zones associated // with this domain, private zone + * sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); } else + */ if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) { // it was decided to return all zones for the user's domain, and // everything above till root @@ -2394,20 +2436,21 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // check the parent, if not null, add zones for that parent to // list - // find all domain Id up to root domain for this account List domainIds = new ArrayList(); DomainVO domainRecord = _domainDao.findById(account.getDomainId()); - if ( domainRecord == null ){ + if (domainRecord == null) { s_logger.error("Could not find the domainId for account:" + account.getAccountName()); - throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName()); + throw new CloudAuthenticationException("Could not find the domainId for account:" + + account.getAccountName()); } domainIds.add(domainRecord.getId()); - while (domainRecord.getParent() != null ){ + while (domainRecord.getParent() != null) { domainRecord = _domainDao.findById(domainRecord.getParent()); domainIds.add(domainRecord.getId()); } - // domainId == null (public zones) or domainId IN [all domain id up to root domain] + // domainId == null (public zones) or domainId IN [all domain id + // up to root domain] SearchCriteria sdc = _dcJoinDao.createSearchCriteria(); sdc.addOr("domainId", SearchCriteria.Op.IN, domainIds.toArray()); sdc.addOr("domainId", SearchCriteria.Op.NULL); @@ -2416,34 +2459,41 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // remove disabled zones sc.addAnd("allocationState", SearchCriteria.Op.NEQ, Grouping.AllocationState.Disabled); - //remove Dedicated zones not dedicated to this domainId or subdomainId + // remove Dedicated zones not dedicated to this domainId or + // subdomainId List dedicatedZoneIds = removeDedicatedZoneNotSuitabe(domainIds); - if(!dedicatedZoneIds.isEmpty()){ - sdc.addAnd("id", SearchCriteria.Op.NIN, dedicatedZoneIds.toArray(new Object[dedicatedZoneIds.size()])); + if (!dedicatedZoneIds.isEmpty()) { + sdc.addAnd("id", SearchCriteria.Op.NIN, + dedicatedZoneIds.toArray(new Object[dedicatedZoneIds.size()])); } - } else if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { + } else if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN + || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { // it was decided to return all zones for the domain admin, and - // everything above till root, as well as zones till the domain leaf + // everything above till root, as well as zones till the domain + // leaf List domainIds = new ArrayList(); DomainVO domainRecord = _domainDao.findById(account.getDomainId()); - if ( domainRecord == null ){ + if (domainRecord == null) { s_logger.error("Could not find the domainId for account:" + account.getAccountName()); - throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName()); + throw new CloudAuthenticationException("Could not find the domainId for account:" + + account.getAccountName()); } domainIds.add(domainRecord.getId()); // find all domain Ids till leaf - List allChildDomains = _domainDao.findAllChildren(domainRecord.getPath(), domainRecord.getId()); + List allChildDomains = _domainDao.findAllChildren(domainRecord.getPath(), + domainRecord.getId()); for (DomainVO domain : allChildDomains) { domainIds.add(domain.getId()); } // then find all domain Id up to root domain for this account - while (domainRecord.getParent() != null ){ + while (domainRecord.getParent() != null) { domainRecord = _domainDao.findById(domainRecord.getParent()); domainIds.add(domainRecord.getId()); } - // domainId == null (public zones) or domainId IN [all domain id up to root domain] + // domainId == null (public zones) or domainId IN [all domain id + // up to root domain] SearchCriteria sdc = _dcJoinDao.createSearchCriteria(); sdc.addOr("domainId", SearchCriteria.Op.IN, domainIds.toArray()); sdc.addOr("domainId", SearchCriteria.Op.NULL); @@ -2452,26 +2502,30 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // remove disabled zones sc.addAnd("allocationState", SearchCriteria.Op.NEQ, Grouping.AllocationState.Disabled); - //remove Dedicated zones not dedicated to this domainId or subdomainId + // remove Dedicated zones not dedicated to this domainId or + // subdomainId List dedicatedZoneIds = removeDedicatedZoneNotSuitabe(domainIds); - if(!dedicatedZoneIds.isEmpty()){ - sdc.addAnd("id", SearchCriteria.Op.NIN, dedicatedZoneIds.toArray(new Object[dedicatedZoneIds.size()])); + if (!dedicatedZoneIds.isEmpty()) { + sdc.addAnd("id", SearchCriteria.Op.NIN, + dedicatedZoneIds.toArray(new Object[dedicatedZoneIds.size()])); } } - // handle available=FALSE option, only return zones with at least one VM running there + // handle available=FALSE option, only return zones with at least + // one VM running there Boolean available = cmd.isAvailable(); if (account != null) { if ((available != null) && Boolean.FALSE.equals(available)) { - Set dcIds = new HashSet(); //data centers with at least one VM running + Set dcIds = new HashSet(); // data centers with + // at least one VM + // running List routers = _routerDao.listBy(account.getId()); - for (DomainRouterVO router : routers){ + for (DomainRouterVO router : routers) { dcIds.add(router.getDataCenterId()); } - if ( dcIds.size() == 0) { + if (dcIds.size() == 0) { return new Pair, Integer>(new ArrayList(), 0); - } - else{ + } else { sc.addAnd("idIn", SearchCriteria.Op.IN, dcIds.toArray()); } @@ -2483,11 +2537,11 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } private List removeDedicatedZoneNotSuitabe(List domainIds) { - //remove dedicated zone of other domain + // remove dedicated zone of other domain List dedicatedZoneIds = new ArrayList(); List dedicatedResources = _dedicatedDao.listZonesNotInDomainIds(domainIds); for (DedicatedResourceVO dr : dedicatedResources) { - if(dr != null) { + if (dr != null) { dedicatedZoneIds.add(dr.getDataCenterId()); } } @@ -2527,7 +2581,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Pair, Integer> result = searchForTemplatesInternal(cmd); ListResponse response = new ListResponse(); - List templateResponses = ViewResponseHelper.createTemplateResponse(result.first().toArray(new TemplateJoinVO[result.first().size()])); + List templateResponses = ViewResponseHelper.createTemplateResponse(result.first().toArray( + new TemplateJoinVO[result.first().size()])); response.setResponses(templateResponses, result.second()); return response; } @@ -2541,7 +2596,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { boolean listAll = false; if (templateFilter != null && templateFilter == TemplateFilter.all) { if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) { - throw new InvalidParameterValueException("Filter " + TemplateFilter.all + " can be specified by admin only"); + throw new InvalidParameterValueException("Filter " + TemplateFilter.all + + " can be specified by admin only"); } listAll = true; } @@ -2549,8 +2605,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { List permittedAccountIds = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary( cmd.getDomainId(), cmd.isRecursive(), null); - _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject, - listAll, false); + _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, + domainIdRecursiveListProject, listAll, false); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); List permittedAccounts = new ArrayList(); for (Long accountId : permittedAccountIds) { @@ -2560,14 +2616,16 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { boolean showDomr = ((templateFilter != TemplateFilter.selfexecutable) && (templateFilter != TemplateFilter.featured)); HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor()); - return searchForTemplatesInternal(id, cmd.getTemplateName(), cmd.getKeyword(), templateFilter, false, null, cmd.getPageSizeVal(), cmd.getStartIndex(), - cmd.getZoneId(), hypervisorType, showDomr, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags); + return searchForTemplatesInternal(id, cmd.getTemplateName(), cmd.getKeyword(), templateFilter, false, null, + cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), hypervisorType, showDomr, + cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags); } - private Pair, Integer> searchForTemplatesInternal(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) { + private Pair, Integer> searchForTemplatesInternal(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) { VMTemplateVO template = null; Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); @@ -2583,14 +2641,15 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { }// If ISO requested then it should be ISO. if (isIso && template.getFormat() != ImageFormat.ISO) { s_logger.error("Template Id " + templateId + " is not an ISO"); - InvalidParameterValueException ex = new InvalidParameterValueException("Specified Template Id is not an ISO"); + InvalidParameterValueException ex = new InvalidParameterValueException( + "Specified Template Id is not an ISO"); ex.addProxyObject(template.getUuid(), "templateId"); throw ex; }// If ISO not requested then it shouldn't be an ISO. if (!isIso && template.getFormat() == ImageFormat.ISO) { s_logger.error("Incorrect format of the template id " + templateId); - InvalidParameterValueException ex = new InvalidParameterValueException("Incorrect format " + template.getFormat() - + " of the specified template id"); + InvalidParameterValueException ex = new InvalidParameterValueException("Incorrect format " + + template.getFormat() + " of the specified template id"); ex.addProxyObject(template.getUuid(), "templateId"); throw ex; } @@ -2648,7 +2707,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // get all child domain ID's if (_accountMgr.isAdmin(account.getType())) { - List allChildDomains = _domainDao.findAllChildren(accountDomain.getPath(), accountDomain.getId()); + List allChildDomains = _domainDao.findAllChildren(accountDomain.getPath(), + accountDomain.getId()); for (DomainVO childDomain : allChildDomains) { relatedDomainIds.add(childDomain.getId()); } @@ -2787,7 +2847,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Pair, Integer> result = searchForIsosInternal(cmd); ListResponse response = new ListResponse(); - List templateResponses = ViewResponseHelper.createIsoResponse(result.first().toArray(new TemplateJoinVO[result.first().size()])); + List templateResponses = ViewResponseHelper.createIsoResponse(result.first().toArray( + new TemplateJoinVO[result.first().size()])); response.setResponses(templateResponses, result.second()); return response; } @@ -2801,7 +2862,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { boolean listAll = false; if (isoFilter != null && isoFilter == TemplateFilter.all) { if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) { - throw new InvalidParameterValueException("Filter " + TemplateFilter.all + " can be specified by admin only"); + throw new InvalidParameterValueException("Filter " + TemplateFilter.all + + " can be specified by admin only"); } listAll = true; } @@ -2809,8 +2871,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { List permittedAccountIds = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary( cmd.getDomainId(), cmd.isRecursive(), null); - _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject, - listAll, false); + _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, + domainIdRecursiveListProject, listAll, false); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); List permittedAccounts = new ArrayList(); for (Long accountId : permittedAccountIds) { @@ -2819,23 +2881,23 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor()); - return searchForTemplatesInternal(cmd.getId(), cmd.getIsoName(), cmd.getKeyword(), isoFilter, true, cmd.isBootable(), cmd.getPageSizeVal(), - cmd.getStartIndex(), cmd.getZoneId(), hypervisorType, true, cmd.listInReadyState(), permittedAccounts, caller, - listProjectResourcesCriteria, tags); + return searchForTemplatesInternal(cmd.getId(), cmd.getIsoName(), cmd.getKeyword(), isoFilter, true, + cmd.isBootable(), cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), hypervisorType, true, + cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags); } public ListResponse listAffinityGroups(Long affinityGroupId, String affinityGroupName, String affinityGroupType, Long vmId, String accountName, Long domainId, boolean isRecursive, boolean listAll, Long startIndex, Long pageSize) { Pair, Integer> result = listAffinityGroupsInternal(affinityGroupId, - affinityGroupName, affinityGroupType, vmId, accountName, domainId, isRecursive, listAll, startIndex, pageSize); + affinityGroupName, affinityGroupType, vmId, accountName, domainId, isRecursive, listAll, startIndex, + pageSize); ListResponse response = new ListResponse(); List agResponses = ViewResponseHelper.createAffinityGroupResponses(result.first()); response.setResponses(agResponses, result.second()); return response; } - public Pair, Integer> listAffinityGroupsInternal(Long affinityGroupId, String affinityGroupName, String affinityGroupType, Long vmId, String accountName, Long domainId, boolean isRecursive, boolean listAll, Long startIndex, Long pageSize) { @@ -2846,7 +2908,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { if (vmId != null) { UserVmVO userVM = _userVmDao.findById(vmId); - if (userVM == null){ + if (userVM == null) { throw new InvalidParameterValueException("Unable to list affinity groups for virtual machine instance " + vmId + "; instance not found."); } @@ -2872,7 +2934,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // distinct SearchCriteria sc = groupSearch.create(); - _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); if (affinityGroupId != null) { sc.addAnd("id", SearchCriteria.Op.EQ, affinityGroupId); @@ -2886,8 +2949,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.addAnd("type", SearchCriteria.Op.EQ, affinityGroupType); } - - Pair, Integer> uniqueGroupsPair = _affinityGroupJoinDao.searchAndCount(sc, searchFilter); + Pair, Integer> uniqueGroupsPair = _affinityGroupJoinDao.searchAndCount(sc, + searchFilter); // search group details by ids Integer count = uniqueGroupsPair.second(); if (count.intValue() == 0) { @@ -2923,27 +2986,26 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { return new Pair, Integer>(ags, count); } - - public List listResource(ListResourceDetailsCmd cmd){ + public List listResource(ListResourceDetailsCmd cmd) { String key = cmd.getKey(); ResourceTag.TaggedResourceType resourceType = cmd.getResourceType(); String resourceId = cmd.getResourceId(); Long id = _taggedResourceMgr.getResourceId(resourceId, resourceType); - if(resourceType == ResourceTag.TaggedResourceType.Volume){ + if (resourceType == ResourceTag.TaggedResourceType.Volume) { List volumeDetailList; - if(key == null){ + if (key == null) { volumeDetailList = _volumeDetailDao.findDetails(id); - }else{ + } else { VolumeDetailVO volumeDetail = _volumeDetailDao.findDetail(id, key); volumeDetailList = new LinkedList(); volumeDetailList.add(volumeDetail); } List volumeDetailResponseList = new ArrayList(); - for (VolumeDetailVO volumeDetail : volumeDetailList ){ + for (VolumeDetailVO volumeDetail : volumeDetailList) { ResourceDetailResponse volumeDetailResponse = new ResourceDetailResponse(); volumeDetailResponse.setResourceId(id.toString()); volumeDetailResponse.setName(volumeDetail.getName()); @@ -2955,22 +3017,21 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { return volumeDetailResponseList; - } else { - + } else { List nicDetailList; - if(key == null){ + if (key == null) { nicDetailList = _nicDetailDao.findDetails(id); - }else { + } else { NicDetailVO nicDetail = _nicDetailDao.findDetail(id, key); nicDetailList = new LinkedList(); nicDetailList.add(nicDetail); } List nicDetailResponseList = new ArrayList(); - for(NicDetailVO nicDetail : nicDetailList){ + for (NicDetailVO nicDetail : nicDetailList) { ResourceDetailResponse nicDetailResponse = new ResourceDetailResponse(); - //String uuid = ApiDBUtils.findN + // String uuid = ApiDBUtils.findN nicDetailResponse.setName(nicDetail.getName()); nicDetailResponse.setValue(nicDetail.getValue()); nicDetailResponse.setResourceType(ResourceTag.TaggedResourceType.Nic.toString()); diff --git a/server/src/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java index a6355ad9867..5ebfa7dc796 100644 --- a/server/src/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java +++ b/server/src/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java @@ -28,27 +28,27 @@ import org.springframework.stereotype.Component; import com.cloud.api.ApiDBUtils; import com.cloud.api.query.vo.StoragePoolJoinVO; +import com.cloud.capacity.Capacity; import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.storage.ScopeType; import com.cloud.storage.StoragePool; import com.cloud.storage.StorageStats; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; - @Component -@Local(value={StoragePoolJoinDao.class}) +@Local(value = { StoragePoolJoinDao.class }) public class StoragePoolJoinDaoImpl extends GenericDaoBase implements StoragePoolJoinDao { public static final Logger s_logger = Logger.getLogger(StoragePoolJoinDaoImpl.class); @Inject - private ConfigurationDao _configDao; + private ConfigurationDao _configDao; private final SearchBuilder spSearch; private final SearchBuilder spIdSearch; - protected StoragePoolJoinDaoImpl() { spSearch = createSearchBuilder(); @@ -62,10 +62,6 @@ public class StoragePoolJoinDaoImpl extends GenericDaoBase 0){ + if (response.getTags() != null && response.getTags().length() > 0) { response.setTags(response.getTags() + "," + tag); - } - else{ + } else { response.setTags(tag); } } @@ -149,12 +143,13 @@ public class StoragePoolJoinDaoImpl extends GenericDaoBase 0){ + if (response.getTags() != null && response.getTags().length() > 0) { response.setTags(response.getTags() + "," + tag); } else { response.setTags(tag); @@ -195,22 +189,20 @@ public class StoragePoolJoinDaoImpl extends GenericDaoBase searchByIds(Long... spIds) { // set detail batch query size int DETAILS_BATCH_SIZE = 2000; String batchCfg = _configDao.getValue("detail.batch.query.size"); - if ( batchCfg != null ){ + if (batchCfg != null) { DETAILS_BATCH_SIZE = Integer.parseInt(batchCfg); } // query details by batches List uvList = new ArrayList(); // query details by batches int curr_index = 0; - if ( spIds.length > DETAILS_BATCH_SIZE ){ - while ( (curr_index + DETAILS_BATCH_SIZE ) <= spIds.length ) { + if (spIds.length > DETAILS_BATCH_SIZE) { + while ((curr_index + DETAILS_BATCH_SIZE) <= spIds.length) { Long[] ids = new Long[DETAILS_BATCH_SIZE]; for (int k = 0, j = curr_index; j < curr_index + DETAILS_BATCH_SIZE; j++, k++) { ids[k] = spIds[j]; @@ -241,7 +233,4 @@ public class StoragePoolJoinDaoImpl extends GenericDaoBase params) throws ConfigurationException { String maxVolumeSizeInGbString = _configDao.getValue(Config.MaxVolumeSize.key()); _maxVolumeSizeInGb = NumbersUtil.parseInt(maxVolumeSizeInGbString, - Integer.parseInt(Config.MaxVolumeSize.getDefaultValue())); + Integer.parseInt(Config.MaxVolumeSize.getDefaultValue())); String defaultPageSizeString = _configDao.getValue(Config.DefaultPageSize.key()); _defaultPageSize = NumbersUtil.parseLong(defaultPageSizeString, - Long.parseLong(Config.DefaultPageSize.getDefaultValue())); + Long.parseLong(Config.DefaultPageSize.getDefaultValue())); populateConfigValuesForValidationSet(); return true; @@ -374,13 +375,22 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (mgtCidr == null || mgtCidr.trim().isEmpty()) { String[] localCidrs = NetUtils.getLocalCidrs(); if (localCidrs.length > 0) { - s_logger.warn("Management network CIDR is not configured originally. Set it default to " + localCidrs[0]); + s_logger.warn("Management network CIDR is not configured originally. Set it default to " + + localCidrs[0]); - _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management network CIDR is not configured originally. Set it default to " + localCidrs[0], ""); - _configDao.update(Config.ManagementNetwork.key(), Config.ManagementNetwork.getCategory(), localCidrs[0]); + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), + "Management network CIDR is not configured originally. Set it default to " + localCidrs[0], ""); + _configDao + .update(Config.ManagementNetwork.key(), Config.ManagementNetwork.getCategory(), localCidrs[0]); } else { s_logger.warn("Management network CIDR is not properly configured and we are not able to find a default setting"); - _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management network CIDR is not properly configured and we are not able to find a default setting", ""); + _alertMgr + .sendAlert( + AlertManager.ALERT_TYPE_MANAGMENT_NODE, + 0, + new Long(0), + "Management network CIDR is not properly configured and we are not able to find a default setting", + ""); } } @@ -394,7 +404,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @DB - public String updateConfiguration(long userId, String name, String category, String value, String scope, Long resourceId) { + public String updateConfiguration(long userId, String name, String category, String value, String scope, + Long resourceId) { String validationMsg = validateConfigurationValue(name, value, scope); @@ -403,62 +414,74 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException(validationMsg); } - // If scope of the parameter is given then it needs to be updated in the corresponding details table, - // if scope is mentioned as global or not mentioned then it is normal global parameter updation - if (scope != null && !scope.isEmpty() && !Config.ConfigurationParameterScope.global.toString().equalsIgnoreCase(scope)) { + // If scope of the parameter is given then it needs to be updated in the + // corresponding details table, + // if scope is mentioned as global or not mentioned then it is normal + // global parameter updation + if (scope != null && !scope.isEmpty() + && !Config.ConfigurationParameterScope.global.toString().equalsIgnoreCase(scope)) { switch (Config.ConfigurationParameterScope.valueOf(scope)) { - case zone: DataCenterVO zone = _zoneDao.findById(resourceId); - if (zone == null) { - throw new InvalidParameterValueException("unable to find zone by id " + resourceId); - } - DcDetailVO dcDetailVO = _dcDetailsDao.findDetail(resourceId, name.toLowerCase()); - if (dcDetailVO == null) { - dcDetailVO = new DcDetailVO(resourceId, name, value); - _dcDetailsDao.persist(dcDetailVO); - } else { - dcDetailVO.setValue(value); - _dcDetailsDao.update(dcDetailVO.getId(), dcDetailVO); - } break; - case cluster: ClusterVO cluster = _clusterDao.findById(resourceId); - if (cluster == null) { - throw new InvalidParameterValueException("unable to find cluster by id " + resourceId); - } - ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(resourceId, name); - if (clusterDetailsVO == null) { - clusterDetailsVO = new ClusterDetailsVO(resourceId, name, value); - _clusterDetailsDao.persist(clusterDetailsVO); - } else { - clusterDetailsVO.setValue(value); - _clusterDetailsDao.update(clusterDetailsVO.getId(), clusterDetailsVO); - } break; + case zone: + DataCenterVO zone = _zoneDao.findById(resourceId); + if (zone == null) { + throw new InvalidParameterValueException("unable to find zone by id " + resourceId); + } + DcDetailVO dcDetailVO = _dcDetailsDao.findDetail(resourceId, name.toLowerCase()); + if (dcDetailVO == null) { + dcDetailVO = new DcDetailVO(resourceId, name, value); + _dcDetailsDao.persist(dcDetailVO); + } else { + dcDetailVO.setValue(value); + _dcDetailsDao.update(dcDetailVO.getId(), dcDetailVO); + } + break; + case cluster: + ClusterVO cluster = _clusterDao.findById(resourceId); + if (cluster == null) { + throw new InvalidParameterValueException("unable to find cluster by id " + resourceId); + } + ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(resourceId, name); + if (clusterDetailsVO == null) { + clusterDetailsVO = new ClusterDetailsVO(resourceId, name, value); + _clusterDetailsDao.persist(clusterDetailsVO); + } else { + clusterDetailsVO.setValue(value); + _clusterDetailsDao.update(clusterDetailsVO.getId(), clusterDetailsVO); + } + break; - case storagepool: StoragePoolVO pool = _storagePoolDao.findById(resourceId); - if (pool == null) { - throw new InvalidParameterValueException("unable to find storage pool by id " + resourceId); - } - StoragePoolDetailVO storagePoolDetailVO = _storagePoolDetailsDao.findDetail(resourceId, name); - if (storagePoolDetailVO == null) { - storagePoolDetailVO = new StoragePoolDetailVO(resourceId, name, value); - _storagePoolDetailsDao.persist(storagePoolDetailVO); + case storagepool: + StoragePoolVO pool = _storagePoolDao.findById(resourceId); + if (pool == null) { + throw new InvalidParameterValueException("unable to find storage pool by id " + resourceId); + } + StoragePoolDetailVO storagePoolDetailVO = _storagePoolDetailsDao.findDetail(resourceId, name); + if (storagePoolDetailVO == null) { + storagePoolDetailVO = new StoragePoolDetailVO(resourceId, name, value); + _storagePoolDetailsDao.persist(storagePoolDetailVO); - } else { - storagePoolDetailVO.setValue(value); - _storagePoolDetailsDao.update(storagePoolDetailVO.getId(), storagePoolDetailVO); - } break; + } else { + storagePoolDetailVO.setValue(value); + _storagePoolDetailsDao.update(storagePoolDetailVO.getId(), storagePoolDetailVO); + } + break; - case account: AccountVO account = _accountDao.findById(resourceId); - if (account == null) { - throw new InvalidParameterValueException("unable to find account by id " + resourceId); - } - AccountDetailVO accountDetailVO = _accountDetailsDao.findDetail(resourceId, name); - if (accountDetailVO == null) { - accountDetailVO = new AccountDetailVO(resourceId, name, value); - _accountDetailsDao.persist(accountDetailVO); - } else { - accountDetailVO.setValue(value); - _accountDetailsDao.update(accountDetailVO.getId(), accountDetailVO); - } break; - default: throw new InvalidParameterValueException("Scope provided is invalid"); + case account: + AccountVO account = _accountDao.findById(resourceId); + if (account == null) { + throw new InvalidParameterValueException("unable to find account by id " + resourceId); + } + AccountDetailVO accountDetailVO = _accountDetailsDao.findDetail(resourceId, name); + if (accountDetailVO == null) { + accountDetailVO = new AccountDetailVO(resourceId, name, value); + _accountDetailsDao.persist(accountDetailVO); + } else { + accountDetailVO.setValue(value); + _accountDetailsDao.update(accountDetailVO.getId(), accountDetailVO); + } + break; + default: + throw new InvalidParameterValueException("Scope provided is invalid"); } return value; } @@ -482,7 +505,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati pstmt.executeUpdate(); } catch (Throwable e) { - throw new CloudRuntimeException("Failed to update guest.network.device in host_details due to exception ", e); + throw new CloudRuntimeException( + "Failed to update guest.network.device in host_details due to exception ", e); } } else if (Config.XenPrivateNetwork.key().equalsIgnoreCase(name)) { String sql = "update host_details set value=? where name=?"; @@ -493,7 +517,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati pstmt.executeUpdate(); } catch (Throwable e) { - throw new CloudRuntimeException("Failed to update private.network.device in host_details due to exception ", e); + throw new CloudRuntimeException( + "Failed to update private.network.device in host_details due to exception ", e); } } else if (Config.XenPublicNetwork.key().equalsIgnoreCase(name)) { String sql = "update host_details set value=? where name=?"; @@ -504,7 +529,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati pstmt.executeUpdate(); } catch (Throwable e) { - throw new CloudRuntimeException("Failed to update public.network.device in host_details due to exception ", e); + throw new CloudRuntimeException( + "Failed to update public.network.device in host_details due to exception ", e); } } else if (Config.XenStorageNetwork1.key().equalsIgnoreCase(name)) { String sql = "update host_details set value=? where name=?"; @@ -515,7 +541,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati pstmt.executeUpdate(); } catch (Throwable e) { - throw new CloudRuntimeException("Failed to update storage.network.device1 in host_details due to exception ", e); + throw new CloudRuntimeException( + "Failed to update storage.network.device1 in host_details due to exception ", e); } } else if (Config.XenStorageNetwork2.key().equals(name)) { String sql = "update host_details set value=? where name=?"; @@ -526,18 +553,23 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati pstmt.executeUpdate(); } catch (Throwable e) { - throw new CloudRuntimeException("Failed to update storage.network.device2 in host_details due to exception ", e); + throw new CloudRuntimeException( + "Failed to update storage.network.device2 in host_details due to exception ", e); } } else if (Config.SystemVMUseLocalStorage.key().equalsIgnoreCase(name)) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Config 'system.vm.use.local.storage' changed to value:" + value + ", need to update System VM offerings"); + s_logger.debug("Config 'system.vm.use.local.storage' changed to value:" + value + + ", need to update System VM offerings"); } boolean useLocalStorage = Boolean.parseBoolean(_configDao.getValue(Config.SystemVMUseLocalStorage.key())); - ServiceOfferingVO serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.consoleProxyDefaultOffUniqueName); + ServiceOfferingVO serviceOffering = _serviceOfferingDao + .findByName(ServiceOffering.consoleProxyDefaultOffUniqueName); if (serviceOffering != null) { serviceOffering.setUseLocalStorage(useLocalStorage); if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) { - throw new CloudRuntimeException("Failed to update ConsoleProxy offering's use_local_storage option to value:" + useLocalStorage); + throw new CloudRuntimeException( + "Failed to update ConsoleProxy offering's use_local_storage option to value:" + + useLocalStorage); } } @@ -545,7 +577,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (serviceOffering != null) { serviceOffering.setUseLocalStorage(useLocalStorage); if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) { - throw new CloudRuntimeException("Failed to update SoftwareRouter offering's use_local_storage option to value:" + useLocalStorage); + throw new CloudRuntimeException( + "Failed to update SoftwareRouter offering's use_local_storage option to value:" + + useLocalStorage); } } @@ -553,7 +587,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (serviceOffering != null) { serviceOffering.setUseLocalStorage(useLocalStorage); if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) { - throw new CloudRuntimeException("Failed to update SecondaryStorage offering's use_local_storage option to value:" + useLocalStorage); + throw new CloudRuntimeException( + "Failed to update SecondaryStorage offering's use_local_storage option to value:" + + useLocalStorage); } } } @@ -572,8 +608,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati Long clusterId = cmd.getClusterId(); Long storagepoolId = cmd.getStoragepoolId(); Long accountId = cmd.getAccountId(); - UserContext.current().setEventDetails(" Name: " + name + " New Value: " + (((name.toLowerCase()).contains("password")) ? "*****" : - (((value == null) ? "" : value)))); + UserContext.current().setEventDetails( + " Name: " + name + " New Value: " + + (((name.toLowerCase()).contains("password")) ? "*****" : (((value == null) ? "" : value)))); // check if config value exists ConfigurationVO config = _configDao.findByName(name); if (config == null) { @@ -614,7 +651,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (paramCountCheck > 1) { - throw new InvalidParameterValueException("cannot handle multiple IDs, provide only one ID corresponding to the scope"); + throw new InvalidParameterValueException( + "cannot handle multiple IDs, provide only one ID corresponding to the scope"); } String updatedValue = updateConfiguration(userId, name, config.getCategory(), value, scope, id); @@ -638,7 +676,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati s_logger.error("Invalid scope id provided for the parameter " + name); return "Invalid scope id provided for the parameter " + name; } - if ((name.equalsIgnoreCase("cpu.overprovisioning.factor") || name.equalsIgnoreCase("mem.overprovisioning.factor")) && value == null) { + if ((name.equalsIgnoreCase("cpu.overprovisioning.factor") || name + .equalsIgnoreCase("mem.overprovisioning.factor")) && value == null) { s_logger.error("value cannot be null for cpu.overprovisioning.factor/mem.overprovisioning.factor"); return "value cannot be null for cpu.overprovisioning.factor/mem.overprovisioning.factor"; } @@ -684,11 +723,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati try { int val = Integer.parseInt(value); if (val <= 0) { - throw new InvalidParameterValueException("Please enter a positive value for the configuration parameter:" + name); + throw new InvalidParameterValueException( + "Please enter a positive value for the configuration parameter:" + name); } } catch (NumberFormatException e) { s_logger.error("There was an error trying to parse the integer value for:" + name); - throw new InvalidParameterValueException("There was an error trying to parse the integer value for:" + name); + throw new InvalidParameterValueException("There was an error trying to parse the integer value for:" + + name); } } @@ -701,7 +742,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (range.equals("privateip")) { try { if (!NetUtils.isSiteLocalAddress(value)) { - s_logger.error("privateip range " + value + " is not a site local address for configuration variable " + name); + s_logger.error("privateip range " + value + + " is not a site local address for configuration variable " + name); return "Please enter a site local IP address."; } } catch (NullPointerException e) { @@ -719,7 +761,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati return "Please enter hypervisor list, seperated by comma"; } for (String hypervisor : hypervisors) { - if (HypervisorType.getType(hypervisor) == HypervisorType.Any || HypervisorType.getType(hypervisor) == HypervisorType.None) { + if (HypervisorType.getType(hypervisor) == HypervisorType.Any + || HypervisorType.getType(hypervisor) == HypervisorType.None) { return "Please enter valid hypervisor type"; } } @@ -733,8 +776,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (route != null) { String routeToVerify = route.trim(); if (!NetUtils.isValidCIDR(routeToVerify)) { - throw new InvalidParameterValueException("Invalid value for blacklisted route: " + route + ". Valid format is list" + - " of cidrs separated by coma. Example: 10.1.1.0/24,192.168.0.0/24"); + throw new InvalidParameterValueException("Invalid value for blacklisted route: " + route + + ". Valid format is list" + + " of cidrs separated by coma. Example: 10.1.1.0/24,192.168.0.0/24"); } } } @@ -814,8 +858,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String errorMsg = table.get(2); String dbName; - if (tableName.equals("event") || tableName.equals("cloud_usage") || tableName.equals("usage_vm_instance") || tableName.equals("usage_ip_address") || tableName.equals("usage_network") - || tableName.equals("usage_job") || tableName.equals("account") || tableName.equals("user_statistics")) { + if (tableName.equals("event") || tableName.equals("cloud_usage") || tableName.equals("usage_vm_instance") + || tableName.equals("usage_ip_address") || tableName.equals("usage_network") + || tableName.equals("usage_job") || tableName.equals("account") + || tableName.equals("user_statistics")) { dbName = "cloud_usage"; } else { dbName = "cloud"; @@ -823,7 +869,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?"; - if (tableName.equals("host") || tableName.equals("cluster") || tableName.equals("volumes") || tableName.equals("vm_instance")) { + if (tableName.equals("host") || tableName.equals("cluster") || tableName.equals("volumes") + || tableName.equals("vm_instance")) { selectSql += " and removed IS NULL"; } @@ -836,17 +883,20 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new CloudRuntimeException("The pod cannot be deleted because " + errorMsg); } } catch (SQLException ex) { - throw new CloudRuntimeException("The Management Server failed to detect if pod is deletable. Please contact Cloud Support."); + throw new CloudRuntimeException( + "The Management Server failed to detect if pod is deletable. Please contact Cloud Support."); } } } - private void checkPodAttributes(long podId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, String allocationStateStr, boolean checkForDuplicates, + private void checkPodAttributes(long podId, String podName, long zoneId, String gateway, String cidr, + String startIp, String endIp, String allocationStateStr, boolean checkForDuplicates, boolean skipGatewayOverlapCheck) { if (checkForDuplicates) { // Check if the pod already exists if (validPod(podName, zoneId)) { - throw new InvalidParameterValueException("A pod with name: " + podName + " already exists in zone " + zoneId + ". Please specify a different pod name. "); + throw new InvalidParameterValueException("A pod with name: " + podName + " already exists in zone " + + zoneId + ". Please specify a different pod name. "); } } @@ -890,8 +940,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (checkPodCIDRs == null || checkPodCIDRs.trim().isEmpty() || Boolean.parseBoolean(checkPodCIDRs)) { checkPodCidrSubnets(zoneId, podId, cidr); /* - * Commenting out due to Bug 11593 - CIDR conflicts with zone when extending pod but not when creating it - * + * Commenting out due to Bug 11593 - CIDR conflicts with zone when + * extending pod but not when creating it + * * checkCidrVlanOverlap(zoneId, cidr); */ } @@ -900,7 +951,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati try { Grouping.AllocationState.valueOf(allocationStateStr); } catch (IllegalArgumentException ex) { - throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state"); + throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + + "' to a supported state"); } } } @@ -924,7 +976,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati txn.start(); // Delete private ip addresses for the pod if there are any - List privateIps = _privateIpAddressDao.listByPodIdDcId(Long.valueOf(podId), pod.getDataCenterId()); + List privateIps = _privateIpAddressDao.listByPodIdDcId(Long.valueOf(podId), + pod.getDataCenterId()); if (!privateIps.isEmpty()) { if (!(_privateIpAddressDao.deleteIpAddressByPod(podId))) { throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId); @@ -932,7 +985,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } // Delete link local ip addresses for the pod - List localIps = _LinkLocalIpAllocDao.listByPodIdDcId(podId, pod.getDataCenterId()); + List localIps = _LinkLocalIpAllocDao.listByPodIdDcId(podId, + pod.getDataCenterId()); if (!localIps.isEmpty()) { if (!(_LinkLocalIpAllocDao.deleteIpAddressByPod(podId))) { throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId); @@ -967,12 +1021,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override public Pod editPod(UpdatePodCmd cmd) { - return editPod(cmd.getId(), cmd.getPodName(), cmd.getStartIp(), cmd.getEndIp(), cmd.getGateway(), cmd.getNetmask(), cmd.getAllocationState()); + return editPod(cmd.getId(), cmd.getPodName(), cmd.getStartIp(), cmd.getEndIp(), cmd.getGateway(), + cmd.getNetmask(), cmd.getAllocationState()); } @Override @DB - public Pod editPod(long id, String name, String startIp, String endIp, String gateway, String netmask, String allocationStateStr) { + public Pod editPod(long id, String name, String startIp, String endIp, String gateway, String netmask, + String allocationStateStr) { // verify parameters HostPodVO pod = _podDao.findById(id); @@ -995,13 +1051,15 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati long oldCidr = pod.getCidrSize(); if (newCidr > oldCidr) { - throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only"); + throw new CloudRuntimeException( + "The specified pod has allocated private IP addresses, so its IP address range can be extended only"); } } if (startIp != null && !startIp.equals(existingPodIpRange[0])) { if (NetUtils.ipRangesOverlap(startIp, null, existingPodIpRange[0], existingPodIpRange[1])) { - throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only"); + throw new CloudRuntimeException( + "The specified pod has allocated private IP addresses, so its IP address range can be extended only"); } else { leftRangeToAdd = new String[2]; long endIpForUpdate = NetUtils.ip2Long(existingPodIpRange[0]) - 1; @@ -1012,7 +1070,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (endIp != null && !endIp.equals(existingPodIpRange[1])) { if (NetUtils.ipRangesOverlap(endIp, endIp, existingPodIpRange[0], existingPodIpRange[1])) { - throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only"); + throw new CloudRuntimeException( + "The specified pod has allocated private IP addresses, so its IP address range can be extended only"); } else { rightRangeToAdd = new String[2]; long startIpForUpdate = NetUtils.ip2Long(existingPodIpRange[1]) + 1; @@ -1057,7 +1116,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // Verify pod's attributes String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); boolean checkForDuplicates = !oldPodName.equals(name); - checkPodAttributes(id, name, pod.getDataCenterId(), gateway, cidr, startIp, endIp, allocationStateStr, checkForDuplicates, false); + checkPodAttributes(id, name, pod.getDataCenterId(), gateway, cidr, startIp, endIp, allocationStateStr, + checkForDuplicates, false); Transaction txn = Transaction.currentTxn(); try { @@ -1116,7 +1176,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } @Override - public Pod createPod(long zoneId, String name, String startIp, String endIp, String gateway, String netmask, String allocationState) { + public Pod createPod(long zoneId, String name, String startIp, String endIp, String gateway, String netmask, + String allocationState) { String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); Long userId = UserContext.current().getCallerUserId(); @@ -1128,7 +1189,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @DB - public HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, String allocationStateStr, boolean skipGatewayOverlapCheck) { + public HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp, + String endIp, String allocationStateStr, boolean skipGatewayOverlapCheck) { // Check if the zone is valid if (!validZone(zoneId)) { @@ -1138,7 +1200,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // Check if zone is disabled DataCenterVO zone = _zoneDao.findById(zoneId); Account account = UserContext.current().getCaller(); - if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) { + if (Grouping.AllocationState.Disabled == zone.getAllocationState() + && !_accountMgr.isRootAdmin(account.getType())) { throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId); } @@ -1154,7 +1217,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } // Validate new pod settings - checkPodAttributes(-1, podName, zoneId, gateway, cidr, startIp, endIp, allocationStateStr, true, skipGatewayOverlapCheck); + checkPodAttributes(-1, podName, zoneId, gateway, cidr, startIp, endIp, allocationStateStr, true, + skipGatewayOverlapCheck); // Create the new pod in the database String ipRange; @@ -1258,7 +1322,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati selectSql += " AND taken IS NOT NULL"; } - if (tableName.equals("host_pod_ref") || tableName.equals("host") || tableName.equals("volumes") || tableName.equals("physical_network")) { + if (tableName.equals("host_pod_ref") || tableName.equals("host") || tableName.equals("volumes") + || tableName.equals("physical_network")) { selectSql += " AND removed is NULL"; } @@ -1275,18 +1340,21 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new CloudRuntimeException("The zone is not deletable because " + errorMsg); } } catch (SQLException ex) { - throw new CloudRuntimeException("The Management Server failed to detect if zone is deletable. Please contact Cloud Support."); + throw new CloudRuntimeException( + "The Management Server failed to detect if zone is deletable. Please contact Cloud Support."); } } } - private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, boolean checkForDuplicates, Long domainId, String allocationStateStr, - String ip6Dns1, String ip6Dns2) { + private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1, + String internalDns2, boolean checkForDuplicates, Long domainId, String allocationStateStr, String ip6Dns1, + String ip6Dns2) { if (checkForDuplicates) { // Check if a zone with the specified name already exists if (validZone(zoneName)) { - throw new InvalidParameterValueException("A zone with that name already exists. Please specify a unique zone name."); + throw new InvalidParameterValueException( + "A zone with that name already exists. Please specify a unique zone name."); } } @@ -1329,7 +1397,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati try { Grouping.AllocationState.valueOf(allocationStateStr); } catch (IllegalArgumentException ex) { - throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state"); + throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + + "' to a supported state"); } } } @@ -1347,12 +1416,15 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("The start address of the IP range is not in the CIDR subnet."); } - if (endIp != null && !NetUtils.getCidrSubNet(endIp, cidrSize).equalsIgnoreCase(NetUtils.getCidrSubNet(cidrAddress, cidrSize))) { + if (endIp != null + && !NetUtils.getCidrSubNet(endIp, cidrSize).equalsIgnoreCase( + NetUtils.getCidrSubNet(cidrAddress, cidrSize))) { throw new InvalidParameterValueException("The end address of the IP range is not in the CIDR subnet."); } if (endIp != null && NetUtils.ip2Long(startIp) > NetUtils.ip2Long(endIp)) { - throw new InvalidParameterValueException("The start IP address must have a lower value than the end IP address."); + throw new InvalidParameterValueException( + "The start IP address must have a lower value than the end IP address."); } } @@ -1365,7 +1437,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati for (IPAddressVO publicIPVO : existingPublicIPs) { long publicIP = NetUtils.ip2Long(publicIPVO.getAddress().addr()); if ((publicIP >= privateStartIp) && (publicIP <= privateEndIp)) { - throw new InvalidParameterValueException("The Start IP and endIP address range overlap with Public IP :" + publicIPVO.getAddress().addr()); + throw new InvalidParameterValueException( + "The Start IP and endIP address range overlap with Public IP :" + + publicIPVO.getAddress().addr()); } } } @@ -1380,7 +1454,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (!NetUtils.isValidIp(IpRange[0]) || !NetUtils.isValidIp(IpRange[1])) continue; if (NetUtils.ipRangesOverlap(startIp, endIp, IpRange[0], IpRange[1])) { - throw new InvalidParameterValueException("The Start IP and endIP address range overlap with private IP :" + IpRange[0] + ":" + IpRange[1]); + throw new InvalidParameterValueException( + "The Start IP and endIP address range overlap with private IP :" + IpRange[0] + ":" + + IpRange[1]); } } } @@ -1448,7 +1524,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati return true; } - @Override @DB public LDAPConfigCmd listLDAPConfig(LDAPConfigCmd cmd) { @@ -1458,13 +1533,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati cmd.setPort(port == null ? 0 : Integer.valueOf(port)); String queryFilter = _configDao.getValue(LDAPParams.queryfilter.toString()); cmd.setQueryFilter(queryFilter == null ? "" : queryFilter); - String searchBase = _configDao.getValue(LDAPParams.searchbase.toString()); + String searchBase = _configDao.getValue(LDAPParams.searchbase.toString()); cmd.setSearchBase(searchBase == null ? "" : searchBase); - String useSSL = _configDao.getValue(LDAPParams.usessl.toString()); + String useSSL = _configDao.getValue(LDAPParams.usessl.toString()); cmd.setUseSSL(useSSL == null ? Boolean.FALSE : Boolean.valueOf(useSSL)); - String binddn = _configDao.getValue(LDAPParams.dn.toString()); + String binddn = _configDao.getValue(LDAPParams.dn.toString()); cmd.setBindDN(binddn == null ? "" : binddn); - String truststore = _configDao.getValue(LDAPParams.truststore.toString()); + String truststore = _configDao.getValue(LDAPParams.truststore.toString()); cmd.setTrustStore(truststore == null ? "" : truststore); return cmd; } @@ -1473,7 +1548,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @DB public boolean updateLDAP(LDAPConfigCmd cmd) { try { - // set the ldap details in the zone details table with a zone id of -12 + // set the ldap details in the zone details table with a zone id of + // -12 String hostname = cmd.getHostname(); Integer port = cmd.getPort(); String queryFilter = cmd.getQueryFilter(); @@ -1485,12 +1561,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String trustStorePassword = cmd.getTrustStorePassword(); if (bindDN != null && bindPasswd == null) { - throw new InvalidParameterValueException("If you specify a bind name then you need to provide bind password too."); + throw new InvalidParameterValueException( + "If you specify a bind name then you need to provide bind password too."); } // check query filter if it contains valid substitution - if (!queryFilter.contains("%u") && !queryFilter.contains("%n") && !queryFilter.contains("%e")){ - throw new InvalidParameterValueException("QueryFilter should contain at least one of the substitutions: %u, %n or %e: " + queryFilter); + if (!queryFilter.contains("%u") && !queryFilter.contains("%n") && !queryFilter.contains("%e")) { + throw new InvalidParameterValueException( + "QueryFilter should contain at least one of the substitutions: %u, %n or %e: " + queryFilter); } // check if the info is correct @@ -1501,7 +1579,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati env.put(Context.SECURITY_PROTOCOL, "ssl"); protocol = "ldaps://"; if (trustStore == null || trustStorePassword == null) { - throw new InvalidParameterValueException("If you plan to use SSL then you need to configure the trust store."); + throw new InvalidParameterValueException( + "If you plan to use SSL then you need to configure the trust store."); } System.setProperty("javax.net.ssl.trustStore", trustStore); System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword); @@ -1519,21 +1598,24 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // store the result in DB Configuration ConfigurationVO cvo = _configDao.findByName(LDAPParams.hostname.toString()); if (cvo == null) { - cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.hostname.toString(), null, "Hostname or ip address of the ldap server eg: my.ldap.com"); + cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.hostname.toString(), + null, "Hostname or ip address of the ldap server eg: my.ldap.com"); } cvo.setValue(DBEncryptionUtil.encrypt(hostname)); _configDao.persist(cvo); cvo = _configDao.findByName(LDAPParams.port.toString()); if (cvo == null) { - cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.port.toString(), null, "Specify the LDAP port if required, default is 389"); + cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.port.toString(), null, + "Specify the LDAP port if required, default is 389"); } cvo.setValue(DBEncryptionUtil.encrypt(port.toString())); _configDao.persist(cvo); cvo = _configDao.findByName(LDAPParams.queryfilter.toString()); if (cvo == null) { - cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.queryfilter.toString(), null, + cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.queryfilter.toString(), + null, "You specify a query filter here, which narrows down the users, who can be part of this domain"); } cvo.setValue(DBEncryptionUtil.encrypt(queryFilter)); @@ -1541,7 +1623,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati cvo = _configDao.findByName(LDAPParams.searchbase.toString()); if (cvo == null) { - cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.searchbase.toString(), null, + cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.searchbase.toString(), + null, "The search base defines the starting point for the search in the directory tree Example: dc=cloud,dc=com."); } cvo.setValue(DBEncryptionUtil.encrypt(searchBase)); @@ -1549,42 +1632,48 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati cvo = _configDao.findByName(LDAPParams.usessl.toString()); if (cvo == null) { - cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.usessl.toString(), null, "Check Use SSL if the external LDAP server is configured for LDAP over SSL."); + cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.usessl.toString(), null, + "Check Use SSL if the external LDAP server is configured for LDAP over SSL."); } cvo.setValue(DBEncryptionUtil.encrypt(useSSL.toString())); _configDao.persist(cvo); cvo = _configDao.findByName(LDAPParams.dn.toString()); if (cvo == null) { - cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.dn.toString(), null, "Specify the distinguished name of a user with the search permission on the directory"); + cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.dn.toString(), null, + "Specify the distinguished name of a user with the search permission on the directory"); } cvo.setValue(DBEncryptionUtil.encrypt(bindDN)); _configDao.persist(cvo); cvo = _configDao.findByName(LDAPParams.passwd.toString()); if (cvo == null) { - cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.passwd.toString(), null, "Enter the password"); + cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.passwd.toString(), null, + "Enter the password"); } cvo.setValue(DBEncryptionUtil.encrypt(bindPasswd)); _configDao.persist(cvo); cvo = _configDao.findByName(LDAPParams.truststore.toString()); if (cvo == null) { - cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.truststore.toString(), null, "Enter the path to trusted keystore"); + cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.truststore.toString(), + null, "Enter the path to trusted keystore"); } cvo.setValue(DBEncryptionUtil.encrypt(trustStore)); _configDao.persist(cvo); cvo = _configDao.findByName(LDAPParams.truststorepass.toString()); if (cvo == null) { - cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.truststorepass.toString(), null, "Enter the password for trusted keystore"); + cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", + LDAPParams.truststorepass.toString(), null, "Enter the password for trusted keystore"); } cvo.setValue(DBEncryptionUtil.encrypt(trustStorePassword)); _configDao.persist(cvo); s_logger.debug("The ldap server is configured: " + hostname); } catch (NamingException ne) { - throw new InvalidParameterValueException("Naming Exception, check you ldap data ! " + ne.getMessage() + (ne.getCause() != null ? ("; Caused by:" + ne.getCause().getMessage()) : "")); + throw new InvalidParameterValueException("Naming Exception, check you ldap data ! " + ne.getMessage() + + (ne.getCause() != null ? ("; Caused by:" + ne.getCause().getMessage()) : "")); } return true; } @@ -1690,7 +1779,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (internalDns2 == null) { - internalDns2 = zone.getInternalDns2(); + internalDns2 = zone.getInternalDns2(); } if (guestCidr == null) { @@ -1707,7 +1796,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } boolean checkForDuplicates = !zoneName.equals(oldZoneName); - checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates, null, allocationStateStr, ip6Dns1, ip6Dns2);// not allowing updating domain associated with a zone, once created + checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates, null, + allocationStateStr, ip6Dns1, ip6Dns2);// not allowing updating + // domain associated with + // a zone, once created zone.setName(zoneName); zone.setDns1(dns1); @@ -1753,20 +1845,27 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // check if zone has necessary trafficTypes before enabling try { PhysicalNetwork mgmtPhyNetwork; - // zone should have a physical network with management traffiType - mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management); - if (NetworkType.Advanced == zone.getNetworkType() && ! zone.isSecurityGroupEnabled() ) { - // advanced zone without SG should have a physical network with public Thpe + // zone should have a physical network with management + // traffiType + mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, + TrafficType.Management); + if (NetworkType.Advanced == zone.getNetworkType() && !zone.isSecurityGroupEnabled()) { + // advanced zone without SG should have a physical + // network with public Thpe _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Public); } try { _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Storage); } catch (InvalidParameterValueException noStorage) { - PhysicalNetworkTrafficTypeVO mgmtTraffic = _trafficTypeDao.findBy(mgmtPhyNetwork.getId(), TrafficType.Management); - _networkSvc.addTrafficTypeToPhysicalNetwork(mgmtPhyNetwork.getId(), TrafficType.Storage.toString(), mgmtTraffic.getXenNetworkLabel(), mgmtTraffic.getKvmNetworkLabel(), - mgmtTraffic.getVmwareNetworkLabel(), mgmtTraffic.getSimulatorNetworkLabel(), mgmtTraffic.getVlan()); - s_logger.info("No storage traffic type was specified by admin, create default storage traffic on physical network " + mgmtPhyNetwork.getId() + " with same configure of management traffic type"); + PhysicalNetworkTrafficTypeVO mgmtTraffic = _trafficTypeDao.findBy(mgmtPhyNetwork.getId(), + TrafficType.Management); + _networkSvc.addTrafficTypeToPhysicalNetwork(mgmtPhyNetwork.getId(), + TrafficType.Storage.toString(), mgmtTraffic.getXenNetworkLabel(), + mgmtTraffic.getKvmNetworkLabel(), mgmtTraffic.getVmwareNetworkLabel(), + mgmtTraffic.getSimulatorNetworkLabel(), mgmtTraffic.getVlan()); + s_logger.info("No storage traffic type was specified by admin, create default storage traffic on physical network " + + mgmtPhyNetwork.getId() + " with same configure of management traffic type"); } } catch (InvalidParameterValueException ex) { throw new InvalidParameterValueException("Cannot enable this Zone since: " + ex.getMessage()); @@ -1790,8 +1889,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @DB - public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String guestCidr, String domain, Long domainId, - NetworkType zoneType, String allocationStateStr, String networkDomain, boolean isSecurityGroupEnabled, boolean isLocalStorageEnabled, String ip6Dns1, String ip6Dns2) { + public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, + String internalDns2, String guestCidr, String domain, Long domainId, NetworkType zoneType, + String allocationStateStr, String networkDomain, boolean isSecurityGroupEnabled, + boolean isLocalStorageEnabled, String ip6Dns1, String ip6Dns2) { // checking the following params outside checkzoneparams method as we do // not use these params for updatezone @@ -1809,7 +1910,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } } - checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId, allocationStateStr, ip6Dns1, ip6Dns2); + checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId, allocationStateStr, + ip6Dns1, ip6Dns2); byte[] bytes = (zoneName + System.currentTimeMillis()).getBytes(); String zoneToken = UUID.nameUUIDFromBytes(bytes).toString(); @@ -1817,18 +1919,22 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati try { txn.start(); // Create the new zone in the database - DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, guestCidr, null, null, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled, isLocalStorageEnabled, ip6Dns1, ip6Dns2); + DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, guestCidr, + null, null, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled, isLocalStorageEnabled, + ip6Dns1, ip6Dns2); if (allocationStateStr != null && !allocationStateStr.isEmpty()) { Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr); zone.setAllocationState(allocationState); } else { - // Zone will be disabled since 3.0. Admin should enable it after physical network and providers setup. + // Zone will be disabled since 3.0. Admin should enable it after + // physical network and providers setup. zone.setAllocationState(Grouping.AllocationState.Disabled); } zone = _zoneDao.persist(zone); if (domainId != null) { - //zone is explicitly dedicated to this domain - DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zone.getId(), null, null, null, domainId, null); + // zone is explicitly dedicated to this domain + DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zone.getId(), null, null, null, + domainId, null); _dedicatedDao.persist(dedicatedResource); } @@ -1869,7 +1975,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } else if (offering.getTrafficType() == TrafficType.Control) { broadcastDomainType = BroadcastDomainType.LinkLocal; } else if (offering.getTrafficType() == TrafficType.Public) { - if ((zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled()) || zone.getNetworkType() == NetworkType.Basic) { + if ((zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled()) + || zone.getNetworkType() == NetworkType.Basic) { broadcastDomainType = BroadcastDomainType.Vlan; } else { continue; @@ -1911,7 +2018,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati allocationState = Grouping.AllocationState.Disabled.toString(); } - if (!(type.equalsIgnoreCase(NetworkType.Basic.toString())) && !(type.equalsIgnoreCase(NetworkType.Advanced.toString()))) { + if (!(type.equalsIgnoreCase(NetworkType.Basic.toString())) + && !(type.equalsIgnoreCase(NetworkType.Advanced.toString()))) { throw new InvalidParameterValueException("Invalid zone type; only Advanced and Basic values are supported"); } else if (type.equalsIgnoreCase(NetworkType.Basic.toString())) { isBasic = true; @@ -1938,7 +2046,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati isSecurityGroupEnabled = true; } - return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, guestCidr, domainVO != null ? domainVO.getName() : null, domainId, zoneType, allocationState, networkDomain, + return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, guestCidr, + domainVO != null ? domainVO.getName() : null, domainId, zoneType, allocationState, networkDomain, isSecurityGroupEnabled, isLocalStorageEnabled, ip6Dns1, ip6Dns2); } @@ -1948,27 +2057,32 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String name = cmd.getServiceOfferingName(); if ((name == null) || (name.length() == 0)) { - throw new InvalidParameterValueException("Failed to create service offering: specify the name that has non-zero length"); + throw new InvalidParameterValueException( + "Failed to create service offering: specify the name that has non-zero length"); } String displayText = cmd.getDisplayText(); if ((displayText == null) || (displayText.length() == 0)) { - throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the display text that has non-zero length"); + throw new InvalidParameterValueException("Failed to create service offering " + name + + ": specify the display text that has non-zero length"); } Long cpuNumber = cmd.getCpuNumber(); if ((cpuNumber == null) || (cpuNumber.intValue() <= 0) || (cpuNumber.intValue() > 2147483647)) { - throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the cpu number value between 1 and 2147483647"); + throw new InvalidParameterValueException("Failed to create service offering " + name + + ": specify the cpu number value between 1 and 2147483647"); } Long cpuSpeed = cmd.getCpuSpeed(); if ((cpuSpeed == null) || (cpuSpeed.intValue() <= 0) || (cpuSpeed.intValue() > 2147483647)) { - throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the cpu speed value between 1 and 2147483647"); + throw new InvalidParameterValueException("Failed to create service offering " + name + + ": specify the cpu speed value between 1 and 2147483647"); } Long memory = cmd.getMemory(); if ((memory == null) || (memory.intValue() < 32) || (memory.intValue() > 2147483647)) { - throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the memory value between 32 and 2147483647 MB"); + throw new InvalidParameterValueException("Failed to create service offering " + name + + ": specify the memory value between 32 and 2147483647 MB"); } // check if valid domain @@ -1982,7 +2096,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (storageType.equalsIgnoreCase(ServiceOffering.StorageType.local.toString())) { localStorageRequired = true; } else if (!storageType.equalsIgnoreCase(ServiceOffering.StorageType.shared.toString())) { - throw new InvalidParameterValueException("Invalid storage type " + storageType + " specified, valid types are: 'local' and 'shared'"); + throw new InvalidParameterValueException("Invalid storage type " + storageType + + " specified, valid types are: 'local' and 'shared'"); } } @@ -2004,7 +2119,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } else if (VirtualMachine.Type.InternalLoadBalancerVm.toString().toLowerCase().equals(vmTypeString)) { vmType = VirtualMachine.Type.InternalLoadBalancerVm; } else { - throw new InvalidParameterValueException("Invalid systemVmType. Supported types are: " + VirtualMachine.Type.DomainRouter + ", " + VirtualMachine.Type.ConsoleProxy + ", " + throw new InvalidParameterValueException("Invalid systemVmType. Supported types are: " + + VirtualMachine.Type.DomainRouter + ", " + VirtualMachine.Type.ConsoleProxy + ", " + VirtualMachine.Type.SecondaryStorageVm); } } else { @@ -2013,7 +2129,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (cmd.getNetworkRate() != null && !allowNetworkRate) { - throw new InvalidParameterValueException("Network rate can be specified only for non-System offering and system offerings having \"domainrouter\" systemvmtype"); + throw new InvalidParameterValueException( + "Network rate can be specified only for non-System offering and system offerings having \"domainrouter\" systemvmtype"); } if (cmd.getDeploymentPlanner() != null) { @@ -2038,10 +2155,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_CREATE, eventDescription = "creating service offering") public ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMachine.Type vm_type, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, - boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, + boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, Integer networkRate, String deploymentPlanner, Map details) { tags = cleanupTags(tags); - ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, null, offerHA, limitResourceUse, volatileVm, displayText, localStorageRequired, false, tags, isSystem, vm_type, + ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, null, offerHA, + limitResourceUse, volatileVm, displayText, localStorageRequired, false, tags, isSystem, vm_type, domainId, hostTag, deploymentPlanner); if ((offering = _serviceOfferingDao.persist(offering)) != null) { @@ -2129,7 +2247,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @ActionEvent(eventType = EventTypes.EVENT_DISK_OFFERING_CREATE, eventDescription = "creating disk offering") - public DiskOfferingVO createDiskOffering(Long domainId, String name, String description, Long numGibibytes, String tags, boolean isCustomized, boolean localStorageRequired, boolean isDisplayOfferingEnabled) { + public DiskOfferingVO createDiskOffering(Long domainId, String name, String description, Long numGibibytes, + String tags, boolean isCustomized, boolean localStorageRequired, boolean isDisplayOfferingEnabled) { long diskSize = 0;// special case for custom disk offerings if (numGibibytes != null && (numGibibytes <= 0)) { throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb."); @@ -2185,11 +2304,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (storageType.equalsIgnoreCase(ServiceOffering.StorageType.local.toString())) { localStorageRequired = true; } else if (!storageType.equalsIgnoreCase(ServiceOffering.StorageType.shared.toString())) { - throw new InvalidParameterValueException("Invalid storage type " + storageType + " specified, valid types are: 'local' and 'shared'"); + throw new InvalidParameterValueException("Invalid storage type " + storageType + + " specified, valid types are: 'local' and 'shared'"); } } - return createDiskOffering(domainId, name, description, numGibibytes, tags, isCustomized, localStorageRequired, isDisplayOfferingEnabled); + return createDiskOffering(domainId, name, description, numGibibytes, tags, isCustomized, localStorageRequired, + isDisplayOfferingEnabled); } @Override @@ -2309,8 +2430,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @DB - @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_CREATE, eventDescription = "creating vlan ip range", async = false) - public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, ResourceAllocationException { + @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_CREATE, eventDescription = "creating vlan ip range", + async = false) + public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, + ConcurrentOperationException, ResourceUnavailableException, ResourceAllocationException { Long zoneId = cmd.getZoneId(); Long podId = cmd.getPodId(); String startIP = cmd.getStartIp(); @@ -2385,7 +2508,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati physicalNetworkId = network.getPhysicalNetworkId(); } } else if (ipv6) { - throw new InvalidParameterValueException("Only support IPv6 on extending existed network"); + throw new InvalidParameterValueException("Only support IPv6 on extending existed network"); } // Verify that zone exists @@ -2395,9 +2518,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (ipv6) { - if (network.getGuestType() != GuestType.Shared || zone.isSecurityGroupEnabled()) { - throw new InvalidParameterValueException("Only support IPv6 on extending existed share network without SG"); - } + if (network.getGuestType() != GuestType.Shared || zone.isSecurityGroupEnabled()) { + throw new InvalidParameterValueException( + "Only support IPv6 on extending existed share network without SG"); + } } // verify that physical network exists PhysicalNetworkVO pNtwk = null; @@ -2419,34 +2543,41 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } else { if (forVirtualNetwork) { // default physical network with public traffic in the zone - physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Public).getId(); + physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, + TrafficType.Public).getId(); } else { if (zone.getNetworkType() == DataCenter.NetworkType.Basic) { - // default physical network with guest traffic in the zone - physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Guest).getId(); + // default physical network with guest traffic in the + // zone + physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, + TrafficType.Guest).getId(); } else if (zone.getNetworkType() == DataCenter.NetworkType.Advanced) { if (zone.isSecurityGroupEnabled()) { - physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Guest).getId(); + physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, + TrafficType.Guest).getId(); } else { - throw new InvalidParameterValueException("Physical Network Id is null, please provide the Network id for Direct vlan creation "); + throw new InvalidParameterValueException( + "Physical Network Id is null, please provide the Network id for Direct vlan creation "); } } } } } - // Check if zone is enabled Account caller = UserContext.current().getCaller(); - if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) { + if (Grouping.AllocationState.Disabled == zone.getAllocationState() + && !_accountMgr.isRootAdmin(caller.getType())) { throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId); } if (zone.isSecurityGroupEnabled() && zone.getNetworkType() != DataCenter.NetworkType.Basic && forVirtualNetwork) { - throw new InvalidParameterValueException("Can't add virtual ip range into a zone with security group enabled"); + throw new InvalidParameterValueException( + "Can't add virtual ip range into a zone with security group enabled"); } - // If networkId is not specified, and vlan is Virtual or Direct Untagged, try to locate default networks + // If networkId is not specified, and vlan is Virtual or Direct + // Untagged, try to locate default networks if (forVirtualNetwork) { if (network == null) { // find default public network in the zone @@ -2469,47 +2600,51 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati zoneId = network.getDataCenterId(); } } else if (network.getGuestType() == null || network.getGuestType() == Network.GuestType.Isolated) { - throw new InvalidParameterValueException("Can't create direct vlan for network id=" + networkId + " with type: " + network.getGuestType()); + throw new InvalidParameterValueException("Can't create direct vlan for network id=" + networkId + + " with type: " + network.getGuestType()); } } - boolean sameSubnet=false; + Pair> sameSubnet = null; // Can add vlan range only to the network which allows it if (!network.getSpecifyIpRanges()) { throw new InvalidParameterValueException("Network " + network + " doesn't support adding ip ranges"); } - if ( zone.getNetworkType() == DataCenter.NetworkType.Advanced ) { + if (zone.getNetworkType() == DataCenter.NetworkType.Advanced) { if (network.getTrafficType() == TrafficType.Guest) { if (network.getGuestType() != GuestType.Shared) { - throw new InvalidParameterValueException("Can execute createVLANIpRanges on shared guest network, but type of this guest network " - + network.getId() + " is " + network.getGuestType()); + throw new InvalidParameterValueException( + "Can execute createVLANIpRanges on shared guest network, but type of this guest network " + + network.getId() + " is " + network.getGuestType()); } List vlans = _vlanDao.listVlansByNetworkId(network.getId()); VlanVO vlan = vlans.get(0); - if ( vlans != null && vlans.size() > 0 ) { - if ( vlanId == null ) { + if (vlans != null && vlans.size() > 0) { + if (vlanId == null) { vlanId = vlan.getVlanTag(); } else if (!vlan.getVlanTag().equals(vlanId)) { - throw new InvalidParameterValueException("there is already one vlan " + vlan.getVlanTag() + " on network :" + - + network.getId() + ", only one vlan is allowed on guest network"); + throw new InvalidParameterValueException("there is already one vlan " + vlan.getVlanTag() + + " on network :" + +network.getId() + ", only one vlan is allowed on guest network"); } } - sameSubnet=validateIpRange(startIP, endIP, newVlanGateway, newVlanNetmask, vlans, ipv4, ipv6, ip6Gateway, ip6Cidr,startIPv6, endIPv6, network); + sameSubnet = validateIpRange(startIP, endIP, newVlanGateway, newVlanNetmask, vlans, ipv4, ipv6, + ip6Gateway, ip6Cidr, startIPv6, endIPv6, network); } } else if (network.getTrafficType() == TrafficType.Management) { - throw new InvalidParameterValueException("Cannot execute createVLANIpRanges on management network"); - } - else if (zone.getNetworkType() == NetworkType.Basic){ - List vlans = _vlanDao.listVlansByNetworkId(network.getId()); - sameSubnet=validateIpRange(startIP,endIP,newVlanGateway, newVlanNetmask, vlans, ipv4, ipv6, ip6Gateway, ip6Cidr, startIPv6, endIPv6, network); + throw new InvalidParameterValueException("Cannot execute createVLANIpRanges on management network"); + } else if (zone.getNetworkType() == NetworkType.Basic) { + List vlans = _vlanDao.listVlansByNetworkId(network.getId()); + sameSubnet = validateIpRange(startIP, endIP, newVlanGateway, newVlanNetmask, vlans, ipv4, ipv6, ip6Gateway, + ip6Cidr, startIPv6, endIPv6, network); } - if (zoneId == null || (ipv4 && (newVlanGateway == null || newVlanNetmask == null)) || (ipv6 && (ip6Gateway == null || ip6Cidr == null))) { - throw new InvalidParameterValueException("Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks"); + if (zoneId == null || (ipv6 && (ip6Gateway == null || ip6Cidr == null))) { + throw new InvalidParameterValueException( + "Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks"); } if (forVirtualNetwork) { @@ -2517,109 +2652,157 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati long accountIpRange = NetUtils.ip2Long(endIP) - NetUtils.ip2Long(startIP) + 1; - //check resource limits + // check resource limits _resourceLimitMgr.checkResourceLimit(vlanOwner, ResourceType.public_ip, accountIpRange); } } // Check if the IP range overlaps with the private ip if (ipv4) { - checkOverlapPrivateIpRange(zoneId, startIP, endIP); + checkOverlapPrivateIpRange(zoneId, startIP, endIP); } Transaction txn = Transaction.currentTxn(); txn.start(); + if (sameSubnet == null || sameSubnet.first() == false) { + s_logger.info("adding a new subnet to the network " + network.getId()); + } else { + // if it is same subnet the user might not send the vlan and the + // netmask details. so we are + // figuring out while validation and setting them here. + newVlanGateway = sameSubnet.second().first(); + newVlanNetmask = sameSubnet.second().second(); + } Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP, endIP, newVlanGateway, newVlanNetmask, vlanId, vlanOwner, startIPv6, endIPv6, ip6Gateway, ip6Cidr); - //create an entry in the nic_secondary table. This will be the new gateway that will be configured on the corresponding routervm. - if (sameSubnet == false) { - s_logger.info("adding a new subnet to the network "+network.getId()); - } + // create an entry in the nic_secondary table. This will be the new + // gateway that will be configured on the corresponding routervm. txn.commit(); return vlan; } - public boolean validateIpRange(String startIP, String endIP, String newVlanGateway, String newVlanNetmask, List vlans, boolean ipv4, boolean ipv6, String ip6Gateway, String ip6Cidr, String startIPv6, String endIPv6, Network network) { - String vlanGateway; - String vlanNetmask; - boolean sameSubnet = false; - if ( vlans != null && vlans.size() > 0 ) { + public int checkIfSubsetOrSuperset(String newVlanGateway, String newVlanNetmask, VlanVO vlan, String startIP, + String endIP) { + if (newVlanGateway == null && newVlanNetmask == null) { + newVlanGateway = vlan.getVlanGateway(); + newVlanNetmask = vlan.getVlanNetmask(); + // this means he is trying to add to the existing subnet. + if (NetUtils.sameSubnet(startIP, newVlanGateway, newVlanNetmask)) { + if (NetUtils.sameSubnet(endIP, newVlanGateway, newVlanNetmask)) { + return 3; + } + } + return 0; + } else if (newVlanGateway == null || newVlanGateway == null) { + throw new InvalidParameterValueException( + "either both netmask and gateway should be passed or both should me omited."); + } else { + if (!NetUtils.sameSubnet(startIP, newVlanGateway, newVlanNetmask)) { + throw new InvalidParameterValueException("The start ip and gateway do not belong to the same subnet"); + } + if (!NetUtils.sameSubnet(endIP, newVlanGateway, newVlanNetmask)) { + throw new InvalidParameterValueException("The end ip and gateway do not belong to the same subnet"); + } + } + String cidrnew = NetUtils.getCidrFromGatewayAndNetmask(newVlanGateway, newVlanNetmask); + String existing_cidr = NetUtils.getCidrFromGatewayAndNetmask(vlan.getVlanGateway(), vlan.getVlanNetmask()); + return (NetUtils.isNetowrkASubsetOrSupersetOfNetworkB(cidrnew, existing_cidr)); + } + + public Pair> validateIpRange(String startIP, String endIP, String newVlanGateway, + String newVlanNetmask, List vlans, boolean ipv4, boolean ipv6, String ip6Gateway, String ip6Cidr, + String startIPv6, String endIPv6, Network network) { + String vlanGateway = null; + String vlanNetmask = null; + boolean sameSubnet = false; + if (vlans != null && vlans.size() > 0) { for (VlanVO vlan : vlans) { if (ipv4) { vlanGateway = vlan.getVlanGateway(); vlanNetmask = vlan.getVlanNetmask(); - // Check if ip addresses are in network range - if (!NetUtils.sameSubnet(startIP, vlanGateway, vlanNetmask)) { - if (!NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)) { - // check if the the new subnet is not a superset of the existing subnets. - if (NetUtils.isNetworkAWithinNetworkB(NetUtils.getCidrFromGatewayAndNetmask(vlanGateway,vlanNetmask), NetUtils.ipAndNetMaskToCidr(startIP, newVlanNetmask))){ - throw new InvalidParameterValueException ("The new subnet is a superset of the existing subnet"); - } - // check if the new subnet is not a subset of the existing subnet. - if (NetUtils.isNetworkAWithinNetworkB(NetUtils.ipAndNetMaskToCidr(startIP, newVlanNetmask), NetUtils.getCidrFromGatewayAndNetmask(vlanGateway,vlanNetmask))){ - throw new InvalidParameterValueException("The new subnet is a subset of the existing subnet"); - } - } - } else if (NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)){ - // trying to add to the same subnet. + // check if subset or super set or neither. + int val = checkIfSubsetOrSuperset(newVlanGateway, newVlanNetmask, vlan, startIP, endIP); + if (val == 1) { + // this means that new cidr is a superset of the + // existing subnet. + throw new InvalidParameterValueException( + "The subnet you are trying to add is a superset of the existing subnet having gateway" + + vlan.getVlanGateway() + " and netmask " + vlan.getVlanNetmask()); + } else if (val == 0) { + // this implies the user is trying to add a new subnet + // which is not a superset or subset of this subnet. + // checking with the other subnets. + continue; + } else if (val == 2) { + // this means he is trying to add to the same subnet. + throw new InvalidParameterValueException( + "The subnet you are trying to add is a subset of the existing subnet having gateway" + + vlan.getVlanGateway() + " and netmask " + vlan.getVlanNetmask()); + } else if (val == 3) { sameSubnet = true; - if (newVlanGateway == null) { - newVlanGateway = vlanGateway; - } - if (!newVlanGateway.equals(vlanGateway)){ - throw new InvalidParameterValueException("The gateway of the ip range is not same as the gateway of the subnet."); - } - break; - } - else { - throw new InvalidParameterValueException("Start ip and End ip is not in vlan range!"); } } if (ipv6) { if (ip6Gateway != null && !ip6Gateway.equals(network.getIp6Gateway())) { - throw new InvalidParameterValueException("The input gateway " + ip6Gateway + " is not same as network gateway " + network.getIp6Gateway()); + throw new InvalidParameterValueException("The input gateway " + ip6Gateway + + " is not same as network gateway " + network.getIp6Gateway()); } if (ip6Cidr != null && !ip6Cidr.equals(network.getIp6Cidr())) { - throw new InvalidParameterValueException("The input cidr " + ip6Cidr + " is not same as network ciddr " + network.getIp6Cidr()); + throw new InvalidParameterValueException("The input cidr " + ip6Cidr + + " is not same as network ciddr " + network.getIp6Cidr()); } ip6Gateway = network.getIp6Gateway(); ip6Cidr = network.getIp6Cidr(); _networkModel.checkIp6Parameters(startIPv6, endIPv6, ip6Gateway, ip6Cidr); } } - if (sameSubnet == false) { - if (newVlanGateway ==null) { - throw new MissingParameterValueException("The gateway for the new subnet is not specified."); - } - } } - return sameSubnet; + if (newVlanGateway == null && newVlanNetmask == null && sameSubnet == false) { + throw new InvalidParameterValueException( + "The ip range dose not belong to any of the existing subnets, Provide the netmask and gateway if you want to add new subnet"); + } + Pair vlanDetails = null; + + if (sameSubnet) { + vlanDetails = new Pair(vlanGateway, vlanNetmask); + } else { + vlanDetails = new Pair(newVlanGateway, newVlanNetmask); + } + // check if the gatewayip is the part of the ip range being added. + if (NetUtils.ipRangesOverlap(startIP, endIP, vlanDetails.first(), vlanDetails.first())) { + throw new InvalidParameterValueException( + "The gateway ip should not be the part of the ip range being added."); + } + + Pair> result = new Pair>(sameSubnet, vlanDetails); + return result; } @Override @DB - public Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, boolean forVirtualNetwork, Long podId, - String startIP, String endIP, String vlanGateway, String vlanNetmask, - String vlanId, Account vlanOwner, String startIPv6, String endIPv6, String vlanIp6Gateway, String vlanIp6Cidr) { + public Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, + boolean forVirtualNetwork, Long podId, String startIP, String endIP, String vlanGateway, + String vlanNetmask, String vlanId, Account vlanOwner, String startIPv6, String endIPv6, + String vlanIp6Gateway, String vlanIp6Cidr) { Network network = _networkModel.getNetwork(networkId); boolean ipv4 = false, ipv6 = false; if (startIP != null) { - ipv4 = true; + ipv4 = true; } if (startIPv6 != null) { - ipv6 = true; + ipv6 = true; } if (!ipv4 && !ipv6) { throw new InvalidParameterValueException("Please specify IPv4 or IPv6 address."); } - //Validate the zone + // Validate the zone DataCenterVO zone = _zoneDao.findById(zoneId); if (zone == null) { throw new InvalidParameterValueException("Please specify a valid zone."); @@ -2628,12 +2811,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // ACL check checkZoneAccess(UserContext.current().getCaller(), zone); - //Validate the physical network + // Validate the physical network if (_physicalNetworkDao.findById(physicalNetworkId) == null) { throw new InvalidParameterValueException("Please specify a valid physical network id"); } - //Validate the pod + // Validate the pod if (podId != null) { Pod pod = _podDao.findById(podId); if (pod == null) { @@ -2642,27 +2825,29 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (pod.getDataCenterId() != zoneId) { throw new InvalidParameterValueException("Pod id=" + podId + " doesn't belong to zone id=" + zoneId); } - //pod vlans can be created in basic zone only + // pod vlans can be created in basic zone only if (zone.getNetworkType() != NetworkType.Basic || network.getTrafficType() != TrafficType.Guest) { throw new InvalidParameterValueException("Pod id can be specified only for the networks of type " - + TrafficType.Guest + " in zone of type " + NetworkType.Basic); + + TrafficType.Guest + " in zone of type " + NetworkType.Basic); } } - //1) if vlan is specified for the guest network range, it should be the same as network's vlan - //2) if vlan is missing, default it to the guest network's vlan + // 1) if vlan is specified for the guest network range, it should be the + // same as network's vlan + // 2) if vlan is missing, default it to the guest network's vlan if (network.getTrafficType() == TrafficType.Guest) { String networkVlanId = null; URI uri = network.getBroadcastUri(); if (uri != null) { String[] vlan = uri.toString().split("vlan:\\/\\/"); networkVlanId = vlan[1]; - //For pvlan + // For pvlan networkVlanId = networkVlanId.split("-")[0]; } if (vlanId != null) { - // if vlan is specified, throw an error if it's not equal to network's vlanId + // if vlan is specified, throw an error if it's not equal to + // network's vlanId if (networkVlanId != null && !networkVlanId.equalsIgnoreCase(vlanId)) { throw new InvalidParameterValueException("Vlan doesn't match vlan of the network"); } @@ -2670,7 +2855,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati vlanId = networkVlanId; } } else if (network.getTrafficType() == TrafficType.Public && vlanId == null) { - //vlan id is required for public network + // vlan id is required for public network throw new InvalidParameterValueException("Vlan id is required when add ip range to the public network"); } @@ -2680,180 +2865,200 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati VlanType vlanType = forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached; - if (vlanOwner != null && zone.getNetworkType() != NetworkType.Advanced) { - throw new InvalidParameterValueException("Vlan owner can be defined only in the zone of type " + NetworkType.Advanced); + throw new InvalidParameterValueException("Vlan owner can be defined only in the zone of type " + + NetworkType.Advanced); } if (ipv4) { - // Make sure the gateway is valid - if (!NetUtils.isValidIp(vlanGateway)) { - throw new InvalidParameterValueException("Please specify a valid gateway"); - } + // Make sure the gateway is valid + if (!NetUtils.isValidIp(vlanGateway)) { + throw new InvalidParameterValueException("Please specify a valid gateway"); + } - // Make sure the netmask is valid - if (!NetUtils.isValidIp(vlanNetmask)) { - throw new InvalidParameterValueException("Please specify a valid netmask"); - } + // Make sure the netmask is valid + if (!NetUtils.isValidIp(vlanNetmask)) { + throw new InvalidParameterValueException("Please specify a valid netmask"); + } } if (ipv6) { - if (!NetUtils.isValidIpv6(vlanIp6Gateway)) { - throw new InvalidParameterValueException("Please specify a valid IPv6 gateway"); - } - if (!NetUtils.isValidIp6Cidr(vlanIp6Cidr)) { - throw new InvalidParameterValueException("Please specify a valid IPv6 CIDR"); - } + if (!NetUtils.isValidIpv6(vlanIp6Gateway)) { + throw new InvalidParameterValueException("Please specify a valid IPv6 gateway"); + } + if (!NetUtils.isValidIp6Cidr(vlanIp6Cidr)) { + throw new InvalidParameterValueException("Please specify a valid IPv6 CIDR"); + } } if (ipv4) { - String newVlanSubnet = NetUtils.getSubNet(vlanGateway, vlanNetmask); + String newVlanSubnet = NetUtils.getSubNet(vlanGateway, vlanNetmask); - // Check if the new VLAN's subnet conflicts with the guest network in - // the specified zone (guestCidr is null for basic zone) - String guestNetworkCidr = zone.getGuestNetworkCidr(); - if (guestNetworkCidr != null) { - String[] cidrPair = guestNetworkCidr.split("\\/"); - String guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrPair[0], Long.parseLong(cidrPair[1])); - long guestCidrSize = Long.parseLong(cidrPair[1]); - long vlanCidrSize = NetUtils.getCidrSize(vlanNetmask); + // Check if the new VLAN's subnet conflicts with the guest network + // in + // the specified zone (guestCidr is null for basic zone) + String guestNetworkCidr = zone.getGuestNetworkCidr(); + if (guestNetworkCidr != null) { + String[] cidrPair = guestNetworkCidr.split("\\/"); + String guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrPair[0], Long.parseLong(cidrPair[1])); + long guestCidrSize = Long.parseLong(cidrPair[1]); + long vlanCidrSize = NetUtils.getCidrSize(vlanNetmask); - long cidrSizeToUse = -1; - if (vlanCidrSize < guestCidrSize) { - cidrSizeToUse = vlanCidrSize; - } else { - cidrSizeToUse = guestCidrSize; - } + long cidrSizeToUse = -1; + if (vlanCidrSize < guestCidrSize) { + cidrSizeToUse = vlanCidrSize; + } else { + cidrSizeToUse = guestCidrSize; + } - String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse); + String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse); - if (newVlanSubnet.equals(guestSubnet)) { - throw new InvalidParameterValueException("The new IP range you have specified has the same subnet as the guest network in zone: " + zone.getName() - + ". Please specify a different gateway/netmask."); - } - } + if (newVlanSubnet.equals(guestSubnet)) { + throw new InvalidParameterValueException( + "The new IP range you have specified has the same subnet as the guest network in zone: " + + zone.getName() + ". Please specify a different gateway/netmask."); + } + } - // Check if there are any errors with the IP range - checkPublicIpRangeErrors(zoneId, vlanId, vlanGateway, vlanNetmask, startIP, endIP); + // Check if there are any errors with the IP range + checkPublicIpRangeErrors(zoneId, vlanId, vlanGateway, vlanNetmask, startIP, endIP); - // Throw an exception if any of the following is true: - // 1. Another VLAN in the same zone has a different tag but the same - // subnet as the new VLAN. Make an exception for the - // case when both vlans are Direct. - // 2. Another VLAN in the same zone that has the same tag and subnet as - // the new VLAN has IPs that overlap with the IPs - // being added - // 3. Another VLAN in the same zone that has the same tag and subnet as - // the new VLAN has a different gateway than the - // new VLAN - // 4. If VLAN is untagged and Virtual, and there is existing UNTAGGED - // vlan with different subnet - List vlans = _vlanDao.listByZone(zone.getId()); - for (VlanVO vlan : vlans) { - String otherVlanGateway = vlan.getVlanGateway(); - // Continue if it's not IPv4 - if (otherVlanGateway == null) { - continue; - } - String otherVlanSubnet = NetUtils.getSubNet(vlan.getVlanGateway(), vlan.getVlanNetmask()); - String[] otherVlanIpRange = vlan.getIpRange().split("\\-"); - String otherVlanStartIP = otherVlanIpRange[0]; - String otherVlanEndIP = null; - if (otherVlanIpRange.length > 1) { - otherVlanEndIP = otherVlanIpRange[1]; - } + // Throw an exception if any of the following is true: + // 1. Another VLAN in the same zone has a different tag but the same + // subnet as the new VLAN. Make an exception for the + // case when both vlans are Direct. + // 2. Another VLAN in the same zone that has the same tag and subnet + // as + // the new VLAN has IPs that overlap with the IPs + // being added + // 3. Another VLAN in the same zone that has the same tag and subnet + // as + // the new VLAN has a different gateway than the + // new VLAN + // 4. If VLAN is untagged and Virtual, and there is existing + // UNTAGGED + // vlan with different subnet + List vlans = _vlanDao.listByZone(zone.getId()); + for (VlanVO vlan : vlans) { + String otherVlanGateway = vlan.getVlanGateway(); + // Continue if it's not IPv4 + if (otherVlanGateway == null) { + continue; + } + String otherVlanSubnet = NetUtils.getSubNet(vlan.getVlanGateway(), vlan.getVlanNetmask()); + String[] otherVlanIpRange = vlan.getIpRange().split("\\-"); + String otherVlanStartIP = otherVlanIpRange[0]; + String otherVlanEndIP = null; + if (otherVlanIpRange.length > 1) { + otherVlanEndIP = otherVlanIpRange[1]; + } - if (forVirtualNetwork && !vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet) && !allowIpRangeOverlap(vlan, forVirtualNetwork, networkId)) { - throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " in zone " + zone.getName() - + " has the same subnet. Please specify a different gateway/netmask."); - } + if (forVirtualNetwork && !vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet) + && !allowIpRangeOverlap(vlan, forVirtualNetwork, networkId)) { + throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + + " in zone " + zone.getName() + + " has the same subnet. Please specify a different gateway/netmask."); + } - boolean vlansUntaggedAndVirtual = (vlanId.equals(Vlan.UNTAGGED) && vlanId.equals(vlan.getVlanTag()) && forVirtualNetwork && vlan.getVlanType() == VlanType.VirtualNetwork); + boolean vlansUntaggedAndVirtual = (vlanId.equals(Vlan.UNTAGGED) && vlanId.equals(vlan.getVlanTag()) + && forVirtualNetwork && vlan.getVlanType() == VlanType.VirtualNetwork); - if (vlansUntaggedAndVirtual && !newVlanSubnet.equals(otherVlanSubnet)) { - throw new InvalidParameterValueException("The Untagged ip range with different subnet already exists in zone " + zone.getId()); - } + if (vlansUntaggedAndVirtual && !newVlanSubnet.equals(otherVlanSubnet)) { + throw new InvalidParameterValueException( + "The Untagged ip range with different subnet already exists in zone " + zone.getId()); + } - if (vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet)) { - if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) { - throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() - + " already has IPs that overlap with the new range. Please specify a different start IP/end IP."); - } + if (vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet)) { + if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) { + throw new InvalidParameterValueException( + "The IP range with tag: " + + vlan.getVlanTag() + + " already has IPs that overlap with the new range. Please specify a different start IP/end IP."); + } - if (!vlanGateway.equals(otherVlanGateway)) { - throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " has already been added with gateway " + otherVlanGateway - + ". Please specify a different tag."); - } - } - } + if (!vlanGateway.equals(otherVlanGateway)) { + throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + + " has already been added with gateway " + otherVlanGateway + + ". Please specify a different tag."); + } + } + } } String ipv6Range = null; if (ipv6) { - ipv6Range = startIPv6; - if (endIPv6 != null) { - ipv6Range += "-" + endIPv6; - } + ipv6Range = startIPv6; + if (endIPv6 != null) { + ipv6Range += "-" + endIPv6; + } - List vlans = _vlanDao.listByZone(zone.getId()); - for (VlanVO vlan : vlans) { - if (vlan.getIp6Gateway() == null) { - continue; - } - if (vlanId.equals(vlan.getVlanTag())) { - if (NetUtils.isIp6RangeOverlap(ipv6Range, vlan.getIp6Range())) { - throw new InvalidParameterValueException("The IPv6 range with tag: " + vlan.getVlanTag() - + " already has IPs that overlap with the new range. Please specify a different start IP/end IP."); - } + List vlans = _vlanDao.listByZone(zone.getId()); + for (VlanVO vlan : vlans) { + if (vlan.getIp6Gateway() == null) { + continue; + } + if (vlanId.equals(vlan.getVlanTag())) { + if (NetUtils.isIp6RangeOverlap(ipv6Range, vlan.getIp6Range())) { + throw new InvalidParameterValueException( + "The IPv6 range with tag: " + + vlan.getVlanTag() + + " already has IPs that overlap with the new range. Please specify a different start IP/end IP."); + } - if (!vlanIp6Gateway.equals(vlan.getIp6Gateway())) { - throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " has already been added with gateway " + vlan.getIp6Gateway() - + ". Please specify a different tag."); - } - } - } + if (!vlanIp6Gateway.equals(vlan.getIp6Gateway())) { + throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + + " has already been added with gateway " + vlan.getIp6Gateway() + + ". Please specify a different tag."); + } + } + } } // Check if a guest VLAN is using the same tag if (_zoneDao.findVnet(zoneId, physicalNetworkId, vlanId).size() > 0) { - throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for the guest network in zone " + zone.getName()); + throw new InvalidParameterValueException("The VLAN tag " + vlanId + + " is already being used for the guest network in zone " + zone.getName()); } String ipRange = null; if (ipv4) { - ipRange = startIP; - if (endIP != null) { - ipRange += "-" + endIP; - } + ipRange = startIP; + if (endIP != null) { + ipRange += "-" + endIP; + } } // Everything was fine, so persist the VLAN Transaction txn = Transaction.currentTxn(); txn.start(); - VlanVO vlan = new VlanVO(vlanType, vlanId, vlanGateway, vlanNetmask, zone.getId(), ipRange, networkId, physicalNetworkId, vlanIp6Gateway, vlanIp6Cidr, ipv6Range); + VlanVO vlan = new VlanVO(vlanType, vlanId, vlanGateway, vlanNetmask, zone.getId(), ipRange, networkId, + physicalNetworkId, vlanIp6Gateway, vlanIp6Cidr, ipv6Range); s_logger.debug("Saving vlan range " + vlan); vlan = _vlanDao.persist(vlan); - // IPv6 use a used ip map, is different from ipv4, no need to save public ip range + // IPv6 use a used ip map, is different from ipv4, no need to save + // public ip range if (ipv4) { - if (!savePublicIPRange(startIP, endIP, zoneId, vlan.getId(), networkId, physicalNetworkId)) { - throw new CloudRuntimeException("Failed to save IPv4 range. Please contact Cloud Support."); - } + if (!savePublicIPRange(startIP, endIP, zoneId, vlan.getId(), networkId, physicalNetworkId)) { + throw new CloudRuntimeException("Failed to save IPv4 range. Please contact Cloud Support."); + } } if (vlanOwner != null) { - // This VLAN is account-specific, so create an AccountVlanMapVO entry + // This VLAN is account-specific, so create an AccountVlanMapVO + // entry AccountVlanMapVO accountVlanMapVO = new AccountVlanMapVO(vlanOwner.getId(), vlan.getId()); _accountVlanMapDao.persist(accountVlanMapVO); - // generate usage event for dedication of every ip address in the range + // generate usage event for dedication of every ip address in the + // range List ips = _publicIpAddressDao.listByVlanId(vlan.getId()); for (IPAddressVO ip : ips) { - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, vlanOwner.getId(), - ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlan.getVlanType().toString(), - ip.getSystem(), ip.getClass().getName(), ip.getUuid()); + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, vlanOwner.getId(), ip + .getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlan + .getVlanType().toString(), ip.getSystem(), ip.getClass().getName(), ip.getUuid()); } // increment resource count for dedicated public ip's _resourceLimitMgr.incrementResourceCount(vlanOwner.getId(), ResourceType.public_ip, new Long(ips.size())); @@ -2870,7 +3075,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @DB - public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller) { + public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller) { VlanVO vlanRange = _vlanDao.findById(vlanDbId); if (vlanRange == null) { throw new InvalidParameterValueException("Please specify a valid IP range id."); @@ -2878,7 +3083,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati boolean isAccountSpecific = false; List acctVln = _accountVlanMapDao.listAccountVlanMapsByVlan(vlanRange.getId()); - // Check for account wide pool. It will have an entry for account_vlan_map. + // Check for account wide pool. It will have an entry for + // account_vlan_map. if (acctVln != null && !acctVln.isEmpty()) { isAccountSpecific = true; } @@ -2900,25 +3106,36 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } for (IPAddressVO ip : ips) { if (ip.isOneToOneNat()) { - throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + - " as ip " + ip + " belonging to the range is used for static nat purposes. Cleanup the rules first"); + throw new InvalidParameterValueException( + "Can't delete account specific vlan " + + vlanDbId + + " as ip " + + ip + + " belonging to the range is used for static nat purposes. Cleanup the rules first"); } if (ip.isSourceNat()) { - throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + - " as ip " + ip + " belonging to the range is a source nat ip for the network id=" + ip.getSourceNetworkId() + - ". IP range with the source nat ip address can be removed either as a part of Network, or account removal"); + throw new InvalidParameterValueException( + "Can't delete account specific vlan " + + vlanDbId + + " as ip " + + ip + + " belonging to the range is a source nat ip for the network id=" + + ip.getSourceNetworkId() + + ". IP range with the source nat ip address can be removed either as a part of Network, or account removal"); } if (_firewallDao.countRulesByIpId(ip.getId()) > 0) { - throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + - " as ip " + ip + " belonging to the range has firewall rules applied. Cleanup the rules first"); + throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + + " as ip " + ip + + " belonging to the range has firewall rules applied. Cleanup the rules first"); } - //release public ip address here + // release public ip address here success = success && _networkMgr.disassociatePublicIpAddress(ip.getId(), userId, caller); } if (!success) { - s_logger.warn("Some ip addresses failed to be released as a part of vlan " + vlanDbId + " removal"); + s_logger.warn("Some ip addresses failed to be released as a part of vlan " + vlanDbId + + " removal"); } } finally { _vlanDao.releaseFromLockTable(vlanDbId); @@ -2928,12 +3145,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (success) { // Delete all public IPs in the VLAN - // if ip range is dedicated to an account generate usage events for release of every ip in the range - if(isAccountSpecific) { + // if ip range is dedicated to an account generate usage events for + // release of every ip in the range + if (isAccountSpecific) { for (IPAddressVO ip : ips) { - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, acctVln.get(0).getId(), - ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlanRange.getVlanType().toString(), - ip.getSystem(), ip.getClass().getName(), ip.getUuid()); + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, acctVln.get(0).getId(), ip + .getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlanRange + .getVlanType().toString(), ip.getSystem(), ip.getClass().getName(), ip.getUuid()); } } if (_networkModel.areServicesSupportedInNetwork(vlanRange.getNetworkId(), Service.Dhcp)) { @@ -2944,39 +3162,44 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati return false; } _vlanDao.expunge(vlanDbId); - return true; + return true; } - //search if the vlan has any allocated ips. + // search if the vlan has any allocated ips. boolean aliasIpBelongsToThisVlan = false; long freeIpsInsubnet = 0; NicIpAliasVO ipAlias = null; allocIpCount = _publicIpAddressDao.countIPs(vlanRange.getDataCenterId(), vlanDbId, true); if (allocIpCount > 1) { - throw new InvalidParameterValueException ("cannot delete this range as some of the vlans are in use."); + throw new InvalidParameterValueException( + "cannot delete this range as some of the vlans are in use."); } - if (allocIpCount == 0){ - //remove the vlan range. + if (allocIpCount == 0) { + // remove the vlan range. if (!deletePublicIPRange(vlanDbId)) { return false; } _vlanDao.expunge(vlanDbId); return true; } - //check if this allocated ip is being used as an ipAlias on the router. - ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(vlanRange.getVlanGateway(), vlanRange.getNetworkId(), NicIpAlias.state.active); - //check if this ip belongs to this vlan and is allocated. + // check if this allocated ip is being used as an ipAlias on the + // router. + ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(vlanRange.getVlanGateway(), + vlanRange.getNetworkId(), NicIpAlias.state.active); + // check if this ip belongs to this vlan and is allocated. IPAddressVO ip = _publicIpAddressDao.findByIpAndVlanId(ipAlias.getIp4Address(), vlanDbId); if (ip != null && ip.getState() == IpAddress.State.Allocated) { - aliasIpBelongsToThisVlan =true; - //check if there any other vlan ranges in the same subnet having free ips - List vlanRanges = _vlanDao.listVlansByNetworkIdAndGateway(vlanRange.getNetworkId(), vlanRange.getVlanGateway()); - //if there is no other vlanrage in this subnet. free the ip and delete the vlan. - if (vlanRanges.size() == 1){ + aliasIpBelongsToThisVlan = true; + // check if there any other vlan ranges in the same subnet + // having free ips + List vlanRanges = _vlanDao.listVlansByNetworkIdAndGateway(vlanRange.getNetworkId(), + vlanRange.getVlanGateway()); + // if there is no other vlanrage in this subnet. free the ip + // and delete the vlan. + if (vlanRanges.size() == 1) { boolean result = dhcpServiceProvider.removeDhcpSupportForSubnet(network); if (result == false) { s_logger.debug("Failed to delete the vlan range as we could not free the ip used to provide the dhcp service."); - } - else { + } else { _publicIpAddressDao.unassignIpAddress(ip.getId()); if (!deletePublicIPRange(vlanDbId)) { return false; @@ -2985,37 +3208,52 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati _nicIpAliasDao.expunge(ipAlias.getId()); } } else { - // if there are more vlans in the subnet check if there are free ips. + // if there are more vlans in the subnet check if there + // are free ips. List vlanDbIdList = new ArrayList(); for (VlanVO vlanrange : vlanRanges) { if (vlanrange.getId() != vlanDbId) { vlanDbIdList.add(vlanrange.getId()); } } - s_logger.info("vlan Range"+vlanRange.getId()+" id being deleted, one of the Ips in this range is used to provide the dhcp service, trying to free this ip and allocate a new one."); + s_logger.info("vlan Range" + + vlanRange.getId() + + " id being deleted, one of the Ips in this range is used to provide the dhcp service, trying to free this ip and allocate a new one."); for (VlanVO vlanrange : vlanRanges) { if (vlanrange.getId() != vlanDbId) { - freeIpsInsubnet = _publicIpAddressDao.countFreeIpsInVlan(vlanrange.getId()); - if (freeIpsInsubnet > 0){ - //assign one free ip to the router for creating ip Alias. + freeIpsInsubnet = _publicIpAddressDao.countFreeIpsInVlan(vlanrange.getId()); + if (freeIpsInsubnet > 0) { + // assign one free ip to the router for + // creating ip Alias. Transaction txn = Transaction.currentTxn(); - //changing the state to revoked so that removeDhcpSupport for subnet sses it. + // changing the state to revoked so that + // removeDhcpSupport for subnet sses it. ipAlias.setState(NicIpAlias.state.revoked); _nicIpAliasDao.update(ipAlias.getId(), ipAlias); boolean result = false; try { - PublicIp routerPublicIP = _networkMgr.assignPublicIpAddressFromVlans(network.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, vlanDbIdList, network.getId(), null, false); + PublicIp routerPublicIP = _networkMgr.assignPublicIpAddressFromVlans( + network.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, + vlanDbIdList, network.getId(), null, false); s_logger.info("creating a db entry for the new ip alias."); - NicIpAliasVO newipAlias = new NicIpAliasVO(ipAlias.getNicId(), routerPublicIP.getAddress().addr(), ipAlias.getVmId(), ipAlias.getAccountId(), network.getDomainId(), network.getId(), ipAlias.getGateway(), ipAlias.getNetmask()); + NicIpAliasVO newipAlias = new NicIpAliasVO(ipAlias.getNicId(), routerPublicIP + .getAddress().addr(), ipAlias.getVmId(), ipAlias.getAccountId(), + network.getDomainId(), network.getId(), ipAlias.getGateway(), + ipAlias.getNetmask()); newipAlias.setAliasCount(routerPublicIP.getIpMacAddress()); _nicIpAliasDao.persist(newipAlias); - //we revoke all the rules and apply all the rules as a part of the removedhcp config. so the new ip will get configured when we delete the old ip. + // we revoke all the rules and apply all + // the rules as a part of the removedhcp + // config. so the new ip will get + // configured when we delete the old ip. - } - catch (InsufficientAddressCapacityException e) { + } catch (InsufficientAddressCapacityException e) { txn.rollback(); txn.close(); - throw new InvalidParameterValueException("cannot delete vlan range"+ vlanRange.getId()+"one of the ips in this range is benig used to provide dhcp service. Cannot use some other ip as there are no free ips in this subnet"); + throw new InvalidParameterValueException( + "cannot delete vlan range" + + vlanRange.getId() + + "one of the ips in this range is benig used to provide dhcp service. Cannot use some other ip as there are no free ips in this subnet"); } s_logger.info("removing the old ip alias on router"); result = dhcpServiceProvider.removeDhcpSupportForSubnet(network); @@ -3042,18 +3280,18 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // when there is no dhcp support in the network. if (!deletePublicIPRange(vlanDbId)) { return false; - } + } _vlanDao.expunge(vlanDbId); - return true; - } + return true; + } } return false; } - @Override @DB - @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_DEDICATE, eventDescription = "dedicating vlan ip range", async = false) + @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_DEDICATE, eventDescription = "dedicating vlan ip range", + async = false) public Vlan dedicatePublicIpRange(DedicatePublicIpRangeCmd cmd) throws ResourceAllocationException { Long vlanDbId = cmd.getId(); String accountName = cmd.getAccountName(); @@ -3078,7 +3316,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (vlanOwner == null) { throw new InvalidParameterValueException("Unable to find account by name " + accountName); } else if (vlanOwner.getId() == Account.ACCOUNT_ID_SYSTEM) { - throw new InvalidParameterValueException("Please specify a valid account. Cannot dedicate IP range to system account"); + throw new InvalidParameterValueException( + "Please specify a valid account. Cannot dedicate IP range to system account"); } } @@ -3101,21 +3340,24 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Unable to find zone by id " + zoneId); } if (zone.getNetworkType() == NetworkType.Basic) { - throw new InvalidParameterValueException("Public IP range can be dedicated to an account only in the zone of type " + NetworkType.Advanced); + throw new InvalidParameterValueException( + "Public IP range can be dedicated to an account only in the zone of type " + NetworkType.Advanced); } // Check Public IP resource limits int accountPublicIpRange = _publicIpAddressDao.countIPs(zoneId, vlanDbId, false); _resourceLimitMgr.checkResourceLimit(vlanOwner, ResourceType.public_ip, accountPublicIpRange); - // Check if any of the Public IP addresses is allocated to another account + // Check if any of the Public IP addresses is allocated to another + // account List ips = _publicIpAddressDao.listByVlanId(vlanDbId); for (IPAddressVO ip : ips) { Long allocatedToAccountId = ip.getAllocatedToAccountId(); if (allocatedToAccountId != null) { Account accountAllocatedTo = _accountMgr.getActiveAccountById(allocatedToAccountId); if (!accountAllocatedTo.getAccountName().equalsIgnoreCase(accountName)) - throw new InvalidParameterValueException(ip.getAddress() + " Public IP address in range is allocated to another account "); + throw new InvalidParameterValueException(ip.getAddress() + + " Public IP address in range is allocated to another account "); } } @@ -3130,8 +3372,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // generate usage event for dedication of every ip address in the range for (IPAddressVO ip : ips) { - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, vlanOwner.getId(), - ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlan.getVlanType().toString(), + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, vlanOwner.getId(), ip.getDataCenterId(), + ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlan.getVlanType().toString(), ip.getSystem(), ip.getClass().getName(), ip.getUuid()); } @@ -3142,7 +3384,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } @Override - @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_RELEASE, eventDescription = "releasing a public ip range", async = false) + @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_RELEASE, eventDescription = "releasing a public ip range", + async = false) public boolean releasePublicIpRange(ReleasePublicIpRangeCmd cmd) { Long vlanDbId = cmd.getId(); @@ -3151,10 +3394,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Please specify a valid IP range id."); } - return releasePublicIpRange(vlanDbId, UserContext.current().getCallerUserId(), UserContext.current().getCaller()); + return releasePublicIpRange(vlanDbId, UserContext.current().getCallerUserId(), UserContext.current() + .getCaller()); } - @DB public boolean releasePublicIpRange(long vlanDbId, long userId, Account caller) { VlanVO vlan = _vlanDao.findById(vlanDbId); @@ -3162,7 +3405,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati List acctVln = _accountVlanMapDao.listAccountVlanMapsByVlan(vlanDbId); // Verify range is dedicated if (acctVln == null || acctVln.isEmpty()) { - throw new InvalidParameterValueException("Can't release Public IP range " + vlanDbId + " as it not dedicated to any account"); + throw new InvalidParameterValueException("Can't release Public IP range " + vlanDbId + + " as it not dedicated to any account"); } // Check if range has any allocated public IPs @@ -3180,17 +3424,17 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } for (IPAddressVO ip : ips) { // Disassociate allocated IP's that are not in use - if ( !ip.isOneToOneNat() && !ip.isSourceNat() && !(_firewallDao.countRulesByIpId(ip.getId()) > 0) ) { + if (!ip.isOneToOneNat() && !ip.isSourceNat() && !(_firewallDao.countRulesByIpId(ip.getId()) > 0)) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing Public IP addresses" + ip +" of vlan " + vlanDbId + " as part of Public IP" + - " range release to the system pool"); + s_logger.debug("Releasing Public IP addresses" + ip + " of vlan " + vlanDbId + + " as part of Public IP" + " range release to the system pool"); } success = success && _networkMgr.disassociatePublicIpAddress(ip.getId(), userId, caller); } } if (!success) { - s_logger.warn("Some Public IP addresses that were not in use failed to be released as a part of" + - " vlan " + vlanDbId + "release to the system pool"); + s_logger.warn("Some Public IP addresses that were not in use failed to be released as a part of" + + " vlan " + vlanDbId + "release to the system pool"); } } finally { _vlanDao.releaseFromLockTable(vlanDbId); @@ -3199,14 +3443,16 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // A Public IP range can only be dedicated to one account at a time if (_accountVlanMapDao.remove(acctVln.get(0).getId())) { - // generate usage events to remove dedication for every ip in the range + // generate usage events to remove dedication for every ip in the + // range for (IPAddressVO ip : ips) { - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, acctVln.get(0).getAccountId(), - ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlan.getVlanType().toString(), - ip.getSystem(), ip.getClass().getName(), ip.getUuid()); + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, acctVln.get(0).getAccountId(), ip + .getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlan + .getVlanType().toString(), ip.getSystem(), ip.getClass().getName(), ip.getUuid()); } // decrement resource count for dedicated public ip's - _resourceLimitMgr.decrementResourceCount(acctVln.get(0).getAccountId(), ResourceType.public_ip, new Long(ips.size())); + _resourceLimitMgr.decrementResourceCount(acctVln.get(0).getAccountId(), ResourceType.public_ip, new Long( + ips.size())); return true; } else { return false; @@ -3275,20 +3521,22 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati return true; } - @DB - protected boolean savePublicIPRange(String startIP, String endIP, long zoneId, long vlanDbId, long sourceNetworkid, long physicalNetworkId) { + protected boolean savePublicIPRange(String startIP, String endIP, long zoneId, long vlanDbId, long sourceNetworkid, + long physicalNetworkId) { long startIPLong = NetUtils.ip2Long(startIP); long endIPLong = NetUtils.ip2Long(endIP); Transaction txn = Transaction.currentTxn(); txn.start(); IPRangeConfig config = new IPRangeConfig(); - List problemIps = config.savePublicIPRange(txn, startIPLong, endIPLong, zoneId, vlanDbId, sourceNetworkid, physicalNetworkId); + List problemIps = config.savePublicIPRange(txn, startIPLong, endIPLong, zoneId, vlanDbId, + sourceNetworkid, physicalNetworkId); txn.commit(); return problemIps != null && problemIps.size() == 0; } - private void checkPublicIpRangeErrors(long zoneId, String vlanId, String vlanGateway, String vlanNetmask, String startIP, String endIP) { + private void checkPublicIpRangeErrors(long zoneId, String vlanId, String vlanGateway, String vlanNetmask, + String startIP, String endIP) { // Check that the start and end IPs are valid if (!NetUtils.isValidIp(startIP)) { throw new InvalidParameterValueException("Please specify a valid start IP"); @@ -3309,19 +3557,21 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (endIP != null && !NetUtils.sameSubnet(startIP, endIP, vlanNetmask)) { - throw new InvalidParameterValueException("Please ensure that your start IP and end IP are in the same subnet, as per the IP range's netmask."); + throw new InvalidParameterValueException( + "Please ensure that your start IP and end IP are in the same subnet, as per the IP range's netmask."); } if (!NetUtils.sameSubnet(startIP, vlanGateway, vlanNetmask)) { - throw new InvalidParameterValueException("Please ensure that your start IP is in the same subnet as your IP range's gateway, as per the IP range's netmask."); + throw new InvalidParameterValueException( + "Please ensure that your start IP is in the same subnet as your IP range's gateway, as per the IP range's netmask."); } if (endIP != null && !NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)) { - throw new InvalidParameterValueException("Please ensure that your end IP is in the same subnet as your IP range's gateway, as per the IP range's netmask."); + throw new InvalidParameterValueException( + "Please ensure that your end IP is in the same subnet as your IP range's gateway, as per the IP range's netmask."); } } - private String getCidrAddress(String cidr) { String[] cidrPair = cidr.split("\\/"); return cidrPair[0]; @@ -3332,7 +3582,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati return Integer.parseInt(cidrPair[1]); } - @Override public void checkPodCidrSubnets(long dcId, Long podIdToBeSkipped, String cidr) { // For each pod, return an error if any of the following is true: @@ -3390,10 +3639,15 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // Check that cidrSubnet does not equal guestSubnet if (cidrSubnet.equals(guestSubnet)) { if (podName.equals("newPod")) { - throw new InvalidParameterValueException("The subnet of the pod you are adding conflicts with the subnet of the Guest IP Network. Please specify a different CIDR."); + throw new InvalidParameterValueException( + "The subnet of the pod you are adding conflicts with the subnet of the Guest IP Network. Please specify a different CIDR."); } else { - throw new InvalidParameterValueException("Warning: The subnet of pod " + podName + " in zone " + zoneName - + " conflicts with the subnet of the Guest IP Network. Please change either the pod's CIDR or the Guest IP Network's subnet, and re-run install-vmops-management."); + throw new InvalidParameterValueException( + "Warning: The subnet of pod " + + podName + + " in zone " + + zoneName + + " conflicts with the subnet of the Guest IP Network. Please change either the pod's CIDR or the Guest IP Network's subnet, and re-run install-vmops-management."); } } } @@ -3421,10 +3675,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (cidrSubnet.equals(otherCidrSubnet)) { String otherPodName = getPodName(otherPodId.longValue()); if (podName.equals("newPod")) { - throw new InvalidParameterValueException("The subnet of the pod you are adding conflicts with the subnet of pod " + otherPodName + " in zone " + zoneName - + ". Please specify a different CIDR."); + throw new InvalidParameterValueException( + "The subnet of the pod you are adding conflicts with the subnet of pod " + otherPodName + + " in zone " + zoneName + ". Please specify a different CIDR."); } else { - throw new InvalidParameterValueException("Warning: The pods " + podName + " and " + otherPodName + " in zone " + zoneName + throw new InvalidParameterValueException("Warning: The pods " + podName + " and " + + otherPodName + " in zone " + zoneName + " have conflicting CIDR subnets. Please change the CIDR of one of these pods."); } } @@ -3481,8 +3737,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } @Override - @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_DELETE, eventDescription = "deleting vlan ip range", async = false) - public boolean deleteVlanIpRange(DeleteVlanIpRangeCmd cmd) { + @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_DELETE, eventDescription = "deleting vlan ip range", + async = false) + public boolean deleteVlanIpRange(DeleteVlanIpRangeCmd cmd) { Long vlanDbId = cmd.getId(); VlanVO vlan = _vlanDao.findById(vlanDbId); @@ -3490,15 +3747,17 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Please specify a valid IP range id."); } - return deleteVlanAndPublicIpRange(UserContext.current().getCallerUserId(), vlanDbId, UserContext.current().getCaller()); + return deleteVlanAndPublicIpRange(UserContext.current().getCallerUserId(), vlanDbId, UserContext.current() + .getCaller()); } @Override - public void checkDiskOfferingAccess(Account caller, DiskOffering dof){ + public void checkDiskOfferingAccess(Account caller, DiskOffering dof) { for (SecurityChecker checker : _secChecker) { if (checker.checkAccess(caller, dof)) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Access granted to " + caller + " to disk offering:" + dof.getId() + " by " + checker.getName()); + s_logger.debug("Access granted to " + caller + " to disk offering:" + dof.getId() + " by " + + checker.getName()); } return; } else { @@ -3507,24 +3766,28 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } assert false : "How can all of the security checkers pass on checking this caller?"; - throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to disk offering:" + dof.getId()); + throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to disk offering:" + + dof.getId()); } @Override - public void checkZoneAccess(Account caller, DataCenter zone){ + public void checkZoneAccess(Account caller, DataCenter zone) { for (SecurityChecker checker : _secChecker) { if (checker.checkAccess(caller, zone)) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Access granted to " + caller + " to zone:" + zone.getId() + " by " + checker.getName()); + s_logger.debug("Access granted to " + caller + " to zone:" + zone.getId() + " by " + + checker.getName()); } return; } else { - throw new PermissionDeniedException("Access denied to " + caller + " by " + checker.getName() + " for zone " + zone.getId()); + throw new PermissionDeniedException("Access denied to " + caller + " by " + checker.getName() + + " for zone " + zone.getId()); } } assert false : "How can all of the security checkers pass on checking this caller?"; - throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to zone:" + zone.getId()); + throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to zone:" + + zone.getId()); } @Override @@ -3553,12 +3816,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } } if (trafficType == null) { - throw new InvalidParameterValueException("Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage"); + throw new InvalidParameterValueException( + "Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage"); } // Only GUEST traffic type is supported in Acton if (trafficType != TrafficType.Guest) { - throw new InvalidParameterValueException("Only traffic type " + TrafficType.Guest + " is supported in the current release"); + throw new InvalidParameterValueException("Only traffic type " + TrafficType.Guest + + " is supported in the current release"); } // Verify offering type @@ -3570,7 +3835,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (guestType == null) { - throw new InvalidParameterValueException("Invalid \"type\" parameter is given; can have Shared and Isolated values"); + throw new InvalidParameterValueException( + "Invalid \"type\" parameter is given; can have Shared and Isolated values"); } // Verify availability @@ -3581,7 +3847,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (availability == null) { - throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + Availability.Required + ", " + Availability.Optional); + throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + + Availability.Required + ", " + Availability.Optional); } Long serviceOfferingId = cmd.getServiceOfferingId(); @@ -3592,7 +3859,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Cannot find specified service offering: " + serviceOfferingId); } if (!VirtualMachine.Type.DomainRouter.toString().equalsIgnoreCase(offering.getSystemVmType())) { - throw new InvalidParameterValueException("The specified service offering " + serviceOfferingId + " cannot be used by virtual router!"); + throw new InvalidParameterValueException("The specified service offering " + serviceOfferingId + + " cannot be used by virtual router!"); } } @@ -3611,7 +3879,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (service == Service.SecurityGroup) { // allow security group service for Shared networks only if (guestType != GuestType.Shared) { - throw new InvalidParameterValueException("Secrity group service is supported for network offerings with guest ip type " + GuestType.Shared); + throw new InvalidParameterValueException( + "Secrity group service is supported for network offerings with guest ip type " + + GuestType.Shared); } Set sgProviders = new HashSet(); sgProviders.add(Provider.SecurityGroupProvider); @@ -3636,10 +3906,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati Network.Service service = Network.Service.getService(serviceStr); if (serviceProviderMap.containsKey(service)) { Set providers = new HashSet(); - // Allow to specify more than 1 provider per service only if the service is LB - if (!serviceStr.equalsIgnoreCase(Service.Lb.getName()) && svcPrv.get(serviceStr) != null && svcPrv.get(serviceStr).size() > 1) { - throw new InvalidParameterValueException("In the current release only one provider can be " + - "specified for the service if the service is not LB"); + // Allow to specify more than 1 provider per service only if + // the service is LB + if (!serviceStr.equalsIgnoreCase(Service.Lb.getName()) && svcPrv.get(serviceStr) != null + && svcPrv.get(serviceStr).size() > 1) { + throw new InvalidParameterValueException("In the current release only one provider can be " + + "specified for the service if the service is not LB"); } for (String prvNameStr : svcPrv.get(serviceStr)) { // check if provider is supported @@ -3652,7 +3924,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati firewallProvider = provider; } - if ((service == Service.PortForwarding || service == Service.StaticNat) && provider == Provider.VirtualRouter){ + if ((service == Service.PortForwarding || service == Service.StaticNat) + && provider == Provider.VirtualRouter) { firewallProvider = Provider.VirtualRouter; } @@ -3670,8 +3943,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } serviceProviderMap.put(service, providers); } else { - throw new InvalidParameterValueException("Service " + serviceStr + " is not enabled for the network " + - "offering, can't add a provider to it"); + throw new InvalidParameterValueException("Service " + serviceStr + + " is not enabled for the network " + "offering, can't add a provider to it"); } } } @@ -3679,24 +3952,33 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // validate providers combination here _networkModel.canProviderSupportServices(providerCombinationToVerify); - // validate the LB service capabilities specified in the network offering + // validate the LB service capabilities specified in the network + // offering Map lbServiceCapabilityMap = cmd.getServiceCapabilities(Service.Lb); - if (!serviceProviderMap.containsKey(Service.Lb) && lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) { - throw new InvalidParameterValueException("Capabilities for LB service can be specifed only when LB service is enabled for network offering."); + if (!serviceProviderMap.containsKey(Service.Lb) && lbServiceCapabilityMap != null + && !lbServiceCapabilityMap.isEmpty()) { + throw new InvalidParameterValueException( + "Capabilities for LB service can be specifed only when LB service is enabled for network offering."); } validateLoadBalancerServiceCapabilities(lbServiceCapabilityMap); - // validate the Source NAT service capabilities specified in the network offering + // validate the Source NAT service capabilities specified in the network + // offering Map sourceNatServiceCapabilityMap = cmd.getServiceCapabilities(Service.SourceNat); - if (!serviceProviderMap.containsKey(Service.SourceNat) && sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) { - throw new InvalidParameterValueException("Capabilities for source NAT service can be specifed only when source NAT service is enabled for network offering."); + if (!serviceProviderMap.containsKey(Service.SourceNat) && sourceNatServiceCapabilityMap != null + && !sourceNatServiceCapabilityMap.isEmpty()) { + throw new InvalidParameterValueException( + "Capabilities for source NAT service can be specifed only when source NAT service is enabled for network offering."); } validateSourceNatServiceCapablities(sourceNatServiceCapabilityMap); - // validate the Static Nat service capabilities specified in the network offering + // validate the Static Nat service capabilities specified in the network + // offering Map staticNatServiceCapabilityMap = cmd.getServiceCapabilities(Service.StaticNat); - if (!serviceProviderMap.containsKey(Service.StaticNat) && sourceNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) { - throw new InvalidParameterValueException("Capabilities for static NAT service can be specifed only when static NAT service is enabled for network offering."); + if (!serviceProviderMap.containsKey(Service.StaticNat) && sourceNatServiceCapabilityMap != null + && !staticNatServiceCapabilityMap.isEmpty()) { + throw new InvalidParameterValueException( + "Capabilities for static NAT service can be specifed only when static NAT service is enabled for network offering."); } validateStaticNatServiceCapablities(staticNatServiceCapabilityMap); @@ -3705,7 +3987,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati serviceCapabilityMap.put(Service.SourceNat, sourceNatServiceCapabilityMap); serviceCapabilityMap.put(Service.StaticNat, staticNatServiceCapabilityMap); - // if Firewall service is missing, add Firewall service/provider combination + // if Firewall service is missing, add Firewall service/provider + // combination if (firewallProvider != null) { s_logger.debug("Adding Firewall service with provider " + firewallProvider.getName()); Set firewallProviderSet = new HashSet(); @@ -3717,7 +4000,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (detailsStr != null) { for (String detailStr : detailsStr.keySet()) { NetworkOffering.Detail offDetail = null; - for (NetworkOffering.Detail supportedDetail: NetworkOffering.Detail.values()) { + for (NetworkOffering.Detail supportedDetail : NetworkOffering.Detail.values()) { if (detailStr.equalsIgnoreCase(supportedDetail.toString())) { offDetail = supportedDetail; break; @@ -3730,14 +4013,18 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } } - return createNetworkOffering(name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false, - serviceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges, isPersistent, details); + return createNetworkOffering(name, displayText, trafficType, tags, specifyVlan, availability, networkRate, + serviceProviderMap, false, guestType, false, serviceOfferingId, conserveMode, serviceCapabilityMap, + specifyIpRanges, isPersistent, details); } void validateLoadBalancerServiceCapabilities(Map lbServiceCapabilityMap) { if (lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) { - if (lbServiceCapabilityMap.keySet().size() > 3 || !lbServiceCapabilityMap.containsKey(Capability.SupportedLBIsolation)) { - throw new InvalidParameterValueException("Only " + Capability.SupportedLBIsolation.getName() + ", " + Capability.ElasticLb.getName() + ", " + Capability.InlineMode.getName() + " capabilities can be sepcified for LB service"); + if (lbServiceCapabilityMap.keySet().size() > 3 + || !lbServiceCapabilityMap.containsKey(Capability.SupportedLBIsolation)) { + throw new InvalidParameterValueException("Only " + Capability.SupportedLBIsolation.getName() + ", " + + Capability.ElasticLb.getName() + ", " + Capability.InlineMode.getName() + + " capabilities can be sepcified for LB service"); } for (Capability cap : lbServiceCapabilityMap.keySet()) { @@ -3746,30 +4033,35 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati boolean dedicatedLb = value.contains("dedicated"); boolean sharedLB = value.contains("shared"); if ((dedicatedLb && sharedLB) || (!dedicatedLb && !sharedLB)) { - throw new InvalidParameterValueException("Either dedicated or shared isolation can be specified for " + Capability.SupportedLBIsolation.getName()); + throw new InvalidParameterValueException( + "Either dedicated or shared isolation can be specified for " + + Capability.SupportedLBIsolation.getName()); } } else if (cap == Capability.ElasticLb) { boolean enabled = value.contains("true"); boolean disabled = value.contains("false"); if (!enabled && !disabled) { - throw new InvalidParameterValueException("Unknown specified value for " + Capability.ElasticLb.getName()); + throw new InvalidParameterValueException("Unknown specified value for " + + Capability.ElasticLb.getName()); } } else if (cap == Capability.InlineMode) { boolean enabled = value.contains("true"); boolean disabled = value.contains("false"); if (!enabled && !disabled) { - throw new InvalidParameterValueException("Unknown specified value for " + Capability.InlineMode.getName()); + throw new InvalidParameterValueException("Unknown specified value for " + + Capability.InlineMode.getName()); } } else if (cap == Capability.LbSchemes) { boolean internalLb = value.contains("internal"); boolean publicLb = value.contains("public"); if (!internalLb && !publicLb) { - throw new InvalidParameterValueException("Unknown specified value for " + Capability.LbSchemes.getName()); + throw new InvalidParameterValueException("Unknown specified value for " + + Capability.LbSchemes.getName()); } } else { - throw new InvalidParameterValueException("Only " + Capability.SupportedLBIsolation.getName() + - ", " + Capability.ElasticLb.getName() + ", " + Capability.InlineMode.getName() - + ", " + Capability.LbSchemes.getName() + " capabilities can be sepcified for LB service"); + throw new InvalidParameterValueException("Only " + Capability.SupportedLBIsolation.getName() + ", " + + Capability.ElasticLb.getName() + ", " + Capability.InlineMode.getName() + ", " + + Capability.LbSchemes.getName() + " capabilities can be sepcified for LB service"); } } } @@ -3778,7 +4070,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati void validateSourceNatServiceCapablities(Map sourceNatServiceCapabilityMap) { if (sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) { if (sourceNatServiceCapabilityMap.keySet().size() > 2) { - throw new InvalidParameterValueException("Only " + Capability.SupportedSourceNatTypes.getName() + " and " + Capability.RedundantRouter + " capabilities can be sepcified for source nat service"); + throw new InvalidParameterValueException("Only " + Capability.SupportedSourceNatTypes.getName() + + " and " + Capability.RedundantRouter + + " capabilities can be sepcified for source nat service"); } for (Capability capability : sourceNatServiceCapabilityMap.keySet()) { @@ -3787,16 +4081,21 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati boolean perAccount = value.contains("peraccount"); boolean perZone = value.contains("perzone"); if ((perAccount && perZone) || (!perAccount && !perZone)) { - throw new InvalidParameterValueException("Either peraccount or perzone source NAT type can be specified for " + Capability.SupportedSourceNatTypes.getName()); + throw new InvalidParameterValueException( + "Either peraccount or perzone source NAT type can be specified for " + + Capability.SupportedSourceNatTypes.getName()); } } else if (capability == Capability.RedundantRouter) { boolean enabled = value.contains("true"); boolean disabled = value.contains("false"); if (!enabled && !disabled) { - throw new InvalidParameterValueException("Unknown specified value for " + Capability.RedundantRouter.getName()); + throw new InvalidParameterValueException("Unknown specified value for " + + Capability.RedundantRouter.getName()); } } else { - throw new InvalidParameterValueException("Only " + Capability.SupportedSourceNatTypes.getName() + " and " + Capability.RedundantRouter + " capabilities can be sepcified for source nat service"); + throw new InvalidParameterValueException("Only " + Capability.SupportedSourceNatTypes.getName() + + " and " + Capability.RedundantRouter + + " capabilities can be sepcified for source nat service"); } } } @@ -3805,7 +4104,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati void validateStaticNatServiceCapablities(Map staticNatServiceCapabilityMap) { if (staticNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) { if (staticNatServiceCapabilityMap.keySet().size() > 2) { - throw new InvalidParameterValueException("Only " + Capability.ElasticIp.getName() + " and " + Capability.AssociatePublicIP.getName() + " capabilitiy can be sepcified for static nat service"); + throw new InvalidParameterValueException("Only " + Capability.ElasticIp.getName() + " and " + + Capability.AssociatePublicIP.getName() + + " capabilitiy can be sepcified for static nat service"); } boolean eipEnabled = false; @@ -3817,7 +4118,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati eipEnabled = value.contains("true"); eipDisabled = value.contains("false"); if (!eipEnabled && !eipDisabled) { - throw new InvalidParameterValueException("Unknown specified value for " + Capability.ElasticIp.getName()); + throw new InvalidParameterValueException("Unknown specified value for " + + Capability.ElasticIp.getName()); } } else if (capability == Capability.AssociatePublicIP) { if (value.contains("true")) { @@ -3825,13 +4127,17 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } else if (value.contains("false")) { associatePublicIP = false; } else { - throw new InvalidParameterValueException("Unknown specified value for " + Capability.AssociatePublicIP.getName()); + throw new InvalidParameterValueException("Unknown specified value for " + + Capability.AssociatePublicIP.getName()); } } else { - throw new InvalidParameterValueException("Only " + Capability.ElasticIp.getName() + " and " + Capability.AssociatePublicIP.getName() + " capabilitiy can be sepcified for static nat service"); + throw new InvalidParameterValueException("Only " + Capability.ElasticIp.getName() + " and " + + Capability.AssociatePublicIP.getName() + + " capabilitiy can be sepcified for static nat service"); } if (eipDisabled && associatePublicIP) { - throw new InvalidParameterValueException("Capability " + Capability.AssociatePublicIP.getName() + " can only be set when capability " + Capability.ElasticIp.getName() + " is true"); + throw new InvalidParameterValueException("Capability " + Capability.AssociatePublicIP.getName() + + " can only be set when capability " + Capability.ElasticIp.getName() + " is true"); } } } @@ -3839,9 +4145,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @DB - public NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, - Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, - boolean conserveMode, Map> serviceCapabilityMap, boolean specifyIpRanges, boolean isPersistent, Map details) { + public NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, + String tags, boolean specifyVlan, Availability availability, Integer networkRate, + Map> serviceProviderMap, boolean isDefault, Network.GuestType type, + boolean systemOnly, Long serviceOfferingId, boolean conserveMode, + Map> serviceCapabilityMap, boolean specifyIpRanges, boolean isPersistent, + Map details) { String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); @@ -3852,23 +4161,27 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("SpecifyVlan should be true if network offering's type is " + type); } - //specifyIpRanges should always be true for Shared networks - //specifyIpRanges can only be true for Isolated networks with no Source Nat service + // specifyIpRanges should always be true for Shared networks + // specifyIpRanges can only be true for Isolated networks with no Source + // Nat service if (specifyIpRanges) { if (type == GuestType.Isolated) { if (serviceProviderMap.containsKey(Service.SourceNat)) { - throw new InvalidParameterValueException("SpecifyIpRanges can only be true for Shared network offerings and Isolated with no SourceNat service"); + throw new InvalidParameterValueException( + "SpecifyIpRanges can only be true for Shared network offerings and Isolated with no SourceNat service"); } } } else { if (type == GuestType.Shared) { - throw new InvalidParameterValueException("SpecifyIpRanges should always be true for Shared network offerings"); + throw new InvalidParameterValueException( + "SpecifyIpRanges should always be true for Shared network offerings"); } } // isPersistent should always be false for Shared network Offerings if (isPersistent && type == GuestType.Shared) { - throw new InvalidParameterValueException("isPersistent should be false if network offering's type is " + type); + throw new InvalidParameterValueException("isPersistent should be false if network offering's type is " + + type); } // validate availability value @@ -3883,8 +4196,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // only one network offering in the system can be Required List offerings = _networkOfferingDao.listByAvailability(Availability.Required, false); if (!offerings.isEmpty()) { - throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() - + " with availability " + Availability.Required); + throw new InvalidParameterValueException("System already has network offering id=" + + offerings.get(0).getId() + " with availability " + Availability.Required); } } @@ -3903,7 +4216,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if ((lbServiceCapabilityMap != null) && (!lbServiceCapabilityMap.isEmpty())) { String isolationCapability = lbServiceCapabilityMap.get(Capability.SupportedLBIsolation); if (isolationCapability != null) { - _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.SupportedLBIsolation, isolationCapability); + _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, + Capability.SupportedLBIsolation, isolationCapability); dedicatedLb = isolationCapability.contains("dedicated"); } else { dedicatedLb = true; @@ -3916,7 +4230,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String inlineMode = lbServiceCapabilityMap.get(Capability.InlineMode); if (inlineMode != null) { - _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.InlineMode, inlineMode); + _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, + Capability.InlineMode, inlineMode); inline = inlineMode.contains("true"); } else { inline = false; @@ -3925,34 +4240,37 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String publicLbStr = lbServiceCapabilityMap.get(Capability.LbSchemes); if (serviceProviderMap.containsKey(Service.Lb)) { if (publicLbStr != null) { - _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.LbSchemes, publicLbStr); + _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, + Capability.LbSchemes, publicLbStr); internalLb = publicLbStr.contains("internal"); publicLb = publicLbStr.contains("public"); } else { - //if not specified, default public lb to true + // if not specified, default public lb to true publicLb = true; } } } - //in the current version of the code, publicLb and specificLb can't both be set to true for the same network offering + // in the current version of the code, publicLb and specificLb can't + // both be set to true for the same network offering if (publicLb && internalLb) { - throw new InvalidParameterValueException("Public lb and internal lb can't be enabled at the same time on the offering"); + throw new InvalidParameterValueException( + "Public lb and internal lb can't be enabled at the same time on the offering"); } Map sourceNatServiceCapabilityMap = serviceCapabilityMap.get(Service.SourceNat); if ((sourceNatServiceCapabilityMap != null) && (!sourceNatServiceCapabilityMap.isEmpty())) { String sourceNatType = sourceNatServiceCapabilityMap.get(Capability.SupportedSourceNatTypes); if (sourceNatType != null) { - _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, - Capability.SupportedSourceNatTypes, sourceNatType); + _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), + Service.SourceNat, Capability.SupportedSourceNatTypes, sourceNatType); sharedSourceNat = sourceNatType.contains("perzone"); } String param = sourceNatServiceCapabilityMap.get(Capability.RedundantRouter); if (param != null) { - _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, - Capability.RedundantRouter, param); + _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), + Service.SourceNat, Capability.RedundantRouter, param); redundantRouter = param.contains("true"); } } @@ -3972,23 +4290,24 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, - sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline, isPersistent, associatePublicIp, publicLb, internalLb); + sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline, isPersistent, + associatePublicIp, publicLb, internalLb); if (serviceOfferingId != null) { offering.setServiceOfferingId(serviceOfferingId); } - //validate the details + // validate the details if (details != null) { validateNtwkOffDetails(details, serviceProviderMap); } Transaction txn = Transaction.currentTxn(); txn.start(); - //1) create network offering object + // 1) create network offering object s_logger.debug("Adding network offering " + offering); offering = _networkOfferingDao.persist(offering, details); - //2) populate services and providers + // 2) populate services and providers if (serviceProviderMap != null) { for (Network.Service service : serviceProviderMap.keySet()) { Set providers = serviceProviderMap.get(service); @@ -3998,9 +4317,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (provider == Provider.VPCVirtualRouter) { vpcOff = true; } - NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), service, provider); + NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), + service, provider); _ntwkOffServiceMapDao.persist(offService); - s_logger.trace("Added service for the network offering: " + offService + " with provider " + provider.getName()); + s_logger.trace("Added service for the network offering: " + offService + " with provider " + + provider.getName()); } if (vpcOff) { @@ -4009,7 +4330,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati _vpcMgr.validateNtwkOffForVpc(offering, supportedSvcs); } } else { - NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), service, null); + NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), service, + null); _ntwkOffServiceMapDao.persist(offService); s_logger.trace("Added service for the network offering: " + offService + " with null provider"); } @@ -4026,11 +4348,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati for (Detail detail : details.keySet()) { Provider lbProvider = null; - if (detail == NetworkOffering.Detail.InternalLbProvider || detail == NetworkOffering.Detail.PublicLbProvider) { - //1) Vaidate the detail values - have to match the lb provider name + if (detail == NetworkOffering.Detail.InternalLbProvider + || detail == NetworkOffering.Detail.PublicLbProvider) { + // 1) Vaidate the detail values - have to match the lb provider + // name String providerStr = details.get(detail); if (Network.Provider.getProvider(providerStr) == null) { - throw new InvalidParameterValueException("Invalid value " + providerStr + " for the detail " + detail); + throw new InvalidParameterValueException("Invalid value " + providerStr + " for the detail " + + detail); } if (serviceProviderMap.get(Service.Lb) != null) { for (Provider provider : serviceProviderMap.get(Service.Lb)) { @@ -4046,24 +4371,26 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati + " for the detail " + detail + ". The provider is not supported by the network offering"); } - //2) validate if the provider supports the scheme + // 2) validate if the provider supports the scheme Set lbProviders = new HashSet(); lbProviders.add(lbProvider); if (detail == NetworkOffering.Detail.InternalLbProvider) { - _networkModel.checkCapabilityForProvider(lbProviders, Service.Lb, Capability.LbSchemes, Scheme.Internal.toString()); - } else if (detail == NetworkOffering.Detail.PublicLbProvider){ - _networkModel.checkCapabilityForProvider(lbProviders, Service.Lb, Capability.LbSchemes, Scheme.Public.toString()); + _networkModel.checkCapabilityForProvider(lbProviders, Service.Lb, Capability.LbSchemes, + Scheme.Internal.toString()); + } else if (detail == NetworkOffering.Detail.PublicLbProvider) { + _networkModel.checkCapabilityForProvider(lbProviders, Service.Lb, Capability.LbSchemes, + Scheme.Public.toString()); } } } } - @Override public List searchForNetworkOfferings(ListNetworkOfferingsCmd cmd) { Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); isAscending = (isAscending == null ? true : isAscending); - Filter searchFilter = new Filter(NetworkOfferingVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal()); + Filter searchFilter = new Filter(NetworkOfferingVO.class, "sortKey", isAscending, cmd.getStartIndex(), + cmd.getPageSizeVal()); Account caller = UserContext.current().getCaller(); SearchCriteria sc = _networkOfferingDao.createSearchCriteria(); @@ -4122,8 +4449,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault); } - if (specifyVlan != null) { + // only root admin can list network offering with specifyVlan = true + if (specifyVlan != null && caller.getType() == Account.ACCOUNT_TYPE_ADMIN) { sc.addAnd("specifyVlan", SearchCriteria.Op.EQ, specifyVlan); + } else { + specifyVlan = false; } if (availability != null) { @@ -4149,7 +4479,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // Don't return system network offerings to the user sc.addAnd("systemOnly", SearchCriteria.Op.EQ, false); - // if networkId is specified, list offerings available for upgrade only (for this network) + // if networkId is specified, list offerings available for upgrade only + // (for this network) Network network = null; if (networkId != null) { // check if network exists and the caller can operate with it @@ -4202,7 +4533,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati for (PhysicalNetworkVO pNtwk : pNtwks) { List pNtwkTag = pNtwk.getTags(); if (pNtwkTag == null || pNtwkTag.isEmpty()) { - throw new CloudRuntimeException("Tags are not defined for physical network in the zone id=" + zoneId); + throw new CloudRuntimeException("Tags are not defined for physical network in the zone id=" + + zoneId); } pNtwkTags.addAll(pNtwkTag); } @@ -4210,7 +4542,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } // filter by supported services - boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty()); + boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings + .isEmpty()); boolean checkIfProvidersAreEnabled = (zoneId != null); boolean parseOfferings = (listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled || forVpc != null || network != null); @@ -4244,7 +4577,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (listBySupportedServices) { - addOffering = addOffering && _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), supportedServices); + addOffering = addOffering + && _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), supportedServices); } if (checkIfProvidersAreEnabled) { @@ -4254,16 +4588,19 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati checkForProviders = _networkModel.listNetworkOfferingServices(offering.getId()); } - addOffering = addOffering && _networkModel.areServicesEnabledInZone(zoneId, offering, checkForProviders); + addOffering = addOffering + && _networkModel.areServicesEnabledInZone(zoneId, offering, checkForProviders); } if (sourceNatSupported != null) { - addOffering = addOffering && (_networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.SourceNat) == sourceNatSupported); + addOffering = addOffering + && (_networkModel.areServicesSupportedByNetworkOffering(offering.getId(), + Network.Service.SourceNat) == sourceNatSupported); } if (forVpc != null) { addOffering = addOffering && (isOfferingForVpc(offering) == forVpc.booleanValue()); - } else if (network != null){ + } else if (network != null) { addOffering = addOffering && (isOfferingForVpc(offering) == (network.getVpcId() != null)); } @@ -4305,12 +4642,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Default network offering can't be deleted"); } - // don't allow to delete network offering if it's in use by existing networks (the offering can be disabled + // don't allow to delete network offering if it's in use by existing + // networks (the offering can be disabled // though) int networkCount = _networkDao.getNetworkCountByNetworkOffId(offeringId); if (networkCount > 0) { - throw new InvalidParameterValueException("Can't delete network offering " + offeringId + " as its used by " + networkCount + " networks. " + - "To make the network offering unavaiable, disable it"); + throw new InvalidParameterValueException("Can't delete network offering " + offeringId + " as its used by " + + networkCount + " networks. " + "To make the network offering unavaiable, disable it"); } if (_networkOfferingDao.remove(offeringId)) { @@ -4379,22 +4717,23 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (availability == null) { throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " - + Availability.Required + ", " + Availability.Optional); + + Availability.Required + ", " + Availability.Optional); } else { if (availability == NetworkOffering.Availability.Required) { - boolean canOffBeRequired = (offeringToUpdate.getGuestType() == GuestType.Isolated - && _networkModel.areServicesSupportedByNetworkOffering(offeringToUpdate.getId(), Service.SourceNat)); + boolean canOffBeRequired = (offeringToUpdate.getGuestType() == GuestType.Isolated && _networkModel + .areServicesSupportedByNetworkOffering(offeringToUpdate.getId(), Service.SourceNat)); if (!canOffBeRequired) { - throw new InvalidParameterValueException("Availability can be " + - NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with " - + Service.SourceNat.getName() + " enabled"); + throw new InvalidParameterValueException("Availability can be " + + NetworkOffering.Availability.Required + " only for networkOfferings of type " + + GuestType.Isolated + " and with " + Service.SourceNat.getName() + " enabled"); } // only one network offering in the system can be Required - List offerings = _networkOfferingDao.listByAvailability(Availability.Required, false); + List offerings = _networkOfferingDao.listByAvailability(Availability.Required, + false); if (!offerings.isEmpty() && offerings.get(0).getId() != offeringToUpdate.getId()) { - throw new InvalidParameterValueException("System already has network offering id=" + - offerings.get(0).getId() + " with availability " + Availability.Required); + throw new InvalidParameterValueException("System already has network offering id=" + + offerings.get(0).getId() + " with availability " + Availability.Required); } } offering.setAvailability(availability); @@ -4409,32 +4748,33 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } @Override - @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_MARK_DEFAULT_ZONE, eventDescription = "Marking account with the " + - "default zone", async=true) + @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_MARK_DEFAULT_ZONE, eventDescription = "Marking account with the " + + "default zone", async = true) public AccountVO markDefaultZone(String accountName, long domainId, long defaultZoneId) { - // Check if the account exists - Account account = _accountDao.findEnabledAccount(accountName, domainId); - if (account == null) { + // Check if the account exists + Account account = _accountDao.findEnabledAccount(accountName, domainId); + if (account == null) { s_logger.error("Unable to find account by name: " + accountName + " in domain " + domainId); - throw new InvalidParameterValueException("Account by name: " + accountName + " doesn't exist in domain " + domainId); + throw new InvalidParameterValueException("Account by name: " + accountName + " doesn't exist in domain " + + domainId); } // Don't allow modification of system account if (account.getId() == Account.ACCOUNT_ID_SYSTEM) { throw new InvalidParameterValueException("Can not modify system account"); - } + } - AccountVO acctForUpdate = _accountDao.findById(account.getId()); + AccountVO acctForUpdate = _accountDao.findById(account.getId()); - acctForUpdate.setDefaultZoneId(defaultZoneId); + acctForUpdate.setDefaultZoneId(defaultZoneId); - if (_accountDao.update(account.getId(), acctForUpdate)) { - UserContext.current().setEventDetails("Default zone id= " + defaultZoneId); - return _accountDao.findById(account.getId()); - } else { - return null; - } + if (_accountDao.update(account.getId(), acctForUpdate)) { + UserContext.current().setEventDetails("Default zone id= " + defaultZoneId); + return _accountDao.findById(account.getId()); + } else { + return null; + } } // Note: This method will be used for entity name validations in the coming @@ -4450,7 +4790,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati char ch = str.charAt(i); for (int j = 0; j < searchChars.length; j++) { if (searchChars[j] == ch) { - throw new InvalidParameterValueException("Name cannot contain any of the following special characters:" + forbidden); + throw new InvalidParameterValueException( + "Name cannot contain any of the following special characters:" + forbidden); } } } @@ -4479,7 +4820,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (no.getRateMbps() != null) { networkRate = no.getRateMbps(); } else { - networkRate = Integer.parseInt(_configServer.getConfigValue(Config.NetworkThrottlingRate.key(), Config.ConfigurationParameterScope.zone.toString(), dataCenterId)); + networkRate = Integer.parseInt(_configServer.getConfigValue(Config.NetworkThrottlingRate.key(), + Config.ConfigurationParameterScope.zone.toString(), dataCenterId)); } // networkRate is unsigned int in netowrkOfferings table, and can't be @@ -4567,27 +4909,27 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } @Override - public AllocationState findClusterAllocationState(ClusterVO cluster){ + public AllocationState findClusterAllocationState(ClusterVO cluster) { - if(cluster.getAllocationState() == AllocationState.Disabled){ - return AllocationState.Disabled; - }else if(ApiDBUtils.findPodById(cluster.getPodId()).getAllocationState() == AllocationState.Disabled){ - return AllocationState.Disabled; - }else { - DataCenterVO zone = ApiDBUtils.findZoneById(cluster.getDataCenterId()); - return zone.getAllocationState(); - } + if (cluster.getAllocationState() == AllocationState.Disabled) { + return AllocationState.Disabled; + } else if (ApiDBUtils.findPodById(cluster.getPodId()).getAllocationState() == AllocationState.Disabled) { + return AllocationState.Disabled; + } else { + DataCenterVO zone = ApiDBUtils.findZoneById(cluster.getDataCenterId()); + return zone.getAllocationState(); + } } @Override - public AllocationState findPodAllocationState(HostPodVO pod){ + public AllocationState findPodAllocationState(HostPodVO pod) { - if(pod.getAllocationState() == AllocationState.Disabled){ - return AllocationState.Disabled; - }else { - DataCenterVO zone = ApiDBUtils.findZoneById(pod.getDataCenterId()); - return zone.getAllocationState(); - } + if (pod.getAllocationState() == AllocationState.Disabled) { + return AllocationState.Disabled; + } else { + DataCenterVO zone = ApiDBUtils.findZoneById(pod.getDataCenterId()); + return zone.getAllocationState(); + } } private boolean allowIpRangeOverlap(VlanVO vlan, boolean forVirtualNetwork, long networkId) { @@ -4628,8 +4970,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati networkRate = offering.getRateMbps(); } else { // for domain router service offering, get network rate from - if (offering.getSystemVmType() != null && offering.getSystemVmType().equalsIgnoreCase(VirtualMachine.Type.DomainRouter.toString())) { - networkRate = Integer.parseInt(_configServer.getConfigValue(Config.NetworkThrottlingRate.key(), Config.ConfigurationParameterScope.zone.toString(), dataCenterId)); + if (offering.getSystemVmType() != null + && offering.getSystemVmType().equalsIgnoreCase(VirtualMachine.Type.DomainRouter.toString())) { + networkRate = Integer.parseInt(_configServer.getConfigValue(Config.NetworkThrottlingRate.key(), + Config.ConfigurationParameterScope.zone.toString(), dataCenterId)); } else { networkRate = Integer.parseInt(_configDao.getValue(Config.VmNetworkThrottlingRate.key())); } @@ -4658,7 +5002,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @DB - @ActionEvent(eventType = EventTypes.EVENT_PORTABLE_IP_RANGE_CREATE, eventDescription = "creating portable ip range", async = false) + @ActionEvent(eventType = EventTypes.EVENT_PORTABLE_IP_RANGE_CREATE, + eventDescription = "creating portable ip range", async = false) public PortableIpRange createPortableIpRange(CreatePortableIpRangeCmd cmd) throws ConcurrentOperationException { Integer regionId = cmd.getRegionId(); String startIP = cmd.getStartIp(); @@ -4677,18 +5022,18 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (!NetUtils.sameSubnet(startIP, gateway, netmask)) { - throw new InvalidParameterValueException("Please ensure that your start IP is in the same subnet as " + - "your portable IP range's gateway and as per the IP range's netmask."); + throw new InvalidParameterValueException("Please ensure that your start IP is in the same subnet as " + + "your portable IP range's gateway and as per the IP range's netmask."); } if (!NetUtils.sameSubnet(endIP, gateway, netmask)) { - throw new InvalidParameterValueException("Please ensure that your end IP is in the same subnet as " + - "your portable IP range's gateway and as per the IP range's netmask."); + throw new InvalidParameterValueException("Please ensure that your end IP is in the same subnet as " + + "your portable IP range's gateway and as per the IP range's netmask."); } if (checkOverlapPortableIpRange(regionId, startIP, endIP)) { - throw new InvalidParameterValueException("Ip range: " + startIP + "-" + endIP + " overlaps with a portable" + - " IP range already configured in the region " + regionId); + throw new InvalidParameterValueException("Ip range: " + startIP + "-" + endIP + + " overlaps with a portable" + " IP range already configured in the region " + regionId); } if (vlanId == null) { @@ -4706,11 +5051,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati PortableIpRangeVO portableIpRange = new PortableIpRangeVO(regionId, vlanId, gateway, netmask, startIP, endIP); portableIpRange = _portableIpRangeDao.persist(portableIpRange); - long startIpLong = NetUtils.ip2Long(startIP); + long startIpLong = NetUtils.ip2Long(startIP); long endIpLong = NetUtils.ip2Long(endIP); - while(startIpLong <= endIpLong) { - PortableIpVO portableIP = new PortableIpVO(regionId, portableIpRange.getId(), vlanId, - gateway, netmask,NetUtils.long2Ip(startIpLong)); + while (startIpLong <= endIpLong) { + PortableIpVO portableIP = new PortableIpVO(regionId, portableIpRange.getId(), vlanId, gateway, netmask, + NetUtils.long2Ip(startIpLong)); _portableIpDao.persist(portableIP); startIpLong++; } @@ -4722,7 +5067,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @DB - @ActionEvent(eventType = EventTypes.EVENT_PORTABLE_IP_RANGE_DELETE, eventDescription = "deleting portable ip range", async = false) + @ActionEvent(eventType = EventTypes.EVENT_PORTABLE_IP_RANGE_DELETE, + eventDescription = "deleting portable ip range", async = false) public boolean deletePortableIpRange(DeletePortableIpRangeCmd cmd) { long rangeId = cmd.getId(); PortableIpRangeVO portableIpRange = _portableIpRangeDao.findById(rangeId); @@ -4731,7 +5077,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } List fullIpRange = _portableIpDao.listByRangeId(portableIpRange.getId()); - List freeIpRange = _portableIpDao.listByRangeIdAndState(portableIpRange.getId(), PortableIp.State.Free); + List freeIpRange = _portableIpDao.listByRangeIdAndState(portableIpRange.getId(), + PortableIp.State.Free); if (fullIpRange != null && freeIpRange != null) { if (fullIpRange.size() == freeIpRange.size()) { @@ -4750,17 +5097,17 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati Integer regionId = cmd.getRegionIdId(); Long rangeId = cmd.getPortableIpRangeId(); - List ranges = new ArrayList(); + List ranges = new ArrayList(); if (regionId != null) { Region region = _regionDao.findById(regionId); if (region == null) { throw new InvalidParameterValueException("Invalid region ID: " + regionId); } - return _portableIpRangeDao.listByRegionId(regionId); + return _portableIpRangeDao.listByRegionId(regionId); } if (rangeId != null) { - PortableIpRangeVO range = _portableIpRangeDao.findById(rangeId); + PortableIpRangeVO range = _portableIpRangeDao.findById(rangeId); if (range == null) { throw new InvalidParameterValueException("Invalid portable IP range ID: " + regionId); } diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java index 5d4a5803da4..ec932dbbeeb 100644 --- a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java @@ -88,7 +88,7 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis } - protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) { + protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) { ServiceOffering offering = vmProfile.getServiceOffering(); VirtualMachine vm = vmProfile.getVirtualMachine(); diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java index 21917f76351..fa34d65ab1a 100755 --- a/server/src/com/cloud/network/NetworkModelImpl.java +++ b/server/src/com/cloud/network/NetworkModelImpl.java @@ -770,7 +770,7 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel { @Override public Nic getNicInNetwork(long vmId, long networkId) { - return _nicDao.findByInstanceIdAndNetworkIdIncludingRemoved(networkId, vmId); + return _nicDao.findByNtwkIdAndInstanceId(networkId, vmId); } @Override @@ -1761,7 +1761,8 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel { return true; } - Nic getNicInNetworkIncludingRemoved(long vmId, long networkId) { + @Override + public Nic getNicInNetworkIncludingRemoved(long vmId, long networkId) { return _nicDao.findByInstanceIdAndNetworkIdIncludingRemoved(networkId, vmId); } diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java index c2af8e8fe60..f026dbc2a32 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -670,8 +670,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { if (network == null) { throw new InvalidParameterValueException("Invalid network id is given"); } - accountId = network.getAccountId(); - domainId = network.getDomainId(); + accountId = ipOwner.getAccountId(); + domainId = ipOwner.getDomainId(); // Validate network offering NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(network.getNetworkOfferingId()); @@ -789,10 +789,15 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { if (dc.getNetworkType() == NetworkType.Advanced && network.getGuestType() == Network.GuestType.Isolated) { //check PF or static NAT is configured on this ip address String secondaryIp = secIpVO.getIp4Address(); - List pfRuleList = _portForwardingDao.listByDestIpAddr(secondaryIp); - if (pfRuleList.size() != 0) { - s_logger.debug("VM nic IP " + secondaryIp + " is associated with the port forwarding rule"); - throw new InvalidParameterValueException("Can't remove the secondary ip " + secondaryIp + " is associate with the port forwarding rule"); + List fwRulesList = _firewallDao.listByNetworkAndPurpose(network.getId(), Purpose.PortForwarding); + + if (fwRulesList.size() != 0) { + for (FirewallRuleVO rule: fwRulesList) { + if (_portForwardingDao.findByIdAndIp(rule.getId(), secondaryIp) != null) { + s_logger.debug("VM nic IP " + secondaryIp + " is associated with the port forwarding rule"); + throw new InvalidParameterValueException("Can't remove the secondary ip " + secondaryIp + " is associate with the port forwarding rule"); + } + } } //check if the secondary ip associated with any static nat rule IPAddressVO publicIpVO = _ipAddressDao.findByVmIp(secondaryIp); @@ -1197,9 +1202,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { + Network.GuestType.Isolated + " with a service " + Service.SourceNat.getName() + " enabled"); } - // Don't allow to specify vlan if the caller is a regular user - if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL && (ntwkOff.getSpecifyVlan() || vlanId != null)) { - throw new InvalidParameterValueException("Regular user is not allowed to specify vlanId"); + // Don't allow to specify vlan if the caller is not ROOT admin + if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && (ntwkOff.getSpecifyVlan() || vlanId != null)) { + throw new InvalidParameterValueException("Only ROOT admin is allowed to specify vlanId"); } if (ipv4) { @@ -2658,7 +2663,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { existingRanges.get(i).second(-1); } value = vnetMap.get((existingRanges.get(i).second())); - if (value != null) { + if (value != null && ( (existingRanges.get(i).second()) != (existingRanges.get(i).first()) )) { vnetMap.remove((existingRanges.get(i).second())); vnetMap.remove(existingRanges.get(i).first()); vnetMap.put(existingRanges.get(i).first(),value); @@ -2680,9 +2685,10 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { vnetString = vnetString+vnetRange.first().toString()+"-"+value.toString()+";"; } } - vnetString = vnetString+"*"; - vnetString = vnetString.replace(";*",""); - network.setVnet(vnetString); + if (vnetString.length() > 0 && vnetString.charAt(vnetString.length()-1)==';') { + vnetString = vnetString.substring(0, vnetString.length()-1); + } + network.setVnet(vnetString); } for (Pair vnetToAdd : vnetsToAdd) { @@ -2788,12 +2794,15 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { _datacneter_vnet.deleteRange(txn, network.getDataCenterId(), network.getId(), start, end); String vnetString=""; - for (Pair vnetRange : existingRanges ){ - vnetString=vnetString+vnetRange.first().toString()+"-"+vnetRange.second().toString()+";"; + if (existingRanges.isEmpty()) { + network.setVnet(null); + } else { + for (Pair vnetRange : existingRanges ) { + vnetString=vnetString+vnetRange.first().toString()+"-"+vnetRange.second().toString()+";"; + } + vnetString = vnetString.substring(0, vnetString.length()-1); + network.setVnet(vnetString); } - vnetString = vnetString+"*"; - vnetString = vnetString.replace(";*",""); - network.setVnet(vnetString); _physicalNetworkDao.update(network.getId(), network); txn.commit(); _physicalNetworkDao.releaseFromLockTable(network.getId()); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 40db31ff6a5..f3719f3334e 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -3145,6 +3145,16 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V vlanIpMap.put(vlanTag, ipList); } + List nics = _nicDao.listByVmId(router.getId()); + String baseMac = null; + for (NicVO nic : nics) { + NetworkVO nw = _networkDao.findById(nic.getNetworkId()); + if (nw.getTrafficType() == TrafficType.Public) { + baseMac = nic.getMacAddress(); + break; + } + } + for (Map.Entry> vlanAndIp : vlanIpMap.entrySet()) { List ipAddrList = vlanAndIp.getValue(); // Source nat ip address should always be sent first @@ -3176,7 +3186,14 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V String vlanId = ipAddr.getVlanTag(); String vlanGateway = ipAddr.getGateway(); String vlanNetmask = ipAddr.getNetmask(); - String vifMacAddress = ipAddr.getMacAddress(); + String vifMacAddress = null; + // For non-source nat IP, set the mac to be something based on first public nic's MAC + // We cannot depends on first ip because we need to deal with first ip of other nics + if (!ipAddr.isSourceNat() && ipAddr.getVlanId() != 0) { + vifMacAddress = NetUtils.generateMacOnIncrease(baseMac, ipAddr.getVlanId()); + } else { + vifMacAddress = ipAddr.getMacAddress(); + } IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, networkRate, ipAddr.isOneToOneNat()); @@ -3337,7 +3354,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V // password should be set only on default network element if (password != null && nic.isDefaultNic()) { - final String encodedPassword = PasswordGenerator.rot13(password); + String encodedPassword = PasswordGenerator.rot13(password); + // We would unset password for BACKUP router in the RvR, to prevent user from accidently reset the + // password again after BACKUP become MASTER + if (router.getIsRedundantRouter() && router.getRedundantState() != RedundantState.MASTER) { + encodedPassword = PasswordGenerator.rot13("saved_password"); + } SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), profile.getVirtualMachine().getHostName()); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(nic.getNetworkId(), router.getId())); diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index 41bf2b3af65..bcda32d1d64 100755 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -1371,7 +1371,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules // create new static nat rule // Get nic IP4 address - Nic guestNic = _networkModel.getNicInNetwork(vm.getId(), networkId); + Nic guestNic = _networkModel.getNicInNetworkIncludingRemoved(vm.getId(), networkId); if (guestNic == null) { throw new InvalidParameterValueException("Vm doesn't belong to the network with specified id"); } diff --git a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java index 4ad22d90770..a28657b4a81 100644 --- a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java +++ b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java @@ -294,6 +294,10 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ throw new InvalidParameterValueException("Start port can't be bigger than end port"); } + // start port and end port must be null for protocol = 'all' + if ((portStart != null || portEnd != null ) && protocol != null && protocol.equalsIgnoreCase("all")) + throw new InvalidParameterValueException("start port and end port must be null if protocol = 'all'"); + if (sourceCidrList != null) { for (String cidr: sourceCidrList){ if (!NetUtils.isValidCIDR(cidr)){ diff --git a/server/src/com/cloud/storage/VolumeManager.java b/server/src/com/cloud/storage/VolumeManager.java index ffa20d306c5..c84bb67e038 100644 --- a/server/src/com/cloud/storage/VolumeManager.java +++ b/server/src/com/cloud/storage/VolumeManager.java @@ -118,4 +118,6 @@ public interface VolumeManager extends VolumeApiService { String getVmNameFromVolumeId(long volumeId); String getStoragePoolOfVolume(long volumeId); + + boolean validateVolumeSizeRange(long size); } diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index eca842800a5..4e7b3353ba0 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -1328,7 +1328,8 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { return true; } - private boolean validateVolumeSizeRange(long size) { + @Override + public boolean validateVolumeSizeRange(long size) { if (size < 0 || (size > 0 && size < (1024 * 1024 * 1024))) { throw new InvalidParameterValueException( "Please specify a size of at least 1 Gb."); diff --git a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java index f5ce55f197f..2b1aa4e1bf2 100755 --- a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java +++ b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java @@ -187,7 +187,6 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor dl.setCurrState(vmTemplateStore.getDownloadState()); } - DownloadListener old = null; synchronized (_listenerTemplateMap) { old = _listenerTemplateMap.put(vmTemplateStore, dl); diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index a1a4c90572a..7e1e3d424bf 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -537,7 +537,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, String intervalTypeStr = cmd.getIntervalType(); String zoneType = cmd.getZoneType(); Map tags = cmd.getTags(); - + Long zoneId = cmd.getZoneId(); Account caller = UserContext.current().getCaller(); List permittedAccounts = new ArrayList(); @@ -565,7 +565,8 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("snapshotTypeEQ", sb.entity().getsnapshotType(), SearchCriteria.Op.IN); sb.and("snapshotTypeNEQ", sb.entity().getsnapshotType(), SearchCriteria.Op.NEQ); - + 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++) { @@ -607,6 +608,10 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, 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/storage/snapshot/SnapshotSchedulerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java index 9b6d2188385..6a5d0cacbd6 100644 --- a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java @@ -208,10 +208,6 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu List snapshotsToBeExecuted = _snapshotScheduleDao.getSchedulesToExecute(_currentTimestamp); s_logger.debug("Got " + snapshotsToBeExecuted.size() + " snapshots to be executed at " + displayTime); - // This is done for recurring snapshots, which are executed by the system automatically - // Hence set user id to that of system - long userId = 1; - for (SnapshotScheduleVO snapshotToBeExecuted : snapshotsToBeExecuted) { SnapshotScheduleVO tmpSnapshotScheduleVO = null; long snapshotScheId = snapshotToBeExecuted.getId(); @@ -236,7 +232,7 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu tmpSnapshotScheduleVO = _snapshotScheduleDao.acquireInLockTable(snapshotScheId); - Long eventId = ActionEventUtils.onScheduledActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, + Long eventId = ActionEventUtils.onScheduledActionEvent(User.UID_SYSTEM, volume.getAccountId(), EventTypes.EVENT_SNAPSHOT_CREATE, "creating snapshot for volume Id:" + volumeId, 0); Map params = new HashMap(); diff --git a/server/src/com/cloud/storage/upload/UploadMonitorImpl.java b/server/src/com/cloud/storage/upload/UploadMonitorImpl.java index 7d75599faad..d46db0ce3a6 100755 --- a/server/src/com/cloud/storage/upload/UploadMonitorImpl.java +++ b/server/src/com/cloud/storage/upload/UploadMonitorImpl.java @@ -111,6 +111,7 @@ public class UploadMonitorImpl extends ManagerBase implements UploadMonitor { private String _name; private Boolean _sslCopy = new Boolean(false); + private String _ssvmUrlDomain; private ScheduledExecutorService _executor = null; Timer _timer; @@ -330,8 +331,14 @@ public class UploadMonitorImpl extends ManagerBase implements UploadMonitor { String scheme = "http"; if (_sslCopy) { hostname = ipAddress.replace(".", "-"); - hostname = hostname + ".realhostip.com"; scheme = "https"; + + // Code for putting in custom certificates. + if(_ssvmUrlDomain != null && _ssvmUrlDomain.length() > 0){ + hostname = hostname + "." + _ssvmUrlDomain; + }else{ + hostname = hostname + ".realhostip.com"; + } } return scheme + "://" + hostname + "/userdata/" + uuid; } @@ -350,6 +357,8 @@ public class UploadMonitorImpl extends ManagerBase implements UploadMonitor { s_logger.warn("Only realhostip.com ssl cert is supported, ignoring self-signed and other certs"); } + _ssvmUrlDomain = configs.get("secstorage.ssl.cert.domain"); + _agentMgr.registerForHostEvents(new UploadListener(this), true, false, false); String cleanupInterval = configs.get("extract.url.cleanup.interval"); _cleanupInterval = NumbersUtil.parseInt(cleanupInterval, 7200); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 6cfb0780533..ee3f252f6c3 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -3398,6 +3398,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override public void collectVmDiskStatistics (UserVmVO userVm) { + // support KVM and XenServer only + if (!userVm.getHypervisorType().equals(HypervisorType.XenServer) + && !userVm.getHypervisorType().equals(HypervisorType.KVM)) + return; // Collect vm disk statistics from host before stopping Vm long hostId = userVm.getHostId(); List vmNames = new ArrayList(); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index c938e782e80..6af664ab4b0 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -129,6 +129,7 @@ import com.cloud.network.rules.RulesManager; import com.cloud.offering.ServiceOffering; import com.cloud.org.Cluster; import com.cloud.resource.ResourceManager; +import com.cloud.server.ConfigurationServer; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.DiskOfferingVO; @@ -256,6 +257,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac protected RulesManager rulesMgr; @Inject protected AffinityGroupVMMapDao _affinityGroupVMMapDao; + @Inject + protected ConfigurationServer _configServer; protected List _planners; public List getPlanners() { @@ -3226,8 +3229,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac long newServiceofferingId = vm.getServiceOfferingId(); ServiceOffering newServiceOffering = _configMgr.getServiceOffering(newServiceofferingId); + HostVO hostVo = _hostDao.findById(vm.hostId); + Float memoryOvercommitRatio = Float.parseFloat(_configServer.getConfigValue(Config.MemOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), hostVo.getClusterId())); + Float cpuOvercommitRatio = Float.parseFloat(_configServer.getConfigValue(Config.CPUOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), hostVo.getClusterId())); + long minMemory = (long) (newServiceOffering.getRamSize()/memoryOvercommitRatio); ScaleVmCommand reconfigureCmd = new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), - newServiceOffering.getSpeed(), newServiceOffering.getRamSize(), newServiceOffering.getRamSize(), newServiceOffering.getLimitCpuUse()); + (int) (newServiceOffering.getSpeed()/cpuOvercommitRatio), newServiceOffering.getSpeed(), minMemory * 1024 * 1024, newServiceOffering.getRamSize() * 1024 * 1024, newServiceOffering.getLimitCpuUse()); Long dstHostId = vm.getHostId(); ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, State.Running, vm.getType(), vm.getId()); diff --git a/server/test/com/cloud/configuration/ValidateIpRangeTest.java b/server/test/com/cloud/configuration/ValidateIpRangeTest.java index 768166719f2..ca9ef110151 100644 --- a/server/test/com/cloud/configuration/ValidateIpRangeTest.java +++ b/server/test/com/cloud/configuration/ValidateIpRangeTest.java @@ -19,6 +19,7 @@ package com.cloud.configuration; import com.cloud.dc.VlanVO; import com.cloud.network.Network; import com.cloud.network.NetworkModel; +import com.cloud.utils.Pair; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -49,20 +50,20 @@ public class ValidateIpRangeTest { @Test public void SameSubnetTest() { - boolean sameSubnet=configurationMgr.validateIpRange("10.147.33.104", "10.147.33.105", "10.147.33.1", "255.255.255.128", vlanVOList, true, false, null, null, null, null,network); - Assert.assertTrue(sameSubnet); + Pair> sameSubnet = configurationMgr.validateIpRange("10.147.33.104", "10.147.33.105", "10.147.33.1", "255.255.255.128", vlanVOList, true, false, null, null, null, null,network); + Assert.assertTrue(sameSubnet.first()); } @Test public void NewSubnetTest() { - boolean sameSubnet= configurationMgr.validateIpRange("10.147.33.140", "10.147.33.145", "10.147.33.129", "255.255.255.191", vlanVOList, true, false, null, null, null, null,network); - Assert.assertTrue(!sameSubnet); + Pair> sameSubnet = configurationMgr.validateIpRange("10.147.33.140", "10.147.33.145", "10.147.33.130", "255.255.255.192", vlanVOList, true, false, null, null, null, null,network); + Assert.assertTrue(!sameSubnet.first()); } @Test public void SuperSetTest() { try { - configurationMgr.validateIpRange("10.147.33.140", "10.147.33.143", "10.147.33.140", "255.255.255.191", vlanVOList, true, false, null, null, null, null,network); + configurationMgr.validateIpRange("10.147.33.10", "10.147.33.20", "10.147.33.21", "255.255.255.0", vlanVOList, true, false, null, null, null, null,network); } catch (Exception e) { junit.framework.Assert.assertTrue(e.getMessage().contains("superset")); } diff --git a/server/test/com/cloud/network/MockNetworkModelImpl.java b/server/test/com/cloud/network/MockNetworkModelImpl.java index c3a0d6c5ae9..3a367480a30 100644 --- a/server/test/com/cloud/network/MockNetworkModelImpl.java +++ b/server/test/com/cloud/network/MockNetworkModelImpl.java @@ -874,4 +874,9 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel { // TODO Auto-generated method stub return null; } + + @Override + public Nic getNicInNetworkIncludingRemoved(long vmId, long networkId) { + return null; + } } diff --git a/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java b/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java index dd51e74a618..8715c9e8663 100644 --- a/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java +++ b/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java @@ -22,11 +22,13 @@ import com.cloud.agent.api.Answer; import com.cloud.agent.api.ScaleVmAnswer; import com.cloud.agent.api.ScaleVmCommand; import com.cloud.capacity.CapacityManager; +import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.deploy.DeployDestination; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; +import com.cloud.server.ConfigurationServer; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VolumeManager; @@ -154,6 +156,10 @@ public class VirtualMachineManagerImplTest { List _rootVols; @Mock ItWorkVO _work; + @Mock + ConfigurationServer _configServer; + @Mock + HostVO hostVO; @Mock ClusterDao _clusterDao; @Mock HostPodDao _podDao; @@ -199,6 +205,7 @@ public class VirtualMachineManagerImplTest { _vmMgr._hvGuruMgr = _hvGuruMgr; _vmMgr._vmSnapshotMgr = _vmSnapshotMgr; _vmMgr._vmDao = _vmInstanceDao; + _vmMgr._configServer = _configServer; when(_vmMock.getId()).thenReturn(314l); when(_vmInstance.getId()).thenReturn(1L); @@ -239,8 +246,12 @@ public class VirtualMachineManagerImplTest { when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance); ServiceOfferingVO newServiceOffering = getSvcoffering(512); + when(_hostDao.findById(_vmInstance.hostId)).thenReturn(hostVO); + doReturn(1L).when(hostVO).getClusterId(); + when(_configServer.getConfigValue(Config.MemOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), 1L)).thenReturn("1.0"); + when(_configServer.getConfigValue(Config.CPUOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), 1L)).thenReturn("1.0"); ScaleVmCommand reconfigureCmd = new ScaleVmCommand("myVmName", newServiceOffering.getCpu(), - newServiceOffering.getSpeed(), newServiceOffering.getRamSize(), newServiceOffering.getRamSize(), newServiceOffering.getLimitCpuUse()); + newServiceOffering.getSpeed(), newServiceOffering.getSpeed(), newServiceOffering.getRamSize(), newServiceOffering.getRamSize(), newServiceOffering.getLimitCpuUse()); Answer answer = new ScaleVmAnswer(reconfigureCmd, true, "details"); when(_agentMgr.send(2l, reconfigureCmd)).thenReturn(null); _vmMgr.reConfigureVm(_vmInstance, getSvcoffering(256), false); diff --git a/server/test/com/cloud/vpc/MockNetworkModelImpl.java b/server/test/com/cloud/vpc/MockNetworkModelImpl.java index d9e33b75616..3e67f5e76e2 100644 --- a/server/test/com/cloud/vpc/MockNetworkModelImpl.java +++ b/server/test/com/cloud/vpc/MockNetworkModelImpl.java @@ -887,4 +887,9 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel { return null; } + @Override + public Nic getNicInNetworkIncludingRemoved(long vmId, long networkId) { + return null; + } + } diff --git a/services/console-proxy/server/js/ajaxkeys.js b/services/console-proxy/server/js/ajaxkeys.js index 5f497bbb785..677962be192 100644 --- a/services/console-proxy/server/js/ajaxkeys.js +++ b/services/console-proxy/server/js/ajaxkeys.js @@ -146,6 +146,17 @@ X11_KEY_TILDE = 0x7e; // ~ X11_KEY_CIRCUMFLEX_ACCENT = 0x5e; // ^ X11_KEY_YEN_MARK = 0xa5; // Japanese YEN mark X11_KEY_ASTERISK = 0x2a; +X11_KEY_KP_0 = 0xFFB0; +X11_KEY_KP_1 = 0xFFB1; +X11_KEY_KP_2 = 0xFFB2; +X11_KEY_KP_3 = 0xFFB3; +X11_KEY_KP_4 = 0xFFB4; +X11_KEY_KP_5 = 0xFFB5; +X11_KEY_KP_6 = 0xFFB6; +X11_KEY_KP_7 = 0xFFB7; +X11_KEY_KP_8 = 0xFFB8; +X11_KEY_KP_9 = 0xFFB9; +X11_KEY_KP_Decimal = 0xFFAE; KEY_DOWN = 5; KEY_UP = 6; @@ -248,17 +259,17 @@ var keyboardTables = [ {keycode: JS_KEY_FORWARD_SLASH, entry : X11_KEY_FORWARD_SLASH}, {keycode: JS_KEY_DASH, entry : X11_KEY_DASH}, {keycode: JS_KEY_SEMI_COLON, entry : X11_KEY_SEMI_COLON}, - {keycode: JS_KEY_NUMPAD0, entry : X11_KEY_NUMPAD0}, - {keycode: JS_KEY_NUMPAD1, entry : X11_KEY_NUMPAD1}, - {keycode: JS_KEY_NUMPAD2, entry : X11_KEY_NUMPAD2}, - {keycode: JS_KEY_NUMPAD3, entry : X11_KEY_NUMPAD3}, - {keycode: JS_KEY_NUMPAD4, entry : X11_KEY_NUMPAD4}, - {keycode: JS_KEY_NUMPAD5, entry : X11_KEY_NUMPAD5}, - {keycode: JS_KEY_NUMPAD6, entry : X11_KEY_NUMPAD6}, - {keycode: JS_KEY_NUMPAD7, entry : X11_KEY_NUMPAD7}, - {keycode: JS_KEY_NUMPAD8, entry : X11_KEY_NUMPAD8}, - {keycode: JS_KEY_NUMPAD9, entry : X11_KEY_NUMPAD9}, - {keycode: JS_KEY_DECIMAL_POINT, entry : X11_KEY_DECIMAL_POINT}, + {keycode: JS_KEY_NUMPAD0, entry : X11_KEY_KP_0}, + {keycode: JS_KEY_NUMPAD1, entry : X11_KEY_KP_1}, + {keycode: JS_KEY_NUMPAD2, entry : X11_KEY_KP_2}, + {keycode: JS_KEY_NUMPAD3, entry : X11_KEY_KP_3}, + {keycode: JS_KEY_NUMPAD4, entry : X11_KEY_KP_4}, + {keycode: JS_KEY_NUMPAD5, entry : X11_KEY_KP_5}, + {keycode: JS_KEY_NUMPAD6, entry : X11_KEY_KP_6}, + {keycode: JS_KEY_NUMPAD7, entry : X11_KEY_KP_7}, + {keycode: JS_KEY_NUMPAD8, entry : X11_KEY_KP_8}, + {keycode: JS_KEY_NUMPAD9, entry : X11_KEY_KP_9}, + {keycode: JS_KEY_DECIMAL_POINT, entry : X11_KEY_KP_Decimal}, {keycode: JS_KEY_DIVIDE, entry : 0xffaf}, {keycode: JS_KEY_MULTIPLY, entry : 0xffaa}, {keycode: JS_KEY_ADD, entry : 0xffab}, @@ -289,9 +300,12 @@ var keyboardTables = [ ] } }, {tindex: 2, keyboardType: KEYBOARD_TYPE_UK, mappingTable: - {X11: [], - keyPress: [ - //[34 = "] + {X11: [ + //[223 = `¬¦] + {keycode: 223, entry : 0x60, browser: "IE"}, + ], + keyPress: [ + //[34 = "] {keycode: 34, entry: [{type : KEY_DOWN, code : 0x40, modifiers : 64, shift : true}] }, diff --git a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyClientBase.java b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyClientBase.java index f4c912a9e53..07a1b6f8f96 100644 --- a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyClientBase.java +++ b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyClientBase.java @@ -253,7 +253,8 @@ public abstract class ConsoleProxyClientBase implements ConsoleProxyClient, Cons if(s_logger.isTraceEnabled()) s_logger.trace("Ajax client start, frame buffer w: " + width + ", " + height); - + +/* int retry = 0; tracker.initCoverageTest(); while(!tracker.hasFullCoverage() && retry < 10) { @@ -263,6 +264,7 @@ public abstract class ConsoleProxyClientBase implements ConsoleProxyClient, Cons } retry++; } +*/ List tiles = tracker.scan(true); String imgUrl = prepareAjaxImage(tiles, true); diff --git a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyGCThread.java b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyGCThread.java index 7f82a965f69..9e637a51a13 100644 --- a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyGCThread.java +++ b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyGCThread.java @@ -64,6 +64,7 @@ public class ConsoleProxyGCThread extends Thread { public void run() { boolean bReportLoad = false; + long lastReportTick = System.currentTimeMillis(); while (true) { cleanupLogging(); bReportLoad = false; @@ -95,10 +96,12 @@ public class ConsoleProxyGCThread extends Thread { client.closeClient(); } - if(bReportLoad) { + if(bReportLoad || System.currentTimeMillis() - lastReportTick > 5000) { // report load changes String loadInfo = new ConsoleProxyClientStatsCollector(connMap).getStatsReport(); ConsoleProxy.reportLoadInfo(loadInfo); + lastReportTick = System.currentTimeMillis(); + if(s_logger.isDebugEnabled()) s_logger.debug("Report load change : " + loadInfo); } diff --git a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java index 6a473b5f007..5c838a59517 100644 --- a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java +++ b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java @@ -46,7 +46,7 @@ public class ConsoleProxyVncClient extends ConsoleProxyClientBase { private VncClient client; private Thread worker; - private boolean workerDone = false; + private volatile boolean workerDone = false; private int lastModifierStates = 0; private int lastPointerMask = 0; @@ -80,7 +80,7 @@ public class ConsoleProxyVncClient extends ConsoleProxyClientBase { String tunnelUrl = getClientParam().getClientTunnelUrl(); String tunnelSession = getClientParam().getClientTunnelSession(); - for(int i = 0; i < 15; i++) { + for(int i = 0; i < 15 && !workerDone; i++) { try { if(tunnelUrl != null && !tunnelUrl.isEmpty() && tunnelSession != null && !tunnelSession.isEmpty()) { URI uri = new URI(tunnelUrl); @@ -136,6 +136,7 @@ public class ConsoleProxyVncClient extends ConsoleProxyClientBase { @Override public void closeClient() { + workerDone = true; if(client != null) client.shutdown(); } diff --git a/services/console-proxy/server/src/com/cloud/consoleproxy/vnc/VncClientPacketSender.java b/services/console-proxy/server/src/com/cloud/consoleproxy/vnc/VncClientPacketSender.java index d27b76d3468..ea15a608dfb 100644 --- a/services/console-proxy/server/src/com/cloud/consoleproxy/vnc/VncClientPacketSender.java +++ b/services/console-proxy/server/src/com/cloud/consoleproxy/vnc/VncClientPacketSender.java @@ -77,8 +77,10 @@ public class VncClientPacketSender implements Runnable, PaintNotificationListene s_logger.error("Unexpected exception: ", e); if (connectionAlive) { closeConnection(); - vncConnection.shutdown(); } + } finally { + s_logger.info("Sending thread exit processing, shutdown connection"); + vncConnection.shutdown(); } } diff --git a/services/console-proxy/server/src/com/cloud/consoleproxy/vnc/VncServerPacketReceiver.java b/services/console-proxy/server/src/com/cloud/consoleproxy/vnc/VncServerPacketReceiver.java index 57c8ff8efe2..2bd2c6f8cce 100644 --- a/services/console-proxy/server/src/com/cloud/consoleproxy/vnc/VncServerPacketReceiver.java +++ b/services/console-proxy/server/src/com/cloud/consoleproxy/vnc/VncServerPacketReceiver.java @@ -90,8 +90,10 @@ public class VncServerPacketReceiver implements Runnable { s_logger.error("Unexpected exception: ", e); if (connectionAlive) { closeConnection(); - vncConnection.shutdown(); } + } finally { + s_logger.info("Receiving thread exit processing, shutdown connection"); + vncConnection.shutdown(); } } diff --git a/setup/db/db/schema-2214to30.sql b/setup/db/db/schema-2214to30.sql index e288b0fd4f9..326e9a71cb6 100755 --- a/setup/db/db/schema-2214to30.sql +++ b/setup/db/db/schema-2214to30.sql @@ -665,6 +665,7 @@ ALTER TABLE `cloud`.`dc_storage_network_ip_range` ADD COLUMN `gateway` varchar(1 ALTER TABLE `cloud`.`volumes` ADD COLUMN `last_pool_id` bigint unsigned; UPDATE `cloud`.`volumes` SET `last_pool_id` = `pool_id`; UPDATE `cloud`.`volumes` SET `path` = SUBSTRING_INDEX(`path`, '/', -1); +UPDATE `cloud`.`template_spool_ref` SET `local_path` = SUBSTRING_INDEX(`local_path`, '/', -1); ALTER TABLE `cloud`.`user_ip_address` ADD COLUMN `is_system` int(1) unsigned NOT NULL default '0'; ALTER TABLE `cloud`.`volumes` ADD COLUMN `update_count` bigint unsigned NOT NULL DEFAULT 0; diff --git a/setup/dev/advanced.cfg b/setup/dev/advanced.cfg index 83357866ca7..302016569ab 100644 --- a/setup/dev/advanced.cfg +++ b/setup/dev/advanced.cfg @@ -99,6 +99,24 @@ "name": "PS1" } ] + }, + { + "clustername": "C1", + "hypervisor": "simulator", + "hosts": [ + { + "username": "root", + "url": "http://sim/c1/h0", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://10.147.28.6:/export/home/sandbox/primary2", + "name": "PS2" + } + ] } ], "gateway": "172.16.15.1" diff --git a/test/integration/component/test_accounts.py b/test/integration/component/test_accounts.py index a25e63688f3..3f106c3b048 100644 --- a/test/integration/component/test_accounts.py +++ b/test/integration/component/test_accounts.py @@ -385,7 +385,6 @@ class TestRemoveUserFromAccount(cloudstackTestCase): ) return - @unittest.skip("Open Questions") @attr(tags=["advanced", "basic", "eip", "advancedns", "sg"]) def test_02_remove_all_users(self): """Test Remove both users from the account @@ -712,7 +711,6 @@ class TestServiceOfferingSiblings(cloudstackTestCase): return -@unittest.skip("Open Questions") class TestServiceOfferingHierarchy(cloudstackTestCase): @classmethod @@ -841,7 +839,6 @@ class TestServiceOfferingHierarchy(cloudstackTestCase): return -@unittest.skip("Open Questions") class TesttemplateHierarchy(cloudstackTestCase): @classmethod @@ -1441,7 +1438,6 @@ class TestUserDetails(cloudstackTestCase): ) return -@unittest.skip("Login API response returns nothing") class TestUserLogin(cloudstackTestCase): @classmethod diff --git a/test/integration/component/test_advancedsg_networks.py b/test/integration/component/test_advancedsg_networks.py index e24254d4b90..e1694f12668 100644 --- a/test/integration/component/test_advancedsg_networks.py +++ b/test/integration/component/test_advancedsg_networks.py @@ -274,7 +274,7 @@ class TestNetworksInAdvancedSG(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, listall=True ) self.assertEqual( @@ -308,7 +308,7 @@ class TestNetworksInAdvancedSG(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.user_account.account.id, + id=self.user_account.id, listall=True ) self.assertEqual( @@ -452,7 +452,7 @@ class TestNetworksInAdvancedSG(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, listall=True ) self.assertEqual( @@ -471,7 +471,7 @@ class TestNetworksInAdvancedSG(cloudstackTestCase): "The admin account created is not enabled." ) - self.debug("Domain admin account created: %s" % self.admin_account.account.id) + self.debug("Domain admin account created: %s" % self.admin_account.id) #Verify that there should be at least one physical network present in zone. list_physical_networks_response = PhysicalNetwork.list( @@ -599,7 +599,7 @@ class TestNetworksInAdvancedSG(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, liistall=True ) self.assertEqual( @@ -693,7 +693,7 @@ class TestNetworksInAdvancedSG(cloudstackTestCase): self.shared_network_sg = Network.create( self.api_client, self.services["shared_network_sg"], - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkofferingid=self.shared_network_offering_sg.id, zoneid=self.zone.id ) @@ -726,10 +726,11 @@ class TestNetworksInAdvancedSG(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkids=self.shared_network_sg.id, serviceofferingid=self.service_offering.id ) + self.cleanup_vms.append(self.shared_network_admin_account_virtual_machine) vms = VirtualMachine.list( self.api_client, id=self.shared_network_admin_account_virtual_machine.id, diff --git a/test/integration/component/test_custom_hostname.py b/test/integration/component/test_custom_hostname.py index a85f619fc00..c9db2154a94 100644 --- a/test/integration/component/test_custom_hostname.py +++ b/test/integration/component/test_custom_hostname.py @@ -169,13 +169,13 @@ class TestInstanceNameFlagTrue(cloudstackTestCase): # 2. Give the user provided user name. Internal name should be # i---display name - self.debug("Deploying VM in account: %s" % self.account.account.name) + self.debug("Deploying VM in account: %s" % self.account.name) # Spawn an instance in that network virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], - accountid=self.account.account.name, - domainid=self.account.account.domainid, + accountid=self.account.name, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, ) self.debug( @@ -208,11 +208,11 @@ class TestInstanceNameFlagTrue(cloudstackTestCase): # Fetch account ID and VMID from database to check internal name self.debug("select id from account where uuid = '%s';" \ - % self.account.account.id) + % self.account.id) qresultset = self.dbclient.execute( "select id from account where uuid = '%s';" \ - % self.account.account.id + % self.account.id ) self.assertEqual( isinstance(qresultset, list), @@ -273,12 +273,12 @@ class TestInstanceNameFlagTrue(cloudstackTestCase): # Removing display name from config del self.services["virtual_machine"]["displayname"] - self.debug("Deploying VM in account: %s" % self.account.account.name) + self.debug("Deploying VM in account: %s" % self.account.name) virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], - accountid=self.account.account.name, - domainid=self.account.account.domainid, + accountid=self.account.name, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, ) self.debug( @@ -307,11 +307,11 @@ class TestInstanceNameFlagTrue(cloudstackTestCase): ) # Fetch account ID and VMID from database to check internal name self.debug("select id from account where uuid = '%s';" \ - % self.account.account.id) + % self.account.id) qresultset = self.dbclient.execute( "select id from account where uuid = '%s';" \ - % self.account.account.id + % self.account.id ) self.assertEqual( isinstance(qresultset, list), diff --git a/test/integration/component/test_egress_rules.py b/test/integration/component/test_egress_rules.py index 607bac86325..c8b3eeeef69 100644 --- a/test/integration/component/test_egress_rules.py +++ b/test/integration/component/test_egress_rules.py @@ -1966,7 +1966,6 @@ class TestStartStopVMWithEgressRule(cloudstackTestCase): return -@unittest.skip("Valid bug- ID: CS-12647") class TestInvalidParametersForEgress(cloudstackTestCase): def setUp(self): diff --git a/test/integration/component/test_eip_elb.py b/test/integration/component/test_eip_elb.py index 14af4a3463f..42a5148762e 100644 --- a/test/integration/component/test_eip_elb.py +++ b/test/integration/component/test_eip_elb.py @@ -182,7 +182,6 @@ class TestEIP(cloudstackTestCase): @attr(tags = ["eip"]) - @unittest.skip("skipped - Framework DB Exception") def test_01_eip_by_deploying_instance(self): """Test EIP by deploying an instance """ @@ -350,7 +349,6 @@ class TestEIP(cloudstackTestCase): return @attr(tags = ["eip"]) - @unittest.skip("skipped - Framework DB Exception") def test_02_acquire_ip_enable_static_nat(self): """Test associate new IP and enable static NAT for new IP and the VM """ @@ -495,7 +493,6 @@ class TestEIP(cloudstackTestCase): return @attr(tags = ["eip"]) - @unittest.skip("skipped - Framework DB Exception") def test_03_disable_static_nat(self): """Test disable static NAT and release EIP acquired """ @@ -695,7 +692,6 @@ class TestEIP(cloudstackTestCase): return @attr(tags = ["eip"]) - @unittest.skip("skipped - Framework DB Exception") def test_04_disable_static_nat_system(self): """Test disable static NAT with system = True """ @@ -765,7 +761,6 @@ class TestEIP(cloudstackTestCase): return @attr(tags = ["eip"]) - @unittest.skip("skipped - Framework DB Exception") def test_05_destroy_instance(self): """Test EIO after destroying instance """ @@ -1406,7 +1401,6 @@ class TestELB(cloudstackTestCase): return @attr(tags = ["eip"]) - @unittest.skip("valid bug : http://bugs.cloudstack.org/browse/CS-15077 : ListPublicIPAddress failing") def test_04_delete_lb_on_eip(self): """Test delete LB rule generated on EIP """ diff --git a/test/integration/component/test_netscaler_configs.py b/test/integration/component/test_netscaler_configs.py index 1c67bc4c29e..3c18c0050fd 100644 --- a/test/integration/component/test_netscaler_configs.py +++ b/test/integration/component/test_netscaler_configs.py @@ -2135,7 +2135,7 @@ class TestGuestNetworkShutDown(cloudstackTestCase): cls.api_client, cls.services["network"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) @@ -2145,7 +2145,7 @@ class TestGuestNetworkShutDown(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -2153,7 +2153,7 @@ class TestGuestNetworkShutDown(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -2161,7 +2161,7 @@ class TestGuestNetworkShutDown(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls.lb_rule = LoadBalancerRule.create( @@ -2658,7 +2658,7 @@ class TestServiceProvider(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -2691,7 +2691,7 @@ class TestServiceProvider(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -2721,7 +2721,7 @@ class TestServiceProvider(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -2734,7 +2734,7 @@ class TestServiceProvider(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -2766,7 +2766,7 @@ class TestServiceProvider(cloudstackTestCase): self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) self.debug( @@ -2813,7 +2813,7 @@ class TestServiceProvider(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) diff --git a/test/integration/component/test_netscaler_lb.py b/test/integration/component/test_netscaler_lb.py index 80b3f0b8b93..b4e6c30497f 100644 --- a/test/integration/component/test_netscaler_lb.py +++ b/test/integration/component/test_netscaler_lb.py @@ -245,7 +245,7 @@ class TestLbSourceNat(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -258,7 +258,7 @@ class TestLbSourceNat(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -294,7 +294,7 @@ class TestLbSourceNat(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -325,7 +325,7 @@ class TestLbSourceNat(cloudstackTestCase): self.apiclient, associatednetworkid=self.network.id, account=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, listall=True, issourcenat=True, ) @@ -454,7 +454,7 @@ class TestLbOnIpWithPf(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -467,7 +467,7 @@ class TestLbOnIpWithPf(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -503,7 +503,7 @@ class TestLbOnIpWithPf(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -535,7 +535,7 @@ class TestLbOnIpWithPf(cloudstackTestCase): self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) @@ -665,7 +665,7 @@ class TestPfOnIpWithLb(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -678,7 +678,7 @@ class TestPfOnIpWithLb(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -714,7 +714,7 @@ class TestPfOnIpWithLb(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -747,7 +747,7 @@ class TestPfOnIpWithLb(cloudstackTestCase): self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) self.debug("Associated %s with network %s" % ( @@ -877,7 +877,7 @@ class TestLbOnNonSourceNat(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -890,7 +890,7 @@ class TestLbOnNonSourceNat(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -926,7 +926,7 @@ class TestLbOnNonSourceNat(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -959,7 +959,7 @@ class TestLbOnNonSourceNat(cloudstackTestCase): self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) self.debug("Associated %s with network %s" % ( @@ -1097,7 +1097,7 @@ class TestAddMultipleVmsLb(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -1110,7 +1110,7 @@ class TestAddMultipleVmsLb(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -1146,7 +1146,7 @@ class TestAddMultipleVmsLb(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -1179,7 +1179,7 @@ class TestAddMultipleVmsLb(cloudstackTestCase): self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) self.debug("Associated %s with network %s" % ( @@ -1371,7 +1371,7 @@ class TestMultipleLbRules(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -1384,7 +1384,7 @@ class TestMultipleLbRules(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -1420,7 +1420,7 @@ class TestMultipleLbRules(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -1455,7 +1455,7 @@ class TestMultipleLbRules(cloudstackTestCase): self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) self.debug("Associated %s with network %s" % ( @@ -1501,7 +1501,7 @@ class TestMultipleLbRules(cloudstackTestCase): self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) self.debug("Associated %s with network %s" % ( @@ -1688,7 +1688,7 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -1701,7 +1701,7 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -1737,7 +1737,7 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -1772,7 +1772,7 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) self.debug("Associated %s with network %s" % ( @@ -1953,7 +1953,7 @@ class TestLoadBalancingRule(cloudstackTestCase): cls.api_client, cls.services["network"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) @@ -1963,7 +1963,7 @@ class TestLoadBalancingRule(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -1971,7 +1971,7 @@ class TestLoadBalancingRule(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls.lb_rule = LoadBalancerRule.create( @@ -2132,7 +2132,6 @@ class TestLoadBalancingRule(cloudstackTestCase): return -@unittest.skip("Questions - How to verify after changing public/private ports?") class TestDeleteCreateLBRule(cloudstackTestCase): @classmethod @@ -2177,7 +2176,7 @@ class TestDeleteCreateLBRule(cloudstackTestCase): cls.api_client, cls.services["network"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) @@ -2187,7 +2186,7 @@ class TestDeleteCreateLBRule(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -2195,7 +2194,7 @@ class TestDeleteCreateLBRule(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls._cleanup = [ @@ -2316,7 +2315,7 @@ class TestVmWithLb(cloudstackTestCase): cls.api_client, cls.services["network"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) @@ -2326,7 +2325,7 @@ class TestVmWithLb(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -2334,7 +2333,7 @@ class TestVmWithLb(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -2342,7 +2341,7 @@ class TestVmWithLb(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls.lb_rule_1 = LoadBalancerRule.create( @@ -2356,7 +2355,7 @@ class TestVmWithLb(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls.lb_rule_2 = LoadBalancerRule.create( diff --git a/test/integration/component/test_netscaler_lb_algo.py b/test/integration/component/test_netscaler_lb_algo.py index 4a2d1fe4c2b..99a537d78e3 100644 --- a/test/integration/component/test_netscaler_lb_algo.py +++ b/test/integration/component/test_netscaler_lb_algo.py @@ -212,7 +212,7 @@ class TestLbWithRoundRobin(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -225,7 +225,7 @@ class TestLbWithRoundRobin(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -259,7 +259,7 @@ class TestLbWithRoundRobin(cloudstackTestCase): self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) self.debug("Associated %s with network %s" % ( @@ -425,7 +425,7 @@ class TestLbWithLeastConn(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -438,7 +438,7 @@ class TestLbWithLeastConn(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -472,14 +472,14 @@ class TestLbWithLeastConn(cloudstackTestCase): self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) ip_with_lb_rule = PublicIPAddress.create( self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) self.debug("Associated %s with network %s" % ( @@ -644,7 +644,7 @@ class TestLbWithSourceIp(cloudstackTestCase): self.apiclient, self.services["network"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) @@ -657,7 +657,7 @@ class TestLbWithSourceIp(cloudstackTestCase): self.apiclient, self.services["virtual_machine"], accountid=self.account.name, - domainid=self.account.account.domainid, + domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) @@ -691,7 +691,7 @@ class TestLbWithSourceIp(cloudstackTestCase): self.apiclient, accountid=self.account.name, zoneid=self.zone.id, - domainid=self.account.account.domainid, + domainid=self.account.domainid, networkid=self.network.id ) self.debug("Associated %s with network %s" % ( @@ -791,7 +791,7 @@ class TestLbAlgoRrLc(cloudstackTestCase): cls.api_client, cls.services["network"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) @@ -808,7 +808,7 @@ class TestLbAlgoRrLc(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -816,7 +816,7 @@ class TestLbAlgoRrLc(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls._cleanup = [ @@ -1003,7 +1003,7 @@ class TestLbAlgoLcRr(cloudstackTestCase): cls.api_client, cls.services["network"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) @@ -1020,7 +1020,7 @@ class TestLbAlgoLcRr(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -1028,7 +1028,7 @@ class TestLbAlgoLcRr(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls._cleanup = [ @@ -1212,7 +1212,7 @@ class TestLbAlgoRrSb(cloudstackTestCase): cls.api_client, cls.services["network"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) @@ -1229,7 +1229,7 @@ class TestLbAlgoRrSb(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -1238,7 +1238,7 @@ class TestLbAlgoRrSb(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls._cleanup = [ @@ -1425,7 +1425,7 @@ class TestLbAlgoSbRr(cloudstackTestCase): cls.api_client, cls.services["network"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) @@ -1442,7 +1442,7 @@ class TestLbAlgoSbRr(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -1451,7 +1451,7 @@ class TestLbAlgoSbRr(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls._cleanup = [ @@ -1639,7 +1639,7 @@ class TestLbAlgoSbLc(cloudstackTestCase): cls.api_client, cls.services["network"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) @@ -1656,7 +1656,7 @@ class TestLbAlgoSbLc(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -1665,7 +1665,7 @@ class TestLbAlgoSbLc(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls._cleanup = [ @@ -1853,7 +1853,7 @@ class TestLbAlgoLcSb(cloudstackTestCase): cls.api_client, cls.services["network"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) @@ -1870,7 +1870,7 @@ class TestLbAlgoLcSb(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -1878,7 +1878,7 @@ class TestLbAlgoLcSb(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls._cleanup = [ diff --git a/test/integration/component/test_netscaler_lb_sticky.py b/test/integration/component/test_netscaler_lb_sticky.py index 7f391d0f79a..5c95fb8ff57 100644 --- a/test/integration/component/test_netscaler_lb_sticky.py +++ b/test/integration/component/test_netscaler_lb_sticky.py @@ -156,7 +156,7 @@ class TestLbStickyPolicy(cloudstackTestCase): cls.api_client, cls.services["network"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkofferingid=cls.network_offering.id, zoneid=cls.zone.id ) @@ -166,7 +166,7 @@ class TestLbStickyPolicy(cloudstackTestCase): cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, networkids=[str(cls.network.id)] ) @@ -174,7 +174,7 @@ class TestLbStickyPolicy(cloudstackTestCase): cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, - domainid=cls.account.account.domainid, + domainid=cls.account.domainid, networkid=cls.network.id ) cls._cleanup = [ diff --git a/test/integration/component/test_network_offering.py b/test/integration/component/test_network_offering.py index b51d0e4c8cb..a3e87f6d61e 100644 --- a/test/integration/component/test_network_offering.py +++ b/test/integration/component/test_network_offering.py @@ -1816,7 +1816,6 @@ class TestNetworkUpgrade(cloudstackTestCase): return -@unittest.skip("Skipped since shared network requires StartIp/endIp/gateway/netmask") class TestSharedNetworkWithoutIp(cloudstackTestCase): @classmethod diff --git a/test/integration/component/test_project_configs.py b/test/integration/component/test_project_configs.py index 1eef123b2ee..641649702e1 100644 --- a/test/integration/component/test_project_configs.py +++ b/test/integration/component/test_project_configs.py @@ -343,7 +343,6 @@ class TestProjectCreationNegative(cloudstackTestCase): @attr(configuration = "allow.user.create.projects") @attr(tags = ["advanced", "basic", "sg", "eip", "advancedns", "simulator"]) - @unittest.skip("Known bug-able to create project as a domain user") def test_user_project_creation(self): """Test create project as a domain admin and domain user """ @@ -1299,7 +1298,6 @@ class TestProjectInviteTimeout(cloudstackTestCase): ) return - @unittest.skip("Requires SMPT configs") def test_09_invite_to_project_by_email(self): """Test invite user to project by email""" diff --git a/test/integration/component/test_project_limits.py b/test/integration/component/test_project_limits.py index af99717ad16..6e3f41d6465 100644 --- a/test/integration/component/test_project_limits.py +++ b/test/integration/component/test_project_limits.py @@ -328,7 +328,6 @@ class TestProjectLimits(cloudstackTestCase): return @attr(tags=["advanced", "basic", "sg", "eip", "advancedns", "simulator"]) - @unittest.skip("No provision for updating resource limits from account through API") def test_02_project_limits_normal_user(self): """ Test project limits """ diff --git a/test/integration/component/test_projects.py b/test/integration/component/test_projects.py index e1975cf5295..5f37f96804e 100644 --- a/test/integration/component/test_projects.py +++ b/test/integration/component/test_projects.py @@ -559,7 +559,6 @@ class TestDeleteAccountWithProject(cloudstackTestCase): return -@unittest.skip("Deleting domain doesn't cleanup account") class TestDeleteDomainWithProject(cloudstackTestCase): @classmethod diff --git a/test/integration/component/test_shared_networks.py b/test/integration/component/test_shared_networks.py index 5f964190356..cb2b55f705a 100644 --- a/test/integration/component/test_shared_networks.py +++ b/test/integration/component/test_shared_networks.py @@ -270,7 +270,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.account.account.id, + id=self.account.id, listall=True ) self.assertEqual( @@ -406,7 +406,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.account.account.id, + id=self.account.id, listall=True ) self.assertEqual( @@ -495,7 +495,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.account.account.id, + id=self.account.id, listall=True ) self.assertEqual( @@ -597,7 +597,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, listall=True ) self.assertEqual( @@ -631,7 +631,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.user_account.account.id, + id=self.user_account.id, listall=True ) self.assertEqual( @@ -807,7 +807,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.user_account.name, - domainid=self.user_account.account.domainid, + domainid=self.user_account.domainid, serviceofferingid=self.service_offering.id, networkids=self.network.id ) @@ -880,7 +880,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, listall=True ) self.assertEqual( @@ -914,7 +914,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.user_account.account.id, + id=self.user_account.id, listall=True ) self.assertEqual( @@ -1027,7 +1027,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["network"], accountid=self.user_account.name, - domainid=self.user_account.account.domainid, + domainid=self.user_account.domainid, networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id ) @@ -1061,7 +1061,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkids=self.network.id, serviceofferingid=self.service_offering.id ) @@ -1073,7 +1073,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.user_account.name, - domainid=self.user_account.account.domainid, + domainid=self.user_account.domainid, networkids=self.network.id, serviceofferingid=self.service_offering.id ) @@ -1146,7 +1146,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, listall=True ) self.assertEqual( @@ -1165,7 +1165,7 @@ class TestSharedNetworks(cloudstackTestCase): "The admin account created is not enabled." ) - self.debug("Admin type account created: %s" % self.admin_account.account.id) + self.debug("Admin type account created: %s" % self.admin_account.id) #create domain self.dom_domain = Domain.create( @@ -1206,7 +1206,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.domain_admin_account.account.id, + id=self.domain_admin_account.id, listall=True ) self.assertEqual( @@ -1225,7 +1225,7 @@ class TestSharedNetworks(cloudstackTestCase): "The domain admin account created is not enabled." ) - self.debug("Domain admin account created: %s" % self.domain_admin_account.account.id) + self.debug("Domain admin account created: %s" % self.domain_admin_account.id) #Create an user account self.domain_user_account = Account.create( @@ -1240,7 +1240,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.domain_user_account.account.id, + id=self.domain_user_account.id, listall=True ) self.assertEqual( @@ -1259,7 +1259,7 @@ class TestSharedNetworks(cloudstackTestCase): "The domain user account created is not enabled." ) - self.debug("Domain user account created: %s" % self.domain_user_account.account.id) + self.debug("Domain user account created: %s" % self.domain_user_account.id) #Verify that there should be at least one physical network present in zone. list_physical_networks_response = PhysicalNetwork.list( @@ -1388,7 +1388,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkids=self.network.id, serviceofferingid=self.service_offering.id ) @@ -1400,7 +1400,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.domain_user_account.name, - domainid=self.domain_user_account.account.domainid, + domainid=self.domain_user_account.domainid, networkids=self.network.id, serviceofferingid=self.service_offering.id ) @@ -1428,7 +1428,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.domain_admin_account.name, - domainid=self.domain_admin_account.account.domainid, + domainid=self.domain_admin_account.domainid, networkids=self.network.id, serviceofferingid=self.service_offering.id ) @@ -1500,7 +1500,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, listall=True ) self.assertEqual( @@ -1519,7 +1519,7 @@ class TestSharedNetworks(cloudstackTestCase): "The admin account created is not enabled." ) - self.debug("Admin account created: %s" % self.admin_account.account.id) + self.debug("Admin account created: %s" % self.admin_account.id) self.services["project"]["name"] = "proj-SADJKS" self.services["project"]["displaytext"] = "proj-SADJKS" @@ -1528,7 +1528,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["project"], account=self.admin_account.name, - domainid=self.admin_account.account.domainid + domainid=self.admin_account.domainid ) self.cleanup_projects.append(self.project1) @@ -1558,7 +1558,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["project"], account=self.admin_account.name, - domainid=self.admin_account.account.domainid + domainid=self.admin_account.domainid ) self.cleanup_projects.append(self.project2) @@ -1674,7 +1674,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["network"], projectid=self.project1.id, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id ) @@ -1709,7 +1709,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkids=self.network.id, projectid=self.project2.id, serviceofferingid=self.service_offering.id @@ -1722,7 +1722,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkids=self.network.id, projectid=self.project1.id, serviceofferingid=self.service_offering.id @@ -1784,7 +1784,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, listall=True ) self.assertEqual( @@ -1803,7 +1803,7 @@ class TestSharedNetworks(cloudstackTestCase): "The admin account created is not enabled." ) - self.debug("Domain admin account created: %s" % self.admin_account.account.id) + self.debug("Domain admin account created: %s" % self.admin_account.id) #Verify that there should be at least one physical network present in zone. list_physical_networks_response = PhysicalNetwork.list( @@ -1944,7 +1944,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, listall=True ) self.assertEqual( @@ -1963,7 +1963,7 @@ class TestSharedNetworks(cloudstackTestCase): "The admin account created is not enabled." ) - self.debug("Admin account created: %s" % self.admin_account.account.id) + self.debug("Admin account created: %s" % self.admin_account.id) #Verify that there should be at least one physical network present in zone. list_physical_networks_response = PhysicalNetwork.list( @@ -2129,7 +2129,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, listall=True ) self.assertEqual( @@ -2148,7 +2148,7 @@ class TestSharedNetworks(cloudstackTestCase): "The admin account created is not enabled." ) - self.debug("Admin account created: %s" % self.admin_account.account.id) + self.debug("Admin account created: %s" % self.admin_account.id) #Verify that there should be at least one physical network present in zone. list_physical_networks_response = PhysicalNetwork.list( @@ -2309,7 +2309,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkids=self.network.id, serviceofferingid=self.service_offering.id ) @@ -2337,7 +2337,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkids=self.network1.id, serviceofferingid=self.service_offering.id ) @@ -2392,7 +2392,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, liistall=True ) self.assertEqual( @@ -2540,7 +2540,7 @@ class TestSharedNetworks(cloudstackTestCase): self.shared_network = Network.create( self.api_client, self.services["network"], - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id ) @@ -2573,7 +2573,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["isolated_network"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkofferingid=self.isolated_network_offering.id, zoneid=self.zone.id ) @@ -2601,7 +2601,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkids=self.shared_network.id, serviceofferingid=self.service_offering.id ) @@ -2628,7 +2628,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["virtual_machine"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkids=self.isolated_network.id, serviceofferingid=self.service_offering.id ) @@ -2657,7 +2657,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, accountid=self.admin_account.name, zoneid=self.zone.id, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkid=self.isolated_network.id ) @@ -2730,7 +2730,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, listall=True ) self.assertEqual( @@ -2749,7 +2749,7 @@ class TestSharedNetworks(cloudstackTestCase): "The admin account created is not enabled." ) - self.debug("Admin type account created: %s" % self.admin_account.account.id) + self.debug("Admin type account created: %s" % self.admin_account.id) #Verify that there should be at least one physical network present in zone. list_physical_networks_response = PhysicalNetwork.list( @@ -2845,7 +2845,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["network"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id ) @@ -2875,7 +2875,7 @@ class TestSharedNetworks(cloudstackTestCase): #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, - id=self.admin_account.account.id, + id=self.admin_account.id, listall=True ) self.assertEqual( @@ -2894,7 +2894,7 @@ class TestSharedNetworks(cloudstackTestCase): "The admin account created is not enabled." ) - self.debug("Admin type account created: %s" % self.admin_account.account.id) + self.debug("Admin type account created: %s" % self.admin_account.id) #Verify that there should be at least one physical network present in zone. list_physical_networks_response = PhysicalNetwork.list( @@ -2990,7 +2990,7 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["network"], accountid=self.admin_account.name, - domainid=self.admin_account.account.domainid, + domainid=self.admin_account.domainid, networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id ) diff --git a/test/integration/component/test_tags.py b/test/integration/component/test_tags.py index 992ca1daf58..52df6da5554 100644 --- a/test/integration/component/test_tags.py +++ b/test/integration/component/test_tags.py @@ -690,7 +690,6 @@ class TestResourceTags(cloudstackTestCase): return @attr(tags=["advanced"]) - @unittest.skip("Not supported in 3.0.5") def test_04_vpn_tag(self): """ Test Create tag on vpn and remove the vpn """ @@ -1421,7 +1420,6 @@ class TestResourceTags(cloudstackTestCase): return @attr(tags=["basic", "sg"]) - @unittest.skip("skip") def test_11_migrate_tagged_vm_del(self): """ Test migration of a tagged vm and delete the tag """ diff --git a/test/integration/component/test_templates.py b/test/integration/component/test_templates.py index 65beabfc98f..e4599d41981 100644 --- a/test/integration/component/test_templates.py +++ b/test/integration/component/test_templates.py @@ -99,7 +99,6 @@ class Services: } -@unittest.skip("Open questions") class TestCreateTemplate(cloudstackTestCase): def setUp(self): diff --git a/test/integration/component/test_vm_passwdenabled.py b/test/integration/component/test_vm_passwdenabled.py index e22a1a0a75a..ebe32c8d75c 100644 --- a/test/integration/component/test_vm_passwdenabled.py +++ b/test/integration/component/test_vm_passwdenabled.py @@ -69,7 +69,6 @@ class Services: # CentOS 5.3 (64-bit) } -@unittest.skip("Additional test") class TestVMPasswordEnabled(cloudstackTestCase): @classmethod diff --git a/test/integration/component/test_vpc.py b/test/integration/component/test_vpc.py index 7dbe7c4bf91..3fc0cc5a7e2 100644 --- a/test/integration/component/test_vpc.py +++ b/test/integration/component/test_vpc.py @@ -2474,7 +2474,6 @@ class TestVPC(cloudstackTestCase): "Updation of VPC display text failed.") -@unittest.skip("Skip") class TestVPCHostMaintenance(cloudstackTestCase): @classmethod diff --git a/test/integration/component/test_vpc_network.py b/test/integration/component/test_vpc_network.py index c0c393c4ca1..a997f43a612 100644 --- a/test/integration/component/test_vpc_network.py +++ b/test/integration/component/test_vpc_network.py @@ -35,139 +35,144 @@ class Services: def __init__(self): self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 128, - }, - "network_offering": { - "name": 'VPC Network offering', - "displaytext": 'VPC Network off', - "guestiptype": 'Isolated', - "supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL', - "traffictype": 'GUEST', - "availability": 'Optional', - "useVpc": 'on', - "serviceProviderList": { - "Vpn": 'VpcVirtualRouter', - "Dhcp": 'VpcVirtualRouter', - "Dns": 'VpcVirtualRouter', - "SourceNat": 'VpcVirtualRouter', - "PortForwarding": 'VpcVirtualRouter', - "Lb": 'VpcVirtualRouter', - "UserData": 'VpcVirtualRouter', - "StaticNat": 'VpcVirtualRouter', - "NetworkACL": 'VpcVirtualRouter' - }, - "servicecapabilitylist": { - }, - }, - "network_off_netscaler": { - "name": 'Network offering-netscaler', - "displaytext": 'Network offering-netscaler', - "guestiptype": 'Isolated', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat', - "traffictype": 'GUEST', - "availability": 'Optional', - "useVpc": 'on', - "serviceProviderList": { - "Dhcp": 'VpcVirtualRouter', - "Dns": 'VpcVirtualRouter', - "SourceNat": 'VpcVirtualRouter', - "PortForwarding": 'VpcVirtualRouter', - "Vpn": 'VpcVirtualRouter', - "Lb": 'Netscaler', - "UserData": 'VpcVirtualRouter', - "StaticNat": 'VpcVirtualRouter', - }, - }, - "network_off_shared": { - "name": 'Shared Network offering', - "displaytext": 'Shared Network offering', - "guestiptype": 'Shared', - "traffictype": 'GUEST', - "availability": 'Optional', - "useVpc": 'on', - "specifyIpRanges": True, - "specifyVlan": True - }, - "vpc_offering": { - "name": 'VPC off', - "displaytext": 'VPC off', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat', - }, - "vpc": { - "name": "TestVPC", - "displaytext": "TestVPC", - "cidr": '10.0.0.1/24' - }, - "network": { - "name": "Test Network", - "displaytext": "Test Network", - "netmask": '255.255.255.0' - }, - "lbrule": { - "name": "SSH", - "alg": "leastconn", - # Algorithm used for load balancing - "privateport": 22, - "publicport": 2222, - "openfirewall": False, - "startport": 22, - "endport": 2222, - "protocol": "TCP", - "cidrlist": '0.0.0.0/0', - }, - "natrule": { - "privateport": 22, - "publicport": 22, - "startport": 22, - "endport": 22, - "protocol": "TCP", - "cidrlist": '0.0.0.0/0', - }, - "fw_rule": { - "startport": 1, - "endport": 6000, - "cidr": '0.0.0.0/0', - # Any network (For creating FW rule) - "protocol": "TCP" - }, - "http_rule": { - "startport": 80, - "endport": 80, - "cidrlist": '0.0.0.0/0', - "protocol": "ICMP" - }, - "virtual_machine": { - "displayname": "Test VM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - # Hypervisor type should be same as - # hypervisor type of cluster - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "ostype": 'CentOS 5.3 (64-bit)', - # Cent OS 5.3 (64 bit) - "sleep": 60, - "timeout": 10, - "mode": 'advanced' - } + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended for unique + # username + "password": "password", + }, + "service_offering": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 128, + }, + "network_offering": { + "name": 'VPC Network offering', + "displaytext": 'VPC Network off', + "guestiptype": 'Isolated', + "supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL', + "traffictype": 'GUEST', + "availability": 'Optional', + "useVpc": 'on', + "serviceProviderList": { + "Vpn": 'VpcVirtualRouter', + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "PortForwarding": 'VpcVirtualRouter', + "Lb": 'VpcVirtualRouter', + "UserData": 'VpcVirtualRouter', + "StaticNat": 'VpcVirtualRouter', + "NetworkACL": 'VpcVirtualRouter' + }, + "serviceCapabilityList": { + "SourceNat": {"SupportedSourceNatTypes": "peraccount"}, + "Lb": {"lbSchemes": "public", "SupportedLbIsolation": "dedicated"} + }, + }, + "network_off_netscaler": { + "name": 'Network offering-netscaler', + "displaytext": 'Network offering-netscaler', + "guestiptype": 'Isolated', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat', + "traffictype": 'GUEST', + "availability": 'Optional', + "useVpc": 'on', + "serviceProviderList": { + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "PortForwarding": 'VpcVirtualRouter', + "Vpn": 'VpcVirtualRouter', + "Lb": 'Netscaler', + "UserData": 'VpcVirtualRouter', + "StaticNat": 'VpcVirtualRouter', + }, + "serviceCapabilityList": { + "SourceNat": {"SupportedSourceNatTypes": "peraccount"}, + "Lb": {"lbSchemes": "public", "SupportedLbIsolation": "dedicated"} + }, + }, + "network_off_shared": { + "name": 'Shared Network offering', + "displaytext": 'Shared Network offering', + "guestiptype": 'Shared', + "traffictype": 'GUEST', + "availability": 'Optional', + "useVpc": 'on', + "specifyIpRanges": True, + "specifyVlan": True + }, + "vpc_offering": { + "name": 'VPC off', + "displaytext": 'VPC off', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat', + }, + "vpc": { + "name": "TestVPC", + "displaytext": "TestVPC", + "cidr": '10.0.0.1/24' + }, + "network": { + "name": "Test Network", + "displaytext": "Test Network", + "netmask": '255.255.255.0' + }, + "lbrule": { + "name": "SSH", + "alg": "leastconn", + # Algorithm used for load balancing + "privateport": 22, + "publicport": 2222, + "openfirewall": False, + "startport": 22, + "endport": 2222, + "protocol": "TCP", + "cidrlist": '0.0.0.0/0', + }, + "natrule": { + "privateport": 22, + "publicport": 22, + "startport": 22, + "endport": 22, + "protocol": "TCP", + "cidrlist": '0.0.0.0/0', + }, + "fw_rule": { + "startport": 1, + "endport": 6000, + "cidr": '0.0.0.0/0', + # Any network (For creating FW rule) + "protocol": "TCP" + }, + "http_rule": { + "startport": 80, + "endport": 80, + "cidrlist": '0.0.0.0/0', + "protocol": "ICMP" + }, + "virtual_machine": { + "displayname": "Test VM", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + # Hypervisor type should be same as + # hypervisor type of cluster + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "ostype": 'CentOS 5.3 (64-bit)', + # Cent OS 5.3 (64 bit) + "sleep": 60, + "timeout": 10, + } class TestVPCNetwork(cloudstackTestCase): @@ -459,7 +464,6 @@ class TestVPCNetwork(cloudstackTestCase): ) return - @unittest.skip("Skip - Requires netscaler setup") @attr(tags=["netscaler", "intervlan"]) def test_03_create_network_netscaler(self): """ Test create network using netscaler for LB @@ -707,7 +711,6 @@ class TestVPCNetwork(cloudstackTestCase): return @attr(tags=["advanced", "intervlan"]) - @unittest.skip("Skipping - able to create network with RvR") def test_06_create_network_with_rvr(self): """ Test create network with eredundant router capability """ @@ -1038,7 +1041,6 @@ class TestVPCNetwork(cloudstackTestCase): "Network creation failed as VPC support nw with conserve mode OFF") return -@unittest.skip("tested") class TestVPCNetworkRanges(cloudstackTestCase): @classmethod @@ -1670,7 +1672,6 @@ class TestVPCNetworkUpgrade(cloudstackTestCase): return @attr(tags=["advanced", "intervlan"]) - @unittest.skip("Error while NW upgrade - Failed to implement network (with specified id) elements and resources as a part of network update") def test_01_network_services_upgrade(self): """ Test update Network that is part of a VPC to a network offering that has more services. diff --git a/test/integration/component/test_vpc_network_pfrules.py b/test/integration/component/test_vpc_network_pfrules.py index c0c2b86426c..92b04ad3f21 100644 --- a/test/integration/component/test_vpc_network_pfrules.py +++ b/test/integration/component/test_vpc_network_pfrules.py @@ -44,138 +44,139 @@ from marvin.integration.lib.common import (get_domain, class Services: """Test VPC network services - Port Forwarding Rules Test Data Class. """ + def __init__(self): self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "host1":None, - "host2":None, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 1000, - "memory": 512, - }, - "network_offering": { - "name": 'VPC Network offering', - "displaytext": 'VPC Network off', - "guestiptype": 'Isolated', - "supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL', - "traffictype": 'GUEST', - "availability": 'Optional', - "useVpc": 'on', - "serviceProviderList": { - "Vpn": 'VpcVirtualRouter', - "Dhcp": 'VpcVirtualRouter', - "Dns": 'VpcVirtualRouter', - "SourceNat": 'VpcVirtualRouter', - "PortForwarding": 'VpcVirtualRouter', - "Lb": 'VpcVirtualRouter', - "UserData": 'VpcVirtualRouter', - "StaticNat": 'VpcVirtualRouter', - "NetworkACL": 'VpcVirtualRouter' - }, - "servicecapabilitylist": { - }, - }, - "network_offering_no_lb": { - "name": 'VPC Network offering', - "displaytext": 'VPC Network off', - "guestiptype": 'Isolated', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,UserData,StaticNat,NetworkACL', - "traffictype": 'GUEST', - "availability": 'Optional', - "useVpc": 'on', - "serviceProviderList": { - "Dhcp": 'VpcVirtualRouter', - "Dns": 'VpcVirtualRouter', - "SourceNat": 'VpcVirtualRouter', - "PortForwarding": 'VpcVirtualRouter', - "UserData": 'VpcVirtualRouter', - "StaticNat": 'VpcVirtualRouter', - "NetworkACL": 'VpcVirtualRouter' - }, - }, - "vpc_offering": { - "name": 'VPC off', - "displaytext": 'VPC off', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat', - }, - "vpc": { - "name": "TestVPC", - "displaytext": "TestVPC", - "cidr": '10.0.0.1/24' - }, - "network": { - "name": "Test Network", - "displaytext": "Test Network", - "netmask": '255.255.255.0' - }, - "lbrule": { - "name": "SSH", - "alg": "leastconn", - # Algorithm used for load balancing - "privateport": 22, - "publicport": 2222, - "openfirewall": False, - "startport": 22, - "endport": 2222, - "protocol": "TCP", - "cidrlist": '0.0.0.0/0', - }, - "lbrule_http": { - "name": "HTTP", - "alg": "leastconn", - # Algorithm used for load balancing - "privateport": 80, - "publicport": 8888, - "openfirewall": False, - "startport": 80, - "endport": 8888, - "protocol": "TCP", - "cidrlist": '0.0.0.0/0', - }, - "natrule": { - "privateport": 22, - "publicport": 22, - "startport": 22, - "endport": 22, - "protocol": "TCP", - "cidrlist": '0.0.0.0/0', - }, - "http_rule": { - "privateport": 80, - "publicport": 80, - "startport": 80, - "endport": 80, - "cidrlist": '0.0.0.0/0', - "protocol": "TCP" - }, - "virtual_machine": { - "displayname": "Test VM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - # Hypervisor type should be same as - # hypervisor type of cluster - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "ostype": 'CentOS 5.3 (64-bit)', - "sleep": 60, - "timeout": 10, - "mode": 'advanced' - } + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended for unique + # username + "password": "password", + }, + "host1": None, + "host2": None, + "service_offering": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 1000, + "memory": 512, + }, + "network_offering": { + "name": 'VPC Network offering', + "displaytext": 'VPC Network off', + "guestiptype": 'Isolated', + "supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL', + "traffictype": 'GUEST', + "availability": 'Optional', + "useVpc": 'on', + "serviceProviderList": { + "Vpn": 'VpcVirtualRouter', + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "PortForwarding": 'VpcVirtualRouter', + "Lb": 'VpcVirtualRouter', + "UserData": 'VpcVirtualRouter', + "StaticNat": 'VpcVirtualRouter', + "NetworkACL": 'VpcVirtualRouter' + }, + "servicecapabilitylist": { + }, + }, + "network_offering_no_lb": { + "name": 'VPC Network offering', + "displaytext": 'VPC Network off', + "guestiptype": 'Isolated', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,UserData,StaticNat,NetworkACL', + "traffictype": 'GUEST', + "availability": 'Optional', + "useVpc": 'on', + "serviceProviderList": { + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "PortForwarding": 'VpcVirtualRouter', + "UserData": 'VpcVirtualRouter', + "StaticNat": 'VpcVirtualRouter', + "NetworkACL": 'VpcVirtualRouter' + }, + }, + "vpc_offering": { + "name": 'VPC off', + "displaytext": 'VPC off', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat', + }, + "vpc": { + "name": "TestVPC", + "displaytext": "TestVPC", + "cidr": '10.0.0.1/24' + }, + "network": { + "name": "Test Network", + "displaytext": "Test Network", + "netmask": '255.255.255.0' + }, + "lbrule": { + "name": "SSH", + "alg": "leastconn", + # Algorithm used for load balancing + "privateport": 22, + "publicport": 2222, + "openfirewall": False, + "startport": 22, + "endport": 2222, + "protocol": "TCP", + "cidrlist": '0.0.0.0/0', + }, + "lbrule_http": { + "name": "HTTP", + "alg": "leastconn", + # Algorithm used for load balancing + "privateport": 80, + "publicport": 8888, + "openfirewall": False, + "startport": 80, + "endport": 8888, + "protocol": "TCP", + "cidrlist": '0.0.0.0/0', + }, + "natrule": { + "privateport": 22, + "publicport": 22, + "startport": 22, + "endport": 22, + "protocol": "TCP", + "cidrlist": '0.0.0.0/0', + }, + "http_rule": { + "privateport": 80, + "publicport": 80, + "startport": 80, + "endport": 80, + "cidrlist": '0.0.0.0/0', + "protocol": "TCP" + }, + "virtual_machine": { + "displayname": "Test VM", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + # Hypervisor type should be same as + # hypervisor type of cluster + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "ostype": 'CentOS 5.3 (64-bit)', + "sleep": 60, + "timeout": 10, + "mode": 'advanced' + } class TestVPCNetworkPFRules(cloudstackTestCase): @@ -251,15 +252,12 @@ class TestVPCNetworkPFRules(cloudstackTestCase): try: #Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self._cleanup) - wait_for_cleanup(self.apiclient, [ - "network.gc.interval", - "network.gc.wait"]) except Exception as e: self.debug("Warning: Exception during cleanup : %s" % e) #raise Exception("Warning: Exception during cleanup : %s" % e) return - def get_Router_For_VPC(self): + def get_vpcrouter(self): routers = list_routers(self.apiclient, account=self.account.name, domainid=self.account.domainid, @@ -276,8 +274,8 @@ class TestVPCNetworkPFRules(cloudstackTestCase): return router - def stop_VPC_VRouter(self): - router = self.get_Router_For_VPC() + def stop_vpcrouter(self): + router = self.get_vpcrouter() self.debug("Stopping router ID: %s" % router.id) cmd = stopRouter.stopRouterCmd() cmd.id = router.id @@ -298,7 +296,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): ) return router - def start_VPC_VRouter(self, router): + def start_vpcrouter(self, router): # Start the VPC Router cmd = startRouter.startRouterCmd() cmd.id = router.id @@ -348,7 +346,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): else: self.debug("Failed to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) - def create_StaticNatRule_For_VM(self, vm, public_ip, network): + def create_staticnat(self, vm, public_ip, network): self.debug("Enabling static NAT for IP: %s" % public_ip.ipaddress.ipaddress) try: @@ -364,7 +362,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): self.fail("Failed to enable static NAT on IP: %s - %s" % ( public_ip.ipaddress.ipaddress, e)) - def create_NatRule_For_VM(self, vm, public_ip, network, services=None): + def create_natrule(self, vm, public_ip, network, services=None): self.debug("Creatinng NAT rule in network for vm with public IP") if not services: services = self.services["natrule"] @@ -386,7 +384,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): self.debug('nwacl_nat=%s' % nwacl_nat.__dict__) return nat_rule - def acquire_Public_IP(self, network): + def acquire_publicip(self, network): self.debug("Associating public IP for network: %s" % network.name) public_ip = PublicIPAddress.create(self.apiclient, accountid=self.account.name, @@ -400,7 +398,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): )) return public_ip - def create_VPC(self, cidr='10.1.2.1/16'): + def create_vpc(self, cidr='10.1.2.1/16'): self.debug("Creating a VPC offering..") self.services["vpc_offering"]["name"] = self.services["vpc_offering"]["name"] + str(cidr) vpc_off = VpcOffering.create( @@ -424,7 +422,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): ) return vpc - def create_Network(self, net_offerring, gateway='10.1.1.1',vpc=None): + def create_network(self, net_offerring, gateway='10.1.1.1',vpc=None): try: self.debug('Create NetworkOffering') net_offerring["name"] = "NET_OFF-" + str(gateway) @@ -453,7 +451,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): except: self.fail('Unable to create a Network with offering=%s' % net_offerring) - def create_VM_in_Network(self, network, host_id=None): + def deployvm_in_network(self, network, host_id=None): try: self.debug('Creating VM in network=%s' % network.name) vm = VirtualMachine.create( @@ -471,7 +469,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): except: self.fail('Unable to create VM in a Network=%s' % network.name) - def create_LB_Rule(self, public_ip, network, vmarray, services=None): + def create_lbrule(self, public_ip, network, vmarray, services=None): self.debug("Creating LB rule for IP address: %s" % public_ip.ipaddress.ipaddress) objservices = None @@ -493,7 +491,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): lb_rule.assign(self.apiclient, vmarray) return lb_rule - def create_egress_Internet_Rule(self, network): + def open_egress_to_world(self, network): self.debug("Adding Egress rules to network %s and %s to allow access to internet" % (network.name,self.services["http_rule"])) nwacl_internet_1 = NetworkACL.create( self.apiclient, @@ -507,8 +505,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): @attr(tags=["advanced", "intervlan"]) def test_01_network_services_VPC_StopCreatePF(self): - """ Test case no 204 : Create PF rules for a single virtual network of a VPC, - using a new Public IP Address available with the VPC when Virtual Router is in Stopped State + """ Test : Create VPC PF rules on acquired public ip when VpcVirtualRouter is stopped """ # Validate the following @@ -521,20 +518,19 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # 7. Start VPC Virtual Router. # 8. Successfully ssh into the Guest VM using the PF rule - network_1 = self.create_Network(self.services["network_offering"]) - vm_1 = self.create_VM_in_Network(network_1) - public_ip_1 = self.acquire_Public_IP(network_1) - router = self.stop_VPC_VRouter() - self.create_NatRule_For_VM( vm_1, public_ip_1, network_1) - self.start_VPC_VRouter(router) + network_1 = self.create_network(self.services["network_offering"]) + vm_1 = self.deployvm_in_network(network_1) + public_ip_1 = self.acquire_publicip(network_1) + router = self.stop_vpcrouter() + self.create_natrule( vm_1, public_ip_1, network_1) + self.start_vpcrouter(router) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) return @attr(tags=["advanced", "intervlan"]) def test_02_network_services_VPC_CreatePF(self): - """ Test case no 190 : Create PF rules for a single virtual network of a VPC using a - new Public IP Address available with the VPC when Virtual Router is in Running State + """ Test Create VPC PF rules on acquired public ip when VpcVirtualRouter is Running """ # Validate the following @@ -545,17 +541,16 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # 5. Use the Create PF rule for vm in network1. # 6. Successfully ssh into the Guest VM using the PF rule - network_1 = self.create_Network(self.services["network_offering"]) - vm_1 = self.create_VM_in_Network(network_1) - public_ip_1 = self.acquire_Public_IP(network_1) - self.create_NatRule_For_VM( vm_1, public_ip_1, network_1) + network_1 = self.create_network(self.services["network_offering"]) + vm_1 = self.deployvm_in_network(network_1) + public_ip_1 = self.acquire_publicip(network_1) + self.create_natrule( vm_1, public_ip_1, network_1) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) return @attr(tags=["advanced", "intervlan"]) def test_03_network_services_VPC_StopCreateMultiplePF(self): - """ Test case no 205 : Create PF rules for a two/multiple virtual networks of a VPC using - a new Public IP Address available with the VPC when Virtual Router is in Stopped State + """ Test Create multiple VPC PF rules on acquired public ip in diff't networks when VpcVirtualRouter is stopped """ # Validate the following @@ -571,24 +566,23 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # 10. Start VPC Virtual Router. # 11. Successfully ssh into the Guest VM1 and VM2 using the PF rule - network_1 = self.create_Network(self.services["network_offering_no_lb"]) - network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') - vm_1 = self.create_VM_in_Network(network_1) - vm_2 = self.create_VM_in_Network(network_2) - public_ip_1 = self.acquire_Public_IP(network_1) - public_ip_2 = self.acquire_Public_IP(network_2) - router = self.stop_VPC_VRouter() - self.create_NatRule_For_VM(vm_1, public_ip_1, network_1) - self.create_NatRule_For_VM(vm_2, public_ip_2, network_2) - self.start_VPC_VRouter(router) + network_1 = self.create_network(self.services["network_offering_no_lb"]) + network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1') + vm_1 = self.deployvm_in_network(network_1) + vm_2 = self.deployvm_in_network(network_2) + public_ip_1 = self.acquire_publicip(network_1) + public_ip_2 = self.acquire_publicip(network_2) + router = self.stop_vpcrouter() + self.create_natrule(vm_1, public_ip_1, network_1) + self.create_natrule(vm_2, public_ip_2, network_2) + self.start_vpcrouter(router) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False) return @attr(tags=["advanced", "intervlan"]) def test_04_network_services_VPC_CreateMultiplePF(self): - """ Test case no 191 : Create PF rules for a two/multiple virtual networks of a VPC using a - new Public IP Address available with the VPC when Virtual Router is in Running State + """ Test Create multiple VPC PF rules on acquired public ip in diff't networks when VpcVirtualRouter is running """ # Validate the following @@ -603,24 +597,23 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # 9. Start VPC Virtual Router. # 10. Successfully ssh into the Guest VM1 and VM2 using the PF rule - network_1 = self.create_Network(self.services["network_offering"]) - network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') - vm_1 = self.create_VM_in_Network(network_1) - vm_2 = self.create_VM_in_Network(network_2) - public_ip_1 = self.acquire_Public_IP(network_1) - public_ip_2 = self.acquire_Public_IP(network_2) - router = self.stop_VPC_VRouter() - self.create_NatRule_For_VM(vm_1, public_ip_1, network_1) - self.create_NatRule_For_VM(vm_2, public_ip_2, network_2) - self.start_VPC_VRouter(router) + network_1 = self.create_network(self.services["network_offering"]) + network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1') + vm_1 = self.deployvm_in_network(network_1) + vm_2 = self.deployvm_in_network(network_2) + public_ip_1 = self.acquire_publicip(network_1) + public_ip_2 = self.acquire_publicip(network_2) + router = self.stop_vpcrouter() + self.create_natrule(vm_1, public_ip_1, network_1) + self.create_natrule(vm_2, public_ip_2, network_2) + self.start_vpcrouter(router) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False) return @attr(tags=["advanced", "intervlan"]) def test_05_network_services_VPC_StopDeletePF(self): - """ Test case no 207 : Delete few(not all) PF rules for a single virtual network of - a VPC belonging to a single Public IP Address when Virtual Router is in Stopped State + """ Test delete a PF rule in VPC when VpcVirtualRouter is Stopped """ # Validate the following @@ -636,24 +629,23 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # 10. Start VPC Virtual Router. # 11. wget a file present on http server of VM1 should fail - network_1 = self.create_Network(self.services["network_offering"]) - vm_1 = self.create_VM_in_Network(network_1) - public_ip_1 = self.acquire_Public_IP(network_1) - self.create_NatRule_For_VM(vm_1, public_ip_1, network_1) - http_rule = self.create_NatRule_For_VM(vm_1, public_ip_1, network_1, self.services["http_rule"]) + network_1 = self.create_network(self.services["network_offering"]) + vm_1 = self.deployvm_in_network(network_1) + public_ip_1 = self.acquire_publicip(network_1) + self.create_natrule(vm_1, public_ip_1, network_1) + http_rule = self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) #http_rule = self.create_egress_Internet_Rule(network_1) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) - router = self.stop_VPC_VRouter() + router = self.stop_vpcrouter() http_rule.delete() - self.start_VPC_VRouter(router) + self.start_vpcrouter(router) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) return @attr(tags=["advanced", "intervlan"]) def test_06_network_services_VPC_DeletePF(self): - """ Test case no 193 : Delete few(not all) PF rules for a single virtual network of - a VPC belonging to a single Public IP Address when Virtual Router is in Running State + """ Test delete a PF rule in VPC when VpcVirtualRouter is Running """ # Validate the following @@ -667,11 +659,11 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # 9. Delete internet PF rule # 10. wget a file present on http server of VM1 should fail - network_1 = self.create_Network(self.services["network_offering"]) - vm_1 = self.create_VM_in_Network(network_1) - public_ip_1 = self.acquire_Public_IP(network_1) - self.create_NatRule_For_VM(vm_1, public_ip_1, network_1) - http_rule=self.create_NatRule_For_VM(vm_1, public_ip_1, network_1, self.services["http_rule"]) + network_1 = self.create_network(self.services["network_offering"]) + vm_1 = self.deployvm_in_network(network_1) + public_ip_1 = self.acquire_publicip(network_1) + self.create_natrule(vm_1, public_ip_1, network_1) + http_rule=self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) #http_rule = self.create_egress_Internet_Rule(network_1) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) @@ -681,8 +673,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): @attr(tags=["advanced", "intervlan"]) def test_07_network_services_VPC_StopDeleteAllPF(self): - """ Test case no 208 : Delete all PF rules for a single virtual network of a - VPC belonging to a single Public IP Address when Virtual Router is in Stopped State + """ Test delete all PF rules in VPC when VpcVirtualRouter is Stopped """ # Validate the following @@ -699,26 +690,25 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # 11. wget a file present on http server of VM1 should fail # 12. ssh into Guest VM using the PF rule should fail - network_1 = self.create_Network(self.services["network_offering"]) - vm_1 = self.create_VM_in_Network(network_1) - public_ip_1 = self.acquire_Public_IP(network_1) - nat_rule = self.create_NatRule_For_VM(vm_1, public_ip_1, network_1) - http_rule = self.create_NatRule_For_VM(vm_1, public_ip_1, network_1, self.services["http_rule"]) + network_1 = self.create_network(self.services["network_offering"]) + vm_1 = self.deployvm_in_network(network_1) + public_ip_1 = self.acquire_publicip(network_1) + nat_rule = self.create_natrule(vm_1, public_ip_1, network_1) + http_rule = self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) #http_rule = self.create_egress_Internet_Rule(network_1) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) - router = self.stop_VPC_VRouter() + router = self.stop_vpcrouter() http_rule.delete() nat_rule.delete() - self.start_VPC_VRouter(router) + self.start_vpcrouter(router) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) return @attr(tags=["advanced", "intervlan"]) def test_08_network_services_VPC_DeleteAllPF(self): - """ Test case no 194 : Delete all PF rules for a single virtual network of a - VPC belonging to a single Public IP Address when Virtual Router is in Running State + """ Test delete all PF rules in VPC when VpcVirtualRouter is Running """ # Validate the following @@ -733,11 +723,11 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # 9. wget a file present on http server of VM1 should fail # 10. ssh into Guest VM using the PF rule should fail - network_1 = self.create_Network(self.services["network_offering"]) - vm_1 = self.create_VM_in_Network(network_1) - public_ip_1 = self.acquire_Public_IP(network_1) - nat_rule = self.create_NatRule_For_VM(vm_1, public_ip_1, network_1) - http_rule = self.create_NatRule_For_VM(vm_1, public_ip_1, network_1, self.services["http_rule"]) + network_1 = self.create_network(self.services["network_offering"]) + vm_1 = self.deployvm_in_network(network_1) + public_ip_1 = self.acquire_publicip(network_1) + nat_rule = self.create_natrule(vm_1, public_ip_1, network_1) + http_rule = self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) #http_rule = self.create_egress_Internet_Rule(network_1) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) @@ -749,8 +739,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): @attr(tags=["advanced", "intervlan"]) def test_09_network_services_VPC_StopDeleteAllMultiplePF(self): - """ Test case no 209 : Delete all PF rules for two/multiple virtual networks of a VPC. - Observe the status of the Public IP Addresses of the rules when Virtual Router is in Stopped State + """ Test delete all PF rules in VPC across multiple networks when VpcVirtualRouter is Stopped """ # Validate the following @@ -769,20 +758,20 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # 12. Start VPC Virtual Router. # 13. Fail to ssh and http to vm1, vm2, vm3 and vm4. - network_1 = self.create_Network(self.services["network_offering"]) - network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') - vm_1 = self.create_VM_in_Network(network_1) - vm_2 = self.create_VM_in_Network(network_1) - vm_3 = self.create_VM_in_Network(network_2) - vm_4 = self.create_VM_in_Network(network_2) - public_ip_1 = self.acquire_Public_IP(network_1) - public_ip_2 = self.acquire_Public_IP(network_1) - nat_rule1 = self.create_NatRule_For_VM(vm_1, public_ip_1, network_1) - nat_rule2 = self.create_NatRule_For_VM(vm_2, public_ip_2, network_1) - http_rule1 = self.create_egress_Internet_Rule(network_1) - nat_rule3 = self.create_NatRule_For_VM(vm_3, public_ip_1, network_2) - nat_rule4 = self.create_NatRule_For_VM(vm_4, public_ip_2, network_2) - http_rule2 = self.create_egress_Internet_Rule(network_2) + network_1 = self.create_network(self.services["network_offering"]) + network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1') + vm_1 = self.deployvm_in_network(network_1) + vm_2 = self.deployvm_in_network(network_1) + vm_3 = self.deployvm_in_network(network_2) + vm_4 = self.deployvm_in_network(network_2) + public_ip_1 = self.acquire_publicip(network_1) + public_ip_2 = self.acquire_publicip(network_1) + nat_rule1 = self.create_natrule(vm_1, public_ip_1, network_1) + nat_rule2 = self.create_natrule(vm_2, public_ip_2, network_1) + http_rule1 = self.open_egress_to_world(network_1) + nat_rule3 = self.create_natrule(vm_3, public_ip_1, network_2) + nat_rule4 = self.create_natrule(vm_4, public_ip_2, network_2) + http_rule2 = self.open_egress_to_world(network_2) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False) self.check_ssh_into_vm(vm_3, public_ip_1, testnegative=False) @@ -791,14 +780,14 @@ class TestVPCNetworkPFRules(cloudstackTestCase): self.check_wget_from_vm(vm_2, public_ip_2, testnegative=False) self.check_wget_from_vm(vm_3, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_4, public_ip_2, testnegative=False) - router = self.stop_VPC_VRouter() + router = self.stop_vpcrouter() nat_rule1.delete() nat_rule2.delete() nat_rule3.delete() nat_rule4.delete() http_rule1.delete() http_rule2.delete() - self.start_VPC_VRouter(router) + self.start_vpcrouter(router) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True) self.check_ssh_into_vm(vm_3, public_ip_1, testnegative=True) @@ -811,10 +800,8 @@ class TestVPCNetworkPFRules(cloudstackTestCase): @attr(tags=["advanced", "intervlan"]) def test_10_network_services_VPC_DeleteAllMultiplePF(self): - """ Test case no 195: Delete all PF rules for two/multiple virtual networks of a VPC. - Observe the status of the Public IP Addresses of the rules when Virtual Router is in Running State + """ Test delete all PF rules in VPC across multiple networks when VpcVirtualRouter is Running """ - # Validate the following # 1. Create a VPC with cidr - 10.1.1.1/16. # 2. Create a Network offering - NO1 with all supported services. @@ -829,20 +816,20 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # 12. Delete all PF rultes for vm1, vm2, vm3 and vm4. # 13. Fail to ssh and http to vm1, vm2, vm3 and vm4. - network_1 = self.create_Network(self.services["network_offering"]) - network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') - vm_1 = self.create_VM_in_Network(network_1) - vm_2 = self.create_VM_in_Network(network_1) - vm_3 = self.create_VM_in_Network(network_2) - vm_4 = self.create_VM_in_Network(network_2) - public_ip_1 = self.acquire_Public_IP(network_1) - public_ip_2 = self.acquire_Public_IP(network_1) - nat_rule1 = self.create_NatRule_For_VM(vm_1, public_ip_1, network_1) - nat_rule2 = self.create_NatRule_For_VM(vm_2, public_ip_2, network_1) - http_rule1 = self.create_egress_Internet_Rule(network_1) - nat_rule3 = self.create_NatRule_For_VM(vm_3, public_ip_1, network_2) - nat_rule4 = self.create_NatRule_For_VM(vm_4, public_ip_2, network_2) - http_rule2 = self.create_egress_Internet_Rule(network_2) + network_1 = self.create_network(self.services["network_offering"]) + network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1') + vm_1 = self.deployvm_in_network(network_1) + vm_2 = self.deployvm_in_network(network_1) + vm_3 = self.deployvm_in_network(network_2) + vm_4 = self.deployvm_in_network(network_2) + public_ip_1 = self.acquire_publicip(network_1) + public_ip_2 = self.acquire_publicip(network_1) + nat_rule1 = self.create_natrule(vm_1, public_ip_1, network_1) + nat_rule2 = self.create_natrule(vm_2, public_ip_2, network_1) + http_rule1 = self.open_egress_to_world(network_1) + nat_rule3 = self.create_natrule(vm_3, public_ip_1, network_2) + nat_rule4 = self.create_natrule(vm_4, public_ip_2, network_2) + http_rule2 = self.open_egress_to_world(network_2) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False) self.check_ssh_into_vm(vm_3, public_ip_1, testnegative=False) diff --git a/test/integration/component/test_vpc_offerings.py b/test/integration/component/test_vpc_offerings.py index 4b9877506f2..a111d7d9059 100644 --- a/test/integration/component/test_vpc_offerings.py +++ b/test/integration/component/test_vpc_offerings.py @@ -278,7 +278,6 @@ class TestVPCOffering(cloudstackTestCase): return @attr(tags=["advanced", "intervlan"]) - @unittest.skip("Skipping - Issue: Deleting account doesn't clean VPC") def test_02_deploy_vms_in_vpc_nw(self): """Test deploy virtual machines in VPC networks""" @@ -897,7 +896,6 @@ class TestVPCOffering(cloudstackTestCase): return @attr(tags=["advanced", "intervlan"]) - @unittest.skip("Skipping - API should not allow to create VPC offering without SourceNAT, Firewall") def test_06_vpc_off_invalid_services(self): """Test VPC offering with invalid services""" diff --git a/test/integration/component/test_vpc_routers.py b/test/integration/component/test_vpc_routers.py index 7dc95e826e3..a8559e5cc6c 100644 --- a/test/integration/component/test_vpc_routers.py +++ b/test/integration/component/test_vpc_routers.py @@ -509,7 +509,6 @@ class TestVPCRoutersBasic(cloudstackTestCase): ) return - @unittest.skip("Needs hosts") @attr(tags=["advanced", "intervlan"]) def test_04_migrate_router_after_creating_vpc(self): """ Test migration of router to another host after creating VPC """ @@ -531,7 +530,6 @@ class TestVPCRoutersBasic(cloudstackTestCase): self.migrate_router(routers[0]) return - @unittest.skip("Fails") @attr(tags=["advanced", "intervlan"]) def test_05_change_service_offerring_vpc(self): """ Tests to change service offering of the Router after @@ -1236,7 +1234,6 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) return - @unittest.skip("Untested - hosts not available") @attr(tags=["advanced", "intervlan"]) def test_04_migrate_router_after_addition_of_one_guest_network(self): """ Test migrate of router after addition of one guest network @@ -1280,7 +1277,6 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): self.migrate_router(routers[0]) return - @unittest.skip("Fails") @attr(tags=["advanced", "intervlan"]) def test_05_chg_srv_off_router_after_addition_of_one_guest_network(self): """ Test to change service offering of router after addition of one guest network diff --git a/test/integration/component/test_vpc_vm_life_cycle.py b/test/integration/component/test_vpc_vm_life_cycle.py index 7658bebe2e2..39fb533bfee 100644 --- a/test/integration/component/test_vpc_vm_life_cycle.py +++ b/test/integration/component/test_vpc_vm_life_cycle.py @@ -26,8 +26,6 @@ from marvin.integration.lib.utils import * from marvin.integration.lib.base import * from marvin.integration.lib.common import * from marvin.remoteSSHClient import remoteSSHClient -import datetime - class Services: """Test VM life cycle in VPC network services @@ -35,155 +33,159 @@ class Services: def __init__(self): self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 128, - }, - "service_offering_1": { - "name": "Tiny Instance- tagged host 1", - "displaytext": "Tiny off-tagged host2", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 128, - "tags": "HOST_TAGS_HERE" - }, - "service_offering_2": { - "name": "Tiny Instance- tagged host 2", - "displaytext": "Tiny off-tagged host2", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 128, - "tags": "HOST_TAGS_HERE" - }, - "network_offering": { - "name": 'VPC Network offering', - "displaytext": 'VPC Network off', - "guestiptype": 'Isolated', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL', - "traffictype": 'GUEST', - "availability": 'Optional', - "useVpc": 'on', - "serviceProviderList": { - "Dhcp": 'VpcVirtualRouter', - "Dns": 'VpcVirtualRouter', - "SourceNat": 'VpcVirtualRouter', - "PortForwarding": 'VpcVirtualRouter', - "Lb": 'VpcVirtualRouter', - "UserData": 'VpcVirtualRouter', - "StaticNat": 'VpcVirtualRouter', - "NetworkACL": 'VpcVirtualRouter' - }, - }, - "network_offering_no_lb": { - "name": 'VPC Network offering', - "displaytext": 'VPC Network off', - "guestiptype": 'Isolated', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,UserData,StaticNat,NetworkACL', - "traffictype": 'GUEST', - "availability": 'Optional', - "useVpc": 'on', - "serviceProviderList": { - "Dhcp": 'VpcVirtualRouter', - "Dns": 'VpcVirtualRouter', - "SourceNat": 'VpcVirtualRouter', - "PortForwarding": 'VpcVirtualRouter', - "UserData": 'VpcVirtualRouter', - "StaticNat": 'VpcVirtualRouter', - "NetworkACL": 'VpcVirtualRouter' - }, - }, - "network_off_shared": { - "name": 'Shared Network offering', - "displaytext": 'Shared Network offering', - "guestiptype": 'Shared', - "traffictype": 'GUEST', - "availability": 'Optional', - "useVpc": 'on', - "specifyIpRanges": True, - "specifyVlan": True - }, - "vpc_offering": { - "name": 'VPC off', - "displaytext": 'VPC off', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat', - }, - "vpc": { - "name": "TestVPC", - "displaytext": "TestVPC", - "cidr": '10.0.0.1/24' - }, - "network": { - "name": "Test Network", - "displaytext": "Test Network", - "netmask": '255.255.255.0', - "limit": 5, - # Max networks allowed as per hypervisor - # Xenserver -> 5, VMWare -> 9 - }, - "lbrule": { - "name": "SSH", - "alg": "leastconn", - # Algorithm used for load balancing - "privateport": 22, - "publicport": 2222, - "openfirewall": False, - "startport": 2222, - "endport": 2222, - "protocol": "TCP", - "cidrlist": '0.0.0.0/0', - }, - "natrule": { - "privateport": 22, - "publicport": 22, - "startport": 22, - "endport": 22, - "protocol": "TCP", - "cidrlist": '0.0.0.0/0', - }, - "fw_rule": { - "startport": 1, - "endport": 6000, - "cidr": '0.0.0.0/0', - # Any network (For creating FW rule) - "protocol": "TCP" - }, - "http_rule": { - "startport": 80, - "endport": 80, - "cidrlist": '0.0.0.0/0', - "protocol": "ICMP" - }, - "virtual_machine": { - "displayname": "Test VM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - # Hypervisor type should be same as - # hypervisor type of cluster - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - "userdata": 'This is sample data', - }, - "ostype": 'CentOS 5.3 (64-bit)', - # Cent OS 5.3 (64 bit) - "sleep": 60, - "timeout": 10, - "mode": 'advanced' - } + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended for unique + # username + "password": "password", + }, + "service_offering": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 128, + }, + "service_offering_1": { + "name": "Tiny Instance- tagged host 1", + "displaytext": "Tiny off-tagged host2", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 128, + "tags": "HOST_TAGS_HERE" + }, + "service_offering_2": { + "name": "Tiny Instance- tagged host 2", + "displaytext": "Tiny off-tagged host2", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 128, + "tags": "HOST_TAGS_HERE" + }, + "network_offering": { + "name": 'VPC Network offering', + "displaytext": 'VPC Network off', + "guestiptype": 'Isolated', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL', + "traffictype": 'GUEST', + "availability": 'Optional', + "useVpc": 'on', + "serviceProviderList": { + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "PortForwarding": 'VpcVirtualRouter', + "Lb": 'VpcVirtualRouter', + "UserData": 'VpcVirtualRouter', + "StaticNat": 'VpcVirtualRouter', + "NetworkACL": 'VpcVirtualRouter' + }, + "serviceCapabilityList": { + "SourceNat": {"SupportedSourceNatTypes": "peraccount"}, + "Lb": {"lbSchemes": "public", "SupportedLbIsolation": "dedicated"} + }, + }, + "network_offering_no_lb": { + "name": 'VPC Network offering no LB', + "displaytext": 'VPC Network off no LB', + "guestiptype": 'Isolated', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,UserData,StaticNat,NetworkACL', + "traffictype": 'GUEST', + "availability": 'Optional', + "useVpc": 'on', + "serviceProviderList": { + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "PortForwarding": 'VpcVirtualRouter', + "UserData": 'VpcVirtualRouter', + "StaticNat": 'VpcVirtualRouter', + "NetworkACL": 'VpcVirtualRouter' + }, + }, + "network_off_shared": { + "name": 'Shared Network offering', + "displaytext": 'Shared Network offering', + "guestiptype": 'Shared', + "traffictype": 'GUEST', + "availability": 'Optional', + "useVpc": 'on', + "specifyIpRanges": True, + "specifyVlan": True + }, + "vpc_offering": { + "name": 'VPC off', + "displaytext": 'VPC off', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat', + }, + "vpc": { + "name": "TestVPC", + "displaytext": "TestVPC", + "cidr": '10.0.0.1/24' + }, + "network": { + "name": "Test Network", + "displaytext": "Test Network", + "netmask": '255.255.255.0', + "limit": 5, + # Max networks allowed as per hypervisor + # Xenserver -> 5, VMWare -> 9 + }, + "lbrule": { + "name": "SSH", + "alg": "leastconn", + # Algorithm used for load balancing + "privateport": 22, + "publicport": 2222, + "openfirewall": False, + "startport": 2222, + "endport": 2222, + "protocol": "TCP", + "cidrlist": '0.0.0.0/0', + }, + "natrule": { + "privateport": 22, + "publicport": 22, + "startport": 22, + "endport": 22, + "protocol": "TCP", + "cidrlist": '0.0.0.0/0', + }, + "fw_rule": { + "startport": 1, + "endport": 6000, + "cidr": '0.0.0.0/0', + # Any network (For creating FW rule) + "protocol": "TCP" + }, + "http_rule": { + "startport": 80, + "endport": 80, + "cidrlist": '0.0.0.0/0', + "protocol": "ICMP" + }, + "virtual_machine": { + "displayname": "Test VM", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + # Hypervisor type should be same as + # hypervisor type of cluster + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + "userdata": 'This is sample data', + }, + "ostype": 'CentOS 5.3 (64-bit)', + # Cent OS 5.3 (64 bit) + "sleep": 60, + "timeout": 10, + "mode": 'advanced' + } class TestVMLifeCycleVPC(cloudstackTestCase): @@ -210,11 +212,6 @@ class TestVMLifeCycleVPC(cloudstackTestCase): cls.api_client, cls.services["service_offering"] ) - cls.vpc_off = VpcOffering.create( - cls.api_client, - cls.services["vpc_offering"] - ) - cls.vpc_off.update(cls.api_client, state='Enabled') cls.account = Account.create( cls.api_client, @@ -266,18 +263,6 @@ class TestVMLifeCycleVPC(cloudstackTestCase): ) # Enable Network offering cls.nw_off_no_lb.update(cls.api_client, state='Enabled') - - # Creating network using the network offering created - cls.network_2 = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - networkofferingid=cls.nw_off_no_lb.id, - zoneid=cls.zone.id, - gateway='10.1.2.1', - vpcid=cls.vpc.id - ) # Spawn an instance in that network cls.vm_1 = VirtualMachine.create( cls.api_client, @@ -287,7 +272,6 @@ class TestVMLifeCycleVPC(cloudstackTestCase): serviceofferingid=cls.service_offering.id, networkids=[str(cls.network_1.id)] ) - # Spawn an instance in that network cls.vm_2 = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], @@ -296,15 +280,6 @@ class TestVMLifeCycleVPC(cloudstackTestCase): serviceofferingid=cls.service_offering.id, networkids=[str(cls.network_1.id)] ) - cls.vm_3 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - networkids=[str(cls.network_2.id)] - ) - cls.public_ip_1 = PublicIPAddress.create( cls.api_client, accountid=cls.account.name, @@ -368,20 +343,15 @@ class TestVMLifeCycleVPC(cloudstackTestCase): cls.service_offering, cls.nw_off, cls.nw_off_no_lb, + cls.account ] return @classmethod def tearDownClass(cls): try: - cls.account.delete(cls.api_client) - wait_for_cleanup(cls.api_client, ["account.cleanup.interval"]) #Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) - - # Waiting for network cleanup to delete vpc offering - wait_for_cleanup(cls.api_client, ["network.gc.wait", "network.gc.interval"]) - cls.vpc_off.delete(cls.api_client) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -396,10 +366,6 @@ class TestVMLifeCycleVPC(cloudstackTestCase): try: #Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) - wait_for_cleanup(self.apiclient, [ - "network.gc.interval", - "network.gc.wait"]) - except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -914,7 +880,6 @@ class TestVMLifeCycleVPC(cloudstackTestCase): ) return - class TestVMLifeCycleSharedNwVPC(cloudstackTestCase): @classmethod @@ -1104,16 +1069,14 @@ class TestVMLifeCycleSharedNwVPC(cloudstackTestCase): cls.service_offering, cls.nw_off, cls.shared_nw_off, - cls.vpc_off + cls.vpc_off, + cls.account ] return @classmethod def tearDownClass(cls): try: - cls.account.delete(cls.api_client) - wait_for_cleanup(cls.api_client, ["account.cleanup.interval"]) - #Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1127,12 +1090,7 @@ class TestVMLifeCycleSharedNwVPC(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) - wait_for_cleanup(self.apiclient, [ - "network.gc.interval", - "network.gc.wait"]) - except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -1819,16 +1777,14 @@ class TestVMLifeCycleBothIsolated(cloudstackTestCase): cls.service_offering, cls.nw_off, cls.nw_off_no_lb, - cls.vpc_off + cls.vpc_off, + cls.account ] return @classmethod def tearDownClass(cls): try: - cls.account.delete(cls.api_client) - wait_for_cleanup(cls.api_client, ["account.cleanup.interval"]) - #Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1844,10 +1800,6 @@ class TestVMLifeCycleBothIsolated(cloudstackTestCase): try: #Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) - wait_for_cleanup(self.apiclient, [ - "network.gc.interval", - "network.gc.wait"]) - except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -2084,11 +2036,6 @@ class TestVMLifeCycleStoppedVPCVR(cloudstackTestCase): cls.api_client, cls.services["service_offering"] ) - cls.vpc_off = VpcOffering.create( - cls.api_client, - cls.services["vpc_offering"] - ) - cls.vpc_off.update(cls.api_client, state='Enabled') cls.account = Account.create( cls.api_client, @@ -2242,21 +2189,14 @@ class TestVMLifeCycleStoppedVPCVR(cloudstackTestCase): cls.service_offering, cls.nw_off, cls.nw_off_no_lb, + cls.account ] return @classmethod def tearDownClass(cls): try: - cls.account.delete(cls.api_client) - wait_for_cleanup(cls.api_client, ["account.cleanup.interval"]) - #Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) - - # Waiting for network cleanup to delete vpc offering - wait_for_cleanup(cls.api_client, ["network.gc.wait", - "network.gc.interval"]) - cls.vpc_off.delete(cls.api_client) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -2285,10 +2225,6 @@ class TestVMLifeCycleStoppedVPCVR(cloudstackTestCase): try: #Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self.cleanup) - wait_for_cleanup(self.apiclient, [ - "network.gc.interval", - "network.gc.wait"]) - except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -2464,805 +2400,6 @@ class TestVMLifeCycleStoppedVPCVR(cloudstackTestCase): ) return - @unittest.skip("Skipping - Not able to SSH if VPCVR is stopped") - @attr(tags=["advanced", "intervlan"]) - def test_03_start_instance_in_network(self): - """ Test start an instance in VPC networks - """ - - # Validate the following - # 1. Start the virtual machines. - # 2. Vm should be started successfully. - # 3. Make sure that all the PF,LB and Static NAT rules on this VM - # works as expected. - # 3. Make sure that we are able to access google.com from this user Vm - - self.debug("Starting the virtual machines in account: %s" % - self.account.name) - try: - self.vm_1.start(self.apiclient) - self.vm_2.start(self.apiclient) - except Exception as e: - self.fail("Failed to start the virtual instances, %s" % e) - self.debug("Validating if the network rules work properly or not?") - self.validate_network_rules() - return - - @unittest.skip("Skipping - Not able to SSH if VPCVR is stopped") - @attr(tags=["advanced", "intervlan"]) - def test_04_reboot_instance_in_network(self): - """ Test reboot an instance in VPC networks - """ - - # Validate the following - # 1. Reboot the virtual machines. - # 2. Vm should be started successfully. - # 3. Make sure that all the PF,LB and Static NAT rules on this VM - # works as expected. - # 3. Make sure that we are able to access google.com from this user Vm - - self.debug("Validating if the network rules work properly or not?") - self.validate_network_rules() - - self.debug("Starting the virtual machines in account: %s" % - self.account.name) - try: - self.vm_1.reboot(self.apiclient) - self.vm_2.reboot(self.apiclient) - except Exception as e: - self.fail("Failed to reboot the virtual instances, %s" % e) - - self.debug("Validating if the network rules work properly or not?") - self.validate_network_rules() - return - - @unittest.skip("Skipping - Not able to SSH if VPCVR is stopped") - @attr(tags=["advanced", "intervlan"]) - def test_05_destroy_instance_in_network(self): - """ Test destroy an instance in VPC networks - """ - - # Validate the following - # 1. Destory the virtual machines. - # 2. Rules should be still configured on virtual router. - - self.debug("Validating if the network rules work properly or not?") - self.validate_network_rules() - - self.debug("Destroying the virtual machines in account: %s" % - self.account.name) - try: - self.vm_1.delete(self.apiclient) - self.vm_2.delete(self.apiclient) - except Exception as e: - self.fail("Failed to stop the virtual instances, %s" % e) - - # Check if the network rules still exists after Vm stop - self.debug("Checking if NAT rules ") - nat_rules = NATRule.list( - self.apiclient, - id=self.nat_rule.id, - listall=True - ) - self.assertEqual( - isinstance(nat_rules, list), - True, - "List NAT rules shall return a valid list" - ) - - lb_rules = LoadBalancerRule.list( - self.apiclient, - id=self.lb_rule.id, - listall=True - ) - self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules shall return a valid list" - ) - return - - @unittest.skip("Skipping - Not able to SSH if VPCVR is stopped") - @attr(tags=["advanced", "intervlan"]) - def test_06_recover_instance_in_network(self): - """ Test recover an instance in VPC networks - """ - - # Validate the following - # 1. Recover the virtual machines. - # 2. Vm should be in stopped state. State both the instances - # 3. Make sure that all the PF,LB and Static NAT rules on this VM - # works as expected. - # 3. Make sure that we are able to access google.com from this user Vm - - self.debug("Recovering the expunged virtual machines in account: %s" % - self.account.name) - try: - self.vm_1.recover(self.apiclient) - self.vm_2.recover(self.apiclient) - except Exception as e: - self.fail("Failed to recover the virtual instances, %s" % e) - - self.debug("Starting the two instances..") - try: - self.vm_1.start(self.apiclient) - self.vm_2.start(self.apiclient) - except Exception as e: - self.fail("Failed to start the instances, %s" % e) - - self.debug("Validating if the network rules work properly or not?") - self.validate_network_rules() - return - - @unittest.skip("Skipping - Not able to SSH if VPCVR is stopped") - @attr(tags=["advanced", "intervlan"]) - def test_07_migrate_instance_in_network(self): - """ Test migrate an instance in VPC networks - """ - - # Validate the following - # 1. Migrate the virtual machines to other hosts - # 2. Vm should be in stopped state. State both the instances - # 3. Make sure that all the PF,LB and Static NAT rules on this VM - # works as expected. - # 3. Make sure that we are able to access google.com from this user Vm - - self.debug("Checking if the host is available for migration?") - hosts = Host.list( - self.apiclient, - zoneid=self.zone.id, - type='Routing' - ) - - self.assertEqual( - isinstance(hosts, list), - True, - "List hosts should return a valid list" - ) - if len(hosts) < 2: - raise unittest.SkipTest( - "No host available for migration. Test requires atleast 2 hosts") - - # Remove the host of current VM from the hosts list - hosts[:] = [host for host in hosts if host.id != self.vm_1.hostid] - - host = hosts[0] - - self.debug("Validating if the network rules work properly or not?") - self.validate_network_rules() - - self.debug("Migrating VM-ID: %s to Host: %s" % ( - self.vm_1.id, - host.id - )) - - try: - self.vm_1.migrate(self.apiclient, hostid=host.id) - except Exception as e: - self.fail("Failed to migrate instance, %s" % e) - - self.debug("Validating if the network rules work properly or not?") - self.validate_network_rules() - return - - @unittest.skip("Skipping - Not able to SSH if VPCVR is stopped") - @attr(tags=["advanced", "intervlan"]) - def test_08_user_data(self): - """ Test user data in virtual machines - """ - - # Validate the following - # 1. Create a VPC with cidr - 10.1.1.1/16 - # 2. Add network1(10.1.1.1/24) and network2(10.1.2.1/24) to this VPC. - # 3. Deploy a vm in network1 and a vm in network2 using userdata - # Steps - # 1.Query for the user data for both the user vms from both networks - # User should be able to query the user data for the vms belonging to - # both the networks from the VR - - try: - ssh = self.vm_1.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress) - self.debug("SSH into VM is successfully") - except Exception as e: - self.fail("Failed to SSH into instance") - - # Find router associated with user account - routers = Router.list( - self.apiclient, - zoneid=self.zone.id, - listall=True - ) - self.assertEqual( - isinstance(routers, list), - True, - "Check list response returns a valid list" - ) - router = routers[0] - self.debug("check the userdata with that of present in router") - try: - cmds = [ - "wget http://%s/latest/user-data" % router.guestipaddress, - "cat user-data", - ] - for c in cmds: - result = ssh.execute(c) - self.debug("%s: %s" % (c, result)) - except Exception as e: - self.fail("Failed to SSH in Virtual machine: %s" % e) - - res = str(result) - self.assertEqual( - res.count( - self.services["virtual_machine"]["userdata"]), - 1, - "Verify user data from router" - ) - return - - @unittest.skip("Skipping - Not able to SSH if VPCVR is stopped") - @attr(tags=["advanced", "intervlan"]) - def test_09_meta_data(self): - """ Test meta data in virtual machines - """ - - # Validate the following - # 1. Create a VPC with cidr - 10.1.1.1/16 - # 2. Add network1(10.1.1.1/24) and network2(10.1.2.1/24) to this VPC. - # 3. Deploy a vm in network1 and a vm in network2 using userdata - # Steps - # 1.Query for the meta data for both the user vms from both networks - # User should be able to query the user data for the vms belonging to - # both the networks from the VR - - try: - ssh = self.vm_1.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress) - self.debug("SSH into VM is successfully") - except Exception as e: - self.fail("Failed to SSH into instance") - - # Find router associated with user account - routers = Router.list( - self.apiclient, - zoneid=self.zone.id, - listall=True - ) - self.assertEqual( - isinstance(routers, list), - True, - "Check list response returns a valid list" - ) - router = routers[0] - self.debug("check the metadata with that of present in router") - try: - cmds = [ - "wget http://%s/latest/meta-data" % router.guestipaddress, - "cat user-data", - ] - for c in cmds: - result = ssh.execute(c) - self.debug("%s: %s" % (c, result)) - except Exception as e: - self.fail("Failed to SSH in Virtual machine: %s" % e) - - res = str(result) - self.assertNotEqual( - res, - None, - "Meta data should be returned from router" - ) - return - - @unittest.skip("Skipping - Not able to SSH if VPCVR is stopped") - @attr(tags=["advanced", "intervlan"]) - def test_10_expunge_instance_in_network(self): - """ Test expunge an instance in VPC networks - """ - - # Validate the following - # 1. Recover the virtual machines. - # 2. Vm should be in stopped state. State both the instances - # 3. Make sure that all the PF,LB and Static NAT rules on this VM - # works as expected. - # 3. Make sure that we are able to access google.com from this user Vm - - self.debug("Validating if the network rules work properly or not?") - self.validate_network_rules() - - self.debug("Delete virtual machines in account: %s" % - self.account.name) - try: - self.vm_1.delete(self.apiclient) - self.vm_2.delete(self.apiclient) - except Exception as e: - self.fail("Failed to destroy the virtual instances, %s" % e) - - self.debug( - "Waiting for expunge interval to cleanup the network and VMs") - - wait_for_cleanup( - self.apiclient, - ["expunge.interval", "expunge.delay"] - ) - - # Check if the network rules still exists after Vm stop - self.debug("Checking if NAT rules ") - nat_rules = NATRule.list( - self.apiclient, - id=self.nat_rule.id, - listall=True - ) - self.assertEqual( - nat_rules, - None, - "List NAT rules should not return anything" - ) - - lb_rules = LoadBalancerRule.list( - self.apiclient, - id=self.lb_rule.id, - listall=True - ) - self.assertEqual( - lb_rules, - None, - "List LB rules should not return anything" - ) - return - - -@unittest.skip("Skip - Requires Tagged hosts setup") -class TestVMLifeCycleDiffHosts(cloudstackTestCase): - - @classmethod - def setUpClass(cls): - cls.api_client = super( - TestVMLifeCycleDiffHosts, - 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.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - cls.services["virtual_machine"]["zoneid"] = cls.zone.id - cls.services["virtual_machine"]["template"] = cls.template.id - - cls.service_offering_1 = ServiceOffering.create( - cls.api_client, - cls.services["service_offering_1"] - ) - cls.service_offering_2 = ServiceOffering.create( - cls.api_client, - cls.services["service_offering_2"] - ) - cls.vpc_off = VpcOffering.create( - cls.api_client, - cls.services["vpc_offering"] - ) - cls.vpc_off.update(cls.api_client, state='Enabled') - - cls.account = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) - - cls.vpc_off = VpcOffering.create( - cls.api_client, - cls.services["vpc_offering"] - ) - - cls.vpc_off.update(cls.api_client, state='Enabled') - - cls.services["vpc"]["cidr"] = '10.1.1.1/16' - cls.vpc = VPC.create( - cls.api_client, - cls.services["vpc"], - vpcofferingid=cls.vpc_off.id, - zoneid=cls.zone.id, - account=cls.account.name, - domainid=cls.account.domainid - ) - - cls.nw_off = NetworkOffering.create( - cls.api_client, - cls.services["network_offering"], - conservemode=False - ) - # Enable Network offering - cls.nw_off.update(cls.api_client, state='Enabled') - - # Creating network using the network offering created - cls.network_1 = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - networkofferingid=cls.nw_off.id, - zoneid=cls.zone.id, - gateway='10.1.1.1', - vpcid=cls.vpc.id - ) - cls.nw_off_no_lb = NetworkOffering.create( - cls.api_client, - cls.services["network_offering_no_lb"], - conservemode=False - ) - # Enable Network offering - cls.nw_off_no_lb.update(cls.api_client, state='Enabled') - - # Creating network using the network offering created - cls.network_2 = Network.create( - cls.api_client, - cls.services["network"], - accountid=cls.account.name, - domainid=cls.account.domainid, - networkofferingid=cls.nw_off_no_lb.id, - zoneid=cls.zone.id, - gateway='10.1.2.1', - vpcid=cls.vpc.id - ) - # Spawn an instance in that network - cls.vm_1 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering_1.id, - networkids=[str(cls.network_1.id)] - ) - # Spawn an instance in that network - cls.vm_2 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering_1.id, - networkids=[str(cls.network_1.id)] - ) - cls.vm_3 = VirtualMachine.create( - cls.api_client, - cls.services["virtual_machine"], - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering_2.id, - networkids=[str(cls.network_2.id)] - ) - - cls.public_ip_1 = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network_1.id, - vpcid=cls.vpc.id - ) - cls.lb_rule = LoadBalancerRule.create( - cls.api_client, - cls.services["lbrule"], - ipaddressid=cls.public_ip_1.ipaddress.id, - accountid=cls.account.name, - networkid=cls.network_1.id, - vpcid=cls.vpc.id, - domainid=cls.account.domainid - ) - cls.lb_rule.assign(cls.api_client, [cls.vm_1, cls.vm_2]) - - cls.public_ip_2 = PublicIPAddress.create( - cls.api_client, - accountid=cls.account.name, - zoneid=cls.zone.id, - domainid=cls.account.domainid, - networkid=cls.network_1.id, - vpcid=cls.vpc.id - ) - - cls.nat_rule = NATRule.create( - cls.api_client, - cls.vm_1, - cls.services["natrule"], - ipaddressid=cls.public_ip_2.ipaddress.id, - openfirewall=False, - networkid=cls.network_1.id, - vpcid=cls.vpc.id - ) - - # Opening up the ports in VPC - cls.nwacl_nat = NetworkACL.create( - cls.api_client, - networkid=cls.network_1.id, - services=cls.services["natrule"], - traffictype='Ingress' - ) - - cls.nwacl_lb = NetworkACL.create( - cls.api_client, - networkid=cls.network_1.id, - services=cls.services["lbrule"], - traffictype='Ingress' - ) - - cls.nwacl_internet = NetworkACL.create( - cls.api_client, - networkid=cls.network_1.id, - services=cls.services["http_rule"], - traffictype='Egress' - ) - cls._cleanup = [ - cls.service_offering_1, - cls.service_offering_2, - cls.nw_off, - cls.nw_off_no_lb, - ] - return - - @classmethod - def tearDownClass(cls): - try: - cls.account.delete(cls.api_client) - wait_for_cleanup(cls.api_client, ["account.cleanup.interval"]) - #Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) - - # Waiting for network cleanup to delete vpc offering - wait_for_cleanup(cls.api_client, ["network.gc.wait", - "network.gc.interval"]) - cls.vpc_off.delete(cls.api_client) - 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.debug("Check the status of VPC virtual router") - routers = Router.list( - self.apiclient, - networkid=self.network_1.id, - listall=True - ) - if not isinstance(routers, list): - raise Exception("No response from list routers API") - - self.router = routers[0] - if self.router.state == "Running": - Router.stop(self.apiclient, id=self.router.id) - - self.cleanup = [] - return - - def tearDown(self): - try: - #Clean up, terminate the created network offerings - cleanup_resources(self.apiclient, self.cleanup) - wait_for_cleanup(self.apiclient, [ - "network.gc.interval", - "network.gc.wait"]) - - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return - - def validate_vm_deployment(self): - """Validates VM deployment on different hosts""" - - vms = VirtualMachine.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - networkid=self.network_1.id, - listall=True - ) - self.assertEqual( - isinstance(vms, list), - True, - "List VMs shall return a valid response" - ) - host_1 = vms[0].hostid - self.debug("Host for network 1: %s" % vms[0].hostid) - - vms = VirtualMachine.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - networkid=self.network_2.id, - listall=True - ) - self.assertEqual( - isinstance(vms, list), - True, - "List VMs shall return a valid response" - ) - host_2 = vms[0].hostid - self.debug("Host for network 2: %s" % vms[0].hostid) - - self.assertNotEqual( - host_1, - host_2, - "Both the virtual machines should be deployed on diff hosts " - ) - return - - def validate_vpc_offering(self, vpc_offering): - """Validates the VPC offering""" - - self.debug("Check if the VPC offering is created successfully?") - vpc_offs = VpcOffering.list( - self.apiclient, - id=vpc_offering.id - ) - self.assertEqual( - isinstance(vpc_offs, list), - True, - "List VPC offerings should return a valid list" - ) - self.assertEqual( - vpc_offering.name, - vpc_offs[0].name, - "Name of the VPC offering should match with listVPCOff data" - ) - self.debug( - "VPC offering is created successfully - %s" % - vpc_offering.name) - return - - def validate_vpc_network(self, network, state=None): - """Validates the VPC network""" - - self.debug("Check if the VPC network is created successfully?") - vpc_networks = VPC.list( - self.apiclient, - id=network.id - ) - self.assertEqual( - isinstance(vpc_networks, list), - True, - "List VPC network should return a valid list" - ) - self.assertEqual( - network.name, - vpc_networks[0].name, - "Name of the VPC network should match with listVPC data" - ) - if state: - self.assertEqual( - vpc_networks[0].state, - state, - "VPC state should be '%s'" % state - ) - self.debug("VPC network validated - %s" % network.name) - return - - def validate_network_rules(self): - """Validates if the network rules work properly or not?""" - try: - ssh_1 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip_1.ipaddress.ipaddress) - self.debug("SSH into VM is successfully") - - self.debug("Verifying if we can ping to outside world from VM?") - # Ping to outsite world - res = ssh_1.execute("ping -c 1 www.google.com") - # res = 64 bytes from maa03s17-in-f20.1e100.net (74.125.236.212): - # icmp_req=1 ttl=57 time=25.9 ms - # --- www.l.google.com ping statistics --- - # 1 packets transmitted, 1 received, 0% packet loss, time 0ms - # rtt min/avg/max/mdev = 25.970/25.970/25.970/0.000 ms - except Exception as e: - self.fail("Failed to SSH into VM - %s, %s" % - (self.public_ip_1.ipaddress.ipaddress, e)) - - result = str(res) - self.assertEqual( - result.count("1 received"), - 1, - "Ping to outside world from VM should be successful" - ) - - self.debug("Checking if we can SSH into VM_1?") - try: - ssh_2 = self.vm_1.get_ssh_client( - ipaddress=self.public_ip_2.ipaddress.ipaddress) - self.debug("SSH into VM is successfully") - - self.debug("Verifying if we can ping to outside world from VM?") - res = ssh_2.execute("ping -c 1 www.google.com") - except Exception as e: - self.fail("Failed to SSH into VM - %s, %s" % - (self.public_ip_2.ipaddress.ipaddress, e)) - - result = str(res) - self.assertEqual( - result.count("1 received"), - 1, - "Ping to outside world from VM should be successful" - ) - return - - @attr(tags=["advanced", "intervlan"]) - def test_01_deploy_instance_in_network(self): - """ Test deploy an instance in VPC networks - """ - - # Validate the following - # 1. Create a VPC with cidr - 10.1.1.1/16 - # 2. Add network1(10.1.1.1/24) and network2(10.1.2.1/24) to this VPC. - # Steps: - # 1. Deploy vm1 and vm2 in network1 and vm3 and vm4 in network2 using - # the default CentOS 6.2 Template - - self.validate_vm_deployment() - self.debug("Check if deployed VMs are in running state?") - vms = VirtualMachine.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - listall=True - ) - self.assertEqual( - isinstance(vms, list), - True, - "List VMs should return a valid response" - ) - for vm in vms: - self.debug("VM name: %s, VM state: %s" % (vm.name, vm.state)) - self.assertEqual( - vm.state, - "Running", - "Vm state should be running for each VM deployed" - ) - return - - @attr(tags=["advanced", "intervlan"]) - def test_02_stop_instance_in_network(self): - """ Test stop an instance in VPC networks - """ - - # Validate the following - # 1. Stop the virtual machines. - # 2. Rules should be still configured on virtual router. - - self.debug("Stopping the virtual machines in account: %s" % - self.account.name) - try: - self.vm_1.stop(self.apiclient) - self.vm_2.stop(self.apiclient) - except Exception as e: - self.fail("Failed to stop the virtual instances, %s" % e) - - # Check if the network rules still exists after Vm stop - self.debug("Checking if NAT rules ") - nat_rules = NATRule.list( - self.apiclient, - id=self.nat_rule.id, - listall=True - ) - self.assertEqual( - isinstance(nat_rules, list), - True, - "List NAT rules shall return a valid list" - ) - - lb_rules = LoadBalancerRule.list( - self.apiclient, - id=self.lb_rule.id, - listall=True - ) - self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules shall return a valid list" - ) - return - @attr(tags=["advanced", "intervlan"]) def test_03_start_instance_in_network(self): """ Test start an instance in VPC networks diff --git a/test/integration/component/test_vpc_vms_deployment.py b/test/integration/component/test_vpc_vms_deployment.py index c49ef458a40..c599d96113e 100644 --- a/test/integration/component/test_vpc_vms_deployment.py +++ b/test/integration/component/test_vpc_vms_deployment.py @@ -1721,7 +1721,6 @@ class TestVMDeployVPC(cloudstackTestCase): return @attr(tags=["advanced", "intervlan"]) - @unittest.skip("Not tested") def test_07_delete_network_with_rules(self): """ Test delete network that has PF/staticNat/LB rules/Network Acl """ 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 67532c78d0f..af832995245 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 +from marvin.integration.lib.base import Account, VirtualMachine, ServiceOffering, Host from marvin.integration.lib.common import get_zone, get_domain, get_template, cleanup_resources from nose.plugins.attrib import attr @@ -76,6 +76,7 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase): domainid=cls.domain.id ) cls.services["account"] = cls.account.name + cls.hosts = Host.list(cls.apiclient, type='Routing') cls.cleanup = [ cls.account ] @@ -177,10 +178,12 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase): "Running", msg="VM is not in Running state" ) + vm1clusterid = filter(lambda c: c.id == vm1.hostid, self.hosts)[0].clusterid + vm2clusterid = filter(lambda c: c.id == vm2.hostid, self.hosts)[0].clusterid self.assertNotEqual( - vm1.hostid, - vm2.hostid, - msg="VMs meant to be dispersed are deployed on the same host" + vm1clusterid, + vm2clusterid, + msg="VMs (%s, %s) meant to be dispersed are deployed in the same cluster %s" % (vm1.id, vm2.id, vm1clusterid) ) @attr(tags=["simulator", "advanced", "basic", "sg"]) @@ -236,10 +239,12 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase): "Running", msg="VM is not in Running state" ) - self.assertNotEqual( - vm1.hostid, - vm2.hostid, - msg="VMs meant to be concentrated are deployed on the different hosts" + vm1clusterid = filter(lambda c: c.id == vm1.hostid, self.hosts)[0].clusterid + vm2clusterid = filter(lambda c: c.id == vm2.hostid, self.hosts)[0].clusterid + 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) ) @classmethod diff --git a/test/integration/smoke/test_network.py b/test/integration/smoke/test_network.py index a65748d2e97..a75ffeb8953 100644 --- a/test/integration/smoke/test_network.py +++ b/test/integration/smoke/test_network.py @@ -664,6 +664,32 @@ class TestLoadBalancingRule(cloudstackTestCase): cleanup_resources(cls.api_client, cls._cleanup) return + def try_ssh(self, src_nat_ip_addr, hostnames): + try: + self.debug( + "SSH into VM (IPaddress: %s) & NAT Rule (Public IP: %s)" % + (self.vm_1.ipaddress, src_nat_ip_addr.ipaddress) + ) + + ssh_1 = remoteSSHClient( + src_nat_ip_addr.ipaddress, + self.services['lbrule']["publicport"], + self.vm_1.username, + self.vm_1.password + ) + + # If Round Robin Algorithm is chosen, + # each ssh command should alternate between VMs + # hostnames = [ssh_1.execute("hostname")[0]] + hostnames.append(ssh_1.execute("hostname")[0]) + + except Exception as e: + self.fail("%s: SSH failed for VM with IP Address: %s" % + (e, src_nat_ip_addr.ipaddress)) + + time.sleep(self.services["lb_switch_wait"]) + return + @attr(tags = ["advanced", "advancedns", "smoke"]) def test_01_create_lb_rule_src_nat(self): """Test to create Load balancing rule with source NAT""" @@ -776,62 +802,33 @@ class TestLoadBalancingRule(cloudstackTestCase): [self.vm_1.id, self.vm_2.id], "Check List Load Balancer instances Rules returns valid VM ID" ) - try: - self.debug( - "SSH into VM (IPaddress: %s) & NAT Rule (Public IP: %s)" % - (self.vm_1.ipaddress, src_nat_ip_addr.ipaddress) - ) - ssh_1 = remoteSSHClient( - src_nat_ip_addr.ipaddress, - self.services['lbrule']["publicport"], - self.vm_1.username, - self.vm_1.password - ) - # If Round Robin Algorithm is chosen, - # each ssh command should alternate between VMs - hostnames = [ssh_1.execute("hostname")[0]] - except Exception as e: - self.fail("%s: SSH failed for VM with IP Address: %s" % - (e, src_nat_ip_addr.ipaddress)) + hostnames = [] + self.try_ssh(src_nat_ip_addr, hostnames) + self.try_ssh(src_nat_ip_addr, hostnames) + self.try_ssh(src_nat_ip_addr, hostnames) + self.try_ssh(src_nat_ip_addr, hostnames) + self.try_ssh(src_nat_ip_addr, hostnames) - time.sleep(self.services["lb_switch_wait"]) - - try: - self.debug("SSHing into IP address: %s after adding VMs (ID: %s , %s)" % - ( - src_nat_ip_addr.ipaddress, - self.vm_1.id, - self.vm_2.id - )) - - ssh_2 = remoteSSHClient( - src_nat_ip_addr.ipaddress, - self.services['lbrule']["publicport"], - self.vm_1.username, - self.vm_1.password - ) - hostnames.append(ssh_2.execute("hostname")[0]) - - except Exception as e: - self.fail("%s: SSH failed for VM with IP Address: %s" % - (e, src_nat_ip_addr.ipaddress)) - - self.debug("Hostnames: %s" % str(hostnames)) - self.assertIn( - self.vm_1.name, - hostnames, - "Check if ssh succeeded for server1" - ) - self.assertIn( - self.vm_2.name, - hostnames, - "Check if ssh succeeded for server2" - ) + self.debug("Hostnames: %s" % str(hostnames)) + self.assertIn( + self.vm_1.name, + hostnames, + "Check if ssh succeeded for server1" + ) + self.assertIn( + self.vm_2.name, + hostnames, + "Check if ssh succeeded for server2" + ) #SSH should pass till there is a last VM associated with LB rule lb_rule.remove(self.apiclient, [self.vm_2]) + + # making hostnames list empty + hostnames[:] = [] + try: self.debug("SSHing into IP address: %s after removing VM (ID: %s)" % ( @@ -839,25 +836,18 @@ class TestLoadBalancingRule(cloudstackTestCase): self.vm_2.id )) - ssh_1 = remoteSSHClient( - src_nat_ip_addr.ipaddress, - self.services['lbrule']["publicport"], - self.vm_1.username, - self.vm_1.password - ) + self.try_ssh(src_nat_ip_addr, hostnames) - hostnames.append(ssh_1.execute("hostname")[0]) - - except Exception as e: - self.fail("%s: SSH failed for VM with IP Address: %s" % - (e, src_nat_ip_addr.ipaddress)) - - self.assertIn( + self.assertIn( self.vm_1.name, hostnames, "Check if ssh succeeded for server1" ) + except Exception as e: + self.fail("%s: SSH failed for VM with IP Address: %s" % + (e, src_nat_ip_addr.ipaddress)) + lb_rule.remove(self.apiclient, [self.vm_1]) with self.assertRaises(Exception): @@ -967,50 +957,24 @@ class TestLoadBalancingRule(cloudstackTestCase): "Check List Load Balancer instances Rules returns valid VM ID" ) try: - self.debug("SSHing into IP address: %s after adding VMs (ID: %s , %s)" % - ( - self.non_src_nat_ip.ipaddress.ipaddress, - self.vm_1.id, - self.vm_2.id - )) - ssh_1 = remoteSSHClient( - self.non_src_nat_ip.ipaddress.ipaddress, - self.services['lbrule']["publicport"], - self.vm_1.username, - self.vm_1.password - ) + hostnames = [] + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) - # If Round Robin Algorithm is chosen, - # each ssh command should alternate between VMs - hostnames = [ssh_1.execute("hostname")[0]] - - time.sleep(self.services["lb_switch_wait"]) - - self.debug("SSHing again into IP address: %s with VMs (ID: %s , %s) added to LB rule" % - ( - self.non_src_nat_ip.ipaddress.ipaddress, - self.vm_1.id, - self.vm_2.id - )) - ssh_2 = remoteSSHClient( - self.non_src_nat_ip.ipaddress.ipaddress, - self.services['lbrule']["publicport"], - self.vm_1.username, - self.vm_1.password - ) - - hostnames.append(ssh_2.execute("hostname")[0]) - self.debug("Hostnames after adding 2 VMs to LB rule: %s" % str(hostnames)) - self.assertIn( + self.debug("Hostnames: %s" % str(hostnames)) + self.assertIn( self.vm_1.name, hostnames, "Check if ssh succeeded for server1" - ) - self.assertIn( + ) + self.assertIn( self.vm_2.name, hostnames, "Check if ssh succeeded for server2" - ) + ) #SSH should pass till there is a last VM associated with LB rule lb_rule.remove(self.apiclient, [self.vm_2]) @@ -1020,25 +984,23 @@ class TestLoadBalancingRule(cloudstackTestCase): self.non_src_nat_ip.ipaddress.ipaddress, self.vm_2.id )) - ssh_1 = remoteSSHClient( - self.non_src_nat_ip.ipaddress.ipaddress, - self.services['lbrule']["publicport"], - self.vm_1.username, - self.vm_1.password - ) + # Making host list empty + hostnames[:] = [] + + self.try_ssh(self.non_src_nat_ip, hostnames) + + self.assertIn( + self.vm_1.name, + hostnames, + "Check if ssh succeeded for server1" + ) - hostnames.append(ssh_1.execute("hostname")[0]) self.debug("Hostnames after removing VM2: %s" % str(hostnames)) + except Exception as e: self.fail("%s: SSH failed for VM with IP Address: %s" % (e, self.non_src_nat_ip.ipaddress.ipaddress)) - self.assertIn( - self.vm_1.name, - hostnames, - "Check if ssh succeeded for server1" - ) - lb_rule.remove(self.apiclient, [self.vm_1]) with self.assertRaises(Exception): self.debug("SSHing into IP address: %s after removing VM (ID: %s) from LB rule" % @@ -1209,7 +1171,7 @@ class TestRebootRouter(cloudstackTestCase): except Exception as e: self.fail( "SSH Access failed for %s: %s" % \ - (self.nat_rule.ipaddress.ipaddress, e)) + (self.vm_1.ipaddress, e)) return def tearDown(self): @@ -1277,6 +1239,36 @@ class TestAssignRemoveLB(cloudstackTestCase): ] return + def tearDown(self): + cleanup_resources(self.apiclient, self.cleanup) + return + + def try_ssh(self, src_nat_ip_addr, hostnames): + try: + self.debug( + "SSH into VM (IPaddress: %s) & NAT Rule (Public IP: %s)" % + (self.vm_1.ipaddress, src_nat_ip_addr.ipaddress) + ) + + ssh_1 = remoteSSHClient( + src_nat_ip_addr.ipaddress, + self.services['lbrule']["publicport"], + self.vm_1.username, + self.vm_1.password + ) + + # If Round Robin Algorithm is chosen, + # each ssh command should alternate between VMs + # hostnames = [ssh_1.execute("hostname")[0]] + hostnames.append(ssh_1.execute("hostname")[0]) + + except Exception as e: + self.fail("%s: SSH failed for VM with IP Address: %s" % + (e, src_nat_ip_addr.ipaddress)) + + time.sleep(self.services["lb_switch_wait"]) + return + @attr(tags = ["advanced", "advancedns", "smoke"]) def test_assign_and_removal_lb(self): """Test for assign & removing load balancing rule""" @@ -1344,137 +1336,74 @@ class TestAssignRemoveLB(cloudstackTestCase): ) lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2]) - try: - self.debug("SSHing into IP address: %s with VMs (ID: %s , %s) added to LB rule" % - ( - self.non_src_nat_ip.ipaddress, - self.vm_1.id, - self.vm_2.id - )) - #Create SSH client for each VM - ssh_1 = remoteSSHClient( - self.non_src_nat_ip.ipaddress, - self.services["lbrule"]["publicport"], - self.vm_1.username, - self.vm_1.password - ) - except Exception as e: - self.fail("SSH failed for VM with IP: %s" % - self.non_src_nat_ip.ipaddress) + hostnames = [] + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) - try: - self.debug("SSHing again into IP address: %s with VMs (ID: %s , %s) added to LB rule" % - ( - self.non_src_nat_ip.ipaddress, - self.vm_1.id, - self.vm_2.id - )) - ssh_2 = remoteSSHClient( - self.non_src_nat_ip.ipaddress, - self.services["lbrule"]["publicport"], - self.vm_2.username, - self.vm_2.password - ) + self.debug("Hostnames: %s" % str(hostnames)) + self.assertIn( + self.vm_1.name, + hostnames, + "Check if ssh succeeded for server1" + ) + self.assertIn( + self.vm_2.name, + hostnames, + "Check if ssh succeeded for server2" + ) - # If Round Robin Algorithm is chosen, - # each ssh command should alternate between VMs - res_1 = ssh_1.execute("hostname")[0] - self.debug(res_1) - - time.sleep(self.services["lb_switch_wait"]) - - res_2 = ssh_2.execute("hostname")[0] - self.debug(res_2) - - except Exception as e: - self.fail("SSH failed for VM with IP: %s" % - self.non_src_nat_ip.ipaddress) - - self.assertIn( - self.vm_1.name, - res_1, - "Check if ssh succeeded for server1" - ) - self.assertIn( - self.vm_2.name, - res_2, - "Check if ssh succeeded for server2" - ) #Removing VM and assigning another VM to LB rule lb_rule.remove(self.apiclient, [self.vm_2]) + # making hostnames list empty + hostnames[:] = [] + try: self.debug("SSHing again into IP address: %s with VM (ID: %s) added to LB rule" % ( self.non_src_nat_ip.ipaddress, self.vm_1.id, )) - # Again make a SSH connection, as previous is not used after LB remove - ssh_1 = remoteSSHClient( - self.non_src_nat_ip.ipaddress, - self.services["lbrule"]["publicport"], - self.vm_1.username, - self.vm_1.password - ) - res_1 = ssh_1.execute("hostname")[0] - self.debug(res_1) + self.try_ssh(self.non_src_nat_ip, hostnames) + + self.assertIn( + self.vm_1.name, + hostnames, + "Check if ssh succeeded for server1" + ) except Exception as e: self.fail("SSH failed for VM with IP: %s" % self.non_src_nat_ip.ipaddress) - self.assertIn( - self.vm_1.name, - res_1, - "Check if ssh succeeded for server1" - ) - lb_rule.assign(self.apiclient, [self.vm_3]) - try: - ssh_1 = remoteSSHClient( - self.non_src_nat_ip.ipaddress, - self.services["lbrule"]["publicport"], - self.vm_1.username, - self.vm_1.password - ) - ssh_3 = remoteSSHClient( - self.non_src_nat_ip.ipaddress, - self.services["lbrule"]["publicport"], - self.vm_3.username, - self.vm_3.password - ) + # Making hostnames list empty + hostnames[:] = [] - res_1 = ssh_1.execute("hostname")[0] - self.debug(res_1) + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip, hostnames) - time.sleep(self.services["lb_switch_wait"]) - - res_3 = ssh_3.execute("hostname")[0] - self.debug(res_3) - - except Exception as e: - self.fail("SSH failed for VM with IP: %s" % - self.non_src_nat_ip.ipaddress) - - self.assertIn( - self.vm_1.name, - res_1, - "Check if ssh succeeded for server1" - ) - self.assertIn( - self.vm_3.name, - res_3, - "Check if ssh succeeded for server3" - ) + self.debug("Hostnames: %s" % str(hostnames)) + self.assertIn( + self.vm_1.name, + hostnames, + "Check if ssh succeeded for server1" + ) + self.assertIn( + self.vm_3.name, + hostnames, + "Check if ssh succeeded for server3" + ) return - def tearDown(self): - cleanup_resources(self.apiclient, self.cleanup) - return - - class TestReleaseIP(cloudstackTestCase): def setUp(self): @@ -1734,6 +1663,9 @@ class TestDeleteAccount(cloudstackTestCase): None, "Check routers are properly deleted." ) + except cloudstackAPIException: + self.debug("Router is deleted") + except Exception as e: raise Exception( "Encountered %s raised while fetching routers for account: %s" % (e, diff --git a/test/integration/smoke/test_vm_life_cycle.py b/test/integration/smoke/test_vm_life_cycle.py index afe9b8a6331..9aaa13fcb57 100644 --- a/test/integration/smoke/test_vm_life_cycle.py +++ b/test/integration/smoke/test_vm_life_cycle.py @@ -687,10 +687,12 @@ class TestVMLifeCycle(cloudstackTestCase): else: break + self.debug("listVirtualMachines response: %s" % list_vm_response) + self.assertEqual( list_vm_response, None, - "Check Expunged virtual machine is listVirtualMachines" + "Check Expunged virtual machine is in listVirtualMachines response" ) return diff --git a/tools/apidoc/generateadmincommands.xsl b/tools/apidoc/generateadmincommands.xsl index a33e7baf20d..9abec10a4fb 100644 --- a/tools/apidoc/generateadmincommands.xsl +++ b/tools/apidoc/generateadmincommands.xsl @@ -150,10 +150,10 @@ version="1.0"> + Apache, CloudStack, Apache CloudStack, the Apache CloudStack logo, the CloudMonkey logo and the Apache feather logo are trademarks of The Apache Software Foundation.

+ diff --git a/tools/apidoc/generatecommand.xsl b/tools/apidoc/generatecommand.xsl index b665cf36f7d..965a3a334d1 100644 --- a/tools/apidoc/generatecommand.xsl +++ b/tools/apidoc/generatecommand.xsl @@ -179,9 +179,9 @@ version="1.0">
  • Contacts
  • -

    Copyright © 2012 The Apache Software Foundation, Licensed under the +

    Copyright © 2013 The Apache Software Foundation, Licensed under the Apache License, Version 2.0.
    - Apache and the Apache feather logo are trademarks of The Apache Software Foundation.

    + Apache, CloudStack, Apache CloudStack, the Apache CloudStack logo, the CloudMonkey logo and the Apache feather logo are trademarks of The Apache Software Foundation.

    diff --git a/tools/apidoc/generatedomainadmincommands.xsl b/tools/apidoc/generatedomainadmincommands.xsl index 7f5321cc06e..7238f05369f 100644 --- a/tools/apidoc/generatedomainadmincommands.xsl +++ b/tools/apidoc/generatedomainadmincommands.xsl @@ -144,9 +144,9 @@ version="1.0"> diff --git a/tools/apidoc/generatetoc_footer.xsl b/tools/apidoc/generatetoc_footer.xsl index cf6dbc4c7b3..93a86671084 100644 --- a/tools/apidoc/generatetoc_footer.xsl +++ b/tools/apidoc/generatetoc_footer.xsl @@ -26,9 +26,9 @@ under the License. diff --git a/tools/apidoc/generateusercommands.xsl b/tools/apidoc/generateusercommands.xsl index e884ab13ac3..4fa1f867fe5 100644 --- a/tools/apidoc/generateusercommands.xsl +++ b/tools/apidoc/generateusercommands.xsl @@ -142,9 +142,9 @@ version="1.0"> diff --git a/tools/apidoc/images/cloudstack.png b/tools/apidoc/images/cloudstack.png index cc3c9d7d342..2f3d899701a 100644 Binary files a/tools/apidoc/images/cloudstack.png and b/tools/apidoc/images/cloudstack.png differ diff --git a/tools/apidoc/images/ins_buttonshadow.gif b/tools/apidoc/images/ins_buttonshadow.gif deleted file mode 100644 index ac34ec859c9..00000000000 Binary files a/tools/apidoc/images/ins_buttonshadow.gif and /dev/null differ diff --git a/tools/apidoc/images/insdownload_button.gif b/tools/apidoc/images/insdownload_button.gif deleted file mode 100644 index eb5cb5e700f..00000000000 Binary files a/tools/apidoc/images/insdownload_button.gif and /dev/null differ diff --git a/tools/apidoc/images/insdownload_button_hover.gif b/tools/apidoc/images/insdownload_button_hover.gif deleted file mode 100644 index 424ab461f52..00000000000 Binary files a/tools/apidoc/images/insdownload_button_hover.gif and /dev/null differ diff --git a/tools/apidoc/images/insjoincomm_button.gif b/tools/apidoc/images/insjoincomm_button.gif deleted file mode 100644 index f149c8506c1..00000000000 Binary files a/tools/apidoc/images/insjoincomm_button.gif and /dev/null differ diff --git a/tools/apidoc/images/insjoincomm_button_hover.gif b/tools/apidoc/images/insjoincomm_button_hover.gif deleted file mode 100644 index 74df0a60e64..00000000000 Binary files a/tools/apidoc/images/insjoincomm_button_hover.gif and /dev/null differ diff --git a/tools/apidoc/includes/main.css b/tools/apidoc/includes/main.css index a8fa348065b..1c3baa871db 100644 --- a/tools/apidoc/includes/main.css +++ b/tools/apidoc/includes/main.css @@ -239,7 +239,7 @@ a:hover.insdownload_button { a.cloud_logo { - width:300px; + width:373px; height:51px; float:left; background:url(../images/cloudstack.png) no-repeat top left; diff --git a/tools/appliance/build.sh b/tools/appliance/build.sh index 0216c067a45..b546c3f8f55 100644 --- a/tools/appliance/build.sh +++ b/tools/appliance/build.sh @@ -46,7 +46,7 @@ done # Get appliance uuids machine_uuid=`vboxmanage showvminfo $appliance | grep UUID | head -1 | awk '{print $2}'` hdd_uuid=`vboxmanage showvminfo $appliance | grep vdi | head -1 | awk '{print $8}' | cut -d ')' -f 1` -hdd_path=`vboxmanage list hdds | grep $appliance | grep vdi | cut -c 14-` +hdd_path=`vboxmanage list hdds | grep "$appliance\/" | grep vdi | cut -c 14-` # Remove any shared folder shared_folders=`vboxmanage showvminfo $appliance | grep Name | grep Host` @@ -67,7 +67,7 @@ mkdir dist set -e # Export for Xen -vboxmanage internalcommands converttoraw "$hdd_path" img.raw +vboxmanage internalcommands converttoraw -format vdi "$hdd_path" img.raw faketime '2010-01-01' vhd-util convert -s 0 -t 1 -i img.raw -o stagefixed.vhd faketime '2010-01-01' vhd-util convert -s 1 -t 2 -i stagefixed.vhd -o $appliance-$build_date-$branch-xen.vhd rm *.bak @@ -75,7 +75,7 @@ bzip2 $appliance-$build_date-$branch-xen.vhd echo "$appliance exported for Xen: dist/$appliance-$build_date-$branch-xen.vhd.bz2" # Export for KVM -vboxmanage internalcommands converttoraw "$hdd_path" raw.img +vboxmanage internalcommands converttoraw -format vdi "$hdd_path" raw.img qemu-img convert -f raw -c -O qcow2 raw.img $appliance-$build_date-$branch-kvm.qcow2 rm raw.img bzip2 $appliance-$build_date-$branch-kvm.qcow2 diff --git a/ui/index.jsp b/ui/index.jsp index 2992afb5c31..34f0c54175b 100644 --- a/ui/index.jsp +++ b/ui/index.jsp @@ -1698,7 +1698,6 @@ under the License. - diff --git a/ui/scripts/configuration.js b/ui/scripts/configuration.js index cb15598d5b8..cadde8c91a7 100644 --- a/ui/scripts/configuration.js +++ b/ui/scripts/configuration.js @@ -1228,8 +1228,11 @@ } }); } - $providers.each(function() { - $(this).val($(this).find('option:first')); + $providers.each(function() { + //if selected option is disabled, select the first enabled option instead + if($(this).find('option:selected:disabled').length > 0) { + $(this).val($(this).find('option:first')); + } }); diff --git a/ui/scripts/instances.js b/ui/scripts/instances.js index 71498156730..54b3187680e 100644 --- a/ui/scripts/instances.js +++ b/ui/scripts/instances.js @@ -640,9 +640,14 @@ name: { label: 'label.name' }, type: { label: 'label.type' } }, - dataProvider: function(args) { + dataProvider: function(args) { + var data = { + domainid: args.context.instances[0].domainid, + account: args.context.instances[0].account + }; $.ajax({ url: createURL('listAffinityGroups'), + data: data, async: false, //make it sync to avoid dataProvider() being called twice which produces duplicate data success: function(json) { var items = []; @@ -1513,6 +1518,7 @@ args.response.success({ _custom: { jobId: json.updatedefaultnicforvirtualmachineresponse.jobid } }); + cloudStack.dialog.notice({message:_l('Please manually update the default NIC on the VM now.')}); } }); }, @@ -1670,8 +1676,8 @@ networkkbswrite: (jsonObj.networkkbswrite == null)? "N/A": cloudStack.converters.convertBytes(jsonObj.networkkbswrite * 1024), diskkbsread: (jsonObj.diskkbsread == null)? "N/A": cloudStack.converters.convertBytes(jsonObj.diskkbsread * 1024), diskkbswrite: (jsonObj.diskkbswrite == null)? "N/A": cloudStack.converters.convertBytes(jsonObj.diskkbswrite * 1024), - diskioread: (jsonObj.diskioread == null)? "N/A": cloudStack.converters.convertBytes(jsonObj.diskioread * 1024), - diskiowrite: (jsonObj.diskiowrite == null)? "N/A": cloudStack.converters.convertBytes(jsonObj.diskiowrite * 1024) + diskioread: (jsonObj.diskioread == null)? "N/A": jsonObj.diskioread, + diskiowrite: (jsonObj.diskiowrite == null)? "N/A": jsonObj.diskiowrite } }); } diff --git a/ui/scripts/network.js b/ui/scripts/network.js index 9e60cbcc20f..fb63e4b4f19 100755 --- a/ui/scripts/network.js +++ b/ui/scripts/network.js @@ -320,8 +320,8 @@ title: 'label.guest.networks', listView: { actions: { - add: { //add Isolated guest network (can't add Shared guest network here) - label: 'Add Isolated Guest Network', + add: { + label: 'Add Isolated Guest Network with SourceNat', preFilter: function(args) { //Isolated networks is only supported in Advanced (SG-disabled) zone if(args.context.zoneType != 'Basic') @@ -331,8 +331,7 @@ }, createForm: { - title: 'Add Isolated Guest Network', - desc: 'Add Isolated Guest Network with SourceNat', + title: 'Add Isolated Guest Network with SourceNat', fields: { name: { label: 'label.name', validation: { required: true }, docID: 'helpGuestNetworkName' }, displayText: { label: 'label.display.text', validation: { required: true }, docID: 'helpGuestNetworkDisplayText'}, @@ -545,7 +544,8 @@ name: { label: 'label.name' }, account: { label: 'label.account' }, type: { label: 'label.type' }, - cidr: { label: 'label.cidr' } + cidr: { label: 'label.cidr' }, + ip6cidr: { label: 'IPv6 CIDR' } }, advSearchFields: { diff --git a/ui/scripts/system.js b/ui/scripts/system.js index a72b520472c..a3db63a7055 100644 --- a/ui/scripts/system.js +++ b/ui/scripts/system.js @@ -1340,7 +1340,7 @@ docID: 'helpGuestNetworkZoneVLANID' }, isolatedpvlanId: { - label: 'Private VLAN ID' + label: 'Secondary Isolated VLAN ID' }, scope: { @@ -7899,7 +7899,13 @@ lbdevicededicated: { label: 'label.dedicated', converter: cloudStack.converters.toBooleanText - } + }, + gslbprovider: { + label: 'GSLB service', + converter: cloudStack.converters.toBooleanText + }, + gslbproviderpublicip: { label: 'GSLB service Public IP' }, + gslbproviderprivateip: { label: 'GSLB service Private IP' } } ], dataProvider: function(args) { diff --git a/ui/scripts/ui-custom/projectSelect.js b/ui/scripts/ui-custom/projectSelect.js index 82d02c174b7..aef49ed23e5 100644 --- a/ui/scripts/ui-custom/projectSelect.js +++ b/ui/scripts/ui-custom/projectSelect.js @@ -32,9 +32,9 @@ var projects = args.data; $(projects).map(function(index, project) { - var $option = $('