/** * @see CreateFirewallRuleOptions#endPort */ public static CreateFirewallRuleOptions endPort(int endPort) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.endPort(endPort); }
/** * @see CreateFirewallRuleOptions#CIDRs */ public static CreateFirewallRuleOptions CIDRs(Set<String> CIDRs) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.CIDRs(CIDRs); }
/** * @see CreateFirewallRuleOptions#icmpCode */ public static CreateFirewallRuleOptions icmpCode(String icmpCode) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.icmpCode(icmpCode); }
/** * @see CreateFirewallRuleOptions#icmpType */ public static CreateFirewallRuleOptions icmpType(String icmpType) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.icmpType(icmpType); } }
/** * @see CreateFirewallRuleOptions#startPort */ public static CreateFirewallRuleOptions startPort(int startPort) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.startPort(startPort); }
public Set<FirewallRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { checkState(ip.getVirtualMachineId() != null, "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.size(ports) == 0) return ImmutableSet.<FirewallRule> of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getFirewallClient().createFirewallRuleForIpAndProtocol(ip.getId(), FirewallRule.Protocol.fromValue(protocol), CreateFirewallRuleOptions.Builder.startPort(port).endPort(port)); logger.debug(">> creating firewall rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response); } Builder<FirewallRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { FirewallRule rule = blockUntilJobCompletesAndReturnResult.<FirewallRule> apply(response); rules.add(rule); getFirewallRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); } }
protected boolean systemOpenFirewall(String publicIpId, Cidr cidr, int lowerBoundPort, int upperBoundPort, FirewallRule.Protocol protocol) { try { boolean success = true; CreateFirewallRuleOptions options = CreateFirewallRuleOptions.Builder. startPort(lowerBoundPort).endPort(upperBoundPort).CIDRs(ImmutableSet.of(cidr.toString())); AsyncCreateResponse job = cloudstackClient.getCloudstackGlobalClient().getFirewallApi().createFirewallRuleForIpAndProtocol( publicIpId, protocol, options); success &= cloudstackClient.waitForJobsSuccess(Arrays.asList(job.getJobId())); if (!success) { log.error("Failed creating firewall rule on "+this+" to "+publicIpId+":"+lowerBoundPort+"-"+upperBoundPort); // it might already be created, so don't crash and burn too hard! return false; } } catch (Exception e) { log.error("Failed creating firewall rule on "+this+" to "+publicIpId+":"+lowerBoundPort+"-"+upperBoundPort); // it might already be created, so don't crash and burn too hard! return false; } return true; }
public Set<FirewallRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { checkState(ip.getVirtualMachineId() != null, "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.size(ports) == 0) return ImmutableSet.<FirewallRule> of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getFirewallClient().createFirewallRuleForIpAndProtocol(ip.getId(), FirewallRule.Protocol.fromValue(protocol), CreateFirewallRuleOptions.Builder.startPort(port).endPort(port)); logger.debug(">> creating firewall rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response); } Builder<FirewallRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { FirewallRule rule = blockUntilJobCompletesAndReturnResult.<FirewallRule> apply(response); rules.add(rule); getFirewallRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); } }
/** * @see CreateFirewallRuleOptions#icmpType */ public static CreateFirewallRuleOptions icmpType(String icmpType) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.icmpType(icmpType); } }
/** * @see CreateFirewallRuleOptions#startPort */ public static CreateFirewallRuleOptions startPort(int startPort) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.startPort(startPort); }
public Set<FirewallRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { checkState(ip.getVirtualMachineId() != null, "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.isEmpty(ports)) return ImmutableSet.<FirewallRule> of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getFirewallApi().createFirewallRuleForIpAndProtocol(ip.getId(), FirewallRule.Protocol.fromValue(protocol), CreateFirewallRuleOptions.Builder.startPort(port).endPort(port)); logger.debug(">> creating firewall rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response); } Builder<FirewallRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { FirewallRule rule = blockUntilJobCompletesAndReturnResult.<FirewallRule> apply(response); rules.add(rule); getFirewallRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); } }
/** * @see CreateFirewallRuleOptions#endPort */ public static CreateFirewallRuleOptions endPort(int endPort) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.endPort(endPort); }
/** * @see CreateFirewallRuleOptions#CIDRs */ public static CreateFirewallRuleOptions CIDRs(Set<String> CIDRs) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.CIDRs(CIDRs); }
/** * @see CreateFirewallRuleOptions#icmpCode */ public static CreateFirewallRuleOptions icmpCode(String icmpCode) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.icmpCode(icmpCode); }
/** * @see CreateFirewallRuleOptions#icmpType */ public static CreateFirewallRuleOptions icmpType(String icmpType) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.icmpType(icmpType); } }
/** * @see CreateFirewallRuleOptions#startPort */ public static CreateFirewallRuleOptions startPort(int startPort) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.startPort(startPort); }
@Test(dependsOnMethods = "testCreatePortForwardingRule") public void testCreateFirewallRule() { if (networksDisabled) return; AsyncCreateResponse job = client.getFirewallClient().createFirewallRuleForIpAndProtocol( ip.getId(), FirewallRule.Protocol.TCP, CreateFirewallRuleOptions.Builder.startPort(30).endPort(35)); assertTrue(jobComplete.apply(job.getJobId())); firewallRule = client.getFirewallClient().getFirewallRule(job.getId()); assertEquals(firewallRule.getStartPort(), 30); assertEquals(firewallRule.getEndPort(), 35); assertEquals(firewallRule.getProtocol(), FirewallRule.Protocol.TCP); checkFirewallRule(firewallRule); }
/** * @see CreateFirewallRuleOptions#endPort */ public static CreateFirewallRuleOptions endPort(int endPort) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.endPort(endPort); }
/** * @see CreateFirewallRuleOptions#CIDRs */ public static CreateFirewallRuleOptions CIDRs(Set<String> CIDRs) { CreateFirewallRuleOptions options = new CreateFirewallRuleOptions(); return options.CIDRs(CIDRs); }