/**
 * Copyright (C) 2009-2015 Dell, Inc.
 *
 * ====================================================================
 * 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.cloudstack.network;

import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException;
import org.dasein.cloud.cloudstack.CSCloud;
import org.dasein.cloud.network.AbstractNetworkServices;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class CSNetworkServices extends AbstractNetworkServices<CSCloud> {
    public CSNetworkServices(@Nonnull CSCloud provider) {
        super(provider);
    }

    @Override 
    public @Nullable SecurityGroup getFirewallSupport() {
        return new SecurityGroup(getProvider());
    }
    
    @Override
    public @Nullable IpAddress getIpAddressSupport() {
        try {
            if( getProvider().hasApi(IpAddress.ASSOCIATE_IP_ADDRESS) ) {
                return new IpAddress(getProvider());
            }
        }
        catch( CloudException e ) {
        }
        catch( InternalException e ) {
        }
        return null;
    }
    
    @Override
    public @Nullable LoadBalancers getLoadBalancerSupport() {
        try {
            if( getProvider().hasApi("createLoadBalancer") ) {
                return new LoadBalancers(getProvider());
            }
        }
        catch( CloudException e ) {
        }
        catch( InternalException e ) {
        }
        return null;
    }
    
    @Override
    public @Nullable Network getVlanSupport() {
        return new Network(getProvider());
    }
}

@@ -1286,47 +1286,325 @@
     
-return new SecurityGroup(getProvider())
+try %7B%0A            if( getProvider().getDataCenterServices().supportsSecurityGroups(getContext().getRegionId(), false) ) %7B%0A                return new SecurityGroup(getProvider());%0A            %7D%0A        %7D%0A        catch( InternalException e ) %7B%0A        %7D%0A        catch( CloudException e ) %7B%0A        %7D%0A        return null
 ;%0A  

Handle security groups in advanced zones