use of com.emc.storageos.networkcontroller.SSHSession in project coprhd-controller by CoprHD.
the class MDSDialogTest method main.
/**
* @param args
* Working directory:
* ${workspace_loc:shared-fczoning-ad/controllersvc/src/main/test/com/emc/storageos/networkcontroller/impl/mds}
* Eclipse launch XML:
*/
public static void main(String[] args) {
Properties properties = new Properties();
// PropertyConfigurator.configure("log4j.properties");
_log.info("Beginning logging");
// try {
// properties.load(new FileInputStream("properties.xml"));
// ipaddress = properties.getProperty("ipaddress");
// sshport = new Integer(properties.getProperty("sshport"));
// username = properties.getProperty("username");
// password = properties.getProperty("password");
// vsanId = properties.getProperty("vsanId");
// } catch (Exception ex) {
// System.out.println("Couldn't load properties.xml file");
// }
SSHSession sshs = null;
try {
sshs = new SSHSession();
sshs.connect(ipaddress, sshport, username, password);
MDSDialog dialog = new MDSDialog(sshs, null);
dialog.initialize();
String[] versions = dialog.showVersion();
if (versions[0] != null) {
System.out.println("Hardware: " + versions[0]);
}
if (versions[1] != null) {
System.out.println("Software: " + versions[1]);
}
Map<Integer, Set<String>> peerDevicesMap = dialog.showTopology();
System.out.println("Peer Devices: ");
for (Entry<Integer, Set<String>> entry : peerDevicesMap.entrySet()) {
_log.info(String.format("...Vsan: %s, Peer devices: %s%n", entry.getKey(), entry.getValue()));
}
testNonIvr(dialog);
testIvr(dialog);
} catch (Exception ex) {
_log.error(ex.getMessage(), ex);
} finally {
if (sshs != null) {
sshs.disconnect();
}
}
}
use of com.emc.storageos.networkcontroller.SSHSession in project coprhd-controller by CoprHD.
the class MdsNetworkSystemDevice method setUpDialog.
/**
* Sets up a session. Gets session parameters from the NetworkSystem.
*
* @param networkSystem NetworkSystem
* @return MDSDialog representing the session
* @throws NetworkDeviceControllerException
*/
private MDSDialog setUpDialog(NetworkSystem networkSystem) throws NetworkDeviceControllerException {
try {
SSHSession session = new SSHSession();
session.connect(networkSystem.getIpAddress(), networkSystem.getPortNumber(), networkSystem.getUsername(), networkSystem.getPassword());
MDSDialog dialog = new MDSDialog(session, getDefaultTimeout());
dialog.initialize();
return dialog;
} catch (Exception ex) {
String exMsg = ex.getLocalizedMessage();
if (exMsg.equals("Auth fail")) {
exMsg = "Authorization Failed";
}
if (exMsg.equals("timeout: socket is not established")) {
exMsg = "Connection Failed";
}
String msg = MessageFormat.format("Could not connect to device {0}: {1}", networkSystem.getLabel(), exMsg);
_log.error(msg);
throw NetworkDeviceControllerException.exceptions.setUpDialogFailed(networkSystem.getLabel(), exMsg, ex);
}
}
use of com.emc.storageos.networkcontroller.SSHSession in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method waitForFinishMethod.
/**
* Utility wait method to check os install status
* @param jobId {@link URI} job id
* @param hostName {@link String} host name for error reporting
* @param stepId {@link String} step id
*/
public void waitForFinishMethod(URI jobId, String hostName, String stepId) {
log.info("waitForFinishMethod {}, {} ", jobId, hostName);
try {
WorkflowStepCompleter.stepExecuting(stepId);
ComputeImageJob job = dbClient.queryObject(ComputeImageJob.class, jobId);
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, job.getComputeImageServerId());
if (job.getJobStartTime() == null) {
log.info("starting the job");
job.setJobStartTime(System.currentTimeMillis());
dbClient.updateObject(job);
} else {
log.info("resuming the job");
}
OsInstallStatus status = null;
while (System.currentTimeMillis() - job.getJobStartTime() < imageServer.getOsInstallTimeoutMs() && status == null) {
try {
log.info("sleep for {} ms", imageServer.getJobPollingIntervalMs());
Thread.sleep(imageServer.getJobPollingIntervalMs());
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
}
log.info("check status for {}, after {} sec", job.getPxeBootIdentifier(), (System.currentTimeMillis() - job.getJobStartTime()) / 1000);
status = osInstallStatusPoller.getOsInstallStatus(job.getPxeBootIdentifier());
}
if (status != null) {
// it is success or failure - do clean up
ImageServerDialog d = null;
try {
SSHSession session = new SSHSession();
session.connect(imageServer.getImageServerIp(), imageServer.getSshPort(), imageServer.getImageServerUser(), imageServer.getImageServerPassword());
d = new ImageServerDialog(session, imageServer.getSshTimeoutMs());
d.init();
d.rm(imageServer.getTftpBootDir() + HTTP_SUCCESS_DIR + job.getPxeBootIdentifier());
d.rm(imageServer.getTftpBootDir() + HTTP_FAILURE_DIR + job.getPxeBootIdentifier());
d.rm(imageServer.getTftpBootDir() + HTTP_KICKSTART_DIR + job.getPxeBootIdentifier());
d.rm(imageServer.getTftpBootDir() + HTTP_FIRSTBOOT_DIR + job.getPxeBootIdentifier());
d.rm(imageServer.getTftpBootDir() + PXELINUX_CFG_DIR + job.getPxeBootIdentifier());
d.rm(imageServer.getTftpBootDir() + PXELINUX_CFG_DIR + job.getPxeBootIdentifier() + ".boot.cfg");
} catch (Exception e) {
log.error("exception when trying to poll for status", e);
} finally {
try {
if (d != null && d.isConnected()) {
d.close();
}
} catch (Exception e) {
log.error(FAILED_TO_CLOSE_STR, e);
}
}
}
log.info("job status: {}", status);
if (status == OsInstallStatus.SUCCESS) {
log.info("session {} - marking job as SUCCESS", job.getPxeBootIdentifier());
job.setJobStatus(JobStatus.SUCCESS.name());
dbClient.updateObject(job);
WorkflowStepCompleter.stepSucceded(stepId);
} else if (status == OsInstallStatus.FAILURE) {
log.info("session {} - marking job as FAILED", job.getPxeBootIdentifier());
job.setJobStatus(JobStatus.FAILED.name());
dbClient.updateObject(job);
WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.osInstallationFailed(hostName, "failure in the post-install"));
} else {
// timed out
log.info("session {} - marking job as TIMEDOUT", job.getPxeBootIdentifier());
job.setJobStatus(JobStatus.TIMEDOUT.name());
dbClient.updateObject(job);
WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.osInstallationTimedOut(hostName, imageServer.getOsInstallTimeoutMs() / 1000));
}
} catch (InternalException e) {
log.error("Exception waiting for finish: " + e.getMessage(), e);
WorkflowStepCompleter.stepFailed(stepId, e);
} catch (Exception e) {
log.error("Unexpected exception waiting for finish: " + e.getMessage(), e);
String opName = ResourceOperationTypeEnum.INSTALL_OPERATING_SYSTEM.getName();
WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.unexpectedException(opName, e));
}
}
use of com.emc.storageos.networkcontroller.SSHSession in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method preparePxeBootMethod.
/**
* Prepare pxe boot method, copies the conf file
* @param jobId {@link URI} job id
* @param stepId {@link String} step id
*/
public void preparePxeBootMethod(URI jobId, String stepId) {
log.info("preparePxeBootMethod {} ", jobId);
ImageServerDialog d = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
ComputeImageJob job = dbClient.queryObject(ComputeImageJob.class, jobId);
ComputeImage img = dbClient.queryObject(ComputeImage.class, job.getComputeImageId());
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, job.getComputeImageServerId());
SSHSession session = new SSHSession();
session.connect(imageServer.getImageServerIp(), imageServer.getSshPort(), imageServer.getImageServerUser(), imageServer.getImageServerPassword());
d = new ImageServerDialog(session, imageServer.getSshTimeoutMs());
d.init();
log.info("connected to image server");
log.info("putting pxe conf file");
pxeIntegrationService.createSession(d, job, img, imageServer);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (InternalException e) {
log.error("Exception preparing pxe boot: " + e.getMessage(), e);
WorkflowStepCompleter.stepFailed(stepId, e);
} catch (Exception e) {
log.error("Unexpected exception preparing pxe boot: " + e.getMessage(), e);
String opName = ResourceOperationTypeEnum.INSTALL_OPERATING_SYSTEM.getName();
WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.unexpectedException(opName, e));
} finally {
try {
if (d != null && d.isConnected()) {
d.close();
}
} catch (Exception e) {
log.error(FAILED_TO_CLOSE_STR, e);
}
}
}
use of com.emc.storageos.networkcontroller.SSHSession in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method deleteImageMethod.
/**
* Deletes a given image from the imageServer
* @param ciId {@link URI} compute image id
* @param imageServerId {@link URI} compute image server id
* @param stepId {@link String} step id
*/
public void deleteImageMethod(URI ciId, URI imageServerId, String stepId) {
log.info("deleteImageMethod {}", ciId);
ImageServerDialog d = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
ComputeImage ci = dbClient.queryObject(ComputeImage.class, ciId);
SSHSession session = new SSHSession();
session.connect(imageServer.getImageServerIp(), imageServer.getSshPort(), imageServer.getImageServerUser(), imageServer.getImageServerPassword());
d = new ImageServerDialog(session, imageServer.getSshTimeoutMs());
d.init();
log.info("connected to image server");
log.info("calling image server to delete image");
d.rm(imageServer.getTftpBootDir() + ci.getPathToDirectory());
log.info("delete done");
if (imageServer.getComputeImages() != null && imageServer.getComputeImages().contains(ciId.toString())) {
imageServer.getComputeImages().remove(ciId.toString());
dbClient.updateObject(imageServer);
}
WorkflowStepCompleter.stepSucceded(stepId);
} catch (InternalException e) {
log.error("Exception deleting image: " + e.getMessage(), e);
WorkflowStepCompleter.stepFailed(stepId, e);
} catch (Exception e) {
log.error("Unexpected exception deleting image: " + e.getMessage(), e);
String opName = ResourceOperationTypeEnum.REMOVE_IMAGE.getName();
WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.unexpectedException(opName, e));
} finally {
try {
if (d != null && d.isConnected()) {
d.close();
}
} catch (Exception e) {
log.error(FAILED_TO_CLOSE_STR, e);
}
}
}
Aggregations