Package com.cloud.stack.models

Examples of com.cloud.stack.models.CloudStackAccount


            return getNetworksWithoutSecurityGroupEnabled(zone.getId());
        }
    }

    private CloudStackZone findZone() throws Exception {
        CloudStackAccount caller = getCurrentAccount();
        List<CloudStackZone> cloudZones;

        String defaultZoneId = getDefaultZoneId(caller.getId());
        if (defaultZoneId != null) {
            cloudZones = getApi().listZones(true, null, defaultZoneId, null);
        } else {
            // caller.getDomainId doesn't work in user mode
            // List<CloudStackZone> cloudZones = getApi().listZones(true, caller.getDomainId(), null, null);
View Full Code Here


            return;
        }

        // validate account is admin level
        try {
            CloudStackAccount currentAccount = ServiceProvider.getInstance().getEC2Engine().getCurrentAccount();

            if (currentAccount.getAccountType() != 1) {
                logger.debug("SetOfferMapping called by non-admin user!");
                response.setStatus(500);
                endResponse(response, "Permission denied for non-admin user to setOfferMapping!");
                return;
            }
View Full Code Here

            return;
        }

        // validate account is admin level
        try {
            CloudStackAccount currentAccount = ServiceProvider.getInstance().getEC2Engine().getCurrentAccount();

            if (currentAccount.getAccountType() != 1) {
                logger.debug("deleteOfferMapping called by non-admin user!");
                response.setStatus(500);
                endResponse(response, "Permission denied for non-admin user to deleteOfferMapping!");
                return;
            }
View Full Code Here

    public EC2Address allocateAddress()
    {
        try {
            EC2Address ec2Address = new EC2Address();
            // this gets our networkId
            CloudStackAccount caller = getCurrentAccount();

            CloudStackZone zone = findZone();
            CloudStackNetwork net = findNetwork(zone);
//      CloudStackIpAddress resp = getApi().associateIpAddress(null, null, null, "0036952d-48df-4422-9fd0-94b0885e18cb");
            CloudStackIpAddress resp = getApi().associateIpAddress(zone.getId(), caller.getName(), caller.getDomainId(), net != null ? net.getId():null);
            ec2Address.setAssociatedInstanceId(resp.getId());

            if (resp.getIpAddress() == null) {
                List<CloudStackIpAddress> addrList = getApi().listPublicIpAddresses(null, null, null, null, null, null, null, null, null);
                if (addrList != null && addrList.size() > 0) {
View Full Code Here

     * @return
     */
    public EC2CreateImageResponse registerImage(EC2RegisterImage request)
    {
        try {
            CloudStackAccount caller = getCurrentAccount();
            if (null == request.getName())
                throw new EC2ServiceException(ClientError.Unsupported, "Missing parameter - name");

            List<CloudStackTemplate> templates = getApi().registerTemplate((request.getDescription() == null ? request.getName() : request.getDescription()),
                    request.getFormat(), request.getHypervisor(), request.getName(), toOSTypeId(request.getOsTypeName()), request.getLocation(),
View Full Code Here

     * @return
     */
    public EC2Volume createVolume( EC2CreateVolume request ) {
        try {

            CloudStackAccount caller = getCurrentAccount();
            // -> put either snapshotid or diskofferingid on the request
            String snapshotId = request.getSnapshotId();
            Long size = request.getSize();
            String diskOfferingId = null;

View Full Code Here

        int createInstances    = 0;
        int canCreateInstances = -1;
        int countCreated       = 0;

        try {
            CloudStackAccount caller = getCurrentAccount();

            // ugly...
            canCreateInstances = calculateAllowedInstances();
            if (-1 == canCreateInstances) canCreateInstances = request.getMaxCount();
View Full Code Here

     *         the user can create.
     */
    private int calculateAllowedInstances() throws Exception {   
        int maxAllowed = -1;

        CloudStackAccount ourAccount = getCurrentAccount();

        if (ourAccount == null) {
            // This should never happen, but
            // we will return -99999 if this happens...
            return -99999;
        }

        // if accountType is Admin == 1, then let's return -1
        if (ourAccount.getAccountType() == 1) return -1;

        // -> get the user limits on instances
        // "0" represents instances: 
        // http://download.cloud.com/releases/2.2.0/api_2.2.8/user/listResourceLimits.html
        List<CloudStackResourceLimit> limits = getApi().listResourceLimits(null, null, null, null, "0");
View Full Code Here

     * @return
     * @throws Exception
     */
    private CloudStackNetwork getNetworksWithoutSecurityGroupEnabled(String zoneId) throws Exception {
        // grab current account
        CloudStackAccount caller = getCurrentAccount();

        //check if account has any networks in the system
        List<CloudStackNetwork> networks = getApi().listNetworks(caller.getName(), caller.getDomainId(), null, true, null, null, null, null, null, zoneId);

        //listRequired offerings in the system - the network created from this offering has to be specified in deployVm command
        List<CloudStackNetworkOffering> reuquiredOfferings = getApi().listNetworkOfferings("Required", null, null, null, true,  null, null, null, null, null, zoneId);
        if (reuquiredOfferings != null && !reuquiredOfferings.isEmpty()) {
            if (networks != null && !networks.isEmpty()) {
                //pick up the first required network from the network list
                for (CloudStackNetwork network : networks)  {
                    for (CloudStackNetworkOffering requiredOffering : reuquiredOfferings) {
                        logger.debug("[reqd/virtual} offering: " + requiredOffering.getId() + " network " + network.getNetworkOfferingId());
                        if (network.getNetworkOfferingId().equals(requiredOffering.getId())) {
                            return network;
                        }               
                    }
                }
            } else {
                //create new network and return it
                return createDefaultGuestNetwork(zoneId, reuquiredOfferings.get(0), caller);
            }
        } else {
            //find all optional network offerings in the system
            List<CloudStackNetworkOffering> optionalOfferings = getApi().listNetworkOfferings("Optional", null, null, null, true, null, null, null, null, null, zoneId);
            if (optionalOfferings != null && !optionalOfferings.isEmpty()) {
                if (networks != null && !networks.isEmpty()) {
                    for (CloudStackNetwork network : networks) {
                        for (CloudStackNetworkOffering optionalOffering : optionalOfferings) {
                            logger.debug("[optional] offering: " + optionalOffering.getId() + " network " + network.getNetworkOfferingId());
                            if (network.getNetworkOfferingId().equals(optionalOffering.getId())) {
                                return network;
                            }
                        }
                    }
                }
            }
        }

        // if we get this far and haven't returned already return an error
        throw new EC2ServiceException(ServerError.InternalError, "Unable to find an appropriate network for account " + caller.getName());
    }
View Full Code Here

            return getNetworksWithoutSecurityGroupEnabled(zone.getId());
        }
    }

    private CloudStackZone findZone() throws Exception {
        CloudStackAccount caller = getCurrentAccount();
        List<CloudStackZone> cloudZones;

        String defaultZoneId = getDefaultZoneId(caller.getId());
        if (defaultZoneId != null) {
            cloudZones = getApi().listZones(true, null, defaultZoneId, null);
        } else {
            // caller.getDomainId doesn't work in user mode
            // List<CloudStackZone> cloudZones = getApi().listZones(true, caller.getDomainId(), null, null);
View Full Code Here

TOP

Related Classes of com.cloud.stack.models.CloudStackAccount

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.