use of com.emc.storageos.vnxe.models.HostInitiatorCreateParam in project coprhd-controller by CoprHD.
the class VNXeApiClient method prepareHostsForExport.
/**
* given host name and initiators, find/create hosts/initiators in the
*
* @param hostInitiators
* @return
*/
public VNXeBase prepareHostsForExport(Collection<VNXeHostInitiator> hostInitiators) throws VNXeException {
String hostId = null;
Set<VNXeHostInitiator> notExistingInits = new HashSet<VNXeHostInitiator>();
Set<VNXeHostInitiator> existingNoHostInits = new HashSet<VNXeHostInitiator>();
String hostOsType = null;
String hostName = null;
for (VNXeHostInitiator init : hostInitiators) {
VNXeHostInitiator existingInit = getInitiatorByWWN(init.getInitiatorId());
if (existingInit != null && existingInit.getParentHost() != null) {
if (hostId == null) {
hostId = existingInit.getParentHost().getId();
} else if (!hostId.equals(existingInit.getParentHost().getId())) {
_logger.error("Initiators belong to different hosts");
throw VNXeException.exceptions.vnxeCommandFailed("Initiators belong to different hosts");
}
} else if (existingInit != null) {
existingNoHostInits.add(existingInit);
} else {
notExistingInits.add(init);
}
if (hostOsType == null) {
hostOsType = init.getHostOsType();
}
if (hostName == null) {
hostName = init.getName();
}
}
if (hostId == null) {
// create host and hostInitiator
HostListRequest hostReq = new HostListRequest(_khClient);
HostCreateParam hostCreateParm = new HostCreateParam();
hostCreateParm.setName(hostName);
hostCreateParm.setType(HostTypeEnum.HOSTMANUAL.getValue());
if (isUnityClient() && hostOsType != null) {
hostCreateParm.setOsType(hostOsType);
}
VNXeCommandResult result = hostReq.createHost(hostCreateParm);
hostId = result.getId();
}
for (VNXeHostInitiator newInit : notExistingInits) {
HostInitiatorCreateParam initCreateParam = new HostInitiatorCreateParam();
VNXeBase host = new VNXeBase(hostId);
initCreateParam.setHost(host);
if (newInit.getType() == HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI) {
initCreateParam.setInitiatorType(HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI.getValue());
initCreateParam.setInitiatorWWNorIqn(newInit.getChapUserName());
initCreateParam.setChapUser(newInit.getChapUserName());
} else {
initCreateParam.setInitiatorType(HostInitiatorTypeEnum.INITIATOR_TYPE_FC.getValue());
initCreateParam.setInitiatorWWNorIqn(newInit.getInitiatorId());
}
HostInitiatorRequest req = new HostInitiatorRequest(_khClient);
try {
req.createHostInitiator(initCreateParam);
} catch (VNXeException e) {
// For ESX hosts, even if we could not get the initiators when we query them, when we try to create the host
// initiator with the created host, it would throw error, saying the initiator exists. ignore the error.
String message = e.getMessage();
if (message != null && message.contains(VNXeConstants.INITIATOR_EXISITNG)) {
_logger.info("The initiator exists. Ignore the error.");
} else {
throw e;
}
}
}
for (VNXeHostInitiator exitInit : existingNoHostInits) {
setInitiatorHost(exitInit.getId(), hostId);
}
return new VNXeBase(hostId);
}
use of com.emc.storageos.vnxe.models.HostInitiatorCreateParam in project coprhd-controller by CoprHD.
the class VNXeApiClient method createInitiator.
/**
* Create host initiator in the array
*
* @param inits
* @param hostId
*/
public void createInitiator(VNXeHostInitiator newInit, String hostId) {
HostInitiatorCreateParam initCreateParam = new HostInitiatorCreateParam();
VNXeBase host = new VNXeBase(hostId);
initCreateParam.setHost(host);
if (newInit.getType() == HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI) {
initCreateParam.setInitiatorType(HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI.getValue());
initCreateParam.setInitiatorWWNorIqn(newInit.getChapUserName());
initCreateParam.setChapUser(newInit.getChapUserName());
} else {
initCreateParam.setInitiatorType(HostInitiatorTypeEnum.INITIATOR_TYPE_FC.getValue());
initCreateParam.setInitiatorWWNorIqn(newInit.getInitiatorId());
}
HostInitiatorRequest req = new HostInitiatorRequest(_khClient);
req.createHostInitiator(initCreateParam);
}
use of com.emc.storageos.vnxe.models.HostInitiatorCreateParam in project coprhd-controller by CoprHD.
the class HostInitiatorTest method createHostInititaor.
// @Test
public void createHostInititaor() {
String hostId = "Host_1";
String wwn = "20:00:00:25:b5:5d:00:04:20:00:00:25:b5:5d:00:e5";
HostInitiatorCreateParam initCreateParam = new HostInitiatorCreateParam();
VNXeBase host = new VNXeBase(hostId);
initCreateParam.setHost(host);
initCreateParam.setInitiatorType(HostInitiatorTypeEnum.INITIATOR_TYPE_FC.getValue());
initCreateParam.setInitiatorWWNorIqn(wwn);
HostInitiatorRequest req = new HostInitiatorRequest(_client);
req.createHostInitiator(initCreateParam);
}
Aggregations