use of org.apache.cloudstack.api.BaseCmd in project cloudstack by apache.
the class NetworkProviderTest method deleteFloatingIp.
public void deleteFloatingIp(IPAddressVO ip) throws Exception {
BaseCmd cmd = new DisableStaticNatCmd();
BaseCmd proxy = ComponentContext.inject(cmd);
ManagementServerMock.setParameter(proxy, "ipAddressId", BaseCmd.CommandType.LONG, ip.getId());
try {
proxy.execute();
} catch (Exception e) {
s_logger.debug("DisableStaticNatCmd exception: " + e);
e.printStackTrace();
throw e;
}
}
use of org.apache.cloudstack.api.BaseCmd in project cloudstack by apache.
the class ManagementServerMock method createPublicVlanIpRange.
private void createPublicVlanIpRange() {
CreateVlanIpRangeCmd cmd = new CreateVlanIpRangeCmd();
BaseCmd proxy = ComponentContext.inject(cmd);
Long public_net_id = null;
List<NetworkVO> nets = _networksDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
if (nets != null && !nets.isEmpty()) {
NetworkVO public_net = nets.get(0);
public_net_id = public_net.getId();
} else {
s_logger.debug("no public network found in the zone: " + _zone.getId());
}
Account system = _accountMgr.getSystemAccount();
setParameter(cmd, "accountName", BaseCmd.CommandType.STRING, system.getAccountName());
setParameter(cmd, "domainId", BaseCmd.CommandType.LONG, Domain.ROOT_DOMAIN);
setParameter(cmd, "startIp", BaseCmd.CommandType.STRING, "10.84.60.200");
setParameter(cmd, "endIp", BaseCmd.CommandType.STRING, "10.84.60.250");
setParameter(cmd, ApiConstants.GATEWAY, BaseCmd.CommandType.STRING, "10.84.60.254");
setParameter(cmd, ApiConstants.NETMASK, BaseCmd.CommandType.STRING, "255.255.255.0");
setParameter(cmd, "networkID", BaseCmd.CommandType.LONG, public_net_id);
setParameter(cmd, "zoneId", BaseCmd.CommandType.LONG, _zone.getId());
setParameter(cmd, "vlan", BaseCmd.CommandType.STRING, "untagged");
s_logger.debug("createPublicVlanIpRange execute : zone id: " + _zone.getId() + ", public net id: " + public_net_id);
try {
_configService.createVlanAndPublicIpRange(cmd);
} catch (Exception e) {
s_logger.debug("createPublicVlanIpRange: " + e);
}
}
use of org.apache.cloudstack.api.BaseCmd in project cloudstack by apache.
the class NetworkProviderTest method createFloatingIp.
public IPAddressVO createFloatingIp(Network network, UserVm vm) throws Exception {
BaseCmd cmd = new AssociateIPAddrCmd();
BaseCmd proxy = ComponentContext.inject(cmd);
Account system = _accountMgr.getSystemAccount();
DataCenter zone = _server.getZone();
ManagementServerMock.setParameter(proxy, "accountName", BaseCmd.CommandType.STRING, system.getAccountName());
ManagementServerMock.setParameter(proxy, "domainId", BaseCmd.CommandType.LONG, Domain.ROOT_DOMAIN);
ManagementServerMock.setParameter(proxy, "zoneId", BaseCmd.CommandType.LONG, zone.getId());
ManagementServerMock.setParameter(proxy, "networkId", BaseCmd.CommandType.LONG, network.getId());
try {
((AssociateIPAddrCmd) cmd).create();
((AssociateIPAddrCmd) cmd).execute();
} catch (Exception e) {
s_logger.debug("AssociateIPAddrCmd exception: " + e);
e.printStackTrace();
throw e;
}
SearchBuilder<IPAddressVO> searchBuilder = _ipAddressDao.createSearchBuilder();
searchBuilder.and("sourceNat", searchBuilder.entity().isSourceNat(), Op.EQ);
searchBuilder.and("network", searchBuilder.entity().getAssociatedWithNetworkId(), Op.EQ);
searchBuilder.and("dataCenterId", searchBuilder.entity().getDataCenterId(), Op.EQ);
searchBuilder.and("associatedWithVmId", searchBuilder.entity().getAssociatedWithVmId(), Op.NULL);
SearchCriteria<IPAddressVO> sc = searchBuilder.create();
sc.setParameters("sourceNat", false);
sc.setParameters("network", network.getId());
List<IPAddressVO> publicIps = _ipAddressDao.search(sc, null);
assertNotNull(publicIps);
cmd = new EnableStaticNatCmd();
proxy = ComponentContext.inject(cmd);
ManagementServerMock.setParameter(proxy, "ipAddressId", BaseCmd.CommandType.LONG, publicIps.get(0).getId());
ManagementServerMock.setParameter(proxy, "networkId", BaseCmd.CommandType.LONG, network.getId());
ManagementServerMock.setParameter(proxy, "virtualMachineId", BaseCmd.CommandType.LONG, vm.getId());
try {
proxy.execute();
} catch (Exception e) {
s_logger.debug("EnableStaticNatCmd exception: " + e);
e.printStackTrace();
throw e;
}
return publicIps.get(0);
}
use of org.apache.cloudstack.api.BaseCmd in project cloudstack by apache.
the class NetworkProviderTest method deleteProject.
public void deleteProject(String name) {
BaseCmd cmd = new DeleteProjectCmd();
BaseCmd proxy = ComponentContext.inject(cmd);
ProjectVO project = _projectDao.findByNameAndDomain(name, Domain.ROOT_DOMAIN);
try {
ManagementServerMock.setParameter(proxy, "id", BaseCmd.CommandType.LONG, project.getId());
((DeleteProjectCmd) proxy).execute();
if (_api.findById(net.juniper.contrail.api.types.Project.class, project.getUuid()) != null) {
fail("unable to delete project in vnc");
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception while deleting project");
}
}
use of org.apache.cloudstack.api.BaseCmd in project cloudstack by apache.
the class CommandCreationWorker method handle.
@Override
public void handle(final DispatchTask task) {
final BaseCmd cmd = task.getCmd();
if (cmd instanceof BaseAsyncCreateCmd) {
try {
CallContext.current().setEventDisplayEnabled(cmd.isDisplay());
((BaseAsyncCreateCmd) cmd).create();
} catch (final ResourceAllocationException e) {
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, e.getMessage(), e);
}
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ATTEMP_TO_CREATE_NON_CREATION_CMD);
}
}
Aggregations