Search in sources :

Example 1 with NetworkSystem

use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.

the class NetworkSystemService method updateNetworkSystem.

/**
 * Updates an already present network system by matching the URI. This can be used to
 * change the IP address or port, change the credentials, or update the name of a
 * network sytem. A refresh (discovery) is asynchronously initiated as a result of this call.
 *
 * @param id - the URN of a ViPR NetworkSystem
 * @param param structure contains all the parameters that can be updated.
 * @prereq none
 * @brief Update network system
 * @return The rest representation for the updated NetworkSystem
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep updateNetworkSystem(@PathParam("id") URI id, NetworkSystemUpdate param) throws InternalException {
    ArgValidator.checkFieldUriType(id, NetworkSystem.class, "id");
    NetworkSystem device = _dbClient.queryObject(NetworkSystem.class, id);
    ArgValidator.checkEntityNotNull(device, id, isIdEmbeddedInURL(id));
    // Check for existing device.
    checkForDuplicateDevice(device.getId(), param.getIpAddress(), param.getPortNumber(), param.getSmisProviderIp(), param.getSmisPortNumber(), param.getName());
    if (param.getName() != null) {
        device.setLabel(param.getName());
    }
    if (param.getIpAddress() != null) {
        device.setIpAddress(param.getIpAddress());
    }
    if (param.getPortNumber() != null) {
        device.setPortNumber(param.getPortNumber());
    }
    if (param.getUserName() != null) {
        device.setUsername(param.getUserName());
    }
    if (param.getPassword() != null) {
        device.setPassword(param.getPassword());
    }
    if (param.getSmisProviderIp() != null) {
        device.setSmisProviderIP(param.getSmisProviderIp());
    }
    if (param.getSmisPortNumber() != null) {
        device.setSmisPortNumber(param.getSmisPortNumber());
    }
    if (param.getSmisUserName() != null) {
        device.setSmisUserName(param.getSmisUserName());
    }
    if (param.getSmisPassword() != null) {
        device.setSmisPassword(param.getSmisPassword());
    }
    if (param.getSmisUseSsl() != null) {
        device.setSmisUseSSL(param.getSmisUseSsl());
    }
    device.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(device));
    _dbClient.updateObject(device);
    startNetworkSystem(device);
    auditOp(OperationTypeEnum.UPDATE_NETWORK_SYSTEM, true, null, device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL(), device.getVersion(), device.getUptime());
    return doDiscoverNetworkSystem(device);
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with NetworkSystem

use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.

the class NetworkSystemService method deleteNetworkSystem.

/**
 * Delete a network system. The method will delete the
 * network system and all resources associated with it.
 *
 * @prereq The network system must be unregistered
 * @brief Delete network system
 * @return An asynchronous task.
 *
 * @throws DatabaseException
 *             When an error occurs querying the database.
 */
@POST
@Path("/{id}/deactivate")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep deleteNetworkSystem(@PathParam("id") URI id) throws DatabaseException {
    NetworkSystem system = queryObject(NetworkSystem.class, id, true);
    ArgValidator.checkEntity(system, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.UNREGISTERED.toString().equals(system.getRegistrationStatus())) {
        throw APIException.badRequests.invalidParameterCannotDeactivateRegisteredNetworkSystem(system.getId());
    }
    if (DiscoveredDataObject.DataCollectionJobStatus.IN_PROGRESS.toString().equals(system.getDiscoveryStatus()) || DiscoveredDataObject.DataCollectionJobStatus.SCHEDULED.toString().equals(system.getDiscoveryStatus())) {
        throw APIException.serviceUnavailable.cannotDeactivateStorageSystemWhileInDiscover(system.getId());
    }
    List<Network> networkList = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Network.class, AlternateIdConstraint.Factory.getConstraint(Network.class, "networkSystems", system.getId().toString()));
    for (Network network : networkList) {
        if (network != null && network.getInactive() != true && network.getConnectedVirtualArrays() != null && !network.getConnectedVirtualArrays().isEmpty() && (network.getNetworkSystems() != null && network.getNetworkSystems().contains(system.getId().toString()) && network.getNetworkSystems().size() == 1)) {
            throw APIException.badRequests.invalidParameterNetworkMustBeUnassignedFromVirtualArray(network.getLabel(), system.getLabel());
        }
    }
    Map<String, List<FCZoneReference>> zonesMap = getNetworkSystemZoneRefs(system);
    List<URI> nsystems = null;
    List<FCZoneReference> zones = null;
    // by the purge process
    for (Network network : networkList) {
        // remove references from ports
        nsystems = StringSetUtil.stringSetToUriList(network.getNetworkSystems());
        nsystems.remove(system.getId());
        if (nsystems.isEmpty()) {
            // This network will be removed - Remove any storage port references
            List<StoragePort> netPorts = NetworkAssociationHelper.getNetworkStoragePorts(network.getId().toString(), null, _dbClient);
            NetworkAssociationHelper.clearPortAssociations(netPorts, _dbClient);
        } else {
            // This network will remain, update any zone references to use another network system
            URI nsUri = nsystems.get(0);
            zones = zonesMap.get(network.getNativeId());
            if (zones != null) {
                for (FCZoneReference zone : zones) {
                    zone.setNetworkSystemUri(nsUri);
                }
                _dbClient.updateObject(zones);
            }
        }
    }
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(NetworkSystem.class, system.getId(), taskId, ResourceOperationTypeEnum.DELETE_NETWORK_SYSTEM);
    PurgeRunnable.executePurging(_dbClient, _dbPurger, _asynchJobService.getExecutorService(), system, _retry_attempts, taskId, 60);
    auditOp(OperationTypeEnum.DELETE_NETWORK_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, system.getId().toString(), system.getLabel(), system.getPortNumber(), system.getUsername(), system.getSmisProviderIP(), system.getSmisPortNumber(), system.getSmisUserName(), system.getSmisUseSSL(), system.getVersion(), system.getUptime());
    return toTask(system, taskId, op);
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) StoragePort(com.emc.storageos.db.client.model.StoragePort) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference) Network(com.emc.storageos.db.client.model.Network) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) NetworkSystemList(com.emc.storageos.model.network.NetworkSystemList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with NetworkSystem

use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.

the class NetworkSystemService method createNetworkSystem.

/**
 * Creates a new network system. This can either represent an SSH connection to a Cisco
 * MDS or Nexus switch, or an SMI-S connection to the Brocade Network Advisor.
 * The call will return before communication has been established, but discovery of
 * the device will be initiated.
 *
 * @param param The NetworkSystemCreate object contains all the parameters for creation.
 * @prereq none
 * @brief Create network system
 * @return A REST representation of the newly created network device.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep createNetworkSystem(NetworkSystemCreate param) throws Exception {
    // check device type
    ArgValidator.checkFieldValueFromSystemType(param.getSystemType(), "system_type", Arrays.asList(NetworkSystem.Type.brocade, NetworkSystem.Type.mds));
    NetworkSystem.Type deviceType = NetworkSystem.Type.valueOf(param.getSystemType());
    if (NetworkSystem.Type.valueOf(param.getSystemType()) == NetworkSystem.Type.brocade) {
        // Validate fields required for brocade
        ArgValidator.checkFieldNotNull(param.getSmisProviderIp(), "smis_provider_ip");
        ArgValidator.checkFieldNotNull(param.getSmisPortNumber(), "smis_port_number");
        ArgValidator.checkFieldNotNull(param.getSmisUserName(), "smis_user_name");
        ArgValidator.checkFieldNotNull(param.getSmisPassword(), "smis_password");
    } else if (NetworkSystem.Type.valueOf(param.getSystemType()) == NetworkSystem.Type.mds) {
        // Validate fields required for mds
        ArgValidator.checkFieldNotNull(param.getIpAddress(), "ip_address");
        ArgValidator.checkFieldNotNull(param.getPortNumber(), "port_number");
        ArgValidator.checkFieldNotNull(param.getUserName(), "user_name");
        ArgValidator.checkFieldNotNull(param.getPassword(), "password");
    }
    // Check for existing device.
    checkForDuplicateDevice(null, param.getIpAddress(), param.getPortNumber(), param.getSmisProviderIp(), param.getSmisPortNumber(), param.getName());
    NetworkSystem device = new NetworkSystem();
    URI id = URIUtil.createId(NetworkSystem.class);
    device.setId(id);
    device.setLabel(param.getName());
    device.setIpAddress(param.getIpAddress());
    device.setPortNumber(param.getPortNumber());
    device.setUsername(param.getUserName());
    device.setPassword(param.getPassword());
    device.setSystemType(deviceType.name());
    device.setSmisProviderIP(param.getSmisProviderIp());
    device.setSmisPortNumber(param.getSmisPortNumber());
    device.setSmisUserName(param.getSmisUserName());
    device.setSmisPassword(param.getSmisPassword());
    device.setSmisUseSSL(param.getSmisUseSsl());
    device.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(device));
    device.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.REGISTERED.name());
    _dbClient.createObject(device);
    auditOp(OperationTypeEnum.CREATE_NETWORK_SYSTEM, true, null, device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL(), device.getVersion(), device.getUptime());
    return doDiscoverNetworkSystem(device);
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) URI(java.net.URI) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with NetworkSystem

use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.

the class NetworkSystemService method getFabrics.

/**
 * Returns a list of the VSAN or fabric names configured on this network system.
 * Note: This is a synchronous call to the device and may take a while to receive a response.
 *
 * @param id the URN of a ViPR network system.
 * @prereq none
 * @brief List network system VSANs and fabrics
 * @return A list of fabric names configured on the Network System.
 * @throws InternalException
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/san-fabrics")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public Fabrics getFabrics(@PathParam("id") URI id) throws InternalException {
    Fabrics fabrics = new Fabrics();
    ArgValidator.checkFieldUriType(id, NetworkSystem.class, "id");
    NetworkSystem device = queryResource(id);
    NetworkController controller = getNetworkController(device.getSystemType());
    List<String> fabricIds = controller.getFabricIds(device.getId());
    fabrics.setFabricIds(fabricIds);
    return fabrics;
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) Fabrics(com.emc.storageos.model.network.Fabrics) NetworkController(com.emc.storageos.networkcontroller.NetworkController) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with NetworkSystem

use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.

the class NetworkSystemService method getAliases.

/**
 * Returns a list of aliases for the specified network system. For Brocade, aliases
 * can be retrieved per fabric only and fabric-id is a required parameter. For MDS,
 * the full list of device aliases for the network system is returned and fabric-id is
 * ignored if provided.
 *
 * Note: This is a synchronous call to the device and may take a while to receive
 * a response.
 *
 * @param id the URN of a ViPR network system.
 * @param fabricId The name of the fabric as returned by
 *            /vdc/network-systems/{id}/san-fabrics or the WWN of the fabric
 * @prereq none
 * @brief List aliases in a network system or a fabric
 * @return A list of aliases.
 * @throws InternalException
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/san-aliases")
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
public WwnAliasesParam getAliases(@PathParam("id") URI id, @QueryParam("fabric-id") String fabricId) throws InternalException {
    ArgValidator.checkFieldUriType(id, NetworkSystem.class, "id");
    NetworkSystem device = queryResource(id);
    if (Type.brocade.toString().equals(device.getSystemType())) {
        ArgValidator.checkFieldNotEmpty(fabricId, "fabric-id");
    }
    String fabricWwn = null;
    if (WWNUtility.isValidWWN(fabricId)) {
        fabricWwn = fabricId;
        fabricId = fabricId.replaceAll(":", "");
    }
    NetworkController controller = getNetworkController(device.getSystemType());
    List<WwnAliasParam> aliases = new ArrayList<WwnAliasParam>(controller.getAliases(device.getId(), fabricId, fabricWwn));
    return new WwnAliasesParam(aliases);
}
Also used : WwnAliasesParam(com.emc.storageos.model.network.WwnAliasesParam) WwnAliasParam(com.emc.storageos.model.network.WwnAliasParam) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) ArrayList(java.util.ArrayList) NetworkController(com.emc.storageos.networkcontroller.NetworkController) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)54 MapNetworkSystem (com.emc.storageos.api.mapper.functions.MapNetworkSystem)21 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)20 Produces (javax.ws.rs.Produces)20 ArrayList (java.util.ArrayList)19 Path (javax.ws.rs.Path)18 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)16 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)16 ControllerException (com.emc.storageos.volumecontroller.ControllerException)16 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)13 URI (java.net.URI)13 NetworkController (com.emc.storageos.networkcontroller.NetworkController)11 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)10 Consumes (javax.ws.rs.Consumes)10 POST (javax.ws.rs.POST)10 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)9 Operation (com.emc.storageos.db.client.model.Operation)8 ZoneMember (com.emc.storageos.networkcontroller.impl.mds.ZoneMember)8 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7