Search in sources :

Example 11 with IpInterface

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);
        }
    }
}
Also used : IpInterface(com.emc.storageos.db.client.model.IpInterface) DbClient(com.emc.storageos.db.client.DbClient) URI(java.net.URI)

Example 12 with 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);
}
Also used : IpInterface(com.emc.storageos.db.client.model.IpInterface) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Example 13 with IpInterface

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);
}
Also used : IpInterface(com.emc.storageos.db.client.model.IpInterface) URI(java.net.URI)

Example 14 with IpInterface

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);
    }
}
Also used : IpInterface(com.emc.storageos.db.client.model.IpInterface) TenantResource(com.emc.storageos.db.client.model.TenantResource) Initiator(com.emc.storageos.db.client.model.Initiator) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) FatalDatabaseException(com.emc.storageos.db.exceptions.FatalDatabaseException)

Example 15 with IpInterface

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();
    }
}
Also used : IpInterface(com.emc.storageos.db.client.model.IpInterface) WindowsSystemWinRM(com.iwave.ext.windows.WindowsSystemWinRM) WinRMException(com.iwave.ext.windows.winrm.WinRMException)

Aggregations

IpInterface (com.emc.storageos.db.client.model.IpInterface)27 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)7 URI (java.net.URI)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 MapIpInterface (com.emc.storageos.api.mapper.functions.MapIpInterface)6 Host (com.emc.storageos.db.client.model.Host)6 POST (javax.ws.rs.POST)4 Initiator (com.emc.storageos.db.client.model.Initiator)3 IPInterface (com.iwave.ext.linux.model.IPInterface)3 ArrayList (java.util.ArrayList)3 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 FileExport (com.emc.storageos.db.client.model.FileExport)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 AixSystem (com.emc.aix.AixSystem)1 HpuxSystem (com.emc.hpux.HpuxSystem)1 MapNetwork (com.emc.storageos.api.mapper.functions.MapNetwork)1 ComputeSystemController (com.emc.storageos.computesystemcontroller.ComputeSystemController)1 DbClient (com.emc.storageos.db.client.DbClient)1