Merge branch 'master' of ssh://git.cloud.com/var/lib/git/cloudstack-oss

This commit is contained in:
nit 2010-12-06 14:07:24 +05:30
commit 39eb645b04
253 changed files with 9135 additions and 6660 deletions

View File

@ -40,12 +40,14 @@ backupdir = "@SHAREDSTATEDIR@/@AGENTPATH@/etcbackup"
try:
# parse cmd line
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "cluster=", "no-kvm", "guid="])
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "cluster=", "no-kvm", "guid=", "pubNic=", "prvNic="])
host=None
zone=None
pod=None
cluster=None
guid=None
pubNic=None
prvNic=None
autoMode=False
do_check_kvm = True
for opt, arg in opts:
@ -64,6 +66,10 @@ try:
elif opt == "--guid":
if arg != "":
guid = arg
elif opt == "--pubNic":
pubNic = arg
elif opt == "--prvNic":
prvNic = arg
elif opt == "--no-kvm":
do_check_kvm = False
elif opt == "-a":
@ -89,7 +95,7 @@ try:
# system configuration tasks that our Cloud Agent setup performs
try:
tasks = cloud_utils.config_tasks(brname)
tasks = cloud_utils.config_tasks(brname, pubNic, prvNic)
for t in tasks:
t.setAutoMode(autoMode)
if all( [ t.done() for t in tasks ] ):
@ -116,7 +122,7 @@ try:
stderr(str(e))
bail(cloud_utils.E_SETUPFAILED,"Cloud Agent setup failed")
setup_agent_config(configfile, host, zone, pod, cluster, guid)
setup_agent_config(configfile, host, zone, pod, cluster, guid, pubNic, prvNic)
stderr("Enabling and starting the Cloud Agent")
stop_service(servicename)
enable_service(servicename)

View File

@ -1338,7 +1338,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
vol = primaryPool.storageVolCreateXML(volDef.toString(), 0);
}
VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(), getStorageResourceType(), pool.getType(), pool.getPath(), vol.getName(),vol.getKey(), disksize);
VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(), getStorageResourceType(), pool.getType(), pool.getPath(), vol.getName(),vol.getKey(), disksize, null);
return new CreateAnswer(cmd, volume);
} catch (LibvirtException e) {

View File

@ -1,7 +0,0 @@
import Options
bld.install_files("${AGENTLIBDIR}",
bld.path.ant_glob("storagepatch/**",src=True,bld=False,dir=False,flat=True),
cwd=bld.path,relative_trick=True)
if not Options.options.PRESERVECONFIG:
bld.install_files_filtered("${AGENTSYSCONFDIR}","conf/*")

View File

@ -0,0 +1,44 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api.routing;
import java.util.HashMap;
import com.cloud.agent.api.Command;
public abstract class RoutingCommand extends Command {
HashMap<String, String> accessDetails = new HashMap<String, String>(0);
protected RoutingCommand() {
super();
}
public void setAccessDetail(String name, String value) {
accessDetails.put(name, value);
}
public String getAccessDetail(String name) {
return accessDetails.get(name);
}
@Override
public boolean executeInSequence() {
return false;
}
}

View File

@ -0,0 +1,38 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api.routing;
import com.cloud.agent.api.Answer;
public class SetFirewallRulesAnswer extends Answer {
String[] results;
protected SetFirewallRulesAnswer() {
}
public SetFirewallRulesAnswer(SetFirewallRulesCommand cmd, String[] results) {
super(cmd, true, null);
assert (cmd.getRules().length == results.length) : "rules and their results should be the same length don't you think?";
this.results = results;
}
public String[] getResults() {
return results;
}
}

View File

@ -0,0 +1,43 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api.routing;
import java.util.List;
import com.cloud.agent.api.to.FirewallRuleTO;
/**
* SetFirewallRulesCommand is the transport for firewall rules.
*
* AccessDetails allow different components to put in information about
* how to access the components inside the command.
*/
public class SetFirewallRulesCommand extends RoutingCommand {
FirewallRuleTO[] rules;
protected SetFirewallRulesCommand() {
}
public SetFirewallRulesCommand(List<FirewallRuleTO> rules) {
this.rules = rules.toArray(new FirewallRuleTO[rules.size()]);
}
public FirewallRuleTO[] getRules() {
return rules;
}
}

View File

@ -0,0 +1,38 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api.routing;
import com.cloud.agent.api.Answer;
public class SetPortForwardingRulesAnswer extends Answer {
String[] results;
protected SetPortForwardingRulesAnswer() {
super();
}
public SetPortForwardingRulesAnswer(SetPortForwardingRulesCommand cmd, String[] results) {
super(cmd, true, null);
assert(cmd.getRules().length == results.length) : "Shouldn't the results match the commands?";
this.results = results;
}
String[] getResults() {
return results;
}
}

View File

@ -0,0 +1,37 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api.routing;
import java.util.List;
import com.cloud.agent.api.to.PortForwardingRuleTO;
public class SetPortForwardingRulesCommand extends RoutingCommand {
PortForwardingRuleTO[] rules;
protected SetPortForwardingRulesCommand() {
}
public SetPortForwardingRulesCommand(List<PortForwardingRuleTO> rules) {
this.rules = rules.toArray(new PortForwardingRuleTO[rules.size()]);
}
public PortForwardingRuleTO[] getRules() {
return rules;
}
}

View File

@ -0,0 +1,56 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api.to;
public class FirewallRuleTO {
String srcIp;
String protocol;
int[] srcPortRange;
boolean revoked;
String vlanNetmask; // FIXME: Get rid of this!
protected FirewallRuleTO() {
}
public FirewallRuleTO(String srcIp, String protocol, int srcPortStart, int srcPortEnd, boolean revoked) {
this.srcIp = srcIp;
this.protocol = protocol;
this.srcPortRange = new int[] {srcPortStart, srcPortEnd};
this.revoked = revoked;
}
public String getSrcIp() {
return srcIp;
}
public String getProtocol() {
return protocol;
}
public int[] getSrcPortRange() {
return srcPortRange;
}
public boolean revoked() {
return revoked;
}
public String getVlanNetmask() {
return vlanNetmask;
}
}

View File

@ -0,0 +1,41 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api.to;
public class PortForwardingRuleTO extends FirewallRuleTO {
String dstIp;
int[] dstPortRange;
protected PortForwardingRuleTO() {
super();
}
public PortForwardingRuleTO(String srcIp, int srcPortStart, int srcPortEnd, String dstIp, int dstPortStart, int dstPortEnd, String protocol, boolean revoked) {
super(srcIp, protocol, srcPortStart, srcPortEnd, revoked);
this.dstIp = dstIp;
this.dstPortRange = new int[] { dstPortStart, dstPortEnd };
}
public String getDstIp() {
return dstIp;
}
public int[] getDstPortRange() {
return dstPortRange;
}
}

View File

@ -37,8 +37,10 @@ public class VolumeTO {
private StoragePoolType storagePoolType;
private long poolId;
private int deviceId;
private String chainInfo;
public VolumeTO(long id, Volume.VolumeType type, Storage.StorageResourceType resourceType, StoragePoolType poolType, String name, String mountPoint, String path, long size) {
public VolumeTO(long id, Volume.VolumeType type, Storage.StorageResourceType resourceType, StoragePoolType poolType,
String name, String mountPoint, String path, long size, String chainInfo) {
this.id = id;
this.name= name;
this.path = path;
@ -47,6 +49,7 @@ public class VolumeTO {
this.resourceType = resourceType;
this.storagePoolType = poolType;
this.mountPoint = mountPoint;
this.chainInfo = chainInfo;
}
public VolumeTO(Volume volume, StoragePool pool) {
@ -58,6 +61,7 @@ public class VolumeTO {
this.resourceType = volume.getStorageResourceType();
this.storagePoolType = pool.getPoolType();
this.mountPoint = volume.getFolder();
this.chainInfo = volume.getChainInfo();
}
@ -97,6 +101,10 @@ public class VolumeTO {
return storagePoolType;
}
public String getChainInfo() {
return chainInfo;
}
@Override
public String toString() {
return new StringBuilder("Vol[").append(id).append("|").append(type).append("|").append(path).append("|").append(size).append("]").toString();

View File

@ -170,6 +170,7 @@ public class ApiConstants {
public static final String MAX_CONNECTIONS = "maxconnections";
public static final String NETWORK_OFFERING_ID = "networkofferingid";
public static final String NETWORK_IDS = "networkids";
public static final String NETWORK_ID = "networkid";
public static final String SPECIFY_VLAN = "specifyvlan";
public static final String IS_DEFAULT = "isdefault";
}

View File

@ -37,7 +37,7 @@ public abstract class BaseAsyncCmd extends BaseCmd {
* used to determine that information.
* @return the id of the account that owns the object being acted upon
*/
public abstract long getAccountId();
public abstract long getEntityOwnerId();
/**
* For proper tracking of async commands through the system, events must be generated when the command is

View File

@ -6,13 +6,13 @@ public abstract class BaseAsyncCreateCmd extends BaseAsyncCmd {
@Parameter(name="id", type=CommandType.LONG)
private Long id;
public abstract void callCreate();
public abstract void create();
public Long getId() {
public Long getEntityId() {
return id;
}
public void setId(Long id) {
public void setEntityId(Long id) {
this.id = id;
}

View File

@ -35,6 +35,8 @@ import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.DomainRouterService;
import com.cloud.network.NetworkService;
import com.cloud.network.lb.LoadBalancingRulesService;
import com.cloud.network.rules.RulesService;
import com.cloud.network.security.NetworkGroupService;
import com.cloud.resource.ResourceService;
import com.cloud.server.ManagementService;
@ -76,7 +78,6 @@ public abstract class BaseCmd {
public static final int RESOURCE_IN_USE_ERROR = 536;
public static final int NETWORK_RULE_CONFLICT_ERROR = 537;
public static final DateFormat INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
private static final DateFormat _outputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
@ -100,9 +101,11 @@ public abstract class BaseCmd {
public static DomainRouterService _routerService;
public static ResponseGenerator _responseGenerator;
public static EntityManager _entityMgr;
public static RulesService _rulesService;
public static LoadBalancingRulesService _lbService;
static void setComponents(ResponseGenerator generator){
static void setComponents(ResponseGenerator generator) {
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
_mgr = (ManagementService)ComponentLocator.getComponent(ManagementService.Name);
_accountService = locator.getManager(AccountService.class);
@ -117,6 +120,8 @@ public abstract class BaseCmd {
_consoleProxyMgr = locator.getManager(ConsoleProxyService.class);
_routerService = locator.getManager(DomainRouterService.class);
_entityMgr = locator.getManager(EntityManager.class);
_rulesService = locator.getManager(RulesService.class);
_lbService = locator.getManager(LoadBalancingRulesService.class);
_responseGenerator = generator;
}
@ -366,7 +371,9 @@ public abstract class BaseCmd {
Object tagValue = tagData.second();
if (tagValue instanceof Object[]) {
Object[] subObjects = (Object[])tagValue;
if (subObjects.length < 1) continue;
if (subObjects.length < 1) {
continue;
}
writeObjectArray(responseType, suffixSb, i++, tagName, subObjects);
} else {
writeNameValuePair(suffixSb, tagName, tagValue, responseType, i++);
@ -395,7 +402,9 @@ public abstract class BaseCmd {
if (tagValue instanceof Object[]) {
Object[] subObjects = (Object[])tagValue;
if (subObjects.length < 1) return;
if (subObjects.length < 1) {
return;
}
writeObjectArray(responseType, sb, propertyCount, tagName, subObjects);
} else {
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
@ -461,24 +470,26 @@ public abstract class BaseCmd {
return xml;
}
int iLen = xml.length();
if (iLen == 0)
return xml;
if (iLen == 0) {
return xml;
}
StringBuffer sOUT = new StringBuffer(iLen + 256);
int i = 0;
for (; i < iLen; i++) {
char c = xml.charAt(i);
if (c == '<')
sOUT.append("&lt;");
else if (c == '>')
sOUT.append("&gt;");
else if (c == '&')
sOUT.append("&amp;");
else if (c == '"')
sOUT.append("&quot;");
else if (c == '\'')
sOUT.append("&apos;");
else
sOUT.append(c);
if (c == '<') {
sOUT.append("&lt;");
} else if (c == '>') {
sOUT.append("&gt;");
} else if (c == '&') {
sOUT.append("&amp;");
} else if (c == '"') {
sOUT.append("&quot;");
} else if (c == '\'') {
sOUT.append("&apos;");
} else {
sOUT.append(c);
}
}
return sOUT.toString();
}

View File

@ -70,12 +70,12 @@ import com.cloud.domain.Domain;
import com.cloud.event.Event;
import com.cloud.host.Host;
import com.cloud.network.IpAddress;
import com.cloud.network.LoadBalancer;
import com.cloud.network.Network;
import com.cloud.network.RemoteAccessVpn;
import com.cloud.network.VpnUser;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.network.security.IngressRule;
import com.cloud.network.security.NetworkGroup;
import com.cloud.network.security.NetworkGroupRules;
@ -142,9 +142,9 @@ public interface ResponseGenerator {
ClusterResponse createClusterResponse(Cluster cluster);
FirewallRuleResponse createFirewallRuleResponse(FirewallRule fwRule);
FirewallRuleResponse createFirewallRuleResponse(PortForwardingRule fwRule);
IpForwardingRuleResponse createIpForwardingRuleResponse(FirewallRule fwRule);
IpForwardingRuleResponse createIpForwardingRuleResponse(PortForwardingRule fwRule);
UserVmResponse createUserVm2Response(UserVm userVm);

View File

@ -93,7 +93,7 @@ public class AddVpnUserCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {
@ -113,7 +113,7 @@ public class AddVpnUserCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
return "Add Remote Access VPN user for account " + getAccountId() + " username= " + getUserName();
return "Add Remote Access VPN user for account " + getEntityOwnerId() + " username= " + getUserName();
}

View File

@ -17,6 +17,7 @@
*/
package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
@ -29,8 +30,8 @@ import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.network.LoadBalancer;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.user.Account;
@Implementation(description="Assigns virtual machine or a list of virtual machines to a load balancer rule.", responseObject=SuccessResponse.class)
@ -78,7 +79,7 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getLoadBalancerId());
if (lb == null) {
return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked
@ -98,16 +99,22 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
@Override
public void execute(){
try {
boolean result = _networkService.assignToLoadBalancer(this);
if (result) {
SuccessResponse response = new SuccessResponse(getName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to assign load balancer rule");
}
} catch (NetworkRuleConflictException ex) {
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
if (virtualMachineIds == null && virtualMachineId == null) {
throw new InvalidParameterValueException("Must specify virtual machine id");
}
if (virtualMachineIds == null) {
virtualMachineIds = new ArrayList<Long>();
}
if (virtualMachineId != null) {
virtualMachineIds.add(virtualMachineId);
}
boolean result = _lbService.assignToLoadBalancer(getLoadBalancerId(), virtualMachineIds);
if (result) {
SuccessResponse response = new SuccessResponse(getName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to assign load balancer rule");
}
}
}

View File

@ -71,7 +71,7 @@ public class AttachIsoCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate iso = _responseGenerator.findTemplateById(getId());
if (iso == null) {
return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked

View File

@ -96,7 +96,7 @@ public class AttachVolumeCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Volume volume = _responseGenerator.findVolumeById(getId());
if (volume == null) {
return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked

View File

@ -153,7 +153,7 @@ public class AuthorizeNetworkGroupIngressCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {

View File

@ -70,7 +70,7 @@ public class CancelMaintenanceCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -27,6 +27,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.StoragePoolResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.storage.StoragePool;
import com.cloud.user.Account;
@ -67,9 +68,17 @@ public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd {
public static String getResultObjectName() {
return "primarystorage";
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Host;
}
public Long getInstanceId() {
return getId();
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -81,7 +81,7 @@ public class CopyIsoCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate iso = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (iso != null) {
return iso.getAccountId();

View File

@ -82,7 +82,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (template != null) {
return template.getAccountId();

View File

@ -24,6 +24,7 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.DiskOfferingResponse;
import com.cloud.offering.DiskOffering;
@ -51,6 +52,10 @@ public class CreateDiskOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.CUSTOMIZED, type=CommandType.BOOLEAN, description="whether disk offering is custom or not")
private Boolean customized;
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public offerings")
private Long domainId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -75,6 +80,9 @@ public class CreateDiskOfferingCmd extends BaseCmd {
return customized;
}
public Long getDomainId(){
return domainId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -28,11 +28,14 @@ import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.FirewallRuleResponse;
import com.cloud.event.EventTypes;
import com.cloud.network.rules.FirewallRule;
import com.cloud.user.Account;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.user.UserContext;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
@Implementation(description="Creates an ip forwarding rule", responseObject=FirewallRuleResponse.class)
public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd {
public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements PortForwardingRule {
public static final Logger s_logger = Logger.getLogger(CreateIpForwardingRuleCmd.class.getName());
private static final String s_name = "createipforwardingruleresponse";
@ -72,9 +75,17 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd {
@Override
public void execute(){
FirewallRule result = _networkService.createIpForwardingRuleOnDomr(this.getId());
if (result != null) {
FirewallRuleResponse fwResponse = _responseGenerator.createFirewallRuleResponse(result);
boolean result;
try {
result = _rulesService.applyPortForwardingRules(new Ip(ipAddress), UserContext.current().getAccount());
} catch (Exception e) {
s_logger.error("Unable to apply port forwarding rules", e);
_rulesService.revokePortForwardingRule(getEntityId(), true);
result = false;
}
if (result) {
PortForwardingRule rule = _entityMgr.findById(PortForwardingRule.class, getEntityId());
FirewallRuleResponse fwResponse = _responseGenerator.createFirewallRuleResponse(rule);
fwResponse.setResponseName(getName());
this.setResponseObject(fwResponse);
} else {
@ -84,18 +95,21 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd {
}
@Override
public void callCreate(){
FirewallRule rule = _networkService.createIpForwardingRuleInDb(ipAddress,virtualMachineId);
if (rule != null){
this.setId(rule.getId());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create ip forwarding rule");
public void create() {
PortForwardingRule rule;
try {
rule = _rulesService.createPortForwardingRule(this, virtualMachineId);
} catch (NetworkRuleConflictException e) {
s_logger.info("Unable to create Port Forwarding Rule due to " + e.getMessage());
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
}
this.setEntityId(rule.getId());
}
@Override
public long getAccountId() {
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
public long getEntityOwnerId() {
return _entityMgr.findById(PortForwardingRule.class, getEntityId()).getAccountId();
}
@Override
@ -108,4 +122,74 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd {
return ("Creating an ipforwarding 1:1 NAT rule for "+ipAddress+" with virtual machine:"+virtualMachineId);
}
@Override
public long getId() {
throw new UnsupportedOperationException("Don't call me");
}
@Override
public String getXid() {
return null;
}
@Override
public Ip getSourceIpAddress() {
return new Ip(ipAddress);
}
@Override
public int getSourcePortStart() {
return -1;
}
@Override
public int getSourcePortEnd() {
return -1;
}
@Override
public String getProtocol() {
return NetUtils.NAT_PROTO;
}
@Override
public Purpose getPurpose() {
return Purpose.PortForwarding;
}
@Override
public State getState() {
throw new UnsupportedOperationException("Don't call me");
}
@Override
public long getNetworkId() {
return -1;
}
@Override
public long getDomainId() {
throw new UnsupportedOperationException("Don't call me");
}
@Override
public Ip getDestinationIpAddress() {
return null;
}
@Override
public int getDestinationPortStart() {
return -1;
}
@Override
public int getDestinationPortEnd() {
return -1;
}
@Override
public long getAccountId() {
throw new UnsupportedOperationException("Get the account id from network");
}
}

View File

@ -18,18 +18,25 @@
package com.cloud.api.commands;
import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCreateCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.LoadBalancerResponse;
import com.cloud.network.LoadBalancer;
import com.cloud.event.EventTypes;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
@Implementation(description="Creates a load balancer rule", responseObject=LoadBalancerResponse.class)
public class CreateLoadBalancerRuleCmd extends BaseCmd {
public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd implements LoadBalancer {
public static final Logger s_logger = Logger.getLogger(CreateLoadBalancerRuleCmd.class.getName());
private static final String s_name = "createloadbalancerruleresponse";
@ -61,10 +68,12 @@ public class CreateLoadBalancerRuleCmd extends BaseCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@Override
public String getAlgorithm() {
return algorithm;
}
@Override
public String getDescription() {
return description;
}
@ -96,14 +105,107 @@ public class CreateLoadBalancerRuleCmd extends BaseCmd {
}
@Override
public void execute(){
LoadBalancer result = _networkService.createLoadBalancerRule(this);
if (result != null) {
LoadBalancerResponse response = _responseGenerator.createLoadBalancerResponse(result);
response.setResponseName(getName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create load balancer rule");
public void execute() {
LoadBalancer result = null;
try {
result = _lbService.createLoadBalancerRule(this);
} catch (NetworkRuleConflictException e) {
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
}
LoadBalancerResponse response = _responseGenerator.createLoadBalancerResponse(result);
response.setResponseName(getName());
this.setResponseObject(response);
}
@Override
public long getId() {
throw new UnsupportedOperationException("not supported");
}
@Override
public String getXid() {
// FIXME: Should fix this.
return null;
}
@Override
public Ip getSourceIpAddress() {
return new Ip(publicIp);
}
@Override
public int getSourcePortStart() {
return Integer.parseInt(publicPort);
}
@Override
public int getSourcePortEnd() {
return Integer.parseInt(publicPort);
}
@Override
public String getProtocol() {
return NetUtils.TCP_PROTO;
}
@Override
public Purpose getPurpose() {
return Purpose.LoadBalancing;
}
@Override
public State getState() {
throw new UnsupportedOperationException("not supported");
}
@Override
public long getNetworkId() {
return -1;
}
@Override
public long getAccountId() {
throw new UnsupportedOperationException("not supported");
}
@Override
public long getDomainId() {
throw new UnsupportedOperationException("not supported");
}
@Override
public int getDefaultPortStart() {
return Integer.parseInt(privatePort);
}
@Override
public int getDefaultPortEnd() {
return Integer.parseInt(privatePort);
}
@Override
public List<? extends Destination> getDestinations() {
throw new UnsupportedOperationException("not supported");
}
@Override
public void create() {
// TODO Auto-generated method stub
}
@Override
public long getEntityOwnerId() {
return _entityMgr.findById(LoadBalancer.class, getEntityId()).getAccountId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_LOAD_BALANCER_CREATE;
}
@Override
public String getEventDescription() {
return "Create load balancer";
}
}

View File

@ -76,6 +76,9 @@ public class CreateNetworkCmd extends BaseCmd {
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a VLAN")
private Long domainId;
@Parameter(name=ApiConstants.IS_SHARED, type=CommandType.BOOLEAN, description="true is network offering supports vlans")
private Boolean isShared;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -131,6 +134,10 @@ public class CreateNetworkCmd extends BaseCmd {
public String getDisplayText() {
return displayText;
}
public boolean getIsShared() {
return isShared == null ? false : isShared;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -57,9 +57,6 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.SPECIFY_VLAN, type=CommandType.BOOLEAN, description="true is network offering supports vlans")
private Boolean specifyVlan;
@Parameter(name=ApiConstants.IS_SHARED, type=CommandType.BOOLEAN, description="true is network offering supports vlans")
private Boolean isShared;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -92,10 +89,6 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
public Boolean getSpecifyVlan() {
return specifyVlan;
}
public Boolean getIsShared() {
return isShared;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -21,16 +21,21 @@ package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCreateCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.FirewallRuleResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.network.rules.FirewallRule;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.user.UserContext;
import com.cloud.utils.net.Ip;
@Implementation(description="Creates a port forwarding rule", responseObject=FirewallRuleResponse.class)
public class CreatePortForwardingRuleCmd extends BaseCmd {
public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements PortForwardingRule {
public static final Logger s_logger = Logger.getLogger(CreatePortForwardingRuleCmd.class.getName());
private static final String s_name = "createportforwardingruleresponse";
@ -67,6 +72,7 @@ public class CreatePortForwardingRuleCmd extends BaseCmd {
return privatePort;
}
@Override
public String getProtocol() {
return protocol;
}
@ -90,19 +96,120 @@ public class CreatePortForwardingRuleCmd extends BaseCmd {
}
@Override
public void execute(){
public void execute() throws ResourceUnavailableException {
try {
FirewallRule result = _networkService.createPortForwardingRule(this);
if (result != null) {
FirewallRuleResponse fwResponse = _responseGenerator.createFirewallRuleResponse(result);
fwResponse.setResponseName(getName());
this.setResponseObject(fwResponse);
} else {
UserContext callerContext = UserContext.current();
PortForwardingRule result = _rulesService.createPortForwardingRule(this, virtualMachineId);
if (result == null) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "An existing rule for ipAddress / port / protocol of " + ipAddress + " / " + publicPort + " / " + protocol + " exits.");
}
boolean success = false;
try {
success = _rulesService.applyPortForwardingRules(result.getSourceIpAddress(), callerContext.getAccount());
} finally {
if (!success) {
_rulesService.revokePortForwardingRule(result.getId(), true);
}
}
FirewallRuleResponse fwResponse = _responseGenerator.createFirewallRuleResponse(result);
fwResponse.setResponseName(getName());
setResponseObject(fwResponse);
} catch (NetworkRuleConflictException ex) {
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
}
}
@Override
public long getId() {
throw new UnsupportedOperationException("database id can only provided by VO objects");
}
@Override
public String getXid() {
// FIXME: We should allow for end user to specify Xid.
return null;
}
@Override
public Ip getSourceIpAddress() {
return new Ip(ipAddress);
}
@Override
public int getSourcePortStart() {
return Integer.parseInt(publicPort);
}
@Override
public int getSourcePortEnd() {
return Integer.parseInt(publicPort);
}
@Override
public Purpose getPurpose() {
return Purpose.PortForwarding;
}
@Override
public State getState() {
throw new UnsupportedOperationException("Should never call me to find the state");
}
@Override
public long getNetworkId() {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public long getEntityOwnerId() {
return _entityMgr.findById(PortForwardingRule.class, getEntityId()).getAccountId();
}
@Override
public long getDomainId() {
throw new UnsupportedOperationException("Get the domain id from network");
}
@Override
public Ip getDestinationIpAddress() {
return null;
}
@Override
public int getDestinationPortStart() {
return Integer.parseInt(privatePort);
}
@Override
public int getDestinationPortEnd() {
return Integer.parseInt(privatePort);
}
@Override
public void create() {
try {
PortForwardingRule result = _rulesService.createPortForwardingRule(this, virtualMachineId);
setEntityId(result.getId());
} catch (NetworkRuleConflictException ex) {
s_logger.info("Network rule conflict: " + ex.getMessage());
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_NET_RULE_ADD;
}
@Override
public String getEventDescription() {
return ("Creating an port forwarding rule for "+ipAddress+" with virtual machine:"+virtualMachineId);
}
@Override
public long getAccountId() {
throw new UnsupportedOperationException("Get the account id from network");
}
}

View File

@ -105,7 +105,7 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {
@ -125,7 +125,7 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
@Override
public String getEventDescription() {
return "Create Remote Access VPN for account " + getAccountId() + " in zone " + getZoneId();
return "Create Remote Access VPN for account " + getEntityOwnerId() + " in zone " + getZoneId();
}
@Override
@ -134,11 +134,11 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
}
@Override
public void callCreate(){
public void create(){
try {
RemoteAccessVpn vpn = _networkService.createRemoteAccessVpn(this);
if (vpn != null) {
this.setId(vpn.getId());
this.setEntityId(vpn.getId());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create remote access vpn");
}

View File

@ -26,7 +26,6 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.SnapshotResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
@ -94,7 +93,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
if (volume != null) {
return volume.getAccountId();
@ -114,14 +113,15 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
return "creating snapshot for volume: " + getVolumeId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Snapshot;
}
@Override
public void callCreate(){
public void create(){
long id = _snapshotMgr.getNextInSequence(this);
this.setId(id);
this.setEntityId(id);
}
@Override

View File

@ -134,7 +134,7 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Long volumeId = getVolumeId();
Long snapshotId = getSnapshotId();
if (volumeId != null) {
@ -168,10 +168,10 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd {
}
@Override
public void callCreate(){
public void create(){
VirtualMachineTemplate template = _userVmService.createPrivateTemplateRecord(this);
if (template != null){
this.setId(template.getId());
this.setEntityId(template.getId());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a template");
}

View File

@ -115,7 +115,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {
@ -144,11 +144,11 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
}
@Override
public void callCreate(){
public void create(){
try {
Volume volume = _storageMgr.allocVolume(this);
if (volume != null) {
this.setId(volume.getId());
this.setEntityId(volume.getId());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create volume");
}

View File

@ -68,7 +68,7 @@ public class DeleteDomainCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Domain domain = _entityMgr.findById(Domain.class, getId());
if (domain != null) {
return domain.getAccountId();

View File

@ -28,6 +28,7 @@ import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.event.EventTypes;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.user.Account;
@Implementation(description="Deletes an ip forwarding rule", responseObject=SuccessResponse.class)
@ -62,9 +63,8 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd {
@Override
public void execute(){
boolean result = false;
result = _networkService.deleteIpForwardingRule(id);
if (result) {
PortForwardingRule rule = _rulesService.revokePortForwardingRule(id, true);
if (rule != null) {
SuccessResponse response = new SuccessResponse(getName());
this.setResponseObject(response);
} else {
@ -73,7 +73,7 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
}

View File

@ -73,7 +73,7 @@ public class DeleteIsoCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate iso = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (iso != null) {
return iso.getAccountId();

View File

@ -27,7 +27,7 @@ import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.event.EventTypes;
import com.cloud.network.LoadBalancer;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.user.Account;
@Implementation(description="Deletes a load balancer rule.", responseObject=SuccessResponse.class)
@ -60,7 +60,7 @@ public class DeleteLoadBalancerRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getId());
if (lb != null) {
return lb.getAccountId();
@ -81,7 +81,7 @@ public class DeleteLoadBalancerRuleCmd extends BaseAsyncCmd {
@Override
public void execute(){
boolean result = _networkService.deleteLoadBalancerRule(this);
boolean result = _lbService.deleteLoadBalancerRule(id, true);
if (result) {
SuccessResponse response = new SuccessResponse(getName());
this.setResponseObject(response);

View File

@ -25,6 +25,8 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.rules.PortForwardingRule;
@Implementation(description="Deletes a port forwarding rule", responseObject=SuccessResponse.class)
public class DeletePortForwardingRuleCmd extends BaseCmd {
@ -57,9 +59,9 @@ public class DeletePortForwardingRuleCmd extends BaseCmd {
}
@Override
public void execute(){
boolean result = _networkService.deletePortForwardingRule(id,false);
if (result) {
public void execute() throws ResourceUnavailableException {
PortForwardingRule result = _rulesService.revokePortForwardingRule(id, true);
if (result != null) {
SuccessResponse response = new SuccessResponse(getName());
this.setResponseObject(response);
} else {

View File

@ -79,7 +79,7 @@ public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {
@ -99,7 +99,7 @@ public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
return "Delete Remote Access VPN for account " + getAccountId() + " in zone " + getZoneId();
return "Delete Remote Access VPN for account " + getEntityOwnerId() + " in zone " + getZoneId();
}
@Override

View File

@ -63,7 +63,7 @@ public class DeleteSnapshotCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Snapshot snapshot = _entityMgr.findById(Snapshot.class, getId());
if (snapshot != null) {
return snapshot.getAccountId();

View File

@ -75,7 +75,7 @@ public class DeleteTemplateCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (template != null) {
return template.getAccountId();

View File

@ -68,7 +68,7 @@ public class DeleteUserCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -23,7 +23,7 @@ import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.BaseAsyncCreateCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@ -31,16 +31,15 @@ import com.cloud.api.ServerApiException;
import com.cloud.api.response.UserVmResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.InsufficientStorageCapacityException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.uservm.UserVm;
@Implementation(description="Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject=UserVmResponse.class)
public class DeployVMCmd extends BaseAsyncCmd {
public class DeployVMCmd extends BaseAsyncCreateCmd {
public static final Logger s_logger = Logger.getLogger(DeployVMCmd.class.getName());
private static final String s_name = "deployvirtualmachineresponse";
@ -175,7 +174,7 @@ public class DeployVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {
@ -203,41 +202,52 @@ public class DeployVMCmd extends BaseAsyncCmd {
return "deploying Vm";
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.VirtualMachine;
}
@Override
public void execute(){
UserVm result;
try {
String password = null;
if (templateId != null ) {
VirtualMachineTemplate template = _responseGenerator.findTemplateById(templateId);
if (template.getEnablePassword()) {
password = _mgr.generateRandomPassword();
}
}
UserVm result = _mgr.deployVirtualMachine(this, password);
if (result != null){
UserVmResponse response = _responseGenerator.createUserVmResponse(result);
result = _userVmService.startVirtualMachine(this);
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVm2Response(result);
response.setPassword(password);
response.setResponseName(getName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
}
} catch (ResourceAllocationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
} catch (InsufficientStorageCapacityException ex) {
s_logger.warn("Exception: ", ex);
} catch (ResourceUnavailableException ex) {
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException ex) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
} catch (InsufficientCapacityException ex) {
throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
} catch (StorageUnavailableException ex) {
}
}
@Override
public void create() {
try {
UserVm result = _userVmService.createVirtualMachine(this);
if (result != null){
setEntityId(result.getId());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
}
} catch (InsufficientCapacityException ex) {
s_logger.info(ex);
s_logger.trace(ex);
throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (Exception ex) {
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
}
}
}
}

View File

@ -1,232 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.commands;
import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCreateCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.UserVmResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.uservm.UserVm;
@Implementation(description="Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject=UserVmResponse.class)
public class DeployVm2Cmd extends BaseAsyncCreateCmd {
public static final Logger s_logger = Logger.getLogger(DeployVMCmd.class.getName());
private static final String s_name = "deployvirtualmachineresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for the virtual machine. Must be used with domainId.")
private String accountName;
@Parameter(name=ApiConstants.DISK_OFFERING_ID, type=CommandType.LONG, description="the ID of the disk offering for the virtual machine. If the template is of ISO format, the diskOfferingId is for the root disk volume. Otherwise this parameter is used to dinidcate the offering for the data disk volume. If the templateId parameter passed is from a Template object, the diskOfferingId refers to a DATA Disk Volume created. If the templateId parameter passed is from an ISO object, the diskOfferingId refers to a ROOT Disk Volume created.")
private Long diskOfferingId;
@Parameter(name=ApiConstants.DISPLAY_NAME, type=CommandType.STRING, description="an optional user generated name for the virtual machine")
private String displayName;
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for the virtual machine. If the account parameter is used, domainId must also be used.")
private Long domainId;
@Parameter(name=ApiConstants.GROUP, type=CommandType.STRING, description="an optional group for the virtual machine")
private String group;
@Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="the hypervisor on which to deploy the virtual machine")
private String hypervisor;
@Parameter(name=ApiConstants.NETWORK_GROUP_LIST, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma separated list of network groups that going to be applied to the virtual machine. Should be passed only when vm is created from service offering with Direct Attach Network support")
private List<String> networkGroupList;
@Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.LONG, required=true, description="the ID of the service offering for the virtual machine")
private Long serviceOfferingId;
@Parameter(name=ApiConstants.SIZE, type=CommandType.LONG, description="the arbitrary size for the DATADISK volume. Mutually exclusive with diskOfferingId")
private Long size;
@Parameter(name=ApiConstants.TEMPLATE_ID, type=CommandType.LONG, required=true, description="the ID of the template for the virtual machine")
private Long templateId;
@Parameter(name=ApiConstants.USER_DATA, type=CommandType.STRING, description="an optional binary data that can be sent to the virtual machine upon a successful deployment. This binary data must be base64 encoded before adding it to the request. Currently only HTTP GET is supported. Using HTTP GET (via querystring), you can send up to 2KB of data after base64 encoding.")
private String userData;
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="availability zone for the virtual machine")
private Long zoneId;
// unexposed parameter needed for serializing/deserializing the command
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, expose=false)
private String password;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getAccountName() {
return accountName;
}
public Long getDiskOfferingId() {
return diskOfferingId;
}
public String getDisplayName() {
return displayName;
}
public Long getDomainId() {
return domainId;
}
public String getGroup() {
return group;
}
public String getHypervisor() {
return hypervisor;
}
public List<String> getNetworkGroupList() {
return networkGroupList;
}
public Long getServiceOfferingId() {
return serviceOfferingId;
}
public Long getSize() {
return size;
}
public Long getTemplateId() {
return templateId;
}
public String getUserData() {
return userData;
}
public Long getZoneId() {
return zoneId;
}
// not exposed parameter
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute(){
UserVm result;
try {
result = _userVmService.startVirtualMachine(this);
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVm2Response(result);
response.setPassword(password);
response.setResponseName(getName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
}
} catch (ResourceUnavailableException ex) {
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException ex) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
} catch (InsufficientCapacityException ex) {
throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
}
}
@Override
public void callCreate() {
// try {
// UserVm vm = _userVmService.createVirtualMachine(this);
// if (vm != null) {
// this.setId(vm.getId());
// } else {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
// }
// } catch (ResourceUnavailableException ex) {
// throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
// } catch (ConcurrentOperationException ex) {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
// } catch (InsufficientCapacityException ex) {
// throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
// }
}
@Override
public String getName() {
return s_name;
}
public static String getResultObjectName() {
return "virtualmachine";
}
@Override
public long getAccountId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
if (userAccount != null) {
return userAccount.getId();
}
}
}
if (account != null) {
return account.getId();
}
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
}
@Override
public String getEventType() {
return EventTypes.EVENT_VM_CREATE;
}
@Override
public String getEventDescription() {
return "deploying Vm";
}
}

View File

@ -64,7 +64,7 @@ public class DestroyConsoleProxyCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = (Account)UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -64,7 +64,7 @@ public class DestroyVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -61,7 +61,7 @@ public class DetachIsoCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _entityMgr.findById(UserVm.class, getVirtualMachineId());
if (vm != null) {
return vm.getAccountId();

View File

@ -88,7 +88,7 @@ public class DetachVolumeCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Long volumeId = getId();
if (volumeId != null) {
Volume volume = _responseGenerator.findVolumeById(volumeId);

View File

@ -72,7 +72,7 @@ public class DisableAccountCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -66,7 +66,7 @@ public class DisableUserCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -88,7 +88,7 @@ public class ExtractIsoCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate iso = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (iso != null) {
return iso.getAccountId();
@ -120,7 +120,7 @@ public class ExtractIsoCmd extends BaseAsyncCmd {
try {
Long uploadId = _templateService.extract(this);
if (uploadId != null){
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getAccountId(), mode);
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
response.setResponseName(getName());
response.setObjectName("iso");
this.setResponseObject(response);

View File

@ -88,7 +88,7 @@ public class ExtractTemplateCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (template != null) {
return template.getAccountId();
@ -121,7 +121,7 @@ public class ExtractTemplateCmd extends BaseAsyncCmd {
try {
Long uploadId = _templateService.extract(this);
if (uploadId != null){
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getAccountId(), mode);
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
response.setResponseName(getName());
this.setResponseObject(response);
} else {

View File

@ -102,7 +102,7 @@ public class ExtractVolumeCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Volume volume = _entityMgr.findById(Volume.class, getId());
if (volume != null) {
return volume.getAccountId();
@ -138,7 +138,7 @@ public class ExtractVolumeCmd extends BaseAsyncCmd {
response.setMode(mode);
response.setUploadId(uploadId);
response.setState(uploadInfo.getUploadState().toString());
response.setAccountId(getAccountId());
response.setAccountId(getEntityOwnerId());
//FIX ME - Need to set the url once the gson jar is upgraded since it is throwing an error right now.
response.setUrl(uploadInfo.getUploadUrl().replaceAll("/", "%2F"));
this.setResponseObject(response);

View File

@ -30,7 +30,8 @@ import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.FirewallRuleResponse;
import com.cloud.api.response.IpForwardingRuleResponse;
import com.cloud.api.response.ListResponse;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.utils.net.Ip;
@Implementation(description="List the ip forwarding rules", responseObject=FirewallRuleResponse.class)
public class ListIpForwardingRulesCmd extends BaseListCmd {
@ -82,10 +83,10 @@ public class ListIpForwardingRulesCmd extends BaseListCmd {
@Override
public void execute(){
List<? extends FirewallRule> result = _mgr.searchForIpForwardingRules(this);
List<? extends PortForwardingRule> result = _rulesService.searchForIpForwardingRules(new Ip(publicIpAddress), this.getStartIndex(), this.getPageSizeVal());
ListResponse<IpForwardingRuleResponse> response = new ListResponse<IpForwardingRuleResponse>();
List<IpForwardingRuleResponse> ipForwardingResponses = new ArrayList<IpForwardingRuleResponse>();
for (FirewallRule rule : result) {
for (PortForwardingRule rule : result) {
IpForwardingRuleResponse resp = _responseGenerator.createIpForwardingRuleResponse(rule);
if (resp != null) {
ipForwardingResponses.add(resp);

View File

@ -69,7 +69,7 @@ public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd {
@Override
public void execute(){
List<? extends UserVm> result = _mgr.listLoadBalancerInstances(this);
List<? extends UserVm> result = _lbService.listLoadBalancerInstances(this);
ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
for (UserVm instance : result) {

View File

@ -29,7 +29,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.LoadBalancerResponse;
import com.cloud.network.LoadBalancer;
import com.cloud.network.rules.LoadBalancer;
@Implementation(description="Lists load balancer rules.", responseObject=LoadBalancerResponse.class)
public class ListLoadBalancerRulesCmd extends BaseListCmd {
@ -98,7 +98,7 @@ public class ListLoadBalancerRulesCmd extends BaseListCmd {
@Override
public void execute(){
List<? extends LoadBalancer> loadBalancers = _mgr.searchForLoadBalancers(this);
List<? extends LoadBalancer> loadBalancers = _lbService.searchForLoadBalancers(this);
ListResponse<LoadBalancerResponse> response = new ListResponse<LoadBalancerResponse>();
List<LoadBalancerResponse> lbResponses = new ArrayList<LoadBalancerResponse>();
for (LoadBalancer loadBalancer : loadBalancers) {

View File

@ -27,6 +27,7 @@ import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.NetworkResponse;
import com.cloud.network.Network;
@ -48,6 +49,9 @@ public class ListNetworksCmd extends BaseListCmd {
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a VLAN")
private Long domainId;
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the Zone ID of the network")
private Long zoneId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -64,6 +68,11 @@ public class ListNetworksCmd extends BaseListCmd {
public Long getDomainId() {
return domainId;
}
public Long getZoneId() {
return zoneId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -28,7 +28,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.FirewallRuleResponse;
import com.cloud.api.response.ListResponse;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.PortForwardingRule;
@Implementation(description="Lists all port forwarding rules for an IP address.", responseObject=FirewallRuleResponse.class)
public class ListPortForwardingRulesCmd extends BaseListCmd {
@ -62,11 +62,11 @@ public class ListPortForwardingRulesCmd extends BaseListCmd {
@Override
public void execute(){
List<? extends FirewallRule> result = _networkService.listPortForwardingRules(this);
List<? extends PortForwardingRule> result = _rulesService.listPortForwardingRules(this);
ListResponse<FirewallRuleResponse> response = new ListResponse<FirewallRuleResponse>();
List<FirewallRuleResponse> fwResponses = new ArrayList<FirewallRuleResponse>();
for (FirewallRule fwRule : result) {
for (PortForwardingRule fwRule : result) {
FirewallRuleResponse ruleData = _responseGenerator.createFirewallRuleResponse(fwRule);
ruleData.setObjectName("portforwardingrule");
fwResponses.add(ruleData);

View File

@ -29,6 +29,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.StoragePoolResponse;
import com.cloud.async.AsyncJob;
import com.cloud.storage.StoragePool;
@Implementation(description="Lists storage pools.", responseObject=StoragePoolResponse.class)
@ -94,6 +95,10 @@ public class ListStoragePoolsCmd extends BaseListCmd {
@Override
public String getName() {
return s_name;
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Host;
}
@Override

View File

@ -70,6 +70,9 @@ public class ListVMsCmd extends BaseListCmd {
@Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="list by network type; true if need to list vms using Virtual Network, false otherwise")
private Boolean forVirtualNetwork;
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="list by network id")
private Long networkId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -118,6 +121,10 @@ public class ListVMsCmd extends BaseListCmd {
public void setForVirtualNetwork(Boolean forVirtualNetwork) {
this.forVirtualNetwork = forVirtualNetwork;
}
public Long getNetworkId() {
return networkId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -67,7 +67,7 @@ public class PrepareForMaintenanceCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -26,6 +26,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.StoragePoolResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.storage.StoragePool;
import com.cloud.user.Account;
@ -63,9 +64,17 @@ public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd {
public static String getResultObjectName() {
return "primarystorage";
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Host;
}
public Long getInstanceId() {
return getId();
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -62,7 +62,7 @@ public class RebootRouterCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualRouter router = _entityMgr.findById(VirtualRouter.class, getId());
if (router != null) {
return router.getAccountId();

View File

@ -64,7 +64,7 @@ public class RebootSystemVmCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -61,7 +61,7 @@ public class RebootVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -69,7 +69,7 @@ public class ReconnectHostCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -30,7 +30,8 @@ import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.event.EventTypes;
import com.cloud.network.LoadBalancer;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.user.Account;
import com.cloud.utils.StringUtils;
@ -79,7 +80,7 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getId());
if (lb == null) {
return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked
@ -105,7 +106,18 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
@Override
public void execute(){
boolean result = _networkService.removeFromLoadBalancer(this);
if (virtualMachineIds == null && virtualMachineId == null) {
throw new InvalidParameterValueException("Must specify virtual machine id");
}
if (virtualMachineIds == null) {
virtualMachineIds = new ArrayList<Long>();
}
if (virtualMachineId != null) {
virtualMachineIds.add(virtualMachineId);
}
boolean result = _lbService.removeFromLoadBalancer(id, virtualMachineIds);
if (result) {
SuccessResponse response = new SuccessResponse(getName());
this.setResponseObject(response);

View File

@ -81,7 +81,7 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {
@ -101,7 +101,7 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
return "Remove Remote Access VPN user for account " + getAccountId() + " username= " + getUserName();
return "Remove Remote Access VPN user for account " + getEntityOwnerId() + " username= " + getUserName();
}

View File

@ -78,7 +78,7 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -127,7 +127,7 @@ public class RevokeNetworkGroupIngressCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {

View File

@ -72,7 +72,7 @@ public class StartRouterCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _entityMgr.findById(UserVm.class, getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -68,7 +68,7 @@ public class StartSystemVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -71,7 +71,7 @@ public class StartVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -66,7 +66,7 @@ public class StopRouterCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _entityMgr.findById(UserVm.class, getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -64,7 +64,7 @@ public class StopSystemVmCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -67,7 +67,7 @@ public class StopVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -27,7 +27,7 @@ import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.LoadBalancerResponse;
import com.cloud.event.EventTypes;
import com.cloud.network.LoadBalancer;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.user.Account;
@Implementation(description="Updates load balancer", responseObject=LoadBalancerResponse.class)
@ -88,7 +88,7 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getId());
if (lb == null) {
return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked
@ -108,7 +108,7 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd {
@Override
public void execute(){
LoadBalancer result = _networkService.updateLoadBalancerRule(this);
LoadBalancer result = _lbService.updateLoadBalancerRule(this);
if (result != null){
LoadBalancerResponse response = _responseGenerator.createLoadBalancerResponse(result);
response.setResponseName(getName());

View File

@ -4,14 +4,11 @@ import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.FirewallRuleResponse;
import com.cloud.event.EventTypes;
import com.cloud.network.IpAddress;
import com.cloud.network.rules.FirewallRule;
import com.cloud.user.Account;
@Implementation(responseObject=FirewallRuleResponse.class, description="Updates a port forwarding rule. Only the private port and the virtual machine can be updated.")
@ -79,10 +76,10 @@ public class UpdatePortForwardingRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
IpAddress addr = _entityMgr.findById(IpAddress.class, getPublicIp());
if (addr != null) {
return addr.getAccountId();
return addr.getAllocatedToAccountId();
}
// bad address given, parent this command to SYSTEM so ERROR events are tracked
@ -101,13 +98,13 @@ public class UpdatePortForwardingRuleCmd extends BaseAsyncCmd {
@Override
public void execute(){
FirewallRule result = _mgr.updatePortForwardingRule(this);
if (result != null) {
FirewallRuleResponse response = _responseGenerator.createFirewallRuleResponse(result);
response.setResponseName(getName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update port forwarding rule");
}
//FIXME: PortForwardingRule result = _mgr.updatePortForwardingRule(this);
// if (result != null) {
// FirewallRuleResponse response = _responseGenerator.createFirewallRuleResponse(result);
// response.setResponseName(getName());
// this.setResponseObject(response);
// } else {
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update port forwarding rule");
// }
}
}

View File

@ -62,7 +62,7 @@ public class UploadCustomCertificateCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
}

View File

@ -32,10 +32,7 @@ public class NetworkOfferingResponse extends BaseResponse{
@SerializedName("isdefault") @Param(description="true if network offering is default, false otherwise")
private Boolean isDefault;
@SerializedName("isshared") @Param(description="true if network offering is shared, false otherwise")
private Boolean isShared;
@SerializedName("specifyvlan") @Param(description="true if network offering supports vlans, false otherwise")
private Boolean specifyVlan;
@ -126,12 +123,4 @@ public class NetworkOfferingResponse extends BaseResponse{
public void setSpecifyVlan(Boolean specifyVlan) {
this.specifyVlan = specifyVlan;
}
public Boolean getIsShared() {
return isShared;
}
public void setIsShared(Boolean isShared) {
this.isShared = isShared;
}
}

View File

@ -47,6 +47,13 @@ public class NetworkResponse extends BaseResponse{
@SerializedName("networkofferingdisplaytext")
private String networkOfferingDisplayText;
//TODO - add description
@SerializedName("isshared")
private Boolean isShared;
@SerializedName("isdefault") @Param(description="true if network offering is default, false otherwise")
private Boolean isDefault;
//TODO - add description
@SerializedName("state")
private String state;
@ -228,4 +235,12 @@ public class NetworkResponse extends BaseResponse{
public void setDisplaytext(String displaytext) {
this.displaytext = displaytext;
}
public Boolean getIsShared() {
return isShared;
}
public void setIsShared(Boolean isShared) {
this.isShared = isShared;
}
}

View File

@ -57,7 +57,7 @@ public class ServiceOfferingResponse extends BaseResponse {
@SerializedName("tags") @Param(description="the tags for the service offering")
private String tags;
@SerializedName("domainId") @Param(description="the domain id of the service offering")
@SerializedName("domainid") @Param(description="the domain id of the service offering")
private Long domainId;
@SerializedName(ApiConstants.DOMAIN) @Param(description="Domain name for the offering")

View File

@ -39,5 +39,7 @@ public interface Capacity {
public long getTotalCapacity();
public short getCapacityType();
long getReservedCapacity();
}

View File

@ -121,5 +121,32 @@ public interface DeploymentPlanner extends Adapter {
return false;
}
public boolean shouldAvoid(Cluster cluster) {
if (_dcIds != null && _dcIds.contains(cluster.getDataCenterId())) {
return true;
}
if (_podIds != null && _podIds.contains(cluster.getPodId())) {
return true;
}
if (_clusterIds != null && _clusterIds.contains(cluster.getId())) {
return true;
}
return false;
}
public boolean shouldAvoid(Pod pod) {
if (_dcIds != null && _dcIds.contains(pod.getDataCenterId())) {
return true;
}
if (_podIds != null && _podIds.contains(pod.getId())) {
return true;
}
return false;
}
}
}

View File

@ -19,30 +19,48 @@ package com.cloud.network;
import java.util.Date;
public interface IpAddress {
import com.cloud.acl.ControlledEntity;
/**
* IpAddress represents the public ip address to be allocated in the CloudStack.
*
* When it is not allocated, it should have
* - State = Free
* - Allocated = null
* - AccountId = null
* - DomainId = null
*
* When it is allocated, it should have
* - State = Allocated
* - AccountId = account owner.
* - DomainId = domain of the account owner.
* - Allocated = time it was allocated.
*/
public interface IpAddress extends ControlledEntity {
enum State {
Allocating, // The IP Address is being propagated to other network elements and is not ready for use yet.
Allocated, // The IP address is in used.
Releasing, // The IP address is being released for other network elements and is not ready for allocation.
Free // The IP address is ready to be allocated.
}
long getDataCenterId();
String getAddress();
Long getAccountId();
Long getDomainId();
Date getAllocated();
Long getAllocatedToAccountId();
Long getAllocatedInDomainId();
Date getAllocatedTime();
boolean isSourceNat();
void setAccountId(Long accountId);
void setDomainId(Long domainId);
void setSourceNat(boolean sourceNat);
boolean getSourceNat();
void setAllocated(Date allocated);
long getVlanDbId();
void setVlanDbId(long vlanDbId);
long getVlanId();
boolean isOneToOneNat();
void setOneToOneNat(boolean oneToOneNat);
State getState();
boolean readyToUse();
}

View File

@ -110,4 +110,6 @@ public interface Network extends ControlledEntity {
GuestIpType getGuestType();
String getDisplayText();
boolean isShared();
}

View File

@ -20,30 +20,21 @@ package com.cloud.network;
import java.util.List;
import com.cloud.api.commands.AddVpnUserCmd;
import com.cloud.api.commands.AssignToLoadBalancerRuleCmd;
import com.cloud.api.commands.AssociateIPAddrCmd;
import com.cloud.api.commands.CreateLoadBalancerRuleCmd;
import com.cloud.api.commands.CreateNetworkCmd;
import com.cloud.api.commands.CreatePortForwardingRuleCmd;
import com.cloud.api.commands.CreateRemoteAccessVpnCmd;
import com.cloud.api.commands.DeleteLoadBalancerRuleCmd;
import com.cloud.api.commands.DeleteNetworkCmd;
import com.cloud.api.commands.DeleteRemoteAccessVpnCmd;
import com.cloud.api.commands.DisassociateIPAddrCmd;
import com.cloud.api.commands.ListNetworksCmd;
import com.cloud.api.commands.ListPortForwardingRulesCmd;
import com.cloud.api.commands.RemoveFromLoadBalancerRuleCmd;
import com.cloud.api.commands.RemoveVpnUserCmd;
import com.cloud.api.commands.UpdateLoadBalancerRuleCmd;
import com.cloud.exception.AccountLimitException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.rules.FirewallRule;
import com.cloud.offering.NetworkOffering;
@ -56,35 +47,26 @@ public interface NetworkService {
* @throws ResourceAllocationException, InsufficientCapacityException
*/
IpAddress associateIP(AssociateIPAddrCmd cmd) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException;
/**
* Assign a virtual machine, or list of virtual machines, to a load balancer.
*/
boolean assignToLoadBalancer(AssignToLoadBalancerRuleCmd cmd) throws NetworkRuleConflictException;
public boolean removeFromLoadBalancer(RemoveFromLoadBalancerRuleCmd cmd);
public boolean deleteLoadBalancerRule(DeleteLoadBalancerRuleCmd cmd);
public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd);
public boolean disassociateIpAddress(DisassociateIPAddrCmd cmd);
boolean disassociateIpAddress(DisassociateIPAddrCmd cmd);
/**
* Create a remote access vpn from the given public ip address and client ip range
* Create a remote access vpn from the given ip address and client ip range
* @param cmd the command specifying the ip address, ip range
* @return the newly created RemoteAccessVpnVO if successful, null otherwise
* @throws InvalidParameterValueException
* @throws PermissionDeniedException
* @throws ConcurrentOperationException
*/
public RemoteAccessVpn createRemoteAccessVpn(CreateRemoteAccessVpnCmd cmd) throws ConcurrentOperationException, InvalidParameterValueException, PermissionDeniedException;
RemoteAccessVpn createRemoteAccessVpn(CreateRemoteAccessVpnCmd cmd) throws ConcurrentOperationException, InvalidParameterValueException, PermissionDeniedException;
/**
* Start a remote access vpn for the given public ip address and client ip range
* Start a remote access vpn for the given ip address and client ip range
* @param cmd the command specifying the ip address, ip range
* @return the RemoteAccessVpnVO if successful, null otherwise
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
*/
public RemoteAccessVpn startRemoteAccessVpn(CreateRemoteAccessVpnCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException;
RemoteAccessVpn startRemoteAccessVpn(CreateRemoteAccessVpnCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* Destroy a previously created remote access VPN
@ -92,40 +74,12 @@ public interface NetworkService {
* @return success if successful, false otherwise
* @throws ConcurrentOperationException
*/
public boolean destroyRemoteAccessVpn(DeleteRemoteAccessVpnCmd cmd) throws ConcurrentOperationException;
boolean destroyRemoteAccessVpn(DeleteRemoteAccessVpnCmd cmd) throws ConcurrentOperationException;
VpnUser addVpnUser(AddVpnUserCmd cmd) throws ConcurrentOperationException, AccountLimitException;
boolean removeVpnUser(RemoveVpnUserCmd cmd) throws ConcurrentOperationException;
/**
* Create a port forwarding rule from the given ipAddress/port to the given virtual machine/port.
* @param cmd the command specifying the ip address, public port, protocol, private port, and virtual machine id.
* @return the newly created FirewallRuleVO if successful, null otherwise.
*/
public FirewallRule createPortForwardingRule(CreatePortForwardingRuleCmd cmd) throws NetworkRuleConflictException;
/**
* List port forwarding rules assigned to an ip address
* @param cmd the command object holding the criteria for listing port forwarding rules (the ipAddress)
* @return list of port forwarding rules on the given address, empty list if no rules exist
*/
public List<? extends FirewallRule> listPortForwardingRules(ListPortForwardingRulesCmd cmd);
/**
* Create a load balancer rule from the given ipAddress/port to the given private port
* @param cmd the command specifying the ip address, public port, protocol, private port, and algorithm
* @return the newly created LoadBalancerVO if successful, null otherwise
*/
public LoadBalancer createLoadBalancerRule(CreateLoadBalancerRuleCmd cmd);
FirewallRule createIpForwardingRuleInDb(String ipAddr, long virtualMachineId);
FirewallRule createIpForwardingRuleOnDomr(long ruleId);
boolean deleteIpForwardingRule(Long id);
boolean deletePortForwardingRule(Long id, boolean sysContext);
Network createNetwork(CreateNetworkCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
List<? extends Network> searchForNetworks(ListNetworksCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
boolean deleteNetwork(DeleteNetworkCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;

View File

@ -3,14 +3,18 @@
*/
package com.cloud.network.element;
import java.util.List;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientNetworkCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.rules.FirewallRule;
import com.cloud.offering.NetworkOffering;
import com.cloud.utils.component.Adapter;
import com.cloud.utils.net.Ip;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
@ -26,15 +30,68 @@ public interface NetworkElement extends Adapter {
* @param offering network offering that originated the network configuration.
* @return true if network configuration is now usable; false if not; null if not handled by this element.
*/
boolean implement(Network config, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
boolean prepare(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientNetworkCapacityException;
/**
* Prepare for a nic to be added into this network.
* @param network
* @param nic
* @param vm
* @param dest
* @param context
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
* @throws InsufficientNetworkCapacityException
*/
boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientNetworkCapacityException;
boolean release(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* A nic is released from this network.
* @param network
* @param nic
* @param vm
* @param context
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
*/
boolean release(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException;
boolean shutdown(Network config, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* The network is being shutdown.
* @param network
* @param context
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
*/
boolean shutdown(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* Associate a new ip address to this network
* @param network
* @param ipAddress
* @return
* @throws ResourceUnavailableException
*/
boolean associate(Network network, Ip ipAddress) throws ResourceUnavailableException;
/**
* Disassociate the ip address from this network
* @param network
* @param ipAddress
* @return
* @throws ResourceUnavailableException
*/
boolean disassociate(Network network, Ip ipAddress) throws ResourceUnavailableException;
boolean addRule();
boolean revokeRule();
/**
* Apply rules
* @param network
* @param rules
* @return
* @throws ResourceUnavailableException
*/
boolean applyRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException;
}

View File

@ -0,0 +1,65 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.network.lb;
import java.util.List;
import com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;
import com.cloud.api.commands.ListLoadBalancerRulesCmd;
import com.cloud.api.commands.UpdateLoadBalancerRuleCmd;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.uservm.UserVm;
public interface LoadBalancingRulesService {
/**
* Create a load balancer rule from the given ipAddress/port to the given private port
* @param cmd the command specifying the ip address, public port, protocol, private port, and algorithm
* @return the newly created LoadBalancerVO if successful, null otherwise
*/
LoadBalancer createLoadBalancerRule(LoadBalancer lb) throws NetworkRuleConflictException;
LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd);
boolean deleteLoadBalancerRule(long lbRuleId, boolean apply);
/**
* Assign a virtual machine, or list of virtual machines, to a load balancer.
*/
boolean assignToLoadBalancer(long lbRuleId, List<Long> vmIds);
boolean removeFromLoadBalancer(long lbRuleId, List<Long> vmIds);
boolean applyLoadBalancerConfig(long id) throws ResourceUnavailableException;
/**
* List instances that have either been applied to a load balancer or are eligible to be assigned to a load balancer.
* @param cmd
* @return list of vm instances that have been or can be applied to a load balancer
*/
List<? extends UserVm> listLoadBalancerInstances(ListLoadBalancerRuleInstancesCmd cmd);
/**
* List load balancer rules based on the given criteria
* @param cmd the command that specifies the criteria to use for listing load balancers. Load balancers can be listed
* by id, name, public ip, and vm instance id
* @return list of load balancers that match the criteria
*/
List<? extends LoadBalancer> searchForLoadBalancers(ListLoadBalancerRulesCmd cmd);
}

View File

@ -17,10 +17,23 @@
*/
package com.cloud.network.rules;
/**
* Specifies the port forwarding for firewall rule.
*/
public interface FirewallRule {
import com.cloud.acl.ControlledEntity;
import com.cloud.utils.net.Ip;
public interface FirewallRule extends ControlledEntity {
enum Purpose {
Firewall,
PortForwarding,
LoadBalancing,
Vpn,
}
enum State {
Staged, // Rule been created but has never got through network rule conflict detection. Rules in this state can not be sent to network elements.
Add, // Add means the rule has been created and has gone through network rule conflict detection.
Revoke // Revoke means this rule has been revoked. If this rule has been sent to the network elements, the rule will be deleted from database.
}
/**
* @return database id.
*/
@ -34,22 +47,26 @@ public interface FirewallRule {
/**
* @return public ip address.
*/
String getPublicIpAddress();
Ip getSourceIpAddress();
/**
* @return public port.
* @return first port of the source port range.
*/
String getPublicPort();
int getSourcePortStart();
/**
* @return private ip address.
* @return last port of the source prot range. If this is null, that means only one port is mapped.
*/
String getPrivateIpAddress();
int getSourcePortEnd();
/**
* @return private port.
* @return protocol to open these ports for.
*/
String getPrivatePort();
String getProtocol();
Purpose getPurpose();
State getState();
long getNetworkId();
}

View File

@ -15,30 +15,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.network;
package com.cloud.network.rules;
public interface LoadBalancer {
long getId();
import java.util.List;
/**
* Definition for a LoadBalancer
*/
public interface LoadBalancer extends FirewallRule {
String getName();
void setName(String name);
String getDescription();
void setDescription(String description);
long getAccountId();
String getIpAddress();
String getPublicPort();
String getPrivatePort();
void setPrivatePort(String privatePort);
int getDefaultPortStart();
int getDefaultPortEnd();
String getAlgorithm();
void setAlgorithm(String algorithm);
Long getDomainId();
List<? extends Destination> getDestinations();
String getAccountName();
public interface Destination {
String getIpAddress();
int getDestinationPortStart();
int getDestinationPortEnd();
}
}

View File

@ -0,0 +1,40 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.network.rules;
import com.cloud.utils.net.Ip;
/**
* Specifies the port forwarding for firewall rule.
*/
public interface PortForwardingRule extends FirewallRule {
/**
* @return destination ip address.
*/
Ip getDestinationIpAddress();
/**
* @return start of destination port.
*/
int getDestinationPortStart();
/**
* @return end of destination port range
*/
int getDestinationPortEnd();
}

View File

@ -0,0 +1,56 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.network.rules;
import java.util.List;
import com.cloud.api.commands.ListPortForwardingRulesCmd;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.utils.net.Ip;
public interface RulesService {
List<? extends PortForwardingRule> searchForIpForwardingRules(Ip ip, Long start, Long size);
/**
* Creates a port forwarding rule between two ip addresses or between
* an ip address and a virtual machine.
* @param rule rule to be created.
* @param vmId vm to be linked to. If specified the destination ip address is ignored.
* @return PortForwardingRule if created.
* @throws NetworkRuleConflictException if conflicts in the network rules are detected.
*/
PortForwardingRule createPortForwardingRule(PortForwardingRule rule, Long vmId) throws NetworkRuleConflictException;
/**
* Revokes a port forwarding rule
* @param ruleId the id of the rule to revoke.
* @param caller
* @return
*/
PortForwardingRule revokePortForwardingRule(long ruleId, boolean apply);
/**
* List port forwarding rules assigned to an ip address
* @param cmd the command object holding the criteria for listing port forwarding rules (the ipAddress)
* @return list of port forwarding rules on the given address, empty list if no rules exist
*/
public List<? extends PortForwardingRule> listPortForwardingRules(ListPortForwardingRulesCmd cmd);
boolean applyPortForwardingRules(Ip ip, Account caller) throws ResourceUnavailableException;
}

View File

@ -26,9 +26,8 @@ import com.cloud.network.Networks.TrafficType;
public interface NetworkOffering {
public enum GuestIpType {
Virtualized,
DirectSingle,
DirectDual
Virtual,
Direct,
}
public final String DefaultVirtualizedNetworkOffering = "DefaultVirtualizedNetworkOffering";
@ -73,7 +72,5 @@ public interface NetworkOffering {
String getTags();
boolean isShared();
boolean isDefault();
}

View File

@ -27,7 +27,6 @@ import com.cloud.api.ServerApiException;
import com.cloud.api.commands.CreateDomainCmd;
import com.cloud.api.commands.DeleteDomainCmd;
import com.cloud.api.commands.DeletePreallocatedLunCmd;
import com.cloud.api.commands.DeployVMCmd;
import com.cloud.api.commands.ExtractVolumeCmd;
import com.cloud.api.commands.GetCloudIdentifierCmd;
import com.cloud.api.commands.ListAccountsCmd;
@ -45,17 +44,13 @@ import com.cloud.api.commands.ListGuestOsCategoriesCmd;
import com.cloud.api.commands.ListGuestOsCmd;
import com.cloud.api.commands.ListHostsCmd;
import com.cloud.api.commands.ListHypervisorsCmd;
import com.cloud.api.commands.ListIpForwardingRulesCmd;
import com.cloud.api.commands.ListIsosCmd;
import com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;
import com.cloud.api.commands.ListLoadBalancerRulesCmd;
import com.cloud.api.commands.ListPodsByCmd;
import com.cloud.api.commands.ListPreallocatedLunsCmd;
import com.cloud.api.commands.ListPublicIpAddressesCmd;
import com.cloud.api.commands.ListRemoteAccessVpnsCmd;
import com.cloud.api.commands.ListRoutersCmd;
import com.cloud.api.commands.ListServiceOfferingsCmd;
import com.cloud.api.commands.ListSnapshotsCmd;
import com.cloud.api.commands.ListStoragePoolsCmd;
import com.cloud.api.commands.ListSystemVMsCmd;
import com.cloud.api.commands.ListTemplateOrIsoPermissionsCmd;
@ -75,7 +70,6 @@ import com.cloud.api.commands.StopSystemVmCmd;
import com.cloud.api.commands.UpdateDomainCmd;
import com.cloud.api.commands.UpdateIsoCmd;
import com.cloud.api.commands.UpdateIsoPermissionsCmd;
import com.cloud.api.commands.UpdatePortForwardingRuleCmd;
import com.cloud.api.commands.UpdateTemplateCmd;
import com.cloud.api.commands.UpdateTemplatePermissionsCmd;
import com.cloud.api.commands.UpdateVMGroupCmd;
@ -88,35 +82,25 @@ import com.cloud.dc.Pod;
import com.cloud.dc.Vlan;
import com.cloud.domain.Domain;
import com.cloud.event.Event;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientStorageCapacityException;
import com.cloud.exception.InternalErrorException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.host.Host;
import com.cloud.network.IpAddress;
import com.cloud.network.LoadBalancer;
import com.cloud.network.RemoteAccessVpn;
import com.cloud.network.VpnUser;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.FirewallRule;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.org.Cluster;
import com.cloud.storage.GuestOS;
import com.cloud.storage.GuestOsCategory;
import com.cloud.storage.Snapshot;
import com.cloud.storage.StoragePool;
import com.cloud.storage.Volume;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;
import com.cloud.user.UserAccount;
import com.cloud.uservm.UserVm;
import com.cloud.utils.exception.ExecutionException;
import com.cloud.vm.InstanceGroup;
import com.cloud.vm.VirtualMachine;
@ -127,30 +111,6 @@ import com.cloud.vm.VirtualMachine;
public interface ManagementService {
static final String Name = "management-server";
/**
* Creates and starts a new Virtual Machine.
*
* @param cmd the command with the deployment parameters
* - userId
* - accountId
* - zoneId
* - serviceOfferingId
* - templateId: the id of the template (or ISO) to use for creating the virtual machine
* - diskOfferingId: ID of the disk offering to use when creating the root disk (if deploying from an ISO) or the data disk (if deploying from a template). If deploying from a template and a disk offering ID is not passed in, the VM will have only a root disk.
* - displayName: user-supplied name to be shown in the UI or returned in the API
* - groupName: user-supplied groupname to be shown in the UI or returned in the API
* - userData: user-supplied base64-encoded data that can be retrieved by the instance from the virtual router
* - size: size to be used for volume creation in case the disk offering is private (i.e. size=0)
* @return VirtualMachine if successfully deployed, null otherwise
* @throws InvalidParameterValueException if the parameter values are incorrect.
* @throws ExecutionException
* @throws StorageUnavailableException
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
* @throws InsufficientCapacityException
*/
UserVm deployVirtualMachine(DeployVMCmd cmd, String password) throws ResourceAllocationException, InsufficientStorageCapacityException, ExecutionException, StorageUnavailableException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
/**
* Retrieves the list of data centers with search criteria.
* Currently the only search criteria is "available" zones for the account that invokes the API. By specifying
@ -222,13 +182,6 @@ public interface ManagementService {
*/
List<? extends UserVm> searchForUserVMs(ListVMsCmd cmd);
/**
* Update an existing port forwarding rule on the given public IP / public port for the given protocol
* @param cmd - the UpdatePortForwardingRuleCmd command that wraps publicIp, privateIp, publicPort, privatePort, protocol of the rule to update
* @return the new firewall rule if updated, null if no rule on public IP / public port of that protocol could be found
*/
FirewallRule updatePortForwardingRule(UpdatePortForwardingRuleCmd cmd);
/**
* Obtains a list of events by the specified search criteria.
* Can search by: "username", "type", "level", "startDate", "endDate"
@ -372,21 +325,6 @@ public interface ManagementService {
*/
List<? extends DiskOffering> searchForDiskOfferings(ListDiskOfferingsCmd cmd);
/**
* List instances that have either been applied to a load balancer or are eligible to be assigned to a load balancer.
* @param cmd
* @return list of vm instances that have been or can be applied to a load balancer
*/
List<? extends UserVm> listLoadBalancerInstances(ListLoadBalancerRuleInstancesCmd cmd);
/**
* List load balancer rules based on the given criteria
* @param cmd the command that specifies the criteria to use for listing load balancers. Load balancers can be listed
* by id, name, public ip, and vm instance id
* @return list of load balancers that match the criteria
*/
List<? extends LoadBalancer> searchForLoadBalancers(ListLoadBalancerRulesCmd cmd);
/**
* List storage pools that match the given criteria
* @param cmd the command that wraps the search criteria (zone, pod, name, IP address, path, and cluster id)
@ -449,8 +387,6 @@ public interface ManagementService {
public List<? extends VpnUser> searchForVpnUsers(ListVpnUsersCmd cmd);
List<? extends FirewallRule> searchForIpForwardingRules(ListIpForwardingRulesCmd cmd);
String getVersion();
/**
@ -480,6 +416,4 @@ public interface ManagementService {
*/
boolean unregisterPreallocatedLun(DeletePreallocatedLunCmd cmd) throws IllegalArgumentException;
}

View File

@ -161,4 +161,6 @@ public interface Volume extends ControlledEntity, BasedOn {
boolean getDestroyed();
long getDiskOfferingId();
String getChainInfo();
}

View File

@ -99,6 +99,8 @@ public enum State implements FiniteState<State, Event> {
s_fsm.addTransition(State.Migrating, VirtualMachine.Event.MigrationRequested, State.Migrating);
s_fsm.addTransition(State.Migrating, VirtualMachine.Event.OperationSucceeded, State.Running);
s_fsm.addTransition(State.Migrating, VirtualMachine.Event.OperationFailed, State.Running);
s_fsm.addTransition(State.Migrating, VirtualMachine.Event.MigrationFailedOnSource, State.Running);
s_fsm.addTransition(State.Migrating, VirtualMachine.Event.MigrationFailedOnDest, State.Running);
s_fsm.addTransition(State.Migrating, VirtualMachine.Event.AgentReportRunning, State.Running);
s_fsm.addTransition(State.Migrating, VirtualMachine.Event.AgentReportStopped, State.Stopped);
s_fsm.addTransition(State.Stopping, VirtualMachine.Event.OperationSucceeded, State.Stopped);

View File

@ -23,7 +23,6 @@ import com.cloud.api.commands.CreateTemplateCmd;
import com.cloud.api.commands.CreateVMGroupCmd;
import com.cloud.api.commands.DeleteVMGroupCmd;
import com.cloud.api.commands.DeployVMCmd;
import com.cloud.api.commands.DeployVm2Cmd;
import com.cloud.api.commands.DestroyVMCmd;
import com.cloud.api.commands.DetachVolumeCmd;
import com.cloud.api.commands.RebootVMCmd;
@ -133,7 +132,7 @@ public interface UserVmService {
* @throws ConcurrentOperationException if there are multiple users working on the same VM.
* @throws ResourceUnavailableException if the resources required the deploy the VM is not currently available.
*/
UserVm startVirtualMachine(DeployVm2Cmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
UserVm startVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
/**
* Creates a vm group.

Some files were not shown because too many files have changed in this diff Show More