public T fromPublicIPAddress(PublicIPAddress in) { return this .id(in.getId()) .account(in.getAccount()) .allocated(in.getAllocated()) .associatedNetworkId(in.getAssociatedNetworkId()) .domain(in.getDomain()) .domainId(in.getDomainId()) .usesVirtualNetwork(in.isUsesVirtualNetwork()) .IPAddress(in.getIPAddress()) .isSourceNAT(in.isSourceNAT()) .isStaticNAT(in.isStaticNAT()) .networkId(in.getNetworkId()) .state(in.getState()) .virtualMachineDisplayName(in.getVirtualMachineDisplayName()) .virtualMachineId(in.getVirtualMachineId()) .virtualMachineName(in.getVirtualMachineName()) .VLANId(in.getVLANId()) .VLANName(in.getVLANName()) .zoneId(in.getZoneId()) .zoneName(in.getZoneName()) .jobId(in.getJobId()) .jobStatus(in.getJobStatus()); } }
public PublicIPAddress build() { return new PublicIPAddress(id, account, allocated, associatedNetworkId, domain, domainId, usesVirtualNetwork, IPAddress, isSourceNAT, isStaticNAT, networkId, state, virtualMachineDisplayName, virtualMachineId, virtualMachineName, VLANId, VLANName, zoneId, zoneName, jobId, jobStatus); }
@Override public boolean apply(PublicIPAddress arg0) { return !checkNotNull(arg0, "ipaddress").isSourceNAT() && !arg0.isStaticNAT() && arg0.getVirtualMachineId() == null && arg0.getState() == PublicIPAddress.State.ALLOCATED; }
protected void checkIP(PublicIPAddress ip) { assertEquals(ip.getId(), client.getAddressClient().getPublicIPAddress(ip.getId()).getId()); assert ip.getId() != null : ip; assert ip.getAccount() != null : ip; assert ip.getDomain() != null : ip; assert ip.getDomainId() != null : ip; assert ip.getState() != null : ip; assert ip.getZoneId() != null : ip; assert ip.getZoneName() != null : ip; } }
protected void systemCreatePublicIpHostnameForForwarding() { PublicIPAddress ip = systemCreatePublicIpHostname(); sensors().set(PUBLIC_HOSTNAME, ip.getIPAddress()); sensors().set(PUBLIC_HOSTNAME_IP_ADDRESS_ID, ip.getId()); }
public void testListPublicIPAddresss() throws Exception { if (!networksEnabled) return; Set<PublicIPAddress> response = client.getAddressClient().listPublicIPAddresses(); assert null != response; assertTrue(response.size() >= 0); for (PublicIPAddress ip : response) { PublicIPAddress newDetails = getOnlyElement(client.getAddressClient().listPublicIPAddresses( ListPublicIPAddressesOptions.Builder.id(ip.getId()))); assertEquals(ip.getId(), newDetails.getId()); checkIP(ip); } }
public Set<IPForwardingRule> 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.<IPForwardingRule> of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getNATClient().createIPForwardingRule(ip.getId(), protocol, port); logger.debug(">> creating IP forwarding rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response); } Builder<IPForwardingRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { IPForwardingRule rule = blockUntilJobCompletesAndReturnResult.<IPForwardingRule> apply(response); rules.add(rule); getIPForwardingRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); } }
public PublicIPAddress apply(VirtualMachine vm) { PublicIPAddress ip; for (ip = reuseOrAssociate.apply(network); !ip.isStaticNAT() || ip.getVirtualMachineId() != vm.getId(); ip = reuseOrAssociate .apply(network)) { // check to see if someone already grabbed this ip if (ip.getVirtualMachineId() != null && ip.getVirtualMachineId() != vm.getId()) continue; try { logger.debug(">> static NATing IPAddress(%s) to virtualMachine(%s)", ip.getId(), vm.getId()); client.getNATClient().enableStaticNATForVirtualMachine(vm.getId(), ip.getId()); ip = client.getAddressClient().getPublicIPAddress(ip.getId()); if (ip.isStaticNAT() && ip.getVirtualMachineId().equals(vm.getId())) break; } catch (IllegalStateException e) { // very likely an ip conflict, so retry; } return ip; } return ip; } }
public void apply(Entity source, Object valueIgnored) { Location targetVm = Iterables.getOnlyElement(getLocations(), null); if (targetVm==null) { log.warn("Skipping adding public IP to "+this+" because it does not have a location"); return; } PublicIPAddress ip = systemCreatePublicIpHostname(); setAttributeIfChanged(whereToAdvertiseHostname, ip.getIPAddress()); } }
public void testIsAvailableWhenAllocated() { PublicIPAddress address = PublicIPAddress.builder().state(PublicIPAddress.State.ALLOCATED).id("204").build(); assert available().apply(address); }
public static PublicIPAddress associateIPAddressInNetwork(Network network, CloudStackClient client, BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult) { AsyncCreateResponse job = client.getAddressClient().associateIPAddressInZone(network.getZoneId(), networkId(network.getId())); PublicIPAddress ip = blockUntilJobCompletesAndReturnResult.<PublicIPAddress> apply(job); assert ip.getZoneId().equals(network.getZoneId()); return ip; }
protected void checkIP(PublicIPAddress ip) { assertEquals(ip.getId(), client.getAddressApi().getPublicIPAddress(ip.getId()).getId()); assert ip.getId() != null : ip; assert ip.getAccount() != null : ip; assert ip.getDomain() != null : ip; assert ip.getDomainId() != null : ip; assert ip.getState() != null : ip; assert ip.getZoneId() != null : ip; assert ip.getZoneName() != null : ip; } }
public void apply(Entity source, Object valueIgnored) { Location targetVm = Iterables.getOnlyElement(serviceToOpen.getLocations(), null); if (targetVm==null) { log.warn("Skipping port forward rule for "+serviceToOpen+" because it does not have a location"); return; } if (isSubnetEnabled()) { PublicIPAddress ip = systemCreatePublicIpHostname(); serviceToOpen.sensors().set(sensorAdvertisingHostname, ip.getIPAddress()); boolean success = systemEnableStaticNat(ip.getId(), targetVm); if (success) { log.debug("Enabled static NAT via to {} via {} (VM {})", new Object[] {serviceToOpen, ip, targetVm}); } } } }
public void testListPublicIPAddresss() throws Exception { if (!networksEnabled) return; Set<PublicIPAddress> response = client.getAddressApi().listPublicIPAddresses(); assert null != response; assertTrue(response.size() > 0); for (PublicIPAddress ip : response) { PublicIPAddress newDetails = getOnlyElement(client.getAddressApi().listPublicIPAddresses( ListPublicIPAddressesOptions.Builder.id(ip.getId()))); assertEquals(ip.getId(), newDetails.getId()); checkIP(ip); } }
@Override public boolean apply(PublicIPAddress arg0) { return !checkNotNull(arg0, "ipaddress").isSourceNAT() && !arg0.isStaticNAT() && arg0.getVirtualMachineId() == null && arg0.getState() == PublicIPAddress.State.ALLOCATED; }
public Set<IPForwardingRule> 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.<IPForwardingRule> of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getNATClient().createIPForwardingRule(ip.getId(), protocol, port); logger.debug(">> creating IP forwarding rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response); } Builder<IPForwardingRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { IPForwardingRule rule = blockUntilJobCompletesAndReturnResult.<IPForwardingRule> apply(response); rules.add(rule); getIPForwardingRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); } }
public PublicIPAddress apply(VirtualMachine vm) { PublicIPAddress ip; for (ip = reuseOrAssociate.apply(network); !ip.isStaticNAT() || ip.getVirtualMachineId() != vm.getId(); ip = reuseOrAssociate .apply(network)) { // check to see if someone already grabbed this ip if (ip.getVirtualMachineId() != null && ip.getVirtualMachineId() != vm.getId()) continue; try { logger.debug(">> static NATing IPAddress(%s) to virtualMachine(%s)", ip.getId(), vm.getId()); client.getNATClient().enableStaticNATForVirtualMachine(vm.getId(), ip.getId()); ip = client.getAddressClient().getPublicIPAddress(ip.getId()); if (ip.isStaticNAT() && ip.getVirtualMachineId().equals(vm.getId())) break; } catch (IllegalStateException e) { // very likely an ip conflict, so retry; } return ip; } return ip; } }
private void loopAndCheckSSH() throws IOException { for (int i = 0; i < 5; i++) {// retry loop TODO replace with predicate. try { checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22)); return; } catch (SshException e) { e.printStackTrace(); try { Thread.sleep(10 * 1000); } catch (InterruptedException e1) { } continue; } } }
public void testIsNotAvailableWhenNotAllocated() { PublicIPAddress address = PublicIPAddress.builder().state(PublicIPAddress.State.ALLOCATING).id("204").build(); assert !available().apply(address); }
public static PublicIPAddress associateIPAddressInNetwork(Network network, CloudStackClient client, BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult) { AsyncCreateResponse job = client.getAddressClient().associateIPAddressInZone(network.getZoneId(), networkId(network.getId())); PublicIPAddress ip = blockUntilJobCompletesAndReturnResult.<PublicIPAddress> apply(job); assert ip.getZoneId().equals(network.getZoneId()); return ip; }