Search in sources :

Example 1 with FirewallList

use of com.google.api.services.compute.model.FirewallList in project cloudbreak by hortonworks.

the class GcpPlatformResources method securityGroups.

@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws IOException {
    Compute compute = GcpStackUtil.buildCompute(cloudCredential);
    String projectId = GcpStackUtil.getProjectId(cloudCredential);
    Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
    if (compute != null) {
        FirewallList firewallList = compute.firewalls().list(projectId).execute();
        for (Firewall firewall : firewallList.getItems()) {
            Map<String, Object> properties = new HashMap<>();
            properties.put("network", getNetworkName(firewall));
            CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(firewall.getName(), firewall.getName(), properties);
            result.computeIfAbsent(region.value(), k -> new HashSet<>()).add(cloudSecurityGroup);
        }
    }
    return new CloudSecurityGroups(result);
}
Also used : FirewallList(com.google.api.services.compute.model.FirewallList) Arrays(java.util.Arrays) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Cacheable(org.springframework.cache.annotation.Cacheable) HashMap(java.util.HashMap) Network(com.google.api.services.compute.model.Network) StringUtils(org.apache.commons.lang3.StringUtils) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Strings(com.google.common.base.Strings) NetworkList(com.google.api.services.compute.model.NetworkList) Firewall(com.google.api.services.compute.model.Firewall) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) Service(org.springframework.stereotype.Service) Map(java.util.Map) RegionList(com.google.api.services.compute.model.RegionList) GcpStackUtil(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil) VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) Subnetwork(com.google.api.services.compute.model.Subnetwork) PlatformResources(com.sequenceiq.cloudbreak.cloud.PlatformResources) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) Set(java.util.Set) IOException(java.io.IOException) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) MachineType(com.google.api.services.compute.model.MachineType) List(java.util.List) MachineTypeList(com.google.api.services.compute.model.MachineTypeList) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) FirewallList(com.google.api.services.compute.model.FirewallList) Collections(java.util.Collections) Compute(com.google.api.services.compute.Compute) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Firewall(com.google.api.services.compute.model.Firewall) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) Compute(com.google.api.services.compute.Compute) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet)

Example 2 with FirewallList

use of com.google.api.services.compute.model.FirewallList in project platformlayer by platformlayer.

the class GoogleComputeClient method getInstanceFirewallRules.

public List<Firewall> getInstanceFirewallRules(String instanceUrl) throws OpsException {
    List<Firewall> ret = Lists.newArrayList();
    FirewallList firewalls;
    try {
        log.debug("Listing firewall rules");
        firewalls = compute.firewalls().list(projectId).execute();
    } catch (IOException e) {
        throw new OpsException("Error listing firewalls", e);
    }
    if (firewalls.getItems() != null) {
        for (Firewall firewall : firewalls.getItems()) {
            if (firewall.getTargetTags() != null && firewall.getTargetTags().contains(instanceUrl)) {
                ret.add(firewall);
            }
        }
    }
    return ret;
}
Also used : FirewallList(com.google.api.services.compute.model.FirewallList) OpsException(org.platformlayer.ops.OpsException) IOException(java.io.IOException) Firewall(com.google.api.services.compute.model.Firewall)

Aggregations

Firewall (com.google.api.services.compute.model.Firewall)2 FirewallList (com.google.api.services.compute.model.FirewallList)2 IOException (java.io.IOException)2 Compute (com.google.api.services.compute.Compute)1 MachineType (com.google.api.services.compute.model.MachineType)1 MachineTypeList (com.google.api.services.compute.model.MachineTypeList)1 Network (com.google.api.services.compute.model.Network)1 NetworkList (com.google.api.services.compute.model.NetworkList)1 RegionList (com.google.api.services.compute.model.RegionList)1 Subnetwork (com.google.api.services.compute.model.Subnetwork)1 Strings (com.google.common.base.Strings)1 PlatformResources (com.sequenceiq.cloudbreak.cloud.PlatformResources)1 GcpStackUtil (com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil)1 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)1 CloudAccessConfigs (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudGateWays (com.sequenceiq.cloudbreak.cloud.model.CloudGateWays)1 CloudIpPools (com.sequenceiq.cloudbreak.cloud.model.CloudIpPools)1 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)1 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)1