mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge branch 'master' into api_limit
Conflicts: server/src/com/cloud/api/ApiServer.java Signed-off-by: Min Chen <min.chen@citrix.com>
This commit is contained in:
commit
57e67c57d7
@ -20,6 +20,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
|
||||
|
||||
import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
|
||||
@ -193,6 +194,8 @@ public interface AccountService {
|
||||
|
||||
UserAccount getUserByApiKey(String apiKey);
|
||||
|
||||
RoleType getRoleType(Account account);
|
||||
|
||||
void checkAccess(Account account, Domain domain) throws PermissionDeniedException;
|
||||
|
||||
void checkAccess(Account account, AccessType accessType, boolean sameOwner, ControlledEntity... entities) throws PermissionDeniedException;
|
||||
|
||||
@ -16,17 +16,13 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.acl;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.User;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import com.cloud.utils.component.Adapter;
|
||||
|
||||
/**
|
||||
* APIAccessChecker checks the ownership and access control to API requests
|
||||
*/
|
||||
public interface APIAccessChecker extends Adapter {
|
||||
// Interface for checking access to an API for an user
|
||||
boolean canAccessAPI(User user, String apiCommandName) throws PermissionDeniedException;
|
||||
// APIChecker checks the ownership and access control to API requests
|
||||
public interface APIChecker extends Adapter {
|
||||
// Interface for checking access for a role using apiname
|
||||
boolean checkAccess(RoleType roleType, String apiCommandName);
|
||||
// Interface for checking existence of an api by name
|
||||
boolean checkExistence(String apiCommandName);
|
||||
}
|
||||
37
api/src/org/apache/cloudstack/acl/RoleType.java
Normal file
37
api/src/org/apache/cloudstack/acl/RoleType.java
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.acl;
|
||||
|
||||
// Enum for default roles in CloudStack
|
||||
public enum RoleType {
|
||||
|
||||
Admin(1),
|
||||
ResourceAdmin(2),
|
||||
DomainAdmin(4),
|
||||
User(8),
|
||||
Unknown(0);
|
||||
|
||||
private int mask;
|
||||
|
||||
private RoleType(int mask) {
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
@ -158,6 +158,7 @@ public class ApiConstants {
|
||||
public static final String RECEIVED_BYTES = "receivedbytes";
|
||||
public static final String REQUIRES_HVM = "requireshvm";
|
||||
public static final String RESOURCE_TYPE = "resourcetype";
|
||||
public static final String RESPONSE = "response";
|
||||
public static final String QUERY_FILTER = "queryfilter";
|
||||
public static final String SCHEDULE = "schedule";
|
||||
public static final String SCOPE = "scope";
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
# 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.
|
||||
|
||||
# bitmap of permissions at the end of each classname, 1 = ADMIN, 2 =
|
||||
# RESOURCE_DOMAIN_ADMIN, 4 = DOMAIN_ADMIN, 8 = USER
|
||||
# Please standardize naming conventions to camel-case (even for acronyms).
|
||||
|
||||
# CloudStack API Discovery service command
|
||||
listApis=15
|
||||
@ -53,7 +53,7 @@ under the License.
|
||||
<dao name="Configuration configuration server" class="com.cloud.configuration.dao.ConfigurationDaoImpl">
|
||||
<param name="premium">true</param>
|
||||
</dao>
|
||||
<adapters key="org.apache.cloudstack.acl.APIAccessChecker">
|
||||
<adapters key="org.apache.cloudstack.acl.APIChecker">
|
||||
<adapter name="StaticRoleBasedAPIAccessChecker" class="org.apache.cloudstack.acl.StaticRoleBasedAPIAccessChecker"/>
|
||||
</adapters>
|
||||
<adapters key="com.cloud.agent.manager.allocator.HostAllocator">
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
<orderedlist>
|
||||
<listitem><para>Log in to the &PRODUCT; UI as a user or admin.</para></listitem>
|
||||
<listitem><para>Click Instances, then click the name of a running VM.</para></listitem>
|
||||
<listitem><para>Click the View Console button <inlinegraphic format="PNG" fileref="images/icon.png"/>.</para></listitem>
|
||||
<listitem><para>Click the View Console button <inlinegraphic format="PNG" fileref="images/view-console-button.png"/>.</para></listitem>
|
||||
</orderedlist>
|
||||
<para>To access a VM directly over the network:</para>
|
||||
<orderedlist>
|
||||
|
||||
284
docs/en-US/autoscale.xml
Normal file
284
docs/en-US/autoscale.xml
Normal file
@ -0,0 +1,284 @@
|
||||
<?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="autoscale">
|
||||
<title>Configuring AutoScale</title>
|
||||
<para>AutoScaling allows you to scale your back-end services or application VMs up or down
|
||||
seamlessly and automatically according to the conditions you define. With AutoScaling enabled,
|
||||
you can ensure that the number of VMs you are using seamlessly scale up when demand increases,
|
||||
and automatically decreases when demand subsides. Thus it helps you save compute costs by
|
||||
terminating underused VMs automatically and launching new VMs when you need them, without the
|
||||
need for manual intervention.</para>
|
||||
<para>NetScaler AutoScaling is designed to seamlessly launch or terminate VMs based on
|
||||
user-defined conditions. Conditions for triggering a scaleup or scaledown action can vary from a
|
||||
simple use case like monitoring the CPU usage of a server to a complex use case of monitoring a
|
||||
combination of server's responsiveness and its CPU usage. For example, you can configure
|
||||
AutoScaling to launch an additional VM whenever CPU usage exceeds 80 percent for 15 minutes, or
|
||||
to remove a VM whenever CPU usage is less than 20 percent for 30 minutes.</para>
|
||||
<para>&PRODUCT; uses the NetScaler load balancer to monitor all aspects of a system's health and
|
||||
work in unison with &PRODUCT; to initiate scale-up or scale-down actions. The supported
|
||||
NetScaler version is 10.0.</para>
|
||||
<formalpara>
|
||||
<title>Prerequisites</title>
|
||||
<para>Before you configure an AutoScale rule, consider the following:</para>
|
||||
</formalpara>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>Ensure that the necessary template is prepared before configuring AutoScale. When a VM
|
||||
is deployed by using a template and when it comes up, the application should be up and
|
||||
running.</para>
|
||||
<note>
|
||||
<para>If the application is not running, the NetScaler device considers the VM as
|
||||
ineffective and continues provisioning the VMs unconditionally until the resource limit is
|
||||
exhausted.</para>
|
||||
</note>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Deploy the templates you prepared. Ensure that the applications come up on the first
|
||||
boot and is ready to take the traffic. Observe the time requires to deploy the template.
|
||||
Consider this time when you specify the quiet time while configuring AutoScale.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>The AutoScale feature supports the SNMP counters that can be used to define conditions
|
||||
for taking scale up or scale down actions. To monitor the SNMP-based counter, ensure that
|
||||
the SNMP agent is installed in the template used for creating the AutoScale VMs, and the
|
||||
SNMP operations work with the configured SNMP community and port by using standard SNMP
|
||||
managers. For example, see <xref linkend="configure-snmp-rhel"/> to configure SNMP on a RHEL
|
||||
machine.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Ensure that the endpointe.url parameter present in the Global Settings is set to the
|
||||
Management Server API URL. For example, http://10.102.102.22:8080/client/api. In a
|
||||
multi-node Management Server deployment, use the virtual IP address configured in the load
|
||||
balancer for the management server’s cluster. Additionally, ensure that the NetScaler device
|
||||
has access to this IP address to provide AutoScale support.</para>
|
||||
<para>If you update the endpointe.url, disable the AutoScale functionality of the load
|
||||
balancer rules in the system, then enable them back to reflect the changes. For more
|
||||
information see <xref linkend="update-autoscale"/></para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>If the API Key and Secret Key are regenerated for an AutoScale user, ensure that the
|
||||
AutoScale functionality of the load balancers that the user participates in are disabled and
|
||||
then enabled to reflect the configuration changes in the NetScaler.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>In an advanced Zone, ensure that at least one VM should be present before configuring a
|
||||
load balancer rule with AutoScale. Having one VM in the network ensures that the network is
|
||||
in implemented state for configuring AutoScale.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<formalpara>
|
||||
<title>Configuration</title>
|
||||
<para>Specify the following:</para>
|
||||
</formalpara>
|
||||
<mediaobject>
|
||||
<imageobject>
|
||||
<imagedata fileref="./images/autoscale-config.png"/>
|
||||
</imageobject>
|
||||
<textobject>
|
||||
<phrase>autoscaleateconfig.png: Configuring AutoScale</phrase>
|
||||
</textobject>
|
||||
</mediaobject>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Template</emphasis>: A template consists of a base OS image and
|
||||
application. A template is used to provision the new instance of an application on a scaleup
|
||||
action. When a VM is deployed from a template, the VM can start taking the traffic from the
|
||||
load balancer without any admin intervention. For example, if the VM is deployed for a Web
|
||||
service, it should have the Web server running, the database connected, and so on.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Compute offering</emphasis>: A predefined set of virtual hardware
|
||||
attributes, including CPU speed, number of CPUs, and RAM size, that the user can select when
|
||||
creating a new virtual machine instance. Choose one of the compute offerings to be used
|
||||
while provisioning a VM instance as part of scaleup action.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Min Instance</emphasis>: The minimum number of active VM instances
|
||||
that is assigned to a load balancing rule. The active VM instances are the application
|
||||
instances that are up and serving the traffic, and are being load balanced. This parameter
|
||||
ensures that a load balancing rule has at least the configured number of active VM instances
|
||||
are available to serve the traffic.</para>
|
||||
<note>
|
||||
<para>If an application, such as SAP, running on a VM instance is down for some reason, the
|
||||
VM is then not counted as part of Min Instance parameter, and the AutoScale feature
|
||||
initiates a scaleup action if the number of active VM instances is below the configured
|
||||
value. Similarly, when an application instance comes up from its earlier down state, this
|
||||
application instance is counted as part of the active instance count and the AutoScale
|
||||
process initiates a scaledown action when the active instance count breaches the Max
|
||||
instance value.</para>
|
||||
</note>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Max Instance</emphasis>: Maximum number of active VM instances
|
||||
that <emphasis role="bold">should be assigned to </emphasis>a load balancing rule. This
|
||||
parameter defines the upper limit of active VM instances that can be assigned to a load
|
||||
balancing rule.</para>
|
||||
<para>Specifying a large value for the maximum instance parameter might result in provisioning
|
||||
large number of VM instances, which in turn leads to a single load balancing rule exhausting
|
||||
the VM instances limit specified at the account or domain level.</para>
|
||||
<note>
|
||||
<para>If an application, such as SAP, running on a VM instance is down for some reason, the
|
||||
VM is not counted as part of Max Instance parameter. So there may be scenarios where the
|
||||
number of VMs provisioned for a scaleup action might be more than the configured Max
|
||||
Instance value. Once the application instances in the VMs are up from an earlier down
|
||||
state, the AutoScale feature starts aligning to the configured Max Instance value.</para>
|
||||
</note>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<para>Specify the following scale-up and scale-down policies:</para>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Duration</emphasis>: The duration, in seconds, for which the
|
||||
conditions you specify must be true to trigger a scaleup action. The conditions defined
|
||||
should hold true for the entire duration you specify for an AutoScale action to be invoked.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Counter</emphasis>: The performance counters expose the state of
|
||||
the monitored instances. By default, &PRODUCT; offers four performance counters: Three SNMP
|
||||
counters and one NetScaler counter. The SNMP counters are Linux User CPU, Linux System CPU,
|
||||
and Linux CPU Idle. The NetScaler counter is ResponseTime. The root administrator can add
|
||||
additional counters into &PRODUCT; by using the &PRODUCT; API. </para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Operator</emphasis>: The following five relational operators are
|
||||
supported in AutoScale feature: Greater than, Less than, Less than or equal to, Greater than
|
||||
or equal to, and Equal to.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Threshold</emphasis>: Threshold value to be used for the counter.
|
||||
Once the counter defined above breaches the threshold value, the AutoScale feature initiates
|
||||
a scaleup or scaledown action.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Add</emphasis>: Click Add to add the condition.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<para>Additionally, if you want to configure the advanced settings, click Show advanced settings,
|
||||
and specify the following:</para>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Polling interval</emphasis>: Frequency in which the conditions,
|
||||
combination of counter, operator and threshold, are to be evaluated before taking a scale up
|
||||
or down action. The default polling interval is 30 seconds.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Quiet Time</emphasis>: This is the cool down period after an
|
||||
AutoScale action is initiated. The time includes the time taken to complete provisioning a
|
||||
VM instance from its template and the time taken by an application to be ready to serve
|
||||
traffic. This quiet time allows the fleet to come up to a stable state before any action can
|
||||
take place. The default is 300 seconds.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Destroy VM Grace Period</emphasis>: The duration in seconds, after
|
||||
a scaledown action is initiated, to wait before the VM is destroyed as part of scaledown
|
||||
action. This is to ensure graceful close of any pending sessions or transactions being
|
||||
served by the VM marked for destroy. The default is 120 seconds.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Security Groups</emphasis>: Security groups provide a way to
|
||||
isolate traffic to the VM instances. A security group is a group of VMs that filter their
|
||||
incoming and outgoing traffic according to a set of rules, called ingress and egress rules.
|
||||
These rules filter network traffic according to the IP address that is attempting to
|
||||
communicate with the VM.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Disk Offerings</emphasis>: A predefined set of disk size for
|
||||
primary data storage. </para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">SNMP Community</emphasis>: The SNMP community string to be used by
|
||||
the NetScaler device to query the configured counter value from the provisioned VM
|
||||
instances. Default is public.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">SNMP Port</emphasis>: The port number on which the SNMP agent that
|
||||
run on the provisioned VMs is listening. Default port is 161. </para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">User</emphasis>: This is the user that the NetScaler device use to
|
||||
invoke scaleup and scaledown API calls to the cloud. If no option is specified, the user who
|
||||
configures AutoScaling is applied. Specify another user name to override.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">Apply</emphasis>: Click Apply to create the AutoScale
|
||||
configuration.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<formalpara>
|
||||
<title>Disabling and Enabling an AutoScale Configuration</title>
|
||||
<para>If you want to perform any maintenance operation on the AutoScale VM instances, disable
|
||||
the AutoScale configuration. When the AutoScale configuration is disabled, no scaleup or
|
||||
scaledown action is performed. You can use this downtime for the maintenance activities. To
|
||||
disable the AutoScale configuration, click the Disable AutoScale<inlinemediaobject>
|
||||
<imageobject>
|
||||
<imagedata fileref="./images/enable-disable-autoscale.png"/>
|
||||
</imageobject>
|
||||
<textobject>
|
||||
<phrase>EnableDisable.png: button to enable or disable AutoScale.</phrase>
|
||||
</textobject>
|
||||
</inlinemediaobject>button.</para>
|
||||
</formalpara>
|
||||
<para>The button toggles between enable and disable, depending on whether AutoScale is currently
|
||||
enabled or not. After the maintenance operations are done, you can enable the AutoScale
|
||||
configuration back. To enable, open the AutoScale configuration page again, then click the
|
||||
Enable AutoScale<inlinemediaobject>
|
||||
<imageobject>
|
||||
<imagedata fileref="./images/enable-disable-autoscale.png"/>
|
||||
</imageobject>
|
||||
<textobject>
|
||||
<phrase>EnableDisable.png: button to enable or disable AutoScale.</phrase>
|
||||
</textobject>
|
||||
</inlinemediaobject>button.</para>
|
||||
<formalpara id="update-autoscale">
|
||||
<title>Updating an AutoScale Configuration</title>
|
||||
<para>You can update the various parameters and add or delete the conditions in a scaleup or
|
||||
scaledown rule. Before you update an AutoScale configuration, ensure that you disable the
|
||||
AutoScale load balancer rule by clicking the Disable AutoScale button.</para>
|
||||
</formalpara>
|
||||
<para>After you modify the required AutoScale parameters, click Apply. To apply the new AutoScale
|
||||
policies, open the AutoScale configuration page again, then click the Enable AutoScale
|
||||
button.</para>
|
||||
<formalpara>
|
||||
<title>Runtime Considerations</title>
|
||||
<para/>
|
||||
</formalpara>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>An administrator should not assign a VM to a load balancing rule which is configured for
|
||||
AutoScale.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Before a VM provisioning is completed if NetScaler is shutdown or restarted, the
|
||||
provisioned VM cannot be a part of the load balancing rule though the intent was to assign
|
||||
it to a load balancing rule. To workaround, rename the AutoScale provisioned VMs based on
|
||||
the rule name or ID so at any point of time the VMs can be reconciled to its load balancing
|
||||
rule.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Making API calls outside the context of AutoScale, such as destroyVM, on an autoscaled
|
||||
VM leaves the load balancing configuration in an inconsistent state. Though VM is destroyed
|
||||
from the load balancer rule, NetScaler continues to show the VM as a service assigned to a
|
||||
rule.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</section>
|
||||
46
docs/en-US/building-marvin.xml
Normal file
46
docs/en-US/building-marvin.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?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="building-marvin">
|
||||
<title>Building and Installing Marvin</title>
|
||||
<para>Marvin is built with Maven and is dependent on APIdoc. To build it do the following in the root tree of &PRODUCT;:</para>
|
||||
<programlisting>mvn -P developer -l :cloud-apidoc</programlisting>
|
||||
<programlisting>mvn -P developer -l :cloud-marvin</programlisting>
|
||||
<para>If successfull the build will have created the cloudstackAPI Python package under tools/marvin/marvin/cloudstackAPI as well as a gziped Marvin package under tools/marvin dist. To install the Python Marvin module do the following in tools/marvin:</para>
|
||||
<programlisting>sudo python ./setup.py install</programlisting>
|
||||
<para>The dependencies will be downloaded the Python module installed and you should be able to use Marvin in Python. Check that you can import the module before starting to use it.</para>
|
||||
<programlisting>$ python
|
||||
Python 2.7.3 (default, Nov 17 2012, 19:54:34)
|
||||
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> import marvin
|
||||
>>> from marvin.cloudstackAPI import *
|
||||
>>> </programlisting>
|
||||
|
||||
<para>You could also install it using <emphasis>pip</emphasis> or <emphasis>easy_install</emphasis> using the local distribution package in tools/marvin/dist :</para>
|
||||
<programlisting>pip install tools/marvin/dist/Marvin-0.1.0.tar.gz</programlisting>
|
||||
<para>Or:</para>
|
||||
<programlisting>easy_install tools/marvin/dist/Marvin-0.1.0.tar.gz</programlisting>
|
||||
|
||||
</section>
|
||||
86
docs/en-US/configure-snmp-rhel.xml
Normal file
86
docs/en-US/configure-snmp-rhel.xml
Normal file
@ -0,0 +1,86 @@
|
||||
<?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="configure-snmp-rhel">
|
||||
<title>Configuring SNMP Community String on a RHEL Server</title>
|
||||
<para>The SNMP Community string is similar to a user id or password that provides access to a
|
||||
network device, such as router. This string is sent along with all SNMP requests. If the
|
||||
community string is correct, the device responds with the requested information. If the
|
||||
community string is incorrect, the device discards the request and does not respond.</para>
|
||||
<para>The NetScaler device uses SNMP to communicate with the VMs. You must install SNMP and
|
||||
configure SNMP Community string for a secure communication between the NetScaler device and the
|
||||
RHEL machine.</para>
|
||||
<orderedlist>
|
||||
<listitem>
|
||||
<para>Ensure that you installed SNMP on RedHat. If not, run the following command:</para>
|
||||
<screen>yum install net-snmp-utils</screen>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Edit the /etc/snmp/snmpd.conf file to allow the SNMP polling from the NetScaler
|
||||
device.</para>
|
||||
<orderedlist>
|
||||
<listitem>
|
||||
<para>Map the community name into a security name (local and mynetwork, depending on where
|
||||
the request is coming from):</para>
|
||||
<note>
|
||||
<para>Use a strong password instead of public when you edit the following table.</para>
|
||||
</note>
|
||||
<screen># sec.name source community
|
||||
com2sec local localhost public
|
||||
com2sec mynetwork 0.0.0.0 public</screen>
|
||||
<note>
|
||||
<para>Setting to 0.0.0.0 allows all IPs to poll the NetScaler server.</para>
|
||||
</note>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Map the security names into group names: </para>
|
||||
<screen># group.name sec.model sec.name
|
||||
group MyRWGroup v1 local
|
||||
group MyRWGroup v2c local
|
||||
group MyROGroup v1 mynetwork
|
||||
group MyROGroup v2c mynetwork</screen>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Create a view to allow the groups to have the permission to:</para>
|
||||
<screen>incl/excl subtree mask view all included .1 </screen>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Grant access with different write permissions to the two groups to the view you
|
||||
created.</para>
|
||||
<screen># context sec.model sec.level prefix read write notif
|
||||
access MyROGroup "" any noauth exact all none none
|
||||
access MyRWGroup "" any noauth exact all all all </screen>
|
||||
</listitem>
|
||||
</orderedlist>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Unblock SNMP in iptables.</para>
|
||||
<screen>iptables -A INPUT -p udp --dport 161 -j ACCEPT</screen>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Start the SNMP service:</para>
|
||||
<screen>service snmpd start</screen>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Ensure that the SNMP service is started automatically during the system startup:</para>
|
||||
<screen>chkconfig snmpd on</screen>
|
||||
</listitem>
|
||||
</orderedlist>
|
||||
</section>
|
||||
@ -3,26 +3,31 @@
|
||||
<!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.
|
||||
-->
|
||||
|
||||
<section id="external-firewalls-and-load-balancers">
|
||||
<title>External Firewalls and Load Balancers</title>
|
||||
<para>&PRODUCT; is capable of replacing its Virtual Router with an external Juniper SRX device and an optional external NetScaler or F5 load balancer for gateway and load balancing services. In this case, the VMs use the SRX as their gateway.</para>
|
||||
<title>External Firewalls and Load Balancers</title>
|
||||
<para>&PRODUCT; is capable of replacing its Virtual Router with an external Juniper SRX device and
|
||||
an optional external NetScaler or F5 load balancer for gateway and load balancing services. In
|
||||
this case, the VMs use the SRX as their gateway.</para>
|
||||
<xi:include href="using-netscaler-load-balancers.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
|
||||
<xi:include href="configure-snmp-rhel.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
|
||||
<xi:include href="initial-setup-of-external-firewalls-loadbalancers.xml"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude"/>
|
||||
<xi:include href="ongoing-configuration-of-external-firewalls-loadbalancer.xml"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude"/>
|
||||
<xi:include href="autoscale.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
|
||||
</section>
|
||||
|
||||
BIN
docs/en-US/images/view-console-button.png
Normal file
BIN
docs/en-US/images/view-console-button.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
@ -29,4 +29,5 @@
|
||||
<para>Marvin's complete documenation is on the wiki at <ulink url="https://cwiki.apache.org/CLOUDSTACK/testing-with-python.html">https://cwiki.apache.org/CLOUDSTACK/testing-with-python.html</ulink></para>
|
||||
<para>The source code is located at <emphasis>tools/marvin</emphasis></para>
|
||||
</note>
|
||||
<xi:include href="building-marvin.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
|
||||
</section>
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
<?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="ongoing-configuration-of-external-firewalls-loadbalancer">
|
||||
<title>Ongoing Configuration of External Firewalls and Load Balancers</title>
|
||||
<para>Additional user actions (e.g. setting a port forward) will cause further programming of the
|
||||
firewall and load balancer. A user may request additional public IP addresses and forward
|
||||
traffic received at these IPs to specific VMs. This is accomplished by enabling static NAT for a
|
||||
public IP address, assigning the IP to a VM, and specifying a set of protocols and port ranges
|
||||
to open. When a static NAT rule is created, &PRODUCT; programs the zone's external firewall with
|
||||
the following objects:</para>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>A static NAT rule that maps the public IP address to the private IP address of a
|
||||
VM.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>A security policy that allows traffic within the set of protocols and port ranges that
|
||||
are specified.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>A firewall filter counter that measures the number of bytes of incoming traffic to the
|
||||
public IP.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<para>The number of incoming and outgoing bytes through source NAT, static NAT, and load balancing
|
||||
rules is measured and saved on each external element. This data is collected on a regular basis
|
||||
and stored in the &PRODUCT; database.</para>
|
||||
</section>
|
||||
@ -26,4 +26,5 @@
|
||||
<title>System Service Offerings</title>
|
||||
<para>System service offerings provide a choice of CPU speed, number of CPUs, tags, and RAM size, just as other service offerings do. But rather than being used for virtual machine instances and exposed to users, system service offerings are used to change the default properties of virtual routers, console proxies, and other system VMs. System service offerings are visible only to the &PRODUCT; root administrator. &PRODUCT; provides default system service offerings. The &PRODUCT; root administrator can create additional custom system service offerings.</para>
|
||||
<para>When &PRODUCT; creates a virtual router for a guest network, it uses default settings which are defined in the system service offering associated with the network offering. You can upgrade the capabilities of the virtual router by applying a new network offering that contains a different system service offering. All virtual routers in that network will begin using the settings from the new service offering.</para>
|
||||
<xi:include href="creating-system-service-offerings.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
|
||||
</section>
|
||||
|
||||
@ -16,93 +16,50 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.acl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.cloudstack.acl.APIAccessChecker;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
|
||||
/*
|
||||
* This is the default API access checker that grab's the user's account
|
||||
* based on the account type, access is granted referring to commands in all *.properties files.
|
||||
*/
|
||||
|
||||
@Local(value=APIAccessChecker.class)
|
||||
public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIAccessChecker {
|
||||
// This is the default API access checker that grab's the user's account
|
||||
// based on the account type, access is granted
|
||||
@Local(value=APIChecker.class)
|
||||
public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIChecker {
|
||||
|
||||
protected static final Logger s_logger = Logger.getLogger(StaticRoleBasedAPIAccessChecker.class);
|
||||
public static final short ADMIN_COMMAND = 1;
|
||||
public static final short DOMAIN_ADMIN_COMMAND = 4;
|
||||
public static final short RESOURCE_DOMAIN_ADMIN_COMMAND = 2;
|
||||
public static final short USER_COMMAND = 8;
|
||||
private static List<String> s_userCommands = null;
|
||||
private static List<String> s_resellerCommands = null; // AKA domain-admin
|
||||
private static List<String> s_adminCommands = null;
|
||||
private static List<String> s_resourceDomainAdminCommands = null;
|
||||
private static List<String> s_allCommands = null;
|
||||
|
||||
protected @Inject AccountManager _accountMgr;
|
||||
private static Map<RoleType, Set<String>> s_roleBasedApisMap =
|
||||
new HashMap<RoleType, Set<String>>();
|
||||
|
||||
protected StaticRoleBasedAPIAccessChecker() {
|
||||
super();
|
||||
s_allCommands = new ArrayList<String>();
|
||||
s_userCommands = new ArrayList<String>();
|
||||
s_resellerCommands = new ArrayList<String>();
|
||||
s_adminCommands = new ArrayList<String>();
|
||||
s_resourceDomainAdminCommands = new ArrayList<String>();
|
||||
for (RoleType roleType: RoleType.values()) {
|
||||
s_roleBasedApisMap.put(roleType, new HashSet<String>());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccessAPI(User user, String apiCommandName)
|
||||
throws PermissionDeniedException{
|
||||
|
||||
boolean commandExists = s_allCommands.contains(apiCommandName);
|
||||
|
||||
if(commandExists && user != null){
|
||||
Long accountId = user.getAccountId();
|
||||
Account userAccount = _accountMgr.getAccount(accountId);
|
||||
short accountType = userAccount.getType();
|
||||
return isCommandAvailableForAccount(accountType, apiCommandName);
|
||||
}
|
||||
|
||||
return commandExists;
|
||||
public boolean checkAccess(RoleType roleType, String commandName) {
|
||||
return s_roleBasedApisMap.get(roleType).contains(commandName);
|
||||
}
|
||||
|
||||
private static boolean isCommandAvailableForAccount(short accountType, String commandName) {
|
||||
boolean isCommandAvailable = false;
|
||||
switch (accountType) {
|
||||
case Account.ACCOUNT_TYPE_ADMIN:
|
||||
isCommandAvailable = s_adminCommands.contains(commandName);
|
||||
break;
|
||||
case Account.ACCOUNT_TYPE_DOMAIN_ADMIN:
|
||||
isCommandAvailable = s_resellerCommands.contains(commandName);
|
||||
break;
|
||||
case Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN:
|
||||
isCommandAvailable = s_resourceDomainAdminCommands.contains(commandName);
|
||||
break;
|
||||
case Account.ACCOUNT_TYPE_NORMAL:
|
||||
isCommandAvailable = s_userCommands.contains(commandName);
|
||||
break;
|
||||
@Override
|
||||
public boolean checkExistence(String apiName) {
|
||||
for (RoleType roleType: RoleType.values()) {
|
||||
if (s_roleBasedApisMap.get(roleType).contains(apiName))
|
||||
return true;
|
||||
}
|
||||
return isCommandAvailable;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -114,69 +71,28 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIA
|
||||
List<PluggableService> services = locator.getAllPluggableServices();
|
||||
services.add((PluggableService) ComponentLocator.getComponent(ManagementServer.Name));
|
||||
|
||||
List<String> configFiles = new ArrayList<String>();
|
||||
Map<String, String> configPropertiesMap = new HashMap<String, String>();
|
||||
for (PluggableService service : services) {
|
||||
configFiles.addAll(Arrays.asList(service.getPropertiesFiles()));
|
||||
configPropertiesMap.putAll(service.getProperties());
|
||||
}
|
||||
|
||||
processConfigFiles(configFiles);
|
||||
processConfigFiles(configPropertiesMap);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void processConfigFiles(List<String> configFiles) {
|
||||
Properties preProcessedCommands = new Properties();
|
||||
|
||||
for (String configFile : configFiles) {
|
||||
File commandsFile = PropertiesUtil.findConfigFile(configFile);
|
||||
if (commandsFile != null) {
|
||||
try {
|
||||
preProcessedCommands.load(new FileInputStream(commandsFile));
|
||||
} catch (FileNotFoundException fnfex) {
|
||||
// in case of a file within a jar in classpath, try to open stream using url
|
||||
InputStream stream = PropertiesUtil.openStreamFromURL(configFile);
|
||||
if (stream != null) {
|
||||
try {
|
||||
preProcessedCommands.load(stream);
|
||||
} catch (IOException e) {
|
||||
s_logger.error("IO Exception, unable to find properties file:", fnfex);
|
||||
}
|
||||
} else {
|
||||
s_logger.error("Unable to find properites file", fnfex);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
s_logger.error("IO Exception loading properties file", ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Object key : preProcessedCommands.keySet()) {
|
||||
String preProcessedCommand = preProcessedCommands.getProperty((String) key);
|
||||
int splitIndex = preProcessedCommand.lastIndexOf(";");
|
||||
// Backward compatible to old style, apiname=pkg;mask
|
||||
String mask = preProcessedCommand.substring(splitIndex+1);
|
||||
|
||||
private void processConfigFiles(Map<String, String> configMap) {
|
||||
for (Map.Entry<String, String> entry: configMap.entrySet()) {
|
||||
String apiName = entry.getKey();
|
||||
String roleMask = entry.getValue();
|
||||
try {
|
||||
short cmdPermissions = Short.parseShort(mask);
|
||||
if ((cmdPermissions & ADMIN_COMMAND) != 0) {
|
||||
s_adminCommands.add((String) key);
|
||||
short cmdPermissions = Short.parseShort(roleMask);
|
||||
for (RoleType roleType: RoleType.values()) {
|
||||
if ((cmdPermissions & roleType.getValue()) != 0)
|
||||
s_roleBasedApisMap.get(roleType).add(apiName);
|
||||
}
|
||||
if ((cmdPermissions & RESOURCE_DOMAIN_ADMIN_COMMAND) != 0) {
|
||||
s_resourceDomainAdminCommands.add((String) key);
|
||||
}
|
||||
if ((cmdPermissions & DOMAIN_ADMIN_COMMAND) != 0) {
|
||||
s_resellerCommands.add((String) key);
|
||||
}
|
||||
if ((cmdPermissions & USER_COMMAND) != 0) {
|
||||
s_userCommands.add((String) key);
|
||||
}
|
||||
s_allCommands.addAll(s_adminCommands);
|
||||
s_allCommands.addAll(s_resourceDomainAdminCommands);
|
||||
s_allCommands.addAll(s_userCommands);
|
||||
s_allCommands.addAll(s_resellerCommands);
|
||||
} catch (NumberFormatException nfe) {
|
||||
s_logger.info("Malformed command.properties permissions value, key = " + key + ", value = " + preProcessedCommand);
|
||||
s_logger.info("Malformed commands.properties permissions value, for entry: " + entry.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,9 +16,12 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.discovery;
|
||||
|
||||
import com.cloud.user.UserContext;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.PlugService;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
@ -27,8 +30,8 @@ import org.apache.cloudstack.api.response.ApiDiscoveryResponse;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@APICommand(name = "listApis", responseObject = ApiDiscoveryResponse.class, description = "lists all available apis on the server, provided by Api Discovery plugin", since = "4.1.0")
|
||||
public class ListApisCmd extends BaseListCmd {
|
||||
@APICommand(name = "listApis", responseObject = ApiDiscoveryResponse.class, description = "lists all available apis on the server, provided by the Api Discovery plugin", since = "4.1.0")
|
||||
public class ListApisCmd extends BaseCmd {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(ListApisCmd.class.getName());
|
||||
private static final String s_name = "listapisresponse";
|
||||
@ -36,12 +39,16 @@ public class ListApisCmd extends BaseListCmd {
|
||||
@PlugService
|
||||
ApiDiscoveryService _apiDiscoveryService;
|
||||
|
||||
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="API name")
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public void execute() throws ServerApiException {
|
||||
if (_apiDiscoveryService != null) {
|
||||
ListResponse<ApiDiscoveryResponse> response = (ListResponse<ApiDiscoveryResponse>) _apiDiscoveryService.listApis();
|
||||
RoleType roleType = _accountService.getRoleType(UserContext.current().getCaller());
|
||||
ListResponse<ApiDiscoveryResponse> response = (ListResponse<ApiDiscoveryResponse>) _apiDiscoveryService.listApis(roleType, name);
|
||||
if (response == null) {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Api Discovery plugin was unable to find and process any apis");
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Api Discovery plugin was unable to find an api by that name or process any apis");
|
||||
}
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
@ -52,4 +59,10 @@ public class ListApisCmd extends BaseListCmd {
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
// no owner is needed for list command
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,18 +16,15 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.response;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
import org.apache.cloudstack.api.EntityReference;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@EntityReference(value = Account.class)
|
||||
public class ApiDiscoveryResponse extends BaseResponse {
|
||||
@SerializedName(ApiConstants.NAME) @Param(description="the name of the api command")
|
||||
private String name;
|
||||
@ -41,11 +38,18 @@ public class ApiDiscoveryResponse extends BaseResponse {
|
||||
@SerializedName(ApiConstants.IS_ASYNC) @Param(description="true if api is asynchronous")
|
||||
private Boolean isAsync;
|
||||
|
||||
@SerializedName("related") @Param(description="comma separated related apis")
|
||||
private String related;
|
||||
|
||||
@SerializedName(ApiConstants.PARAMS) @Param(description="the list params the api accepts", responseObject = ApiParameterResponse.class)
|
||||
private Set<ApiParameterResponse> params;
|
||||
|
||||
@SerializedName(ApiConstants.RESPONSE) @Param(description="api response fields", responseObject = ApiResponseResponse.class)
|
||||
private Set<ApiResponseResponse> apiResponse;
|
||||
|
||||
public ApiDiscoveryResponse(){
|
||||
params = new HashSet<ApiParameterResponse>();
|
||||
apiResponse = new HashSet<ApiResponseResponse>();
|
||||
isAsync = false;
|
||||
}
|
||||
|
||||
@ -65,6 +69,18 @@ public class ApiDiscoveryResponse extends BaseResponse {
|
||||
this.isAsync = isAsync;
|
||||
}
|
||||
|
||||
public String getRelated() {
|
||||
return related;
|
||||
}
|
||||
|
||||
public void setRelated(String related) {
|
||||
this.related = related;
|
||||
}
|
||||
|
||||
public Set<ApiParameterResponse> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(Set<ApiParameterResponse> params) {
|
||||
this.params = params;
|
||||
}
|
||||
@ -72,4 +88,8 @@ public class ApiDiscoveryResponse extends BaseResponse {
|
||||
public void addParam(ApiParameterResponse param) {
|
||||
this.params.add(param);
|
||||
}
|
||||
|
||||
public void addApiResponse(ApiResponseResponse apiResponse) {
|
||||
this.apiResponse.add(apiResponse);
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +40,9 @@ public class ApiParameterResponse extends BaseResponse {
|
||||
@SerializedName(ApiConstants.SINCE) @Param(description="version of CloudStack the api was introduced in")
|
||||
private String since;
|
||||
|
||||
@SerializedName("related") @Param(description="comma separated related apis to get the parameter")
|
||||
private String related;
|
||||
|
||||
public ApiParameterResponse(){
|
||||
}
|
||||
|
||||
@ -67,4 +70,12 @@ public class ApiParameterResponse extends BaseResponse {
|
||||
this.since = since;
|
||||
}
|
||||
|
||||
public String getRelated() {
|
||||
return related;
|
||||
}
|
||||
|
||||
public void setRelated(String related) {
|
||||
this.related = related;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
// 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.api.response;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
|
||||
public class ApiResponseResponse extends BaseResponse {
|
||||
@SerializedName(ApiConstants.NAME) @Param(description="the name of the api response field")
|
||||
private String name;
|
||||
|
||||
@SerializedName(ApiConstants.DESCRIPTION) @Param(description="description of the api response field")
|
||||
private String description;
|
||||
|
||||
@SerializedName(ApiConstants.TYPE) @Param(description="response field type")
|
||||
private String type;
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@ -17,9 +17,10 @@
|
||||
package org.apache.cloudstack.discovery;
|
||||
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
|
||||
public interface ApiDiscoveryService extends PluggableService {
|
||||
ListResponse<? extends BaseResponse> listApis();
|
||||
ListResponse<? extends BaseResponse> listApis(RoleType roleType, String apiName);
|
||||
}
|
||||
@ -16,7 +16,14 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.discovery;
|
||||
|
||||
import com.cloud.serializer.Param;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.utils.ReflectUtil;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
@ -25,6 +32,7 @@ import org.apache.cloudstack.api.BaseResponse;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.ApiDiscoveryResponse;
|
||||
import org.apache.cloudstack.api.response.ApiParameterResponse;
|
||||
import org.apache.cloudstack.api.response.ApiResponseResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@ -32,6 +40,7 @@ import javax.ejb.Local;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -40,30 +49,57 @@ import java.util.Set;
|
||||
public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
|
||||
private static final Logger s_logger = Logger.getLogger(ApiDiscoveryServiceImpl.class);
|
||||
|
||||
private ListResponse<ApiDiscoveryResponse> _discoveryResponse = new ListResponse<ApiDiscoveryResponse>();
|
||||
private static Map<RoleType, List<ApiDiscoveryResponse>> _roleTypeDiscoveryResponseListMap;
|
||||
|
||||
private Map<String, Class<?>> _apiNameCmdClassMap = new HashMap<String, Class<?>>();
|
||||
private static Map<String, ApiDiscoveryResponse> _apiNameDiscoveryResponseMap =
|
||||
new HashMap<String, ApiDiscoveryResponse>();
|
||||
|
||||
private static Map<String, List<RoleType>> _apiNameRoleTypeListMap = null;
|
||||
|
||||
protected ApiDiscoveryServiceImpl() {
|
||||
super();
|
||||
generateApiNameCmdClassMap();
|
||||
cacheListApiResponse();
|
||||
if (_roleTypeDiscoveryResponseListMap == null) {
|
||||
long startTime = System.nanoTime();
|
||||
_roleTypeDiscoveryResponseListMap = new HashMap<RoleType, List<ApiDiscoveryResponse>>();
|
||||
for (RoleType roleType: RoleType.values())
|
||||
_roleTypeDiscoveryResponseListMap.put(roleType, new ArrayList<ApiDiscoveryResponse>());
|
||||
cacheResponseMap();
|
||||
long endTime = System.nanoTime();
|
||||
s_logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms");
|
||||
}
|
||||
}
|
||||
|
||||
private void generateApiNameCmdClassMap() {
|
||||
private Map<String, List<RoleType>> getApiNameRoleTypeListMap() {
|
||||
Map<String, List<RoleType>> apiNameRoleTypeMap = new HashMap<String, List<RoleType>>();
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
List<PluggableService> services = locator.getAllPluggableServices();
|
||||
services.add((PluggableService) ComponentLocator.getComponent(ManagementServer.Name));
|
||||
for (PluggableService service : services) {
|
||||
for (Map.Entry<String, String> entry: service.getProperties().entrySet()) {
|
||||
String apiName = entry.getKey();
|
||||
String roleMask = entry.getValue();
|
||||
try {
|
||||
short cmdPermissions = Short.parseShort(roleMask);
|
||||
if (!apiNameRoleTypeMap.containsKey(apiName))
|
||||
apiNameRoleTypeMap.put(apiName, new ArrayList<RoleType>());
|
||||
for (RoleType roleType: RoleType.values()) {
|
||||
if ((cmdPermissions & roleType.getValue()) != 0)
|
||||
apiNameRoleTypeMap.get(apiName).add(roleType);
|
||||
}
|
||||
} catch (NumberFormatException nfe) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return apiNameRoleTypeMap;
|
||||
}
|
||||
|
||||
private void cacheResponseMap() {
|
||||
Set<Class<?>> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class,
|
||||
new String[]{"org.apache.cloudstack.api", "com.cloud.api"});
|
||||
|
||||
for(Class<?> cmdClass: cmdClasses)
|
||||
_apiNameCmdClassMap.put(cmdClass.getAnnotation(APICommand.class).name(), cmdClass);
|
||||
}
|
||||
Map<String, List<String>> responseApiNameListMap = new HashMap<String, List<String>>();
|
||||
|
||||
private void cacheListApiResponse() {
|
||||
|
||||
List<ApiDiscoveryResponse> apiDiscoveryResponses = new ArrayList<ApiDiscoveryResponse>();
|
||||
|
||||
for(String key: _apiNameCmdClassMap.keySet()) {
|
||||
Class<?> cmdClass = _apiNameCmdClassMap.get(key);
|
||||
for(Class<?> cmdClass: cmdClasses) {
|
||||
APICommand apiCmdAnnotation = cmdClass.getAnnotation(APICommand.class);
|
||||
if (apiCmdAnnotation == null)
|
||||
apiCmdAnnotation = cmdClass.getSuperclass().getAnnotation(APICommand.class);
|
||||
@ -72,10 +108,33 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
|
||||
|| apiCmdAnnotation.name().isEmpty())
|
||||
continue;
|
||||
|
||||
String apiName = apiCmdAnnotation.name();
|
||||
String responseName = apiCmdAnnotation.responseObject().getName();
|
||||
if (!responseName.contains("SuccessResponse")) {
|
||||
if (!responseApiNameListMap.containsKey(responseName))
|
||||
responseApiNameListMap.put(responseName, new ArrayList<String>());
|
||||
responseApiNameListMap.get(responseName).add(apiName);
|
||||
}
|
||||
ApiDiscoveryResponse response = new ApiDiscoveryResponse();
|
||||
response.setName(apiCmdAnnotation.name());
|
||||
response.setName(apiName);
|
||||
response.setDescription(apiCmdAnnotation.description());
|
||||
response.setSince(apiCmdAnnotation.since());
|
||||
if (!apiCmdAnnotation.since().isEmpty())
|
||||
response.setSince(apiCmdAnnotation.since());
|
||||
response.setRelated(responseName);
|
||||
|
||||
Field[] responseFields = apiCmdAnnotation.responseObject().getDeclaredFields();
|
||||
for(Field responseField: responseFields) {
|
||||
SerializedName serializedName = responseField.getAnnotation(SerializedName.class);
|
||||
if(serializedName != null) {
|
||||
ApiResponseResponse responseResponse = new ApiResponseResponse();
|
||||
responseResponse.setName(serializedName.value());
|
||||
Param param = responseField.getAnnotation(Param.class);
|
||||
if (param != null)
|
||||
responseResponse.setDescription(param.description());
|
||||
responseResponse.setType(responseField.getType().getSimpleName().toLowerCase());
|
||||
response.addApiResponse(responseResponse);
|
||||
}
|
||||
}
|
||||
|
||||
Field[] fields = ReflectUtil.getAllFieldsForClass(cmdClass,
|
||||
new Class<?>[] {BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class});
|
||||
@ -94,26 +153,80 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
|
||||
ApiParameterResponse paramResponse = new ApiParameterResponse();
|
||||
paramResponse.setName(parameterAnnotation.name());
|
||||
paramResponse.setDescription(parameterAnnotation.description());
|
||||
paramResponse.setType(parameterAnnotation.type().toString());
|
||||
paramResponse.setType(parameterAnnotation.type().toString().toLowerCase());
|
||||
paramResponse.setLength(parameterAnnotation.length());
|
||||
paramResponse.setRequired(parameterAnnotation.required());
|
||||
paramResponse.setSince(parameterAnnotation.since());
|
||||
if (!parameterAnnotation.since().isEmpty())
|
||||
paramResponse.setSince(parameterAnnotation.since());
|
||||
paramResponse.setRelated(parameterAnnotation.entityType()[0].getName());
|
||||
response.addParam(paramResponse);
|
||||
}
|
||||
}
|
||||
response.setObjectName("apis");
|
||||
apiDiscoveryResponses.add(response);
|
||||
response.setObjectName("api");
|
||||
_apiNameDiscoveryResponseMap.put(apiName, response);
|
||||
}
|
||||
|
||||
for (String apiName: _apiNameDiscoveryResponseMap.keySet()) {
|
||||
ApiDiscoveryResponse response = _apiNameDiscoveryResponseMap.get(apiName);
|
||||
Set<ApiParameterResponse> processedParams = new HashSet<ApiParameterResponse>();
|
||||
for (ApiParameterResponse param: response.getParams()) {
|
||||
if (responseApiNameListMap.containsKey(param.getRelated())) {
|
||||
List<String> relatedApis = responseApiNameListMap.get(param.getRelated());
|
||||
param.setRelated(StringUtils.join(relatedApis, ","));
|
||||
} else {
|
||||
param.setRelated(null);
|
||||
}
|
||||
processedParams.add(param);
|
||||
}
|
||||
response.setParams(processedParams);
|
||||
|
||||
if (responseApiNameListMap.containsKey(response.getRelated())) {
|
||||
List<String> relatedApis = responseApiNameListMap.get(response.getRelated());
|
||||
relatedApis.remove(apiName);
|
||||
response.setRelated(StringUtils.join(relatedApis, ","));
|
||||
} else {
|
||||
response.setRelated(null);
|
||||
}
|
||||
_apiNameDiscoveryResponseMap.put(apiName, response);
|
||||
}
|
||||
_discoveryResponse.setResponses(apiDiscoveryResponses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListResponse<? extends BaseResponse> listApis() {
|
||||
return _discoveryResponse;
|
||||
public ListResponse<? extends BaseResponse> listApis(RoleType roleType, String name) {
|
||||
// Creates roles based response list cache the first time listApis is called
|
||||
// Due to how adapters work, this cannot be done when mgmt loads
|
||||
if (_apiNameRoleTypeListMap == null) {
|
||||
long startTime = System.nanoTime();
|
||||
_apiNameRoleTypeListMap = getApiNameRoleTypeListMap();
|
||||
for (Map.Entry<String, List<RoleType>> entry: _apiNameRoleTypeListMap.entrySet()) {
|
||||
String apiName = entry.getKey();
|
||||
for (RoleType roleTypeInList: entry.getValue()) {
|
||||
_roleTypeDiscoveryResponseListMap.get(roleTypeInList).add(
|
||||
_apiNameDiscoveryResponseMap.get(apiName));
|
||||
}
|
||||
}
|
||||
long endTime = System.nanoTime();
|
||||
s_logger.info("Api Discovery Service: List apis cached in " + (endTime - startTime) / 1000000.0 + " ms");
|
||||
}
|
||||
ListResponse<ApiDiscoveryResponse> response = new ListResponse<ApiDiscoveryResponse>();
|
||||
if (name != null) {
|
||||
if (!_apiNameDiscoveryResponseMap.containsKey(name))
|
||||
return null;
|
||||
|
||||
List<ApiDiscoveryResponse> singleResponse = new ArrayList<ApiDiscoveryResponse>();
|
||||
singleResponse.add(_apiNameDiscoveryResponseMap.get(name));
|
||||
response.setResponses(singleResponse);
|
||||
|
||||
} else {
|
||||
response.setResponses(_roleTypeDiscoveryResponseListMap.get(roleType));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "api-discovery_commands.properties" };
|
||||
public Map<String, String> getProperties() {
|
||||
Map<String, String> apiDiscoveryPropertyMap = new HashMap<String, String>();
|
||||
apiDiscoveryPropertyMap.put("listApis", "15");
|
||||
return apiDiscoveryPropertyMap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,16 +17,16 @@
|
||||
package com.cloud.server;
|
||||
|
||||
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ManagementServerSimulatorImpl extends ManagementServerExtImpl {
|
||||
@Override
|
||||
public String[] getPropertiesFiles() {
|
||||
String[] apis = super.getPropertiesFiles();
|
||||
String[] newapis = new String[apis.length + 1];
|
||||
for (int i = 0; i < apis.length; i++) {
|
||||
newapis[i] = apis[i];
|
||||
}
|
||||
|
||||
newapis[apis.length] = "commands-simulator.properties";
|
||||
return newapis;
|
||||
public Map<String, String> getProperties() {
|
||||
Map<String, String> apiNameRoleMaskMapping = super.getProperties();
|
||||
apiNameRoleMaskMapping.putAll(PropertiesUtil.processConfigFile(new String[]
|
||||
{"commands-simulator.properties"}));
|
||||
return apiNameRoleMaskMapping;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
package com.cloud.network.element;
|
||||
|
||||
import java.lang.String;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
@ -24,6 +25,7 @@ import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.commands.DeleteCiscoNexusVSMCmd;
|
||||
@ -237,7 +239,8 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "cisconexusvsm_commands.properties" };
|
||||
public Map<String, String> getProperties() {
|
||||
return PropertiesUtil.processConfigFile(new String[]
|
||||
{ "cisconexusvsm_commands.properties" });
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
// under the License.
|
||||
package com.cloud.network.element;
|
||||
|
||||
import java.lang.String;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -24,6 +25,7 @@ import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
@ -260,8 +262,9 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "f5bigip_commands.properties" };
|
||||
public Map<String, String> getProperties() {
|
||||
return PropertiesUtil.processConfigFile(new String[]
|
||||
{ "f5bigip_commands.properties" });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
// under the License.
|
||||
package com.cloud.network.element;
|
||||
|
||||
import java.lang.String;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -24,6 +25,7 @@ import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
@ -402,8 +404,9 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "junipersrx_commands.properties"};
|
||||
public Map<String, String> getProperties() {
|
||||
return PropertiesUtil.processConfigFile(new String[]
|
||||
{ "junipersrx_commands.properties"});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -26,6 +26,7 @@ import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
@ -464,8 +465,9 @@ StaticNatServiceProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "netscalerloadbalancer_commands.properties" };
|
||||
public Map<String, String> getProperties() {
|
||||
return PropertiesUtil.processConfigFile(new String[]
|
||||
{ "netscalerloadbalancer_commands.properties" });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -27,6 +27,7 @@ import java.util.UUID;
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
@ -540,8 +541,9 @@ public class NiciraNvpElement extends AdapterBase implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "nicira-nvp_commands.properties" };
|
||||
public Map<String, String> getProperties() {
|
||||
return PropertiesUtil.processConfigFile(new String[]
|
||||
{ "nicira-nvp_commands.properties" });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
2
pom.xml
2
pom.xml
@ -245,6 +245,7 @@
|
||||
<exclude>scripts/vm/systemvm/id_rsa.cloud</exclude>
|
||||
<exclude>tools/devcloud/basebuild/puppet-devcloudinitial/files/network.conf</exclude>
|
||||
<exclude>tools/devcloud/devcloud.cfg</exclude>
|
||||
<exclude>tools/devcloud-kvm/devcloud-kvm.cfg</exclude>
|
||||
<exclude>ui/lib/flot/jquery.colorhelpers.js</exclude>
|
||||
<exclude>ui/lib/flot/jquery.flot.crosshair.js</exclude>
|
||||
<exclude>ui/lib/flot/jquery.flot.fillbetween.js</exclude>
|
||||
@ -371,6 +372,7 @@
|
||||
<module>developer</module>
|
||||
<module>tools/apidoc</module>
|
||||
<module>tools/devcloud</module>
|
||||
<module>tools/devcloud-kvm</module>
|
||||
<module>tools/marvin</module>
|
||||
<module>tools/cli</module>
|
||||
</modules>
|
||||
|
||||
@ -51,9 +51,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.cloud.utils.ReflectUtil;
|
||||
import org.apache.cloudstack.acl.APIAccessChecker;
|
||||
import org.apache.cloudstack.acl.APILimitChecker;
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.APIChecker;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.*;
|
||||
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
|
||||
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
|
||||
@ -149,8 +149,8 @@ public class ApiServer implements HttpRequestHandler {
|
||||
|
||||
@Inject(adapter = APILimitChecker.class)
|
||||
protected Adapters<APILimitChecker> _apiLimitCheckers;
|
||||
@Inject(adapter = APIAccessChecker.class)
|
||||
protected Adapters<APIAccessChecker> _apiAccessCheckers;
|
||||
@Inject(adapter = APIChecker.class)
|
||||
protected Adapters<APIChecker> _apiAccessCheckers;
|
||||
|
||||
private Account _systemAccount = null;
|
||||
private User _systemUser = null;
|
||||
@ -564,14 +564,14 @@ public class ApiServer implements HttpRequestHandler {
|
||||
}
|
||||
}
|
||||
if (!isCommandAvailable(user, commandName)) {
|
||||
s_logger.warn("The given command:" + commandName + " does not exist or it is not available for user");
|
||||
s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user with id:" + userId);
|
||||
throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// check against every available command to see if the command exists or not
|
||||
if (!isCommandAvailable(null, commandName) && !commandName.equals("login") && !commandName.equals("logout")) {
|
||||
s_logger.warn("The given command:" + commandName + " does not exist or it is not available for user");
|
||||
if (!doesCommandExist(commandName) && !commandName.equals("login") && !commandName.equals("logout")) {
|
||||
s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user with id:" + userId);
|
||||
throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user");
|
||||
}
|
||||
}
|
||||
@ -665,8 +665,8 @@ public class ApiServer implements HttpRequestHandler {
|
||||
UserContext.updateContext(user.getId(), account, null);
|
||||
|
||||
if (!isCommandAvailable(user, commandName)) {
|
||||
s_logger.warn("The given command:" + commandName + " does not exist or it is not available for user");
|
||||
throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given command:" + commandName + " does not exist or it is not available for user");
|
||||
s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user");
|
||||
throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given command:" + commandName + " does not exist or it is not available for user with id:" + userId);
|
||||
}
|
||||
|
||||
// verify secret key exists
|
||||
@ -802,6 +802,7 @@ public class ApiServer implements HttpRequestHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean isRequestAllowed(User user) {
|
||||
Account account = ApiDBUtils.findAccountById(user.getAccountId());
|
||||
if ( _accountMgr.isRootAdmin(account.getType()) ){
|
||||
@ -816,10 +817,25 @@ public class ApiServer implements HttpRequestHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean doesCommandExist(String apiName) {
|
||||
for (APIChecker apiChecker : _apiAccessCheckers) {
|
||||
// If any checker has api info on the command, return true
|
||||
if (apiChecker.checkExistence(apiName))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isCommandAvailable(User user, String commandName) {
|
||||
for (APIAccessChecker apiChecker : _apiAccessCheckers) {
|
||||
if (user == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Account account = _accountMgr.getAccount(user.getAccountId());
|
||||
RoleType roleType = _accountMgr.getRoleType(account);
|
||||
for (APIChecker apiChecker : _apiAccessCheckers) {
|
||||
// Fail the checking if any checker fails to verify
|
||||
if (!apiChecker.canAccessAPI(user, commandName))
|
||||
if (!apiChecker.checkAccess(roleType, commandName))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -24,6 +24,7 @@ import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElementCmd;
|
||||
import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
@ -680,8 +681,9 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "virtualrouter_commands.properties" };
|
||||
public Map<String, String> getProperties() {
|
||||
return PropertiesUtil.processConfigFile(new String[]
|
||||
{ "virtualrouter_commands.properties" });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -29,6 +29,7 @@ import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import org.apache.cloudstack.api.response.UsageTypeResponse;
|
||||
import com.cloud.usage.UsageJobVO;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
@ -206,8 +207,9 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "commands.properties", "commands-ext.properties" };
|
||||
public Map<String, String> getProperties() {
|
||||
return PropertiesUtil.processConfigFile(new String[]
|
||||
{ "commands.properties", "commands-ext.properties" });
|
||||
}
|
||||
|
||||
private Date computeAdjustedTime(Date initialDate, TimeZone targetTZ, boolean adjustToDayStart) {
|
||||
|
||||
@ -223,6 +223,7 @@ import com.cloud.utils.EnumUtils;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.PasswordGenerator;
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import com.cloud.utils.Ternary;
|
||||
import com.cloud.utils.component.Adapters;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
@ -2297,8 +2298,9 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "commands.properties" };
|
||||
public Map<String, String> getProperties() {
|
||||
return PropertiesUtil.processConfigFile(new String[]
|
||||
{ "commands.properties" });
|
||||
}
|
||||
|
||||
protected class EventPurgeTask implements Runnable {
|
||||
|
||||
@ -37,6 +37,7 @@ import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.acl.SecurityChecker;
|
||||
import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
|
||||
@ -1542,6 +1543,31 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleType getRoleType(Account account) {
|
||||
RoleType roleType = RoleType.Unknown;
|
||||
if (account == null)
|
||||
return roleType;
|
||||
short accountType = account.getType();
|
||||
|
||||
// Account type to role type translation
|
||||
switch (accountType) {
|
||||
case Account.ACCOUNT_TYPE_ADMIN:
|
||||
roleType = RoleType.Admin;
|
||||
break;
|
||||
case Account.ACCOUNT_TYPE_DOMAIN_ADMIN:
|
||||
roleType = RoleType.DomainAdmin;
|
||||
break;
|
||||
case Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN:
|
||||
roleType = RoleType.ResourceAdmin;
|
||||
break;
|
||||
case Account.ACCOUNT_TYPE_NORMAL:
|
||||
roleType = RoleType.User;
|
||||
break;
|
||||
}
|
||||
return roleType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getActiveUser(long userId) {
|
||||
return _userDao.findById(userId);
|
||||
|
||||
@ -23,6 +23,7 @@ import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
|
||||
import com.cloud.api.query.vo.ControlledViewEntity;
|
||||
|
||||
@ -344,4 +345,9 @@ public class MockAccountManagerImpl implements Manager, AccountManager, AccountS
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleType getRoleType(Account account) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -129,7 +129,6 @@ known_categories = {
|
||||
'AutoScale': 'AutoScale',
|
||||
'Counter': 'AutoScale',
|
||||
'Condition': 'AutoScale',
|
||||
'Api': 'API Discovery',
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@
|
||||
<argument>${client.config.jars}</argument>
|
||||
<argument>./target</argument>
|
||||
<argument>-f</argument>
|
||||
<argument>${client.config.conf}/commands.properties,${client.config.conf}/commands-ext.properties,${client.config.conf}/virtualrouter_commands.properties,${client.config.conf}/nicira-nvp_commands.properties,${client.config.conf}/api-discovery_commands.properties </argument>
|
||||
<argument>${client.config.conf}/commands.properties,${client.config.conf}/commands-ext.properties,${client.config.conf}/virtualrouter_commands.properties,${client.config.conf}/nicira-nvp_commands.properties</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
21
tools/devcloud-kvm/README.md
Normal file
21
tools/devcloud-kvm/README.md
Normal file
@ -0,0 +1,21 @@
|
||||
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.
|
||||
|
||||
===========================================================
|
||||
|
||||
This directory hosts configs for setting up the devcloud-kvm
|
||||
environment.
|
||||
97
tools/devcloud-kvm/devcloud-kvm.cfg
Normal file
97
tools/devcloud-kvm/devcloud-kvm.cfg
Normal file
@ -0,0 +1,97 @@
|
||||
{
|
||||
"zones": [
|
||||
{
|
||||
"name": "DevCloudKVM0",
|
||||
"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.100.250",
|
||||
"name": "test00",
|
||||
"startip": "192.168.100.200",
|
||||
"guestIpRanges": [
|
||||
{
|
||||
"startip": "192.168.100.100",
|
||||
"endip": "192.168.100.199",
|
||||
"netmask": "255.255.255.0",
|
||||
"gateway": "192.168.100.1"
|
||||
}
|
||||
],
|
||||
"netmask": "255.255.255.0",
|
||||
"clusters": [
|
||||
{
|
||||
"clustername": "test000",
|
||||
"hypervisor": "KVM",
|
||||
"hosts": [
|
||||
{
|
||||
"username": "root",
|
||||
"url": "http://192.168.100.10/",
|
||||
"password": "password"
|
||||
}
|
||||
],
|
||||
"clustertype": "CloudManaged"
|
||||
}
|
||||
],
|
||||
"gateway": "192.168.100.1"
|
||||
}
|
||||
],
|
||||
"internaldns1": "192.168.100.10",
|
||||
"secondaryStorages": [
|
||||
{
|
||||
"url": "nfs://192.168.100.10:/nfs/secondary"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"logger": [
|
||||
{
|
||||
"name": "TestClient",
|
||||
"file": "/tmp/testclient.log"
|
||||
},
|
||||
{
|
||||
"name": "TestCase",
|
||||
"file": "/tmp/testcase.log"
|
||||
}
|
||||
],
|
||||
"mgtSvr": [
|
||||
{
|
||||
"mgtSvrIp": "127.0.0.1",
|
||||
"port": 8096
|
||||
}
|
||||
],
|
||||
"dbSvr":
|
||||
{
|
||||
"dbSvr": "127.0.0.1",
|
||||
"port": 3306,
|
||||
"user": "cloud",
|
||||
"passwd": "cloud",
|
||||
"db": "cloud"
|
||||
}
|
||||
}
|
||||
40
tools/devcloud-kvm/devcloud-kvm.sql
Normal file
40
tools/devcloud-kvm/devcloud-kvm.sql
Normal file
@ -0,0 +1,40 @@
|
||||
-- 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.
|
||||
|
||||
|
||||
INSERT INTO `cloud`.`disk_offering` (id, name, uuid, display_text, created, use_local_storage, type, disk_size) VALUES (17, 'tinyOffering', UUID(), 'tinyOffering', NOW(), 1, 'Service', 0);
|
||||
INSERT INTO `cloud`.`service_offering` (id, cpu, speed, ram_size) VALUES (17, 1, 100, 100);
|
||||
INSERT INTO `cloud`.`disk_offering` (id, name, uuid, display_text, created, type, disk_size) VALUES (18, 'tinyDiskOffering', UUID(), 'tinyDiskOffering', NOW(), 'Disk', 1073741824);
|
||||
INSERT INTO `cloud`.`configuration` (instance, name,value) VALUE('DEFAULT','router.ram.size', '100');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name,value) VALUE('DEFAULT','router.cpu.mhz','100');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name,value) VALUE('DEFAULT','console.ram.size','100');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name,value) VALUE('DEFAULT','console.cpu.mhz', '100');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name,value) VALUE('DEFAULT','ssvm.ram.size','100');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name,value) VALUE('DEFAULT','ssvm.cpu.mhz','100');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'system.vm.use.local.storage', 'true');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'expunge.workers', '3');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'expunge.delay', '60');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'expunge.interval', '60');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'enable.ec2.api', 'true');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'enable.s3.api', 'true');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'host', '192.168.100.10');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'management.network.cidr', '192.168.100.0/24');
|
||||
INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'secstorage.allowed.internal.sites', '192.168.0.0/8');
|
||||
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="http://marcus.mlsorensen.com/cloudstack-extras/ttylinux_pv.qcow2",checksum="81dcf4b4ca05a3b637a040e851568f29",display_text="tiny Linux",format='QCOW2',hypervisor_type='KVM' where id=5;
|
||||
138
tools/devcloud-kvm/pom.xml
Normal file
138
tools/devcloud-kvm/pom.xml
Normal file
@ -0,0 +1,138 @@
|
||||
<!-- 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. -->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" 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-devcloud-kvm</artifactId>
|
||||
<name>Apache CloudStack Developer Tools</name>
|
||||
<packaging>pom</packaging>
|
||||
<parent>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloudstack</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.21</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>deploydb</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>deploydb</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.0-alpha-2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>read-project-properties</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<files>
|
||||
<file>${project.parent.basedir}/utils/conf/db.properties</file>
|
||||
<file>${project.parent.basedir}/utils/conf/db.properties.override</file>
|
||||
</files>
|
||||
<quiet>true</quiet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>sql-maven-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<dependencies>
|
||||
<!-- specify the dependent jdbc driver here -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${cs.mysql.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<configuration>
|
||||
<driver>org.gjt.mm.mysql.Driver</driver>
|
||||
<url>jdbc:mysql://${db.cloud.host}:${db.cloud.port}/cloud</url>
|
||||
<username>${db.cloud.username}</username>
|
||||
<password>${db.cloud.password}</password>
|
||||
<!--all executions are ignored if -Dmaven.test.skip=true -->
|
||||
<skip>${maven.test.skip}</skip>
|
||||
<forceMojoExecution>true</forceMojoExecution>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>create-schema</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>execute</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<srcFiles>
|
||||
<srcFile>${basedir}/devcloud-kvm.sql</srcFile>
|
||||
</srcFiles>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>deploysvr</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>deploysvr</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<executable>python</executable>
|
||||
<arguments>
|
||||
<argument>../marvin/marvin/deployDataCenter.py</argument>
|
||||
<argument>-i</argument>
|
||||
<argument>devcloud-kvm.cfg</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@ -17,6 +17,8 @@
|
||||
package com.cloud.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
@ -28,6 +30,7 @@ import java.util.Set;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class PropertiesUtil {
|
||||
private static final Logger s_logger = Logger.getLogger(PropertiesUtil.class);
|
||||
/**
|
||||
* Searches the class path and local paths to find the config file.
|
||||
* @param path path to find. if it starts with / then it's absolute path.
|
||||
@ -116,4 +119,41 @@ public class PropertiesUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Returns key=value pairs by parsing a commands.properties/config file
|
||||
// with syntax; key=cmd;value (with this syntax cmd is stripped) and key=value
|
||||
public static Map<String, String> processConfigFile(String[] configFiles) {
|
||||
Map<String, String> configMap = new HashMap<String, String>();
|
||||
Properties preProcessedCommands = new Properties();
|
||||
for (String configFile : configFiles) {
|
||||
File commandsFile = findConfigFile(configFile);
|
||||
if (commandsFile != null) {
|
||||
try {
|
||||
preProcessedCommands.load(new FileInputStream(commandsFile));
|
||||
} catch (FileNotFoundException fnfex) {
|
||||
// in case of a file within a jar in classpath, try to open stream using url
|
||||
InputStream stream = PropertiesUtil.openStreamFromURL(configFile);
|
||||
if (stream != null) {
|
||||
try {
|
||||
preProcessedCommands.load(stream);
|
||||
} catch (IOException e) {
|
||||
s_logger.error("IO Exception, unable to find properties file:", fnfex);
|
||||
}
|
||||
} else {
|
||||
s_logger.error("Unable to find properites file", fnfex);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
s_logger.error("IO Exception loading properties file", ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Object key : preProcessedCommands.keySet()) {
|
||||
String preProcessedCommand = preProcessedCommands.getProperty((String) key);
|
||||
int splitIndex = preProcessedCommand.lastIndexOf(";");
|
||||
String value = preProcessedCommand.substring(splitIndex+1);
|
||||
configMap.put((String)key, value);
|
||||
}
|
||||
return configMap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,9 +16,11 @@
|
||||
// under the License.
|
||||
package com.cloud.utils.component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
// This interface defines methods for pluggable code within the Cloud Stack.
|
||||
public interface PluggableService {
|
||||
// The config command properties filenames that lists allowed API commands
|
||||
// and role masks supported by this pluggable service
|
||||
String[] getPropertiesFiles();
|
||||
Map<String, String> getProperties();
|
||||
}
|
||||
|
||||
@ -18,14 +18,21 @@ package com.cloud.utils.log;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.*;
|
||||
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.apache.log4j.spi.RootLogger;
|
||||
import org.apache.log4j.spi.ThrowableRenderer;
|
||||
|
||||
import java.io.CharArrayWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
|
||||
public class CglibThrowableRendererTest extends TestCase {
|
||||
static Logger another = Logger.getLogger("TEST");
|
||||
|
||||
private final static Logger s_logger = Logger.getLogger(CglibThrowableRendererTest.class);
|
||||
public static class Test {
|
||||
@DB
|
||||
@ -48,13 +55,40 @@ public class CglibThrowableRendererTest extends TestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Logger getAlternateLogger(Writer writer, ThrowableRenderer renderer) {
|
||||
Hierarchy hierarchy = new Hierarchy(new RootLogger(Level.INFO));
|
||||
if (renderer != null) {
|
||||
hierarchy.setThrowableRenderer(renderer);
|
||||
}
|
||||
Logger alternateRoot = hierarchy.getRootLogger();
|
||||
alternateRoot.addAppender(new WriterAppender(new SimpleLayout(), writer));
|
||||
return alternateRoot;
|
||||
}
|
||||
|
||||
public void testException() {
|
||||
Writer w = new CharArrayWriter();
|
||||
Logger alt = getAlternateLogger(w, null);
|
||||
|
||||
Test test = ComponentLocator.inject(Test.class);
|
||||
try {
|
||||
test.exception();
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("exception caught", e);
|
||||
alt.warn("exception caught", e);
|
||||
}
|
||||
// first check that we actually have some call traces containing "<generated>"
|
||||
assertTrue(w.toString().contains("<generated>"));
|
||||
|
||||
w = new CharArrayWriter();
|
||||
alt = getAlternateLogger(w, new CglibThrowableRenderer());
|
||||
|
||||
try {
|
||||
test.exception();
|
||||
} catch (Exception e) {
|
||||
alt.warn("exception caught", e);
|
||||
}
|
||||
// then we check that CglibThrowableRenderer indeed remove those occurrences
|
||||
assertFalse(w.toString().contains("<generated>"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user