//update lun name
lun.setLunName(lunName.toString());
_lunDao.update(lun.getId(), lun);
NaElement xi;
NaElement xi1;
long lSizeBytes = 1L*lunSize*1024*1024*1024; //This prevents integer overflow
Long lunSizeBytes = new Long(lSizeBytes);
s = getServer(selectedVol.getIpAddress(), selectedVol.getUsername(),selectedVol.getPassword());
//create lun
xi = new NaElement("lun-create-by-size");
xi.addNewChild("ostype","linux");
xi.addNewChild("path",exportPath.toString());
xi.addNewChild("size", (lunSizeBytes.toString()));
s.invokeElem(xi);
try
{
//now create an igroup
xi1 = new NaElement("igroup-create");
xi1.addNewChild("initiator-group-name", lunName .toString());
xi1.addNewChild("initiator-group-type", "iscsi");
xi1.addNewChild("os-type", "linux");
s.invokeElem(xi1);
}catch(NaAPIFailedException e)
{
if(e.getErrno() == 9004)
{
//igroup already exists hence no error
s_logger.warn("Igroup already exists");
}
}
//get target iqn
NaElement xi4 = new NaElement("iscsi-node-get-name");
NaElement xo = s.invokeElem(xi4);
String iqn = xo.getChildContent("node-name");
lun.setTargetIqn(iqn);
_lunDao.update(lun.getId(), lun);
//create lun mapping
//now map the lun to the igroup
NaElement xi3 = new NaElement("lun-map");
xi3.addNewChild("force", "true");
xi3.addNewChild("initiator-group", lunName.toString());
xi3.addNewChild("path", lun.getPath() + lun.getLunName());
xi3.addNewChild("lun-id", lunIdStr);
s.invokeElem(xi3);
txn.commit();
//set the result
result[0] = lunName.toString();//lunname