Merge branch 'master' into regions

This commit is contained in:
Kishan Kavala 2013-01-25 18:49:47 +05:30
commit c6ae19d12f
75 changed files with 2894 additions and 1261 deletions

View File

@ -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

View File

@ -47,6 +47,15 @@ public interface EntityManager {
*/
public <T> T findByUuid(Class<T> entityType, String uuid);
/**
* Finds a unique entity by uuid string
* @param <T> 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> T findByUuidIncludingRemoved(Class<T> entityType, String uuid);
/**
* Finds an entity by external id which is always String
* @param <T> entity class

View File

@ -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<HypervisorType> getSupportedHypervisorTypes(long zoneId, boolean forVirtualRouter, Long podId);
List<? extends Swift> listSwifts(ListSwiftsCmd cmd);
Pair<List<? extends Swift>, Integer> listSwifts(ListSwiftsCmd cmd);
List<? extends S3> listS3s(ListS3sCmd cmd);

View File

@ -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<? extends DataCenter> listDataCenters(ListZonesByCmd cmd);
/**
* returns the a map of the names/values in the configuraton table
*

View File

@ -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() {

View File

@ -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;

View File

@ -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<? extends Swift> result = _resourceService.listSwifts(this);
Pair<List<? extends Swift>, Integer> result = _resourceService.listSwifts(this);
ListResponse<SwiftResponse> response = new ListResponse<SwiftResponse>();
List<SwiftResponse> swiftResponses = new ArrayList<SwiftResponse>();
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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<String> 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;
}

View File

@ -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<? extends DataCenter> dataCenters = _mgr.listDataCenters(this);
ListResponse<ZoneResponse> response = new ListResponse<ZoneResponse>();
List<ZoneResponse> zoneResponses = new ArrayList<ZoneResponse>();
for (DataCenter dataCenter : dataCenters) {
ZoneResponse zoneResponse = _responseGenerator.createZoneResponse(dataCenter, showCapacities);
zoneResponse.setObjectName("zone");
zoneResponses.add(zoneResponse);
}
response.setResponses(zoneResponses);
ListResponse<ZoneResponse> response = _queryService.listDataCenters(this);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}

View File

@ -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;
}

View File

@ -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<DiskOfferingResponse> searchForDiskOfferings(ListDiskOfferingsCmd cmd);
public ListResponse<ServiceOfferingResponse> searchForServiceOfferings(ListServiceOfferingsCmd cmd);
public ListResponse<ZoneResponse> listDataCenters(ListZonesByCmd cmd);
}

View File

@ -83,6 +83,11 @@
<para>Make sure the new host has the same network configuration (guest, private, and
public network) as other hosts in the cluster.</para>
</listitem>
<listitem>
<para>If you are using OpenVswitch bridges edit the file agent.properties on the KVM host
and set the parameter <emphasis role="italic">network.bridge.type</emphasis> to
<emphasis role="italic">openvswitch</emphasis> before adding the host to &PRODUCT;</para>
</listitem>
</itemizedlist>
</section>
<!-- <section>

View File

@ -0,0 +1,116 @@
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
]>
<!-- 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.
-->
<section id="hypervisor-host-install-network-openvswitch">
<title>Configure the network using OpenVswitch</title>
<warning><para>This is a very important section, please make sure you read this thoroughly.</para></warning>
<para>In order to forward traffic to your instances you will need at least two bridges: <emphasis>public</emphasis> and <emphasis>private</emphasis>.</para>
<para>By default these bridges are called <emphasis>cloudbr0</emphasis> and <emphasis>cloudbr1</emphasis>, but you do have to make sure they are available on each hypervisor.</para>
<para>The most important factor is that you keep the configuration consistent on all your hypervisors.</para>
<section id="hypervisor-host-install-network-openvswitch-prepare">
<title>Preparing</title>
<para>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.</para>
<para>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/</para>
</section>
<section id="hypervisor-host-install-network-openvswitch-vlan">
<title>Network example</title>
<para>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.</para>
<para>We assume that the hypervisor has one NIC (eth0) with three tagged VLAN's:</para>
<orderedlist>
<listitem><para>VLAN 100 for management of the hypervisor</para></listitem>
<listitem><para>VLAN 200 for public network of the instances (cloudbr0)</para></listitem>
<listitem><para>VLAN 300 for private network of the instances (cloudbr1)</para></listitem>
</orderedlist>
<para>On VLAN 100 we give the Hypervisor the IP-Address 192.168.42.11/24 with the gateway 192.168.42.1</para>
<note><para>The Hypervisor and Management server don't have to be in the same subnet!</para></note>
</section>
<section id="hypervisor-host-install-network-openvswitch-configure">
<title>Configuring the network bridges</title>
<para>It depends on the distribution you are using how to configure these, below you'll find
examples for RHEL/CentOS.</para>
<note><para>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.</para></note>
<section id="hypervisor-host-install-network-openvswitch-configure-ovs">
<title>Configure OpenVswitch</title>
<para>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.</para>
<para>First we create a main bridge connected to the eth0 interface. Next we create three fake bridges, each connected to a specific vlan tag.</para>
<programlisting><![CDATA[# ovs-vsctl add-br cloudbr
# ovs-vsctl add-port cloudbr eth0
# ovs-vsctl set port cloudbr trunks=100,200,300
# ovs-vsctl add-br mgmt0 cloudbr 100
# ovs-vsctl add-br cloudbr0 cloudbr 200
# ovs-vsctl add-br cloudbr1 cloudbr 300]]></programlisting>
</section>
<section id="hypervisor-host-install-network-openvswitch-configure-rhel">
<title>Configure in RHEL or CentOS</title>
<para>The required packages were installed when openvswitch and libvirt were installed,
we can proceed to configuring the network.</para>
<para>First we configure eth0</para>
<programlisting language="Bash">vi /etc/sysconfig/network-scripts/ifcfg-eth0</programlisting>
<para>Make sure it looks similair to:</para>
<programlisting><![CDATA[DEVICE=eth0
HWADDR=00:04:xx:xx:xx:xx
ONBOOT=yes
HOTPLUG=no
BOOTPROTO=none
TYPE=Ethernet]]></programlisting>
<para>We have to configure the base bridge with the trunk.</para>
<programlisting language="Bash">vi /etc/sysconfig/network-scripts/ifcfg-cloudbr</programlisting>
<programlisting><![CDATA[DEVICE=cloudbr
ONBOOT=yes
HOTPLUG=no
BOOTPROTO=none
DEVICETYPE=ovs
TYPE=OVSBridge]]></programlisting>
<para>We now have to configure the three VLAN bridges:</para>
<programlisting language="Bash">vi /etc/sysconfig/network-scripts/ifcfg-mgmt0</programlisting>
<programlisting><![CDATA[DEVICE=mgmt0
ONBOOT=yes
HOTPLUG=no
BOOTPROTO=static
DEVICETYPE=ovs
TYPE=OVSBridge
IPADDR=192.168.42.11
GATEWAY=192.168.42.1
NETMASK=255.255.255.0]]></programlisting>
<programlisting language="Bash">vi /etc/sysconfig/network-scripts/ifcfg-cloudbr0</programlisting>
<programlisting><![CDATA[DEVICE=cloudbr0
ONBOOT=yes
HOTPLUG=no
BOOTPROTO=none
DEVICETYPE=ovs
TYPE=OVSBridge]]></programlisting>
<programlisting language="Bash">vi /etc/sysconfig/network-scripts/ifcfg-cloudbr1</programlisting>
<programlisting><![CDATA[DEVICE=cloudbr1
ONBOOT=yes
HOTPLUG=no
BOOTPROTO=none
TYPE=OVSBridge
DEVICETYPE=ovs]]></programlisting>
<para>With this configuration you should be able to restart the network, although a reboot is recommended to see if everything works properly.</para>
<warning><para>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!</para></warning>
</section>
</section>
</section>

View File

@ -25,6 +25,7 @@
<section id="hypervisor-host-install-network">
<title>Configure the network bridges</title>
<warning><para>This is a very important section, please make sure you read this thoroughly.</para></warning>
<note><para>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</para></note>
<para>In order to forward traffic to your instances you will need at least two bridges: <emphasis>public</emphasis> and <emphasis>private</emphasis>.</para>
<para>By default these bridges are called <emphasis>cloudbr0</emphasis> and <emphasis>cloudbr1</emphasis>, but you do have to make sure they are available on each hypervisor.</para>
<para>The most important factor is that you keep the configuration consistent on all your hypervisors.</para>
@ -146,4 +147,4 @@ iface cloudbr1 inet manual
<warning><para>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!</para></warning>
</section>
</section>
</section>
</section>

View File

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
]>
@ -31,6 +31,7 @@
<xi:include href="hypervisor-host-install-libvirt.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="hypervisor-host-install-security-policies.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="hypervisor-host-install-network.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="hypervisor-host-install-network-openvswitch.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="hypervisor-host-install-firewall.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="hypervisor-host-install-finish.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
</section>

View File

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
]>
@ -35,6 +35,11 @@
<listitem><para>libvirt: 0.9.4 or higher</para></listitem>
<listitem><para>Qemu/KVM: 1.0 or higher</para></listitem>
</itemizedlist>
<para>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</para>
<itemizedlist>
<listitem><para>libvirt: 0.9.11 or higher</para></listitem>
<listitem><para>openvswitch: 1.7.1 or higher</para></listitem>
</itemizedlist>
<para>In addition, the following hardware requirements apply:</para>
<itemizedlist>
<listitem><para>Within a single cluster, the hosts must be of the same distribution version.</para></listitem>

View File

@ -1,25 +1,22 @@
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
]>
<!-- 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.
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.
-->
<chapter id="offerings">
@ -28,4 +25,5 @@
are discussed in the section on setting up networking for users.</para>
<xi:include href="compute-disk-service-offerings.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="system-service-offerings.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="sys-offering-sysvm.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
</chapter>

View File

@ -24,6 +24,10 @@
<title>Features of the Nicira NVP Plugin</title>
<para>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.</para>
<para>The plugin has been tested with Nicira NVP versions 2.1.0, 2.2.0 and 2.2.1</para>
<note><para>In CloudStack 4.0.0-incubating only the XenServer hypervisor is supported for use in combination with Nicira NVP</para></note>
<note><para>In CloudStack 4.0.0-incubating the UI components for this plugin are not complete, configuration is done by sending commands to the API</para></note>
<note><para>In CloudStack 4.0.0-incubating only the XenServer hypervisor is supported for use in
combination with Nicira NVP.</para>
<para>In CloudStack 4.1.0-incubating both KVM and XenServer hypervisors are
supported.</para></note>
<note><para>In CloudStack 4.0.0-incubating the UI components for this plugin are not complete,
configuration is done by sending commands to the API.</para></note>
</section>

View File

@ -24,7 +24,9 @@
<title>Prerequisites</title>
<para>Before enabling the Nicira NVP plugin the NVP Controller needs to be configured. Please review the NVP User Guide on how to do that. </para>
<para>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.</para>
<note><para>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.</para></note>
<note><para>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.</para></note>
<para>Make sure you have the following information ready:</para>
<itemizedlist>
<listitem><para>The IP address of the NVP Controller</para></listitem>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
<!ENTITY % xinclude SYSTEM "http://www.docbook.org/xml/4.4/xinclude.mod">
%xinclude;
]>
<!-- 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.
-->
<section id="plugin-niciranvp-ui">
<title>Configuring the Nicira NVP plugin from the UI</title>
<para>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. <!-- TODO add screenshot --></para>
</section>

View File

@ -24,6 +24,7 @@
<title>Using the Nicira NVP Plugin</title>
<xi:include href="plugin-niciranvp-preparations.xml" xmlns:xi="http://www.w3.org/2001/XInclude"></xi:include>
<xi:include href="plugin-niciranvp-ui.xml" xmlns:xi="http://www.w3.org/2001/XInclude"></xi:include>
<xi:include href="plugin-niciranvp-provider.xml" xmlns:xi="http://www.w3.org/2001/XInclude"></xi:include>
<xi:include href="plugin-niciranvp-devicemanagement.xml" xmlns:xi="http://www.w3.org/2001/XInclude"></xi:include>
</chapter>

View File

@ -0,0 +1,75 @@
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
]>
<!-- 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.
-->
<section id="sys-offering-sysvm">
<title>Changing the Default System Offering for System VMs</title>
<para>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.</para>
<orderedlist>
<listitem>
<para>Create a new system offering.</para>
<para>For more information, see <phrase condition="install"><xref
linkend="creating-system-service-offerings"/></phrase>
<phrase condition="admin">Creating a New System Service Offering</phrase>. </para>
</listitem>
<listitem>
<para>Back up the database:</para>
<programlisting>mysqldump -u root -p cloud | bzip2 > cloud_backup.sql.bz2</programlisting>
</listitem>
<listitem>
<para>Open an MySQL prompt:</para>
<programlisting>mysql -u cloud -p cloud</programlisting>
</listitem>
<listitem>
<para>Run the following queries on the cloud database.</para>
<orderedlist numeration="loweralpha">
<listitem>
<para>In the disk_offering table, identify the original default offering and the new
offering you want to use by default. </para>
<para>Take a note of the ID of the new offering.</para>
<programlisting>select id,name,unique_name,type from disk_offering;</programlisting>
</listitem>
<listitem>
<para>For the original default offering, set the value of unique_name to NULL.</para>
<programlisting># update disk_offering set unique_name = NULL where id = 10;</programlisting>
<para>Ensure that you use the correct value for the ID.</para>
</listitem>
<listitem>
<para>For the new offering that you want to use by default, set the value of unique_name
as follows:</para>
<para>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:</para>
<programlisting>update disk_offering set unique_name = 'Cloud.com-ConsoleProxy' where id = 16;</programlisting>
</listitem>
</orderedlist>
</listitem>
<listitem>
<para>Restart &PRODUCT; Management Server. Restarting is required because the default
offerings are loaded into the memory at startup.</para>
<programlisting>service cloud-management restart</programlisting>
</listitem>
<listitem>
<para>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. </para>
</listitem>
</orderedlist>
</section>

View File

@ -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">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-plugin-api-discovery</artifactId>
<name>Apache CloudStack Plugin - API Discovery</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-utils</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-plugin-api-discovery</artifactId>
<name>Apache CloudStack Plugin - API Discovery</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-utils</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<testResources>
<testResource>
<directory>test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx1024m</argLine>
<excludes>
<exclude>org/apache/cloudstack/discovery/integration/*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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;
}

View File

@ -58,18 +58,16 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
if (s_apiNameDiscoveryResponseMap == null) {
long startTime = System.nanoTime();
s_apiNameDiscoveryResponseMap = new HashMap<String, ApiDiscoveryResponse>();
cacheResponseMap();
//TODO: Fix and use PluggableService to get the classes
Set<Class<?>> 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<Class<?>> 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<Class<?>> cmdClasses) {
Map<String, List<String>> responseApiNameListMap = new HashMap<String, List<String>>();
for (Class<?> cmdClass : cmdClasses) {
@ -109,7 +107,7 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
}
}
Field[] fields = ReflectUtil.getAllFieldsForClass(cmdClass,
Set<Field> fields = ReflectUtil.getAllFieldsForClass(cmdClass,
new Class<?>[]{BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class});
boolean isAsync = ReflectUtil.isCmdClassAsync(cmdClass,

View File

@ -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<Class<?>> cmdClasses = new HashSet<Class<?>>();
cmdClasses.add(ListApisCmd.class);
_discoveryService.cacheResponseMap(cmdClasses);
_discoveryService.s_apiAccessCheckers = (Adapters<APIChecker>) 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<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>) _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<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>) _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());
}
}
}

View File

@ -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);

View File

@ -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<String> 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++;

View File

@ -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("<model type='" + _model + "'/>\n");
}
if (_virtualPortType != null) {
netBuilder.append("<virtualport type='" + _virtualPortType + "'>\n");
if (_virtualPortInterfaceId != null) {
netBuilder.append("<parameters interfaceid='" + _virtualPortInterfaceId + "'/>\n");
}
netBuilder.append("</virtualport>\n");
}
if (_vlanTag > 0 && _vlanTag < 4095) {
netBuilder.append("<vlan trunk='no'>\n<tag id='" + _vlanTag + "'/>\n</vlan>");
}
netBuilder.append("</interface>\n");
return netBuilder.toString();
}

View File

@ -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<String, Object> 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;
}
}
}

View File

@ -38,6 +38,10 @@ public class KVMStoragePoolManager {
private final Map<String, StorageAdaptor> _storageMapper = new HashMap<String, StorageAdaptor>();
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

View File

@ -105,6 +105,7 @@
<exclude>com/cloud/vm/dao/*</exclude>
<exclude>com/cloud/vpc/*</exclude>
<exclude>com/cloud/api/ListPerfTest.java</exclude>
<exclude>com/cloud/network/vpn/RemoteAccessVpnTest.java</exclude>
</excludes>
</configuration>
</plugin>

View File

@ -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);
}
}

View File

@ -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<Field> 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;
}

View File

@ -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<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(dataCenter.getId(), null, null);
Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
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<SummedCapacity> 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<CapacityResponse>(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<CapacityResponse> getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) {
public static List<CapacityResponse> getDataCenterCapacityResponse(Long zoneId){
List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(zoneId, null, null);
Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
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<SummedCapacity> 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<CapacityResponse>(capacityResponses);
}
private static List<CapacityResponse> getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) {
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
capacities.add(ApiDBUtils.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId));
if (clusterId == null && podId == null) {

View File

@ -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);
}

View File

@ -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<Field> 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<Argument> setRequestFields(Field[] fields) {
private static ArrayList<Argument> setRequestFields(Set<Field> fields) {
ArrayList<Argument> arguments = new ArrayList<Argument>();
ArrayList<Argument> requiredArguments = new ArrayList<Argument>();
ArrayList<Argument> optionalArguments = new ArrayList<Argument>();
Set<Argument> requiredArguments = new HashSet<Argument>();
Set<Argument> optionalArguments = new HashSet<Argument>();
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;
}

View File

@ -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<ZoneResponse> listDataCenters(ListZonesByCmd cmd) {
Pair<List<DataCenterJoinVO>, Integer> result = listDataCentersInternal(cmd);
ListResponse<ZoneResponse> response = new ListResponse<ZoneResponse>();
List<ZoneResponse> dcResponses = ViewResponseHelper.createDataCenterResponse(cmd.getShowCapacities(), result.first().toArray(new DataCenterJoinVO[result.first().size()]));
response.setResponses(dcResponses, result.second());
return response;
}
private Pair<List<DataCenterJoinVO>, 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<DataCenterJoinVO> sc = _dcJoinDao.createSearchCriteria();
if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
} else {
if (keyword != null) {
SearchCriteria<DataCenterJoinVO> 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<Long> domainIds = new ArrayList<Long>();
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<DataCenterJoinVO> 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<Long> domainIds = new ArrayList<Long>();
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<DomainVO> 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<DataCenterJoinVO> 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<Long> dcIds = new HashSet<Long>(); //data centers with at least one VM running
List<DomainRouterVO> routers = _routerDao.listBy(account.getId());
for (DomainRouterVO router : routers){
dcIds.add(router.getDataCenterIdToDeployIn());
}
if ( dcIds.size() == 0) {
return new Pair<List<DataCenterJoinVO>, Integer>(new ArrayList<DataCenterJoinVO>(), 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;
}
}

View File

@ -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<ZoneResponse> createDataCenterResponse(Boolean showCapacities, DataCenterJoinVO... dcs) {
List<ZoneResponse> respList = new ArrayList<ZoneResponse>();
for (DataCenterJoinVO vt : dcs){
respList.add(ApiDBUtils.newDataCenterResponse(vt, showCapacities));
}
return respList;
}
}

View File

@ -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<DataCenterJoinVO, Long> {
ZoneResponse newDataCenterResponse(DataCenterJoinVO dof, Boolean showCapacities);
DataCenterJoinVO newDataCenterView(DataCenter dof);
}

View File

@ -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<DataCenterJoinVO, Long> implements DataCenterJoinDao {
public static final Logger s_logger = Logger.getLogger(DataCenterJoinDaoImpl.class);
private SearchBuilder<DataCenterJoinVO> 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<DataCenterJoinVO> sc = dofIdSearch.create();
sc.setParameters("id", dataCenter.getId());
List<DataCenterJoinVO> 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);
}
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -51,6 +51,13 @@ public class EntityManagerImpl implements EntityManager, Manager {
return dao.findByUuid(uuid);
}
@Override
public <T> T findByUuidIncludingRemoved(Class<T> entityType, String uuid) {
// Finds and returns a unique VO using uuid, null if entity not found in db
GenericDao<? extends T, String> dao = (GenericDao<? extends T, String>)GenericDaoBase.getDao(entityType);
return dao.findByUuidIncludingRemoved(uuid);
}
@Override
public <T> T findByXId(Class<T> entityType, String xid) {
return null;

View File

@ -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<? extends PhysicalNetwork> 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();
}

View File

@ -560,8 +560,9 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
}
@Override
public List<SwiftVO> listSwifts(ListSwiftsCmd cmd) {
return _swiftMgr.listSwifts(cmd);
public Pair<List<? extends Swift>, Integer> listSwifts(ListSwiftsCmd cmd) {
Pair<List<SwiftVO>, Integer> swifts = _swiftMgr.listSwifts(cmd);
return new Pair<List<? extends Swift>, Integer>(swifts.first(), swifts.second());
}
@Override

View File

@ -416,119 +416,7 @@ public class ManagementServerImpl implements ManagementServer {
return PasswordGenerator.generateRandomPassword(6);
}
@Override
public List<DataCenterVO> listDataCenters(ListZonesByCmd cmd) {
Account account = UserContext.current().getCaller();
List<DataCenterVO> 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<DataCenterVO>();
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<DataCenterVO>();
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<DomainVO> allChildDomains = _domainDao.findAllChildren(domainRecord.getPath(), domainRecord.getId());
List<Long> allChildDomainIds = new ArrayList<Long>();
// 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<DataCenterVO> 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<DomainRouterVO> routers = _routerDao.listBy(account.getId());
for (Iterator<DataCenterVO> 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<DataCenterVO> singleZone = new ArrayList<DataCenterVO>();
for (DataCenterVO zone : dcs) {
if (zone.getId() == id) {
singleZone.add(zone);
}
}
return singleZone;
}
return dcs;
}
@Override
public HostVO getHostBy(long hostId) {

View File

@ -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<SwiftVO> listSwifts(ListSwiftsCmd cmd);
Pair<List<SwiftVO>, Integer> listSwifts(ListSwiftsCmd cmd);
VMTemplateSwiftVO findByTmpltId(Long tmpltId);
}

View File

@ -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<VMTemplateHostVO> tmpltHosts = _vmTmpltHostDao.listByOnlyTemplateId(tmpltId);
if (tmpltHosts != null) {
Collections.shuffle(tmpltHosts);
@ -260,13 +261,13 @@ public class SwiftManagerImpl implements SwiftManager {
}
@Override
public List<SwiftVO> listSwifts(ListSwiftsCmd cmd) {
public Pair<List<SwiftVO>, Integer> listSwifts(ListSwiftsCmd cmd) {
Filter searchFilter = new Filter(SwiftVO.class, "id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchCriteria<SwiftVO> 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);
}

View File

@ -202,7 +202,7 @@ public class MockResourceManagerImpl implements ResourceManager, Manager {
* @see com.cloud.resource.ResourceService#listSwifts(com.cloud.api.commands.ListSwiftsCmd)
*/
@Override
public List<? extends Swift> listSwifts(ListSwiftsCmd cmd) {
public Pair<List<? extends Swift>, Integer> listSwifts(ListSwiftsCmd cmd) {
// TODO Auto-generated method stub
return null;
}

File diff suppressed because it is too large Load Diff

View File

@ -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');

View File

@ -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:

View File

@ -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',

View File

@ -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",

View File

@ -12,7 +12,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-devcloud-kvm</artifactId>
<name>Apache CloudStack Developer Tools</name>
<name>Apache CloudStack DevCloud-KVM</name>
<packaging>pom</packaging>
<parent>
<groupId>org.apache.cloudstack</groupId>
@ -27,6 +27,14 @@
<version>5.1.21</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-developer</artifactId>
<version>${project.version}</version>
<type>pom</type>
<optional>true</optional>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>

View File

@ -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;

View File

@ -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"
}
]
}

View File

@ -12,7 +12,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-devcloud</artifactId>
<name>Apache CloudStack Developer Tools</name>
<name>Apache CloudStack DevCloud</name>
<packaging>pom</packaging>
<parent>
<groupId>org.apache.cloudstack</groupId>
@ -27,6 +27,14 @@
<version>5.1.21</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-developer</artifactId>
<version>${project.version}</version>
<type>pom</type>
<optional>true</optional>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>

View File

@ -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;
}

View File

@ -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',

View File

@ -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];

View File

@ -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 }}
}
},

View File

@ -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
/*

View File

@ -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)

View File

@ -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 <T> Iterable<T> enumerationAsIterable(final Enumeration<T> e) {
@ -51,4 +54,11 @@ public class IteratorUtil {
}
};
}
public static
<T extends Comparable<? super T>> List<T> asSortedList(Collection<T> c) {
List<T> list = new ArrayList<T>(c);
java.util.Collections.sort(list);
return list;
}
}

View File

@ -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<Field> getAllFieldsForClass(Class<?> cmdClass,
Class<?> baseClass) {
List<Field> fields = new ArrayList<Field>();
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<Field> getAllFieldsForClass(Class<?> cmdClass,
Class<?>[] excludeClasses) {
Set<Field> fields = new HashSet<Field>();
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();
}

View File

@ -57,6 +57,9 @@ public interface GenericDao<T, ID extends Serializable> {
// 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.

View File

@ -921,6 +921,14 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
return findOneBy(sc);
}
@Override @DB(txn=false)
@SuppressWarnings("unchecked")
public T findByUuidIncludingRemoved(final String uuid) {
SearchCriteria<T> 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);

View File

@ -195,51 +195,65 @@ public class Script implements Callable<String> {
}
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);
}