All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dasein.cloud.jclouds.openstack.swift.Locales Maven / Gradle / Ivy

/**
 * Copyright (C) 2010-2011 enStratusNetworks LLC
 *
 * ====================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ====================================================================
 */

package org.dasein.cloud.jclouds.openstack.swift;

import java.util.Collection;
import java.util.Collections;
import java.util.Locale;

import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException;
import org.dasein.cloud.dc.DataCenter;
import org.dasein.cloud.dc.DataCenterServices;
import org.dasein.cloud.dc.Region;

public class Locales implements DataCenterServices {
    private Swift         swift;
    
    Locales(Swift cloud) { this.swift = cloud; }
    
    @Override
    public DataCenter getDataCenter(String providerDataCenterId) throws InternalException, CloudException {
        if( providerDataCenterId == null || !providerDataCenterId.equals(swift.getContext().getRegionId() + "-a") ) {
            return null;
        }
        for( DataCenter dc : listDataCenters(swift.getContext().getRegionId()) ) {
            if( dc.getProviderDataCenterId().equals(providerDataCenterId) ) {
                return dc;
            }
        }
        return null;
    }

    @Override
    public String getProviderTermForDataCenter(Locale locale) {
        return "location";
    }

    @Override
    public String getProviderTermForRegion(Locale locale) {
        return "region";
    }

    @Override
    public Region getRegion(String providerRegionId) throws InternalException, CloudException {
        if( providerRegionId == null ) {
            return null;
        }
        for( Region r : listRegions() ) {
            if( r.getProviderRegionId().equals(providerRegionId) ) {
                return r;
            }
        }
        return null;
    }

    @Override
    public Collection listDataCenters(String providerRegionId) throws InternalException, CloudException {
        Region region;
        
        if( providerRegionId == null || (region = getRegion(providerRegionId)) == null ) {
            throw new CloudException("No such region: " + providerRegionId);
        }
        DataCenter dc = new DataCenter();
        
        dc.setActive(true);
        dc.setAvailable(true);
        dc.setName(region.getName() + " (DC)");
        dc.setProviderDataCenterId(providerRegionId + "-a");
        dc.setRegionId(providerRegionId);
        return Collections.singletonList(dc);
    }

    @Override
    public Collection listRegions() throws InternalException, CloudException {
        Region region = new Region();
        
        region.setActive(true);
        region.setAvailable(true);
        region.setName("local");
        region.setProviderRegionId("local");
        return Collections.singletonList(region);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy