diff --git a/agent/conf/agent.properties b/agent/conf/agent.properties index 27572b53653..74cfd1c21d6 100644 --- a/agent/conf/agent.properties +++ b/agent/conf/agent.properties @@ -69,3 +69,14 @@ domr.scripts.dir=scripts/network/domr/kvm # set the vm migrate speed, by default, it will try to guess the speed of the guest network # In MegaBytes per second #vm.migrate.speed=0 + +# set the type of bridge used on the hypervisor, this defines what commands the resource +# will use to setup networking. Currently supported NATIVE, OPENVSWITCH +#network.bridge.type=native + +# set the driver used to plug and unplug nics from the bridges +# a sensible default will be selected based on the network.bridge.type but can +# be overridden here. +# native = com.cloud.hypervisor.kvm.resource.BridgeVifDriver +# openvswitch = com.cloud.hypervisor.kvm.resource.OvsBridgeDriver +#libvirt.vif.driver=com.cloud.hypervisor.kvm.resource.BridgeVifDriver \ No newline at end of file diff --git a/api/src/com/cloud/dao/EntityManager.java b/api/src/com/cloud/dao/EntityManager.java index 4e4b9c293b5..b8fdaa7e9a7 100644 --- a/api/src/com/cloud/dao/EntityManager.java +++ b/api/src/com/cloud/dao/EntityManager.java @@ -47,6 +47,15 @@ public interface EntityManager { */ public T findByUuid(Class entityType, String uuid); + /** + * Finds a unique entity by uuid string + * @param entity class + * @param entityType type of entity you're looking for. + * @param uuid the unique id + * @return T if found, null if not. + */ + public T findByUuidIncludingRemoved(Class entityType, String uuid); + /** * Finds an entity by external id which is always String * @param entity class diff --git a/api/src/com/cloud/resource/ResourceService.java b/api/src/com/cloud/resource/ResourceService.java index b9db8e734d9..7348a5a6867 100755 --- a/api/src/com/cloud/resource/ResourceService.java +++ b/api/src/com/cloud/resource/ResourceService.java @@ -34,6 +34,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.org.Cluster; import com.cloud.storage.S3; import com.cloud.storage.Swift; +import com.cloud.utils.Pair; import com.cloud.utils.fsm.NoTransitionException; import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd; @@ -94,10 +95,10 @@ public interface ResourceService { Swift discoverSwift(AddSwiftCmd addSwiftCmd) throws DiscoveryException; S3 discoverS3(AddS3Cmd cmd) throws DiscoveryException; - + List getSupportedHypervisorTypes(long zoneId, boolean forVirtualRouter, Long podId); - List listSwifts(ListSwiftsCmd cmd); + Pair, Integer> listSwifts(ListSwiftsCmd cmd); List listS3s(ListS3sCmd cmd); diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index 3bc7f934c04..32c2b053047 100755 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -93,16 +93,6 @@ import com.cloud.vm.VirtualMachine.Type; public interface ManagementService { static final String Name = "management-server"; - /** - * Retrieves the list of data centers with search criteria. Currently the only search criteria is "available" zones - * for the - * account that invokes the API. By specifying available=true all zones which the account can access. By specifying - * available=false the zones where the account has virtual machine instances will be returned. - * - * @return a list of DataCenters - */ - List listDataCenters(ListZonesByCmd cmd); - /** * returns the a map of the names/values in the configuraton table * diff --git a/api/src/org/apache/cloudstack/api/BaseListAccountResourcesCmd.java b/api/src/org/apache/cloudstack/api/BaseListAccountResourcesCmd.java index 038da63ec4c..0586117f0c6 100644 --- a/api/src/org/apache/cloudstack/api/BaseListAccountResourcesCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseListAccountResourcesCmd.java @@ -18,7 +18,7 @@ package org.apache.cloudstack.api; public abstract class BaseListAccountResourcesCmd extends BaseListDomainResourcesCmd { - @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "List resources by account. Must be used with the domainId parameter.") + @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "list resources by account. Must be used with the domainId parameter.") private String accountName; public String getAccountName() { diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java index 6733a35a5fd..9d3ceb828e1 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Map; import org.apache.cloudstack.api.*; -import org.apache.cloudstack.api.response.DiskOfferingResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; @@ -69,7 +69,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd { @Parameter(name=ApiConstants.CONSERVE_MODE, type=CommandType.BOOLEAN, description="true if the network offering is IP conserve mode enabled") private Boolean conserveMode; - @Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.UUID, entityType=DiskOfferingResponse.class, + @Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.UUID, entityType=ServiceOfferingResponse.class, description="the service offering ID used by virtual router provider") private Long serviceOfferingId; diff --git a/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java index d7c151188e7..af266437932 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java @@ -30,6 +30,7 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.SwiftResponse; import com.cloud.storage.Swift; import com.cloud.user.Account; +import com.cloud.utils.Pair; @APICommand(name = "listSwifts", description = "List Swift.", responseObject = HostResponse.class, since="3.0.0") public class ListSwiftsCmd extends BaseListCmd { @@ -64,20 +65,19 @@ public class ListSwiftsCmd extends BaseListCmd { @Override public void execute(){ - List result = _resourceService.listSwifts(this); + Pair, Integer> result = _resourceService.listSwifts(this); ListResponse response = new ListResponse(); List swiftResponses = new ArrayList(); if (result != null) { - SwiftResponse swiftResponse = null; - for (Swift swift : result) { - swiftResponse = _responseGenerator.createSwiftResponse(swift); + for (Swift swift : result.first()) { + SwiftResponse swiftResponse = _responseGenerator.createSwiftResponse(swift); swiftResponse.setResponseName(getCommandName()); swiftResponse.setObjectName("swift"); swiftResponses.add(swiftResponse); } } - response.setResponses(swiftResponses); + response.setResponses(swiftResponses, result.second()); response.setResponseName(getCommandName()); this.setResponseObject(response); } diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java index 2a0b2c61617..89e72920db0 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java @@ -47,7 +47,7 @@ public class AttachIsoCmd extends BaseAsyncCmd { required=true, description="the ID of the ISO file") private Long id; - @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = TemplateResponse.class, + @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = UserVmResponse.class, required=true, description="the ID of the virtual machine") private Long virtualMachineId; diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java index c8a87cbdb3e..2a6ecf4ce10 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java @@ -42,7 +42,7 @@ public class DetachIsoCmd extends BaseAsyncCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = TemplateResponse.class, + @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = UserVmResponse.class, required=true, description="The ID of the virtual machine") private Long virtualMachineId; diff --git a/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java index 406f32cc958..f865dd6d493 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java @@ -51,7 +51,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd { required=true, description="ID of the zone the template is being copied to.") private Long destZoneId; - @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = UserVmResponse.class, + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = TemplateResponse.class, required=true, description="Template ID.") private Long id; diff --git a/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java index 8ee3041713c..12359bfe9ac 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java @@ -17,7 +17,7 @@ package org.apache.cloudstack.api.command.user.template; import org.apache.cloudstack.api.*; -import org.apache.cloudstack.api.response.UserVmResponse; +import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; @@ -38,7 +38,7 @@ public class DeleteTemplateCmd extends BaseAsyncCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = UserVmResponse.class, + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = TemplateResponse.class, required=true, description="the ID of the template") private Long id; diff --git a/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java index 54f3e3782fb..8b4e809f247 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java @@ -17,7 +17,7 @@ package org.apache.cloudstack.api.command.user.template; import org.apache.cloudstack.api.*; -import org.apache.cloudstack.api.response.UserVmResponse; +import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; @@ -40,7 +40,7 @@ public class ExtractTemplateCmd extends BaseAsyncCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = UserVmResponse.class, + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = TemplateResponse.class, required=true, description="the ID of the template") private Long id; diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java index 6d3c8bd06c7..2501574f241 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java @@ -64,15 +64,6 @@ public class ListVPCsCmd extends BaseListTaggedResourcesCmd{ , description="list by ID of the VPC offering") private Long VpcOffId; - @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="list by account associated with the VPC. " + - "Must be used with the domainId parameter.") - private String accountName; - - @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType=DomainResponse.class, - description="list by domain ID associated with the VPC. " + - "If used with the account parameter returns the VPC associated with the account for the specified domain.") - private Long domainId; - @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, description="list VPC supporting certain services") private List supportedServices; @@ -87,14 +78,6 @@ public class ListVPCsCmd extends BaseListTaggedResourcesCmd{ /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - public String getAccountName() { - return accountName; - } - - public Long getDomainId() { - return domainId; - } - public Long getZoneId() { return zoneId; } diff --git a/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java b/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java index 5f5f9e7bda0..ccacf060b19 100644 --- a/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java @@ -27,6 +27,7 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.cloudstack.api.response.ZoneResponse; import com.cloud.dc.DataCenter; @@ -86,16 +87,8 @@ public class ListZonesByCmd extends BaseListCmd { @Override public void execute(){ - List dataCenters = _mgr.listDataCenters(this); - ListResponse response = new ListResponse(); - List zoneResponses = new ArrayList(); - for (DataCenter dataCenter : dataCenters) { - ZoneResponse zoneResponse = _responseGenerator.createZoneResponse(dataCenter, showCapacities); - zoneResponse.setObjectName("zone"); - zoneResponses.add(zoneResponse); - } - response.setResponses(zoneResponses); + ListResponse response = _queryService.listDataCenters(this); response.setResponseName(getCommandName()); this.setResponseObject(response); } diff --git a/api/src/org/apache/cloudstack/api/response/ZoneResponse.java b/api/src/org/apache/cloudstack/api/response/ZoneResponse.java index 72e0bb2844d..ca1cb57629c 100644 --- a/api/src/org/apache/cloudstack/api/response/ZoneResponse.java +++ b/api/src/org/apache/cloudstack/api/response/ZoneResponse.java @@ -65,8 +65,8 @@ public class ZoneResponse extends BaseResponse { @SerializedName(ApiConstants.DOMAIN) @Param(description="Network domain name for the networks in the zone") private String domain; - @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the ID of the containing domain, null for public zones") - private Long domainId; + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the UUID of the containing domain, null for public zones") + private String domainId; @SerializedName("domainname") @Param(description="the name of the containing domain, null for public zones") private String domainName; @@ -140,7 +140,7 @@ public class ZoneResponse extends BaseResponse { this.domain = domain; } - public void setDomainId(Long domainId) { + public void setDomainId(String domainId) { this.domainId = domainId; } diff --git a/api/src/org/apache/cloudstack/query/QueryService.java b/api/src/org/apache/cloudstack/query/QueryService.java index add9d23943c..f3f6d3d5645 100644 --- a/api/src/org/apache/cloudstack/query/QueryService.java +++ b/api/src/org/apache/cloudstack/query/QueryService.java @@ -35,6 +35,7 @@ import org.apache.cloudstack.api.command.user.tag.ListTagsCmd; import org.apache.cloudstack.api.command.user.vm.ListVMsCmd; import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd; import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd; +import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.AsyncJobResponse; import org.apache.cloudstack.api.response.DiskOfferingResponse; @@ -53,6 +54,7 @@ import org.apache.cloudstack.api.response.StoragePoolResponse; 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; @@ -100,4 +102,6 @@ public interface QueryService { public ListResponse searchForDiskOfferings(ListDiskOfferingsCmd cmd); public ListResponse searchForServiceOfferings(ListServiceOfferingsCmd cmd); + + public ListResponse listDataCenters(ListZonesByCmd cmd); } diff --git a/docs/en-US/host-add-xenserver-kvm-ovm.xml b/docs/en-US/host-add-xenserver-kvm-ovm.xml index 4bbeefcbed4..1f13e72d4c3 100644 --- a/docs/en-US/host-add-xenserver-kvm-ovm.xml +++ b/docs/en-US/host-add-xenserver-kvm-ovm.xml @@ -83,6 +83,11 @@ Make sure the new host has the same network configuration (guest, private, and public network) as other hosts in the cluster. + + If you are using OpenVswitch bridges edit the file agent.properties on the KVM host + and set the parameter network.bridge.type to + openvswitch before adding the host to &PRODUCT; + + +
+ Configure the network using OpenVswitch + This is a very important section, please make sure you read this thoroughly. + In order to forward traffic to your instances you will need at least two bridges: public and private. + By default these bridges are called cloudbr0 and cloudbr1, but you do have to make sure they are available on each hypervisor. + The most important factor is that you keep the configuration consistent on all your hypervisors. +
+ Preparing + To make sure that the native bridge module will not interfere with openvswitch the bridge module should be added to the blacklist. See the modprobe documentation for your distribution on where to find the blacklist. Make sure the module is not loaded either by rebooting or executing rmmod bridge before executing next steps. + The network configurations below depend on the ifup-ovs and ifdown-ovs scripts which are part of the openvswitch installation. They should be installed in /etc/sysconfig/network-scripts/ +
+
+ Network example + There are many ways to configure your network. In the Basic networking mode you should have two (V)LAN's, one for your private network and one for the public network. + We assume that the hypervisor has one NIC (eth0) with three tagged VLAN's: + + VLAN 100 for management of the hypervisor + VLAN 200 for public network of the instances (cloudbr0) + VLAN 300 for private network of the instances (cloudbr1) + + On VLAN 100 we give the Hypervisor the IP-Address 192.168.42.11/24 with the gateway 192.168.42.1 + The Hypervisor and Management server don't have to be in the same subnet! +
+
+ Configuring the network bridges + It depends on the distribution you are using how to configure these, below you'll find + examples for RHEL/CentOS. + The goal is to have three bridges called 'mgmt0', 'cloudbr0' and 'cloudbr1' after this + section. This should be used as a guideline only. The exact configuration will + depend on your network layout. +
+ Configure OpenVswitch + The network interfaces using OpenVswitch are created using the ovs-vsctl command. This command will configure the interfaces and persist them to the OpenVswitch database. + First we create a main bridge connected to the eth0 interface. Next we create three fake bridges, each connected to a specific vlan tag. + +
+
+ Configure in RHEL or CentOS + The required packages were installed when openvswitch and libvirt were installed, + we can proceed to configuring the network. + First we configure eth0 + vi /etc/sysconfig/network-scripts/ifcfg-eth0 + Make sure it looks similair to: + + We have to configure the base bridge with the trunk. + vi /etc/sysconfig/network-scripts/ifcfg-cloudbr + + We now have to configure the three VLAN bridges: + vi /etc/sysconfig/network-scripts/ifcfg-mgmt0 + + vi /etc/sysconfig/network-scripts/ifcfg-cloudbr0 + + vi /etc/sysconfig/network-scripts/ifcfg-cloudbr1 + + With this configuration you should be able to restart the network, although a reboot is recommended to see if everything works properly. + Make sure you have an alternative way like IPMI or ILO to reach the machine in case you made a configuration error and the network stops functioning! +
+
+
diff --git a/docs/en-US/hypervisor-host-install-network.xml b/docs/en-US/hypervisor-host-install-network.xml index 8f6a10cdd69..3a6dfac48bd 100644 --- a/docs/en-US/hypervisor-host-install-network.xml +++ b/docs/en-US/hypervisor-host-install-network.xml @@ -25,6 +25,7 @@
Configure the network bridges This is a very important section, please make sure you read this thoroughly. + This section details how to configure bridges using the native implementation in Linux. Please refer to the next section if you intend to use OpenVswitch In order to forward traffic to your instances you will need at least two bridges: public and private. By default these bridges are called cloudbr0 and cloudbr1, but you do have to make sure they are available on each hypervisor. The most important factor is that you keep the configuration consistent on all your hypervisors. @@ -146,4 +147,4 @@ iface cloudbr1 inet manual Make sure you have an alternative way like IPMI or ILO to reach the machine in case you made a configuration error and the network stops functioning!
- \ No newline at end of file + diff --git a/docs/en-US/hypervisor-kvm-install-flow.xml b/docs/en-US/hypervisor-kvm-install-flow.xml index 76e03ef7919..6cc73e4fdfa 100644 --- a/docs/en-US/hypervisor-kvm-install-flow.xml +++ b/docs/en-US/hypervisor-kvm-install-flow.xml @@ -1,5 +1,5 @@ - %BOOK_ENTITIES; ]> @@ -31,6 +31,7 @@ + diff --git a/docs/en-US/hypervisor-kvm-requirements.xml b/docs/en-US/hypervisor-kvm-requirements.xml index c42db86a2b8..cdfc808e490 100644 --- a/docs/en-US/hypervisor-kvm-requirements.xml +++ b/docs/en-US/hypervisor-kvm-requirements.xml @@ -1,5 +1,5 @@ - %BOOK_ENTITIES; ]> @@ -35,6 +35,11 @@ libvirt: 0.9.4 or higher Qemu/KVM: 1.0 or higher + The default bridge in &PRODUCT; is the Linux native bridge implementation (bridge module). &PRODUCT; includes an option to work with OpenVswitch, the requirements are listed below + + libvirt: 0.9.11 or higher + openvswitch: 1.7.1 or higher + In addition, the following hardware requirements apply: Within a single cluster, the hosts must be of the same distribution version. diff --git a/docs/en-US/offerings.xml b/docs/en-US/offerings.xml index 10252fd8af4..ca6312d7bfe 100644 --- a/docs/en-US/offerings.xml +++ b/docs/en-US/offerings.xml @@ -1,25 +1,22 @@ - %BOOK_ENTITIES; ]> - @@ -28,4 +25,5 @@ are discussed in the section on setting up networking for users. + diff --git a/docs/en-US/plugin-niciranvp-features.xml b/docs/en-US/plugin-niciranvp-features.xml index b67323d56d2..b71e67f4199 100644 --- a/docs/en-US/plugin-niciranvp-features.xml +++ b/docs/en-US/plugin-niciranvp-features.xml @@ -24,6 +24,10 @@ Features of the Nicira NVP Plugin In CloudStack release 4.0.0-incubating this plugin supports the Connectivity service. This service is responsible for creating Layer 2 networks supporting the networks created by Guests. In other words when an tennant creates a new network, instead of the traditional VLAN a logical network will be created by sending the appropriate calls to the Nicira NVP Controller. The plugin has been tested with Nicira NVP versions 2.1.0, 2.2.0 and 2.2.1 - In CloudStack 4.0.0-incubating only the XenServer hypervisor is supported for use in combination with Nicira NVP - In CloudStack 4.0.0-incubating the UI components for this plugin are not complete, configuration is done by sending commands to the API + In CloudStack 4.0.0-incubating only the XenServer hypervisor is supported for use in + combination with Nicira NVP. + In CloudStack 4.1.0-incubating both KVM and XenServer hypervisors are + supported. + In CloudStack 4.0.0-incubating the UI components for this plugin are not complete, + configuration is done by sending commands to the API. diff --git a/docs/en-US/plugin-niciranvp-preparations.xml b/docs/en-US/plugin-niciranvp-preparations.xml index 95a25bdca26..86b795ccd0b 100644 --- a/docs/en-US/plugin-niciranvp-preparations.xml +++ b/docs/en-US/plugin-niciranvp-preparations.xml @@ -24,7 +24,9 @@ Prerequisites Before enabling the Nicira NVP plugin the NVP Controller needs to be configured. Please review the NVP User Guide on how to do that. CloudStack needs to have at least one physical network with the isolation method set to "STT". This network should be enabled for the Guest traffic type. - The Guest traffic type should be configured with the traffic label that matches the name of the Integration Bridge on XenServer. See the Nicira NVP User Guide for more details on how to set this up in XenServer. + The Guest traffic type should be configured with the traffic label that matches the name of + the Integration Bridge on the hypervisor. See the Nicira NVP User Guide for more details + on how to set this up in XenServer or KVM. Make sure you have the following information ready: The IP address of the NVP Controller diff --git a/docs/en-US/plugin-niciranvp-ui.xml b/docs/en-US/plugin-niciranvp-ui.xml new file mode 100644 index 00000000000..8b1bbad8395 --- /dev/null +++ b/docs/en-US/plugin-niciranvp-ui.xml @@ -0,0 +1,26 @@ + + +%BOOK_ENTITIES; + +%xinclude; +]> + +
+ Configuring the Nicira NVP plugin from the UI + In CloudStack 4.1.0-incubating the Nicira NVP plugin and its resources can be configured in the infrastructure tab of the UI. Navigate to the physical network with STT isolation and configure the network elements. The NiciraNvp is listed here. +
diff --git a/docs/en-US/plugin-niciranvp-usage.xml b/docs/en-US/plugin-niciranvp-usage.xml index 17413387ea4..76f9a0b5b05 100644 --- a/docs/en-US/plugin-niciranvp-usage.xml +++ b/docs/en-US/plugin-niciranvp-usage.xml @@ -24,6 +24,7 @@ Using the Nicira NVP Plugin + diff --git a/docs/en-US/sys-offering-sysvm.xml b/docs/en-US/sys-offering-sysvm.xml new file mode 100644 index 00000000000..cccf3e04796 --- /dev/null +++ b/docs/en-US/sys-offering-sysvm.xml @@ -0,0 +1,75 @@ + + +%BOOK_ENTITIES; +]> + +
+ Changing the Default System Offering for System VMs + You can manually change the system offering for a particular System VM. Additionally, as a + &PRODUCT; administrator, you can also change the default system offering used for System + VMs. + + + Create a new system offering. + For more information, see + Creating a New System Service Offering. + + + Back up the database: + mysqldump -u root -p cloud | bzip2 > cloud_backup.sql.bz2 + + + Open an MySQL prompt: + mysql -u cloud -p cloud + + + Run the following queries on the cloud database. + + + In the disk_offering table, identify the original default offering and the new + offering you want to use by default. + Take a note of the ID of the new offering. + select id,name,unique_name,type from disk_offering; + + + For the original default offering, set the value of unique_name to NULL. + # update disk_offering set unique_name = NULL where id = 10; + Ensure that you use the correct value for the ID. + + + For the new offering that you want to use by default, set the value of unique_name + as follows: + For the default Console Proxy VM (CPVM) offering,set unique_name to + 'Cloud.com-ConsoleProxy'. For the default Secondary Storage VM (SSVM) offering, set + unique_name to 'Cloud.com-SecondaryStorage'. For example: + update disk_offering set unique_name = 'Cloud.com-ConsoleProxy' where id = 16; + + + + + Restart &PRODUCT; Management Server. Restarting is required because the default + offerings are loaded into the memory at startup. + service cloud-management restart + + + Destroy the existing CPVM or SSVM offerings and wait for them to be recreated. The new + CPVM or SSVM are configured with the new offering. + + +
diff --git a/plugins/api/discovery/pom.xml b/plugins/api/discovery/pom.xml index a61b275addc..1cfc5c2eaf2 100644 --- a/plugins/api/discovery/pom.xml +++ b/plugins/api/discovery/pom.xml @@ -20,25 +20,47 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - 4.0.0 - cloud-plugin-api-discovery - Apache CloudStack Plugin - API Discovery - - org.apache.cloudstack - cloudstack-plugins - 4.1.0-SNAPSHOT - ../../pom.xml - - - - org.apache.cloudstack - cloud-api - ${project.version} - - - org.apache.cloudstack - cloud-utils - ${project.version} - - + 4.0.0 + cloud-plugin-api-discovery + Apache CloudStack Plugin - API Discovery + + org.apache.cloudstack + cloudstack-plugins + 4.1.0-SNAPSHOT + ../../pom.xml + + + + org.apache.cloudstack + cloud-api + ${project.version} + + + org.apache.cloudstack + cloud-utils + ${project.version} + + + + install + src + test + + + test/resources + + + + + org.apache.maven.plugins + maven-surefire-plugin + + -Xmx1024m + + org/apache/cloudstack/discovery/integration/* + + + + + diff --git a/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiDiscoveryResponse.java b/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiDiscoveryResponse.java index de6a9f93965..77484f0f7e7 100644 --- a/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiDiscoveryResponse.java +++ b/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiDiscoveryResponse.java @@ -57,18 +57,34 @@ public class ApiDiscoveryResponse extends BaseResponse { this.name = name; } + public String getName() { + return name; + } + public void setDescription(String description) { this.description = description; } + public String getDescription() { + return description; + } + public void setSince(String since) { this.since = since; } + public String getSince() { + return since; + } + public void setAsync(Boolean isAsync) { this.isAsync = isAsync; } + public boolean getAsync() { + return isAsync; + } + public String getRelated() { return related; } diff --git a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java index f06e2005552..bfd2719d8bd 100644 --- a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java +++ b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java @@ -58,18 +58,16 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { if (s_apiNameDiscoveryResponseMap == null) { long startTime = System.nanoTime(); s_apiNameDiscoveryResponseMap = new HashMap(); - cacheResponseMap(); + //TODO: Fix and use PluggableService to get the classes + Set> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class, + new String[]{"org.apache.cloudstack.api", "com.cloud.api"}); + cacheResponseMap(cmdClasses); long endTime = System.nanoTime(); s_logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms"); } } - private void cacheResponseMap() { - Set> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class, - new String[]{"org.apache.cloudstack.api", "com.cloud.api"}); - - //TODO: Fix and use PluggableService to get the classes - + protected void cacheResponseMap(Set> cmdClasses) { Map> responseApiNameListMap = new HashMap>(); for (Class cmdClass : cmdClasses) { @@ -109,7 +107,7 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { } } - Field[] fields = ReflectUtil.getAllFieldsForClass(cmdClass, + Set fields = ReflectUtil.getAllFieldsForClass(cmdClass, new Class[]{BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class}); boolean isAsync = ReflectUtil.isCmdClassAsync(cmdClass, diff --git a/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java b/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java new file mode 100644 index 00000000000..a0e2a139164 --- /dev/null +++ b/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java @@ -0,0 +1,87 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.discovery; + +import com.cloud.user.User; +import com.cloud.user.UserVO; +import com.cloud.utils.component.Adapters; + +import java.util.*; +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.acl.APIChecker; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.command.user.discovery.ListApisCmd; +import org.apache.cloudstack.api.response.ApiDiscoveryResponse; +import org.apache.cloudstack.api.response.ListResponse; + +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +public class ApiDiscoveryTest { + + private static ApiDiscoveryServiceImpl _discoveryService = new ApiDiscoveryServiceImpl(); + private static APIChecker _apiChecker = mock(APIChecker.class); + + private static Class testCmdClass = ListApisCmd.class; + private static User testUser; + private static String testApiName; + private static String testApiDescription; + private static String testApiSince; + private static boolean testApiAsync; + + @BeforeClass + public static void setUp() throws ConfigurationException { + testApiName = testCmdClass.getAnnotation(APICommand.class).name(); + testApiDescription = testCmdClass.getAnnotation(APICommand.class).description(); + testApiSince = testCmdClass.getAnnotation(APICommand.class).since(); + testApiAsync = false; + testUser = new UserVO(); + + Set> cmdClasses = new HashSet>(); + cmdClasses.add(ListApisCmd.class); + _discoveryService.cacheResponseMap(cmdClasses); + _discoveryService.s_apiAccessCheckers = (Adapters) mock(Adapters.class); + + when(_apiChecker.checkAccess(any(User.class), anyString())).thenReturn(true); + when(_discoveryService.s_apiAccessCheckers.iterator()).thenReturn(Arrays.asList(_apiChecker).iterator()); + } + + @Test + public void verifyListSingleApi() throws Exception { + ListResponse responses = (ListResponse) _discoveryService.listApis(testUser, testApiName); + ApiDiscoveryResponse response = responses.getResponses().get(0); + assertTrue("No. of response items should be one", responses.getCount() == 1); + assertEquals("Error in api name", testApiName, response.getName()); + assertEquals("Error in api description", testApiDescription, response.getDescription()); + assertEquals("Error in api since", testApiSince, response.getSince()); + assertEquals("Error in api isAsync", testApiAsync, response.getAsync()); + } + + @Test + public void verifyListApis() throws Exception { + ListResponse responses = (ListResponse) _discoveryService.listApis(testUser, null); + assertTrue("No. of response items > 1", responses.getCount() > 1); + for (ApiDiscoveryResponse response: responses.getResponses()) { + assertFalse("API name is empty", response.getName().isEmpty()); + assertFalse("API description is empty", response.getDescription().isEmpty()); + } + } +} diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java index 51849f123ed..b897df2ecf3 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java @@ -86,6 +86,9 @@ public class BridgeVifDriver extends VifDriverBase { URI broadcastUri = nic.getBroadcastUri(); vlanId = broadcastUri.getHost(); } + else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { + throw new InternalErrorException("Nicira NVP Logicalswitches are not supported by the BridgeVifDriver"); + } String trafficLabel = nic.getName(); if (nic.getType() == Networks.TrafficType.Guest) { if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan @@ -173,7 +176,7 @@ public class BridgeVifDriver extends VifDriverBase { createControlNetwork(_bridges.get("linklocal")); } - private void deletExitingLinkLocalRoutTable(String linkLocalBr) { + private void deleteExitingLinkLocalRouteTable(String linkLocalBr) { Script command = new Script("/bin/bash", _timeout); command.add("-c"); command.add("ip route | grep " + NetUtils.getLinkLocalCIDR()); @@ -198,7 +201,7 @@ public class BridgeVifDriver extends VifDriverBase { } private void createControlNetwork(String privBrName) { - deletExitingLinkLocalRoutTable(privBrName); + deleteExitingLinkLocalRouteTable(privBrName); if (!isBridgeExists(privBrName)) { Script.runSimpleBashScript("brctl addbr " + privBrName + "; ifconfig " + privBrName + " up; ifconfig " + privBrName + " 169.254.0.1", _timeout); 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 a269e8ab732..8a9f71bf7d5 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 @@ -365,10 +365,16 @@ public class LibvirtComputingResource extends ServerResourceBase implements private String _pingTestPath; private int _dom0MinMem; + + protected enum BridgeType { + NATIVE, OPENVSWITCH + } protected enum defineOps { UNDEFINE_VM, DEFINE_VM } + + protected BridgeType _bridgeType; private String getEndIpFromStartIp(String startIp, int numIps) { String[] tokens = startIp.split("[.]"); @@ -477,6 +483,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements if (storageScriptsDir == null) { storageScriptsDir = getDefaultStorageScriptsDir(); } + + String bridgeType = (String) params.get("network.bridge.type"); + if (bridgeType == null) { + _bridgeType = BridgeType.NATIVE; + } + else { + _bridgeType = BridgeType.valueOf(bridgeType.toUpperCase()); + } params.put("domr.scripts.dir", domrScriptsDir); @@ -661,6 +675,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Connect conn = null; try { conn = LibvirtConnection.getConnection(); + + if (_bridgeType == BridgeType.OPENVSWITCH) { + if (conn.getLibVirVersion() < (9 * 1000 + 11)) { + throw new ConfigurationException("LibVirt version 0.9.11 required for openvswitch support, but version " + + conn.getLibVirVersion() + " detected"); + } + } } catch (LibvirtException e) { throw new CloudRuntimeException(e.getMessage()); } @@ -706,7 +727,16 @@ public class LibvirtComputingResource extends ServerResourceBase implements } } - getPifs(); + switch (_bridgeType) { + case OPENVSWITCH: + getOvsPifs(); + break; + case NATIVE: + default: + getPifs(); + break; + } + if (_pifs.get("private") == null) { s_logger.debug("Failed to get private nic name"); throw new ConfigurationException("Failed to get private nic name"); @@ -765,25 +795,29 @@ public class LibvirtComputingResource extends ServerResourceBase implements // Load the vif driver String vifDriverName = (String) params.get("libvirt.vif.driver"); if (vifDriverName == null) { - s_logger.info("No libvirt.vif.driver specififed. Defaults to BridgeVifDriver."); - vifDriverName = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver"; + if (_bridgeType == BridgeType.OPENVSWITCH) { + s_logger.info("No libvirt.vif.driver specififed. Defaults to OvsVifDriver."); + vifDriverName = "com.cloud.hypervisor.kvm.resource.OvsVifDriver"; + } else { + s_logger.info("No libvirt.vif.driver specififed. Defaults to BridgeVifDriver."); + vifDriverName = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver"; + } } params.put("libvirt.computing.resource", (Object) this); try { - Class clazz = Class.forName(vifDriverName); - _vifDriver = (VifDriver) clazz.newInstance(); - _vifDriver.configure(params); + Class clazz = Class.forName(vifDriverName); + _vifDriver = (VifDriver) clazz.newInstance(); + _vifDriver.configure(params); } catch (ClassNotFoundException e) { - throw new ConfigurationException("Unable to find class for libvirt.vif.driver " + e); + throw new ConfigurationException("Unable to find class for libvirt.vif.driver " + e); } catch (InstantiationException e) { - throw new ConfigurationException("Unable to instantiate class for libvirt.vif.driver " + e); + throw new ConfigurationException("Unable to instantiate class for libvirt.vif.driver " + e); } catch (Exception e) { - throw new ConfigurationException("Failed to initialize libvirt.vif.driver " + e); + throw new ConfigurationException("Failed to initialize libvirt.vif.driver " + e); } - return true; } @@ -814,6 +848,27 @@ public class LibvirtComputingResource extends ServerResourceBase implements } s_logger.debug("done looking for pifs, no more bridges"); } + + private void getOvsPifs() { + String cmdout = Script.runSimpleBashScript("ovs-vsctl list-br | sed '{:q;N;s/\\n/%/g;t q}'"); + s_logger.debug("cmdout was " + cmdout); + List bridges = Arrays.asList(cmdout.split("%")); + for (String bridge : bridges) { + s_logger.debug("looking for pif for bridge " + bridge); + // String pif = getOvsPif(bridge); + // Not really interested in the pif name at this point for ovs + // bridges + String pif = bridge; + if (_publicBridgeName != null && bridge.equals(_publicBridgeName)) { + _pifs.put("public", pif); + } + if (_guestBridgeName != null && bridge.equals(_guestBridgeName)) { + _pifs.put("private", pif); + } + _pifs.put(bridge, pif); + } + s_logger.debug("done looking for pifs, no more bridges"); + } private String getPif(String bridge) { String pif = matchPifFileInDirectory(bridge); @@ -827,6 +882,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements return pif; } + private String getOvsPif(String bridge) { + String pif = Script.runSimpleBashScript("ovs-vsctl list-ports " + bridge); + return pif; + } + private String matchPifFileInDirectory(String bridgeName){ File f = new File("/sys/devices/virtual/net/" + bridgeName + "/brif"); @@ -860,6 +920,18 @@ public class LibvirtComputingResource extends ServerResourceBase implements return true; } + if (_bridgeType == BridgeType.OPENVSWITCH) { + return checkOvsNetwork(networkName); + } else { + return checkBridgeNetwork(networkName); + } + } + + private boolean checkBridgeNetwork(String networkName) { + if (networkName == null) { + return true; + } + String name = matchPifFileInDirectory(networkName); if (name == null || name.isEmpty()) { @@ -868,6 +940,23 @@ public class LibvirtComputingResource extends ServerResourceBase implements return true; } } + + private boolean checkOvsNetwork(String networkName) { + s_logger.debug("Checking if network " + networkName + " exists as openvswitch bridge"); + if (networkName == null) { + return true; + } + + Script command = new Script("/bin/sh", _timeout); + command.add("-c"); + command.add("ovs-vsctl br-exists " + networkName); + String result = command.execute(null); + if ("Ok".equals(result)) { + return true; + } else { + return false; + } + } private String getVnetId(String vnetId) { return vnetId; @@ -1652,13 +1741,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements String pluggedVlan = pluggedNic.getBrName(); if (pluggedVlan.equalsIgnoreCase(_linkLocalBridgeName)) { vlanToNicNum.put("LinkLocal",devNum); - } - else if (pluggedVlan.equalsIgnoreCase(_publicBridgeName) + } else if (pluggedVlan.equalsIgnoreCase(_publicBridgeName) || pluggedVlan.equalsIgnoreCase(_privBridgeName) || pluggedVlan.equalsIgnoreCase(_guestBridgeName)) { vlanToNicNum.put(Vlan.UNTAGGED,devNum); - } - else { + } else { vlanToNicNum.put(getVlanIdFromBridge(pluggedVlan),devNum); } devNum++; 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 ba6c715e455..acfd9cf1fe8 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 @@ -646,6 +646,9 @@ public class LibvirtVMDef { private String _ipAddr; private String _scriptPath; private nicModel _model; + private String _virtualPortType; + private String _virtualPortInterfaceId; + private int _vlanTag = -1; public void defBridgeNet(String brName, String targetBrName, String macAddr, nicModel model) { @@ -695,7 +698,31 @@ public class LibvirtVMDef { public String getMacAddress() { return _macAddr; } + + public void setVirtualPortType(String virtualPortType) { + _virtualPortType = virtualPortType; + } + public String getVirtualPortType() { + return _virtualPortType; + } + + public void setVirtualPortInterfaceId(String virtualPortInterfaceId) { + _virtualPortInterfaceId = virtualPortInterfaceId; + } + + public String getVirtualPortInterfaceId() { + return _virtualPortInterfaceId; + } + + public void setVlanTag(int vlanTag) { + _vlanTag = vlanTag; + } + + public int getVlanTag() { + return _vlanTag; + } + @Override public String toString() { StringBuilder netBuilder = new StringBuilder(); @@ -714,6 +741,16 @@ public class LibvirtVMDef { if (_model != null) { netBuilder.append("\n"); } + if (_virtualPortType != null) { + netBuilder.append("\n"); + if (_virtualPortInterfaceId != null) { + netBuilder.append("\n"); + } + netBuilder.append("\n"); + } + if (_vlanTag > 0 && _vlanTag < 4095) { + netBuilder.append("\n\n"); + } netBuilder.append("\n"); return netBuilder.toString(); } diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java new file mode 100644 index 00000000000..37761aa5555 --- /dev/null +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.cloud.hypervisor.kvm.resource; + +import java.net.URI; +import java.util.Map; + +import javax.naming.ConfigurationException; + +import org.apache.log4j.Logger; +import org.libvirt.LibvirtException; + +import com.cloud.agent.api.to.NicTO; +import com.cloud.exception.InternalErrorException; +import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef; +import com.cloud.network.Networks; +import com.cloud.utils.NumbersUtil; +import com.cloud.utils.net.NetUtils; +import com.cloud.utils.script.OutputInterpreter; +import com.cloud.utils.script.Script; + +public class OvsVifDriver extends VifDriverBase { + private static final Logger s_logger = Logger.getLogger(OvsVifDriver.class); + private int _timeout; + private String _modifyVlanPath; + + @Override + public void configure(Map params) throws ConfigurationException { + super.configure(params); + + String networkScriptsDir = (String) params.get("network.scripts.dir"); + if (networkScriptsDir == null) { + networkScriptsDir = "scripts/vm/network/vnet"; + } + + String value = (String) params.get("scripts.timeout"); + _timeout = NumbersUtil.parseInt(value, 30 * 60) * 1000; + + _modifyVlanPath = Script.findScript(networkScriptsDir, "modifyvlan.sh"); + if (_modifyVlanPath == null) { + throw new ConfigurationException("Unable to find modifyvlan.sh"); + } + + createControlNetwork(_bridges.get("linklocal")); + } + + @Override + public InterfaceDef plug(NicTO nic, String guestOsType) + throws InternalErrorException, LibvirtException { + s_logger.debug("plugging nic=" + nic); + + LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef(); + intf.setVirtualPortType("openvswitch"); + + String vlanId = null; + String logicalSwitchUuid = null; + if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) { + URI broadcastUri = nic.getBroadcastUri(); + vlanId = broadcastUri.getHost(); + } + else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { + logicalSwitchUuid = nic.getBroadcastUri().getSchemeSpecificPart(); + } + String trafficLabel = nic.getName(); + if (nic.getType() == Networks.TrafficType.Guest) { + if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan + && !vlanId.equalsIgnoreCase("untagged")) { + if(trafficLabel != null && !trafficLabel.isEmpty()) { + s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); + intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType)); + intf.setVlanTag(Integer.parseInt(vlanId)); + } else { + intf.defBridgeNet(_pifs.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType)); + intf.setVlanTag(Integer.parseInt(vlanId)); + } + } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { + s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid); + intf.setVirtualPortInterfaceId(nic.getUuid()); + String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private"); + intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType)); + } + else { + intf.defBridgeNet(_bridges.get("guest"), null, nic.getMac(), getGuestNicModel(guestOsType)); + } + } else if (nic.getType() == Networks.TrafficType.Control) { + /* Make sure the network is still there */ + createControlNetwork(_bridges.get("linklocal")); + intf.defBridgeNet(_bridges.get("linklocal"), null, nic.getMac(), getGuestNicModel(guestOsType)); + } else if (nic.getType() == Networks.TrafficType.Public) { + if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan + && !vlanId.equalsIgnoreCase("untagged")) { + if(trafficLabel != null && !trafficLabel.isEmpty()){ + s_logger.debug("creating a vlan dev and bridge for public traffic per traffic label " + trafficLabel); + intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType)); + intf.setVlanTag(Integer.parseInt(vlanId)); + } else { + intf.defBridgeNet(_pifs.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType)); + intf.setVlanTag(Integer.parseInt(vlanId)); + } + } else { + intf.defBridgeNet(_bridges.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType)); + } + } else if (nic.getType() == Networks.TrafficType.Management) { + intf.defBridgeNet(_bridges.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType)); + } else if (nic.getType() == Networks.TrafficType.Storage) { + String storageBrName = nic.getName() == null ? _bridges.get("private") + : nic.getName(); + intf.defBridgeNet(storageBrName, null, nic.getMac(), getGuestNicModel(guestOsType)); + } + return intf; + } + + @Override + public void unplug(InterfaceDef iface) { + // Libvirt apparently takes care of this, see BridgeVifDriver unplug + } + + private String setVnetBrName(String pifName, String vnetId) { + String brName = "br" + pifName + "-"+ vnetId; + String oldStyleBrName = "cloudVirBr" + vnetId; + + if (isBridgeExists(oldStyleBrName)) { + s_logger.info("Using old style bridge name for vlan " + vnetId + " because existing bridge " + oldStyleBrName + " was found"); + brName = oldStyleBrName; + } + + return brName; + } + + private void deleteExitingLinkLocalRouteTable(String linkLocalBr) { + Script command = new Script("/bin/bash", _timeout); + command.add("-c"); + command.add("ip route | grep " + NetUtils.getLinkLocalCIDR()); + OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); + String result = command.execute(parser); + boolean foundLinkLocalBr = false; + if (result == null && parser.getLines() != null) { + String[] lines = parser.getLines().split("\\n"); + for (String line : lines) { + String[] tokens = line.split(" "); + if (!tokens[2].equalsIgnoreCase(linkLocalBr)) { + Script.runSimpleBashScript("ip route del " + NetUtils.getLinkLocalCIDR()); + } else { + foundLinkLocalBr = true; + } + } + } + if (!foundLinkLocalBr) { + Script.runSimpleBashScript("ifconfig " + linkLocalBr + " 169.254.0.1;" + "ip route add " + + NetUtils.getLinkLocalCIDR() + " dev " + linkLocalBr + " src " + NetUtils.getLinkLocalGateway()); + } + } + + private void createControlNetwork(String privBrName) { + deleteExitingLinkLocalRouteTable(privBrName); + if (!isBridgeExists(privBrName)) { + Script.runSimpleBashScript("ovs-vsctl add-br " + privBrName + "; ifconfig " + privBrName + " up; ifconfig " + + privBrName + " 169.254.0.1", _timeout); + } + } + + private boolean isBridgeExists(String bridgeName) { + Script command = new Script("/bin/sh", _timeout); + command.add("-c"); + command.add("ovs-vsctl br-exists " + bridgeName); + String result = command.execute(null); + if ("Ok".equals(result)) { + return true; + } else { + return false; + } + } +} diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java index ac611275e5a..c2bfad9feef 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java @@ -38,6 +38,10 @@ public class KVMStoragePoolManager { private final Map _storageMapper = new HashMap(); private StorageAdaptor getStorageAdaptor(StoragePoolType type) { + // type can be null: LibVirtComputingResource:3238 + if (type == null) { + return _storageMapper.get("libvirt"); + } StorageAdaptor adaptor = _storageMapper.get(type.toString()); if (adaptor == null) { // LibvirtStorageAdaptor is selected by default diff --git a/server/pom.xml b/server/pom.xml index 64bd2a206da..4c3ba6f9e76 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -105,6 +105,7 @@ com/cloud/vm/dao/* com/cloud/vpc/* com/cloud/api/ListPerfTest.java + com/cloud/network/vpn/RemoteAccessVpnTest.java diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 9b88664fe2b..0b08b26cc32 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -41,9 +41,11 @@ import org.apache.cloudstack.api.response.StoragePoolResponse; 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 com.cloud.api.query.dao.AccountJoinDao; import com.cloud.api.query.dao.AsyncJobJoinDao; +import com.cloud.api.query.dao.DataCenterJoinDao; import com.cloud.api.query.dao.DiskOfferingJoinDao; import com.cloud.api.query.dao.DomainRouterJoinDao; import com.cloud.api.query.dao.HostJoinDao; @@ -60,6 +62,7 @@ import com.cloud.api.query.dao.UserVmJoinDao; import com.cloud.api.query.dao.VolumeJoinDao; import com.cloud.api.query.vo.AccountJoinVO; import com.cloud.api.query.vo.AsyncJobJoinVO; +import com.cloud.api.query.vo.DataCenterJoinVO; import com.cloud.api.query.vo.DiskOfferingJoinVO; import com.cloud.api.query.vo.DomainRouterJoinVO; import com.cloud.api.query.vo.EventJoinVO; @@ -88,6 +91,7 @@ import com.cloud.configuration.Resource.ResourceType; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.AccountVlanMapVO; import com.cloud.dc.ClusterVO; +import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; import com.cloud.dc.Vlan; @@ -342,6 +346,7 @@ public class ApiDBUtils { private static AsyncJobJoinDao _jobJoinDao; private static DiskOfferingJoinDao _diskOfferingJoinDao; private static ServiceOfferingJoinDao _srvOfferingJoinDao; + private static DataCenterJoinDao _dcJoinDao; private static PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao; private static PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao; @@ -448,6 +453,7 @@ public class ApiDBUtils { _asyncJobDao = locator.getDao(AsyncJobDao.class); _diskOfferingJoinDao = locator.getDao(DiskOfferingJoinDao.class); _srvOfferingJoinDao = locator.getDao(ServiceOfferingJoinDao.class); + _dcJoinDao = locator.getDao(DataCenterJoinDao.class); // Note: stats collector should already have been initialized by this time, otherwise a null instance is returned _statsCollector = StatsCollector.getInstance(); @@ -1426,4 +1432,12 @@ public class ApiDBUtils { public static ServiceOfferingJoinVO newServiceOfferingView(ServiceOffering offering){ return _srvOfferingJoinDao.newServiceOfferingView(offering); } + + public static ZoneResponse newDataCenterResponse(DataCenterJoinVO dc, Boolean showCapacities) { + return _dcJoinDao.newDataCenterResponse(dc, showCapacities); + } + + public static DataCenterJoinVO newDataCenterView(DataCenter dc){ + return _dcJoinDao.newDataCenterView(dc); + } } diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index 129ef7d4a2e..f7d881dfe30 100755 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -27,6 +27,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.StringTokenizer; import java.util.regex.Matcher; @@ -157,8 +158,7 @@ public class ApiDispatcher { } if (queueSizeLimit != null) { - _asyncMgr - .syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(), asyncCmd.getSyncObjId().longValue(), queueSizeLimit); + _asyncMgr.syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(), asyncCmd.getSyncObjId().longValue(), queueSizeLimit); } else { s_logger.trace("The queue size is unlimited, skipping the synchronizing"); } @@ -190,8 +190,7 @@ public class ApiDispatcher { } } - Field[] fields = ReflectUtil.getAllFieldsForClass(cmd.getClass(), - new Class[] {BaseCmd.class}); + List fields = ReflectUtil.getAllFieldsForClass(cmd.getClass(), BaseCmd.class); for (Field field : fields) { PlugService plugServiceAnnotation = field.getAnnotation(PlugService.class); @@ -360,8 +359,9 @@ public class ApiDispatcher { // Go through each entity which is an interface to a VO class and get a VO object // Try to getId() for the object using reflection, break on first non-null value for (Class entity: entities) { - // findByUuid returns one VO object using uuid, use reflect to get the Id - Object objVO = s_instance._entityMgr.findByUuid(entity, uuid); + // For backward compatibility, we search within removed entities and let service layer deal + // with removed ones, return empty response or error + Object objVO = s_instance._entityMgr.findByUuidIncludingRemoved(entity, uuid); if (objVO == null) { continue; } @@ -377,11 +377,10 @@ public class ApiDispatcher { break; } if (internalId == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Object entity with uuid=" + uuid + " does not exist in the database."); - } + if (s_logger.isDebugEnabled()) + s_logger.debug("Object entity uuid = " + uuid + " does not exist in the database."); throw new InvalidParameterValueException("Invalid parameter value=" + uuid - + " due to incorrect long value, entity not found, or an annotation bug."); + + " due to incorrect long value format, or entity was not found as it may have been deleted, or due to incorrect parameter annotation for the field in api cmd."); } return internalId; } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 3706d4fc9a7..cef780d121b 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -44,6 +44,7 @@ import com.cloud.api.query.ViewResponseHelper; import com.cloud.api.query.vo.AccountJoinVO; import com.cloud.api.query.vo.AsyncJobJoinVO; import com.cloud.api.query.vo.ControlledViewEntity; +import com.cloud.api.query.vo.DataCenterJoinVO; import com.cloud.api.query.vo.DiskOfferingJoinVO; import com.cloud.api.query.vo.DomainRouterJoinVO; import com.cloud.api.query.vo.EventJoinVO; @@ -723,77 +724,42 @@ public class ApiResponseHelper implements ResponseGenerator { @Override public ZoneResponse createZoneResponse(DataCenter dataCenter, Boolean showCapacities) { - Account account = UserContext.current().getCaller(); - ZoneResponse zoneResponse = new ZoneResponse(); - zoneResponse.setId(dataCenter.getUuid()); - zoneResponse.setName(dataCenter.getName()); - zoneResponse.setSecurityGroupsEnabled(ApiDBUtils.isSecurityGroupEnabledInZone(dataCenter.getId())); - zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled()); - - if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) { - zoneResponse.setDescription(dataCenter.getDescription()); - } - - if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) { - zoneResponse.setDns1(dataCenter.getDns1()); - zoneResponse.setDns2(dataCenter.getDns2()); - zoneResponse.setInternalDns1(dataCenter.getInternalDns1()); - zoneResponse.setInternalDns2(dataCenter.getInternalDns2()); - // FIXME zoneResponse.setVlan(dataCenter.get.getVnet()); - zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr()); - } - - if (showCapacities != null && showCapacities) { - List capacities = ApiDBUtils.getCapacityByClusterPodZone(dataCenter.getId(), null, null); - Set capacityResponses = new HashSet(); - float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor(); - - for (SummedCapacity capacity : capacities) { - CapacityResponse capacityResponse = new CapacityResponse(); - capacityResponse.setCapacityType(capacity.getCapacityType()); - capacityResponse.setCapacityUsed(capacity.getUsedCapacity()); - if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) { - capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor))); - } else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) { - List c = ApiDBUtils.findNonSharedStorageForClusterPodZone(dataCenter.getId(), null, null); - capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity()); - capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity()); - } else { - capacityResponse.setCapacityTotal(capacity.getTotalCapacity()); - } - if (capacityResponse.getCapacityTotal() != 0) { - capacityResponse.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f)); - } else { - capacityResponse.setPercentUsed(s_percentFormat.format(0L)); - } - capacityResponses.add(capacityResponse); - } - // Do it for stats as well. - capacityResponses.addAll(getStatsCapacityresponse(null, null, null, dataCenter.getId())); - - zoneResponse.setCapacitites(new ArrayList(capacityResponses)); - } - - // set network domain info - zoneResponse.setDomain(dataCenter.getDomain()); - - // set domain info - Long domainId = dataCenter.getDomainId(); - if (domainId != null) { - Domain domain = ApiDBUtils.findDomainById(domainId); - zoneResponse.setDomainId(domain.getId()); - zoneResponse.setDomainName(domain.getName()); - } - - zoneResponse.setType(dataCenter.getNetworkType().toString()); - zoneResponse.setAllocationState(dataCenter.getAllocationState().toString()); - zoneResponse.setZoneToken(dataCenter.getZoneToken()); - zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider()); - zoneResponse.setObjectName("zone"); - return zoneResponse; + DataCenterJoinVO vOffering = ApiDBUtils.newDataCenterView(dataCenter); + return ApiDBUtils.newDataCenterResponse(vOffering, showCapacities); } - private List getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) { + public static List getDataCenterCapacityResponse(Long zoneId){ + List capacities = ApiDBUtils.getCapacityByClusterPodZone(zoneId, null, null); + Set capacityResponses = new HashSet(); + float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor(); + + for (SummedCapacity capacity : capacities) { + CapacityResponse capacityResponse = new CapacityResponse(); + capacityResponse.setCapacityType(capacity.getCapacityType()); + capacityResponse.setCapacityUsed(capacity.getUsedCapacity()); + if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) { + capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor))); + } else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) { + List c = ApiDBUtils.findNonSharedStorageForClusterPodZone(zoneId, null, null); + capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity()); + capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity()); + } else { + capacityResponse.setCapacityTotal(capacity.getTotalCapacity()); + } + if (capacityResponse.getCapacityTotal() != 0) { + capacityResponse.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f)); + } else { + capacityResponse.setPercentUsed(s_percentFormat.format(0L)); + } + capacityResponses.add(capacityResponse); + } + // Do it for stats as well. + capacityResponses.addAll(getStatsCapacityresponse(null, null, null, zoneId)); + + return new ArrayList(capacityResponses); + } + + private static List getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) { List capacities = new ArrayList(); capacities.add(ApiDBUtils.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId)); if (clusterId == null && podId == null) { diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index 07b89c3b808..0b160f1018e 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -61,6 +61,7 @@ import org.apache.cloudstack.api.command.user.event.ListEventsCmd; import org.apache.cloudstack.api.command.user.vm.ListVMsCmd; import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd; import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd; +import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd; import org.apache.commons.codec.binary.Base64; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.ConnectionClosedException; @@ -521,6 +522,7 @@ public class ApiServer implements HttpRequestHandler { && !(cmdObj instanceof ListStoragePoolsCmd) && !(cmdObj instanceof ListDiskOfferingsCmd) && !(cmdObj instanceof ListServiceOfferingsCmd) + && !(cmdObj instanceof ListZonesByCmd) ) { buildAsyncListResponse((BaseListCmd) cmdObj, caller); } diff --git a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java index 84851c389ad..c3c0cabdf17 100644 --- a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java +++ b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java @@ -28,6 +28,7 @@ import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import com.cloud.utils.IteratorUtil; import com.cloud.utils.ReflectUtil; import org.apache.cloudstack.api.*; import org.apache.log4j.Logger; @@ -135,7 +136,7 @@ public class ApiXmlDocWriter { String commandRoleMask = preProcessedCommand.substring(splitIndex + 1); Class cmdClass = _apiNameCmdClassMap.get(key); if (cmdClass == null) { - System.out.println("Check, Null Value for key: " + key + " preProcessedCommand=" + preProcessedCommand); + System.out.println("Check, is this api part of another build profile? Null value for key: " + key + " preProcessedCommand=" + preProcessedCommand); continue; } String commandName = cmdClass.getName(); @@ -349,7 +350,7 @@ public class ApiXmlDocWriter { apiCommand.setAsync(isAsync); - Field[] fields = ReflectUtil.getAllFieldsForClass(clas, + Set fields = ReflectUtil.getAllFieldsForClass(clas, new Class[] {BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class}); request = setRequestFields(fields); @@ -422,10 +423,10 @@ public class ApiXmlDocWriter { out.writeObject(apiCommand); } - private static ArrayList setRequestFields(Field[] fields) { + private static ArrayList setRequestFields(Set fields) { ArrayList arguments = new ArrayList(); - ArrayList requiredArguments = new ArrayList(); - ArrayList optionalArguments = new ArrayList(); + Set requiredArguments = new HashSet(); + Set optionalArguments = new HashSet(); Argument id = null; for (Field f : fields) { Parameter parameterAnnotation = f.getAnnotation(Parameter.class); @@ -444,7 +445,7 @@ public class ApiXmlDocWriter { reqArg.setSinceVersion(parameterAnnotation.since()); } - if (reqArg.isRequired() == true) { + if (reqArg.isRequired()) { if (parameterAnnotation.name().equals("id")) { id = reqArg; } else { @@ -456,15 +457,12 @@ public class ApiXmlDocWriter { } } - Collections.sort(requiredArguments); - Collections.sort(optionalArguments); - // sort required and optional arguments here if (id != null) { arguments.add(id); } - arguments.addAll(requiredArguments); - arguments.addAll(optionalArguments); + arguments.addAll(IteratorUtil.asSortedList(requiredArguments)); + arguments.addAll(IteratorUtil.asSortedList(optionalArguments)); return arguments; } diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index ee472961871..cf240b17548 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -18,8 +18,11 @@ package com.cloud.api.query; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import javax.ejb.Local; import javax.naming.ConfigurationException; @@ -41,6 +44,7 @@ import org.apache.cloudstack.api.command.user.tag.ListTagsCmd; import org.apache.cloudstack.api.command.user.vm.ListVMsCmd; import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd; import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd; +import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.AsyncJobResponse; import org.apache.cloudstack.api.response.DiskOfferingResponse; @@ -59,11 +63,13 @@ import org.apache.cloudstack.api.response.StoragePoolResponse; 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.query.QueryService; import org.apache.log4j.Logger; import com.cloud.api.query.dao.AccountJoinDao; import com.cloud.api.query.dao.AsyncJobJoinDao; +import com.cloud.api.query.dao.DataCenterJoinDao; import com.cloud.api.query.dao.DiskOfferingJoinDao; import com.cloud.api.query.dao.DomainRouterJoinDao; import com.cloud.api.query.dao.HostJoinDao; @@ -80,6 +86,7 @@ import com.cloud.api.query.dao.UserVmJoinDao; import com.cloud.api.query.dao.VolumeJoinDao; import com.cloud.api.query.vo.AccountJoinVO; import com.cloud.api.query.vo.AsyncJobJoinVO; +import com.cloud.api.query.vo.DataCenterJoinVO; import com.cloud.api.query.vo.DiskOfferingJoinVO; import com.cloud.api.query.vo.DomainRouterJoinVO; import com.cloud.api.query.vo.EventJoinVO; @@ -96,6 +103,7 @@ import com.cloud.api.query.vo.UserAccountJoinVO; import com.cloud.api.query.vo.UserVmJoinVO; import com.cloud.api.query.vo.VolumeJoinVO; import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.DataCenterVO; import com.cloud.domain.Domain; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; @@ -107,6 +115,7 @@ import com.cloud.ha.HighAvailabilityManager; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.security.SecurityGroupVMMapVO; import com.cloud.network.security.dao.SecurityGroupVMMapDao; +import com.cloud.org.Grouping; import com.cloud.projects.ProjectInvitation; import com.cloud.projects.Project.ListProjectResourcesCriteria; import com.cloud.projects.Project; @@ -135,8 +144,10 @@ import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.vm.DomainRouterVO; import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachine; +import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.UserVmDao; /** @@ -233,6 +244,12 @@ public class QueryManagerImpl implements QueryService, Manager { @Inject private ServiceOfferingDao _srvOfferingDao; + @Inject + private DataCenterJoinDao _dcJoinDao; + + @Inject + private DomainRouterDao _routerDao; + @Inject private HighAvailabilityManager _haMgr; @@ -2114,7 +2131,7 @@ public class QueryManagerImpl implements QueryService, Manager { domainRecord = _domainDao.findById(domainRecord.getParent()); domainIds.add(domainRecord.getId()); } - sc.addAnd("domainIdIn", SearchCriteria.Op.IN, domainIds); + sc.addAnd("domainId", SearchCriteria.Op.IN, domainIds); // include also public offering if no keyword, name and id specified if ( keyword == null && name == null && id == null ){ @@ -2187,6 +2204,125 @@ public class QueryManagerImpl implements QueryService, Manager { + @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()])); + response.setResponses(dcResponses, result.second()); + return response; + } + + + private Pair, Integer> listDataCentersInternal(ListZonesByCmd cmd) { + Account account = UserContext.current().getCaller(); + Long domainId = cmd.getDomainId(); + Long id = cmd.getId(); + String keyword = cmd.getKeyword(); + + Filter searchFilter = new Filter(DataCenterJoinVO.class, null, false, cmd.getStartIndex(), cmd.getPageSizeVal()); + SearchCriteria sc = _dcJoinDao.createSearchCriteria(); + + if (id != null) { + sc.addAnd("id", SearchCriteria.Op.EQ, id); + } else { + if (keyword != null) { + SearchCriteria ssc = _dcJoinDao.createSearchCriteria(); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } + + 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 + // list all zones belonging to this domain, and all of its + // parents + // 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 ){ + s_logger.error("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 ){ + domainRecord = _domainDao.findById(domainRecord.getParent()); + domainIds.add(domainRecord.getId()); + } + // 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); + sdc.addOr("domainId", SearchCriteria.Op.NULL); + sc.addAnd("domain", SearchCriteria.Op.SC, sdc); + + // remove disabled zones + sc.addAnd("allocationState", SearchCriteria.Op.NEQ, Grouping.AllocationState.Disabled); + + } 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 + List domainIds = new ArrayList(); + DomainVO domainRecord = _domainDao.findById(account.getDomainId()); + 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()); + } + domainIds.add(domainRecord.getId()); + // find all domain Ids till leaf + 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 ){ + domainRecord = _domainDao.findById(domainRecord.getParent()); + domainIds.add(domainRecord.getId()); + } + + // 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); + sdc.addOr("domainId", SearchCriteria.Op.NULL); + sc.addAnd("domain", SearchCriteria.Op.SC, sdc); + + // remove disabled zones + sc.addAnd("allocationState", SearchCriteria.Op.NEQ, Grouping.AllocationState.Disabled); + } + + // 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 + List routers = _routerDao.listBy(account.getId()); + for (DomainRouterVO router : routers){ + dcIds.add(router.getDataCenterIdToDeployIn()); + } + if ( dcIds.size() == 0) { + return new Pair, Integer>(new ArrayList(), 0); + } + else{ + sc.addAnd("idIn", SearchCriteria.Op.IN, dcIds); + } + + } + } + } + + return _dcJoinDao.searchAndCount(sc, searchFilter); + } + + // This method is used for permissions check for both disk and service // offerings private boolean isPermissible(Long accountDomainId, Long offeringDomainId) { @@ -2214,4 +2350,6 @@ public class QueryManagerImpl implements QueryService, Manager { return false; } + + } diff --git a/server/src/com/cloud/api/query/ViewResponseHelper.java b/server/src/com/cloud/api/query/ViewResponseHelper.java index dfccdceb8d4..55d84bb5af4 100644 --- a/server/src/com/cloud/api/query/ViewResponseHelper.java +++ b/server/src/com/cloud/api/query/ViewResponseHelper.java @@ -40,11 +40,13 @@ import org.apache.cloudstack.api.response.StoragePoolResponse; 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.log4j.Logger; import com.cloud.api.ApiDBUtils; import com.cloud.api.query.vo.AccountJoinVO; import com.cloud.api.query.vo.AsyncJobJoinVO; +import com.cloud.api.query.vo.DataCenterJoinVO; import com.cloud.api.query.vo.DiskOfferingJoinVO; import com.cloud.api.query.vo.DomainRouterJoinVO; import com.cloud.api.query.vo.EventJoinVO; @@ -294,4 +296,12 @@ public class ViewResponseHelper { } return respList; } + + public static List createDataCenterResponse(Boolean showCapacities, DataCenterJoinVO... dcs) { + List respList = new ArrayList(); + for (DataCenterJoinVO vt : dcs){ + respList.add(ApiDBUtils.newDataCenterResponse(vt, showCapacities)); + } + return respList; + } } diff --git a/server/src/com/cloud/api/query/dao/DataCenterJoinDao.java b/server/src/com/cloud/api/query/dao/DataCenterJoinDao.java new file mode 100644 index 00000000000..340f86f247d --- /dev/null +++ b/server/src/com/cloud/api/query/dao/DataCenterJoinDao.java @@ -0,0 +1,30 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.api.query.dao; + +import org.apache.cloudstack.api.response.ZoneResponse; + +import com.cloud.api.query.vo.DataCenterJoinVO; +import com.cloud.dc.DataCenter; +import com.cloud.utils.db.GenericDao; + +public interface DataCenterJoinDao extends GenericDao { + + ZoneResponse newDataCenterResponse(DataCenterJoinVO dof, Boolean showCapacities); + + DataCenterJoinVO newDataCenterView(DataCenter dof); +} diff --git a/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java new file mode 100644 index 00000000000..4ef182bb7ec --- /dev/null +++ b/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java @@ -0,0 +1,109 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.api.query.dao; + +import java.util.List; +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiDBUtils; +import com.cloud.api.ApiResponseHelper; +import com.cloud.api.query.vo.DataCenterJoinVO; +import com.cloud.dc.DataCenter; +import org.apache.cloudstack.api.response.ZoneResponse; + +import com.cloud.user.Account; +import com.cloud.user.UserContext; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + + +@Local(value={DataCenterJoinDao.class}) +public class DataCenterJoinDaoImpl extends GenericDaoBase implements DataCenterJoinDao { + public static final Logger s_logger = Logger.getLogger(DataCenterJoinDaoImpl.class); + + + private SearchBuilder dofIdSearch; + + protected DataCenterJoinDaoImpl() { + + dofIdSearch = createSearchBuilder(); + dofIdSearch.and("id", dofIdSearch.entity().getId(), SearchCriteria.Op.EQ); + dofIdSearch.done(); + + this._count = "select count(distinct id) from data_center_view WHERE "; + } + + + + @Override + public ZoneResponse newDataCenterResponse(DataCenterJoinVO dataCenter, Boolean showCapacities) { + + Account account = UserContext.current().getCaller(); + ZoneResponse zoneResponse = new ZoneResponse(); + zoneResponse.setId(dataCenter.getUuid()); + zoneResponse.setName(dataCenter.getName()); + zoneResponse.setSecurityGroupsEnabled(ApiDBUtils.isSecurityGroupEnabledInZone(dataCenter.getId())); + zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled()); + + if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) { + zoneResponse.setDescription(dataCenter.getDescription()); + } + + if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) { + zoneResponse.setDns1(dataCenter.getDns1()); + zoneResponse.setDns2(dataCenter.getDns2()); + zoneResponse.setInternalDns1(dataCenter.getInternalDns1()); + zoneResponse.setInternalDns2(dataCenter.getInternalDns2()); + // FIXME zoneResponse.setVlan(dataCenter.get.getVnet()); + zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr()); + } + + if (showCapacities != null && showCapacities) { + zoneResponse.setCapacitites(ApiResponseHelper.getDataCenterCapacityResponse(dataCenter.getId())); + } + + // set network domain info + zoneResponse.setDomain(dataCenter.getDomain()); + + // set domain info + + zoneResponse.setDomainId(dataCenter.getDomainUuid()); + zoneResponse.setDomainName(dataCenter.getDomainName()); + + zoneResponse.setType(dataCenter.getNetworkType().toString()); + zoneResponse.setAllocationState(dataCenter.getAllocationState().toString()); + zoneResponse.setZoneToken(dataCenter.getZoneToken()); + zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider()); + zoneResponse.setObjectName("zone"); + return zoneResponse; + } + + + @Override + public DataCenterJoinVO newDataCenterView(DataCenter dataCenter) { + SearchCriteria sc = dofIdSearch.create(); + sc.setParameters("id", dataCenter.getId()); + List dcs = searchIncludingRemoved(sc, null, null, false); + assert dcs != null && dcs.size() == 1 : "No data center found for data center id " + dataCenter.getId(); + return dcs.get(0); + } + + +} diff --git a/server/src/com/cloud/api/query/vo/DataCenterJoinVO.java b/server/src/com/cloud/api/query/vo/DataCenterJoinVO.java new file mode 100644 index 00000000000..67a3f2715f0 --- /dev/null +++ b/server/src/com/cloud/api/query/vo/DataCenterJoinVO.java @@ -0,0 +1,284 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.api.query.vo; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.dc.DataCenter.NetworkType; +import com.cloud.org.Grouping.AllocationState; +import com.cloud.utils.db.GenericDao; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +@Entity +@Table(name="data_center_view") +public class DataCenterJoinVO extends BaseViewVO implements InternalIdentity, Identity { + + @Id + @Column(name="id") + private long id; + + @Column(name="uuid") + private String uuid; + + @Column(name="name") + private String name; + + @Column(name="description") + private String description = null; + + @Column(name="dns1") + private String dns1 = null; + + @Column(name="dns2") + private String dns2 = null; + + @Column(name="internal_dns1") + private String internalDns1 = null; + + @Column(name="internal_dns2") + private String internalDns2 = null; + + @Column(name="guest_network_cidr") + private String guestNetworkCidr = null; + + @Column(name="domain") + private String domain; + + @Column(name="networktype") + @Enumerated(EnumType.STRING) + NetworkType networkType; + + @Column(name="dhcp_provider") + private String dhcpProvider; + + @Column(name="zone_token") + private String zoneToken; + + @Column(name="allocation_state") + @Enumerated(value=EnumType.STRING) + AllocationState allocationState; + + @Column(name="is_security_group_enabled") + boolean securityGroupEnabled; + + @Column(name="is_local_storage_enabled") + boolean localStorageEnabled; + + @Column(name=GenericDao.REMOVED_COLUMN) + private Date removed; + + @Column(name="domain_id") + private long domainId; + + @Column(name="domain_uuid") + private String domainUuid; + + @Column(name="domain_name") + private String domainName; + + @Column(name="domain_path") + private String domainPath; + + + public DataCenterJoinVO() { + } + + @Override + public long getId() { + return id; + } + + @Override + public void setId(long id) { + this.id = id; + } + + @Override + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDns1() { + return dns1; + } + + public void setDns1(String dns1) { + this.dns1 = dns1; + } + + public String getDns2() { + return dns2; + } + + public void setDns2(String dns2) { + this.dns2 = dns2; + } + + public String getInternalDns1() { + return internalDns1; + } + + public void setInternalDns1(String internalDns1) { + this.internalDns1 = internalDns1; + } + + public String getInternalDns2() { + return internalDns2; + } + + public void setInternalDns2(String internalDns2) { + this.internalDns2 = internalDns2; + } + + public String getGuestNetworkCidr() { + return guestNetworkCidr; + } + + public void setGuestNetworkCidr(String guestNetworkCidr) { + this.guestNetworkCidr = guestNetworkCidr; + } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + public NetworkType getNetworkType() { + return networkType; + } + + public void setNetworkType(NetworkType networkType) { + this.networkType = networkType; + } + + public String getDhcpProvider() { + return dhcpProvider; + } + + public void setDhcpProvider(String dhcpProvider) { + this.dhcpProvider = dhcpProvider; + } + + public String getZoneToken() { + return zoneToken; + } + + public void setZoneToken(String zoneToken) { + this.zoneToken = zoneToken; + } + + public AllocationState getAllocationState() { + return allocationState; + } + + public void setAllocationState(AllocationState allocationState) { + this.allocationState = allocationState; + } + + public boolean isSecurityGroupEnabled() { + return securityGroupEnabled; + } + + public void setSecurityGroupEnabled(boolean securityGroupEnabled) { + this.securityGroupEnabled = securityGroupEnabled; + } + + + public boolean isLocalStorageEnabled() { + return localStorageEnabled; + } + + public void setLocalStorageEnabled(boolean localStorageEnabled) { + this.localStorageEnabled = localStorageEnabled; + } + + public Date getRemoved() { + return removed; + } + + public void setRemoved(Date removed) { + this.removed = removed; + } + + public long getDomainId() { + return domainId; + } + + public void setDomainId(long domainId) { + this.domainId = domainId; + } + + public String getDomainUuid() { + return domainUuid; + } + + public void setDomainUuid(String domainUuid) { + this.domainUuid = domainUuid; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public String getDomainPath() { + return domainPath; + } + + public void setDomainPath(String domainPath) { + this.domainPath = domainPath; + } + + +} diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index 09a6d21fb78..ee70b55825b 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -27,6 +27,7 @@ import com.cloud.alert.dao.AlertDaoImpl; import com.cloud.api.query.QueryManagerImpl; import com.cloud.api.query.dao.AccountJoinDaoImpl; import com.cloud.api.query.dao.AsyncJobJoinDaoImpl; +import com.cloud.api.query.dao.DataCenterJoinDaoImpl; import com.cloud.api.query.dao.DiskOfferingJoinDaoImpl; import com.cloud.api.query.dao.ServiceOfferingJoinDaoImpl; import com.cloud.api.query.dao.DomainRouterJoinDaoImpl; @@ -399,6 +400,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com addDao("StoragePoolJoinDao", StoragePoolJoinDaoImpl.class); addDao("DiskOfferingJoinDao", DiskOfferingJoinDaoImpl.class); addDao("ServiceOfferingJoinDao", ServiceOfferingJoinDaoImpl.class); + addDao("DataCenterJoinDao", DataCenterJoinDaoImpl.class); } @Override diff --git a/server/src/com/cloud/dao/EntityManagerImpl.java b/server/src/com/cloud/dao/EntityManagerImpl.java index 2eee445f933..1d881927533 100644 --- a/server/src/com/cloud/dao/EntityManagerImpl.java +++ b/server/src/com/cloud/dao/EntityManagerImpl.java @@ -51,6 +51,13 @@ public class EntityManagerImpl implements EntityManager, Manager { return dao.findByUuid(uuid); } + @Override + public T findByUuidIncludingRemoved(Class entityType, String uuid) { + // Finds and returns a unique VO using uuid, null if entity not found in db + GenericDao dao = (GenericDao)GenericDaoBase.getDao(entityType); + return dao.findByUuidIncludingRemoved(uuid); + } + @Override public T findByXId(Class entityType, String xid) { return null; diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java index b05aece918e..7530e943116 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -1814,9 +1814,6 @@ public class NetworkServiceImpl implements NetworkService, Manager { throw new InvalidParameterValueException("Please specify valid integers for the vlan range."); } - //check for vnet conflicts with other physical network(s) in the zone - checkGuestVnetsConflicts(zoneId, vnetStart, vnetEnd, null); - if ((vnetStart > vnetEnd) || (vnetStart < 0) || (vnetEnd > 4096)) { s_logger.warn("Invalid vnet range: start range:" + vnetStart + " end range:" + vnetEnd); throw new InvalidParameterValueException("Vnet range should be between 0-4096 and start range should be lesser than or equal to end range"); @@ -1995,9 +1992,6 @@ public class NetworkServiceImpl implements NetworkService, Manager { throw new InvalidParameterValueException("Vnet range has to be" + rangeMessage + " and start range should be lesser than or equal to stop range"); } - //check if new vnet conflicts with vnet ranges of other physical networks - checkGuestVnetsConflicts(network.getDataCenterId(), newStartVnet, newEndVnet, network.getId()); - if (physicalNetworkHasAllocatedVnets(network.getDataCenterId(), network.getId())) { String[] existingRange = network.getVnet().split("-"); int existingStartVnet = Integer.parseInt(existingRange[0]); @@ -2042,24 +2036,6 @@ public class NetworkServiceImpl implements NetworkService, Manager { return network; } - protected void checkGuestVnetsConflicts(long zoneId, int newStartVnet, int newEndVnet, Long pNtwkIdToSkip) { - List pNtwks = _physicalNetworkDao.listByZone(zoneId); - for (PhysicalNetwork pNtwk : pNtwks) { - // skip my own network and networks that don't have vnet range set - if ((pNtwk.getVnet() == null || pNtwk.getVnet().isEmpty()) || (pNtwkIdToSkip != null && pNtwkIdToSkip == pNtwk.getId())) { - continue; - } - String[] existingRange = pNtwk.getVnet().split("-"); - int startVnet = Integer.parseInt(existingRange[0]); - int endVnet = Integer.parseInt(existingRange[1]); - if ((newStartVnet >= startVnet && newStartVnet <= endVnet) - || (newEndVnet <= endVnet && newEndVnet >= startVnet)) { - throw new InvalidParameterValueException("Vnet range for physical network conflicts with another " + - "physical network's vnet in the zone"); - } - } - } - private boolean physicalNetworkHasAllocatedVnets(long zoneId, long physicalNetworkId) { return !_dcDao.listAllocatedVnets(physicalNetworkId).isEmpty(); } diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index b6ee747bee9..f82424a10c2 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -560,8 +560,9 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma } @Override - public List listSwifts(ListSwiftsCmd cmd) { - return _swiftMgr.listSwifts(cmd); + public Pair, Integer> listSwifts(ListSwiftsCmd cmd) { + Pair, Integer> swifts = _swiftMgr.listSwifts(cmd); + return new Pair, Integer>(swifts.first(), swifts.second()); } @Override diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 8182421bf02..a2a74c25a9a 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -416,119 +416,7 @@ public class ManagementServerImpl implements ManagementServer { return PasswordGenerator.generateRandomPassword(6); } - @Override - public List listDataCenters(ListZonesByCmd cmd) { - Account account = UserContext.current().getCaller(); - List dcs = null; - Long domainId = cmd.getDomainId(); - Long id = cmd.getId(); - boolean removeDisabledZones = false; - String keyword = cmd.getKeyword(); - if (domainId != null) { - // for domainId != null - // right now, we made the decision to only list zones associated - // with this domain - dcs = _dcDao.findZonesByDomainId(domainId, keyword); // private - // zones - } else if ((account == null || account.getType() == Account.ACCOUNT_TYPE_ADMIN)) { - if (keyword != null) { - dcs = _dcDao.findByKeyword(keyword); - } else { - dcs = _dcDao.listAll(); // all zones - } - } 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 - // list all zones belonging to this domain, and all of its parents - // check the parent, if not null, add zones for that parent to list - dcs = new ArrayList(); - DomainVO domainRecord = _domainDao.findById(account.getDomainId()); - if (domainRecord != null) { - while (true) { - dcs.addAll(_dcDao.findZonesByDomainId(domainRecord.getId(), keyword)); - if (domainRecord.getParent() != null) { - domainRecord = _domainDao.findById(domainRecord.getParent()); - } else { - break; - } - } - } - // add all public zones too - dcs.addAll(_dcDao.listPublicZones(keyword)); - removeDisabledZones = true; - } 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 - dcs = new ArrayList(); - DomainVO domainRecord = _domainDao.findById(account.getDomainId()); - // this covers path till root - if (domainRecord != null) { - DomainVO localRecord = domainRecord; - while (true) { - dcs.addAll(_dcDao.findZonesByDomainId(localRecord.getId(), keyword)); - if (localRecord.getParent() != null) { - localRecord = _domainDao.findById(localRecord.getParent()); - } else { - break; - } - } - } - // this covers till leaf - if (domainRecord != null) { - // find all children for this domain based on a like search by - // path - List allChildDomains = _domainDao.findAllChildren(domainRecord.getPath(), domainRecord.getId()); - List allChildDomainIds = new ArrayList(); - // create list of domainIds for search - for (DomainVO domain : allChildDomains) { - allChildDomainIds.add(domain.getId()); - } - // now make a search for zones based on this - if (allChildDomainIds.size() > 0) { - List childZones = _dcDao.findChildZones((allChildDomainIds.toArray()), keyword); - dcs.addAll(childZones); - } - } - // add all public zones too - dcs.addAll(_dcDao.listPublicZones(keyword)); - removeDisabledZones = true; - } - if (removeDisabledZones) { - dcs.removeAll(_dcDao.listDisabledZones()); - } - - Boolean available = cmd.isAvailable(); - if (account != null) { - if ((available != null) && Boolean.FALSE.equals(available)) { - List routers = _routerDao.listBy(account.getId()); - for (Iterator iter = dcs.iterator(); iter.hasNext();) { - DataCenterVO dc = iter.next(); - boolean found = false; - for (DomainRouterVO router : routers) { - if (dc.getId() == router.getDataCenterIdToDeployIn()) { - found = true; - break; - } - } - if (!found) { - iter.remove(); - } - } - } - } - - if (id != null) { - List singleZone = new ArrayList(); - for (DataCenterVO zone : dcs) { - if (zone.getId() == id) { - singleZone.add(zone); - } - } - return singleZone; - } - return dcs; - } @Override public HostVO getHostBy(long hostId) { diff --git a/server/src/com/cloud/storage/swift/SwiftManager.java b/server/src/com/cloud/storage/swift/SwiftManager.java index 0dd6e1cf22a..2abdac7f807 100644 --- a/server/src/com/cloud/storage/swift/SwiftManager.java +++ b/server/src/com/cloud/storage/swift/SwiftManager.java @@ -27,6 +27,7 @@ import com.cloud.exception.DiscoveryException; import com.cloud.storage.Swift; import com.cloud.storage.SwiftVO; import com.cloud.storage.VMTemplateSwiftVO; +import com.cloud.utils.Pair; import com.cloud.utils.component.Manager; public interface SwiftManager extends Manager { @@ -50,7 +51,7 @@ public interface SwiftManager extends Manager { Long chooseZoneForTmpltExtract(Long tmpltId); - List listSwifts(ListSwiftsCmd cmd); + Pair, Integer> listSwifts(ListSwiftsCmd cmd); VMTemplateSwiftVO findByTmpltId(Long tmpltId); } diff --git a/server/src/com/cloud/storage/swift/SwiftManagerImpl.java b/server/src/com/cloud/storage/swift/SwiftManagerImpl.java index dab16ced985..d62dd63c068 100644 --- a/server/src/com/cloud/storage/swift/SwiftManagerImpl.java +++ b/server/src/com/cloud/storage/swift/SwiftManagerImpl.java @@ -50,6 +50,7 @@ import com.cloud.storage.dao.SwiftDao; import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.storage.dao.VMTemplateSwiftDao; import com.cloud.storage.dao.VMTemplateZoneDao; +import com.cloud.utils.Pair; import com.cloud.utils.component.Inject; import com.cloud.utils.db.Filter; import com.cloud.utils.db.SearchCriteria; @@ -242,7 +243,7 @@ public class SwiftManagerImpl implements SwiftManager { if (swift == null) { return null; } - + List tmpltHosts = _vmTmpltHostDao.listByOnlyTemplateId(tmpltId); if (tmpltHosts != null) { Collections.shuffle(tmpltHosts); @@ -260,13 +261,13 @@ public class SwiftManagerImpl implements SwiftManager { } @Override - public List listSwifts(ListSwiftsCmd cmd) { + public Pair, Integer> listSwifts(ListSwiftsCmd cmd) { Filter searchFilter = new Filter(SwiftVO.class, "id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal()); SearchCriteria sc = _swiftDao.createSearchCriteria(); if (cmd.getId() != null) { sc.addAnd("id", SearchCriteria.Op.EQ, cmd.getId()); } - return _swiftDao.search(sc, searchFilter); + return _swiftDao.searchAndCount(sc, searchFilter); } diff --git a/server/test/com/cloud/resource/MockResourceManagerImpl.java b/server/test/com/cloud/resource/MockResourceManagerImpl.java index e94cdea9853..a0dad479144 100644 --- a/server/test/com/cloud/resource/MockResourceManagerImpl.java +++ b/server/test/com/cloud/resource/MockResourceManagerImpl.java @@ -202,7 +202,7 @@ public class MockResourceManagerImpl implements ResourceManager, Manager { * @see com.cloud.resource.ResourceService#listSwifts(com.cloud.api.commands.ListSwiftsCmd) */ @Override - public List listSwifts(ListSwiftsCmd cmd) { + public Pair, Integer> listSwifts(ListSwiftsCmd cmd) { // TODO Auto-generated method stub return null; } diff --git a/setup/db/create-schema-view.sql b/setup/db/create-schema-view.sql index 495b6c5cd20..f68a6cadb71 100644 --- a/setup/db/create-schema-view.sql +++ b/setup/db/create-schema-view.sql @@ -14,862 +14,1123 @@ -- KIND, either express or implied. See the License for the -- specific language governing permissions and limitations -- under the License. -use cloud; ---- DB views for list api --- +-- DB views for list api + DROP VIEW IF EXISTS `cloud`.`user_vm_view`; CREATE VIEW `cloud`.`user_vm_view` AS -select -vm_instance.id id, -vm_instance.name name, -user_vm.display_name display_name, -user_vm.user_data user_data, -account.id account_id, -account.uuid account_uuid, -account.account_name account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name, -instance_group.id instance_group_id, -instance_group.uuid instance_group_uuid, -instance_group.name instance_group_name, -vm_instance.uuid uuid, -vm_instance.last_host_id last_host_id, -vm_instance.vm_type type, -vm_instance.vnc_password vnc_password, -vm_instance.limit_cpu_use limit_cpu_use, -vm_instance.created created, -vm_instance.state state, -vm_instance.removed removed, -vm_instance.ha_enabled ha_enabled, -vm_instance.hypervisor_type hypervisor_type, -vm_instance.instance_name instance_name, -vm_instance.guest_os_id guest_os_id, -guest_os.uuid guest_os_uuid, -vm_instance.pod_id pod_id, -host_pod_ref.uuid pod_uuid, -vm_instance.private_ip_address private_ip_address, -vm_instance.private_mac_address private_mac_address, -vm_instance.vm_type vm_type, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -data_center.is_security_group_enabled security_group_enabled, -host.id host_id, -host.uuid host_uuid, -host.name host_name, -vm_template.id template_id, -vm_template.uuid template_uuid, -vm_template.name template_name, -vm_template.display_text template_display_text, -vm_template.enable_password password_enabled, -iso.id iso_id, -iso.uuid iso_uuid, -iso.name iso_name, -iso.display_text iso_display_text, -service_offering.id service_offering_id, -disk_offering.uuid service_offering_uuid, -service_offering.cpu cpu, -service_offering.speed speed, -service_offering.ram_size ram_size, -disk_offering.name service_offering_name, -storage_pool.id pool_id, -storage_pool.uuid pool_uuid, -storage_pool.pool_type pool_type, -volumes.id volume_id, -volumes.uuid volume_uuid, -volumes.device_id volume_device_id, -volumes.volume_type volume_type, -security_group.id security_group_id, -security_group.uuid security_group_uuid, -security_group.name security_group_name, -security_group.description security_group_description, -nics.id nic_id, -nics.uuid nic_uuid, -nics.network_id network_id, -nics.ip4_address ip_address, -nics.default_nic is_default_nic, -nics.gateway gateway, -nics.netmask netmask, -nics.mac_address mac_address, -nics.broadcast_uri broadcast_uri, -nics.isolation_uri isolation_uri, -vpc.id vpc_id, -vpc.uuid vpc_uuid, -networks.uuid network_uuid, -networks.traffic_type traffic_type, -networks.guest_type guest_type, -user_ip_address.id public_ip_id, -user_ip_address.uuid public_ip_uuid, -user_ip_address.public_ip_address public_ip_address, -ssh_keypairs.keypair_name keypair_name, -resource_tags.id tag_id, -resource_tags.uuid tag_uuid, -resource_tags.key tag_key, -resource_tags.value tag_value, -resource_tags.domain_id tag_domain_id, -resource_tags.account_id tag_account_id, -resource_tags.resource_id tag_resource_id, -resource_tags.resource_uuid tag_resource_uuid, -resource_tags.resource_type tag_resource_type, -resource_tags.customer tag_customer, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from user_vm -inner join vm_instance on vm_instance.id = user_vm.id and vm_instance.removed is NULL -inner join account on vm_instance.account_id=account.id -inner join domain on vm_instance.domain_id=domain.id -left join guest_os on vm_instance.guest_os_id = guest_os.id -left join host_pod_ref on vm_instance.pod_id = host_pod_ref.id -left join projects on projects.project_account_id = account.id -left join instance_group_vm_map on vm_instance.id=instance_group_vm_map.instance_id -left join instance_group on instance_group_vm_map.group_id=instance_group.id -left join data_center on vm_instance.data_center_id=data_center.id -left join host on vm_instance.host_id=host.id -left join vm_template on vm_instance.vm_template_id=vm_template.id -left join vm_template iso on iso.id=user_vm.iso_id -left join service_offering on vm_instance.service_offering_id=service_offering.id -left join disk_offering on vm_instance.service_offering_id=disk_offering.id -left join volumes on vm_instance.id=volumes.instance_id -left join storage_pool on volumes.pool_id=storage_pool.id -left join security_group_vm_map on vm_instance.id=security_group_vm_map.instance_id -left join security_group on security_group_vm_map.security_group_id=security_group.id -left join nics on vm_instance.id=nics.instance_id -left join networks on nics.network_id=networks.id -left join vpc on networks.vpc_id = vpc.id -left join user_ip_address on user_ip_address.vm_id=vm_instance.id -left join user_vm_details on user_vm_details.vm_id=vm_instance.id and user_vm_details.name = "SSH.PublicKey" -left join ssh_keypairs on ssh_keypairs.public_key = user_vm_details.value -left join resource_tags on resource_tags.resource_id = vm_instance.id and resource_tags.resource_type = "UserVm" -left join async_job on async_job.instance_id = vm_instance.id and async_job.instance_type = "VirtualMachine" and async_job.job_status = 0; + select + vm_instance.id id, + vm_instance.name name, + user_vm.display_name display_name, + user_vm.user_data user_data, + account.id account_id, + account.uuid account_uuid, + account.account_name account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name, + instance_group.id instance_group_id, + instance_group.uuid instance_group_uuid, + instance_group.name instance_group_name, + vm_instance.uuid uuid, + vm_instance.last_host_id last_host_id, + vm_instance.vm_type type, + vm_instance.vnc_password vnc_password, + vm_instance.limit_cpu_use limit_cpu_use, + vm_instance.created created, + vm_instance.state state, + vm_instance.removed removed, + vm_instance.ha_enabled ha_enabled, + vm_instance.hypervisor_type hypervisor_type, + vm_instance.instance_name instance_name, + vm_instance.guest_os_id guest_os_id, + guest_os.uuid guest_os_uuid, + vm_instance.pod_id pod_id, + host_pod_ref.uuid pod_uuid, + vm_instance.private_ip_address private_ip_address, + vm_instance.private_mac_address private_mac_address, + vm_instance.vm_type vm_type, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + data_center.is_security_group_enabled security_group_enabled, + host.id host_id, + host.uuid host_uuid, + host.name host_name, + vm_template.id template_id, + vm_template.uuid template_uuid, + vm_template.name template_name, + vm_template.display_text template_display_text, + vm_template.enable_password password_enabled, + iso.id iso_id, + iso.uuid iso_uuid, + iso.name iso_name, + iso.display_text iso_display_text, + service_offering.id service_offering_id, + disk_offering.uuid service_offering_uuid, + service_offering.cpu cpu, + service_offering.speed speed, + service_offering.ram_size ram_size, + disk_offering.name service_offering_name, + storage_pool.id pool_id, + storage_pool.uuid pool_uuid, + storage_pool.pool_type pool_type, + volumes.id volume_id, + volumes.uuid volume_uuid, + volumes.device_id volume_device_id, + volumes.volume_type volume_type, + security_group.id security_group_id, + security_group.uuid security_group_uuid, + security_group.name security_group_name, + security_group.description security_group_description, + nics.id nic_id, + nics.uuid nic_uuid, + nics.network_id network_id, + nics.ip4_address ip_address, + nics.default_nic is_default_nic, + nics.gateway gateway, + nics.netmask netmask, + nics.mac_address mac_address, + nics.broadcast_uri broadcast_uri, + nics.isolation_uri isolation_uri, + vpc.id vpc_id, + vpc.uuid vpc_uuid, + networks.uuid network_uuid, + networks.traffic_type traffic_type, + networks.guest_type guest_type, + user_ip_address.id public_ip_id, + user_ip_address.uuid public_ip_uuid, + user_ip_address.public_ip_address public_ip_address, + ssh_keypairs.keypair_name keypair_name, + resource_tags.id tag_id, + resource_tags.uuid tag_uuid, + resource_tags.key tag_key, + resource_tags.value tag_value, + resource_tags.domain_id tag_domain_id, + resource_tags.account_id tag_account_id, + resource_tags.resource_id tag_resource_id, + resource_tags.resource_uuid tag_resource_uuid, + resource_tags.resource_type tag_resource_type, + resource_tags.customer tag_customer, + async_job.id job_id, + async_job.uuid job_uuid, + async_job.job_status job_status, + async_job.account_id job_account_id + from + `cloud`.`user_vm` + inner join + `cloud`.`vm_instance` ON vm_instance.id = user_vm.id + and vm_instance.removed is NULL + inner join + `cloud`.`account` ON vm_instance.account_id = account.id + inner join + `cloud`.`domain` ON vm_instance.domain_id = domain.id + left join + `cloud`.`guest_os` ON vm_instance.guest_os_id = guest_os.id + left join + `cloud`.`host_pod_ref` ON vm_instance.pod_id = host_pod_ref.id + left join + `cloud`.`projects` ON projects.project_account_id = account.id + left join + `cloud`.`instance_group_vm_map` ON vm_instance.id = instance_group_vm_map.instance_id + left join + `cloud`.`instance_group` ON instance_group_vm_map.group_id = instance_group.id + left join + `cloud`.`data_center` ON vm_instance.data_center_id = data_center.id + left join + `cloud`.`host` ON vm_instance.host_id = host.id + left join + `cloud`.`vm_template` ON vm_instance.vm_template_id = vm_template.id + left join + `cloud`.`vm_template` iso ON iso.id = user_vm.iso_id + left join + `cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id + left join + `cloud`.`disk_offering` ON vm_instance.service_offering_id = disk_offering.id + left join + `cloud`.`volumes` ON vm_instance.id = volumes.instance_id + left join + `cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id + left join + `cloud`.`security_group_vm_map` ON vm_instance.id = security_group_vm_map.instance_id + left join + `cloud`.`security_group` ON security_group_vm_map.security_group_id = security_group.id + left join + `cloud`.`nics` ON vm_instance.id = nics.instance_id + left join + `cloud`.`networks` ON nics.network_id = networks.id + left join + `cloud`.`vpc` ON networks.vpc_id = vpc.id + left join + `cloud`.`user_ip_address` ON user_ip_address.vm_id = vm_instance.id + left join + `cloud`.`user_vm_details` ON user_vm_details.vm_id = vm_instance.id + and user_vm_details.name = 'SSH.PublicKey' + left join + `cloud`.`ssh_keypairs` ON ssh_keypairs.public_key = user_vm_details.value + left join + `cloud`.`resource_tags` ON resource_tags.resource_id = vm_instance.id + and resource_tags.resource_type = 'UserVm' + left join + `cloud`.`async_job` ON async_job.instance_id = vm_instance.id + and async_job.instance_type = 'VirtualMachine' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`domain_router_view`; -CREATE VIEW domain_router_view AS -select -vm_instance.id id, -vm_instance.name name, -account.id account_id, -account.uuid account_uuid, -account.account_name account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name, -vm_instance.uuid uuid, -vm_instance.created created, -vm_instance.state state, -vm_instance.removed removed, -vm_instance.pod_id pod_id, -vm_instance.instance_name instance_name, -host_pod_ref.uuid pod_uuid, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -data_center.dns1 dns1, -data_center.dns2 dns2, -host.id host_id, -host.uuid host_uuid, -host.name host_name, -vm_template.id template_id, -vm_template.uuid template_uuid, -service_offering.id service_offering_id, -disk_offering.uuid service_offering_uuid, -disk_offering.name service_offering_name, -nics.id nic_id, -nics.uuid nic_uuid, -nics.network_id network_id, -nics.ip4_address ip_address, -nics.default_nic is_default_nic, -nics.gateway gateway, -nics.netmask netmask, -nics.mac_address mac_address, -nics.broadcast_uri broadcast_uri, -nics.isolation_uri isolation_uri, -vpc.id vpc_id, -vpc.uuid vpc_uuid, -networks.uuid network_uuid, -networks.name network_name, -networks.network_domain network_domain, -networks.traffic_type traffic_type, -networks.guest_type guest_type, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id, -domain_router.template_version template_version, -domain_router.scripts_version scripts_version, -domain_router.is_redundant_router is_redundant_router, -domain_router.redundant_state redundant_state, -domain_router.stop_pending stop_pending -from domain_router -inner join vm_instance on vm_instance.id = domain_router.id -inner join account on vm_instance.account_id=account.id -inner join domain on vm_instance.domain_id=domain.id -left join host_pod_ref on vm_instance.pod_id = host_pod_ref.id -left join projects on projects.project_account_id = account.id -left join data_center on vm_instance.data_center_id=data_center.id -left join host on vm_instance.host_id=host.id -left join vm_template on vm_instance.vm_template_id=vm_template.id -left join service_offering on vm_instance.service_offering_id=service_offering.id -left join disk_offering on vm_instance.service_offering_id=disk_offering.id -left join volumes on vm_instance.id=volumes.instance_id -left join storage_pool on volumes.pool_id=storage_pool.id -left join nics on vm_instance.id=nics.instance_id -left join networks on nics.network_id=networks.id -left join vpc on networks.vpc_id = vpc.id -left join async_job on async_job.instance_id = vm_instance.id and async_job.instance_type = "DomainRouter" and async_job.job_status = 0; +CREATE VIEW `cloud`.`domain_router_view` AS + select + vm_instance.id id, + vm_instance.name name, + account.id account_id, + account.uuid account_uuid, + account.account_name account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name, + vm_instance.uuid uuid, + vm_instance.created created, + vm_instance.state state, + vm_instance.removed removed, + vm_instance.pod_id pod_id, + vm_instance.instance_name instance_name, + host_pod_ref.uuid pod_uuid, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + data_center.dns1 dns1, + data_center.dns2 dns2, + host.id host_id, + host.uuid host_uuid, + host.name host_name, + vm_template.id template_id, + vm_template.uuid template_uuid, + service_offering.id service_offering_id, + disk_offering.uuid service_offering_uuid, + disk_offering.name service_offering_name, + nics.id nic_id, + nics.uuid nic_uuid, + nics.network_id network_id, + nics.ip4_address ip_address, + nics.default_nic is_default_nic, + nics.gateway gateway, + nics.netmask netmask, + nics.mac_address mac_address, + nics.broadcast_uri broadcast_uri, + nics.isolation_uri isolation_uri, + vpc.id vpc_id, + vpc.uuid vpc_uuid, + networks.uuid network_uuid, + networks.name network_name, + networks.network_domain network_domain, + networks.traffic_type traffic_type, + networks.guest_type guest_type, + async_job.id job_id, + async_job.uuid job_uuid, + async_job.job_status job_status, + async_job.account_id job_account_id, + domain_router.template_version template_version, + domain_router.scripts_version scripts_version, + domain_router.is_redundant_router is_redundant_router, + domain_router.redundant_state redundant_state, + domain_router.stop_pending stop_pending + from + `cloud`.`domain_router` + inner join + `cloud`.`vm_instance` ON vm_instance.id = domain_router.id + inner join + `cloud`.`account` ON vm_instance.account_id = account.id + inner join + `cloud`.`domain` ON vm_instance.domain_id = domain.id + left join + `cloud`.`host_pod_ref` ON vm_instance.pod_id = host_pod_ref.id + left join + `cloud`.`projects` ON projects.project_account_id = account.id + left join + `cloud`.`data_center` ON vm_instance.data_center_id = data_center.id + left join + `cloud`.`host` ON vm_instance.host_id = host.id + left join + `cloud`.`vm_template` ON vm_instance.vm_template_id = vm_template.id + left join + `cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id + left join + `cloud`.`disk_offering` ON vm_instance.service_offering_id = disk_offering.id + left join + `cloud`.`volumes` ON vm_instance.id = volumes.instance_id + left join + `cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id + left join + `cloud`.`nics` ON vm_instance.id = nics.instance_id + left join + `cloud`.`networks` ON nics.network_id = networks.id + left join + `cloud`.`vpc` ON networks.vpc_id = vpc.id + left join + `cloud`.`async_job` ON async_job.instance_id = vm_instance.id + and async_job.instance_type = 'DomainRouter' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`security_group_view`; -CREATE VIEW security_group_view AS -select -security_group.id id, -security_group.name name, -security_group.description description, -security_group.uuid uuid, -account.id account_id, -account.uuid account_uuid, -account.account_name account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name, -security_group_rule.id rule_id, -security_group_rule.uuid rule_uuid, -security_group_rule.type rule_type, -security_group_rule.start_port rule_start_port, -security_group_rule.end_port rule_end_port, -security_group_rule.protocol rule_protocol, -security_group_rule.allowed_network_id rule_allowed_network_id, -security_group_rule.allowed_ip_cidr rule_allowed_ip_cidr, -security_group_rule.create_status rule_create_status, -resource_tags.id tag_id, -resource_tags.uuid tag_uuid, -resource_tags.key tag_key, -resource_tags.value tag_value, -resource_tags.domain_id tag_domain_id, -resource_tags.account_id tag_account_id, -resource_tags.resource_id tag_resource_id, -resource_tags.resource_uuid tag_resource_uuid, -resource_tags.resource_type tag_resource_type, -resource_tags.customer tag_customer, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from security_group -left join security_group_rule on security_group.id = security_group_rule.security_group_id -inner join account on security_group.account_id=account.id -inner join domain on security_group.domain_id=domain.id -left join projects on projects.project_account_id = security_group.account_id -left join resource_tags on resource_tags.resource_id = security_group.id and resource_tags.resource_type = "SecurityGroup" -left join async_job on async_job.instance_id = security_group.id and async_job.instance_type = "SecurityGroup" and async_job.job_status = 0; +CREATE VIEW `cloud`.`security_group_view` AS + select + security_group.id id, + security_group.name name, + security_group.description description, + security_group.uuid uuid, + account.id account_id, + account.uuid account_uuid, + account.account_name account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name, + security_group_rule.id rule_id, + security_group_rule.uuid rule_uuid, + security_group_rule.type rule_type, + security_group_rule.start_port rule_start_port, + security_group_rule.end_port rule_end_port, + security_group_rule.protocol rule_protocol, + security_group_rule.allowed_network_id rule_allowed_network_id, + security_group_rule.allowed_ip_cidr rule_allowed_ip_cidr, + security_group_rule.create_status rule_create_status, + resource_tags.id tag_id, + resource_tags.uuid tag_uuid, + resource_tags.key tag_key, + resource_tags.value tag_value, + resource_tags.domain_id tag_domain_id, + resource_tags.account_id tag_account_id, + resource_tags.resource_id tag_resource_id, + resource_tags.resource_uuid tag_resource_uuid, + resource_tags.resource_type tag_resource_type, + resource_tags.customer tag_customer, + async_job.id job_id, + async_job.uuid job_uuid, + async_job.job_status job_status, + async_job.account_id job_account_id + from + `cloud`.`security_group` + left join + `cloud`.`security_group_rule` ON security_group.id = security_group_rule.security_group_id + inner join + `cloud`.`account` ON security_group.account_id = account.id + inner join + `cloud`.`domain` ON security_group.domain_id = domain.id + left join + `cloud`.`projects` ON projects.project_account_id = security_group.account_id + left join + `cloud`.`resource_tags` ON resource_tags.resource_id = security_group.id + and resource_tags.resource_type = 'SecurityGroup' + left join + `cloud`.`async_job` ON async_job.instance_id = security_group.id + and async_job.instance_type = 'SecurityGroup' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`resource_tag_view`; -CREATE VIEW resource_tag_view AS -select -resource_tags.id, -resource_tags.uuid, -resource_tags.key, -resource_tags.value, -resource_tags.resource_id, -resource_tags.resource_uuid, -resource_tags.resource_type, -resource_tags.customer, -account.id account_id, -account.uuid account_uuid, -account.account_name account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name -from resource_tags -inner join account on resource_tags.account_id=account.id -inner join domain on resource_tags.domain_id=domain.id -left join projects on projects.project_account_id = resource_tags.account_id; +CREATE VIEW `cloud`.`resource_tag_view` AS + select + resource_tags.id, + resource_tags.uuid, + resource_tags.key, + resource_tags.value, + resource_tags.resource_id, + resource_tags.resource_uuid, + resource_tags.resource_type, + resource_tags.customer, + account.id account_id, + account.uuid account_uuid, + account.account_name account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name + from + `cloud`.`resource_tags` + inner join + `cloud`.`account` ON resource_tags.account_id = account.id + inner join + `cloud`.`domain` ON resource_tags.domain_id = domain.id + left join + `cloud`.`projects` ON projects.project_account_id = resource_tags.account_id; DROP VIEW IF EXISTS `cloud`.`event_view`; -CREATE VIEW event_view AS -select -event.id, -event.uuid, -event.type, -event.state, -event.description, -event.created, -event.level, -event.parameters, -event.start_id, -eve.uuid start_uuid, -event.user_id, -user.username user_name, -account.id account_id, -account.uuid account_uuid, -account.account_name account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name -from event -inner join account on event.account_id=account.id -inner join domain on event.domain_id=domain.id -inner join user on event.user_id = user.id -left join projects on projects.project_account_id = event.account_id -left join event eve on event.start_id = eve.id; +CREATE VIEW `cloud`.`event_view` AS + select + event.id, + event.uuid, + event.type, + event.state, + event.description, + event.created, + event.level, + event.parameters, + event.start_id, + eve.uuid start_uuid, + event.user_id, + user.username user_name, + account.id account_id, + account.uuid account_uuid, + account.account_name account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name + from + `cloud`.`event` + inner join + `cloud`.`account` ON event.account_id = account.id + inner join + `cloud`.`domain` ON event.domain_id = domain.id + inner join + `cloud`.`user` ON event.user_id = user.id + left join + `cloud`.`projects` ON projects.project_account_id = event.account_id + left join + `cloud`.`event` eve ON event.start_id = eve.id; DROP VIEW IF EXISTS `cloud`.`instance_group_view`; -CREATE VIEW instance_group_view AS -select -instance_group.id, -instance_group.uuid, -instance_group.name, -instance_group.removed, -instance_group.created, -account.id account_id, -account.uuid account_uuid, -account.account_name account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name -from instance_group -inner join account on instance_group.account_id=account.id -inner join domain on account.domain_id=domain.id -left join projects on projects.project_account_id = instance_group.account_id; +CREATE VIEW `cloud`.`instance_group_view` AS + select + instance_group.id, + instance_group.uuid, + instance_group.name, + instance_group.removed, + instance_group.created, + account.id account_id, + account.uuid account_uuid, + account.account_name account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name + from + `cloud`.`instance_group` + inner join + `cloud`.`account` ON instance_group.account_id = account.id + inner join + `cloud`.`domain` ON account.domain_id = domain.id + left join + `cloud`.`projects` ON projects.project_account_id = instance_group.account_id; DROP VIEW IF EXISTS `cloud`.`user_view`; -CREATE VIEW user_view AS -select -user.id, -user.uuid, -user.username, -user.password, -user.firstname, -user.lastname, -user.email, -user.state, -user.api_key, -user.secret_key, -user.created, -user.removed, -user.timezone, -user.registration_token, -user.is_registered, -user.incorrect_login_attempts, -account.id account_id, -account.uuid account_uuid, -account.account_name account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from user -inner join account on user.account_id = account.id -inner join domain on account.domain_id=domain.id -left join async_job on async_job.instance_id = user.id and async_job.instance_type = "User" and async_job.job_status = 0; - - +CREATE VIEW `cloud`.`user_view` AS + select + user.id, + user.uuid, + user.username, + user.password, + user.firstname, + user.lastname, + user.email, + user.state, + user.api_key, + user.secret_key, + user.created, + user.removed, + user.timezone, + user.registration_token, + user.is_registered, + user.incorrect_login_attempts, + account.id account_id, + account.uuid account_uuid, + account.account_name account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + async_job.id job_id, + async_job.uuid job_uuid, + async_job.job_status job_status, + async_job.account_id job_account_id + from + `cloud`.`user` + inner join + `cloud`.`account` ON user.account_id = account.id + inner join + `cloud`.`domain` ON account.domain_id = domain.id + left join + `cloud`.`async_job` ON async_job.instance_id = user.id + and async_job.instance_type = 'User' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`project_view`; -CREATE VIEW project_view AS -select -projects.id, -projects.uuid, -projects.name, -projects.display_text, -projects.state, -projects.removed, -projects.created, -account.account_name owner, -pacct.account_id, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -resource_tags.id tag_id, -resource_tags.uuid tag_uuid, -resource_tags.key tag_key, -resource_tags.value tag_value, -resource_tags.domain_id tag_domain_id, -resource_tags.account_id tag_account_id, -resource_tags.resource_id tag_resource_id, -resource_tags.resource_uuid tag_resource_uuid, -resource_tags.resource_type tag_resource_type, -resource_tags.customer tag_customer -from projects -inner join domain on projects.domain_id=domain.id -inner join project_account on projects.id = project_account.project_id and project_account.account_role = "Admin" -inner join account on account.id = project_account.account_id -left join resource_tags on resource_tags.resource_id = projects.id and resource_tags.resource_type = "Project" -left join project_account pacct on projects.id = pacct.project_id; +CREATE VIEW `cloud`.`project_view` AS + select + projects.id, + projects.uuid, + projects.name, + projects.display_text, + projects.state, + projects.removed, + projects.created, + account.account_name owner, + pacct.account_id, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + resource_tags.id tag_id, + resource_tags.uuid tag_uuid, + resource_tags.key tag_key, + resource_tags.value tag_value, + resource_tags.domain_id tag_domain_id, + resource_tags.account_id tag_account_id, + resource_tags.resource_id tag_resource_id, + resource_tags.resource_uuid tag_resource_uuid, + resource_tags.resource_type tag_resource_type, + resource_tags.customer tag_customer + from + `cloud`.`projects` + inner join + `cloud`.`domain` ON projects.domain_id = domain.id + inner join + `cloud`.`project_account` ON projects.id = project_account.project_id + and project_account.account_role = 'Admin' + inner join + `cloud`.`account` ON account.id = project_account.account_id + left join + `cloud`.`resource_tags` ON resource_tags.resource_id = projects.id + and resource_tags.resource_type = 'Project' + left join + `cloud`.`project_account` pacct ON projects.id = pacct.project_id; DROP VIEW IF EXISTS `cloud`.`project_account_view`; -CREATE VIEW project_account_view AS -select -project_account.id, -account.id account_id, -account.uuid account_uuid, -account.account_name, -account.type account_type, -project_account.account_role, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path -from project_account -inner join account on project_account.account_id = account.id -inner join domain on account.domain_id=domain.id -inner join projects on projects.id = project_account.project_id; +CREATE VIEW `cloud`.`project_account_view` AS + select + project_account.id, + account.id account_id, + account.uuid account_uuid, + account.account_name, + account.type account_type, + project_account.account_role, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`project_account` + inner join + `cloud`.`account` ON project_account.account_id = account.id + inner join + `cloud`.`domain` ON account.domain_id = domain.id + inner join + `cloud`.`projects` ON projects.id = project_account.project_id; DROP VIEW IF EXISTS `cloud`.`project_invitation_view`; -CREATE VIEW project_invitation_view AS -select -project_invitations.id, -project_invitations.uuid, -project_invitations.email, -project_invitations.created, -project_invitations.state, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name, -account.id account_id, -account.uuid account_uuid, -account.account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path -from project_invitations -left join account on project_invitations.account_id = account.id -left join domain on project_invitations.domain_id=domain.id -left join projects on projects.id = project_invitations.project_id; +CREATE VIEW `cloud`.`project_invitation_view` AS + select + project_invitations.id, + project_invitations.uuid, + project_invitations.email, + project_invitations.created, + project_invitations.state, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name, + account.id account_id, + account.uuid account_uuid, + account.account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`project_invitations` + left join + `cloud`.`account` ON project_invitations.account_id = account.id + left join + `cloud`.`domain` ON project_invitations.domain_id = domain.id + left join + `cloud`.`projects` ON projects.id = project_invitations.project_id; DROP VIEW IF EXISTS `cloud`.`host_view`; -CREATE VIEW host_view AS -select -host.id, -host.uuid, -host.name, -host.status, -host.disconnected, -host.type, -host.private_ip_address, -host.version, -host.hypervisor_type, -host.hypervisor_version, -host.capabilities, -host.last_ping, -host.created, -host.removed, -host.resource_state, -host.mgmt_server_id, -host.cpus, -host.speed, -host.ram, -cluster.id cluster_id, -cluster.uuid cluster_uuid, -cluster.name cluster_name, -cluster.cluster_type, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -host_pod_ref.id pod_id, -host_pod_ref.uuid pod_uuid, -host_pod_ref.name pod_name, -host_tags.tag, -guest_os_category.id guest_os_category_id, -guest_os_category.uuid guest_os_category_uuid, -guest_os_category.name guest_os_category_name, -mem_caps.used_capacity memory_used_capacity, -mem_caps.reserved_capacity memory_reserved_capacity, -cpu_caps.used_capacity cpu_used_capacity, -cpu_caps.reserved_capacity cpu_reserved_capacity, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from host -left join cluster on host.cluster_id = cluster.id -left join data_center on host.data_center_id = data_center.id -left join host_pod_ref on host.pod_id = host_pod_ref.id -left join host_details on host.id = host_details.id and host_details.name = "guest.os.category.id" -left join guest_os_category on guest_os_category.id = CONVERT( host_details.value, UNSIGNED ) -left join host_tags on host_tags.host_id = host.id -left join op_host_capacity mem_caps on host.id = mem_caps.host_id and mem_caps.capacity_type = 0 -left join op_host_capacity cpu_caps on host.id = cpu_caps.host_id and cpu_caps.capacity_type = 1 -left join async_job on async_job.instance_id = host.id and async_job.instance_type = "Host" and async_job.job_status = 0; +CREATE VIEW `cloud`.`host_view` AS + select + host.id, + host.uuid, + host.name, + host.status, + host.disconnected, + host.type, + host.private_ip_address, + host.version, + host.hypervisor_type, + host.hypervisor_version, + host.capabilities, + host.last_ping, + host.created, + host.removed, + host.resource_state, + host.mgmt_server_id, + host.cpus, + host.speed, + host.ram, + cluster.id cluster_id, + cluster.uuid cluster_uuid, + cluster.name cluster_name, + cluster.cluster_type, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + host_pod_ref.id pod_id, + host_pod_ref.uuid pod_uuid, + host_pod_ref.name pod_name, + host_tags.tag, + guest_os_category.id guest_os_category_id, + guest_os_category.uuid guest_os_category_uuid, + guest_os_category.name guest_os_category_name, + mem_caps.used_capacity memory_used_capacity, + mem_caps.reserved_capacity memory_reserved_capacity, + cpu_caps.used_capacity cpu_used_capacity, + cpu_caps.reserved_capacity cpu_reserved_capacity, + async_job.id job_id, + async_job.uuid job_uuid, + async_job.job_status job_status, + async_job.account_id job_account_id + from + `cloud`.`host` + left join + `cloud`.`cluster` ON host.cluster_id = cluster.id + left join + `cloud`.`data_center` ON host.data_center_id = data_center.id + left join + `cloud`.`host_pod_ref` ON host.pod_id = host_pod_ref.id + left join + `cloud`.`host_details` ON host.id = host_details.id + and host_details.name = 'guest.os.category.id' + left join + `cloud`.`guest_os_category` ON guest_os_category.id = CONVERT( host_details.value , UNSIGNED) + left join + `cloud`.`host_tags` ON host_tags.host_id = host.id + left join + `cloud`.`op_host_capacity` mem_caps ON host.id = mem_caps.host_id + and mem_caps.capacity_type = 0 + left join + `cloud`.`op_host_capacity` cpu_caps ON host.id = cpu_caps.host_id + and cpu_caps.capacity_type = 1 + left join + `cloud`.`async_job` ON async_job.instance_id = host.id + and async_job.instance_type = 'Host' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`volume_view`; -CREATE VIEW volume_view AS -select -volumes.id, -volumes.uuid, -volumes.name, -volumes.device_id, -volumes.volume_type, -volumes.size, -volumes.created, -volumes.state, -volumes.attached, -volumes.removed, -volumes.pod_id, -account.id account_id, -account.uuid account_uuid, -account.account_name account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -vm_instance.id vm_id, -vm_instance.uuid vm_uuid, -vm_instance.name vm_name, -vm_instance.state vm_state, -vm_instance.vm_type, -user_vm.display_name vm_display_name, -volume_host_ref.size volume_host_size, -volume_host_ref.created volume_host_created, -volume_host_ref.format, -volume_host_ref.download_pct, -volume_host_ref.download_state, -volume_host_ref.error_str, -disk_offering.id disk_offering_id, -disk_offering.uuid disk_offering_uuid, -disk_offering.name disk_offering_name, -disk_offering.display_text disk_offering_display_text, -disk_offering.use_local_storage, -disk_offering.system_use, -storage_pool.id pool_id, -storage_pool.uuid pool_uuid, -storage_pool.name pool_name, -cluster.hypervisor_type, -vm_template.id template_id, -vm_template.uuid template_uuid, -vm_template.extractable, -vm_template.type template_type, -resource_tags.id tag_id, -resource_tags.uuid tag_uuid, -resource_tags.key tag_key, -resource_tags.value tag_value, -resource_tags.domain_id tag_domain_id, -resource_tags.account_id tag_account_id, -resource_tags.resource_id tag_resource_id, -resource_tags.resource_uuid tag_resource_uuid, -resource_tags.resource_type tag_resource_type, -resource_tags.customer tag_customer, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from volumes -inner join account on volumes.account_id=account.id -inner join domain on volumes.domain_id=domain.id -left join projects on projects.project_account_id = account.id -left join data_center on volumes.data_center_id = data_center.id -left join vm_instance on volumes.instance_id = vm_instance.id -left join user_vm on user_vm.id = vm_instance.id -left join volume_host_ref on volumes.id = volume_host_ref.volume_id and volumes.data_center_id = volume_host_ref.zone_id -left join disk_offering on volumes.disk_offering_id = disk_offering.id -left join storage_pool on volumes.pool_id = storage_pool.id -left join cluster on storage_pool.cluster_id = cluster.id -left join vm_template on volumes.template_id = vm_template.id -left join resource_tags on resource_tags.resource_id = volumes.id and resource_tags.resource_type = "Volume" -left join async_job on async_job.instance_id = volumes.id and async_job.instance_type = "Volume" and async_job.job_status = 0; +CREATE VIEW `cloud`.`volume_view` AS + select + volumes.id, + volumes.uuid, + volumes.name, + volumes.device_id, + volumes.volume_type, + volumes.size, + volumes.created, + volumes.state, + volumes.attached, + volumes.removed, + volumes.pod_id, + account.id account_id, + account.uuid account_uuid, + account.account_name account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + vm_instance.id vm_id, + vm_instance.uuid vm_uuid, + vm_instance.name vm_name, + vm_instance.state vm_state, + vm_instance.vm_type, + user_vm.display_name vm_display_name, + volume_host_ref.size volume_host_size, + volume_host_ref.created volume_host_created, + volume_host_ref.format, + volume_host_ref.download_pct, + volume_host_ref.download_state, + volume_host_ref.error_str, + disk_offering.id disk_offering_id, + disk_offering.uuid disk_offering_uuid, + disk_offering.name disk_offering_name, + disk_offering.display_text disk_offering_display_text, + disk_offering.use_local_storage, + disk_offering.system_use, + storage_pool.id pool_id, + storage_pool.uuid pool_uuid, + storage_pool.name pool_name, + cluster.hypervisor_type, + vm_template.id template_id, + vm_template.uuid template_uuid, + vm_template.extractable, + vm_template.type template_type, + resource_tags.id tag_id, + resource_tags.uuid tag_uuid, + resource_tags.key tag_key, + resource_tags.value tag_value, + resource_tags.domain_id tag_domain_id, + resource_tags.account_id tag_account_id, + resource_tags.resource_id tag_resource_id, + resource_tags.resource_uuid tag_resource_uuid, + resource_tags.resource_type tag_resource_type, + resource_tags.customer tag_customer, + async_job.id job_id, + async_job.uuid job_uuid, + async_job.job_status job_status, + async_job.account_id job_account_id + from + `cloud`.`volumes` + inner join + `cloud`.`account` ON volumes.account_id = account.id + inner join + `cloud`.`domain` ON volumes.domain_id = domain.id + left join + `cloud`.`projects` ON projects.project_account_id = account.id + left join + `cloud`.`data_center` ON volumes.data_center_id = data_center.id + left join + `cloud`.`vm_instance` ON volumes.instance_id = vm_instance.id + left join + `cloud`.`user_vm` ON user_vm.id = vm_instance.id + left join + `cloud`.`volume_host_ref` ON volumes.id = volume_host_ref.volume_id + and volumes.data_center_id = volume_host_ref.zone_id + left join + `cloud`.`disk_offering` ON volumes.disk_offering_id = disk_offering.id + left join + `cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id + left join + `cloud`.`cluster` ON storage_pool.cluster_id = cluster.id + left join + `cloud`.`vm_template` ON volumes.template_id = vm_template.id + left join + `cloud`.`resource_tags` ON resource_tags.resource_id = volumes.id + and resource_tags.resource_type = 'Volume' + left join + `cloud`.`async_job` ON async_job.instance_id = volumes.id + and async_job.instance_type = 'Volume' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`account_netstats_view`; -CREATE VIEW account_netstats_view AS -SELECT account_id, -sum(net_bytes_received)+ sum(current_bytes_received) as bytesReceived, -sum(net_bytes_sent)+ sum(current_bytes_sent) as bytesSent -FROM user_statistics -group by account_id; +CREATE VIEW `cloud`.`account_netstats_view` AS + SELECT + account_id, + sum(net_bytes_received) + sum(current_bytes_received) as bytesReceived, + sum(net_bytes_sent) + sum(current_bytes_sent) as bytesSent + FROM + `cloud`.`user_statistics` + group by account_id; DROP VIEW IF EXISTS `cloud`.`account_vmstats_view`; -CREATE VIEW account_vmstats_view AS -SELECT account_id, state, count(*) as vmcount -from vm_instance -group by account_id, state; +CREATE VIEW `cloud`.`account_vmstats_view` AS + SELECT + account_id, state, count(*) as vmcount + from + `cloud`.`vm_instance` + group by account_id , state; DROP VIEW IF EXISTS `cloud`.`free_ip_view`; -CREATE VIEW free_ip_view AS -select count(user_ip_address.id) free_ip -from user_ip_address -inner join vlan on vlan.id = user_ip_address.vlan_db_id and vlan.vlan_type = "VirtualNetwork" -where state = "Free"; +CREATE VIEW `cloud`.`free_ip_view` AS + select + count(user_ip_address.id) free_ip + from + `cloud`.`user_ip_address` + inner join + `cloud`.`vlan` ON vlan.id = user_ip_address.vlan_db_id + and vlan.vlan_type = 'VirtualNetwork' + where + state = 'Free'; DROP VIEW IF EXISTS `cloud`.`account_view`; -CREATE VIEW account_view AS -select -account.id, -account.uuid, -account.account_name, -account.type, -account.state, -account.removed, -account.cleanup_needed, -account.network_domain, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -account_netstats_view.bytesReceived, -account_netstats_view.bytesSent, -vmlimit.max vmLimit, -vmcount.count vmTotal, -runningvm.vmcount runningVms, -stoppedvm.vmcount stoppedVms, -iplimit.max ipLimit, -ipcount.count ipTotal, -free_ip_view.free_ip ipFree, -volumelimit.max volumeLimit, -volumecount.count volumeTotal, -snapshotlimit.max snapshotLimit, -snapshotcount.count snapshotTotal, -templatelimit.max templateLimit, -templatecount.count templateTotal, -vpclimit.max vpcLimit, -vpccount.count vpcTotal, -projectlimit.max projectLimit, -projectcount.count projectTotal, -networklimit.max networkLimit, -networkcount.count networkTotal, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from free_ip_view, account -inner join domain on account.domain_id=domain.id -left join data_center on account.default_zone_id = data_center.id -left join account_netstats_view on account.id = account_netstats_view.account_id -left join resource_limit vmlimit on account.id = vmlimit.account_id and vmlimit.type = "user_vm" -left join resource_count vmcount on account.id = vmcount.account_id and vmcount.type = "user_vm" -left join account_vmstats_view runningvm on account.id = runningvm.account_id and runningvm.state = "Running" -left join account_vmstats_view stoppedvm on account.id = stoppedvm.account_id and stoppedvm.state = "Stopped" -left join resource_limit iplimit on account.id = iplimit.account_id and iplimit.type = "public_ip" -left join resource_count ipcount on account.id = ipcount.account_id and ipcount.type = "public_ip" -left join resource_limit volumelimit on account.id = volumelimit.account_id and volumelimit.type = "volume" -left join resource_count volumecount on account.id = volumecount.account_id and volumecount.type = "volume" -left join resource_limit snapshotlimit on account.id = snapshotlimit.account_id and snapshotlimit.type = "snapshot" -left join resource_count snapshotcount on account.id = snapshotcount.account_id and snapshotcount.type = "snapshot" -left join resource_limit templatelimit on account.id = templatelimit.account_id and templatelimit.type = "template" -left join resource_count templatecount on account.id = templatecount.account_id and templatecount.type = "template" -left join resource_limit vpclimit on account.id = vpclimit.account_id and vpclimit.type = "vpc" -left join resource_count vpccount on account.id = vpccount.account_id and vpccount.type = "vpc" -left join resource_limit projectlimit on account.id = projectlimit.account_id and projectlimit.type = "project" -left join resource_count projectcount on account.id = projectcount.account_id and projectcount.type = "project" -left join resource_limit networklimit on account.id = networklimit.account_id and networklimit.type = "network" -left join resource_count networkcount on account.id = networkcount.account_id and networkcount.type = "network" -left join async_job on async_job.instance_id = account.id and async_job.instance_type = "Account" and async_job.job_status = 0; +CREATE VIEW `cloud`.`account_view` AS + select + account.id, + account.uuid, + account.account_name, + account.type, + account.state, + account.removed, + account.cleanup_needed, + account.network_domain, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + account_netstats_view.bytesReceived, + account_netstats_view.bytesSent, + vmlimit.max vmLimit, + vmcount.count vmTotal, + runningvm.vmcount runningVms, + stoppedvm.vmcount stoppedVms, + iplimit.max ipLimit, + ipcount.count ipTotal, + free_ip_view.free_ip ipFree, + volumelimit.max volumeLimit, + volumecount.count volumeTotal, + snapshotlimit.max snapshotLimit, + snapshotcount.count snapshotTotal, + templatelimit.max templateLimit, + templatecount.count templateTotal, + vpclimit.max vpcLimit, + vpccount.count vpcTotal, + projectlimit.max projectLimit, + projectcount.count projectTotal, + networklimit.max networkLimit, + networkcount.count networkTotal, + async_job.id job_id, + async_job.uuid job_uuid, + async_job.job_status job_status, + async_job.account_id job_account_id + from + `cloud`.`free_ip_view`, + `cloud`.`account` + inner join + `cloud`.`domain` ON account.domain_id = domain.id + left join + `cloud`.`data_center` ON account.default_zone_id = data_center.id + left join + `cloud`.`account_netstats_view` ON account.id = account_netstats_view.account_id + left join + `cloud`.`resource_limit` vmlimit ON account.id = vmlimit.account_id + and vmlimit.type = 'user_vm' + left join + `cloud`.`resource_count` vmcount ON account.id = vmcount.account_id + and vmcount.type = 'user_vm' + left join + `cloud`.`account_vmstats_view` runningvm ON account.id = runningvm.account_id + and runningvm.state = 'Running' + left join + `cloud`.`account_vmstats_view` stoppedvm ON account.id = stoppedvm.account_id + and stoppedvm.state = 'Stopped' + left join + `cloud`.`resource_limit` iplimit ON account.id = iplimit.account_id + and iplimit.type = 'public_ip' + left join + `cloud`.`resource_count` ipcount ON account.id = ipcount.account_id + and ipcount.type = 'public_ip' + left join + `cloud`.`resource_limit` volumelimit ON account.id = volumelimit.account_id + and volumelimit.type = 'volume' + left join + `cloud`.`resource_count` volumecount ON account.id = volumecount.account_id + and volumecount.type = 'volume' + left join + `cloud`.`resource_limit` snapshotlimit ON account.id = snapshotlimit.account_id + and snapshotlimit.type = 'snapshot' + left join + `cloud`.`resource_count` snapshotcount ON account.id = snapshotcount.account_id + and snapshotcount.type = 'snapshot' + left join + `cloud`.`resource_limit` templatelimit ON account.id = templatelimit.account_id + and templatelimit.type = 'template' + left join + `cloud`.`resource_count` templatecount ON account.id = templatecount.account_id + and templatecount.type = 'template' + left join + `cloud`.`resource_limit` vpclimit ON account.id = vpclimit.account_id + and vpclimit.type = 'vpc' + left join + `cloud`.`resource_count` vpccount ON account.id = vpccount.account_id + and vpccount.type = 'vpc' + left join + `cloud`.`resource_limit` projectlimit ON account.id = projectlimit.account_id + and projectlimit.type = 'project' + left join + `cloud`.`resource_count` projectcount ON account.id = projectcount.account_id + and projectcount.type = 'project' + left join + `cloud`.`resource_limit` networklimit ON account.id = networklimit.account_id + and networklimit.type = 'network' + left join + `cloud`.`resource_count` networkcount ON account.id = networkcount.account_id + and networkcount.type = 'network' + left join + `cloud`.`async_job` ON async_job.instance_id = account.id + and async_job.instance_type = 'Account' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`async_job_view`; -CREATE VIEW async_job_view AS -select -account.id account_id, -account.uuid account_uuid, -account.account_name account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -user.id user_id, -user.uuid user_uuid, -async_job.id, -async_job.uuid, -async_job.job_cmd, -async_job.job_status, -async_job.job_process_status, -async_job.job_result_code, -async_job.job_result, -async_job.created, -async_job.removed, -async_job.instance_type, -async_job.instance_id, -CASE -WHEN async_job.instance_type = 'Volume' THEN volumes.uuid -WHEN async_job.instance_type = 'Template' or async_job.instance_type = 'Iso' THEN vm_template.uuid -WHEN async_job.instance_type = 'VirtualMachine' or async_job.instance_type = 'ConsoleProxy' or async_job.instance_type = 'SystemVm' or async_job.instance_type = 'DomainRouter' THEN vm_instance.uuid -WHEN async_job.instance_type = 'Snapshot' THEN snapshots.uuid -WHEN async_job.instance_type = 'Host' THEN host.uuid -WHEN async_job.instance_type = 'StoragePool' THEN storage_pool.uuid -WHEN async_job.instance_type = 'IpAddress' THEN user_ip_address.uuid -WHEN async_job.instance_type = 'SecurityGroup' THEN security_group.uuid -WHEN async_job.instance_type = 'PhysicalNetwork' THEN physical_network.uuid -WHEN async_job.instance_type = 'TrafficType' THEN physical_network_traffic_types.uuid -WHEN async_job.instance_type = 'PhysicalNetworkServiceProvider' THEN physical_network_service_providers.uuid -WHEN async_job.instance_type = 'FirewallRule' THEN firewall_rules.uuid -WHEN async_job.instance_type = 'Account' THEN acct.uuid -WHEN async_job.instance_type = 'User' THEN us.uuid -WHEN async_job.instance_type = 'StaticRoute' THEN static_routes.uuid -WHEN async_job.instance_type = 'PrivateGateway' THEN vpc_gateways.uuid -WHEN async_job.instance_type = 'Counter' THEN counter.uuid -WHEN async_job.instance_type = 'Condition' THEN conditions.uuid -WHEN async_job.instance_type = 'AutoScalePolicy' THEN autoscale_policies.uuid -WHEN async_job.instance_type = 'AutoScaleVmProfile' THEN autoscale_vmprofiles.uuid -WHEN async_job.instance_type = 'AutoScaleVmGroup' THEN autoscale_vmgroups.uuid -ELSE null -END instance_uuid -from async_job -left join account on async_job.account_id = account.id -left join domain on domain.id = account.domain_id -left join user on async_job.user_id = user.id -left join volumes on async_job.instance_id = volumes.id -left join vm_template on async_job.instance_id = vm_template.id -left join vm_instance on async_job.instance_id = vm_instance.id -left join snapshots on async_job.instance_id = snapshots.id -left join host on async_job.instance_id = host.id -left join storage_pool on async_job.instance_id = storage_pool.id -left join user_ip_address on async_job.instance_id = user_ip_address.id -left join security_group on async_job.instance_id = security_group.id -left join physical_network on async_job.instance_id = physical_network.id -left join physical_network_traffic_types on async_job.instance_id = physical_network_traffic_types.id -left join physical_network_service_providers on async_job.instance_id = physical_network_service_providers.id -left join firewall_rules on async_job.instance_id = firewall_rules.id -left join account acct on async_job.instance_id = acct.id -left join user us on async_job.instance_id = us.id -left join static_routes on async_job.instance_id = static_routes.id -left join vpc_gateways on async_job.instance_id = vpc_gateways.id -left join counter on async_job.instance_id = counter.id -left join conditions on async_job.instance_id = conditions.id -left join autoscale_policies on async_job.instance_id = autoscale_policies.id -left join autoscale_vmprofiles on async_job.instance_id = autoscale_vmprofiles.id -left join autoscale_vmgroups on async_job.instance_id = autoscale_vmgroups.id; +CREATE VIEW `cloud`.`async_job_view` AS + select + account.id account_id, + account.uuid account_uuid, + account.account_name account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + user.id user_id, + user.uuid user_uuid, + async_job.id, + async_job.uuid, + async_job.job_cmd, + async_job.job_status, + async_job.job_process_status, + async_job.job_result_code, + async_job.job_result, + async_job.created, + async_job.removed, + async_job.instance_type, + async_job.instance_id, + CASE + WHEN async_job.instance_type = 'Volume' THEN volumes.uuid + WHEN + async_job.instance_type = 'Template' + or async_job.instance_type = 'Iso' + THEN + vm_template.uuid + WHEN + async_job.instance_type = 'VirtualMachine' + or async_job.instance_type = 'ConsoleProxy' + or async_job.instance_type = 'SystemVm' + or async_job.instance_type = 'DomainRouter' + THEN + vm_instance.uuid + WHEN async_job.instance_type = 'Snapshot' THEN snapshots.uuid + WHEN async_job.instance_type = 'Host' THEN host.uuid + WHEN async_job.instance_type = 'StoragePool' THEN storage_pool.uuid + WHEN async_job.instance_type = 'IpAddress' THEN user_ip_address.uuid + WHEN async_job.instance_type = 'SecurityGroup' THEN security_group.uuid + WHEN async_job.instance_type = 'PhysicalNetwork' THEN physical_network.uuid + WHEN async_job.instance_type = 'TrafficType' THEN physical_network_traffic_types.uuid + WHEN async_job.instance_type = 'PhysicalNetworkServiceProvider' THEN physical_network_service_providers.uuid + WHEN async_job.instance_type = 'FirewallRule' THEN firewall_rules.uuid + WHEN async_job.instance_type = 'Account' THEN acct.uuid + WHEN async_job.instance_type = 'User' THEN us.uuid + WHEN async_job.instance_type = 'StaticRoute' THEN static_routes.uuid + WHEN async_job.instance_type = 'PrivateGateway' THEN vpc_gateways.uuid + WHEN async_job.instance_type = 'Counter' THEN counter.uuid + WHEN async_job.instance_type = 'Condition' THEN conditions.uuid + WHEN async_job.instance_type = 'AutoScalePolicy' THEN autoscale_policies.uuid + WHEN async_job.instance_type = 'AutoScaleVmProfile' THEN autoscale_vmprofiles.uuid + WHEN async_job.instance_type = 'AutoScaleVmGroup' THEN autoscale_vmgroups.uuid + ELSE null + END instance_uuid + from + `cloud`.`async_job` + left join + `cloud`.`account` ON async_job.account_id = account.id + left join + `cloud`.`domain` ON domain.id = account.domain_id + left join + `cloud`.`user` ON async_job.user_id = user.id + left join + `cloud`.`volumes` ON async_job.instance_id = volumes.id + left join + `cloud`.`vm_template` ON async_job.instance_id = vm_template.id + left join + `cloud`.`vm_instance` ON async_job.instance_id = vm_instance.id + left join + `cloud`.`snapshots` ON async_job.instance_id = snapshots.id + left join + `cloud`.`host` ON async_job.instance_id = host.id + left join + `cloud`.`storage_pool` ON async_job.instance_id = storage_pool.id + left join + `cloud`.`user_ip_address` ON async_job.instance_id = user_ip_address.id + left join + `cloud`.`security_group` ON async_job.instance_id = security_group.id + left join + `cloud`.`physical_network` ON async_job.instance_id = physical_network.id + left join + `cloud`.`physical_network_traffic_types` ON async_job.instance_id = physical_network_traffic_types.id + left join + `cloud`.`physical_network_service_providers` ON async_job.instance_id = physical_network_service_providers.id + left join + `cloud`.`firewall_rules` ON async_job.instance_id = firewall_rules.id + left join + `cloud`.`account` acct ON async_job.instance_id = acct.id + left join + `cloud`.`user` us ON async_job.instance_id = us.id + left join + `cloud`.`static_routes` ON async_job.instance_id = static_routes.id + left join + `cloud`.`vpc_gateways` ON async_job.instance_id = vpc_gateways.id + left join + `cloud`.`counter` ON async_job.instance_id = counter.id + left join + `cloud`.`conditions` ON async_job.instance_id = conditions.id + left join + `cloud`.`autoscale_policies` ON async_job.instance_id = autoscale_policies.id + left join + `cloud`.`autoscale_vmprofiles` ON async_job.instance_id = autoscale_vmprofiles.id + left join + `cloud`.`autoscale_vmgroups` ON async_job.instance_id = autoscale_vmgroups.id; DROP VIEW IF EXISTS `cloud`.`storage_pool_view`; -CREATE VIEW storage_pool_view AS -select -storage_pool.id, -storage_pool.uuid, -storage_pool.name, -storage_pool.status, -storage_pool.path, -storage_pool.pool_type, -storage_pool.host_address, -storage_pool.created, -storage_pool.removed, -storage_pool.capacity_bytes, -cluster.id cluster_id, -cluster.uuid cluster_uuid, -cluster.name cluster_name, -cluster.cluster_type, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -host_pod_ref.id pod_id, -host_pod_ref.uuid pod_uuid, -host_pod_ref.name pod_name, -storage_pool_details.name tag, -op_host_capacity.used_capacity disk_used_capacity, -op_host_capacity.reserved_capacity disk_reserved_capacity, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from storage_pool -left join cluster on storage_pool.cluster_id = cluster.id -left join data_center on storage_pool.data_center_id = data_center.id -left join host_pod_ref on storage_pool.pod_id = host_pod_ref.id -left join storage_pool_details on storage_pool_details.pool_id = storage_pool.id and storage_pool_details.value = 'true' -left join op_host_capacity on storage_pool.id = op_host_capacity.host_id and op_host_capacity.capacity_type = 3 -left join async_job on async_job.instance_id = storage_pool.id and async_job.instance_type = "StoragePool" and async_job.job_status = 0; +CREATE VIEW `cloud`.`storage_pool_view` AS + select + storage_pool.id, + storage_pool.uuid, + storage_pool.name, + storage_pool.status, + storage_pool.path, + storage_pool.pool_type, + storage_pool.host_address, + storage_pool.created, + storage_pool.removed, + storage_pool.capacity_bytes, + cluster.id cluster_id, + cluster.uuid cluster_uuid, + cluster.name cluster_name, + cluster.cluster_type, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + host_pod_ref.id pod_id, + host_pod_ref.uuid pod_uuid, + host_pod_ref.name pod_name, + storage_pool_details.name tag, + op_host_capacity.used_capacity disk_used_capacity, + op_host_capacity.reserved_capacity disk_reserved_capacity, + async_job.id job_id, + async_job.uuid job_uuid, + async_job.job_status job_status, + async_job.account_id job_account_id + from + `cloud`.`storage_pool` + left join + `cloud`.`cluster` ON storage_pool.cluster_id = cluster.id + left join + `cloud`.`data_center` ON storage_pool.data_center_id = data_center.id + left join + `cloud`.`host_pod_ref` ON storage_pool.pod_id = host_pod_ref.id + left join + `cloud`.`storage_pool_details` ON storage_pool_details.pool_id = storage_pool.id + and storage_pool_details.value = 'true' + left join + `cloud`.`op_host_capacity` ON storage_pool.id = op_host_capacity.host_id + and op_host_capacity.capacity_type = 3 + left join + `cloud`.`async_job` ON async_job.instance_id = storage_pool.id + and async_job.instance_type = 'StoragePool' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`disk_offering_view`; -CREATE VIEW disk_offering_view AS -select -disk_offering.id, -disk_offering.uuid, -disk_offering.name, -disk_offering.display_text, -disk_offering.disk_size, -disk_offering.created, -disk_offering.tags, -disk_offering.customized, -disk_offering.removed, -disk_offering.use_local_storage, -disk_offering.system_use, -disk_offering.sort_key, -disk_offering.type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path -from disk_offering -left join domain on disk_offering.domain_id=domain.id; +CREATE VIEW `cloud`.`disk_offering_view` AS + select + disk_offering.id, + disk_offering.uuid, + disk_offering.name, + disk_offering.display_text, + disk_offering.disk_size, + disk_offering.created, + disk_offering.tags, + disk_offering.customized, + disk_offering.removed, + disk_offering.use_local_storage, + disk_offering.system_use, + disk_offering.sort_key, + disk_offering.type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`disk_offering` + left join + `cloud`.`domain` ON disk_offering.domain_id = domain.id; DROP VIEW IF EXISTS `cloud`.`service_offering_view`; -CREATE VIEW service_offering_view AS -select -service_offering.id, -disk_offering.uuid, -disk_offering.name, -disk_offering.display_text, -disk_offering.created, -disk_offering.tags, -disk_offering.removed, -disk_offering.use_local_storage, -disk_offering.system_use, -service_offering.cpu, -service_offering.speed, -service_offering.ram_size, -service_offering.nw_rate, -service_offering.mc_rate, -service_offering.ha_enabled, -service_offering.limit_cpu_use, -service_offering.host_tag, -service_offering.default_use, -service_offering.vm_type, -service_offering.sort_key, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path -from service_offering -inner join disk_offering on service_offering.id = disk_offering.id -left join domain on disk_offering.domain_id=domain.id; +CREATE VIEW `cloud`.`service_offering_view` AS + select + service_offering.id, + disk_offering.uuid, + disk_offering.name, + disk_offering.display_text, + disk_offering.created, + disk_offering.tags, + disk_offering.removed, + disk_offering.use_local_storage, + disk_offering.system_use, + service_offering.cpu, + service_offering.speed, + service_offering.ram_size, + service_offering.nw_rate, + service_offering.mc_rate, + service_offering.ha_enabled, + service_offering.limit_cpu_use, + service_offering.host_tag, + service_offering.default_use, + service_offering.vm_type, + service_offering.sort_key, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`service_offering` + inner join + `cloud`.`disk_offering` ON service_offering.id = disk_offering.id + left join + `cloud`.`domain` ON disk_offering.domain_id = domain.id; + +DROP VIEW IF EXISTS `cloud`.`data_center_view`; +CREATE VIEW `cloud`.`data_center_view` AS + select + data_center.id, + data_center.uuid, + data_center.name, + data_center.is_security_group_enabled, + data_center.is_local_storage_enabled, + data_center.description, + data_center.dns1, + data_center.dns2, + data_center.internal_dns1, + data_center.internal_dns2, + data_center.guest_network_cidr, + data_center.domain, + data_center.networktype, + data_center.allocation_state, + data_center.zone_token, + data_center.dhcp_provider, + data_center.removed, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`data_center` + left join + `cloud`.`domain` ON data_center.domain_id = domain.id; \ No newline at end of file diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql index 947059e7f94..93949b8e4fa 100644 --- a/setup/db/db/schema-40to410.sql +++ b/setup/db/db/schema-40to410.sql @@ -194,16 +194,11 @@ CREATE VIEW `cloud`.`user_vm_view` AS vm_template.name template_name, vm_template.display_text template_display_text, vm_template.enable_password password_enabled, --- iso.id iso_id, --- iso.uuid iso_uuid, --- iso.name iso_name, --- iso.display_text iso_display_text, --- FIXME workaround - NULL iso_id, - NULL iso_uuid, - NULL iso_name, - NULL iso_display_text, service_offering.id service_offering_id, --- end of workaround + iso.id iso_id, + iso.uuid iso_uuid, + iso.name iso_name, + iso.display_text iso_display_text, + service_offering.id service_offering_id, disk_offering.uuid service_offering_uuid, service_offering.cpu cpu, service_offering.speed speed, @@ -278,8 +273,8 @@ CREATE VIEW `cloud`.`user_vm_view` AS `cloud`.`host` ON vm_instance.host_id = host.id left join `cloud`.`vm_template` ON vm_instance.vm_template_id = vm_template.id --- left join --- `cloud`.`vm_template iso` ON iso.id = user_vm.iso_id + left join + `cloud`.`vm_template` iso ON iso.id = user_vm.iso_id left join `cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id left join @@ -1237,4 +1232,33 @@ CREATE VIEW `cloud`.`service_offering_view` AS left join `cloud`.`domain` ON disk_offering.domain_id = domain.id; +DROP VIEW IF EXISTS `cloud`.`data_center_view`; +CREATE VIEW `cloud`.`data_center_view` AS + select + data_center.id, + data_center.uuid, + data_center.name, + data_center.is_security_group_enabled, + data_center.is_local_storage_enabled, + data_center.description, + data_center.dns1, + data_center.dns2, + data_center.internal_dns1, + data_center.internal_dns2, + data_center.guest_network_cidr, + data_center.domain, + data_center.networktype, + data_center.allocation_state, + data_center.zone_token, + data_center.dhcp_provider, + data_center.removed, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`data_center` + left join + `cloud`.`domain` ON data_center.domain_id = domain.id; + INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'direct.agent.pool.size', '500', 'Default size for DirectAgentPool'); diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py index 339a2014522..eadf23ff173 100644 --- a/tools/cli/cloudmonkey/cloudmonkey.py +++ b/tools/cli/cloudmonkey/cloudmonkey.py @@ -75,7 +75,8 @@ class CloudMonkeyShell(cmd.Cmd, object): # datastructure {'verb': {cmd': ['api', [params], doc, required=[]]}} cache_verbs = precached_verbs - def __init__(self): + def __init__(self, pname): + self.program_name = pname if os.path.exists(self.config_file): config = self.read_config() else: @@ -262,8 +263,9 @@ class CloudMonkeyShell(cmd.Cmd, object): return isAsync = isAsync and (self.asyncblock == "true") - if isAsync and 'jobid' in response[response.keys()[0]]: - jobId = response[response.keys()[0]]['jobid'] + responsekey = filter(lambda x: 'response' in x, response.keys())[0] + if isAsync and 'jobid' in response[responsekey]: + jobId = response[responsekey]['jobid'] command = "queryAsyncJobResult" requests = {'jobid': jobId} timeout = int(self.timeout) @@ -282,7 +284,7 @@ class CloudMonkeyShell(cmd.Cmd, object): jobstatus = result['jobstatus'] if jobstatus == 2: jobresult = result["jobresult"] - self.print_shell("Async query failed for jobid=", + self.print_shell("\rAsync query failed for jobid", jobId, "\nError", jobresult["errorcode"], jobresult["errortext"]) return @@ -293,7 +295,7 @@ class CloudMonkeyShell(cmd.Cmd, object): timeout = timeout - pollperiod progress += 1 logger.debug("job: %s to timeout in %ds" % (jobId, timeout)) - self.print_shell("Error:", "Async query timeout for jobid=", jobId) + self.print_shell("Error:", "Async query timeout for jobid", jobId) return response @@ -306,7 +308,19 @@ class CloudMonkeyShell(cmd.Cmd, object): return None return api_mod + def pipe_runner(self, args): + if args.find(' |') > -1: + pname = self.program_name + if '.py' in pname: + pname = "python " + pname + self.do_shell("%s %s" % (pname, args)) + return True + return False + def default(self, args): + if self.pipe_runner(args): + return + lexp = shlex.shlex(args.strip()) lexp.whitespace = " " lexp.whitespace_split = True @@ -387,7 +401,8 @@ class CloudMonkeyShell(cmd.Cmd, object): self.cache_verbs[verb][subject][1]) search_string = text - autocompletions.append("filter=") + if self.tabularize == "true": + autocompletions.append("filter=") return [s for s in autocompletions if s.startswith(search_string)] def do_api(self, args): @@ -504,22 +519,21 @@ def main(): for rule in grammar: def add_grammar(rule): def grammar_closure(self, args): - if '|' in args: # FIXME: Consider parsing issues - prog_name = sys.argv[0] - if '.py' in prog_name: - prog_name = "python " + prog_name - self.do_shell("%s %s %s" % (prog_name, rule, args)) + if self.pipe_runner("%s %s" % (rule, args)): return try: args_partition = args.partition(" ") res = self.cache_verbs[rule][args_partition[0]] + cmd = res[0] + helpdoc = res[2] + args = args_partition[2] except KeyError, e: self.print_shell("Error: invalid %s api arg" % rule, e) return if ' --help' in args or ' -h' in args: - self.print_shell(res[2]) + self.print_shell(helpdoc) return - self.default(res[0] + " " + args_partition[2]) + self.default("%s %s" % (cmd, args)) return grammar_closure grammar_handler = add_grammar(rule) @@ -527,7 +541,7 @@ def main(): grammar_handler.__name__ = 'do_' + rule setattr(self, grammar_handler.__name__, grammar_handler) - shell = CloudMonkeyShell() + shell = CloudMonkeyShell(sys.argv[0]) if len(sys.argv) > 1: shell.onecmd(' '.join(sys.argv[1:])) else: diff --git a/tools/cli/cloudmonkey/common.py b/tools/cli/cloudmonkey/common.py index 3199af26c85..0865a8ee8cc 100644 --- a/tools/cli/cloudmonkey/common.py +++ b/tools/cli/cloudmonkey/common.py @@ -40,9 +40,9 @@ config_fields = {'host': 'localhost', 'port': '8080', os.path.expanduser('~/.cloudmonkey_history')} # Add verbs in grammar -grammar = ['create', 'list', 'delete', 'update', +grammar = ['create', 'list', 'delete', 'update', 'lock', 'enable', 'activate', 'disable', 'add', 'remove', - 'attach', 'detach', 'associate', 'generate', 'ldap', + 'attach', 'detach', 'associate', 'disassociate', 'generate', 'ldap', 'assign', 'authorize', 'change', 'register', 'configure', 'start', 'restart', 'reboot', 'stop', 'reconnect', 'cancel', 'destroy', 'revoke', 'mark', 'reset', diff --git a/tools/cli/setup.py b/tools/cli/setup.py index 739c044f7dd..f1efa741a02 100644 --- a/tools/cli/setup.py +++ b/tools/cli/setup.py @@ -53,7 +53,7 @@ setup( include_package_data = True, zip_safe = False, classifiers = [ - "Development Status :: 4 - Beta", + "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: End Users/Desktop", diff --git a/tools/devcloud-kvm/pom.xml b/tools/devcloud-kvm/pom.xml index c9af192bee3..f29e8375219 100644 --- a/tools/devcloud-kvm/pom.xml +++ b/tools/devcloud-kvm/pom.xml @@ -12,7 +12,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 cloud-devcloud-kvm - Apache CloudStack Developer Tools + Apache CloudStack DevCloud-KVM pom org.apache.cloudstack @@ -27,6 +27,14 @@ 5.1.21 runtime + + org.apache.cloudstack + cloud-developer + ${project.version} + pom + true + runtime + diff --git a/tools/devcloud/devcloud.sql b/tools/devcloud/devcloud.sql index cebf5a3702e..009c2b5c0d5 100644 --- a/tools/devcloud/devcloud.sql +++ b/tools/devcloud/devcloud.sql @@ -37,4 +37,4 @@ INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'se UPDATE `cloud`.`configuration` SET value='10' where name = 'storage.overprovisioning.factor'; UPDATE `cloud`.`configuration` SET value='10' where name = 'cpu.overprovisioning.factor'; UPDATE `cloud`.`configuration` SET value='10' where name = 'mem.overprovisioning.factor'; -UPDATE `cloud`.`vm_template` SET unique_name="tiny Linux",name="tiny Linux",url="https://github.com/downloads/bhaisaab/incubator-cloudstack/ttylinux_pv.vhd",checksum="046e134e642e6d344b34648223ba4bc1",display_text="tiny Linux" where id=5; +UPDATE `cloud`.`vm_template` SET unique_name="tiny Linux",name="tiny Linux",url="http://people.apache.org/~bhaisaab/vms/ttylinux_pv.vhd",checksum="046e134e642e6d344b34648223ba4bc1",display_text="tiny Linux" where id=5; diff --git a/tools/devcloud/devcloud_internal-mgt.cfg b/tools/devcloud/devcloud_internal-mgt.cfg new file mode 100644 index 00000000000..fe3dd1b41da --- /dev/null +++ b/tools/devcloud/devcloud_internal-mgt.cfg @@ -0,0 +1,121 @@ +# 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. +# + +{ + "zones": [ + { + "name": "DevCloud0", + "physical_networks": [ + { + "broadcastdomainrange": "Zone", + "name": "test-network", + "traffictypes": [ + { + "typ": "Guest" + }, + { + "typ": "Management" + } + ], + "providers": [ + { + "broadcastdomainrange": "ZONE", + "name": "VirtualRouter" + }, + { + "broadcastdomainrange": "Pod", + "name": "SecurityGroupProvider" + } + ] + } + ], + "dns2": "4.4.4.4", + "dns1": "8.8.8.8", + "securitygroupenabled": "true", + "localstorageenabled": "true", + "networktype": "Basic", + "pods": [ + { + "endip": "192.168.56.220", + "name": "test00", + "startip": "192.168.56.200", + "guestIpRanges": [ + { + "startip": "192.168.56.100", + "endip": "192.168.56.199", + "netmask": "255.255.255.0", + "gateway": "192.168.56.1" + } + ], + "netmask": "255.255.255.0", + "clusters": [ + { + "clustername": "test000", + "hypervisor": "XenServer", + "hosts": [ + { + "username": "root", + "url": "http://192.168.56.10/", + "password": "password" + } + ], + "clustertype": "CloudManaged" + } + ], + "gateway": "192.168.56.1" + } + ], + "internaldns1": "192.168.56.1", + "secondaryStorages": [ + { + "url": "nfs://192.168.56.10:/opt/storage/secondary" + } + ] + } + ], + "logger": [ + { + "name": "TestClient", + "file": "/tmp/testclient.log" + }, + { + "name": "TestCase", + "file": "/tmp/testcase.log" + } + ], + "mgtSvr": [ + { + "mgtSvrIp": "192.168.56.10", + "port": 8096 + } + ], + "dbSvr": + { + "dbSvr": "127.0.0.1", + "port": 3306, + "user": "cloud", + "passwd": "cloud", + "db": "cloud" + } + "globalConfig": [ + { + "name": "host", + "value": "192.168.56.10" + } + ] +} diff --git a/tools/devcloud/pom.xml b/tools/devcloud/pom.xml index 5c532c90a1b..8345e6468af 100644 --- a/tools/devcloud/pom.xml +++ b/tools/devcloud/pom.xml @@ -12,7 +12,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 cloud-devcloud - Apache CloudStack Developer Tools + Apache CloudStack DevCloud pom org.apache.cloudstack @@ -27,6 +27,14 @@ 5.1.21 runtime + + org.apache.cloudstack + cloud-developer + ${project.version} + pom + true + runtime + diff --git a/ui/css/cloudstack3.css b/ui/css/cloudstack3.css index db101d21ec4..6519ed053e8 100644 --- a/ui/css/cloudstack3.css +++ b/ui/css/cloudstack3.css @@ -5859,6 +5859,10 @@ label.error { margin: 7px 0px 7px 7px; } +.multi-wizard.instance-wizard .select-network.no-add-network .select-vpc { + visibility: hidden !important; +} + .multi-wizard.instance-wizard .select-network .select-vpc select { width: 124px; } diff --git a/ui/scripts/accounts.js b/ui/scripts/accounts.js index 59e9d8bbd15..4c327ee759b 100644 --- a/ui/scripts/accounts.js +++ b/ui/scripts/accounts.js @@ -642,12 +642,16 @@ }, vmLimit: { label: 'label.instance.limits', - isEditable: function(context) { + isEditable: function(context) { + + if(context.accounts == undefined) + return false; + else { if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin return true; else return false; - } + } } }, ipLimit: { label: 'label.ip.limits', diff --git a/ui/scripts/instanceWizard.js b/ui/scripts/instanceWizard.js index 8ebee623bf5..070f7e7b98d 100644 --- a/ui/scripts/instanceWizard.js +++ b/ui/scripts/instanceWizard.js @@ -16,7 +16,7 @@ // under the License. (function($, cloudStack) { - var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, featuredIsoObjs, community; + var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, featuredIsoObjs, community, networkObjs; var selectedZoneObj, selectedTemplateObj, selectedHypervisor, selectedDiskOfferingObj; var step5ContainerType = 'nothing-to-select'; //'nothing-to-select', 'select-network', 'select-security-group' @@ -40,6 +40,33 @@ !data.vpcid; }, + // Runs when advanced SG-enabled zone is run, before + // the security group step + // + // -- if it returns false, then 'Select Security Group' is skipped. + // + advSGFilter: function(args) { + var selectedNetworks; + + if ($.isArray(args.data['my-networks'])) { + selectedNetworks = $(args.data['my-networks']).map(function(index, myNetwork) { + return $.grep(networkObjs, function(networkObj) { + return networkObj.id == myNetwork; + }); + }); + } else { + selectedNetworks = $.grep(networkObjs, function(networkObj) { + return networkObj.id == args.data['my-networks']; + }); + } + + return $.grep(selectedNetworks, function(network) { + return $.grep(network.service, function(service) { + return service.name == 'SecurityGroup'; + }).length; + }).length; + }, + // Data providers for each wizard step steps: [ @@ -347,7 +374,7 @@ networkData.account = g_account; } - var networkObjs, vpcObjs; + var vpcObjs; //listVPCs without account/domainid/listAll parameter will return only VPCs belonging to the current login. That's what should happen in Instances page's VM Wizard. //i.e. If the current login is root-admin, do not show VPCs belonging to regular-user/domain-admin in Instances page's VM Wizard. @@ -365,7 +392,7 @@ async: false, success: function(json) { networkObjs = json.listnetworksresponse.network ? json.listnetworksresponse.network : []; - + if(networkObjs.length > 0) { for(var i = 0; i < networkObjs.length; i++) { var networkObj = networkObjs[i]; diff --git a/ui/scripts/projects.js b/ui/scripts/projects.js index 31b68e7a338..b62dcb4c6a2 100644 --- a/ui/scripts/projects.js +++ b/ui/scripts/projects.js @@ -1026,7 +1026,7 @@ createForm: { desc: 'message.enter.token', fields: { - projectid: { label: 'label.project.id', validation: { required: true, docID: 'helpEnterTokenProjectID' }}, + projectid: { label: 'label.project.id', validation: { required: true}, docID: 'helpEnterTokenProjectID' }, token: { label: 'label.token', docID: 'helpEnterTokenToken', validation: { required: true }} } }, diff --git a/ui/scripts/system.js b/ui/scripts/system.js index bd8d3316103..761900be218 100644 --- a/ui/scripts/system.js +++ b/ui/scripts/system.js @@ -1322,6 +1322,12 @@ networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering; if (networkOfferingObjs != null && networkOfferingObjs.length > 0) { for (var i = 0; i < networkOfferingObjs.length; i++) { + + if(args.scope=="account-specific" && args.context.zones[0].securitygroupsenabled == true) { //BUG - CLOUDSTACK-1063 + var serviceObjArray = networkOfferingObjs[i].name; + if(serviceObjArray == "DefaultSharedNetworkOfferingWithSGService"){ + continue; + } //comment out the following 12 lines because of CS-16718 /* diff --git a/ui/scripts/ui-custom/instanceWizard.js b/ui/scripts/ui-custom/instanceWizard.js index d1f2507e120..67d2a69c968 100644 --- a/ui/scripts/ui-custom/instanceWizard.js +++ b/ui/scripts/ui-custom/instanceWizard.js @@ -821,6 +821,16 @@ cloudStack.dialog.notice({ message: 'message.step.4.continue' }); return false; } + + if ($activeStep.hasClass('next-use-security-groups')) { + var advSGFilter = args.advSGFilter({ + data: cloudStack.serializeForm($form) + }); + + if (!advSGFilter) { + showStep(6); + } + } } //step 6 - review (spcifiy displyname, group as well) diff --git a/utils/src/com/cloud/utils/IteratorUtil.java b/utils/src/com/cloud/utils/IteratorUtil.java index d7a85f1e6d3..0a7fd72c882 100644 --- a/utils/src/com/cloud/utils/IteratorUtil.java +++ b/utils/src/com/cloud/utils/IteratorUtil.java @@ -16,8 +16,11 @@ // under the License. package com.cloud.utils; +import java.util.ArrayList; +import java.util.Collection; import java.util.Enumeration; import java.util.Iterator; +import java.util.List; public class IteratorUtil { public static Iterable enumerationAsIterable(final Enumeration e) { @@ -51,4 +54,11 @@ public class IteratorUtil { } }; } + + public static + > List asSortedList(Collection c) { + List list = new ArrayList(c); + java.util.Collections.sort(list); + return list; + } } diff --git a/utils/src/com/cloud/utils/ReflectUtil.java b/utils/src/com/cloud/utils/ReflectUtil.java index 09447059fe6..e5a890a28e2 100755 --- a/utils/src/com/cloud/utils/ReflectUtil.java +++ b/utils/src/com/cloud/utils/ReflectUtil.java @@ -19,7 +19,10 @@ package com.cloud.utils; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; import com.cloud.utils.exception.CloudRuntimeException; @@ -87,26 +90,39 @@ public class ReflectUtil { return isAsync; } - // Returns all fields across the base class for a cmd - public static Field[] getAllFieldsForClass(Class cmdClass, - Class[] searchClasses) { - Field[] fields = cmdClass.getDeclaredFields(); + // Returns all fields until a base class for a cmd class + public static List getAllFieldsForClass(Class cmdClass, + Class baseClass) { + List fields = new ArrayList(); + Collections.addAll(fields, cmdClass.getDeclaredFields()); + Class superClass = cmdClass.getSuperclass(); + while (baseClass.isAssignableFrom(superClass)) { + Field[] superClassFields = superClass.getDeclaredFields(); + if (superClassFields != null) + Collections.addAll(fields, superClassFields); + superClass = superClass.getSuperclass(); + } + return fields; + } + + // Returns all unique fields except excludeClasses for a cmd class + public static Set getAllFieldsForClass(Class cmdClass, + Class[] excludeClasses) { + Set fields = new HashSet(); + Collections.addAll(fields, cmdClass.getDeclaredFields()); Class superClass = cmdClass.getSuperclass(); while (superClass != null && superClass != Object.class) { String superName = superClass.getName(); - for (Class baseClass: searchClasses) { - if(!baseClass.isAssignableFrom(superClass)) - continue; - if (!superName.equals(baseClass.getName())) { - Field[] superClassFields = superClass.getDeclaredFields(); - if (superClassFields != null) { - Field[] tmpFields = new Field[fields.length + superClassFields.length]; - System.arraycopy(fields, 0, tmpFields, 0, fields.length); - System.arraycopy(superClassFields, 0, tmpFields, fields.length, superClassFields.length); - fields = tmpFields; - } - } + boolean isNameEqualToSuperName = false; + for (Class baseClass: excludeClasses) + if (superName.equals(baseClass.getName())) + isNameEqualToSuperName = true; + + if (!isNameEqualToSuperName) { + Field[] superClassFields = superClass.getDeclaredFields(); + if (superClassFields != null) + Collections.addAll(fields, superClassFields); } superClass = superClass.getSuperclass(); } diff --git a/utils/src/com/cloud/utils/db/GenericDao.java b/utils/src/com/cloud/utils/db/GenericDao.java index 9864b18b17f..c0a9029bf3c 100755 --- a/utils/src/com/cloud/utils/db/GenericDao.java +++ b/utils/src/com/cloud/utils/db/GenericDao.java @@ -57,6 +57,9 @@ public interface GenericDao { // Finds one unique VO using uuid T findByUuid(String uuid); + + // Finds one unique VO using uuid including removed entities + T findByUuidIncludingRemoved(String uuid); /** * @return VO object ready to be used for update. It won't have any fields filled in. diff --git a/utils/src/com/cloud/utils/db/GenericDaoBase.java b/utils/src/com/cloud/utils/db/GenericDaoBase.java index ec2e7e0c06e..4ecf242ba22 100755 --- a/utils/src/com/cloud/utils/db/GenericDaoBase.java +++ b/utils/src/com/cloud/utils/db/GenericDaoBase.java @@ -921,6 +921,14 @@ public abstract class GenericDaoBase implements Gene return findOneBy(sc); } + @Override @DB(txn=false) + @SuppressWarnings("unchecked") + public T findByUuidIncludingRemoved(final String uuid) { + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("uuid", SearchCriteria.Op.EQ, uuid); + return findOneIncludingRemovedBy(sc); + } + @Override @DB(txn=false) public T findByIdIncludingRemoved(ID id) { return findById(id, true, null); diff --git a/utils/src/com/cloud/utils/script/Script.java b/utils/src/com/cloud/utils/script/Script.java index 1444f83f425..1e5aab45408 100755 --- a/utils/src/com/cloud/utils/script/Script.java +++ b/utils/src/com/cloud/utils/script/Script.java @@ -195,51 +195,65 @@ public class Script implements Callable { } Task task = null; - if (interpreter.drain()) { + if (interpreter != null && interpreter.drain()) { task = new Task(interpreter, ir); s_executors.execute(task); } - while (true) { - try { - if (_process.waitFor() == 0) { - _logger.debug("Execution is successful."); + while (true) { + try { + if (_process.waitFor() == 0) { + _logger.debug("Execution is successful."); + if (interpreter != null) { + return interpreter.drain() ? task.getResult() : interpreter.interpret(ir); + } else { + // null return is ok apparently + return (_process.exitValue() == 0) ? "Ok" : "Failed, exit code " + _process.exitValue(); + } + } else { + break; + } + } catch (InterruptedException e) { + if (!_isTimeOut) { + /* + * This is not timeout, we are interrupted by others, + * continue + */ + _logger.debug("We are interrupted but it's not a timeout, just continue"); + continue; + } - return interpreter.drain() ? task.getResult() : interpreter.interpret(ir); - } else { - break; - } - } catch (InterruptedException e) { - if (!_isTimeOut) { - /* This is not timeout, we are interrupted by others, continue */ - _logger.debug("We are interrupted but it's not a timeout, just continue"); - continue; - } - - TimedOutLogger log = new TimedOutLogger(_process); - Task timedoutTask = new Task(log, ir); + TimedOutLogger log = new TimedOutLogger(_process); + Task timedoutTask = new Task(log, ir); - timedoutTask.run(); - if (!_passwordCommand) { - _logger.warn("Timed out: " + buildCommandLine(command) + ". Output is: " + timedoutTask.getResult()); - } else { - _logger.warn("Timed out: " + buildCommandLine(command)); - } + timedoutTask.run(); + if (!_passwordCommand) { + _logger.warn("Timed out: " + buildCommandLine(command) + ". Output is: " + timedoutTask.getResult()); + } else { + _logger.warn("Timed out: " + buildCommandLine(command)); + } - return ERR_TIMEOUT; - } finally { - if (future != null) { - future.cancel(false); - } - Thread.interrupted(); - } - } + return ERR_TIMEOUT; + } finally { + if (future != null) { + future.cancel(false); + } + Thread.interrupted(); + } + } - _logger.debug("Exit value is " + _process.exitValue()); + _logger.debug("Exit value is " + _process.exitValue()); BufferedReader reader = new BufferedReader(new InputStreamReader(_process.getInputStream()), 128); - String error = interpreter.processError(reader); + String error; + if (interpreter != null) { + error = interpreter.processError(reader); + } + else { + error = "Non zero exit code : " + _process.exitValue(); + } + if (_logger.isDebugEnabled()) { _logger.debug(error); }