public void createFirewallRule(Firewall rule) throws OpsException { try { log.debug("Inserting firewall rule: " + rule); Operation operation = compute.firewalls().insert(projectId, rule).execute(); waitComplete(operation, 5, TimeUnit.MINUTES); // TODO: Check success of operation? } catch (IOException e) { throw new OpsException("Error creating firewall", e); } catch (TimeoutException e) { throw new OpsException("Timeout while waiting for firewall creation", e); } }
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); } // TODO: Use filter if (firewalls.getItems() != null) { for (Firewall firewall : firewalls.getItems()) { if (firewall.getTargetTags() != null && firewall.getTargetTags().contains(instanceUrl)) { ret.add(firewall); } } } return ret; }