com.google.api.services.compute.model.Firewall Java Examples
The following examples show how to use
com.google.api.services.compute.model.Firewall.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FirewallResourceController.java From pubsub with Apache License 2.0 | 6 votes |
@Override protected void startAction() throws Exception { log.info("Creating firewall"); Firewall firewallRule = new Firewall() .setName(FIREWALL_NAME) .setDescription( "A firewall rule to allow the driver to coordinate load test instances.") .setAllowed( ImmutableList.of( new Firewall.Allowed() .setIPProtocol("tcp") .setPorts(Collections.singletonList("5000")))); try { compute.firewalls().insert(project, firewallRule).execute(); } catch (GoogleJsonResponseException e) { log.info("Firewall error: " + e); if (e.getStatusCode() != HttpStatus.SC_CONFLICT) { throw e; } } }
Example #2
Source File: GcpPlatformResources.java From cloudbreak with Apache License 2.0 | 6 votes |
@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<>(); 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); }
Example #3
Source File: GcpFirewallInResourceBuilder.java From cloudbreak with Apache License 2.0 | 6 votes |
private ComputeRequest<Operation> createNewFirewallRule(GcpContext context, AuthenticatedContext auth, Group group, Network network, Security security, CloudResource buildableResource, String projectId) throws IOException { List<String> sourceRanges = getSourceRanges(security); Firewall firewall = new Firewall(); firewall.setSourceRanges(sourceRanges); List<Allowed> allowedRules = new ArrayList<>(createAllowedRules(security)); firewall.setTargetTags(Collections.singletonList(GcpStackUtil.getGroupClusterTag(auth.getCloudContext(), group))); firewall.setAllowed(allowedRules); firewall.setName(buildableResource.getName()); if (isNotEmpty(getSharedProjectId(network))) { firewall.setNetwork(String.format("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", getSharedProjectId(network), context.getParameter(GcpNetworkResourceBuilder.NETWORK_NAME, String.class))); } else { firewall.setNetwork(String.format("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", projectId, context.getParameter(GcpNetworkResourceBuilder.NETWORK_NAME, String.class))); } return context.getCompute().firewalls().insert(projectId, firewall); }
Example #4
Source File: GcpFirewallInResourceBuilder.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public CloudResourceStatus update(GcpContext context, AuthenticatedContext auth, Group group, Network network, Security security, CloudResource resource) { String projectId = context.getProjectId(); Compute compute = context.getCompute(); String resourceName = resource.getName(); try { Firewall fireWall = compute.firewalls().get(projectId, resourceName).execute(); List<String> sourceRanges = getSourceRanges(security); fireWall.setSourceRanges(sourceRanges); Operation operation = compute.firewalls().update(projectId, resourceName, fireWall).execute(); CloudResource cloudResource = createOperationAwareCloudResource(resource, operation); return checkResources(context, auth, Collections.singletonList(cloudResource)).get(0); } catch (IOException e) { throw new GcpResourceException("Failed to update resource!", GCP_FIREWALL_IN, resourceName, e); } }
Example #5
Source File: GcpFirewallInResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
private Update updateExistingFirewallForNewTargets(GcpContext context, AuthenticatedContext auth, Group group, Security security) throws java.io.IOException { Firewall firewall = context.getCompute().firewalls().get(context.getProjectId(), security.getCloudSecurityId()).execute(); if (firewall.getTargetTags() == null) { firewall.setTargetTags(Lists.newArrayListWithCapacity(1)); } firewall.getTargetTags().add(GcpStackUtil.getGroupClusterTag(auth.getCloudContext(), group)); return context.getCompute().firewalls().update(context.getProjectId(), firewall.getName(), firewall); }
Example #6
Source File: GcpPlatformResources.java From cloudbreak with Apache License 2.0 | 4 votes |
private String getNetworkName(Firewall firewall) { String[] splittedNetworkName = firewall.getNetwork().split("/"); return splittedNetworkName[splittedNetworkName.length - 1]; }