Search in sources :

Example 1 with BaseCmd

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;
    }
}
Also used : DisableStaticNatCmd(org.apache.cloudstack.api.command.user.nat.DisableStaticNatCmd) BaseCmd(org.apache.cloudstack.api.BaseCmd) CloudException(com.cloud.exception.CloudException) IOException(java.io.IOException)

Example 2 with BaseCmd

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);
    }
}
Also used : Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CreateVlanIpRangeCmd(org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd) BaseCmd(org.apache.cloudstack.api.BaseCmd) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException)

Example 3 with BaseCmd

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);
}
Also used : Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) AssociateIPAddrCmd(org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd) IPAddressVO(com.cloud.network.dao.IPAddressVO) EnableStaticNatCmd(org.apache.cloudstack.api.command.user.nat.EnableStaticNatCmd) BaseCmd(org.apache.cloudstack.api.BaseCmd) CloudException(com.cloud.exception.CloudException) IOException(java.io.IOException)

Example 4 with BaseCmd

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");
    }
}
Also used : Project(net.juniper.contrail.api.types.Project) BaseCmd(org.apache.cloudstack.api.BaseCmd) DeleteProjectCmd(org.apache.cloudstack.api.command.user.project.DeleteProjectCmd) ProjectVO(com.cloud.projects.ProjectVO) CloudException(com.cloud.exception.CloudException) IOException(java.io.IOException)

Example 5 with BaseCmd

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);
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) BaseAsyncCreateCmd(org.apache.cloudstack.api.BaseAsyncCreateCmd) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) BaseCmd(org.apache.cloudstack.api.BaseCmd)

Aggregations

BaseCmd (org.apache.cloudstack.api.BaseCmd)13 Account (com.cloud.user.Account)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 CloudException (com.cloud.exception.CloudException)4 UserVO (com.cloud.user.UserVO)3 Test (org.junit.Test)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)2 AccountVO (com.cloud.user.AccountVO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ConfigurationException (javax.naming.ConfigurationException)2 Project (net.juniper.contrail.api.types.Project)2 APICommand (org.apache.cloudstack.api.APICommand)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 DataCenter (com.cloud.dc.DataCenter)1 Domain (com.cloud.domain.Domain)1 DomainVO (com.cloud.domain.DomainVO)1 AccountLimitException (com.cloud.exception.AccountLimitException)1