use of com.emc.storageos.db.client.model.IpInterface in project coprhd-controller by CoprHD.
the class HostInterfaceLabelMigration method processIpInterfaces.
private void processIpInterfaces() {
DbClient dbClient = getDbClient();
List<URI> uris = dbClient.queryByType(IpInterface.class, false);
Iterator<IpInterface> objects = dbClient.queryIterativeObjects(IpInterface.class, uris);
while (objects.hasNext()) {
IpInterface ipinterface = objects.next();
if (ipinterface.getLabel() == null || ipinterface.getLabel().isEmpty()) {
log.info("Setting label of " + ipinterface.getId() + " to " + ipinterface.getIpAddress());
ipinterface.setLabel(ipinterface.getIpAddress());
dbClient.persistObject(ipinterface);
}
}
}
use of com.emc.storageos.db.client.model.IpInterface in project coprhd-controller by CoprHD.
the class DbHostInterfaceLabelMigrationTest method prepareIpInterfaceData.
private void prepareIpInterfaceData() {
for (int i = 0; i < INSTANCES_TO_CREATE / 2; i++) {
IpInterface ipinterface = new IpInterface();
ipinterface.setId(URIUtil.createId(IpInterface.class));
ipinterface.setIpAddress("10.0.0." + i);
_dbClient.createObject(ipinterface);
}
for (int i = 0; i < INSTANCES_TO_CREATE / 2; i++) {
IpInterface ipinterface = new IpInterface();
ipinterface.setId(URIUtil.createId(IpInterface.class));
ipinterface.setHost(URIUtil.createId(Host.class));
ipinterface.setIpAddress("10.0.1." + i);
ipinterface.setLabel("label" + i);
_dbClient.createObject(ipinterface);
}
List<URI> list = _dbClient.queryByType(IpInterface.class, false);
int count = 0;
for (@SuppressWarnings("unused") URI ignore : list) {
count++;
}
Assert.assertTrue("Expected " + INSTANCES_TO_CREATE + " prepared " + IpInterface.class.getSimpleName() + ", found only " + count, count == INSTANCES_TO_CREATE);
}
use of com.emc.storageos.db.client.model.IpInterface in project coprhd-controller by CoprHD.
the class DbHostInterfaceLabelMigrationTest method verifyIpInterfaceData.
private void verifyIpInterfaceData() {
List<URI> list = _dbClient.queryByType(IpInterface.class, false);
int count = 0;
Iterator<IpInterface> objs = _dbClient.queryIterativeObjects(IpInterface.class, list);
while (objs.hasNext()) {
IpInterface ipinterface = objs.next();
count++;
Assert.assertNotNull("Label for ipInterface shouldn't be null", ipinterface.getLabel());
if (ipinterface.getHost() != null) {
Assert.assertNotSame("Label should not be equal to the ipAddress", ipinterface.getLabel(), ipinterface.getIpAddress());
} else {
Assert.assertEquals("Label should equal to ipAddress", ipinterface.getLabel(), ipinterface.getIpAddress());
}
}
Assert.assertTrue("We should still have " + INSTANCES_TO_CREATE + " " + IpInterface.class.getSimpleName() + " after migration, not " + count, count == INSTANCES_TO_CREATE);
}
use of com.emc.storageos.db.client.model.IpInterface in project coprhd-controller by CoprHD.
the class BasePermissionsHelper method getTenantResourceTenantId.
/**
* Get tenant id from a project id retrieved from uri
*
* @param childId
* @return
*/
public URI getTenantResourceTenantId(String childId) {
if (childId == null) {
return null;
}
try {
URI id = URI.create(childId);
TenantResource ret = null;
if (URIUtil.isType(id, Host.class)) {
ret = getObjectById(id, Host.class);
} else if (URIUtil.isType(id, VcenterDataCenter.class)) {
ret = getObjectById(id, VcenterDataCenter.class);
} else if (URIUtil.isType(id, Cluster.class)) {
ret = getObjectById(id, Cluster.class);
} else if (URIUtil.isType(id, Initiator.class)) {
Initiator ini = getObjectById(id, Initiator.class);
if (ini.getHost() != null) {
ret = getObjectById(ini.getHost(), Host.class);
}
} else if (URIUtil.isType(id, IpInterface.class)) {
IpInterface hostIf = getObjectById(id, IpInterface.class);
if (hostIf.getHost() != null) {
ret = getObjectById(hostIf.getHost(), Host.class);
}
} else {
throw APIException.badRequests.theURIIsNotOfType(id, TenantResource.class.getName());
}
if (ret == null) {
throw FatalDatabaseException.fatals.unableToFindEntity(id);
}
return ret.getTenant();
} catch (DatabaseException ex) {
throw SecurityException.fatals.failedGettingTenant(ex);
}
}
use of com.emc.storageos.db.client.model.IpInterface in project coprhd-controller by CoprHD.
the class WindowsHostDiscoveryAdapter method discoverIpInterfaces.
@Override
protected void discoverIpInterfaces(Host host, List<IpInterface> oldIpInterfaces) {
WindowsSystemWinRM windows = createWindowsSystem(host);
try {
for (NetworkAdapter adapter : windows.listNetworkAdapters()) {
if (StringUtils.isNotBlank(adapter.getIpAddress())) {
IpInterface ipInterface = getOrCreateIpInterface(oldIpInterfaces, adapter.getIpAddress());
discoverIp4Interface(host, ipInterface, adapter);
}
if (StringUtils.isNotBlank(adapter.getIp6Address())) {
IpInterface ipInterface = getOrCreateIpInterface(oldIpInterfaces, adapter.getIp6Address());
discoverIp6Interface(host, ipInterface, adapter);
}
}
} catch (WinRMException e) {
warn(e, "Error while retrieving IP interfaces: %s", e.getMessage());
oldIpInterfaces.clear();
}
}
Aggregations