use of netapp.manage.NaServer in project cloudstack by apache.
the class NetappManagerImpl method getServer.
/**
* Utility method to get the netapp server object
* @param serverIp -- ip address of netapp box
* @param userName -- username
* @param password -- password
* @return
* @throws UnknownHostException
*/
private NaServer getServer(String serverIp, String userName, String password) throws UnknownHostException {
//Initialize connection to server, and
//request version 1.3 of the API set
NaServer s = new NaServer(serverIp, 1, 3);
s.setStyle(NaServer.STYLE_LOGIN_PASSWORD);
s.setAdminUser(userName, password);
return s;
}
use of netapp.manage.NaServer in project cloudstack by apache.
the class NetappManagerImpl method returnSnapshotSchedule.
/**
* Utility method to return snapshot schedule for a volume
* @param vol -- volume for the snapshot schedule creation
* @return -- the snapshot schedule
* @throws ServerException
*/
private String returnSnapshotSchedule(NetappVolumeVO vol) throws ServerException {
NaElement xi = new NaElement("snapshot-get-schedule");
xi.addNewChild("volume", vol.getVolumeName());
NaServer s = null;
try {
s = getServer(vol.getIpAddress(), vol.getUsername(), vol.getPassword());
NaElement xo = s.invokeElem(xi);
String weeks = xo.getChildContent("weeks");
String days = xo.getChildContent("days");
String hours = xo.getChildContent("hours");
String minutes = xo.getChildContent("minutes");
String whichHours = xo.getChildContent("which-hours");
String whichMinutes = xo.getChildContent("which-minutes");
StringBuilder sB = new StringBuilder();
sB.append(weeks).append(" ").append(days).append(" ").append(hours).append("@").append(whichHours).append(" ").append(minutes).append("@").append(whichMinutes);
return sB.toString();
} catch (NaException nae) {
s_logger.warn("Failed to get volume size ", nae);
throw new ServerException("Failed to get volume size", nae);
} catch (IOException ioe) {
s_logger.warn("Failed to get volume size ", ioe);
throw new ServerException("Failed to get volume size", ioe);
} finally {
if (s != null)
s.close();
}
}
use of netapp.manage.NaServer in project cloudstack by apache.
the class NetappManagerImpl method destroyLunOnFiler.
/**
* This method destroys a lun on the netapp filer
* @param lunName -- name of the lun to be destroyed
*/
@Override
@DB
public void destroyLunOnFiler(String lunName) throws InvalidParameterValueException, ServerException {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
LunVO lun = _lunDao.findByName(lunName);
if (lun == null)
throw new InvalidParameterValueException("Cannot find lun");
NetappVolumeVO vol = _volumeDao.acquireInLockTable(lun.getVolumeId());
if (vol == null) {
s_logger.warn("Failed to lock volume id= " + lun.getVolumeId());
return;
}
NaServer s = null;
try {
s = getServer(vol.getIpAddress(), vol.getUsername(), vol.getPassword());
if (s_logger.isDebugEnabled())
s_logger.debug("Request --> destroyLun " + ":serverIp:" + vol.getIpAddress());
try {
//Unmap lun
NaElement xi2 = new NaElement("lun-unmap");
xi2.addNewChild("initiator-group", lunName);
xi2.addNewChild("path", lun.getPath() + lun.getLunName());
s.invokeElem(xi2);
} catch (NaAPIFailedException naf) {
if (naf.getErrno() == 9016)
s_logger.warn("no map exists excpn 9016 caught in deletelun, continuing with delete");
}
//destroy lun
NaElement xi = new NaElement("lun-destroy");
xi.addNewChild("force", "true");
xi.addNewChild("path", lun.getPath() + lun.getLunName());
s.invokeElem(xi);
//destroy igroup
NaElement xi1 = new NaElement("igroup-destroy");
//xi1.addNewChild("force","true");
xi1.addNewChild("initiator-group-name", lunName);
s.invokeElem(xi1);
_lunDao.remove(lun.getId());
txn.commit();
} catch (UnknownHostException uhe) {
txn.rollback();
s_logger.warn("Failed to delete lun", uhe);
throw new ServerException("Failed to delete lun", uhe);
} catch (IOException ioe) {
txn.rollback();
s_logger.warn("Failed to delete lun", ioe);
throw new ServerException("Failed to delete lun", ioe);
} catch (NaAPIFailedException naf) {
if (naf.getErrno() == 9017) {
//no such group exists excpn
s_logger.warn("no such group exists excpn 9017 caught in deletelun, continuing with delete");
_lunDao.remove(lun.getId());
txn.commit();
} else if (naf.getErrno() == 9029) {
//LUN maps for this initiator group exist
s_logger.warn("LUN maps for this initiator group exist errno 9029 caught in deletelun, continuing with delete");
_lunDao.remove(lun.getId());
txn.commit();
} else {
txn.rollback();
s_logger.warn("Failed to delete lun", naf);
throw new ServerException("Failed to delete lun", naf);
}
} catch (NaException nae) {
txn.rollback();
s_logger.warn("Failed to delete lun", nae);
throw new ServerException("Failed to delete lun", nae);
} finally {
if (vol != null) {
_volumeDao.releaseFromLockTable(vol.getId());
}
if (s != null)
s.close();
}
}
use of netapp.manage.NaServer in project cloudstack by apache.
the class NetappManagerImpl method createVolumeOnFiler.
/**
* This method creates a volume on netapp filer
* @param ipAddress -- ip address of the filer
* @param aggName -- name of aggregate
* @param poolName -- name of pool
* @param volName -- name of volume
* @param volSize -- size of volume to be created
* @param snapshotPolicy -- associated snapshot policy for volume
* @param snapshotReservation -- associated reservation for snapshots
* @param username -- username
* @param password -- password
* @throws UnknownHostException
* @throws InvalidParameterValueException
*/
@Override
@DB
public void createVolumeOnFiler(String ipAddress, String aggName, String poolName, String volName, String volSize, String snapshotPolicy, Integer snapshotReservation, String username, String password) throws UnknownHostException, ServerException, InvalidParameterValueException {
if (s_logger.isDebugEnabled())
s_logger.debug("Request --> createVolume " + "serverIp:" + ipAddress);
boolean snapPolicy = false;
boolean snapshotRes = false;
boolean volumeCreated = false;
NaServer s = getServer(ipAddress, username, password);
NaElement xi = new NaElement("volume-create");
xi.addNewChild("volume", volName);
xi.addNewChild("containing-aggr-name", aggName);
xi.addNewChild("size", volSize);
NaElement xi1 = new NaElement("snapshot-set-reserve");
if (snapshotReservation != null) {
snapshotRes = true;
xi1.addNewChild("percentage", snapshotReservation.toString());
xi1.addNewChild("volume", volName);
}
NaElement xi2 = new NaElement("snapshot-set-schedule");
if (snapshotPolicy != null) {
snapPolicy = true;
String weeks = null;
String days = null;
String hours = null;
String whichHours = null;
String minutes = null;
String whichMinutes = null;
StringTokenizer s1 = new StringTokenizer(snapshotPolicy, " ");
if (s1.hasMoreTokens()) {
weeks = s1.nextToken();
}
if (weeks != null && s1.hasMoreTokens()) {
days = s1.nextToken();
}
if (days != null && s1.hasMoreTokens()) {
String[] hoursArr = s1.nextToken().split("@");
hours = hoursArr[0];
whichHours = hoursArr[1];
}
if (hours != null && s1.hasMoreTokens()) {
String[] minsArr = s1.nextToken().split("@");
minutes = minsArr[0];
whichMinutes = minsArr[1];
}
if (weeks != null)
xi2.addNewChild("weeks", weeks);
if (days != null)
xi2.addNewChild("days", days);
if (hours != null)
xi2.addNewChild("hours", hours);
if (minutes != null)
xi2.addNewChild("minutes", minutes);
xi2.addNewChild("volume", volName);
if (whichHours != null)
xi2.addNewChild("which-hours", whichHours);
if (whichMinutes != null)
xi2.addNewChild("which-minutes", whichMinutes);
}
Long volumeId = null;
final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
NetappVolumeVO volume = null;
volume = _volumeDao.findVolume(ipAddress, aggName, volName);
if (volume != null) {
throw new InvalidParameterValueException("The volume for the given ipAddress/aggregateName/volumeName tuple already exists");
}
PoolVO pool = _poolDao.findPool(poolName);
if (pool == null) {
throw new InvalidParameterValueException("Cannot find pool " + poolName);
}
pool = _poolDao.acquireInLockTable(pool.getId());
if (pool == null) {
s_logger.warn("Failed to acquire lock on pool " + poolName);
throw new ConcurrentModificationException("Failed to acquire lock on pool " + poolName);
}
volume = new NetappVolumeVO(ipAddress, aggName, pool.getId(), volName, volSize, "", 0, username, password, 0, pool.getName());
volume = _volumeDao.persist(volume);
volumeId = volume.getId();
try {
s.invokeElem(xi);
volumeCreated = true;
if (snapshotRes) {
s.invokeElem(xi1);
volume.setSnapshotReservation(snapshotReservation);
_volumeDao.update(volumeId, volume);
}
if (snapPolicy) {
s.invokeElem(xi2);
volume.setSnapshotPolicy(snapshotPolicy);
_volumeDao.update(volumeId, volume);
}
txn.commit();
} catch (NaException nae) {
//zapi call failed, log and throw e
s_logger.warn("Failed to create volume on the netapp filer:", nae);
txn.rollback();
if (volumeCreated) {
try {
//deletes created volume on filer
deleteRogueVolume(volName, s);
} catch (NaException e) {
s_logger.warn("Failed to cleanup created volume whilst rolling back on the netapp filer:", e);
throw new ServerException("Unable to create volume via cloudtools." + "Failed to cleanup created volume on netapp filer whilst rolling back on the cloud db:", e);
} catch (IOException e) {
s_logger.warn("Failed to cleanup created volume whilst rolling back on the netapp filer:", e);
throw new ServerException("Unable to create volume via cloudtools." + "Failed to cleanup created volume on netapp filer whilst rolling back on the cloud db:", e);
}
}
throw new ServerException("Unable to create volume", nae);
} catch (IOException ioe) {
s_logger.warn("Failed to create volume on the netapp filer:", ioe);
txn.rollback();
if (volumeCreated) {
try {
//deletes created volume on filer
deleteRogueVolume(volName, s);
} catch (NaException e) {
s_logger.warn("Failed to cleanup created volume whilst rolling back on the netapp filer:", e);
throw new ServerException("Unable to create volume via cloudtools." + "Failed to cleanup created volume on netapp filer whilst rolling back on the cloud db:", e);
} catch (IOException e) {
s_logger.warn("Failed to cleanup created volume whilst rolling back on the netapp filer:", e);
throw new ServerException("Unable to create volume via cloudtools." + "Failed to cleanup created volume on netapp filer whilst rolling back on the cloud db:", e);
}
}
throw new ServerException("Unable to create volume", ioe);
} finally {
if (s != null)
s.close();
if (pool != null)
_poolDao.releaseFromLockTable(pool.getId());
}
}
use of netapp.manage.NaServer in project coprhd-controller by CoprHD.
the class Server method createNaServer.
private NaServer createNaServer(String addr, int port, String username, String password, boolean useHTTPS, boolean isVserver, String vServerName, boolean isCluster) {
NaServer server = null;
try {
// Added this condition to support lower versions of ontapi for 7-mode.
if (isCluster) {
server = new NaServer(addr, 1, 20);
} else {
server = new NaServer(addr, 1, 17);
}
server.setServerType(NaServer.SERVER_TYPE_FILER);
server.setStyle(NaServer.STYLE_LOGIN_PASSWORD);
if (useHTTPS) {
server.setTransportType(NaServer.TRANSPORT_TYPE_HTTPS);
} else {
server.setTransportType(NaServer.TRANSPORT_TYPE_HTTP);
}
server.setPort(port);
server.setAdminUser(username, password);
server.setKeepAliveEnabled(true);
if (isVserver) {
if (vServerName != null && !vServerName.isEmpty()) {
server.setVserver(vServerName);
}
} else {
if (vServerName != null && !vServerName.isEmpty()) {
server.setVfilerTunneling(vServerName);
}
}
} catch (NoClassDefFoundError nCDFE) {
// no class found in OSS version of file controller and we need to handle this scenario gracefully.
throw new NetAppException("ONTAP SDK APIs could not be found in the classpath. " + "Please check the classpath for availability of the appropriate jar.");
} catch (Exception e) {
_log.error("Problem while connecting to Array due to {}", e);
}
return server;
}
Aggregations