@Override public boolean apply(PortForwardingRule portForwardingRule) { return portForwardingRule.getVirtualMachineId().equals(vmId); } });
@Override public int compareTo(PortForwardingRule o) { return id.compareTo(o.getId()); } }
public PortForwardingRule build() { return new PortForwardingRule(id, IPAddress, IPAddressId, privatePort, protocol, publicPort, state, virtualMachineDisplayName, virtualMachineId, virtualMachineName, CIDRs, privateEndPort, publicEndPort); }
public T fromPortForwardingRule(PortForwardingRule in) { return this .id(in.getId()) .IPAddress(in.getIPAddress()) .IPAddressId(in.getIPAddressId()) .privatePort(in.getPrivatePort()) .protocol(in.getProtocol()) .publicPort(in.getPublicPort()) .state(in.getState()) .virtualMachineDisplayName(in.getVirtualMachineDisplayName()) .virtualMachineId(in.getVirtualMachineId()) .virtualMachineName(in.getVirtualMachineName()) .CIDRs(in.getCIDRs()) .privateEndPort(in.getPrivateEndPort()) .publicEndPort(in.getPublicEndPort()); } }
protected void checkPortForwardingRule(PortForwardingRule rule) { assertEquals(rule, client.getFirewallClient().getPortForwardingRule(rule.getId())); assert rule.getId() != null : rule; assert rule.getIPAddress() != null : rule; assert rule.getIPAddressId() != null : rule; assert rule.getPrivatePort() > 0 : rule; assert rule.getProtocol() != null : rule; assert rule.getPublicPort() > 0 : rule; assert rule.getState() != null : rule; assert rule.getVirtualMachineId() != null : rule; assert rule.getVirtualMachineName() != null : rule; } }
public void testCreatePortForwardingRule() throws Exception { if (networksDisabled) return; while (portForwardingRule == null) { ip = reuseOrAssociate.apply(network); try { AsyncCreateResponse job = client.getFirewallClient() .createPortForwardingRuleForVirtualMachine(ip.getId(), PortForwardingRule.Protocol.TCP, 22, vm.getId(), 22); assertTrue(jobComplete.apply(job.getJobId())); portForwardingRule = client.getFirewallClient().getPortForwardingRule(job.getId()); } catch (IllegalStateException e) { Logger.CONSOLE.error("Failed while trying to allocate ip: " + e); // very likely an ip conflict, so retry; } } assertEquals(portForwardingRule.getIPAddressId(), ip.getId()); assertEquals(portForwardingRule.getVirtualMachineId(), vm.getId()); assertEquals(portForwardingRule.getPublicPort(), 22); assertEquals(portForwardingRule.getProtocol(), PortForwardingRule.Protocol.TCP); checkPortForwardingRule(portForwardingRule); checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22)); }
public Maybe<PublicIPAddress> findPublicIpAddressByVmId(final String vmId) { Set<PortForwardingRule> portForwardingRules = getCloudstackGlobalClient().getFirewallApi().listPortForwardingRules(); Optional<PortForwardingRule> pfr = Iterables.tryFind(portForwardingRules, new Predicate<PortForwardingRule>() { @Override public boolean apply(PortForwardingRule portForwardingRule) { return portForwardingRule.getVirtualMachineId().equals(vmId); } }); if (pfr.isPresent()) { return Maybe.of(getCloudstackGlobalClient().getAddressApi().getPublicIPAddress(pfr.get().getIPAddressId())); } else { return Maybe.absent(); } } }
public T fromPortForwardingRule(PortForwardingRule in) { return this .id(in.getId()) .IPAddress(in.getIPAddress()) .IPAddressId(in.getIPAddressId()) .privatePort(in.getPrivatePort()) .protocol(in.getProtocol()) .publicPort(in.getPublicPort()) .state(in.getState()) .virtualMachineDisplayName(in.getVirtualMachineDisplayName()) .virtualMachineId(in.getVirtualMachineId()) .virtualMachineName(in.getVirtualMachineName()) .CIDRs(in.getCIDRs()) .privateEndPort(in.getPrivateEndPort()) .publicEndPort(in.getPublicEndPort()); } }
protected void checkPortForwardingRule(PortForwardingRule rule) { assertEquals(rule, client.getFirewallApi().getPortForwardingRule(rule.getId())); assert rule.getId() != null : rule; assert rule.getIPAddress() != null : rule; assert rule.getIPAddressId() != null : rule; assert rule.getPrivatePort() > 0 : rule; assert rule.getProtocol() != null : rule; assert rule.getPublicPort() > 0 : rule; assert rule.getState() != null : rule; assert rule.getVirtualMachineId() != null : rule; assert rule.getVirtualMachineName() != null : rule; } }
public void testCreatePortForwardingRule() throws Exception { if (networksDisabled) return; while (portForwardingRule == null) { ip = reuseOrAssociate.apply(network); try { AsyncCreateResponse job = client.getFirewallApi() .createPortForwardingRuleForVirtualMachine(ip.getId(), PortForwardingRule.Protocol.TCP, 22, vm.getId(), 22); assertTrue(jobComplete.apply(job.getJobId())); portForwardingRule = client.getFirewallApi().getPortForwardingRule(job.getId()); } catch (IllegalStateException e) { Logger.CONSOLE.error("Failed while trying to allocate ip: " + e); // very likely an ip conflict, so retry; } } assertEquals(portForwardingRule.getIPAddressId(), ip.getId()); assertEquals(portForwardingRule.getVirtualMachineId(), vm.getId()); assertEquals(portForwardingRule.getPublicPort(), 22); assertEquals(portForwardingRule.getProtocol(), PortForwardingRule.Protocol.TCP); checkPortForwardingRule(portForwardingRule); checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22)); }
public T fromPortForwardingRule(PortForwardingRule in) { return this .id(in.getId()) .IPAddress(in.getIPAddress()) .IPAddressId(in.getIPAddressId()) .privatePort(in.getPrivatePort()) .protocol(in.getProtocol()) .publicPort(in.getPublicPort()) .state(in.getState()) .virtualMachineDisplayName(in.getVirtualMachineDisplayName()) .virtualMachineId(in.getVirtualMachineId()) .virtualMachineName(in.getVirtualMachineName()) .CIDRs(in.getCIDRs()) .privateEndPort(in.getPrivateEndPort()) .publicEndPort(in.getPublicEndPort()) .tags(in.getTags()); } }
@Override public int compareTo(PortForwardingRule o) { return id.compareTo(o.getId()); } }
public PortForwardingRule build() { return new PortForwardingRule(id, IPAddress, IPAddressId, privatePort, protocol, publicPort, state, virtualMachineDisplayName, virtualMachineId, virtualMachineName, CIDRs, privateEndPort, publicEndPort); }
@Override public int compareTo(PortForwardingRule o) { return id.compareTo(o.getId()); } }
public PortForwardingRule build() { return new PortForwardingRule(id, IPAddress, IPAddressId, privatePort, protocol, publicPort, state, virtualMachineDisplayName, virtualMachineId, virtualMachineName, CIDRs, privateEndPort, publicEndPort, tags); }
@AfterGroups(groups = "live") @Override protected void tearDownContext() { if (firewallRule != null) { client.getFirewallClient().deleteFirewallRule(firewallRule.getId()); } if (portForwardingRule != null) { client.getFirewallClient().deletePortForwardingRule(portForwardingRule.getId()); } if (vm != null) { jobComplete.apply(client.getVirtualMachineClient().destroyVirtualMachine(vm.getId())); } if (ip != null) { client.getAddressClient().disassociateIPAddress(ip.getId()); } super.tearDownContext(); }
@AfterGroups(groups = "live") @Override protected void tearDownContext() { if (firewallRule != null) { client.getFirewallApi().deleteFirewallRule(firewallRule.getId()); } if (egressFirewallRule != null) { client.getFirewallApi().deleteEgressFirewallRule(egressFirewallRule.getId()); } if (portForwardingRule != null) { client.getFirewallApi().deletePortForwardingRule(portForwardingRule.getId()); } if (vm != null) { jobComplete.apply(client.getVirtualMachineApi().destroyVirtualMachine(vm.getId())); } if (ip != null) { client.getAddressApi().disassociateIPAddress(ip.getId()); } super.tearDownContext(); }