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; }
protected void assignPrimaryIpAddress(Instance instance, Map<String, Object> resultData) { int min = Integer.MAX_VALUE; IpAddress ip = null; IpAddress fallBackIp = null; for (Nic nic : getObjectManager().children(instance, Nic.class)) { if (nic.getDeviceNumber().intValue() < min) { min = nic.getDeviceNumber(); ip = ipAddressDao.getPrimaryIpAddress(nic); if (ip == null) { List<IpAddress> ips = getObjectManager().mappedChildren(nic, IpAddress.class); if (ips.size() > 0) { fallBackIp = ips.get(0); } } } } String address = null; if (ip == null) { address = fallBackIp == null ? null : fallBackIp.getAddress(); } else { address = ip.getAddress(); } if (address != null) { resultData.put(InstanceConstants.FIELD_PRIMARY_IP_ADDRESS, address); } }
protected void populateNic(IdFormatter idFormatter, Map<String, Object> instanceData, Nic nic, Network network) { Integer deviceNumber = nic.getDeviceNumber(); String mac = nic.getMacAddress(); if (mac == null) { return; } @SuppressWarnings("unchecked") Map<String, Object> data = (Map<String, Object>) CollectionUtils.getNestedValue(instanceData, "network", "interfaces", "macs", mac); if (data == null) { data = new HashMap<String, Object>(); setNestedValue(instanceData, data, "network", "interfaces", "macs", mac); } else { return; } data.put("device-number", deviceNumber); data.put("mac", nic.getMacAddress()); data.put("owner-id", formatId(idFormatter, Instance.class, nic.getInstanceId())); // TODO don't have a security group concept yet data.put("security-group-ids", ""); data.put("security-groups", ""); data.put("vpc-id", formatId(idFormatter, Network.class, network.getId())); data.put("vpc-ipv4-cidr-block", DataAccessor.fieldString(network, NetworkConstants.FIELD_CIDR)); if (deviceNumber != null && deviceNumber.intValue() == 0) { instanceData.put("mac", nic.getMacAddress()); setNestedValue(instanceData, HostnameGenerator.getServicesDomain(network), "services", "domain"); } }
protected void populateIps(IdFormatter idFormatter, Map<Long, String> primaryIps, Map<String, Object> instanceMetadata, Instance instance, Nic nic, Network network, Subnet subnet, IpAddress localIp) { boolean firstNic = (org.apache.commons.lang3.ObjectUtils.equals(nic.getDeviceNumber(), 0)); boolean primaryIp = localIp == null ? firstNic : IpAddressConstants.ROLE_PRIMARY.equals(localIp.getRole());
Integer device = nic.getDeviceNumber();
/** * {@inheritDoc} */ @Override public void from(io.cattle.platform.core.model.Nic 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()); setInstanceId(from.getInstanceId()); setNetworkId(from.getNetworkId()); setDeviceNumber(from.getDeviceNumber()); setMacAddress(from.getMacAddress()); }