protected IpAddress getIpAddress(Host host) { IpAddress choice = null; for (IpAddress ip : objectManager.mappedChildren(host, IpAddress.class)) { if (ip.getAddress() == null || !CommonStatesConstants.ACTIVE.equals(ip.getState())) { continue; } if (IpAddressConstants.ROLE_PRIMARY.equals(ip.getRole())) { choice = ip; break; } else if (choice == null || choice.getCreated() == null) { choice = ip; } else if (ip.getCreated() != null && ip.getCreated().before(choice.getCreated())) { choice = ip; } } return choice; }
protected Instance getInstanceForPrimaryIp(IpAddress ipAddress) { if (IpAddressConstants.ROLE_PRIMARY.equals(ipAddress.getRole())) { for (Nic nic : getObjectManager().mappedChildren(ipAddress, Nic.class)) { if (nic.getDeviceNumber() != null && nic.getDeviceNumber() == 0) { Instance instance = getObjectManager().loadResource(Instance.class, nic.getInstanceId()); if (instance != null) { return instance; } } } } return null; }
boolean primaryIp = localIp == null ? firstNic : IpAddressConstants.ROLE_PRIMARY.equals(localIp.getRole());
@Override public IpAddress getPrimaryIpAddress(Nic nic) { List<? extends IpAddress> ipAddresses = create() .select(IP_ADDRESS.fields()) .from(IP_ADDRESS) .join(IP_ADDRESS_NIC_MAP) .on(IP_ADDRESS_NIC_MAP.IP_ADDRESS_ID.eq(IP_ADDRESS.ID) .and(IP_ADDRESS_NIC_MAP.NIC_ID.eq(nic.getId()))) .where(IP_ADDRESS_NIC_MAP.REMOVED.isNull()) .fetchInto(IpAddressRecord.class); if (ipAddresses.size() == 1) { return ipAddresses.get(0); } for (IpAddress ipAddress : ipAddresses) { if (IpAddressConstants.ROLE_PRIMARY.equals(ipAddress.getRole())) { return ipAddress; } } return null; }
/** * {@inheritDoc} */ @Override public void from(io.cattle.platform.core.model.IpAddress from) { setId(from.getId()); setName(from.getName()); setAccountId(from.getAccountId()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription()); setState(from.getState()); setCreated(from.getCreated()); setRemoved(from.getRemoved()); setRemoveTime(from.getRemoveTime()); setData(from.getData()); setAddress(from.getAddress()); setSubnetId(from.getSubnetId()); setNetworkId(from.getNetworkId()); setIsPublic(from.getIsPublic()); setRole(from.getRole()); setHostname(from.getHostname()); }