Search in sources :

Example 21 with Account

use of com.cloud.user.Account in project cloudstack by apache.

the class QuotaResponseBuilderImpl method createQuotaSummaryResponse.

@Override
public List<QuotaSummaryResponse> createQuotaSummaryResponse(final String accountName, final Long domainId) {
    List<QuotaSummaryResponse> result = new ArrayList<QuotaSummaryResponse>();
    if (accountName != null && domainId != null) {
        Account account = _accountDao.findActiveAccount(accountName, domainId);
        QuotaSummaryResponse qr = getQuotaSummaryResponse(account);
        result.add(qr);
    }
    return result;
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList)

Example 22 with Account

use of com.cloud.user.Account in project cloudstack by apache.

the class QuotaCreditsCmd method execute.

@Override
public void execute() {
    Long accountId = null;
    Account account = _accountService.getActiveAccountByName(accountName, domainId);
    if (account != null) {
        accountId = account.getAccountId();
    }
    if (accountId == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "The account does not exists or has been removed/disabled");
    }
    if (getValue() == null) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Please send a valid non-empty quota value");
    }
    if (getQuotaEnforce() != null) {
        _quotaService.setLockAccount(accountId, getQuotaEnforce());
    }
    if (getMinBalance() != null) {
        _quotaService.setMinBalance(accountId, getMinBalance());
    } else {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Please set a value for min balance");
    }
    final QuotaCreditsResponse response = _responseBuilder.addQuotaCredits(accountId, getDomainId(), getValue(), CallContext.current().getCallingUserId(), getQuotaEnforce());
    response.setResponseName(getCommandName());
    response.setObjectName("quotacredits");
    setResponseObject(response);
}
Also used : Account(com.cloud.user.Account) ServerApiException(org.apache.cloudstack.api.ServerApiException) QuotaCreditsResponse(org.apache.cloudstack.api.response.QuotaCreditsResponse)

Example 23 with Account

use of com.cloud.user.Account in project cloudstack by apache.

the class CiscoVnmcElementTest method implementTest.

@Test
public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    URI uri = URI.create("vlan://123");
    Network network = mock(Network.class);
    when(network.getId()).thenReturn(1L);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
    when(network.getDataCenterId()).thenReturn(1L);
    when(network.getGateway()).thenReturn("1.1.1.1");
    when(network.getBroadcastUri()).thenReturn(uri);
    when(network.getCidr()).thenReturn("1.1.1.0/24");
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(1L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    DeployDestination dest = mock(DeployDestination.class);
    Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("d1");
    Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("a1");
    ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    DataCenter dc = mock(DataCenter.class);
    when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
    when(_entityMgr.findById(DataCenter.class, network.getDataCenterId())).thenReturn(dc);
    List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>();
    devices.add(mock(CiscoVnmcControllerVO.class));
    when(_ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(devices);
    CiscoAsa1000vDeviceVO asaVO = mock(CiscoAsa1000vDeviceVO.class);
    when(asaVO.getInPortProfile()).thenReturn("foo");
    when(asaVO.getManagementIp()).thenReturn("1.2.3.4");
    List<CiscoAsa1000vDeviceVO> asaList = new ArrayList<CiscoAsa1000vDeviceVO>();
    asaList.add(asaVO);
    when(_ciscoAsa1000vDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(asaList);
    when(_networkAsa1000vMapDao.findByNetworkId(network.getId())).thenReturn(mock(NetworkAsa1000vMapVO.class));
    when(_networkAsa1000vMapDao.findByAsa1000vId(anyLong())).thenReturn(null);
    when(_networkAsa1000vMapDao.persist(any(NetworkAsa1000vMapVO.class))).thenReturn(mock(NetworkAsa1000vMapVO.class));
    when(_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.CiscoVnmc)).thenReturn(true);
    ClusterVSMMapVO clusterVsmMap = mock(ClusterVSMMapVO.class);
    when(_clusterVsmMapDao.findByClusterId(anyLong())).thenReturn(clusterVsmMap);
    CiscoNexusVSMDeviceVO vsmDevice = mock(CiscoNexusVSMDeviceVO.class);
    when(vsmDevice.getUserName()).thenReturn("foo");
    when(vsmDevice.getPassword()).thenReturn("bar");
    when(vsmDevice.getipaddr()).thenReturn("1.2.3.4");
    when(_vsmDeviceDao.findById(anyLong())).thenReturn(vsmDevice);
    HostVO hostVO = mock(HostVO.class);
    when(hostVO.getId()).thenReturn(1L);
    when(_hostDao.findById(anyLong())).thenReturn(hostVO);
    Ip ip = mock(Ip.class);
    when(ip.addr()).thenReturn("1.2.3.4");
    PublicIp publicIp = mock(PublicIp.class);
    when(publicIp.getAddress()).thenReturn(ip);
    when(publicIp.getState()).thenReturn(IpAddress.State.Releasing);
    when(publicIp.getAccountId()).thenReturn(1L);
    when(publicIp.isSourceNat()).thenReturn(true);
    when(publicIp.getVlanTag()).thenReturn("123");
    when(publicIp.getGateway()).thenReturn("1.1.1.1");
    when(publicIp.getNetmask()).thenReturn("1.1.1.1");
    when(publicIp.getMacAddress()).thenReturn(null);
    when(publicIp.isOneToOneNat()).thenReturn(true);
    when(_ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(acc, network)).thenReturn(publicIp);
    VlanVO vlanVO = mock(VlanVO.class);
    when(vlanVO.getVlanGateway()).thenReturn("1.1.1.1");
    List<VlanVO> vlanVOList = new ArrayList<VlanVO>();
    when(_vlanDao.listVlansByPhysicalNetworkId(network.getPhysicalNetworkId())).thenReturn(vlanVOList);
    Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentMgr.easySend(anyLong(), any(CreateLogicalEdgeFirewallCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(ConfigureNexusVsmForAsaCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(SetSourceNatCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(AssociateAsaWithLogicalEdgeFirewallCommand.class))).thenReturn(answer);
    assertTrue(_element.implement(network, offering, dest, context));
}
Also used : Account(com.cloud.user.Account) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) AssociateAsaWithLogicalEdgeFirewallCommand(com.cloud.agent.api.AssociateAsaWithLogicalEdgeFirewallCommand) SetSourceNatCommand(com.cloud.agent.api.routing.SetSourceNatCommand) URI(java.net.URI) ReservationContext(com.cloud.vm.ReservationContext) Network(com.cloud.network.Network) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) VlanVO(com.cloud.dc.VlanVO) CiscoAsa1000vDeviceVO(com.cloud.network.cisco.CiscoAsa1000vDeviceVO) CiscoNexusVSMDeviceVO(com.cloud.network.CiscoNexusVSMDeviceVO) NetworkOffering(com.cloud.offering.NetworkOffering) PublicIp(com.cloud.network.addr.PublicIp) ConfigureNexusVsmForAsaCommand(com.cloud.agent.api.ConfigureNexusVsmForAsaCommand) HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) DataCenter(com.cloud.dc.DataCenter) CreateLogicalEdgeFirewallCommand(com.cloud.agent.api.CreateLogicalEdgeFirewallCommand) DeployDestination(com.cloud.deploy.DeployDestination) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 24 with Account

use of com.cloud.user.Account in project cloudstack by apache.

the class LoadBalanceRuleHandler method deployLoadBalancerVM.

private DomainRouterVO deployLoadBalancerVM(final Long networkId, final IPAddressVO ipAddr) {
    final NetworkVO network = _networkDao.findById(networkId);
    final DataCenter dc = _dcDao.findById(network.getDataCenterId());
    final Long podId = getPodIdForDirectIp(ipAddr);
    final Pod pod = podId == null ? null : _podDao.findById(podId);
    final Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
    params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
    final Account owner = _accountService.getActiveAccountByName("system", new Long(1));
    final DeployDestination dest = new DeployDestination(dc, pod, null, null);
    s_logger.debug("About to deploy ELB vm ");
    try {
        final DomainRouterVO elbVm = deployELBVm(network, dest, owner, params);
        if (elbVm == null) {
            throw new InvalidParameterValueException("Could not deploy or find existing ELB VM");
        }
        s_logger.debug("Deployed ELB  vm = " + elbVm);
        return elbVm;
    } catch (final Throwable t) {
        s_logger.warn("Error while deploying ELB VM:  ", t);
        return null;
    }
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) Pod(com.cloud.dc.Pod) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DeployDestination(com.cloud.deploy.DeployDestination) Param(com.cloud.vm.VirtualMachineProfile.Param) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 25 with Account

use of com.cloud.user.Account in project cloudstack by apache.

the class NetworkProviderTest method purgeTestNetwork.

private void purgeTestNetwork() {
    Account system = _accountMgr.getSystemAccount();
    DataCenter zone = _server.getZone();
    List<? extends Network> list = _networkService.getIsolatedNetworksOwnedByAccountInZone(zone.getId(), system);
    for (Network net : list) {
        s_logger.debug("Delete network " + net.getName());
        _networkService.deleteNetwork(net.getId(), false);
    }
}
Also used : Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) VirtualNetwork(net.juniper.contrail.api.types.VirtualNetwork) Network(com.cloud.network.Network)

Aggregations

Account (com.cloud.user.Account)566 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)254 ArrayList (java.util.ArrayList)152 ActionEvent (com.cloud.event.ActionEvent)114 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)98 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)82 List (java.util.List)80 Test (org.junit.Test)73 User (com.cloud.user.User)66 AccountVO (com.cloud.user.AccountVO)64 DB (com.cloud.utils.db.DB)61 Network (com.cloud.network.Network)60 Pair (com.cloud.utils.Pair)52 DataCenter (com.cloud.dc.DataCenter)49 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)46 Filter (com.cloud.utils.db.Filter)46 CallContext (org.apache.cloudstack.context.CallContext)45 DomainVO (com.cloud.domain.DomainVO)44 TransactionStatus (com.cloud.utils.db.TransactionStatus)44 NetworkVO (com.cloud.network.dao.NetworkVO)43